@inkeep/impulse-compute 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1426 @@
1
+ #!/usr/bin/env node
2
+ // openteammate bundle: {"schema":"openteammate.bundle/provenance@1","source":{"repository":"inkeep/openteammate","commit":"3e82f8538f896372e1d4d6f005ed8c9b60fa0b77","path":"scripts/offload","tree":"beb50530b533754a4a23a1bb087390b19a67f3bc","entry":"../../packages/compute/src/main.ts"},"lockfile":{"path":"scripts/offload/pnpm-lock.yaml","sha256":"7af5bf26be1f3ddf53b9b03e8a5d3e3b63c009256f80a72764106322bed7263d"},"sources":[{"path":"packages/compute","tree":"bb481ded704ff05c1ed2b7bd50052bd757b061d8","lockfile":{"path":"pnpm-lock.yaml","sha256":"7b82bd3b6f37902ad8e6c59385b2cb438750ef640319bf3a3f8ef591a2cbf518"}},{"path":"scripts/offload","tree":"beb50530b533754a4a23a1bb087390b19a67f3bc","lockfile":{"path":"scripts/offload/pnpm-lock.yaml","sha256":"7af5bf26be1f3ddf53b9b03e8a5d3e3b63c009256f80a72764106322bed7263d"}},{"path":"scripts/linux-desktop","tree":"127da1f1939a80f54393ad8f2c26376b70087cf6","lockfile":{"path":"scripts/linux-desktop/pnpm-lock.yaml","sha256":"33de8bef2e511ca1dc5a86038349955ac25ffeb880de0285ace6f3b048d2174b"}},{"path":"scripts/ec2-instance","tree":"94bfbbed80a2b9b634423d1a037235bacff3fd64","lockfile":{"path":"scripts/ec2-instance/pnpm-lock.yaml","sha256":"5b49d1967c45f686c0a4497fdc3555d6a57946e28dd2cd6bb476996da72ceaee"}}],"bundler":{"name":"rolldown","version":"1.2.11"},"format":"esm","platform":"node"}
3
+ import{isBuiltin as e}from"node:module";import*as t from"node:os";import n,{constants as r,tmpdir as i}from"node:os";import*as a from"node:path";import o,{basename as s,delimiter as c,dirname as l,isAbsolute as u,join as d,relative as f,resolve as p}from"node:path";import*as m from"node:url";import h,{fileURLToPath as g}from"node:url";import*as _ from"node:crypto";import v,{createHash as y,randomUUID as b}from"node:crypto";import*as ee from"node:child_process";import{execFile as x,spawn as te}from"node:child_process";import*as ne from"node:stream";import re,{PassThrough as ie,finished as ae}from"node:stream";import"node:string_decoder";import*as S from"node:fs";import oe,{accessSync as C,chmodSync as se,closeSync as ce,constants as le,existsSync as ue,mkdirSync as w,mkdtempSync as de,openSync as fe,readFileSync as T,renameSync as pe,rmSync as me,writeFileSync as E}from"node:fs";import*as he from"node:readline";import{link as ge,lstat as _e,mkdir as ve,readFile as ye,rename as be,stat as xe,unlink as Se,writeFile as Ce}from"node:fs/promises";import*as eee from"node:zlib";import{crc32 as tee,inflateSync as nee}from"node:zlib";import*as ree from"node:util";import*as iee from"node:assert";import*as aee from"node:buffer";import we from"node:process";import Te from"node:tty";var oee=Object.create,Ee=Object.defineProperty,see=Object.getOwnPropertyDescriptor,cee=Object.getOwnPropertyNames,lee=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty,Oe=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),uee=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=cee(t),a=0,o=i.length,s;a<o;a++)s=i[a],!De.call(e,s)&&s!==n&&Ee(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=see(t,s))||r.enumerable});return e},dee=(e,t,n)=>(n=e==null?{}:oee(lee(e)),uee(t||!e||!e.__esModule||!De.call(e,`default`)?Ee(n,`default`,{value:e,enumerable:!0}):n,e)),ke=`0.2.0`;const Ae=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}},fee={pipe(){return Ae(this,arguments)}},je=function(){function e(){}return e.prototype=fee,e}(),D=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},Me=e=>e,Ne=e=>()=>e,Pe=Ne(!0),pee=Ne(!1),mee=Ne(null),Fe=Ne(void 0),Ie=Fe;function Le(e,...t){return Ae(e,t)}function Re(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i}}function ze(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i!==n&&t.set(i,i),i}}const hee=[`line`,`column`,`sourceURL`,`originalLine`,`originalColumn`],Be=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;if(e instanceof Error){t.delete(`stack`);for(let n of hee)Object.prototype.propertyIsEnumerable.call(e,n)||t.delete(n)}let n=Object.getPrototypeOf(e),r=n;for(;r!==null&&r!==Object.prototype;){let e=Reflect.ownKeys(r);for(let n=0;n<e.length;n++)t.add(e[n]);r=Object.getPrototypeOf(r)}return t.has(`constructor`)&&typeof e.constructor==`function`&&n===e.constructor.prototype&&t.delete(`constructor`),t},Ve=new WeakSet,He=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),Ue=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer,We=e=>{try{return new Uint8Array(e)}catch{return}};let Ge=0;const gee=()=>{Ge++};function Ke(e){return typeof e==`string`}function qe(e){return typeof e==`number`}function Je(e){return typeof e==`boolean`}function _ee(e){return typeof e==`bigint`}function vee(e){return typeof e==`symbol`}function yee(e){return Ke(e)||qe(e)||vee(e)}function Ye(e){return typeof e==`function`}function Xe(e){return e===void 0}function Ze(e){return e!==void 0}function Qe(e){return e!==null}function bee(e){return e==null}function xee(e){return e!=null}function See(e){return!0}function Cee(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e){return typeof e==`object`&&!!e||Ye(e)}const et=D(2,(e,t)=>$e(e)&&t in e),tt=D(2,(e,t)=>et(e,`_tag`)&&e._tag===t);function wee(e){return e instanceof Error}function Tee(e){return et(e,Symbol.iterator)||Ke(e)}const nt=`~effect/Hash`,rt=e=>{switch(typeof e){case`number`:return lt(e);case`bigint`:return ut(e.toString(10));case`string`:return ut(e);case`function`:case`object`:if(e===null)break;if(e instanceof Date)return Number.isNaN(e.getTime())?ut(`Invalid Date`):ut(e.toISOString());if(e instanceof RegExp)return ut(e.toString());{if(Ve.has(e))return it(e);let t=ht.get(e);if(t!==void 0)return t;if(gt.has(e))return gee(),ut(`[Circular]`);gt.add(e);let n=Ge,r;try{if(Eee(e))r=e[nt]();else if(typeof e==`function`)r=it(e);else if(Ue(e)){let t=We(e);r=t===void 0?it(e):ft(t)}else r=e instanceof DataView?ft(He(e)):Array.isArray(e)||ArrayBuffer.isView(e)?ft(e):e instanceof Map?kee(e):e instanceof Set?Aee(e):Oee(e)}finally{gt.delete(e)}return n===Ge&&ht.set(e,r),r}}return st(at(ut(String(e))))},it=e=>(mt.has(e)||mt.set(e,st(Math.random()*4294967296|0)),mt.get(e)),at=e=>(e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^e>>>16),ot=D(2,(e,t)=>at(Math.imul(e,2654435761)+Math.imul(t,2246822507))),st=e=>e&3221225471|e>>>1&1073741824,Eee=e=>et(e,`~effect/Hash`)&&typeof e[`~effect/Hash`]==`function`,ct=new DataView(new ArrayBuffer(8)),lt=e=>{let t=e|0;return t===e?st(t):(ct.setFloat64(0,e===e?e:NaN),st(ot(ct.getInt32(0),ct.getInt32(4))))},ut=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return st(t)},Dee=(e,t)=>{let n=12289;for(let r of t)n^=ot(rt(r),rt(e[r]));return st(n)},Oee=e=>Dee(e,Be(e)),dt=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return st(r)},ft=e=>{let t=6151;for(let n of e)t=ot(t,rt(n));return st(t)},kee=dt(ut(`Map`),([e,t])=>ot(rt(e),rt(t))),pt=ut(`Set`),Aee=dt(pt,e=>ot(pt,rt(e))),mt=new WeakMap,ht=new WeakMap,gt=new WeakSet,_t=`~effect/Equal`;function vt(){return arguments.length===1?e=>yt(e,arguments[0]):yt(arguments[0],arguments[1])}function yt(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let n=typeof e;return n===typeof t?n===`number`&&e!==e&&t!==t?!0:n!==`object`&&n!==`function`||Ve.has(e)||Ve.has(t)?!1:jee(e,t):!1}function jee(e,t){let n=xt.length;for(let r=n;r-->0;)if(xt[r]===e&&St[r]===t)return!0;if(n)return bt(e,t);let r=Ct.get(e);r||Ct.set(e,r=new WeakMap);let i=r.get(t);return i===void 0&&r.set(t,i=bt(e,t)),i}function bt(e,t){xt.push(e),St.push(t);try{return Mee(e,t)}finally{xt.pop(),St.pop()}}const xt=[],St=[],Ct=new WeakMap;function Mee(e,t){if(rt(e)!==rt(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let n=Et(e);if(n!==Et(t)||typeof e==`function`&&!n)return!1;if(n)return e[_t](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:Nee(e,t);if(Ue(e)){if(!Ue(t)||e instanceof ArrayBuffer!=t instanceof ArrayBuffer)return!1;let n=We(e),r=We(t);return n!==void 0&&r!==void 0&&wt(n,r)}if(ArrayBuffer.isView(e)){let n=e instanceof DataView;return!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||n!==t instanceof DataView?!1:n?wt(He(e),He(t)):wt(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:Tt(e,t,Fee,Iee):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:Tt(e,t,rt,yt):Pee(e,t)}function Nee(e,t){for(let n=0;n<e.length;n++)if(!yt(e[n],t[n]))return!1;return!0}function wt(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Pee(e,t){let n=Be(e),r=Be(t);if(n.size!==r.size)return!1;for(let i of n)if(!r.has(i)||!yt(e[i],t[i]))return!1;return!0}function Tt(e,t,n,r){let i=new Map,a=0;for(let e of t){let t=n(e),r=i.get(t);r?r.push(e):i.set(t,[e]),a++}outer:for(let t of e){let e=i.get(n(t));if(e){for(let n=0;n<e.length;n++)if(r(t,e[n])){e[n]=e[e.length-1],e.pop(),a--;continue outer}}return!1}return a===0}const Fee=e=>rt(e[0]),Iee=(e,t)=>yt(e[0],t[0])&&yt(e[1],t[1]),Et=e=>et(e,`~effect/Equal`)&&typeof e[`~effect/Equal`]==`function`,Dt=Symbol.for(`~effect/Redactable`),Lee=e=>et(e,Dt);function Ot(e){return Lee(e)?Ree(e):e}function Ree(e){return e[Dt](globalThis[`~effect/Fiber/currentFiber`]?.context??zee)}const kt=`~effect/Fiber/currentFiber`,At=new Map,zee={"~effect/Context":{},base:At,depth:0,mapUnsafe:At,pipe(){return Ae(this,arguments)}};function jt(e,t){let n=t?.space??0,r=new WeakSet,i=n?typeof n==`number`?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,t=0){try{return l(e,t)}catch{return(typeof e==`object`&&e||typeof e==`function`)&&r.delete(e),`[inspection threw]`}}function l(e,n=0){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||e==null||typeof e==`boolean`||typeof e==`symbol`)return String(e);if(typeof e==`bigint`)return String(e)+`n`;if(typeof e==`object`||typeof e==`function`){if(r.has(e))return Bee;r.add(e);let l;if(Dt in e)l=c(Ree(e),n);else if(Array.isArray(e))l=!i||e.length<=1?`[${e.map(e=>c(e,n)).join(`,`)}]`:`[\n${a(n+1)}${e.map(e=>c(e,n+1)).join(`,
4
+ `+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=Hee(e);else if(!t?.ignoreToString&&et(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=Uee(e);l=e instanceof Error&&e.cause!==void 0?`${t} (cause: ${c(e.cause,n)})`:t}else if(Symbol.iterator in e)l=`${e.constructor.name}(${c(Array.from(e),n)})`;else{let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${Mt(t)}:${c(Nt(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${Mt(t)}: ${c(Nt(e,t),n+1)}`).join(`,
5
+ `)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}const Bee=`[Circular]`;function Mt(e){return typeof e==`string`?JSON.stringify(e):String(e)}function Vee(e){return e.map(e=>`[${Mt(e)}]`).join(``)}function Hee(e){try{return e.toISOString()}catch{return`Invalid Date`}}function Uee(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function Nt(e,t){try{return e[t]}catch{return`[property access threw]`}}function Pt(e,t){let n=[],r=new WeakMap;return JSON.stringify(e,function(e,t){let i=Object.getOwnPropertyDescriptor(r.get(this)??this,e)?.value,a=et(i,Dt)?Ot(i):Ot(t);if(typeof a==`bigint`)return jt(a);if(typeof a!=`object`||!a)return a;let o=a instanceof Error&&!et(a,`toJSON`)?{...a,name:a.name,message:a.message}:a;for(;n.length>0&&n[n.length-1]!==this;)n.pop();if(n.includes(a))return;if(n.push(a),o!==a&&n.push(o),!Wee(o)||Kee(o))return o;let s=Gee(o);return r.set(s,o),n.push(s),s},t?.space)??`null`}function Wee(e){for(let t of Object.getOwnPropertyNames(e))if(Object.getOwnPropertyDescriptor(e,t)?.get!==void 0)return!0;return!1}function Gee(e){let t=Array.isArray(e)?[]:{},n=Array.isArray(e)?Array.from({length:e.length},(e,t)=>String(t)):Object.keys(e);for(let r of n)Object.defineProperty(t,r,{enumerable:!0,get:()=>{let t=Reflect.get(e,r);return Object.getOwnPropertyDescriptor(e,r)?.get===void 0?t:Ot(t)}});return t}function Kee(e){for(let t of[Number.prototype.valueOf,Boolean.prototype.valueOf,String.prototype.valueOf])try{return Reflect.apply(t,e,[]),!0}catch{}return!1}const Ft=Symbol.for(`nodejs.util.inspect.custom`),It=e=>{try{return e=Ot(e),et(e,`toJSON`)&&Ye(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(It):e}catch{return`[toJSON threw]`}},qee=(e,t=2)=>{if(typeof e==`string`)return e;try{return typeof e==`object`?Pt(e,{space:t}):jt(e,{space:t})}catch{return String(e)}},Lt={toJSON(){return It(this)},[Ft](){return this.toJSON()},toString(){return jt(this.toJSON())}},Jee=(()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),Rt=()=>Error.stackTraceLimit,zt=e=>{Jee&&(Error.stackTraceLimit=e)};var Bt=class{constructor(e){this.value=e,this.done=!1}next(e){return this.done?(this.value=e,this):(this.done=!0,{value:this.value,done:!1})}};const Vt=(()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}},r=Rt();if(r===0)return n[e];zt(2);let i=t[e](()=>Error());return zt(r),i.stack?.includes(e)===!0?t[e]:n[e]})();function Ht(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function Yee(e,t){if(!Object.hasOwn(t,`__proto__`)){Object.assign(e,t);return}for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&Ht(e,n,t[n])}const Ut=`~effect/Effect`,Wt=`~effect/Exit`,Xee={_A:Me,_E:Me,_R:Me},Gt=`${Ut}/identifier`,Kt=`${Ut}/args`,qt=`${Ut}/evaluate`,Jt=`${Ut}/successCont`,Yt=`${Ut}/failureCont`,Xt=`${Ut}/ensureCont`,Zt=Symbol.for(`effect/Effect/Yield`),Qt={pipe(){return Ae(this,arguments)},toJSON(){return{...this}},toString(){return jt(this.toJSON(),{ignoreToString:!0,space:2})},[Ft](){return this.toJSON()}},Zee={[Ut]:Xee,...Qt,[Symbol.iterator](){return new Bt(this)},toJSON(){return{_id:`Effect`,op:this[Gt],...Kt in this?{args:this[Kt]}:void 0}}},$t=e=>et(e,Ut),en=e=>et(e,Wt),tn=`~effect/Cause`,nn=`~effect/Cause/Reason`,rn=e=>et(e,tn);var an=class{constructor(e){this[tn]=tn,this.reasons=e}pipe(){return Ae(this,arguments)}toJSON(){return{_id:`Cause`,reasons:this.reasons.map(e=>e.toJSON())}}toString(){return`Cause(${jt(this.reasons)})`}[Ft](){return this.toJSON()}[_t](e){return rn(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>vt(t,e.reasons[n]))}[nt](){return ft(this.reasons)}};const on=new WeakMap;var sn=class{[nn];annotations;_tag;constructor(e,t,n){if(this[nn]=nn,this._tag=e,t!==cn&&typeof n==`object`&&n&&t.size>0){let e=on.get(n);e&&(t=new Map([...e,...t])),on.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);if(e.mapUnsafe.forEach((e,r)=>{t?.overwrite!==!0&&n.has(r)||n.set(r,e)}),t?.overwrite!==!0&&n.size===this.annotations.size)return this;let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return Ae(this,arguments)}toString(){return jt(this)}[Ft](){return this.toString()}};const cn=new Map;var ln=class extends sn{constructor(e,t=cn){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${jt(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[_t](e){return _n(e)&&vt(this.error,e.error)&&vt(this.annotations,e.annotations)}[nt](){return ot(ut(this._tag))(ot(rt(this.error))(rt(this.annotations)))}};const un=e=>new an(e),Qee=(e,t)=>{let n=new Map,r=[];for(let i of e.concat(t)){let e=rt(i),t=n.get(e);if(t===void 0)n.set(e,[i]);else if(t.some(e=>vt(e,i)))continue;else t.push(i);r.push(i)}return r},dn=D(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new an(Qee(e.reasons,t.reasons));return vt(e,n)?e:n}),fn=(e,t)=>{let n=e.reasons.slice();for(let e of t.reasons)yn(e)&&!n.some(t=>yn(t)&&t.fiberId===e.fiberId&&t.annotations===e.annotations)&&n.push(e);return n.length===e.reasons.length?e:new an(n)},$ee=new an([]),pn=e=>new an([new ln(e)]);var mn=class extends sn{constructor(e,t=cn){super(`Die`,t,e),this.defect=e}toString(){return`Die(${jt(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[_t](e){return vn(e)&&vt(this.defect,e.defect)&&vt(this.annotations,e.annotations)}[nt](){return ot(ut(this._tag))(ot(rt(this.defect))(rt(this.annotations)))}};const hn=e=>new an([new mn(e)]),gn=D(e=>rn(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new an(e.reasons.map(e=>e.annotate(t,n)))),_n=e=>e._tag===`Fail`,vn=e=>e._tag===`Die`,yn=e=>e._tag===`Interrupt`;function ete(e){return Dn(`Effect.evaluate: Not implemented`)}const bn=e=>({...Zee,[Gt]:e.op,[qt]:e[qt]??ete,[Jt]:e[Jt],[Yt]:e[Yt],[Xt]:e[Xt]}),xn=e=>{let t=bn(e),n=function(e){this[Kt]=e};return n.prototype=t,function(e){return new n(e)}},Sn=e=>{let t={[Wt]:Wt,_tag:e.op,get[e.prop](){return this[Kt]},...bn(e),toString(){return`${e.op}(${jt(this[Kt])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[Kt]}},[_t](e){return en(e)&&e._tag===this._tag&&vt(this[Kt],e[Kt])},[nt](){return ot(ut(e.op),rt(this[Kt]))}},n=function(e){this[Kt]=e};return n.prototype=t,function(e){return new n(e)}},Cn=Sn({op:`Success`,prop:`value`,[qt](e){let t=e.getCont(Jt);return t?t[Jt](this[Kt],e,this):e.yieldWith(this)}}),wn={key:`effect/Cause/StackTrace`},tte={key:`effect/Cause/InterruptorStackTrace`},Tn=Sn({op:`Failure`,prop:`cause`,[qt](e){let t=this[Kt],n=!1;e.cache.stackFrame&&(t=gn(t,{mapUnsafe:new Map([[wn.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(Yt),i=e._interruptedCause;if(i&&e.interruptible){let a=!1;for(;r&&e.interruptible;)a||=Gt in r,r=e.getCont(Yt);a&&(t=un(t.reasons.filter(e=>e._tag!==`Fail`))),t=fn(t,i),n=!0}return r?r[Yt](t,e,n?void 0:this):e.yieldWith(n?Tn(t):this)}}),En=e=>Tn(pn(e)),Dn=e=>Tn(hn(e)),On=xn({op:`WithFiber`,[qt](e){return this[Kt](e)}}),nte=function(){class e extends globalThis.Error{}let t=bn({op:`YieldableError`,[qt](){return En(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),kn=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return class extends nte{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Yee(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),An=e=>{class t extends kn{_tag=e}return t.prototype.name=e,t},jn=`~effect/Cause/Done`,Mn=e=>et(e,jn),Nn={[jn]:jn,_tag:`Done`,value:void 0},Pn=e=>e===void 0?Nn:{[jn]:jn,_tag:`Done`,value:e},rte=En(Nn),ite=e=>e===void 0?rte:En(Pn(e)),Fn=e=>bn({op:e.label,[qt]:e.evaluate}),In=e=>(t,n)=>t===n||e(t,n),ate=(e,t)=>e===t,ote=()=>ate;function ste(e){return In((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e(t[r],n[r]))return!1;return!0})}const Ln=`~effect/Option`,Rn={[Ln]:{_A:e=>e},...Qt,[Symbol.iterator](){return new Bt(this)}},cte=Object.defineProperty(Object.assign(Object.create(Rn),{_tag:`Some`,_op:`Some`,[_t](e){return zn(e)&&Vn(e)&&vt(this.value,e.value)},[nt](){return ot(rt(this._tag))(rt(this.value))},toString(){return`some(${jt(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:It(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),lte=rt(`None`),ute=Object.assign(Object.create(Rn),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[_t](e){return zn(e)&&Bn(e)},[nt](){return lte},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),zn=e=>et(e,Ln),Bn=e=>e._tag===`None`,Vn=e=>e._tag===`Some`,dte=Object.create(ute),Hn=function(e){this.value=e};Hn.prototype=cte;const fte=e=>new Hn(e),Un=`~effect/Result`,Wn={[Un]:{_A:e=>e,_E:e=>e},...Qt,[Symbol.iterator](){return new Bt(this)}},pte=Object.assign(Object.create(Wn),{_tag:`Success`,_op:`Success`,[_t](e){return Gn(e)&&qn(e)&&vt(this.success,e.success)},[nt](){return ot(rt(this._tag))(rt(this.success))},toString(){return`success(${jt(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:It(this.success)}}}),mte=Object.assign(Object.create(Wn),{_tag:`Failure`,_op:`Failure`,[_t](e){return Gn(e)&&Kn(e)&&vt(this.failure,e.failure)},[nt](){return ot(rt(this._tag))(rt(this.failure))},toString(){return`failure(${jt(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:It(this.failure)}}}),Gn=e=>et(e,Un),Kn=e=>e._tag===`Failure`,qn=e=>e._tag===`Success`,Jn=function(e){this.failure=e};Jn.prototype=mte;const hte=e=>new Jn(e),Yn=function(e){this.success=e};Yn.prototype=pte;const gte=e=>new Yn(e);function Xn(e){return(t,n)=>t===n?0:e(t,n)}const Zn=Xn((e,t)=>e<t?-1:1),Qn=Xn((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t)?0:globalThis.Number.isNaN(e)?-1:globalThis.Number.isNaN(t)?1:e<t?-1:1),$n=D(2,(e,t)=>Xn((n,r)=>e(t(n),t(r)))),er=e=>D(2,(t,n)=>e(t,n)===-1),tr=e=>D(2,(t,n)=>e(t,n)===1),_te=e=>D(2,(t,n)=>e(t,n)!==1),vte=e=>D(2,(t,n)=>e(t,n)!==-1),yte=e=>D(2,(t,n)=>t===n||e(t,n)<1?t:n),O=()=>dte,nr=fte,rr=Bn,ir=Vn,ar=D(2,(e,{onNone:t,onSome:n})=>rr(e)?t():n(e.value)),or=D(2,(e,t)=>rr(e)?t():e.value),bte=D(2,(e,t)=>rr(e)?t():e),sr=e=>e==null?O():nr(e),cr=e=>e===void 0?O():nr(e),xte=or(mee),lr=or(Fe),ur=e=>(...t)=>{try{return nr(e(...t))}catch{return O()}},Ste=D(2,(e,t)=>{if(ir(e))return e.value;throw t()})(()=>Error(`getOrThrow called on a None`)),Cte=D(2,(e,t)=>rr(e)?O():nr(t(e.value))),dr=D(2,(e,t)=>rr(e)?O():t(e.value)),fr=D(2,(e,t)=>!rr(e)&&t(e.value)),pr=`~effect/Context/Service`,mr=function(){function e(){}let t=e;Object.setPrototypeOf(t,wte);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[gr]=gr,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&hr.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},wte={[pr]:pr,...Fn({label:`Service`,evaluate(e){return Cn(Mr(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return Dr(this,e)},use(e){return On(t=>e(Mr(t.context,this)))},useSync(e){return On(t=>Cn(e(Mr(t.context,this))))}},hr=new Set,gr=`~effect/Context/Reference`,_r=`~effect/Context`,vr=(e,t,n,r,i)=>{let a=Object.create(Ete);return a.cacheRoot=e??a,a.base=t,a.overlay=n,a.depth=r,a._flat=void 0,a.baseHits=0,a.maxDepth=i,a},yr=(e,t)=>{t&&(yr(e,t.parent),e.set(t.key,t.value))},br=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return yr(t,e.overlay),e._flat=t},Tte=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),vr(void 0,n,void 0,0,e.maxDepth)},xr=Symbol(),Sr=(e,t)=>{let n=e;for(let e=n.overlay;e;e=e.parent)if(e.key===t)return e.value;let r=n.base.get(t);return r===void 0&&!n.base.has(t)?xr:(n.overlay&&++n.baseHits>=n.base.size&&n.baseHits>=8&&(n.base=br(n),n.overlay=void 0,n.depth=0),r)},Cr=(e,t)=>{let n=t?.maxDepth;return vr(void 0,e,void 0,0,Number.isInteger(n)&&n>=0?n:8)},Ete={get mapUnsafe(){return br(this)},...Qt,[_r]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[_t](e){if(!wr(e))return!1;let t=this.mapUnsafe,n=e.mapUnsafe;if(t.size!==n.size)return!1;for(let[e,r]of t)if(!n.has(e)||!vt(r,n.get(e)))return!1;return!0},[nt](){return lt(this.mapUnsafe.size)}},Dte=(e,t)=>e.cacheRoot===t.cacheRoot,wr=e=>et(e,_r),Tr=e=>!!e[gr],Er=()=>Ote,Ote=Cr(new Map),Dr=(e,t)=>Cr(new Map([[e.key,t]])),Or=D(3,(e,t,n)=>kte(e,t.key,n)),kte=(e,t,n)=>{let r=e,i=hr.has(t)?void 0:r.cacheRoot;if(r.depth>=r.maxDepth){let e=new Map(r._flat??r.base);return r._flat||yr(e,r.overlay),e.set(t,n),vr(i,e,void 0,0,r.maxDepth)}return vr(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1,r.maxDepth)},kr=D(2,(e,t)=>Ar(e,t.key)),Ar=(e,t)=>{let n=Sr(e,t);return n===xr?void 0:n},jr=D(2,(e,t)=>{let n=Sr(e,t.key);if(n===xr){if(Tr(t))return Pr(t);throw Ate(t)}return n}),Mr=jr,Nr=`~effect/Context/defaultValue`,Pr=e=>Nr in e?e[Nr]:e[Nr]=e.defaultValue(),Ate=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(t.stack){let e=t.stack.split(`
6
+ `);e.splice(1,3),t.stack=e.join(`
7
+ `)}return t},jte=D(2,(e,t)=>{let n=Sr(e,t.key);return n===xr?Tr(t)?nr(Pr(t)):O():nr(n)}),Fr=D(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:Tte(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),Mte=(...e)=>{let t=new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return Cr(t)},Ir=mr,Lr=e=>e.length>0,Rr=e=>e>0?Math.floor(e):0,zr=gte,Br=hte,Nte=e=>{if(Ye(e))try{return zr(e())}catch(e){return Br(e)}try{return zr(e.try())}catch(t){return Br(e.catch(t))}},Vr=Kn,Hr=qn,Pte=D(2,(e,t)=>Vr(e)?Br(t(e.failure)):e),Fte=D(2,(e,{onFailure:t,onSuccess:n})=>Vr(e)?t(e.failure):n(e.success)),Ite=D(2,(e,t)=>{if(Hr(e))return e.success;throw t(e.failure)})(Me),Lte=D(2,(e,t)=>{let n=0;for(let r of e){let e=t(r,n);if(Je(e)){if(e)return nr(r)}else if(ir(e))return e;n++}return O()}),Ur=globalThis.Array,Wr=e=>Ur.isArray(e)?e:Ur.from(e),Gr=D(2,(e,{onEmpty:t,onNonEmpty:n})=>qr(e)?n(e):t()),Kr=D(2,(e,t)=>[...e,t]);Ur.isArray;const Rte=Lr,qr=Lr,Jr=D(2,(e,t)=>{let n=0;for(let r of e){if(t(r,n))return nr(n);n++}return O()}),zte=Lte,Bte=D(2,(e,t)=>{let n=Wr(e);for(let e=n.length-1;e>=0;e--){let r=n[e],i=t(r,e);if(typeof i==`boolean`){if(i)return nr(r)}else if(ir(i))return i}return O()}),Vte=D(2,(e,t)=>{let n=Ur.from(e);return n.sort(t),n}),Yr=()=>[],Xr=e=>[e],Zr=D(2,(e,t)=>e.map(t)),Qr=D(3,(e,t,n)=>Wr(e).reduce((e,t,r)=>n(e,t,r),t)),$r=`~effect/Duration`,ei=BigInt(0),ti=BigInt(1),ni=BigInt(2),Hte=BigInt(10),ri=BigInt(24),ii=BigInt(60),ai=BigInt(1e3),oi=BigInt(1e6),si=BigInt(1e9),Ute=BigInt(6e10),Wte=BigInt(36e11),Gte=BigInt(864e11),Kte=BigInt(6048e11),ci=e=>BigInt(Math.sign(e)*Math.round(Math.abs(e))),li=e=>Number.isInteger(e)?BigInt(e)*oi:ci(e*1e6),ui=e=>bi(Number.isFinite(e)?ci(e):e),qte=(e,t)=>{let n=Number(e);if(Number.isFinite(n))return n/t;let r=BigInt(t);return Number(e/r)+Number(e%r)/t},di=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=Hte**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t;return fi(r?-o:o,a)},fi=(e,t)=>{let n=e<ei?-e:e,r=n/t+(n%t*ni>=t?ti:ei);return e<ei?-r:r},pi=(e,t)=>{let n=Number(e)*t;if(!Number.isFinite(n))return bi(n);let r=di(e,BigInt(t)*oi);return bi(Number.isInteger(n)&&BigInt(n)*oi===r?n:r)},Jte=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,mi=e=>{switch(typeof e){case`number`:return Di(e);case`bigint`:return Ei(e);case`string`:{if(e===`Infinity`)return wi;if(e===`-Infinity`)return Ti;let t=Jte.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return Ei(di(r,ti));if(i===`micro`||i===`micros`)return Ei(di(r,ai));switch(i){case`milli`:case`millis`:return pi(r,1);case`second`:case`seconds`:return pi(r,1e3);case`minute`:case`minutes`:return pi(r,6e4);case`hour`:case`hours`:return pi(r,36e5);case`day`:case`days`:return pi(r,864e5);case`week`:case`weeks`:return pi(r,6048e5)}break}case`object`:{if(e===null)break;if($r in e)return e;if(Array.isArray(e)){if(e.length!==2||!e.every(qe))return _i(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return Ci;if(e[0]===-1/0||e[1]===-1/0)return Ti;if(e[0]===1/0||e[1]===1/0)return wi;let t=e[0]*1e9+e[1];return Number.isFinite(t)&&Number.isInteger(e[0])&&Number.isInteger(e[1])?bi(BigInt(e[0])*si+BigInt(e[1])):ui(t)}let t=e,n=0;if(t.weeks&&(n+=t.weeks*6048e5),t.days&&(n+=t.days*864e5),t.hours&&(n+=t.hours*36e5),t.minutes&&(n+=t.minutes*6e4),t.seconds&&(n+=t.seconds*1e3),t.milliseconds&&(n+=t.milliseconds),!t.microseconds&&!t.nanoseconds){if(!Number.isFinite(n))return bi(n);let e=gi(t);return e===void 0||BigInt(n)*oi===e?bi(n):bi(e)}let r=n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0),i=Number.isFinite(r)?gi(t):void 0;return i===void 0?ui(r):bi(i)}}return _i(e)},hi=e=>!e||Number.isInteger(e),gi=e=>{if(!hi(e.weeks)||!hi(e.days)||!hi(e.hours)||!hi(e.minutes)||!hi(e.seconds)||!hi(e.milliseconds)||!hi(e.microseconds)||!hi(e.nanoseconds))return;let t=ei;return e.weeks&&(t+=BigInt(e.weeks)*Kte),e.days&&(t+=BigInt(e.days)*Gte),e.hours&&(t+=BigInt(e.hours)*Wte),e.minutes&&(t+=BigInt(e.minutes)*Ute),e.seconds&&(t+=BigInt(e.seconds)*si),e.milliseconds&&(t+=BigInt(e.milliseconds)*oi),e.microseconds&&(t+=BigInt(e.microseconds)*ai),e.nanoseconds&&(t+=BigInt(e.nanoseconds)),t},_i=e=>{throw Error(`Invalid Input: ${e}`)},vi=ur(mi),yi={_tag:`Millis`,millis:0},Yte={_tag:`Infinity`},Xte={_tag:`NegativeInfinity`},Zte={[$r]:$r,[nt](){switch(this.value._tag){case`Millis`:return rt(li(this.value.millis));case`Nanos`:return rt(this.value.nanos);default:return Oee(this.value)}},[_t](e){return xi(e)&&ane(this,e)},toString(){switch(this.value._tag){case`Infinity`:return`Infinity`;case`NegativeInfinity`:return`-Infinity`;case`Nanos`:return`${this.value.nanos} nanos`;case`Millis`:return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,nanos:String(this.value.nanos)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`};case`NegativeInfinity`:return{_id:`Duration`,_tag:`NegativeInfinity`}}},[Ft](){return this.toJSON()},pipe(){return Ae(this,arguments)}},bi=e=>{let t=Object.create(Zte);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?yi:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:li(e)}:e>0?Yte:Xte:e===ei?yi:{_tag:`Nanos`,nanos:e},t},xi=e=>et(e,$r),Si=e=>e.value._tag!==`Infinity`&&e.value._tag!==`NegativeInfinity`,Qte=e=>{switch(e.value._tag){case`Millis`:return e.value.millis===0;case`Nanos`:return e.value.nanos===ei;case`Infinity`:case`NegativeInfinity`:return!1}},$te=e=>{switch(e.value._tag){case`Millis`:return e.value.millis<0;case`Nanos`:return e.value.nanos<ei;case`NegativeInfinity`:return!0;case`Infinity`:return!1}},ene=e=>{switch(e.value._tag){case`Infinity`:case`NegativeInfinity`:return wi;case`Millis`:return e.value.millis<0?bi(-e.value.millis):e;case`Nanos`:return e.value.nanos<ei?bi(-e.value.nanos):e}},Ci=bi(0),wi=bi(1/0),Ti=bi(-1/0),Ei=e=>bi(e),Di=e=>bi(e),Oi=e=>bi(e*1e3),ki=e=>bi(e*6e4),tne=e=>bi(e*36e5),Ai=e=>Mi(mi(e),{onMillis:Me,onNanos:e=>qte(e,1e6),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),ji=e=>{let t=mi(e);switch(t.value._tag){case`Infinity`:case`NegativeInfinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return li(t.value.millis)}},Mi=D(2,(e,t)=>{switch(e.value._tag){case`Millis`:return t.onMillis(e.value.millis);case`Nanos`:return t.onNanos(e.value.nanos);case`Infinity`:return t.onInfinity();case`NegativeInfinity`:return(t.onNegativeInfinity??t.onInfinity)()}}),Ni=D(3,(e,t,n)=>e.value._tag===`Infinity`||e.value._tag===`NegativeInfinity`||t.value._tag===`Infinity`||t.value._tag===`NegativeInfinity`?n.onInfinity(e,t):e.value._tag===`Millis`?t.value._tag===`Millis`?n.onMillis(e.value.millis,t.value.millis):n.onNanos(ji(e),t.value.nanos):n.onNanos(e.value.nanos,ji(t))),nne=Xn((e,t)=>Ni(e,t,{onMillis:(e,t)=>e<t?-1:+(e>t),onNanos:(e,t)=>e<t?-1:+(e>t),onInfinity:(e,t)=>e.value._tag===t.value._tag?0:e.value._tag===`Infinity`?1:e.value._tag===`NegativeInfinity`||t.value._tag===`Infinity`?-1:1})),rne=(e,t)=>Ni(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),Pi=yte(nne),ine=D(2,(e,t)=>Mi(e,{onMillis:e=>bi(e*t),onNanos:e=>{if(Number.isInteger(t))return bi(e*BigInt(t));let n=Number(e),r=n*t;if(!Number.isFinite(t)||Number.isSafeInteger(n)&&Math.abs(r)<=2**53-1)return ui(r);let i=t,a=ti;for(;!Number.isInteger(i);)i*=2,a*=ni;return bi(fi(e*BigInt(i),a))},onInfinity:()=>t>0?wi:t<0?Ti:Ci,onNegativeInfinity:()=>t>0?Ti:t<0?wi:Ci})),ane=D(2,(e,t)=>rne(e,t)),one=e=>{if(e.value._tag===`Infinity`)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};if(e.value._tag===`NegativeInfinity`)return{days:-1/0,hours:-1/0,minutes:-1/0,seconds:-1/0,millis:-1/0,nanos:-1/0};let t=ji(e),n=t<ei,r=n?-t:t,i=r/oi,a=i/ai,o=a/ii,s=o/ii,c=s/ri,l=n?-1:1;return{days:l*Number(c),hours:l*Number(s%ri),minutes:l*Number(o%ii),seconds:l*Number(a%ii),millis:l*Number(i%ai),nanos:l*Number(r%oi)}},Fi=e=>{if(e.value._tag===`Infinity`)return`Infinity`;if(e.value._tag===`NegativeInfinity`)return`-Infinity`;if(Qte(e))return`0`;if($te(e))return`-`+Fi(ene(e));let t=one(e),n=[];return t.days!==0&&n.push(`${t.days}d`),t.hours!==0&&n.push(`${t.hours}h`),t.minutes!==0&&n.push(`${t.minutes}m`),t.seconds!==0&&n.push(`${t.seconds}s`),t.millis!==0&&n.push(`${t.millis}ms`),t.nanos!==0&&n.push(`${t.nanos}ns`),n.join(` `)},Ii=Ir(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new zi}),Li=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},sne=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},Ri=e=>{try{return sne(e)}catch{return Li(e)}};var cne=class{buckets=[];scheduleTask(e,t){let n=this.buckets,r=n.length,i,a=0;for(;a<r&&!(n[a][0]>t);a++)i=n[a];i&&i[0]===t?i[1].push(e):a===r?n.push([t,[e]]):n.splice(a,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}},zi=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?Li:Ri)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new lne(this.setImmediate)}},lne=class{tasks=new cne;running=void 0;setImmediate;constructor(e=Ri){this.setImmediate=e}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running===void 0&&(this.running=this.setImmediate(this.afterScheduled))}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let n=e[t][1];for(let e=0;e<n.length;e++)n[e]()}}flush(){for(;this.tasks.buckets.length>0;)this.running!==void 0&&(this.running(),this.running=void 0),this.runTasks()}};const une=Ir(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),dne=Ir(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),fne=()=>new Proxy({},{get(e,t,n){return t===`$is`?tt:t===`$match`?pne:e=>({...e,_tag:t})}});function pne(){if(arguments.length===1){let e=arguments[0];return function(t){return e[t._tag](t)}}let e=arguments[0];return arguments[1][e._tag](e)}const mne=kn,Bi=An,Vi=`~effect/encoding/EncodingError`;var Hi=class extends Bi(`EncodingError`){[Vi]=Vi};const hne=e=>vne(typeof e==`string`?gne.encode(e):e),gne=new TextEncoder,_ne=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),vne=e=>{let t=Uint8Array.prototype.toHex;if(e.length>=6&&typeof t==`function`)return t.call(e);let n=``;for(let t=0;t<e.length;t++)n+=_ne[e[t]];return n},Ui=new Uint8Array(256).fill(255);for(let e=0;e<16;e++)Ui[`0123456789abcdef`.charCodeAt(e)]=e,Ui[`0123456789ABCDEF`.charCodeAt(e)]=e;const yne=Ir(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:Fe}),bne=Ir(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:Pe}),Wi=Ir(`effect/References/CurrentLogAnnotations`,{defaultValue:()=>({})}),xne=Ir(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Gi=Ir(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Sne=Ir(`effect/References/UnhandledLogLevel`,{defaultValue:()=>`Error`}),Cne=Ir(`effect/References/CurrentLogSpans`,{defaultValue:()=>[]});var wne=class extends sn{constructor(e,t=cn){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[_t](e){return yn(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[nt](){return ut(`${this._tag}:${this.fiberId}`)}};const Ki=e=>new an([new wne(e)]),Tne=e=>e.reasons.some(_n),qi=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return zr(n.error)}return Br(e)},Ji=e=>e.reasons.some(vn),Yi=e=>Ji(e)&&Tne(e)?un(e.reasons.map(e=>e._tag===`Fail`&&!Mn(e.error)?new mn(e.error,e.annotations):e)):e,Xi=e=>Ji(e)?Br(Yi(e)):qi(e),Zi=e=>e.reasons.some(yn),Ene=e=>e.reasons.length>0&&e.reasons.every(yn),Dne=e=>Cr(e.annotations),Qi=D(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>_n(e)?(n=!0,new ln(t(e.error),e.annotations)):e);return n?un(r):e}),One=e=>{let t;for(let n of e.reasons){if(n._tag===`Fail`)return n.error;n._tag===`Die`&&(t??=n)}return t===void 0?e.reasons.length>0?new globalThis.Error(`All fibers interrupted without error`):new globalThis.Error(`Empty cause`):t.defect},kne=(e,t)=>{let n=[],r=[];if(e.reasons.length===0)return n;let i=Rt();i!==0&&zt(1);try{for(let i of e.reasons){if(i._tag===`Interrupt`){r.push(i);continue}n.push($i(i._tag===`Die`?i.defect:i.error,i.annotations,t))}if(n.length===0){let e=Error(`The fiber was interrupted by:`);e.name=`InterruptCause`,e.stack=Nne(e,r);let i=new globalThis.Error(`All fibers interrupted without error`,{cause:e});i.name=`InterruptError`,i.stack=`${i.name}: ${i.message}`,n.push($i(i,r[0].annotations,t))}}finally{i!==0&&zt(i)}return n},$i=(e,t,n,r=new Set)=>{let i=typeof e,a;if(e&&i===`object`){r.add(e);let i=e.cause;if(a=new globalThis.Error(Ane(e),{cause:i!==void 0&&!r.has(i)?$i(i,void 0,void 0,r):void 0}),typeof e.name==`string`&&(a.name=e.name),typeof e.stack==`string`)a.stack=Mne(e.stack,a,t);else{let e=`${a.name}: ${a.message}`;a.stack=t?ea(e,t):e}n?.includeCauseInStack&&(a.stack=ra(a));for(let t of Object.keys(e))t in a||(a[t]=e[t])}else{a=new globalThis.Error(e?i===`string`?e:Pt(e):`Unknown error: ${e}`);let n=`${a.name}: ${a.message}`;a.stack=t?ea(n,t):n}return a},Ane=e=>{if(typeof e.message==`string`)return e.message;if(typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString)try{return e.toString()}catch{}return Pt(e)},jne=/\((.*)\)/g,Mne=(e,t,n)=>{let r=`${t.name}: ${t.message}`,i=(e.startsWith(r)?e.slice(r.length):e).split(`
8
+ `),a=[r];for(let e=1;e<i.length&&!/Generator\.next|~effect\/(?:Effect|Utils)/.test(i[e]);e++)a.push(i[e]);return n?ea(a.join(`
9
+ `),n):a.join(`
10
+ `)},ea=(e,t)=>{let n=t?.get(wn.key);return n&&(e=`${e}\n${ta(n)}`),e},Nne=(e,t)=>{let n=[`${e.name}: ${e.message}`];for(let e of t){let t=e.fiberId===void 0?`unknown`:`#${e.fiberId}`,r=e.annotations.get(tte.key);n.push(` at fiber (${t})`),r&&n.push(ta(r))}return n.join(`
11
+ `)},ta=e=>{let t=[],n=e,r=0;for(;n&&r<10;){let e=n.stack();if(e){let r=e.matchAll(jne),i=!1;for(let[,e]of r)i=!0,t.push(` at ${n.name} (${e})`);i||t.push(` at ${n.name} (${e.replace(/^at /,``)})`)}else t.push(` at ${n.name}`);n=n.parent,r++}return t.join(`
12
+ `)},na=e=>kne(e).map(ra).join(`
13
+ `),ra=e=>e.cause?`${e.stack} {\n${ia(e.cause,` `)}\n}`:e.stack,ia=(e,t)=>{let n=e.stack.split(`
14
+ `),r=`${t}[cause]: ${n[0]}`;for(let e=1,i=n.length;e<i;e++)r+=`\n${t}${n[e]}`;return e.cause&&(r+=` {\n${ia(e.cause,`${t} `)}\n${t}}`),r},aa=`~effect/Fiber`,Pne={_A:Me,_E:Me},Fne={id:0},oa=(()=>{try{return globalThis.process?.getBuiltinModule?.(`node:async_hooks`)?.AsyncResource}catch{return}})(),sa=()=>oa===void 0?void 0:new oa(`effect/Fiber`),ca=()=>globalThis[kt];var la=class{constructor(e,t=!0){this.setContext(e),this.id=++Fne.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._autoYielded=!1,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[aa](){return Pne}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return Mr(this.context,e)}addObserver(e){return this._exit?(e(this._exit),Ie):(this._observers===void 0?this._observers=[e]:this._observers.push(e),()=>this.removeObserver(e))}removeObserver(e){if(this._exit||this._observers===void 0)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let n=Ki(e);this.cache.stackFrame&&(n=gn(n,Dr(wn,this.cache.stackFrame))),t&&(n=gn(n,t)),this._interruptedCause=this._interruptedCause?fn(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(ga(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._asyncContext!==void 0){let t=this._asyncContext;this._asyncContext=void 0;try{return t.runInAsyncScope(this.evaluate,this,e)}finally{t.emitDestroy()}}else if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===Zt){this._asyncContext=sa();return}let n=ua.interruptChildren&&ua.interruptChildren(this);if(n!==void 0)return this.evaluate(Ua(n,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&=(this._parent._children?.delete(this),void 0),this._observers!==void 0){let e=this._observers;this._observers=void 0;for(let n=0;n<e.length;n++)e[n](t)}this._stack.length=0,this._children=void 0,this.context=Er();let r=this.cache;(r.span!==void 0||r.stackFrame!==void 0)&&(this.cache={...r,span:void 0,stackFrame:void 0})}runLoop(e){let t=globalThis[kt];globalThis[kt]=this;let n=this._running;this._running=!0;let r=!1,i=this._autoYielded;this._autoYielded=!1;let a=e;this.currentOpCount=+!!i;try{for(;;)try{this._deferredInterrupt&&(this._deferredInterrupt=!1,a=ga(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!i&&!r&&!e.preventYield&&e.scheduler.shouldYield(this)?(r=!0,a=this.yieldNow(a,0,!0)):(i=!1,a=e.tracerContext?e.tracerContext(a,this):a[qt](this)),a===Zt){let e=this._yielded;if(Wt in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return Zt}}catch(e){if(!et(a,qt))return Dn(`Fiber.runLoop: Not a valid effect: ${String(a)}`);a=Dn(e)}}finally{this._running=n,globalThis[kt]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,Lne;for(;;){let t=this._stack.pop();if(!t)return;let n=t[Xt];if(n!==void 0){let r=n.call(t,this);if(r)return r[e]=r,r}if(t[e])return t}}succeedWith(e){if(!(++this.currentOpCount&Rne-1))return Cn(e);let t=this.getCont(Jt);return t?t[Jt](e,this):this.yieldWith(Cn(e))}yieldWith(e){return this._yielded=e,Zt}yieldNow(e,t=0,n=!1){let r=!1;return this.currentDispatcher.scheduleTask(()=>{r||(this._autoYielded=n,this.evaluate(e))},t),this.yieldWith(()=>{r=!0})}children(){return this._children??=new Set}pipe(){return Ae(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Dte(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=Ine(e);this.cache?.scheduler!==r.scheduler&&(this._dispatcher=void 0),this.cache=r}get currentSpanLocal(){let e=this.cache.span;return e?._tag===`Span`?e:void 0}};const Ine=e=>{let t=Ar(e,`effect/Tracer`);return{scheduler:Mr(e,Ii),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:Mr(e,bne),span:Ar(e,`effect/Tracer/ParentSpan`),logLevel:Mr(e,xne),minimumLogLevel:Mr(e,Gi),stackFrame:Mr(e,yne),runtimeMetrics:Ar(e,`effect/Metric/FiberRuntimeMetrics`),maxOpsBeforeYield:Mr(e,une),preventYield:Mr(e,dne)}},Lne={[Jt](e,t){return ga(t._interruptedCause)},[Yt](e,t){return ga(t._interruptedCause)}},Rne=32,ua={interruptChildren:void 0},da=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(tte.key,e.cache.stackFrame),Cr(t)},zne=e=>{if(e._children!==void 0&&e._children.size!==0)return ma(e._children)},Bne=e=>{let t=e;return t._exit?ha(t._exit):wa(n=>t._exit?n(ha(t._exit)):va(e.addObserver(e=>n(ha(e)))))},Vne=e=>wa(t=>{let n=e[Symbol.iterator](),r=[],i;function a(){let e=n.next();for(;!e.done;){if(e.value._exit){r.push(e.value._exit),e=n.next();continue}i=e.value.addObserver(e=>{r.push(e),a()});return}t(ha(r))}return a(),va(()=>i?.())}),fa=e=>{let t=e;return t._exit?t._exit:wa(n=>t._exit?n(t._exit):va(e.addObserver(n)))},pa=e=>On(t=>Hne(e,t.id)),Hne=D(e=>et(e[0],aa),(e,t,n)=>On(r=>{let i=da(r);return i=i&&n?Fr(i,n):i??n,e.interruptUnsafe(t,i),Va(Bne(e))})),ma=e=>On(t=>{let n=da(t),r=Yr();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return Va(Vne(r))}),ha=Cn,ga=Tn,_a=En,va=xn({op:`Sync`,[qt](e){let t=this[Kt],n=t(),r=e.getCont(Jt);return r?r[Jt](n,e):e.yieldWith(Cn(n))}}),ya=xn({op:`Suspend`,[qt](e){let t=this[Kt];return t()}}),Une=Fte({onFailure:_a,onSuccess:ha}),ba=xn({op:`Yield`,[qt](e){return e.yieldNow(qa,this[Kt]??0)}})(0),Wne=ha(O()),Gne=e=>ya(()=>ga(e())),xa=e=>Dn(e),Kne=e=>ya(()=>_a(e())),Sa=ha(void 0),qne=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new ls(e,`An error occurred in Effect.try`):e.catch;return ya(()=>{try{return ha(t())}catch(e){return _a(n(e))}})},Jne=e=>Ca(function(t,n){e(n).then(e=>t(ha(e)),e=>t(xa(e)))},e.length!==0),Yne=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new ls(e,`An error occurred in Effect.tryPromise`):e.catch;return Ca(function(e,r){let i=e=>ya(()=>{try{return _a(Vt(()=>n(e)))}catch(e){return xa(e)}});try{t(r).then(t=>e(ha(t)),t=>e(i(t)))}catch(t){e(i(t))}},t.length!==0)},Ca=function(){let e=bn({op:`Async`,[qt](e){let t=!1,n=!1,r=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,r=>{t||(t=!0,n?e.evaluate(r):n=r)},r?.signal);return n===!1?(n=!0,e.yieldWith(()=>{t=!0}),r===void 0&&i===void 0||e._stack.push(Xne(()=>(t=!0,r?.abort(),i??qa))),Zt):n}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),Xne=xn({op:`AsyncFinalizer`,[Xt](e){e.interruptible&&(e.interruptible=!1,e._stack.push(Ro))},[Yt](e,t){return Zi(e)?Ua(xo(Tn(e),this[Kt]()),()=>ga(e)):ga(e)}}),wa=e=>Ca(e,e.length>=2),Ta=wa(Ie),Zne=(...e)=>{if(e.length===1){let t=e[0];return ya(()=>Aa(t()))}let[t,n]=e;return ya(()=>Aa(n.call(t.self)))},Ea=(e,t)=>typeof e==`function`?e:t.shift().bind(e.self),Da=(e,...t)=>{let n=Ea(e,t),r=t.length===0?function(){return ya(()=>Aa(n.apply(this,arguments)))}:function(){let e=ya(()=>Aa(n.apply(this,arguments)));for(let n=0;n<t.length;n++)e=t[n](e,...arguments);return e};return Oa(n.length,r)},Oa=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),Qne=(e,...t)=>{let n=Ea(e,t);return Oa(n.length,t.length===0?function(){return ka(()=>n.apply(this,arguments))}:function(){let e=ka(()=>n.apply(this,arguments));for(let n of t)e=n(e,...arguments);return e})},ka=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return ha(r.value);let i=r.value;if(i&&i._tag===`Success`){n=i.value;continue}if(i&&i._tag===`Failure`)return r.value;{let n=!0;return ya(()=>n?(n=!1,Ua(r.value,e=>Aa(t,e))):ya(()=>Aa(e())))}}}catch(e){return xa(e)}},Aa=function(){let e=bn({op:`Iterator`,[Jt](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return ha(r.value);if(!Wa(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[qt](e){return this[Jt](this.initial,e)}}),t=function(e,t){this.iterator=e,this.initial=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),ja=D(2,(e,t)=>new Na(e,Pa,ha(t))),Ma=function(e){return e._stack.push(this),this[Kt]},$ne=bn({op:`OnSuccess`,[qt]:Ma}),Na=function(e,t,n){this[Kt]=e,this[Jt]=t,this.payload=n};Na.prototype=$ne;const Pa=function(){return this.payload},Fa=function(e,t){return t.succeedWith(this.payload)},Ia=(()=>{let e=Rt();if(e===0)return!1;let t=`~effect/Effect/stackProbe`,n={[t]:function(){return Error()}};zt(1);let r=n[t]();return zt(e),r.stack?.includes(`[as `+t+`]`)===!0})(),ere=function(e,t){let n=this.payload;return t.succeedWith(Ia?n(e):Vt(()=>n(e)))},La=function(e){let t=this.payload;return t(e)},tre=function(e){let t=this.payload;return new Na(t(e),Fa,e)},nre=function(e){return new Na(this.payload,Fa,e)},Ra=e=>Ga(e,nr),za=D(2,(e,t)=>new Na(e,$t(t)?Pa:La,t)),Ba=D(2,(e,t)=>new Na(e,$t(t)?nre:tre,t)),Va=e=>new Na(e,Pa,qa),rre=(e,t)=>On(n=>{let r=new Set;return Po(n,()=>r.size===0?void 0:ma(r)),wa(i=>{let a=!1,o=0;for(let s of e){if(a)break;let e=o++,c=qo(n,s,!0,!0,!1);r.add(c),c.addObserver(o=>{r.delete(c);let s=!a;a=!0,i(o),s&&(ire(r,n),t?.onWinner?.({fiber:c,index:e,parentFiber:n}))})}})}),ire=(e,t)=>{let n=da(t);for(let r of e)r.interruptUnsafe(t.id,n)},Ha=D(e=>$t(e[1]),(e,t,n)=>rre([e,t],n)),Ua=D(2,(e,t)=>new Na(e,La,t)),Wa=e=>e[Wt]!==void 0,are=D(2,(e,t)=>Wa(e)?e._tag===`Success`?t(e.value):e:Ua(e,t)),ore=e=>Ua(e,Me),Ga=D(2,(e,t)=>new Na(e,ere,t)),sre=D(2,(e,t)=>Wa(e)?pre(e,t):Ga(e,t)),cre=D(2,(e,t)=>Wa(e)?mre(e,t):ao(e,t)),lre=e=>Tn(Ki(e)),Ka=e=>e._tag===`Success`,ure=e=>e._tag===`Failure`,dre=e=>e._tag===`Failure`?zr(e.cause):Br(e),fre=e=>e._tag===`Failure`&&Zi(e.cause),qa=Cn(void 0),pre=D(2,(e,t)=>e._tag===`Success`?Cn(t(e.value)):e),mre=D(2,(e,t)=>e._tag===`Success`?e:Tn(Qi(e.cause,t))),hre=D(2,(e,t)=>Ka(e)?t:e),gre=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?qa:Tn(un(t))},_re=e=>On(t=>ha(jte(t.context,e))),Ja=D(2,(e,t)=>On(n=>{let r=n.context,i=t(r);return r===i?e:(n.setContext(i),Po(n,()=>{n.setContext(r)}),e)})),vre=()=>yre,yre=On(e=>ha(e.context)),Ya=e=>On(t=>e(t.context)),Xa=D(2,(e,t)=>Wa(e)?e:Ja(e,Fr(t))),Za=function(){return arguments.length===1?D(2,(e,t)=>Qa(e,arguments[0],t)):D(3,(e,t,n)=>Qa(e,t,n)).apply(this,arguments)},Qa=(e,t,n)=>Ja(e,Or(t,n)),bre=D(e=>$t(e[1]),(e,t,n,r)=>r?.concurrent?Ga(Bo([e,t],{concurrency:2}),([e,t])=>n(e,t)):Ua(e,e=>Ga(t,t=>n(e,t)))),xre=D(e=>$t(e[0]),(e,t)=>Vo({while:Pe,body:Ne(t?.disableYield?e:Ua(e,e=>ba)),step:Ie})),$a=D(2,(e,t)=>new eo(e,t.length===1?t:e=>t(e))),Sre=bn({op:`OnFailure`,[qt]:Ma}),eo=function(e,t){this[Kt]=e,this[Yt]=t};eo.prototype=Sre;const to=D(3,(e,t,n)=>$a(e,e=>{let r=t(e);return Vr(r)?ga(r.failure):n(r.success,e)})),no=D(2,(e,t)=>to(e,Xi,e=>t(e))),Cre=D(2,(e,t)=>$a(e,e=>za(t(e),ga(e)))),wre=D(3,(e,t,n)=>$a(e,e=>{let r=t(e);return Vr(r)?ga(e):za(n(r.success,e),ga(e))})),Tre=D(2,(e,t)=>wre(e,qi,e=>t(e))),ro=D(e=>$t(e[0]),(e,t,n,r)=>$a(e,e=>{let i=Xi(e);return Vr(i)?ga(i.failure):t(i.success)?n(i.success):r?r(i.success):ga(e)})),io=D(e=>$t(e[0]),(e,t,n,r)=>$a(e,e=>{let i=Xi(e);if(Vr(i))return ga(i.failure);let a=t(i.success);return Vr(a)?r?r(a.failure):ga(e):n(a.success)})),Ere=D(e=>$t(e[0]),(e,t,n,r)=>{let i=Array.isArray(t)?e=>et(e,`_tag`)&&t.includes(e._tag):tt(t);return ro(e,i,n,r)}),Dre=D(e=>$t(e[0]),(e,t,n)=>{let r;return io(e,e=>(r??=Object.keys(t),et(e,`_tag`)&&Ke(e._tag)&&r.includes(e._tag)?zr(e):Br(e)),e=>t[e._tag](e),n)}),Ore=D(e=>$t(e[0]),(e,t,n,r,i)=>ro(e,e=>tt(e,t)&&et(e,`reason`)&&(i!==void 0||tt(e.reason,n)),e=>{let t=e.reason;return tt(t,n)?r(t,e):i?i(t,e):_a(e)})),ao=D(2,(e,t)=>$a(e,e=>ga(Qi(e,t)))),kre=e=>no(e,xa),oo=e=>e===`Unhandled`?(...e)=>On(t=>{let n=t.getRef(Sne);return n===void 0?Sa:fs(n)(...e)}):fs(e===!0?void 0:e),Are=D(e=>$t(e[0]),(e,t)=>{if(!t?.log)return uo(e,{onFailure:e=>Sa,onSuccess:e=>Sa});let n=oo(t.log);return co(e,{onFailure(e){let r=Xi(e);return Vr(r)?ga(r.failure):t.message===void 0?n(e):n(t.message,e)},onSuccess:e=>Sa})}),jre=D(e=>$t(e[0]),(e,t)=>{if(!t?.log)return co(e,{onFailure:e=>Sa,onSuccess:e=>Sa});let n=oo(t.log);return co(e,{onFailure:e=>t.message===void 0?n(e):n(t.message,e),onSuccess:e=>Sa})}),so=e=>Fre(e,{onFailure:Br,onSuccess:zr}),co=D(2,(e,t)=>new lo(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Mre=bn({op:`OnSuccessAndFailure`,[qt]:Ma}),lo=function(e,t,n){this[Kt]=e,this[Jt]=t,this[Yt]=n};lo.prototype=Mre;const Nre=function(e,t){let n=this.payload;return t.succeedWith(Ia?n.onSuccess(e):Vt(()=>n.onSuccess(e)))},Pre=((e,t)=>{let n=bn({op:e,[qt]:Ma,[Jt]:Nre,[Yt]:t}),r=function(e,t){this[Kt]=e,this.payload=t};return r.prototype=n,r})(`Match`,function(e,t){let n=Xi(e);if(Vr(n))return ga(n.failure);let r=this.payload;return t.succeedWith(Ia?r.onFailure(n.success):Vt(()=>r.onFailure(n.success)))}),uo=D(2,(e,t)=>co(e,{onFailure:e=>{let n=Xi(e);return Vr(n)?ga(n.failure):t.onFailure(n.success)},onSuccess:t.onSuccess})),fo=D(2,(e,t)=>new Pre(e,t)),Fre=D(2,(e,t)=>{if(Wa(e)){if(e._tag===`Success`)return Cn(t.onSuccess(e.value));let n=Xi(e.cause);return Vr(n)?Tn(n.failure):Cn(t.onFailure(n.success))}return fo(e,t)}),po=e=>Wa(e)?Cn(e):Ire(e),Ire=xn({op:`Exit`,[qt](e){return e._stack.push(this),this[Kt]},[Jt](e,t,n){return t.succeedWith(n??Cn(e))},[Yt](e,t,n){return t.succeedWith(n??Tn(e))}}),mo=D(2,(e,t)=>Ua(zre(e,t.duration),e=>rr(e)?t.orElse():ha(e.value))),Lre=e=>new gie(`Operation timed out after '${Fi(e)}'`),Rre=D(2,(e,t)=>{let n=mi(t);return mo(e,{duration:n,orElse:()=>_a(Lre(n))})}),zre=D(2,(e,t)=>Ha(Ra(e),ja(is(t),O()))),ho=`~effect/Scope`,go=`~effect/Scope/Closeable`,_o=mr(`effect/Scope`),vo=(e,t)=>On(n=>(tie(n),yo(e,t)??Sa)),yo=(e,t)=>{let n=e.state;if(n._tag===`Closed`||(e.state={_tag:`Closed`,exit:t},e.parent!==void 0&&Eo(e.parent,e),n._tag===`Empty`))return;if(n.finalizer!==void 0)return bo(n.finalizer,t);let r=n.finalizers;return r.size===1?bo(r.values().next().value,t):Bre(e,r,t)},bo=(e,t)=>{try{return e(t)}catch(e){return Dn(e)}},xo=(e,t)=>Ka(e)?t:$a(t,t=>ga(Yi(dn(e.cause,t)))),Bre=Da(function*(e,t,n){let r=[],i=[],a=Array.from(t),o=ca();for(let t=a.length-1;t>=0;t--){let[s,c]=a[t];e.strategy===`sequential`?r.push(yield*po(bo(c,n))):s!==o&&i.push(qo(o,bo(c,n),!0,!0,`inherit`))}return i.length>0&&(r=yield*Vne(i)),yield*gre(r)}),Vre=(e,t)=>va(()=>So(e,t)),So=(e,t)=>{let n=Oo(t,e);return e.state._tag===`Closed`?(n.state=e.state,n):(To(e,n,e=>vo(n,e)),n)},Co=(e,t)=>ya(()=>e.state._tag===`Closed`?t(e.state.exit):(To(e,{},t),Sa)),wo=(e,t)=>Co(e,Ne(t)),To=(e,t,n)=>{if(e.state._tag===`Empty`)e.state={_tag:`Open`,finalizerKey:t,finalizer:n,finalizers:void 0};else if(e.state._tag===`Open`){let r=e.state;r.finalizer===void 0?r.finalizers.set(t,n):(r.finalizers=new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0,r.finalizers.set(t,n))}},Eo=(e,t)=>{if(e.state._tag!==`Open`)return;let n=e.state;n.finalizerKey===t?e.state=ko:n.finalizers!==void 0&&(n.finalizers.delete(t),n.finalizers.size===0&&(e.state=ko))},Do=e=>Oo(e,void 0),Oo=(e=`sequential`,t)=>({[go]:go,[ho]:ho,strategy:e,parent:t,state:ko}),ko={_tag:`Empty`},Ao=_o,Hre=Za(_o),Ure=e=>On(t=>{let n=t.context,r=Do();return t.setContext(Or(t.context,_o,r)),Po(t,e=>(t.setContext(n),yo(r,e))),e}),jo=e=>ya(()=>{let t=Do();return Fo(e(t),e=>ya(()=>yo(t,e)??Sa))}),Wre=(e,t,n)=>Ya(r=>zo(i=>Ua(Ao,a=>Ba(n?.interruptible?i(e):e,e=>Co(a,n=>Xa(t(e,n),r)))))),Gre=e=>Ua(Ao,t=>Ya(n=>Co(t,t=>Xa(e(t),n)))),Mo=function(){let e=bn({op:`OnExit`,[qt](e){return e._stack.push(this),this.effect},[Xt](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(Ro),e.interruptible=!1)},[Jt](e,t,n){n??=Cn(e);let r;try{r=this.onExit(n)}catch(e){r=Dn(e)}return r?Ua(r,e=>n):n},[Yt](e,t,n){n??=Tn(e);let r;try{r=this.onExit(n)}catch(e){r=Dn(e)}return r?Ua(xo(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,t}(),No=(e,t,n)=>new Mo(e,t,n),Po=(e,t)=>{e._stack.push(new Mo(void 0,t,void 0))},Fo=D(2,No),Kre=D(2,(e,t)=>Fo(e,e=>t)),qre=D(3,(e,t,n)=>Fo(e,e=>{let r=t(e);return Vr(r)?Sa:n(r.success,e)})),Jre=D(2,(e,t)=>qre(e,dre,t)),Yre=Ne(1/0),Xre=(e,t)=>{let n=0,r,i,a=(e,t)=>(t.awaiters++,Po(e,()=>{if(!(--t.awaiters>0||t.done))return i===t&&(i=void 0),pa(t.fiber)}),fa(t.fiber));return[On(o=>{if(i!==void 0)return o===i.fiber?fa(i.fiber):a(o,i);if(r!==void 0&&(n===1/0||o.getRef($o).currentTimeMillisUnsafe()<n))return r;r=void 0;let s=o.getRef($o),c={fiber:new la(o.context),awaiters:0,done:!1};i=c;let l=a(o,c);return c.fiber.evaluate(No(e,e=>{if(c.done=!0,i!==c||(i=void 0,fre(e)))return;let a=t(e);n=a===1/0?1/0:s.currentTimeMillisUnsafe()+a,r=e})),c.fiber._exit??l}),va(()=>{i=void 0,r=void 0})]},Zre=e=>va(()=>Xre(e,Yre)[0]),Qre=On(e=>ga(Ki(e.id))),Io=e=>On(t=>t.interruptible?(t.interruptible=!1,t._stack.push(Ro),e):e),Lo=xn({op:`SetInterruptible`,[Xt](e){if(e.interruptible=this[Kt],e._interruptedCause&&e.interruptible)return()=>ga(e._interruptedCause)}}),Ro=Lo(!0),$re=Lo(!1),eie=e=>{if(e.interruptible=!0,e._stack.push($re),e._interruptedCause)return ga(e._interruptedCause)},tie=e=>{let t=e;t.interruptible&&(t.interruptible=!1,t._stack.push(Ro))},nie=e=>On(t=>t.interruptible?e:eie(t)??e),zo=e=>On(t=>t.interruptible?(t.interruptible=!1,t._stack.push(Ro),e(nie)):e(Me)),Bo=(e,t)=>Tee(e)?t?.mode===`result`?Ho(e,so,t):Ho(e,Me,t):t?.discard?t.mode===`result`?Ho(Object.values(e),so,t):Ho(Object.values(e),Me,t):ya(()=>Ga(Ho(Object.entries(e),([e,n])=>Ga(t?.mode===`result`?so(n):n,t=>[e,t]),{concurrency:t?.concurrency}),Object.fromEntries)),Vo=xn({op:`While`,[Jt](e,t){return this[Kt].step(e),this[Kt].while()?(t._stack.push(this),this[Kt].body()):qa},[qt](e){return this[Kt].while()?(e._stack.push(this),this[Kt].body()):qa}}),Ho=D(e=>typeof e[1]==`function`,(e,t,n)=>ya(()=>{let r=Uo(n?.concurrency);if(r===1)return rie(e,t,n);let i=Wr(e),a=i.length;if(a===0)return n?.discard?Sa:ha([]);let o=n?.discard?void 0:Array(a),s=iie({f:t,out:o},i,{concurrency:r});return s?ja(s,o):ha(o)})),rie=(e,t,n)=>ya(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return ja(Vo({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),Uo=e=>e===`unbounded`?1/0:Math.max(1,e??1),Wo=()=>e=>{let t=e.onItem,n=e.step,r=(e,t,r,a,o)=>Ua(po(o),o=>n(e,t[r],o,r)??i(e,t,r+1,a)??Sa),i=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!Wa(c))return r(e,i,a,o,c);let l=n(e,s,c,a);if(l)return l._tag===`Failure`?l:void 0}};return i},Go=e=>{let t=e.onItem,n=e.step;return(e,r,i)=>{let a=0,o=i.end??r.length,s=i.concurrency,c=!1,l,u,d,f,p,m=e=>{let t=Dn(e);return f=t,c=!0,u&&u.size>0?Ua(Io(ma(Array.from(u))),()=>f??t):t},h=()=>{let i=!1;for(;!f&&a<o;a++){let o=r[a],g=p??t(e,o,a);if(Wa(g)){if(f=n(e,o,g,a),f)break}else if(l){p=void 0;let t=qo(l,g,!0,!0,`inherit`);if(t._exit){if(f=n(e,o,t._exit,a),f)break;continue}u.add(t);let r=a;if(t.addObserver(a=>{u.delete(t);try{if(f){if(a._tag===`Failure`){let e=a.cause.reasons.filter(e=>e._tag!==`Interrupt`);if(e.length>0){let t=un(e);f=Tn(f._tag===`Failure`?Yi(dn(f.cause,t)):t)}}}else{let t=n(e,o,a,r);t&&(f=t,h())}if(i){let e=h();e&&d(e)}else c&&u.size===0&&d(f??Sa)}catch(e){d(m(e))}}),u.size<s)continue;i=!0,a++;return}else return wa(e=>{l=ca(),u=new Set,p=g,d=e;let t;try{t=h()}catch(t){return e(m(t))}return t?e(t):ya(()=>(f??=qa,Ua(u?ma(u):Sa,()=>f?._tag===`Failure`?f:Sa)))})}if(c=!0,f){if(u&&u.size>0){let e=da(l);u.forEach(t=>t.interruptUnsafe(l.id,e));return}if(d||f._tag===`Failure`)return f}else if(d){if(u)u.size===0&&d(Sa);else return qa}};return h()}},Ko=()=>e=>Go(e),iie=Go({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag===`Failure`)return n;e.out&&(e.out[r]=n.value)}}),aie=D(e=>$t(e[0]),(e,t)=>On(n=>(Oie(),ha(qo(n,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),qo=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new la(a.context,o);return r||(a.children().add(s),s._parent=a),n?s.evaluate(t):(s._asyncContext=sa(),a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),s},Jo=e=>()=>On(t=>t===e?Sa:pa(e)),Yo=D(e=>$t(e[0]),(e,t,n)=>On(r=>{let i=t.state._tag===`Closed`?new la(r.context):qo(r,e,n?.startImmediately,!0,n?.uninterruptible);return i._exit||(t.state._tag===`Closed`?i.interruptUnsafe(r.id,da(r)):(To(t,i,Jo(i)),i.addObserver(()=>Eo(t,i)))),ha(i)})),oie=D(e=>$t(e[0]),(e,t)=>Ua(Ao,n=>Yo(e,n,t))),Xo=e=>(t,n)=>{let r=new la(n?.scheduler?Or(e,Ii,n.scheduler):e,n?.uninterruptible!==!0);if(r.evaluate(t),r._exit)return r;if(n?.signal){if(n.signal.aborted)r.interruptUnsafe();else{let e=()=>r.interruptUnsafe();n.signal.addEventListener(`abort`,e,{once:!0}),r.addObserver(()=>n.signal.removeEventListener(`abort`,e))}}return n?.onFiberStart&&n.onFiberStart(r),r},sie=D(2,(e,t)=>e._exit?e:t.state._tag===`Closed`?(e.interruptUnsafe(e.id),e):(Eo(t,e),To(t,e,Jo(e)),e.addObserver(()=>Eo(t,e)),e)),cie=Xo(Er()),lie=(e=>{let t=Xo(e);return e=>{if(Wa(e))return e;let n=new zi(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??Dn(new vie(r))}})(Er()),Zo=ha(!0),Qo=ha(!1);var uie=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return Zo;if(this.scheduled===void 0)this.scheduled=this.waiters,e.currentDispatcher.scheduleTask(this.flushScheduled,0);else for(let e=0;e<this.waiters.length;e++)this.scheduled.push(this.waiters[e]);return this.waiters=[],Zo}flushScheduled=()=>{if(this.scheduled===void 0)return;let e=this.scheduled;this.scheduled=void 0;for(let t=0;t<e.length;t++)e[t](qa)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](qa)}open=On(e=>this._isOpen?Qo:(this._isOpen=!0,this.scheduleUnsafe(e)));release=On(e=>this._isOpen?Qo:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=wa(e=>this._isOpen?e(Sa):(this.waiters.push(e),va(()=>{let t=this.waiters.indexOf(e);t===-1?this.scheduled!==void 0&&(t=this.scheduled.indexOf(e),t!==-1&&this.scheduled.splice(t,1)):this.waiters.splice(t,1)})));closeUnsafe(){return this._isOpen?(this._isOpen=!1,!0):!1}close=va(()=>this.closeUnsafe());whenOpen=e=>Ua(this.await,()=>e);isOpen(){return this._isOpen}};const die=e=>new uie(e??!1),$o=Ir(`effect/Clock`,{defaultValue:()=>new fie}),es=2**31-1;var fie=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=va(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return pie()}currentTimeNanos=va(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return ns()}monotonicTimeNanos=va(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(Ai(e))}sleepMillis(e){return e<=0?ba:Number.isFinite(e)?wa(t=>{let n=e>es?this.sleepMillis(e-es):Sa,r=setTimeout(()=>t(n),Math.min(e,es));return va(()=>clearTimeout(r))}):Ta}};const ts=BigInt(1e6),ns=function(){let e=globalThis.process?.hrtime;if(typeof e?.bigint==`function`)return()=>e.bigint();if(typeof performance<`u`&&typeof performance.now==`function`)return()=>BigInt(Math.round(performance.now()*1e6));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*ts;return e>t&&(t=e),t}}(),pie=function(){let e=BigInt(1e9),t;return()=>{let n=ns(),r=BigInt(Date.now())*ts;if(t===void 0)t=r-n;else{let i=t+n;(r>i?r-i:i-r)>e&&(t=r-n)}return t+n}}(),rs=e=>On(t=>e(t.getRef($o))),is=e=>rs(t=>t.sleep(mi(e))),mie=rs(e=>e.currentTimeMillis),hie=rs(e=>e.monotonicTimeNanos),as=`~effect/Cause/TimeoutError`;var gie=class extends An(`TimeoutError`){[as]=as;constructor(e){super({message:e})}};const os=`~effect/Cause/IllegalArgumentError`;var _ie=class extends An(`IllegalArgumentError`){[os]=os;constructor(e){super({message:e})}};const ss=`~effect/Cause/AsyncFiberError`;var vie=class extends An(`AsyncFiberError`){[ss]=ss;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}};const cs=`~effect/Cause/UnknownError`;var ls=class extends An(`UnknownError`){[cs]=cs;constructor(e,t){super({message:t,cause:e})}};const us=Ir(`effect/Console`,{defaultValue:()=>globalThis.console}),yie=tr($n(Qn,e=>{switch(e){case`All`:return-(2**53-1);case`Fatal`:return 5e4;case`Error`:return 4e4;case`Warn`:return 3e4;case`Info`:return 2e4;case`Debug`:return 1e4;case`Trace`:return 0;case`None`:return 2**53-1}})),bie=Ir(`effect/Logger/CurrentLoggers`,{defaultValue:()=>new Set([Eie,Die])}),xie=Ir(`effect/Logger/LogToStderr`,{defaultValue:pee}),Sie={"~effect/Logger":{_Message:Me,_Output:Me},pipe(){return Ae(this,arguments)}},ds=e=>{let t=Object.create(Sie);return t.log=e,t},Cie=e=>e.replace(/[\s="]/g,`_`),wie=(e,t)=>`${Cie(e[0])}=${t-e[1]}ms`,fs=e=>(...t)=>{let n;for(let e=0,r=t.length;e<r;e++){let r=t[e];rn(r)&&(n?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),n=n?un(n.reasons.concat(r.reasons)):r,e--)}return n===void 0&&(n=$ee),On(r=>{let i=e??r.cache.logLevel;if(yie(r.cache.minimumLogLevel,i))return Sa;let a=r.getRef($o),o=r.getRef(bie);if(o.size>0){let e=new Date(a.currentTimeMillisUnsafe());for(let a of o)a.log({cause:n,fiber:r,date:e,logLevel:i,message:t})}return Sa})},ps={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};ps.gray,ps.blue,ps.green,ps.yellow,ps.red,ps.bgBrightRed,ps.black;const Tie=e=>`${e.getHours().toString().padStart(2,`0`)}:${e.getMinutes().toString().padStart(2,`0`)}:${e.getSeconds().toString().padStart(2,`0`)}.${e.getMilliseconds().toString().padStart(3,`0`)}`,Eie=ds(({cause:e,date:t,fiber:n,logLevel:r,message:i})=>{let a=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&a.push(na(e));let o=t.getTime(),s=n.getRef(Cne),c=``;for(let e of s)c+=` ${wie(e,o)}`;let l=n.getRef(Wi);Object.keys(l).length>0&&a.push(l);let u=n.getRef(us);(n.getRef(xie)?u.error:u.log)(`[${Tie(t)}] ${r.toUpperCase()} (#${n.id})${c}:`,...a)}),Die=ds(({cause:e,fiber:t,logLevel:n,message:r})=>{let i=t.getRef($o),a=t.getRef(Wi),o=t.cache.span;if(o===void 0||o._tag===`ExternalSpan`||o.status._tag===`Ended`)return;let s={};for(let[e,t]of Object.entries(a))Ht(s,e,t);s[`effect.fiberId`]=t.id,s[`effect.logLevel`]=n.toUpperCase(),e.reasons.length>0&&(s[`effect.cause`]=na(e)),o.event(qee(Array.isArray(r)&&r.length===1?r[0]:r),i.currentTimeNanosUnsafe(),s)});function Oie(){ua.interruptChildren??=zne}const kie=ha(void 0),Aie=rn,ms=_n,hs=un,jie=pn,Mie=hn,gs=Ene,_s=Qi,vs=One,Nie=qi,Pie=na,ys=Mn,bs=Pn,xs=ite,Fie=_ie,Iie=ls,Lie=Dne,Ss=Cn,Cs=Tn,ws=En,Ts=qa,Es=Ka,Rie=ure,zie={"~effect/Deferred":{_A:Me,_E:Me},pipe(){return Ae(this,arguments)}},Ds=function(){this.resumes=void 0,this.effect=void 0};Ds.prototype=zie;const Os=()=>new Ds,ks=()=>va(()=>Os()),As=e=>wa(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),va(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),js=D(2,(e,t)=>va(()=>Is(e,t))),Ms=D(2,(e,t)=>js(e,En(t))),Ns=e=>va(()=>Ps(e)),Ps=e=>e.effect!==void 0;function Bie(e){return va(()=>cr(e.effect))}const Fs=D(2,(e,t)=>js(e,Cn(t))),Is=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let n=e.resumes;e.resumes=void 0;for(let e=0;e<n.length;e++)n[e](t)}return!0},Vie=D(2,(e,t)=>zo(n=>Ua(po(n(e)),e=>js(t,e)))),Hie=Gi,Ls=_o,Rs=Do,zs=Hre,Bs=Co,Vs=wo,Hs=Vre,Us=So,Ws=vo,Gs=`~effect/Layer/MemoMap`,Uie=(e,t)=>{let n={observers:0,deferred:Os(),scope:Rs(),finalizer:r=>ya(()=>--n.observers>0?Sa:(e.map.delete(t),Ws(n.scope,r)))};return n},Ks=(e,t)=>t.state._tag!==`Closed`&&(e.observers++,To(t,{},e.finalizer),!0),Wie={"~effect/Layer":{_ROut:Me,_E:Me,_RIn:Me},pipe(){return Ae(this,arguments)}},qs=e=>{let t=Object.create(Wie);return t.build=e,t},Gie=e=>qs((t,n)=>{let r=Us(n);return Fo(e(t,r),e=>e._tag===`Failure`?Ws(r,e):Sa)}),Js=e=>{let t=Gie((n,r)=>n.getOrElseMemoize(t,r,e));return t};var Ys=class{get[Gs](){return Gs}parent;constructor(e){this.parent=e}map=new Map;get(e,t){let n=this.map.get(e);return n?(Ks(n,t),n.deferred.effect??As(n.deferred)):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return ya(()=>{let r;return No(ya(()=>{let i=this.get(e,t);if(i)return i;let a=Uie(this,e);return Ks(a,t)?(r=a.deferred,this.map.set(e,a),n(this,a.scope)):n(this,t)}),e=>{r&&Is(r,e)})})}};const Xs=()=>new Ys,Kie=e=>new Ys(e);var Zs=class e extends mr()(`effect/Layer/CurrentMemoMap`){static forkOrCreate(t){let n=kr(t,e);return n?Kie(n):Xs()}};const Qs=D(3,(e,t,n)=>Za(Ga(ya(()=>e.build(t,n)),Or(Zs,t)),Zs,t)),qie=D(2,(e,t)=>On(n=>Qs(e,Zs.forkOrCreate(n.context),t))),$s=function(){return arguments.length===1?e=>ec(Dr(arguments[0],e)):ec(Dr(arguments[0],arguments[1]))},ec=e=>qs(Ne(ha(e))),tc=function(){return arguments.length===1?e=>nc(arguments[0],e):nc(arguments[0],arguments[1])},nc=(e,t)=>rc(Ga(t,t=>Dr(e,t))),rc=e=>Js((t,n)=>zs(e,n)),ic=(e,t,n)=>{let r=Us(n,`parallel`);return Ho(e,e=>e.build(t,Us(r,`sequential`)),{concurrency:e.length}).pipe(Ga(e=>Mte(...e)))},ac=(...e)=>Js((t,n)=>ic(e,t,n)),Jie=(e,t,n)=>Js((r,i)=>Ua(Array.isArray(t)?ic(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(Xa(t),Ga(e=>n(e,t))))),Yie=D(2,(e,t)=>Jie(e,t,(e,t)=>Fr(t,e))),oc=mie,sc=hie,cc=`~effect/DateTime`,lc=`~effect/DateTime/TimeZone`,uc={[cc]:cc,pipe(){return Ae(this,arguments)},[Ft](){return this.toString()},toJSON(){return bc(this).toJSON()}},dc={...uc,_tag:`Utc`,[nt](){return lt(this.epochMilliseconds)},[_t](e){return gc(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${bc(this).toJSON()})`}},Xie={...uc,_tag:`Zoned`,[nt](){return ot(lt(this.epochMilliseconds))(rt(this.zone))},[_t](e){return gc(e)&&e._tag===`Zoned`&&this.epochMilliseconds===e.epochMilliseconds&&vt(this.zone,e.zone)},toString(){return`DateTime.Zoned(${cae(this)})`}},fc={[lc]:lc,[Ft](){return this.toString()}};({...fc}),{...fc};const Zie={value:void 0,enumerable:!1,writable:!0},pc=new WeakMap,mc=(e,t)=>({get(){return Object.isExtensible(this)?void 0:pc.get(this)?.[e]},set(n){if(Object.isExtensible(this)){for(let e of t)Object.defineProperty(this,e,Zie);this[e]=n}else{let t=pc.get(this);t===void 0&&(t={},pc.set(this,t)),t[e]=n}}}),hc=[`partsUtc`,`adjustedEpochMilliseconds`,`partsAdjusted`];Object.defineProperty(dc,"partsUtc",mc(`partsUtc`,[`partsUtc`])),Object.defineProperties(Xie,{partsUtc:mc(`partsUtc`,hc),adjustedEpochMilliseconds:mc(`adjustedEpochMilliseconds`,hc),partsAdjusted:mc(`partsAdjusted`,hc)});const gc=e=>et(e,cc),Qie=e=>e._tag===`Utc`,_c=e=>{let t=Object.create(dc);return t.epochMilliseconds=e,t},vc=e=>{let t=e.getTime();if(Number.isNaN(t))throw new Fie(`Invalid date`);return _c(t)},yc=e=>{if(gc(e))return e;if(e instanceof Date)return vc(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return vc(new Date(e.epochMilliseconds));let t=new Date(0);return oae(t,e),vc(t)}return typeof e==`string`&&!$ie(e)?vc(new Date(e+`Z`)):vc(new Date(e))},$ie=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e)||/z$|gmt$/i.test(e),eae=ur(yc),tae=Ga(oc,_c),nae=e=>_c(e.epochMilliseconds),bc=e=>new Date(e.epochMilliseconds),xc=e=>{if(e._tag===`Utc`)return new Date(e.epochMilliseconds);if(e.zone._tag===`Offset`)return new Date(e.epochMilliseconds+e.zone.offset);if(e.adjustedEpochMilliseconds!==void 0)return new Date(e.adjustedEpochMilliseconds);let t=!1,n=e.zone.format.formatToParts(e.epochMilliseconds).filter(e=>e.type===`era`?(t=e.value===`BC`,!1):e.type!==`literal`),r=Number(n[2].value),i=new Date(0);return i.setUTCFullYear(t?1-r:r,Number(n[0].value)-1,Number(n[1].value)),i.setUTCHours(Number(n[3].value),Number(n[4].value),Number(n[5].value),n[6]?.type===`fractionalSecond`?Number(n[6].value):(e.epochMilliseconds%1e3+1e3)%1e3),e.adjustedEpochMilliseconds=i.getTime(),i},rae=e=>xc(e).getTime()-Sc(e),iae=e=>{let t=Math.abs(e),n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r===60&&(n+=1,r=0),`${e<0?`-`:`+`}${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`},aae=e=>iae(rae(e)),Sc=e=>e.epochMilliseconds,oae=(e,t)=>{if((t.year!==void 0||t.month!==void 0||t.day!==void 0)&&e.setUTCFullYear(t.year??e.getUTCFullYear(),t.month===void 0?e.getUTCMonth():t.month-1,t.day??e.getUTCDate()),t.weekDay!==void 0){let n=t.weekDay-e.getUTCDay();e.setUTCDate(e.getUTCDate()+n)}t.hour!==void 0&&e.setUTCHours(t.hour),t.minute!==void 0&&e.setUTCMinutes(t.minute),t.second!==void 0&&e.setUTCSeconds(t.second),t.millisecond!==void 0&&e.setUTCMilliseconds(t.millisecond)},sae=e=>bc(e).toISOString(),Cc=e=>{let t=xc(e);return e._tag===`Utc`?t.toISOString():`${t.toISOString().slice(0,-1)}${aae(e)}`},cae=e=>e.zone._tag===`Offset`?Cc(e):`${Cc(e)}[${e.zone.id}]`;globalThis.Number;const lae=D(2,(e,t)=>{let n=10**t;return Math.round(e*n)/n}),wc=D(2,(e,t)=>to(e,uae,e=>t(e))),Tc=e=>e.reasons.some(Ec),Ec=e=>e._tag===`Fail`&&ys(e.error),Dc=e=>{let t,n=!1;for(let r of e.reasons)Ec(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?Br(e):n?Br(hs(e.reasons.filter(e=>!Ec(e)))):zr(t)},uae=e=>{let t=Dc(e);return Vr(t)?t:zr(t.success.value)},Oc=e=>{let t=Dc(e);return Vr(t)?Cs(t.failure):Ss(t.success.value)},kc=D(2,(e,t)=>co(e,{onSuccess:t.onSuccess,onFailure:e=>{let n=Dc(e);return Vr(n)?t.onFailure(n.failure):t.onDone(n.success.value)}})),Ac=`~effect/Schedule`,jc=Ir(`effect/Schedule/CurrentMetadata`,{defaultValue:Ne({input:void 0,output:void 0,duration:Ci,attempt:0,start:0,now:0,elapsed:0,elapsedSincePrevious:0})}),dae={[Ac]:{_Out:Me,_In:Me,_Env:Me},pipe(){return Ae(this,arguments)}},Mc=e=>et(e,Ac),Nc=e=>{let t=Object.create(dae);return t.step=e,t},Pc=()=>{let e=0,t,n;return(r,i)=>{n===void 0&&(n=r);let a=r-n,o=t===void 0?0:r-t;return t=r,{input:i,attempt:++e,start:n,now:r,elapsed:a,elapsedSincePrevious:o}}},Fc=e=>Nc(Ga(e,e=>{let t=Pc();return(n,r)=>e(t(n,r))})),Ic=e=>$a(e.step,e=>ha(()=>ga(e))),Lc=e=>rs(t=>Ga(Ic(e),e=>{let n=Pc();return r=>ya(()=>{let i=t.currentTimeMillisUnsafe();return Ua(e(i,r),([e,t])=>{let a=n(i,r);return a.output=e,a.duration=t,ja(is(t),a)})})})),fae=e=>Nc(Ga(Bo(e.map(Ic)),e=>(t,n)=>Ua(Ho(e,e=>kc(e(t,n),{onSuccess:e=>ha(e[1]),onDone:()=>kie,onFailure:ga})),e=>{let t=pae(e);return t===void 0?xs(Ci):ha([t,t])}))),pae=e=>{let t;for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&(t=t===void 0?r:Pi(t,r))}return t},mae=(e,t=2)=>{let n=Ai(mi(e));return Fc(ha(e=>{let r=Di(n*t**(e.attempt-1));return ha([r,r])}))},Rc=e=>Nc(Ga(Ic(e),e=>(t,n)=>kc(e(t,n),{onSuccess:e=>ha([n,e[1]]),onFailure:ga,onDone:()=>xs(n)}))),zc=e=>{let t=mi(e);return Fc(ha(e=>ha([e.attempt-1,t])))},Bc=D(2,(e,t)=>Nc(Ga(Ic(e),e=>{let n=Pc();return(r,i)=>Ua(e(r,i),e=>{let[a,o]=e,s=t({...n(r,i),output:a,duration:o});return Ua($t(s)?s:ha(s),t=>t?ha(e):xs(a))})}))),hae=zc(Ci),gae=(e,t,n)=>jo(r=>Ua(n?.local?Qs(t,Xs(),r):qie(t,r),t=>Xa(e,t))),_ae=D(e=>$t(e[0]),(e,t,n)=>wr(t)?Xa(e,t):gae(e,Array.isArray(t)?ac(...t):t,n)),vae=D(3,(e,t,n)=>Ua(Lc(t),t=>{let r=jc.defaultValue(),i=n=>kc(t(n),{onSuccess(t){return r=t,Ua(Za(e,jc,r),i)},onFailure:ga,onDone:ha});return to(Ua(Za(e,jc,r),i),Xi,e=>n(e,r.attempt===0?O():nr(r)))})),yae=D(3,(e,t,n)=>Ua(Lc(t),t=>{let r=jc.defaultValue(),i,a=to(ya(()=>Za(e,jc,r)),Xi,e=>(i=e,Ua(t(e),e=>(r=e,a))));return wc(a,e=>Vt(()=>n(i,e)))})),bae=D(2,(e,t)=>{let n=typeof t==`function`?t(Me):Mc(t)?t:Vc(t);return vae(e,n,_a)}),xae=D(2,(e,t)=>{let n=typeof t==`function`?t(Me):Mc(t)?t:Vc(t);return yae(e,n,_a)}),Sae=Rc(hae),Vc=e=>{let t=e.schedule?Rc(e.schedule):Sae;return e.while&&(t=Bc(t,({input:t})=>{let n=e.while(t);return $t(n)?n:ha(n)})),e.until&&(t=Bc(t,({input:t})=>{let n=e.until(t);return $t(n)?Ga(n,e=>!e):ha(!n)})),e.times!==void 0&&(t=Bc(t,({attempt:t})=>ha(t<=e.times))),t},Hc=$t,Uc=Bo,Wc=Ho,Cae=Vo,wae=Jne,Gc=Yne,k=ha,Kc=ya,qc=va,Jc=Sa,Yc=wa,Xc=Ta,Zc=Zne,A=_a,Tae=Kne,Qc=ga,$c=Gne,el=xa,tl=qne,nl=On,Eae=Une,j=Ua,rl=ore,il=za,al=Ba,ol=so,sl=po,M=Ga,cl=ja,ll=Va,Dae=bre,ul=no,dl=Ere,Oae=Dre,kae=Ore,fl=$a,pl=ro,ml=io,hl=ao,gl=kre,_l=Tre,Aae=Cre,vl=xae,yl=Are,jae=jre,Mae=Rre,bl=mo,xl=is,Sl=Ha,Cl=fo,wl=co,Nae=uo,Tl=vre,Pae=Ya,El=_ae,Dl=Xa,Ol=_re,kl=Za,Al=Ao,jl=Ure,Fae=jo,Ml=Wre,Nl=Gre,Pl=Kre,Fl=Jre,Iae=No,Il=Fo,Lae=Zre,Ll=Qre,Rae=Io,Rl=zo,zl=xre,Bl=bae,zae=aie,Vl=Yo,Hl=oie,Ul=cie,Wl=Xo,Gl=lie,N=Da,Bae=fs(`Error`),Kl=(e,t,n)=>(...r)=>Yc(i=>{let a=!0,o;try{e(...r,(e,n)=>{let s=e?t?Kc(()=>A(t(e,r))):A(e):k(n);a?o??=s:i(s)})}catch(e){o=n?A(n(e,r)):el(e)}a=!1,o&&i(o)}),Vae=sre,Hae=cre,ql=are,Uae=Qne,Jl=Bne,Yl=fa,Xl=pa,Wae=ca,Zl=sie,Gae=Symbol.for(`effect/MutableList/Empty`),Kae=()=>({head:void 0,tail:void 0,length:0}),Ql=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},$l=()=>({array:[],mutable:!0,offset:0,next:void 0}),eu=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=$l(),e.tail=e.tail.next):e.head=e.tail=$l(),e.tail.array.push(t),e.length++},tu=e=>{e.head=e.tail=void 0,e.length=0},qae=(e,t)=>{if(t=Rr(t),t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return tu(e),t}let n=Array(t),r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,e.length===0?tu(e):Ql(e),n;i=i.next}return tu(e),n},Jae=(e,t)=>{if(t=Rr(t),t<=0||!e.head)return;if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){tu(e);return}let n=0,r=e.head;for(;r;){let i=r.array.length-r.offset;if(n+i>t){r.offset+=t-n,e.head=r,e.length-=t,Ql(e);return}n+=i,r=r.next}tu(e)},nu=e=>{if(!e.head)return Gae;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:tu(e):Ql(e),t},ru={_A:Me,_E:Me},Yae={"~effect/Queue":ru,"~effect/Queue/Enqueue":ru,"~effect/Queue/Dequeue":ru,...Qt,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:eoe(this)}}},iu=e=>On(t=>{let n=Object.create(Yae);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=Kae(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},ha(n)}),au=e=>iu({capacity:e}),Xae=e=>iu({capacity:e,strategy:`sliding`}),ou=D(2,(e,t)=>ya(()=>su(e,t)?gu:e.state._tag===`Open`&&e.strategy===`suspend`?ioe(e,t):hu)),su=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.capacity<=0&&e.state.takers.size>(e.strategy===`sliding`?0:e.messages.length)?(eu(e.messages,t),e.strategy===`sliding`&&Jae(e.messages,e.messages.length-e.state.takers.size),_u(e),!0):e.strategy===`sliding`&&(e.capacity>0&&(nu(e.messages),eu(e.messages,t)),!0):(eu(e.messages,t),vu(e),!0):!1,cu=D(2,(e,t)=>va(()=>lu(e,t))),lu=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=Tn(t),r=hre(n,toe);return e.state.offers.size===0&&e.messages.length===0?(Tu(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},vu(e),!0)},uu=e=>lu(e,pn(Pn())),du=e=>va(()=>Zae(e)),Zae=e=>{if(e.state._tag===`Done`)return!1;tu(e.messages);let t=e.state.offers;Tu(e,e.state._tag===`Open`?noe:e.state.exit);for(let e of t)Su(e);return!0},Qae=e=>fu(e,1,1/0),fu=D(3,(e,t,n)=>(t=Rr(t),n=Rr(n),yu(()=>roe(e,t,n)??za(xu(e,()=>bu(e,t)),fu(e,t,n))))),pu=e=>yu(()=>mu(e)??za(xu(e,()=>bu(e,1)),pu(e))),$ae=e=>yu(()=>{let t=mu(e);return t===void 0?ha(O()):t._tag===`Success`?ha(nr(t.value)):ha(O())}),mu=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=nu(e.messages);return wu(e),Cn(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=Cu(e.state.offers);return wu(e),Cn(t)}},eoe=e=>e.state._tag===`Done`?0:e.messages.length,hu=Cn(!1),gu=Cn(!0),toe=En(Pn()),noe=lre(),_u=e=>{if(e.state._tag!==`Done`&&e.state.takers.size!==0){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(qa),e.messages.length===0))break}},vu=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,_u(e)},0))},roe=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return Cn([]);if(!bu(e,t))return;let r=e.messages.length>0?qae(e.messages,n):[Cu(e.state.offers)];return wu(e),Cn(r)},yu=xn({op:`QueueTake`,[qt](e){let t=this[Kt]();return en(t)?t[qt](e):t}}),bu=(e,t)=>e.messages.length>=(e.state._tag===`Closing`?1:Math.min(t,e.capacity||1))||e.capacity<=0&&e.state._tag!==`Done`&&e.state.offers.size>0,xu=(e,t)=>wa(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(qa);let r={ready:t,resume:n};return e.state.takers.add(r),va(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),ioe=(e,t)=>wa(n=>su(e,t)?n(gu):aoe(e,{_tag:`Single`,message:t,resume:n})),aoe=(e,t)=>{if(e.state._tag!==`Open`)return Su(t);let n=e.state.offers;return n.add(t),va(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&Tu(e,e.state.exit))})},Su=e=>e._tag===`Single`?e.resume(hu):e.resume(Cn(e.remaining.slice(e.offset))),Cu=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(gu),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(Cn([]))),n},wu=e=>{if(e.state._tag===`Done`)return Tc(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(Tu(e,e.state.exit),Tc(e.state.exit.cause));for(let t of e.state.offers){let n=e.capacity-e.messages.length;if(n<=0)break;if(t._tag===`Single`)eu(e.messages,t.message),e.state.offers.delete(t),t.resume(gu);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;eu(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(Cn([]))}let r=e.state;if(r._tag===`Done`)return Tc(r.exit.cause)}return!1},Tu=(e,t)=>{if(e.state._tag===`Done`)return;let n=e.state;e.state={_tag:`Done`,exit:t};for(let e of n.takers)e.resume(t);n.takers.clear();for(let e of n.awaiters)e(t);n.awaiters.clear()},ooe=Ir(`effect/crypto/WebCrypto`,{defaultValue:()=>globalThis.crypto}),Eu=e=>new soe(e),Du=e=>{for(let t of e.waiters)if(t.permits<=e.free)return t},Ou=(e,t,n,r=Me)=>On(i=>{if(e.free>=t&&Du(e)===void 0)return e.taken+=t,n();let a={permits:t,resume:void 0},o=()=>{e.waiters.delete(a)&&e.releaseUnsafe(i,0)};e.waiters.add(a),Po(i,o);let s=r(wa(t=>{Du(e)===a?t(Sa):a.resume=t})),c=Ua(s,()=>Du(e)===a?(e.taken+=t,o(),n()):c);return c});var soe=class{waiters=new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){return Ou(this,e,()=>ha(e))}takeScoped(e){return zo(t=>Ua(Ao,n=>Ou(this,e,()=>wo(n,this.release(e)),t)))}takeIfAvailable(e){return ya(()=>this.free<e?ha(!1):(this.taken+=e,ha(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{let e=this.free;for(let t of Array.from(this.waiters)){if(!this.waiters.has(t)||t.permits>e)continue;e-=t.permits;let n=t.resume;t.resume=void 0,n?.(Sa)}},0),this.free}resize(e){return On(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),Sa))}release(e){return On(t=>ha(this.releaseUnsafe(t,e)))}get releaseAll(){return On(e=>ha(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>zo(n=>Ou(this,e,()=>No(n(t),()=>{this.releaseUnsafe(ca(),e)},!0),n))}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>zo(n=>this.free<e?Wne:(this.taken+=e,No(n(Ra(t)),()=>{this.releaseUnsafe(ca(),e)},!0)))}};const ku=`~effect/BigDecimal`,coe={[ku]:ku,[nt](){let e=Mu(this);return ot(ut(String(e.value)),lt(e.scale))},[_t](e){return loe(e)&&goe(this,e)===0},toString(){return`BigDecimal(${_oe(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[Ft](){return this.toJSON()},pipe(){return Ae(this,arguments)}},loe=e=>et(e,ku),uoe=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(coe);return n.value=e,n.scale=t,n},Au=(e,t)=>{let n=uoe(e,t);return n.normalized=n,n},ju=BigInt(0),doe=BigInt(1),foe=BigInt(10),poe=Au(ju,0),Mu=e=>{if(e.normalized===void 0){if(e.value===ju)e.normalized=poe;else{let t=`${e.value}`,n=moe(t);e.normalized=Au(BigInt(t.slice(0,t.length-n)),e.scale-n)}}return e.normalized},moe=e=>{let t=e.length;for(;e[t-1]===`0`;)t--;return e.length-t},hoe=[doe],Nu=(e,t)=>e===t?0:e<t?-1:1,Pu=(e,t)=>{let n=`${e.value<ju?-e.value:e.value}`,r=`${t.value<ju?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==ju)return i<ju?-1:1;let a=Math.max(n.length,r.length);return Zn(n.padEnd(a,`0`),r.padEnd(a,`0`))},goe=(e,t)=>{if(e.scale===t.scale)return Nu(e.value,t.value);let n=Fu(e),r=Fu(t);if(n!==r)return n<r?-1:1;if(n===0)return 0;let i=e.scale-t.scale,a=Math.abs(i);if(a>100)return n===-1?Pu(t,e):Pu(e,t);let o=hoe[a]??=foe**BigInt(a);return i>0?Nu(e.value,t.value*o):Nu(e.value*o,t.value)},Fu=e=>e.value===ju?0:e.value<ju?-1:1,_oe=e=>{let t=Mu(e);if(Math.abs(t.scale)>=16)return voe(t);let n=t.value<ju,r=`${n?-t.value:t.value}`,i=t.scale>0?r.padStart(t.scale+1,`0`):r.padEnd(r.length-t.scale,`0`),a=i.length-t.scale,o=t.scale>0?`${i.slice(0,a)}.${i.slice(a)}`:i;return n?`-${o}`:o},voe=e=>{if(yoe(e))return`0e+0`;let t=Mu(e),n=`${t.value}`,r=t.value<ju?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},yoe=e=>e.value===ju,Iu=globalThis.BigInt,boe=e=>e>Iu(2**53-1)||e<Iu(-(2**53-1))?O():nr(Number(e)),Lu=BigInt(0),xoe=BigInt(1),Ru=BigInt(1e3),zu=BigInt(1024),Bu=[{symbol:`B`,factor:xoe,names:[`B`,`byte`,`bytes`]},{symbol:`kB`,factor:Ru,names:[`kB`,`kilobyte`,`kilobytes`]},{symbol:`MB`,factor:Ru**BigInt(2),names:[`MB`,`megabyte`,`megabytes`]},{symbol:`GB`,factor:Ru**BigInt(3),names:[`GB`,`gigabyte`,`gigabytes`]},{symbol:`TB`,factor:Ru**BigInt(4),names:[`TB`,`terabyte`,`terabytes`]},{symbol:`PB`,factor:Ru**BigInt(5),names:[`PB`,`petabyte`,`petabytes`]},{symbol:`EB`,factor:Ru**BigInt(6),names:[`EB`,`exabyte`,`exabytes`]},{symbol:`ZB`,factor:Ru**BigInt(7),names:[`ZB`,`zettabyte`,`zettabytes`]},{symbol:`YB`,factor:Ru**BigInt(8),names:[`YB`,`yottabyte`,`yottabytes`]},{symbol:`RB`,factor:Ru**BigInt(9),names:[`RB`,`ronnabyte`,`ronnabytes`]},{symbol:`QB`,factor:Ru**BigInt(10),names:[`QB`,`quettabyte`,`quettabytes`]}],Soe=[Bu[0],{symbol:`KiB`,factor:zu,names:[`KiB`,`kibibyte`,`kibibytes`]},{symbol:`MiB`,factor:zu**BigInt(2),names:[`MiB`,`mebibyte`,`mebibytes`]},{symbol:`GiB`,factor:zu**BigInt(3),names:[`GiB`,`gibibyte`,`gibibytes`]},{symbol:`TiB`,factor:zu**BigInt(4),names:[`TiB`,`tebibyte`,`tebibytes`]},{symbol:`PiB`,factor:zu**BigInt(5),names:[`PiB`,`pebibyte`,`pebibytes`]},{symbol:`EiB`,factor:zu**BigInt(6),names:[`EiB`,`exbibyte`,`exbibytes`]},{symbol:`ZiB`,factor:zu**BigInt(7),names:[`ZiB`,`zebibyte`,`zebibytes`]},{symbol:`YiB`,factor:zu**BigInt(8),names:[`YiB`,`yobibyte`,`yobibytes`]}],Coe=[...Bu,...Soe.slice(1)],woe=new Map(Coe.flatMap(e=>e.names.map(t=>[t,e]))),Vu=e=>e,Hu=e=>{throw Error(`Invalid ByteSize: ${e}`)},Uu=e=>!Number.isSafeInteger(e)||e<0?Hu(`expected a non-negative safe integer, received ${e}`):Vu(BigInt(e)),Toe=(e,t)=>{let n=/^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(e);if(n===null)return;let r=n[2]??``,i=BigInt(n[1]+r)*t,a=Number(n[3]??0)-r.length;if(a>=0)return i*BigInt(10)**BigInt(a);let o=BigInt(10)**BigInt(-a);return i%o===Lu?i/o:void 0},Eoe=e=>{let t=/^\s*(\d+(?:\.\d+)?)\s*([A-Za-z]+)\s*$/.exec(e);if(t===null)return Hu(`unsupported syntax ${JSON.stringify(e)}`);let n=woe.get(t[2]);if(n===void 0)return Hu(`unsupported unit ${JSON.stringify(t[2])}`);let r=Toe(t[1],n.factor);return r===void 0?Hu(`${JSON.stringify(e)} does not represent an integral number of bytes`):Vu(r)},Wu=e=>{switch(typeof e){case`bigint`:return e<Lu?Hu(`expected a non-negative bigint, received ${e}`):Vu(e);case`number`:return Uu(e);case`string`:return Eoe(e)}return Hu(`unsupported input ${e}`)},Gu=e=>typeof e==`bigint`?Wu(e):Uu(e),Doe=()=>Error(`crypto.subtle is unavailable; browsers expose it only in secure contexts`),Ooe=(e,t,n)=>{if(e.length<128)return;let r=Uint8Array;if(typeof r.fromBase64==`function`)try{let i=r.fromBase64(e,n);return i.length===t?i:null}catch{return null}},koe=e=>e.indexOf(`
15
+ `)===-1&&e.indexOf(`\r`)===-1?e:e.replace(/[\n\r]/g,``),Ku=e=>Aoe(typeof e==`string`?Ju.encode(e):e),qu=e=>{let t=koe(e),n=t.length;if(n%4!=0)return Br(new Hi({kind:`Decode`,module:`Base64`,input:t,message:`Length must be a multiple of 4, but is ${n}`}));let r=t.indexOf(`=`);if(r!==-1&&(r<n-2||r===n-2&&t[n-1]!==`=`))return Br(new Hi({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));let i=t.endsWith(`==`)?2:+!!t.endsWith(`=`),a=n/4*3-i,o=Ooe(t,a,void 0);if(o)return zr(o);if(o===null){let e=Poe.exec(t);if(e!==null)return Br(new Hi({kind:`Decode`,module:`Base64`,input:t,message:`Invalid character ${e[0]}`}))}try{let e=new Uint8Array(a);for(let r=0,i=0;r<n;r+=4,i+=3){let n=$u(t.charCodeAt(r))<<18|$u(t.charCodeAt(r+1))<<12|$u(t.charCodeAt(r+2))<<6|$u(t.charCodeAt(r+3));e[i]=n>>16,e[i+1]=n>>8&255,e[i+2]=n&255}return zr(e)}catch(e){return Br(new Hi({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},Aoe=e=>{let t=e.length,n=Uint8Array.prototype.toBase64;return t>=32&&typeof n==`function`?n.call(e):t<128?joe(e):Moe(e)},joe=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=Yu[e[r-2]>>2],n+=Yu[(e[r-2]&3)<<4|e[r-1]>>4],n+=Yu[(e[r-1]&15)<<2|e[r]>>6],n+=Yu[e[r]&63];return r===t+1&&(n+=Yu[e[r-2]>>2],n+=Yu[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=Yu[e[r-2]>>2],n+=Yu[(e[r-2]&3)<<4|e[r-1]>>4],n+=Yu[(e[r-1]&15)<<2],n+=`=`),n},Moe=e=>{let t=e.length,n=new Uint8Array(Math.ceil(t/3)*4),r,i=0;for(r=2;r<t;r+=3,i+=4)n[i]=Xu[e[r-2]>>2],n[i+1]=Xu[(e[r-2]&3)<<4|e[r-1]>>4],n[i+2]=Xu[(e[r-1]&15)<<2|e[r]>>6],n[i+3]=Xu[e[r]&63];return r===t+1&&(n[i]=Xu[e[r-2]>>2],n[i+1]=Xu[(e[r-2]&3)<<4],n[i+2]=Zu,n[i+3]=Zu),r===t&&(n[i]=Xu[e[r-2]>>2],n[i+1]=Xu[(e[r-2]&3)<<4|e[r-1]>>4],n[i+2]=Xu[(e[r-1]&15)<<2],n[i+3]=Zu),Noe.decode(n)},Ju=new TextEncoder,Noe=new TextDecoder(`utf-8`,{ignoreBOM:!0}),Yu=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Xu=Ju.encode(Yu),Zu=61,Poe=/[^A-Za-z0-9+/=]/,Qu=new Uint8Array(123).fill(255);for(let e=0;e<64;e++)Qu[Yu.charCodeAt(e)]=e;Qu[61]=0;const $u=e=>{if(e>=Qu.length||Qu[e]===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return Qu[e]},ed=(e,t,n)=>{let r=t.implementation;return r===void 0?Kc(()=>{let r=e?.subtle;return r===void 0?el(Doe()):wae(async()=>new Uint8Array(await r.digest(t.name,n)))}):qc(()=>r(n))},Foe={name:`SHA-256`,outputLength:32,implementation:void 0};var td=class extends mr()(`effect/crypto/Digest`){};const Ioe=tc(td,ooe.use(e=>k({digest:(t,n)=>ed(e,t,n),digestHex:(t,n)=>M(ed(e,t,n),hne)}))),Loe=gc,Roe=Qie,nd=yc,rd=eae,id=tae,zoe=nae,ad=Sc,od=sae;({...Lt}),{...Lt};const sd=new WeakMap,Boe=e=>{if(sd.has(e))return sd.get(e);throw Error(`Unable to get redacted value`+(e.label?` with label: "${e.label}"`:``))},cd=`~effect/Redacted`,ld=e=>et(e,cd),ud=(e,t)=>{let n=Object.create(Voe);return t?.label&&(n.label=t.label),sd.set(n,e),n},Voe={[cd]:{_A:e=>e},label:void 0,...Qt,toJSON(){return this.toString()},toString(){return`<redacted${Ke(this.label)?`:`+this.label:``}>`},[nt](){return rt(sd.get(this))},[_t](e){return ld(e)&&vt(sd.get(this),sd.get(e))}},dd=Boe;Lt.toString,Lt[Ft],{...Qt};function Hoe(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}const fd=`~sentinels`,pd=`~constructor`,md=Re(e=>{let t=Hoe(e)?.identifier;return typeof t==`string`?t:e.getExpected(md)}),hd=Symbol.for(`effect/schema/parser/missing`),gd=Ss,_d=gd(hd),vd=Object.assign(gd(hd),{[hd]:!0}),yd=e=>e[hd]===!0,bd=e=>e===hd?O():nr(e),xd=e=>e._tag===`None`?_d:gd(e.value),Sd=`~effect/SchemaIssue/Issue`;function Cd(e){return et(e,Sd)&&e[Sd]===Sd}function Uoe(e){return Object.hasOwn(e,`input`)}var wd=class{[Sd]=Sd;constructor(e,t){t?.reportInput===!0&&e!==hd&&(this.input=e)}};const Woe=class extends wd{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},Goe=class extends wd{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},Td=class extends wd{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},Ed=class extends wd{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},Dd=class extends wd{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Od=class extends wd{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},kd=class extends wd{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Ad=class extends wd{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},jd=class extends wd{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Md=class extends wd{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},Koe=class extends wd{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Nd(e,t,n){if(Cd(e))return e;if(typeof e==`string`)return new Ad({message:e},t,n);let r=typeof e.issue==`string`?new Ad({message:e.issue},t,n):e.issue;return new Td(e.path,r)}function qoe(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Ad(void 0,t,n):Nd(e,t,n)}function Joe(e,t,n,r){return Array.isArray(t)?qr(t)?t.length===1?Nd(t[0],n,r):new Od(e,Zr(t,e=>Nd(e,n,r)),n,r):void 0:qoe(t,n,r)}const Yoe=e=>{let t=zd(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Id(md(e.ast),e);case`InvalidValue`:{let t=Fd(e);if(t!==void 0)return Id(t,e);let n=Pd(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Pd(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Pd(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},Xoe=e=>zd(e)??zd(e.issue);function Pd(e){return Uoe(e)?jt(e.input):void 0}function Fd(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Id(e,t){let n=Pd(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function Zoe(e,t){let n=t(e);if(n!==void 0||e.issue._tag!==`InvalidValue`)return n;let r=Fd(e.issue);return r===void 0?Id(Ld(e.filter),e):Id(r,e.issue)}function Ld(e){let t=e.annotations?.expected;if(typeof t==`string`)return t;switch(e._tag){case`Filter`:return`<filter>`;case`FilterGroup`:return e.checks.map(e=>Ld(e)).join(` & `)}}function Qoe(){return e=>Rd(e,``)}const $oe=Qoe();function Rd(e,t,n){let r;switch(e._tag){case`Filter`:return Rd(e.issue,t,n??Zoe(e,Xoe));case`Encoding`:return Rd(e.issue,t,n);case`Pointer`:return Rd(e.issue,t+Vee(e.path),n);case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>Rd(e,t,n)).join(`
16
+ `);r=n??zd(e)??Id(md(e.ast),e);break;default:r=n??Yoe(e)}return t?`${r}\n at ${t}`:r}function zd(e){if(e._tag===`Pointer`||e._tag===`Composite`)return;if(e._tag===`Encoding`)return zd(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function Bd(e){let t;for(let n of e.reasons){if(!ms(n)||!Cd(n.error))return;t??=n.error}return t}function Vd(e,t){let n=Bd(e);if(n===void 0)throw Error(t,{cause:e});return n}const Hd=e=>Object.assign(Object.create(fee),e);function ese(e){return ise((t,n)=>A(e(t,n)))}function tse(e){return ese((t,n)=>{let r={message:e(t)};return ir(t)?new jd(r,t.value,n):new jd(r)})}const nse=tse(()=>`Encoding is not supported`),rse=Hd({_tag:`Passthrough`});function Ud(){return rse}function Wd(e){return Hd({_tag:`Transform`,transform:e})}function Gd(e){return Hd({_tag:`TransformEffect`,transform:e})}function ise(e){return Hd({_tag:`TransformOptionalEffect`,transform:e})}function Kd(){return Wd(globalThis.String)}function qd(){return Wd(globalThis.Number)}function ase(){return Gd((e,t)=>{try{return k(globalThis.BigInt(e))}catch{return A(new Ad({expected:`a value that can be converted to a bigint`},e,t))}})}function ose(e){return Gd((t,n)=>tl({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Ad({expected:`a valid JSON string`},t,n)}))}function sse(e){return Gd((t,n)=>tl({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new Ad({expected:`a JSON-serializable value`},t,n)}))}function cse(){return Wd(Ku)}function lse(){return Gd((e,t)=>Hae(Eae(qu(e)),()=>new Ad({expected:`a valid Base64 string`},e,t)))}const use=Symbol.for(`~effect/Schema/content`);function dse(e,t){return Object.defineProperty(e,use,{value:t}),e}const fse=class extends je{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new fse(this.encode,this.decode)}},Jd=`~effect/SchemaTransformation/Transformation`,Yd=class extends je{[Jd]=Jd;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Yd(this.encode,this.decode)}};function pse(e){return et(e,Jd)&&e[Jd]===Jd}const Xd=e=>pse(e)?e:new Yd(e.decode,e.encode);function Zd(e){return new Yd(Gd(e.decode),Gd(e.encode))}function Qd(e){return new Yd(Wd(e.decode),Wd(e.encode))}const mse=new Yd(Ud(),Ud());function $d(){return mse}const ef=new Yd(qd(),Kd()),hse=new Yd(ase(),Kd()),gse=e=>Cee(e)&&typeof e.message==`string`,_se=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:tf(e.cause)}):Error(e.message);return typeof e.name==`string`&&e.name!==`Error`&&(t.name=e.name),typeof e.stack==`string`&&(t.stack=e.stack),t},vse=e=>{try{let t=Pt(e);return t===void 0?jt(e):JSON.parse(t)}catch{return jt(e)}},yse=(e,t,n)=>{let r={name:e.name,message:typeof e.message==`string`?e.message:``};return t?.includeStack&&typeof e.stack==`string`&&(r.stack=e.stack),!t?.excludeCause&&e.cause!==void 0&&(r.cause=n(e.cause)),r},bse=e=>{let t=new WeakSet,n=r=>{if(wee(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=yse(r,e,n);return t.delete(r),i}return vse(r)};return n},tf=e=>gse(e)?_se(e):e,xse=e=>Qd({decode:tf,encode:bse(e)}),Sse=new Yd(lse(),cse());function Cse(e){return new Yd(ose(e??{}),dse(sse(e),{mediaType:`application/json`,preserveSchema:e?.reviver===void 0&&e?.replacer===void 0}))}function nf(e){return t=>t._tag===e}const rf=nf(`Declaration`),wse=nf(`Never`),af=nf(`Literal`),of=nf(`UniqueSymbol`),Tse=nf(`Arrays`),Ese=nf(`Objects`),sf=nf(`Suspend`),cf=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},lf={},uf=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},df=`~effect/Schema`;var ff=class{[df]=df;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}};const pf=class extends ff{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>{if(t===hd)return _d;e??=this.run(this.typeParameters);try{return e(t,this,n)}catch(e){return el(e)}}}_rebuild(e,t,n,r,i){let a=fp(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new pf(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},mf=new class extends ff{_tag=`Null`;getParser(){return bp(this,null)}getExpected(){return`null`}},Dse=class extends ff{_tag=`Undefined`;getParser(){return bp(this,void 0)}toCodecJson(){return np(this,[Ose])}getExpected(){return`undefined`}},Ose=new cf(mf,new Yd(Wd(()=>void 0),Wd(()=>null))),hf=new Dse,gf=new class extends ff{_tag=`Unknown`;getParser(){return xp(this,See)}getExpected(){return`unknown`}},_f=class extends ff{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${jt(e)}`);this.literal=e}getParser(){return bp(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?vf(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:vf(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function vf(e){let t=globalThis.String(e.literal);return np(e,[new cf(new _f(t),new Yd(Wd(()=>e.literal),Wd(()=>t)))])}const yf=new class extends ff{_tag=`String`;getParser(){return xp(this,Ke)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&Dp(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},kse=class extends ff{_tag=`Number`;getParser(){return xp(this,qe)}matchKey(e,t){return this._match(ace,e,t)}matchPart(e,t){return this._match(wp,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:Dp(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(bf(this.checks,`effect/schema/isFinite`)||bf(this.checks,`effect/schema/isInt`))?this:np(this,[qse])}toCodecStringTree(){return this.toCodecJson()===this?np(this,[sce]):np(this,[cce])}getExpected(){return`number`}};function bf(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&bf(e.checks,t))}const xf=new kse,Ase=new class extends ff{_tag=`Boolean`;getParser(){return xp(this,Je)}getExpected(){return`boolean`}},jse=new class extends ff{_tag=`BigInt`;getParser(){return xp(this,_ee)}matchPart(e,t){if(!Ep.test(e))return;let n=globalThis.BigInt(e);return t.disableChecks||!this.checks?n:Dp(this.checks,n,void 0,this,t)?void 0:n}toCodecStringTree(){return np(this,[uce])}getExpected(){return`bigint`}},Sf=class extends ff{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(hp(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(hp(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}let c=e=>{let{input:t,len:r,options:i}=e;if(n.rest.length===0&&r>a)for(let o=a;o<r;o++){let r=new Dd(n,t[o],i),a=new Td([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return A(new Od(n,[a],t,i))}return e.issues?A(new Od(n,e.issues,t,i)):gd(e.output)},l=(e,t)=>{let r=e.length,i={ast:n,getParser:s,input:e,len:r,tailThreshold:Math.max(a,r-o),output:[],issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:Uo(t.concurrency),f=d===1?Nse(i,e,0,u):Pse(i,e,{concurrency:d,end:u});if(!f)return c(i);if(Wa(f))return ql(f,()=>c(i));let p=!0;return Kc(()=>p?(p=!1,j(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===hd)return _d;try{return Array.isArray(e)?(r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)}))),l(e,a)):A(new kd(n,e,a))}catch(e){return el(e)}}}_rebuild(e,t,n){let r=fp(this.elements,e),i=fp(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new Sf(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function Mse(e,t,n,r){if(n._tag===`Failure`)return wf(e,e.ast,r,n);let i=yd(n)?t:n[Kt];if(i!==hd)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(hp(t.ast))return;let n=new Td([r],new Ed(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return ws(new Od(e.ast,[n],e.input,e.options))}}const Cf={onItem(e,t,n){let r=n<e.len?t:hd;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:Mse},Nse=Wo()(Cf),Pse=Ko()(Cf),wf=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=Bd(r.cause);if(i===void 0)return Cs(_s(r.cause,r=>new Od(t,[new Td([n],r)],e.input,e.options)));let a=new Td([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return ws(new Od(t,[a],e.input,e.options))},Tf=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[Ee][+-]?\\d+)?`;function Ef(e,t,n=lf){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(r=>Object.prototype.propertyIsEnumerable.call(e,r)&&t.matchKey(r,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(Sp(vp(t)))}const Df=class{name;type;constructor(e,t){this.name=e,this.type=t}};function Of(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(Of);default:return!1}}function kf(e){let t=ip(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(kf);default:return!1}}function Fse(e){return Of(e)&&kf(e)}const Af=class{parameter;type;constructor(e,t){if(!Fse(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,hp(t)||t.encoding!==void 0&&hp(vp(t)))throw Error("Cannot use `Schema.optionalKey` or `Schema.optional` with index signatures. Index signatures already allow keys to be absent; use `Schema.UndefinedOr` to allow `undefined` values.")}},jf=class extends ff{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o}getParser(e,t=e){let n=this,r=n.propertySignatures.length,i=n.indexSignatures.length;if(!r&&!i)return xp(n,xee);let a,o,s=()=>(a||(a=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type,ownOnly:Hse(e.name)})),o=i?n.indexSignatures.map(n=>({is:n,parserKey:e(Sp(n.parameter)),parserValue:t(n.type)})):void 0),a),c=()=>{let e=new Set(n.propertySignatures.map(e=>typeof e.name==`number`?globalThis.String(e.name):e.name)),t=(t,i,a,o,s)=>{if(s._tag===`Failure`)return wf(t,n,i,s)??Ts;let c=yd(s)?o:s[Kt];if(a!==hd&&c!==hd){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return Ts;Ht(t.out,a,c)}return Ts},c=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!Wa(t))return j(sl(t),t=>c(e,r,i,t));a=t}if(a._tag===`Failure`)return wf(e,n,r,a)??Ts;let o=yd(a)?r:a[Kt],s=e.input[r],l=i.parserValue(s,e.options);return Wa(l)?t(e,r,o,s,l):j(sl(l),n=>t(e,r,o,s,n))},l=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return Wa(a)?t(e,n,n,i,a):j(sl(a),r=>t(e,n,n,i,r))},u=i?Ko()({onItem:(e,[t,n])=>n.is.parameter===yf?l(e,t,n):c(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return Uae(function*(t,d){if(t===hd)return hd;if(typeof t!=`object`||!t||Array.isArray(t))return yield*A(new kd(n,t,d));s();let f=t,p={},m={ast:n,input:f,out:p,issues:void 0,options:d},h=d.errors===`all`,g=d.onExcessProperty===`error`,_=d.concurrency===void 0?1:Uo(d.concurrency),v=i&&g?n.indexSignatures.map(e=>Ef(f,e.parameter,d)):void 0;if(g){let r=v?new Set(e):e;if(v)for(let e of v)for(let t of e)r.add(t);let i=Reflect.ownKeys(f);for(let e=0;e<i.length;e++){let a=i[e];if(!r.has(a)&&Object.prototype.propertyIsEnumerable.call(f,a)){let e=new Dd(n,f[a],d),r=new Td([a],e);if(h){m.issues?m.issues.push(r):m.issues=[r];continue}return yield*A(new Od(n,[r],t,d))}}}if(r){let e=_===1?Pf(m,a):Ise(m,a,{concurrency:_});e&&(yield*e)}if(i&&_===1)for(let e=0;e<i;e++){let t=o[e],n=t.is.parameter===yf?l:c,r=v?.[e]??(t.is.parameter===yf?Object.keys(f):Ef(f,t.is.parameter,d));for(let e=0;e<r.length;e++){let i=n(m,r[e],t);if(!Wa(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(u){let e=Yr();for(let t=0;t<i;t++){let n=o[t],r=v?.[t]??(n.is.parameter===yf?Object.keys(f):Ef(f,n.is.parameter,d));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=u(m,e,{concurrency:_});t&&(yield*t)}return m.issues?yield*A(new Od(n,m.issues,t,d)):p})};if(i)return c();let l,u=(e,t,n)=>{let r=a[t];return j(sl(n),n=>{let i={...e,out:{...e.out}},o=Mf(i,r,n);if(o)return o;let s=()=>gd(i.out),c=Pf(i,a.slice(t+1));return c?ql(c,s):s()})};return(e,t)=>{if(e===hd)return _d;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&Uo(t.concurrency)!==1)return(l??=c())(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return A(new kd(n,e,t));let r=s(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=n.ownOnly?Object.hasOwn(i,s):s in i,l=c?i[s]:hd,d=n.parser(l,t);if(!Wa(d))return u(o,e,d);if(yd(d)){c&&Ht(a,s,l);continue}let f=Mf(o,n,d);if(f)return f}}catch(e){return el(e)}return gd(a)}}_rebuild(e,t,n,r){let i=fp(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new Df(t.name,n)}),a=fp(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new Af(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new jf(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function Mf(e,t,n){if(n._tag===`Failure`)return wf(e,e.ast,t.name,n);if(yd(n))return;let r=n[Kt];if(r!==hd){Ht(e.out,t.name,r);return}if(delete e.out[t.name],!hp(t.type)){let n=new Td([t.name],new Ed(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return ws(new Od(e.ast,[n],e.input,e.options))}}const Nf={onItem(e,t){if(!(t.ownOnly?Object.hasOwn(e.input,t.name):t.name in e.input))return t.parser(hd,e.options);let n=e.input[t.name];return Ht(e.out,t.name,n),t.parser(n,e.options)},step:Mf},Pf=Wo()(Nf),Ise=Ko()(Nf);function Ff(e,t){return e?t?[...e,...t]:e:t}function If(e,t,n){return new jf(Reflect.ownKeys(e).map(t=>new Df(t,e[t].ast)),[],n,t)}function Lse(e){return e.ast}function Lf(e,t,n){return new Hf(e.map(Lse),t,void 0,n)}const Rf=ze(e=>{for(;;){if(sf(e))return gf;let t=e.encoding;if(!t)return e.recur?.(Rf,Me)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==Me))return gf;e=t[t.length-1].to}});function Rse(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(Rse)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function zf(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[fd];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!hp(t)){if(af(t))return[{key:e.name,literal:t.literal}];if(of(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!hp(e)){if(af(e))return[{key:t,literal:e.literal}];if(of(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>zf(Rf(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return zf(e.thunk())}}const zse=new WeakMap,Bf=Object.freeze([]),Bse=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Vse=new Set(Reflect.ownKeys(Object.prototype)).add(`__proto__`),Hse=e=>Vse.has(typeof e==`number`?globalThis.String(e):e),Vf=(e,t)=>Object.hasOwn(e,t)||t in e&&!Hse(t);function Use(e){let t=zse.get(e);if(t)return t;let n,r=0,i,a,o=!0,s=[];for(let t=0;t<e.length;t++){let c=e[t],l=Rf(c);if(wse(l))continue;if(af(l)||of(l)){a??=new Map;let e=af(l)?l.literal:l.symbol;s[t]=e;let n=a.get(e);n||a.set(e,n=[]),n.push(t)}else o=!1;let u=zf(l);if(u.length){n??=new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=Rse(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??Bf);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??Bf;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=new Map;for(let[e,t]of i)a.set(e,Object.freeze(Array.from(t)));let o=Object.freeze(e.map((e,t)=>t));t=(e,t)=>{if($e(e)){let n=Vf(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??Bf;if(t)return o}return Bf}}else if(n){let e;for(let t of n)(!e||t[1][0].size>e[1][0].size)&&t[1][1].size===r&&(e=t);t=(t,r)=>{let a=Bse(t);if(!$e(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=Vf(t,n),u=c?t[n]:void 0;if(c&&(!r||u!==void 0)){let e=i.get(u);if(!e)return l(a);for(let t of e)o.add(t);s=n}}if(s===void 0)for(let[e,[i,a]]of n){let n=Vf(t,e),s=n?t[e]:void 0;if(n&&(!r||s!==void 0)){let e=i.get(s);if(e)for(let t of e)o.add(t)}else if(r)for(let e of a)o.add(e)}for(let[e,[i,a]]of n){if(e===s)continue;let n=Vf(t,e),c=n?t[e]:void 0;if(n&&(!r||c!==void 0)){let e=i.get(c);for(let t of o)a.has(t)&&!e?.has(t)&&o.delete(t)}}return Array.from(o).sort((e,t)=>e-t)}}else t=e=>{let t=l(Bse(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return zse.set(e,t),t}const Hf=class extends ff{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this,r=t!==void 0,i=[],a=t=>i[t]??=e(n.types[t]),o;return(e,t)=>{if(e===hd)return _d;let i=(o??=Use(n.types))(e,r);if(i.length===0)return A(new Md(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:Wa(r)?Uf(n,r.cause,e,t):Wse(n,r,e,t)}return Wf(n,a,i,e,t)}}_rebuild(e,t,n){let r=fp(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new Hf(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=vp(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(af);if(t.length>0)return`${qf(n.isMutable)}[ ${t.map(t=>e(t)+Jf(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>af(e.type));if(t.length>0)return`{ ${t.map(t=>`${qf(t.type.context?.isMutable)}${Mt(t.name)}${Jf(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function Uf(e,t,n,r){let i=Bd(t);return i?ws(new Md(e,[i],n,r)):Cs(t)}function Wse(e,t,n,r){return fl(t,t=>Uf(e,t,n,r))}function Wf(e,t,n,r,i){let a={ast:e,parser:t,input:r,out:void 0,successes:e.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},o=Gse(a,n);if(!o)return a.out?a.out:A(new Md(e,a.issues??[],r,i));if(Wa(o))return Gf(o,a);let s=!0;return Kc(()=>s?(s=!1,Gf(o,a)):Wf(e,t,n,r,i))}function Gf(e,t){return ql(e,e=>t.out?yd(t.out)?k(t.input):t.out:A(new Md(t.ast,t.issues??[],t.input,t.options)))}const Gse=Wo()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=Bd(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(e.ast.types[t]),ws(new Koe(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return Ts}}}),Kf=new Hf([new _f(`Infinity`),new _f(`-Infinity`),new _f(`NaN`)]);function qf(e){return e?``:`readonly `}function Jf(e){return e?`?`:``}const Yf=class extends je{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new Yf(this.run,{...this.annotations,...e},this.aborted)}abort(){return new Yf(this.run,this.annotations,!0)}and(e,t){return new Xf([this,e],t)}},Xf=class extends je{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new Xf(this.checks,{...this.annotations,...e})}and(e,t){return new Xf([this,e],t)}};function Zf(e,t,n=!1){return new Yf((t,n,r)=>Joe(n,e(t,n,r),t,r),t,n)}function Kse(e){return Zf(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}const qse=new cf(new Hf([sp(xf,[Kse()]),Kf]),new Yd(qd(),Wd(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function Qf(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return Zf(e=>(n.lastIndex=0,n.test(e)),{expected:`a string matching the RegExp ${r.source}`,representation:{id:`effect/schema/isPattern`,payload:r},toJsonSchema:()=>[{},!0],arbitraryConstraint:{patterns:[r]},...t})}const $f=new WeakMap;function ep(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&$f.set(n,tp(e)),n}function tp(e){let t=$f.get(e);if(t!==void 0)return t;if(e.encoding===void 0)return e;let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,{encoding:void 0});return $f.set(e,n),n}function np(e,t){return e.encoding===t?e:ep(e,{encoding:t})}function rp(e,t){if(e.context===t)return e;let n=tp(e);return n.context===t&&n.encoding===e.encoding?n:ep(e,{context:t})}function ip(e){return e.encoding?ip(e.encoding[e.encoding.length-1].to):e}function ap(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return op(e,Kr(e.checks.slice(0,-1),n.annotate(t)))}return ep(e,{annotations:{...e.annotations,...t}})}function op(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:ep(e,{checks:t})}function sp(e,t){return op(e,Ff(e.checks,t))}function cp(e,t){let n=t(e.to);return n===e.to?e:new cf(n,e.transformation)}function lp(e,t){let n=e,r=n[n.length-1],i=cp(r,t);return i===r?e:Kr(e.slice(0,e.length-1),i)}function up(e){return t=>t.encoding?np(t,lp(t.encoding,e)):t}function Jse(e,t){return up(e=>rp(e,t))(e)}function dp(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:np(r,lp(r.encoding,n))}return e(r)}return ze(n)}function Yse(e,t,n){let r=new cf(e,t);return np(n,n.encoding?[...n.encoding,r]:[r])}function fp(e,t){let n;for(let r=0;r<e.length;r++){let i=e[r],a=t(i);if(n)n[r]=a;else if(a!==i){n=Array(e.length);for(let t=0;t<r;t++)n[t]=e[t];n[r]=a}}return n??e}function pp(e,t){return rp(e,e.context?new uf(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new uf(!1,!1,void 0,t))}const mp=ze(e=>{let t=e.context?e.context.isOptional===!1?new uf(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new uf(!0,!1);return Xse(rp(e,t))}),Xse=up(mp),Zse=Re(e=>mp(new Hf([e,hf])));function Qse(e,t){return rp(e,e.context?new uf(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new uf(!1,!1,t))}function $se(e,t,n){return Yse(e,n,t)}function ece(e){let t=[],n=[];function r(e){t.includes(e)||t.push(e)}function i(e){switch(e._tag){case`Literal`:yee(e.literal)&&r(e.literal);return;case`UniqueSymbol`:r(e.symbol);return;case`Enum`:for(let[,t]of e.enums)r(t);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)i(e.types[t]);return;default:n.push(e)}}return i(e),{literals:t,parameters:n}}function tce(e,t){let{literals:n,parameters:r}=ece(e);return new jf(n.map(e=>new Df(e,t)),r.map(e=>new Af(e,t)))}function hp(e){return e.context?.isOptional??!1}function gp(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(gp)}function nce(e){function t(e){return gp(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return Rte(n)?n:void 0}function rce(e){let t=!0;function n(e){return t=t&&!e.encoding&&!sf(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}const _p=ze(e=>{let t=tp(e);if(t!==e){let n=_p(t);return n===t&&e.encoding===void 0?e:rp(n,e.context)}let n=`recur`in e?e.recur(_p):e;return`encodingChecks`in n&&n.encodingChecks?ep(n,{encodingChecks:void 0,checks:Ff(rce(e)?n.encodingChecks:Tse(n)||Ese(n)||rf(n)&&n.typeParameters.length>0?nce(n.encodingChecks):void 0,n.checks)}):n}),vp=ze(e=>_p(yp(e)));function ice(e,t){let n=t,r=n.length,i=n[r-1],a=[new cf(yp(np(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new cf(yp(n[e-1].to),n[e].transformation.flip()));let o=yp(i.to);return o.encoding?np(o,[...o.encoding,...a]):np(o,a)}const yp=Re(e=>{if(e.encoding)return ice(e,e.encoding);let t=tp(e);if(t!==e){let n=yp(t);return n===t?e:rp(n,e.context)}return`flip`in e?e.flip(yp):`recur`in e?e.recur(yp):e});function bp(e,t){let n=t===0?vd:gd(t);return(r,i)=>r===hd?_d:r===t?n:A(new kd(e,r,i))}function xp(e,t){return(n,r)=>n===hd?_d:t(n)?vd:A(new kd(e,n,r))}const Sp=dp(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(Sp)}}),Cp=dp(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(Cp)}}),wp=new globalThis.RegExp(`^${Tf}$`),ace=new globalThis.RegExp(`^(?:${Tf}|Infinity|-Infinity|NaN)$`);function oce(e){return Qf(wp,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:wp.source}),...e})}const Tp=sp(yf,[oce()]),sce=new cf(Tp,ef),cce=new cf(new Hf([Tp,Kf]),ef),Ep=new globalThis.RegExp(`^-?\\d+$`);function lce(e){return Qf(Ep,{expected:`a string representing a bigint`,representation:{id:`effect/schema/isStringBigInt`,payload:null},toJsonSchema:()=>({pattern:Ep.source}),...e})}const uce=new cf(sp(yf,[lce({expected:`a string representing a bigint`})]),hse);function Dp(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=Dp(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new Woe(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function Op(e){if(!rf(e))return;let t=e.annotations?.[pd];return Ye(t)?t(e.typeParameters):void 0}function dce(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function fce(e){return e===void 0||typeof e==`string`}function kp(e,t){let n=new WeakMap,r=[];outer:for(;;){if(typeof e!=`object`||!e){if(!t(e))return!1}else{let t=e,i=n.get(t);if(i===!1)return!1;if(i===void 0){let e=Array.isArray(t);if(!e){let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null)return!1}n.set(t,!1),r.push({value:t,keys:e?t.length:Object.keys(t),index:0})}}for(;r.length>0;){let t=r[r.length-1],i=t.keys;if(typeof i==`number`){if(t.index<i){e=t.value[t.index++];continue outer}}else if(t.index<i.length){e=t.value[i[t.index++]];continue outer}n.set(t.value,!0),r.pop()}return!0}}function pce(e){return kp(e,dce)}const mce=new pf([],()=>(e,t,n)=>pce(e)?vd:A(new kd(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>Ap});function hce(e){return kp(e,fce)}const Ap=new cf(new pf([],()=>(e,t,n)=>hce(e)?vd:A(new kd(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),$d()),jp=(e,t,n)=>yd(e)?n(t):ql(e,n);function Mp(e){let t=gce(e);return(e,n,r)=>{try{return t(e,n,r)}catch(e){return el(e)}}}function gce(e){if(e._tag===`Middleware`)return(t,n,r)=>{let i=yd(t)?e.decode(gd(bd(n)),r):e.decode(Vae(t,bd),r);return Np(i)};let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>yd(e)?gd(t):e;case`Transform`:{let e=e=>e===hd?_d:gd(t.transform(e));return(t,n)=>jp(t,n,e)}case`TransformOptional`:{let e=e=>xd(t.transform(bd(e)));return(t,n)=>jp(t,n,e)}case`TransformEffect`:return(e,n,r)=>jp(e,n,e=>e===hd?_d:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>jp(e,n,e=>Np(t.transform(bd(e),r)))}}const Np=e=>ql(e,xd),Pp=(e,t,n,r)=>fl(r,r=>$c(()=>_s(r,r=>new Goe(e,r,t,n))));function _ce(e,t){let n=Mp(e.link.transformation),r;return(i,a)=>{if(i===hd)return _d;if(e.isConstructed(i))return vd;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function vce(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==hd&&r!==void 0)return t(r,i);let a=n;if(Wa(a)&&a._tag===`Success`){let e=t(a[Kt],i);return yd(e)?a:e}return ql(Pp(e,r,i,a),e=>{let n=t(e,i);return yd(n)?gd(e):n})}}function yce(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:vce(e,n)}function Fp(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?Op(e):void 0,o=a?_ce(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Mp(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);try{if(u&&!n.disableChecks){if(Wa(r)){if(r._tag===`Success`){let i=yd(r)?t:r[Kt];if(t!==hd&&i!==hd){let i=Dp(u,t,void 0,e,n);i&&(r=A(new Od(e,i,t,n)))}}}else r=j(r,r=>{if(t!==hd&&r!==hd){let r=Dp(u,t,void 0,e,n);if(r)return A(new Od(e,r,t,n))}return k(r)})}if(s&&!n.disableChecks){if(Wa(r)){if(r._tag===`Success`){let i=yd(r)?t:r[Kt];if(i===hd)return r;let a=Dp(s,i,void 0,e,n);a&&(r=A(new Od(e,a,i,n)))}}else r=j(r,t=>{if(t!==hd){let r=Dp(s,t,void 0,e,n);if(r)return A(new Od(e,r,t,n))}return k(t)})}return r}catch(e){return el(e)}},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[Kt],o=t(a,r)):o=ql(o,e=>{let n=t(e,r);return yd(n)?gd(e):n})}if(o._tag===`Success`){let e=o[Kt],t=p(e,r);return yd(t)?o:t}return o=Pp(e,n,r,o),ql(o,e=>{let t=p(e,r);return yd(t)?gd(e):t})}:p}const bce=Symbol(),Ip=new WeakMap,xce=e=>Rp(e).parser,Lp=e=>Rp(e).makeEffect,Sce=e=>yce(e,Lp);var Cce=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Fp(this.ast,xce)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Fp(this.ast,Lp,Sce)}};function Rp(e){let t=Ip.get(e);if(t!==void 0)return t;let n=new Cce(e);return Ip.set(e,n),n}function zp(e){let t=e.ast,n;return(e,r)=>(n??=Gp(Ice,_p(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Bp(e){let t=zp(e);return(e,n)=>{let r=Gl(t(e,n));return Es(r)?nr(r.value):(Vd(r.cause,`Option adapter can only return none for schema issues`),O())}}function wce(e){return Nce(_p(e.ast))}function Tce(e){return Dce(e.ast)}function Ece(e){{let t=Kp(Wp(e));return e=>{let n=t(e,lf);return Es(n)?!0:(Vd(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Dce(e){let t=_p(e),n=e=>(n=Ece(t),n(e));return e=>n(e)}function Vp(e,t){let n=Wp(e.ast);return t===void 0?n:(e,r)=>n(e,Hp(t,r))}function Oce(e,t){return jce(Vp(e,t))}function kce(e,t){let n=Wp(yp(e.ast));return t===void 0?n:(e,r)=>n(e,Hp(t,r))}const Hp=(e,t)=>t?{...e,...t}:e,Up=e=>e===hd?A(new Ad):k(e);function Wp(e){return Gp(Fce,e)}function Ace(e,t){return yd(e)?k(t):Wa(e)?e[Kt]===hd?Up(hd):e:ql(e,Up)}function Gp(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??lf);return yd(a)?k(r):Wa(a)?a[Kt]===hd?Up(hd):a:ql(a,Up)}}function Kp(e){return(t,n)=>Gl(e(t,n))}function jce(e){let t=Kp(e);return(e,n)=>{let r=t(e,n);return Es(r)?nr(r.value):(Vd(r.cause,`Option adapter can only return none for schema issues`),O())}}function Mce(e,t){let n=Gl(e);if(Es(n))return n.value;let r=Vd(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}const qp=`Constructor adapter can only throw schema issues`;function Jp(e){throw Error(qp,{cause:Mie(e)})}function Nce(e){let t;return(n,r)=>Yp(t??=Rp(e),n,r)}function Yp(e,t,n){let r=n?.disableChecks?n.parseOptions?{...n.parseOptions,disableChecks:!0}:{disableChecks:!0}:n?.parseOptions??lf,i=e.make;if(i!==void 0&&t!==hd){let e;try{e=i(t,r)}catch(e){Jp(e)}if(e!==bce&&e!==hd)return e}return Mce(Ace(e.makeEffect(t,r),t),qp)}function Pce(e,t,n,r){let i=Rp(e),a=Op(e);if(a===void 0||i.make!==void 0||i.compiledMakeEffect!==void 0)return Yp(i,t,n);if(a.isConstructed(t))return t;let o=Yp((i.resolve??Rp)(a.link.to),t,n);try{return r(o)}catch(e){Jp(e)}}const Fce=e=>Rp(e).parser,Ice=e=>Rp(e).makeEffect,Xp=`~effect/Schema/Schema`,Zp=Symbol(),Lce={[Xp]:Xp,get make(){let e=wce(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=zp(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=Bp(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return Ae(this,arguments)},annotate(e){return this.rebuild(ap(this.ast,e))},annotateKey(e){return this.rebuild(pp(this.ast,e))},check(...e){return this.rebuild(sp(this.ast,e))},rebuild(e){return Qp(e,this[Zp])}};function Qp(e,t){function n(){}let r=Object.setPrototypeOf(n,Lce);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r[Zp]=t,r.ast=e,r}function Rce(e,t){let n=Re(t=>{let n=rp(t,void 0),i=e(n,r);return i===n?null:i}),r=dp(e=>{let t=n(tp(e));if(t===null)return e;let r=rp(t,e.context);return e.context===void 0?r:Jse(r,zce(e.context))},t);return r}function zce(e){return e.constructorDefault===void 0?e:new uf(e.isOptional,e.isMutable,void 0,e.annotations)}function Bce(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function Vce(e){return t=>{let n=[...t].sort((t,n)=>e(vp(t))-e(vp(n)));return n.some((e,n)=>e!==t[n])?n:t}}function Hce(e){return Qp(Jce(e.ast),{schema:e})}const Uce=Vce(e=>{switch(e._tag){case`Null`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function Wce(e,t,n){switch(e._tag){case`Declaration`:{let r=e.typeParameters.map(e=>Qp(t(vp(e)))),i=e.annotations?.toCodecStringTree;if(Ye(i)){let n=i(r);return n===void 0?e:np(e,[cp(n,t)])}let a=e.annotations?.toCodecJson,o=Ye(a)?a(r):void 0,s=o===void 0?e.annotations?.toCodec:void 0,c=o??(Ye(s)?s(r):void 0);return c===void 0?n(e):np(e,[cp(c,t)])}case`Null`:return np(e,[Gce]);case`Boolean`:return np(e,[Kce]);case`Unknown`:case`ObjectKeyword`:return np(e,[Ap]);case`Enum`:case`Number`:case`Literal`:case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return Bce(e),e.recur(t,Cp);case`Union`:{let n=Uce(e.types);return n===e.types?e.recur(t):new Hf(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}const Gce=new cf(new _f(`null`),new Yd(Wd(()=>null),Wd(()=>`null`))),Kce=new cf(new Hf([new _f(`true`),new _f(`false`)]),new Yd(Wd(e=>e===`true`),Kd())),qce=new Yd(Wd(e=>typeof e==`string`?[e]:e),Ud()),Jce=Rce((e,t)=>Wce(e,t,e=>{throw new globalThis.Error(`Missing structural codec for StringTree`,{cause:e})}),{stopAt:e=>e.transformation===qce}),$p=e=>e,em=`~effect/Schema/SchemaError`;function Yce(e){return et(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}({...Lt}),{...Lt},{...Lt},{...Lt},{...Lt},{...Lt},{...Lt},{...Lt};const tm=`~effect/SemVer`,nm=`~effect/SemVer/SemVerError`;var rm=class extends Bi(`SemVerError`){[nm]=nm};const Xce=e=>et(e,nm),im=e=>{throw new rm({message:e})},Zce=e=>Nte({try:e,catch:e=>{if(!Xce(e))throw e;return e}}),Qce=(e,t,n)=>Pte(Zce(()=>n(t)),n=>new rm({message:`Invalid ${e} ${JSON.stringify(t)}: ${n.message}`,input:t})),$ce=/^(?:0|[1-9]\d*)$/,ele=/^\d+$/,am=/^[0-9A-Za-z-]+$/,om=(e,t)=>!Number.isSafeInteger(e)||e<0?im(`${t} must be a non-negative safe integer, received ${e}`):e,sm=(e,t)=>$ce.test(e)?om(Number(e),t):im(`${t} must be a non-negative integer without leading zeros, received ${JSON.stringify(e)}`),cm=e=>typeof e==`number`?om(e,`numeric pre-release identifier`):am.test(e)?ele.test(e)?sm(e,`numeric pre-release identifier`):e:im(`pre-release identifier must be non-empty [0-9A-Za-z-], received ${JSON.stringify(e)}`),lm=e=>am.test(e)?e:im(`build identifier must be non-empty [0-9A-Za-z-], received ${JSON.stringify(e)}`),tle=(e,t)=>{if(e.length===0)return t.length===0?0:1;if(t.length===0)return-1;let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e[r],i=t[r];if(n!==i)return typeof n==`number`?typeof i==`number`?Qn(n,i):-1:typeof i==`number`?1:Zn(n,i)}return Qn(e.length,t.length)},nle=(e,t)=>Qn(e.major,t.major)||Qn(e.minor,t.minor)||Qn(e.patch,t.patch)||tle(e.prerelease,t.prerelease),rle={[tm]:tm,[_t](e){return ile(e)&&lle(this,e)},[nt](){return ut(dm(this))},toString(){return`SemVer(${dm(this)})`},toJSON(){return{_id:`SemVer`,value:dm(this)}},[Ft](){return this.toJSON()},pipe(){return Ae(this,arguments)}},um=(e,t,n,r,i)=>{let a=Object.create(rle);return a.major=e,a.minor=t,a.patch=n,a.prerelease=r,a.build=i,a},ile=e=>et(e,tm),ale=e=>um(om(e.major,`major`),om(e.minor,`minor`),om(e.patch,`patch`),e.prerelease?.map(cm)??[],e.build?.map(lm)??[]),ole=e=>{let t=e,n=[],r=t.indexOf(`+`);r!==-1&&(n=t.slice(r+1).split(`.`).map(lm),t=t.slice(0,r));let i=[],a=t.indexOf(`-`);a!==-1&&(i=t.slice(a+1).split(`.`).map(cm),t=t.slice(0,a));let o=t.split(`.`);return o.length===3?um(sm(o[0],`major`),sm(o[1],`minor`),sm(o[2],`patch`),i,n):im(`expected MAJOR.MINOR.PATCH`)},sle=e=>Qce(`SemVer`,e,ole),dm=e=>{let t=`${e.major}.${e.minor}.${e.patch}`;return e.prerelease.length>0&&(t+=`-${e.prerelease.join(`.`)}`),e.build.length>0&&(t+=`+${e.build.join(`.`)}`),t},cle=Xn(nle),fm=ste(ote()),lle=In((e,t)=>e.major===t.major&&e.minor===t.minor&&e.patch===t.patch&&fm(e.prerelease,t.prerelease)&&fm(e.build,t.build)),ule=er(cle),pm=Xp;function dle(){return(e,t,n)=>Sm(new pf(e.map(Lse),e=>t(e.map(e=>Sm(e))),n))}function mm(e,t){return dle()([],()=>(t,n,r)=>e(t)?k(t):A(new kd(n,t,r)),t)}var hm=class extends Bi(`SchemaError`){[em]=em;constructor(e){let t=Rt();zt(0);try{super({issue:e})}finally{zt(t)}}get message(){return $oe(this.issue)}toJSON(){return{_tag:this._tag,message:this.message}}[Ft](){return this.toJSON()}toString(){return`SchemaError(${this.message})`}};function fle(e){return Yce(e)}function gm(e){return Wa(e)?ple(e):fl(e,e=>$c(()=>_s(e,e=>new hm(e))))}function ple(e){return Es(e)?e:Cs(_s(e.cause,e=>new hm(e)))}function mle(e,t){let n;for(let r of e.reasons){if(!ms(r)||!fle(r.error))throw new globalThis.Error(t,{cause:e});n??=r.error}if(n===void 0)throw new globalThis.Error(t,{cause:e});return n}function hle(e){let t=Gl(e);if(Es(t))return t.value;throw mle(t.cause,`Sync adapter can only throw schema errors`)}const _m=Tce;function vm(e,t){let n=Vp(e,t);return(e,t)=>gm(n(e,t))}const ym=Oce;function bm(e,t){let n=vm(e,t);return(e,t)=>hle(n(e,t))}function gle(e,t){let n=kce(e,t);return(e,t)=>gm(n(e,t))}const xm=gle,Sm=Qp;function _le(e){return et(e,pm)&&e[pm]===pm}const Cm=$p(e=>Sm(mp(e.ast),{schema:e})),wm=$p(e=>{let t=Cle(e);return Sm(Zse(e.ast),{schema:t})});function Tm(e){let t=Sm(new _f(e),{literal:e,transform(n){return t.pipe(Mm(Tm(n),{decode:Wd(()=>n),encode:Wd(()=>e)}))}});return t}const Em=Sm(gf),vle=Sm(mf),yle=Sm(hf),P=Sm(yf),ble=Sm(xf),Dm=Sm(Ase),xle=Sm(jse);function Om(e,t){return Sm(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Om(If(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function F(e){return Om(If(e,void 0),e)}function Sle(e,t){return Sm(tce(e.ast,t.ast),{key:e,value:t})}const I=$p(e=>Sm(new Sf(!1,[],[e.ast]),{value:e}));function km(e,t){return Sm(e,{members:t,mapMembers(e,t){let n=e(this.members);return km(Lf(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Am(e,t){return km(Lf(e,t,void 0),e)}function jm(e){let t=e.map(Tm);return Sm(Lf(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return Am(e(this.members))},pick(e){return jm(e)},transform(e){return Am(t.map((t,n)=>t.transform(e[n])))}})}const L=$p(e=>Am([e,vle])),Cle=$p(e=>Am([e,yle]));function Mm(e,t){return n=>Sm($se(n.ast,e.ast,t?Xd(t):$d()),{from:n,to:e})}function wle(){return(e,t)=>Lm()(e,{decode:t,encode:nse})}const Nm=jm([`true`,`yes`,`on`,`1`,`y`]),Pm=jm([`false`,`no`,`off`,`0`,`n`]),Tle=jm([...Nm.literals,...Pm.literals]).pipe(Mm(Dm,Qd({decode:e=>e===`true`||e===`yes`||e===`on`||e===`1`||e===`y`,encode:e=>e?`true`:`false`})));function Ele(e){return t=>Sm(Qse(t.ast,e),{schema:t})}function Fm(e){return Tm(e).pipe(Ele(k(e)))}function Im(e,t){return F({_tag:Fm(e),...t})}function Dle(e,t){return mm(t=>t instanceof e,t)}function Lm(){return(e,t)=>new cf(e.ast,Xd(t))}const Rm=Zf;function zm(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new globalThis.RegExp(${jt(n)})`:`new globalThis.RegExp(${jt(n)}, ${jt(r)})`;return Qf(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}function Ole(e){let t=vte(e.order),n=tr(e.order),r=_te(e.order),i=er(e.order),a=e.formatter??jt;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return Rm(e=>c(e,o.minimum)&&l(e,o.maximum),{expected:`a value between ${a(o.minimum)}${o.exclusiveMinimum?` (excluded)`:``} and ${a(o.maximum)}${o.exclusiveMaximum?` (excluded)`:``}`,arbitraryConstraint:{order:e.order,minimum:o.minimum,maximum:o.maximum,...o.exclusiveMinimum&&{exclusiveMinimum:!0},...o.exclusiveMaximum&&{exclusiveMaximum:!0}},...e.annotate?.(o),...s})}}function Bm(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${jt(e)}`);return e}const Vm=Ole({order:Qn,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:Bm(e.minimum),maximum:Bm(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${jt(e.minimum)}, maximum: ${jt(e.maximum)}, exclusiveMinimum: ${jt(t)}, exclusiveMaximum: ${jt(n)} })`})}}});function kle(e){return Rm(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>({type:`integer`,minimum:globalThis.Number.MIN_SAFE_INTEGER,maximum:globalThis.Number.MAX_SAFE_INTEGER}),toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}const Hm=ble.check(kle());function Um(e,t){return e=jle(e),Wm(e,Math.ceil(e/2),t)}function Wm(e,t,n){return Rm(t=>t.length>=e,{expected:`a value with a length of at least ${e}`,representation:{id:`effect/schema/isMinLength`,payload:{minLength:e}},toJsonSchema:({type:n})=>n===`string`?e<=1?{minLength:t}:[{minLength:t},!0]:n===`array`?{minItems:e}:n===void 0?[{minLength:t,minItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMinLength(${e})`}),"~structural":!0,arbitraryConstraint:{minLength:e},...n})}function Ale(e){return Wm(1,1,e)}function jle(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${e}`);return Math.max(0,Math.floor(e))}const Gm=P.check(Ale()),Mle=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),Nle=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},Km=[];function Ple(e){let t=Mle(e),n=Km[t];if(n!==void 0)return n;let r=Jle.pipe(Mm(Em,xse(Nle(t))));return Km[t]=r,r}globalThis.RegExp,globalThis.URL;const Fle=P.annotate({expected:`a string that will be decoded as JSON`});function qm(e,t){return Fle.pipe(Mm(e,Cse(t)))}globalThis.File,globalThis.URLSearchParams;const Ile=P.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),Lle=Dle(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>Lm()(Ile,Sse)}),Jm=Zd({decode:(e,t)=>ar(rd(e),{onNone:()=>A(new Ad({expected:`a valid UTC DateTime string`},e,t)),onSome:e=>k(zoe(e))}),encode:e=>k(od(e))});function Rle(e,t,n){let r=Math.max(t,e?.minimum===void 0?t:e.minimum.epochMilliseconds+ +(e.exclusiveMinimum===!0)),i=Math.min(n,e?.maximum===void 0?n:e.maximum.epochMilliseconds-+(e.exclusiveMaximum===!0));return r<=i?[r,i]:[t,n]}function zle(e,t){return Hm.check(Vm({minimum:e,maximum:t}))}const Ble=mm(e=>Loe(e)&&Roe(e),{representation:{id:`effect/schema/DateTimeUtc`,payload:null},toCode:()=>({runtime:`Schema.DateTimeUtc`,Type:`DateTime.Utc`,importDeclarations:[`import * as DateTime from "effect/DateTime"`]}),expected:`DateTime.Utc`,toCodecArbitrary:({constraint:e})=>{let[t,n]=Rle(e,-864e13,864e13);return wle()(zle(t,n),Wd(nd))},toCodecJson:()=>Lm()(P,Jm),toFormatter:()=>e=>e.toString()}),Ym=P.annotate({expected:`a string that will be decoded as a DateTime.Utc`}).pipe(Mm(Ble,Jm)),Vle=Zd({decode:(e,t)=>ar(vi(e),{onNone:()=>A(new Ad({expected:`a valid Duration string`},e,t)),onSome:k}),encode:e=>k(globalThis.String(e))}),Hle=mm(xi,{representation:{id:`effect/schema/Duration`,payload:null},toCode:()=>({runtime:`Schema.Duration`,Type:`Duration.Duration`,importDeclarations:[`import * as Duration from "effect/Duration"`]}),expected:`Duration`,toCodecJson:()=>Lm()(Am([F({_tag:Tm(`Infinity`)}),F({_tag:Tm(`NegativeInfinity`)}),F({_tag:Tm(`Nanos`),value:xle}),F({_tag:Tm(`Millis`),value:Hm})]),Qd({decode:e=>{switch(e._tag){case`Infinity`:return wi;case`NegativeInfinity`:return Ti;case`Nanos`:return Ei(e.value);case`Millis`:return Di(e.value)}},encode:e=>{switch(e.value._tag){case`Infinity`:return{_tag:`Infinity`};case`NegativeInfinity`:return{_tag:`NegativeInfinity`};case`Nanos`:return{_tag:`Nanos`,value:e.value.nanos};case`Millis`:return{_tag:`Millis`,value:e.value.millis}}}}))}),Ule=P.annotate({expected:`a string that will be decoded as a Duration`}).pipe(Mm(Hle,Vle)),Wle=globalThis.Symbol.for(`immer-draftable`),Xm={};function Zm(e,t,n,r,i){let a=Kle(n,t,r),o=$m(t),s=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===Xm?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:Xm,value:i}})}static[pm]=pm;get[o](){return o}static[Wle]=!0;static identifier=t;static fields=n.fields;static get ast(){return a(this).ast}static pipe(){return Ae(this,arguments)}static rebuild(e){return a(this).rebuild(e)}static make(e,t){return Pce(_p(a(this).ast),e??{},t,e=>Qm(this,e))}static makeOption(e,t){return Bp(a(this))(e??{},t)}static makeEffect(e,t){return a(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(ap(this.ast,e))}static annotateKey(e){return this.rebuild(pp(this.ast,e))}static check(...e){return this.rebuild(sp(this.ast,e))}static extend(e){return(t,r)=>{let a=eh(t)?t:F(t),o={...n.fields,...a.fields},s=If(o,n.ast.checks,{identifier:e});return Zm(this,e,Om(sp(s,a.ast.checks),o),r,i)}}static mapFields(e,t){return n.mapFields(e,t)}};return i!==void 0&&Object.assign(s.prototype,i(t)),s}function Qm(e,t){return new e(t,{"~payload":{token:Xm,value:t}})}function Gle(e){return new Yd(Wd(t=>Qm(e,t)),Ud())}function $m(e){return`~effect/Schema/Class/${e}`}function Kle(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=$m(t),o=e=>e instanceof i||et(e,a),s=Gle(i);return r=Mm(Sm(new pf([e.ast],()=>(e,t,n)=>o(e)?k(e):A(new kd(t,e,n)),{identifier:t,[pd]:([e])=>({isConstructed:o,link:new cf(e,s)}),toCodec:([e])=>new cf(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[fd]:zf(e.ast),...n})),s)(e)}}function eh(e){return _le(e)}const th=e=>(t,n)=>{let r=eh(t)?t:F(t);return Zm(kn,e,r,n,e=>({name:e}))},nh=e=>(t,n,r)=>{let i=eh(n)?n.mapFields(e=>({_tag:Fm(t),...e}),{unsafePreserveChecks:!0}):Im(t,n);return th(e??t)(i,r)},qle=Hce,Jle=Sm(ap(mce,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})}));function rh(){return Object.assign(e=>e,{option:e=>nr(e),result:e=>zr(e),is:e=>!0})}const Yle=die,ih=`~effect/MutableRef`,Xle={[ih]:ih,...Qt,toJSON(){return{_id:`MutableRef`,current:It(this.current)}}},ah=e=>{let t=Object.create(Xle);return t.current=e,t},Zle=D(2,(e,t)=>(e.current=t,e)),oh=`~effect/Channel`,sh=e=>et(e,oh),Qle={[oh]:{_Env:Me,_InErr:Me,_InElem:Me,_OutErr:Me,_OutElem:Me},pipe(){return Ae(this,arguments)}},ch=e=>{let t=Object.create(Qle);return t.transform=(t,n)=>fl(e(t,n),e=>k(Qc(e))),t},lh=(e,t)=>ch((n,r)=>j(fh(e)(n,r),e=>t(e,r))),uh=e=>ch((t,n)=>e),dh=e=>ch(N(function*(t,n){let r=Us(n),i=e=>Ws(r,Oc(e)),a=yield*Fl(e(t,n,r),i);return Fl(a,i)})),fh=e=>e.transform,$le=(e,t,n)=>iu({capacity:n?.bufferSize,strategy:n?.strategy}).pipe(al(t=>Vs(e,du(t))),al(n=>zs(t(n),e).pipe(fl(e=>cu(n,e)),Vl(e,{startImmediately:!0})))),eue=(e,t)=>ch((n,r)=>M($le(r,e,t),Qae)),tue=e=>ch((t,n)=>Kc(()=>fh(e())(t,n))),nue=e=>oue(k(e)),rue=uh(k(xs())),iue=uh(k(Xc)),aue=e=>uh(k(A(e))),oue=e=>uh(qc(()=>{let t=!1;return Kc(()=>t?xs():(t=!0,e))})),sue=e=>uh(j(e,()=>xs())),cue=D(2,(e,t)=>lh(e,e=>qc(()=>{let n=0;return M(e,e=>t(e,n++))}))),lue=D(2,(e,t)=>uue(e,e=>k(t(e)))),uue=D(2,(e,t)=>lh(e,e=>k(wc(e,e=>j(t(e),xs))))),due=e=>e===void 0||e!==`unbounded`&&e<=1,fue=D(e=>sh(e[0]),(e,t,n)=>due(n?.concurrency)?pue(e,t):mue(e,t,n)),pue=(e,t)=>ch((n,r)=>{let i=0;return M(fh(e)(n,r),j(e=>t(e,i++)))}),mue=(e,t,n)=>dh(N(function*(r,i,a){let o=0,s=yield*fh(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:Math.min(n.concurrency,2**53-1),l=yield*au(0);yield*Vs(a,du(l));let u=Wl(yield*Tl()),d=Zl(a);if(n.unordered){let e=Eu(c),n=Ne(e.release(1)),r=wl({onFailure:e=>j(cu(l,e),n),onSuccess:e=>j(ou(l,e),n)});yield*e.take(1).pipe(j(()=>s),j(e=>{let n=o++;return d(u(r(Kc(()=>t(e,n))))),Jc}),zl({disableYield:!0}),fl(t=>e.withPermits(c-1)(cu(l,t))),Vl(a))}else{let e=yield*au(c-2);yield*Vs(a,du(e)),yield*pu(e).pipe(rl,j(e=>ou(l,e)),zl({disableYield:!0}),fl(e=>cu(l,e)),Vl(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,lu(l,e.cause))};yield*s.pipe(j(i=>{if(n)return Qc(n);let a=o++,s=u(Kc(()=>t(i,a)));return d(s),s.addObserver(r),ou(e,Yl(s))}),zl({disableYield:!0}),fl(t=>ou(e,Cs(t)).pipe(il(cu(e,t)))),Vl(a))}return pu(l)})),hue=e=>lh(e,e=>{let t,n=0,r=Kc(function r(){if(t===void 0)return j(e,e=>{switch(e.length){case 0:return r();case 1:return k(e[0]);default:return t=e,k(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),k(i)});return k(r)}),gue=D(2,(e,t)=>ch((n,r)=>{let i=Us(r);return M(fh(e)(n,i),e=>{let a=e.pipe(fl(e=>{if(Tc(e))return Qc(e);let o=i;return i=Us(r),Ws(o,Cs(e)).pipe(il(fh(t(e))(n,i)),j(e=>(a=e,e)))}));return Kc(()=>a)})})),_ue=D(2,(e,t)=>lh(e,e=>k(_l(e,e=>ys(e)?Jc:ll(t(e)))))),ph=D(e=>sh(e[0])&&sh(e[1]),(e,t,n)=>dh(N(function*(r,i,a){let o=n?.haltStrategy??`both`,s=yield*au(0);yield*Vs(a,du(s));let c=0;function l(e,t){if(c++,!Tc(t))return cu(s,t);switch(o){case`both`:return c===2?cu(s,t):Jc;case`left`:case`right`:return e===o?cu(s,t):Jc;case`either`:return cu(s,t)}}let u=(e,t,n)=>fh(t)(r,n).pipe(j(e=>e.pipe(j(e=>ou(s,e)),zl)),Fl(t=>Iae(Oc(t),e=>Ws(n,e)).pipe(wl({onFailure:t=>l(e,t),onSuccess:()=>l(e,t)}))),Vl(a));return yield*u(`left`,e,Us(a)),yield*u(`right`,t,Us(a)),pu(s)}))),vue=D(2,(e,t)=>ph(e,sue(t),{haltStrategy:`left`})),yue=()=>ch((e,t)=>qc(()=>{let t=``,n=!1,r=O();function i(e){let r=[];function i(e){t.length===0?r.push(e):(r.push(t+e),t=``)}for(let r=0;r<e.length;r++){let a=e[r];if(a.length!==0){let e=0,r=a.indexOf(`\r`),o=a.indexOf(`
17
+ `);for(n&&=(o===0&&(e=1,o=a.indexOf(`
18
+ `,e)),!1);r!==-1||o!==-1;)r===-1||o!==-1&&o<r?(i(a.substring(e,o)),e=o+1,o=a.indexOf(`
19
+ `,e)):(i(a.substring(e,r)),a.length===r+1?(n=!0,e=a.length,r=-1):(e=r+(o===r+1?2:1),r=a.indexOf(`\r`,e),o=a.indexOf(`
20
+ `,e)));t+=a.substring(e)}}return qr(r)?r:null}let a=Kc(()=>r._tag===`Some`?xs(r.value):kc(e,{onSuccess:o,onFailure:Qc,onDone:e=>{if(r=nr(e),t.length>0){let e=t;return t=``,n=!1,k([e])}return xs(e)}}));function o(e){let t=i(e);return t===null?a:k(t)}return a})),bue=(e,t)=>ch((n,r)=>qc(()=>{let r=new TextDecoder(e,t),i={stream:!0},a=n.pipe(M(Zr(e=>r.decode(e,i))),wc(e=>{a=xs(e);let t=r.decode();return t.length>0?k(Xr(t)):a}));return Kc(()=>a)})),mh=D(2,(e,t)=>ch((n,r)=>j(fh(e)(n,r),e=>fh(t)(e,r)))),hh=e=>e._tag===`Die`&&ys(e.defect)&&Aie(e.defect.value),xue=e=>e.reasons.some(hh),Sue=e=>fl(e,e=>Tc(e)?Qc(e):el(bs(e))),Cue=e=>xue(e)?hs(e.reasons.flatMap(e=>hh(e)?e.defect.value.reasons:[e])):e,wue=e=>fl(e,e=>Qc(Cue(e))),gh=e=>ch((t,n)=>{let r;return k(Kc(()=>r||e.pipe(zs(n),j(e=>fh(e)(t,n)),j(e=>r=e))))}),_h=(e,t,n)=>Kc(()=>{let r=Rs(),i=fh(e)(xs(),r);return wc(j(i,t),n||k).pipe(Il(e=>Ws(r,e)))}),Tue=e=>_h(e,e=>zl(e,{disableYield:!0})),vh=D(3,(e,t,n)=>Kc(()=>{let r=t();return _h(e,e=>Cae({while:Pe,body:()=>e,step:e=>{r=n(r,e)}}),()=>k(r))})),Eue=N(function*(e){let t=Eu(1),n=yield*Tl(),r=Mr(n,Ls);return(yield*fh(e)(xs(),r)).pipe(Dl(n),t.withPermits(1))},fl(e=>k(Qc(e)))),yh=(e,t)=>fh(e)(xs(),t),bh=1e4,Due=2**22,xh=(e,t)=>{let n=[],r=new Set;for(let t of e)for(let e of zue(t)){let t=n.length;Aue(e,n)&&r.add(t)}let i=jh(n,r);return{nodes:n,initial:i,dot:t,masks:n.length<=32?Oue(n,i):void 0}},Oue=(e,t)=>{let n=0;for(let e of t)n|=1<<e;let r=0,i=0,a=0;for(let t=0;t<e.length;t++){let n=e[t],o=1<<t;n._tag===`Globstar`?r|=o:n._tag===`End`&&(i|=o,n.directoryOnly||(a|=o))}return{initial:n,globstar:r,end:i,endFile:a}},kue=e=>e.startsWith(`//`)&&e[2]!==void 0&&e[2]!==`/`,Aue=(e,t)=>{if(e===``||kue(e))return!1;let n=jue(e),r=n.indexOf(`**`);if(r!==-1&&n.some((e,t)=>t>r&&(e===`.`||e===`..`)))return!1;let{directory:i,segments:a}=Pue(n);if(a.length===0)return!1;for(let e of a)e===`**`?t[t.length-1]!==Sh&&t.push(Sh):t.push(Fue(Array.from(e)));return t.push({_tag:`End`,directoryOnly:i}),!0},Sh={_tag:`Globstar`},jue=e=>{let t=[],n=0;for(let r=0;r<e.length;r++)e[r]===`\\`?r++:e[r]===`/`&&(t.push(e.slice(n,r)),n=r+1);return t.push(e.slice(n)),t},Ch=/^[A-Za-z]:/,Mue=e=>e.length===2&&Ch.test(e),wh=e=>e===``||e.length===3&&e[2]===`/`&&Ch.test(e),Nue=e=>e.startsWith(`/`)||e[2]===`/`&&Ch.test(e),Pue=e=>{let t=[],n=0;e.length>1&&(e[0]===``||Mue(e[0]))&&(t.push(e[0]===``?``:`${e[0]}/`),n=1);let r=!1;for(;n<e.length;n++){let i=e[n];i===``||i===`.`?r=n===e.length-1&&t.length>0:(t.push(i),r=!1)}return t.length===0&&e.includes(`.`)&&t.push(`.`),{segments:t,directory:r}},Fue=e=>{let t=[],n=``,r=!1,i=!0;for(let a=0;a<e.length;a++){let o=e[a];if(o===`\\`&&a+1<e.length)n+=e[++a],t.push({_tag:`Char`,code:e[a].codePointAt(0)});else if(o===`*`)r=!0,t[t.length-1]?._tag!==`Star`&&t.push({_tag:`Star`});else if(o===`?`)r=!0,t.push({_tag:`Any`});else if(o===`[`&&i){let s=Eh(e,a);s===void 0?(i=!1,n+=o,t.push({_tag:`Char`,code:o.codePointAt(0)})):(r=!0,t.push(s.token),a=s.end)}else n+=o,t.push({_tag:`Char`,code:o.codePointAt(0)})}if(!r)return{_tag:`Literal`,value:n};let a=t[0];return{_tag:`Wildcard`,tokens:t,leadingDot:a._tag===`Char`&&a.code===46,affixes:Iue(t)}},Iue=e=>{let t=``,n;for(let r of e)if(r._tag===`Star`&&n===void 0)n=``;else if(r._tag===`Char`&&(r.code<55296||r.code>57343)){let e=String.fromCodePoint(r.code);n===void 0?t+=e:n+=e}else return;return n===void 0?void 0:{prefix:t,suffix:n}},Th=(e,t)=>[e.codePointAt(0),t.codePointAt(0)],Lue={alnum:[...Th(`0`,`9`),...Th(`A`,`Z`),...Th(`a`,`z`)],alpha:[...Th(`A`,`Z`),...Th(`a`,`z`)],blank:[9,9,32,32],cntrl:[0,31,127,127],digit:Th(`0`,`9`),graph:[33,126],lower:Th(`a`,`z`),print:[32,126],punct:[33,47,58,64,91,96,123,126],space:[9,13,32,32],upper:Th(`A`,`Z`),word:[...Th(`0`,`9`),...Th(`A`,`Z`),95,95,...Th(`a`,`z`)],xdigit:[...Th(`0`,`9`),...Th(`A`,`F`),...Th(`a`,`f`)]},Rue=(e,t)=>{for(let n=t+2;n<e.length&&n<=t+8;n++)if(e[n]===`:`&&e[n+1]===`]`){let r=Lue[e.slice(t+2,n).join(``)];return r===void 0?void 0:{ranges:r,end:n+1}}},Eh=(e,t)=>{let n=t+1,r=e[n]===`!`||e[n]===`^`;r&&n++;let i=[];for(let t=!0;n<e.length;n++,t=!1){let a=e[n];if(a===`/`)return;if(a===`]`&&!t)return{token:{_tag:`Class`,ranges:i,negated:r},end:n};if(a===`[`&&e[n+1]===`:`){let t=Rue(e,n);if(t!==void 0){i.push(...t.ranges),n=t.end;continue}}if(a===`\\`&&n+1<e.length&&(a=e[++n]),e[n+1]===`-`&&n+2<e.length&&e[n+2]!==`]`){let t=n+2;if(e[t]===`/`)return;e[t]===`\\`&&t+1<e.length&&t++,i.push(...Th(a,e[t])),n=t;continue}i.push(...Th(a,a))}},zue=e=>{let t=Array.from(e),n=Bue(t);if(n.size===0)return[e];let r=Dh(t,0,t.length,n,0);if(r===void 0)return[e];let i=Oh(r);return i>bh||i*e.length>Due?[e]:kh(r)},Bue=e=>{let t=new Map,n=[],r=!0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`)i++;else if(a===`/`)r=!0;else if(a===`[`&&r){let t=Eh(e,i);t===void 0?r=!1:i=t.end}else if(a===`{`)n.push({open:i,commas:[]});else if(a===`,`)n[n.length-1]?.commas.push(i);else if(a===`}`){let e=n.pop();e!==void 0&&e.commas.length>0&&t.set(e.open,{commas:e.commas,close:i})}}return t},Dh=(e,t,n,r,i)=>{if(i>64)return;let a=[],o=``;for(let s=t;s<n;s++){let t=r.get(s);if(t===void 0){e[s]===`\\`&&s+1<n&&(o+=e[s++]),o+=e[s];continue}let c=[],l=s+1;for(let n of[...t.commas,t.close]){let t=Dh(e,l,n,r,i+1);if(t===void 0)return;c.push(t),l=n+1}o!==``&&(a.push(o),o=``),a.push(c),s=t.close}return o!==``&&a.push(o),a},Oh=e=>{let t=1;for(let n of e)if(typeof n!=`string`){let e=0;for(let t of n)e+=Oh(t);if(t*=e,t>bh)return 1/0}return t},kh=e=>{let t=[``];for(let n of e)if(typeof n==`string`)t=t.map(e=>e+n);else{let e=n.flatMap(kh);t=t.flatMap(t=>e.map(e=>t+e))}return t},Vue=(e,t)=>{switch(e._tag){case`Char`:return e.code===t;case`Any`:return!0;case`Star`:return!1;case`Class`:{let n=!1;for(let r=0;r<e.ranges.length&&!n;r+=2)n=t>=e.ranges[r]&&t<=e.ranges[r+1];return n!==e.negated}}},Ah=e=>e>65535?2:1,Hue=(e,t,n)=>{if(t===`.`||t===`..`||t.startsWith(`.`)&&!n&&!e.leadingDot)return!1;if(e.affixes!==void 0){let{prefix:n,suffix:r}=e.affixes;return t.length>=n.length+r.length&&t.startsWith(n)&&t.endsWith(r)}let{tokens:r}=e,i=0,a=0,o=-1,s=0;for(;a<t.length;){if(r[i]?._tag===`Star`){o=i++,s=a;continue}let e=t.codePointAt(a);if(i<r.length&&Vue(r[i],e))i++,a+=Ah(e);else if(o!==-1)i=o+1,s+=Ah(t.codePointAt(s)),a=s;else return!1}for(;r[i]?._tag===`Star`;)i++;return i===r.length},jh=(e,t)=>{for(let n of t)e[n]._tag===`Globstar`&&t.add(n+1);return t},Mh=(e,t,n)=>{let r=new Set,i=new Set,a=wh(n);for(let o of t){let t=e.nodes[o];switch(t._tag){case`Globstar`:!a&&n!==`.`&&n!==`..`&&(e.dot||!n.startsWith(`.`))&&i.add(o);break;case`Literal`:t.value===n&&r.add(o+1);break;case`Wildcard`:!a&&Hue(t,n,e.dot)&&r.add(o+1)}}return{explicit:jh(e.nodes,r),globstar:jh(e.nodes,i)}},Nh=e=>{if(e.globstar.size===0)return e.explicit;let t=new Set(e.explicit);for(let n of e.globstar)t.add(n);return t},Ph=(e,t,n)=>{for(let r of t){let t=e.nodes[r];if(t._tag===`End`&&(n||!t.directoryOnly))return!0}return!1},Fh=(e,t)=>{for(let n of t)if(e.nodes[n]._tag!==`End`)return!0;return!1},Uue=(e,t)=>{for(let n of t){let t=e.nodes[n];if(t._tag===`End`&&t.directoryOnly)return!0}return!1},Ih=(e,t)=>e===``?t===``?`/`:t:e.endsWith(`/`)?e+t:`${e}/${t}`,Lh=e=>e.reason._tag===`NotFound`||e.reason._tag===`BadResource`,Rh=e=>Lh(e)||e.reason._tag===`PermissionDenied`,zh=e=>Rh(e)||e.reason._tag===`Unknown`,Wue=$n(Zn,e=>e.name),Gue=e=>(t,n)=>Kue(e,xh([t],n?.dot??!1),n),Kue=N(function*(e,t,n){if(t.initial.size===0)return[];let r=n?.root??``,i=xh(n?.exclude??[],!0),a=i.nodes.some(e=>e._tag===`End`&&e.directoryOnly),o=e=>Nue(e)?e:e===``?r===``?`.`:r:Ih(r,e),s=e=>e===`.`||e===`..`||wh(e),c=(t,n,r)=>{let i=o(Ih(t,n));return e.stat(i).pipe(M(e=>e.type),kae(`PlatformError`,`NotFound`,()=>e.readLink(i).pipe(cl(`SymbolicLink`),pl(zh,()=>k(void 0)))),pl(r?Lh:Rh,()=>k(void 0)),M(e=>e===void 0?void 0:{name:n,type:e}))},l=(n,r,i)=>{let a=new Set,l=!i;for(let e of r){let n=t.nodes[e];n._tag===`Literal`?a.add(n.value):n._tag!==`End`&&(l=!0)}let u=l?[...a].filter(s):[...a];return Dae(l?pl(e.readDirectoryEntries(o(n)),i?Lh:Rh,()=>k([])):k([]),Wc(u,e=>c(n,e,i),{concurrency:16}),(e,t)=>({entries:Vte([...e,...t.filter(Ze)],Wue),named:i&&!l}))},u=({name:n,type:r},s,c,l)=>{let u=Mh(t,c,n),d=Nh(u);if(d.size===0)return;let f=Ih(s,n),p=Nh(Mh(i,l,n)),m=Fh(t,d),h=(e,n)=>{let r=Ph(t,d,e);if((r||e&&m)&&!Ph(i,p,e))return{relative:f,accepted:r,excluded:p,next:!e||!m?void 0:!n||u.globstar.size===0?d:Fh(t,u.explicit)?u.explicit:void 0}};if(!m&&!Uue(t,d)&&!a)return h(!1,!1);if(r!==`Unknown`&&r!==`SymbolicLink`)return h(r===`Directory`,!1);let g=o(f);return e.stat(g).pipe(M(e=>e.type===`Directory`),pl(Rh,()=>k(!1)),j(t=>{let n=h(t,r===`SymbolicLink`);return r===`SymbolicLink`||n?.next===void 0||u.globstar.size===0?k(n):e.readLink(g).pipe(cl(h(t,!0)),pl(zh,()=>k(n)))}))},d=16,f=!1,p=Os(),m=e=>e.pipe(Fl(e=>qc(()=>{f||Is(p,Qc(e))})),Pl(qc(()=>{d++})),zae),h=N(function*(e,t,n,r){let i=yield*l(e,t,r),a=[],o=[];for(let r of i.entries){let i=u(r,e,t,n);if(Hc(i)){let e=a.push(void 0)-1;o.push(M(i,t=>{a[e]=t}))}else a.push(i)}o.length>0&&(yield*Uc(o,{concurrency:16,discard:!0}));let s=[];for(let e of a)if(e?.next!==void 0){let t=h(e.relative,e.next,e.excluded,i.named);d>0?(d--,s.push(Yl(yield*m(t)))):s.push(k(yield*t))}let c=[],f=0;for(let e of a)if(e!==void 0&&(e.accepted&&c.push(e.relative),e.next!==void 0))for(let e of yield*s[f++])c.push(e);return c});return yield*Sl(Pl(h(``,t.initial,i.initial,!0),qc(()=>{f=!0})),As(p))}),Bh=`~effect/PlatformError`;var Vh=class extends Bi(`BadArgument`){get message(){return`${this.module}.${this.method}${this.description?`: ${this.description}`:``}`}},que=class extends mne{get message(){return`${this._tag}: ${this.module}.${this.method}${this.pathOrDescriptor===void 0?``:` (${this.pathOrDescriptor})`}${this.description?`: ${this.description}`:``}`}},Hh=class extends Bi(`PlatformError`){constructor(e){`cause`in e?super({reason:e,cause:e.cause}):super({reason:e})}[Bh]=Bh;get message(){return this.reason.message}};const Uh=e=>new Hh(new que(e)),Wh=e=>new Hh(new Vh(e)),Jue={_R:Me,_E:Me,_A:Me},Gh=function(e){this.channel=e};Gh.prototype={"~effect/Stream":Jue,pipe(){return Ae(this,arguments)}};const Yue=e=>new Gh(e),Kh=`~effect/Sink`,qh=k([void 0]),Xue={_A:Me,_In:Me,_L:Me,_E:Me,_R:Me},Zue={[Kh]:Xue,pipe(){return Ae(this,arguments)}},Jh=e=>et(e,Kh),Yh=e=>Xh((t,n)=>fh(e)(t,n).pipe(j(zl({disableYield:!0})),wc(k))),Xh=e=>{let t=Object.create(Zue);return t.transform=e,t},Que=e=>ch((t,n)=>k(j(e.transform(t,n),xs))),Zh=Xh(e=>wc(zl(e,{disableYield:!0}),()=>qh)),$ue=e=>ede(Wc(t=>e(t),{discard:!0})),ede=e=>Xh(t=>t.pipe(j(e),zl({disableYield:!0}),wc(()=>qh))),tde=e=>Yh(gh(M(e,Que))),Qh={_tag:`Empty`},nde={_tag:`Closed`},rde={_A:Me,_E:Me};var ide=class{"~effect/RcRef"=rde;pipe(){return Ae(this,arguments)}state=Qh;acquire;context;scope;idleTimeToLive;constructor(e,t,n,r){this.acquire=e,this.context=t,this.scope=n,this.idleTimeToLive=r}};const ade=e=>nl(t=>{let n=t.context,r=Mr(n,Ls),i=new ide(e.acquire,n,r,e.idleTimeToLive===void 0?void 0:mi(e.idleTimeToLive));return cl(Bs(r,()=>{let e=i.state;return i.state=nde,e._tag===`Acquired`?Ws(e.scope,Ts):e._tag===`Acquiring`?Xl(e.fiber):Jc}),i)}),ode=(e,t)=>{switch(e.state._tag){case`Closed`:return Ll;case`Acquired`:{let t=e.state;return t.refCount++,t.fiber?cl(Xl(t.fiber),t):k(t)}case`Acquiring`:{let n=e.state;return n.awaiters++,$h(e,n,t)}case`Empty`:{let n={_tag:`Acquiring`,fiber:void 0,awaiters:1,acquired:void 0};e.state=n;let r=Rs(),i=Dl(e.acquire,Or(e.context,Ls,r)).pipe(j(t=>{if(e.state!==n)return Ll;let i={_tag:`Acquired`,value:t,scope:r,fiber:void 0,refCount:n.awaiters,invalidated:!1};return e.state=i,n.acquired=i,k(i)}),Il(t=>Es(t)?Jc:(e.state===n&&(e.state=Qh),Ws(r,t))));return n.fiber=Wl(Wae().context)(i),$h(e,n,t)}}},$h=(e,t,n)=>Il(n(Yl(t.fiber)),n=>{let r=t.acquired;return r===void 0?--t.awaiters>0||e.state!==t?Jc:(e.state=Qh,Xl(t.fiber)):Rie(n)?eg(e,r):Jc}),sde=e=>{let t=e;return Rl(e=>j(Al,n=>j(ode(t,e),e=>cl(Bs(n,()=>eg(t,e)),e.value))))},eg=(e,t)=>{if(t.refCount--,t.refCount>0)return Jc;let n=e.idleTimeToLive;return n===void 0||t.invalidated?(e.state===t&&(e.state=Qh),Ws(t.scope,Ts)):(Si(n)&&(t.fiber=Rl(r=>j(r(xl(n)),()=>e.state===t&&t.refCount===0?(e.state=Qh,jae(Ws(t.scope,Ts),{log:`Unhandled`,message:`Unhandled error in RcRef finalizer`})):Jc)).pipe(Pl(qc(()=>{t.fiber=void 0})),Wl(e.context),Zl(e.scope))),Jc)},tg=ade,ng=sde,rg=e=>et(e,`~effect/Stream`),ig=Yue,ag=e=>ig(uh(e)),cde=(e,t)=>ig(ch((n,r)=>j(yh(e.channel,r),e=>t(e,r)))),og=e=>e.channel,lde=(e,t)=>ig(eue(e,t)),sg=ig(rue),cg=(...e)=>pde(e),ude=e=>{let t=ig(tue(()=>e().channel));return dde.set(t,e),t},dde=new WeakMap,fde=e=>ig(aue(e)),pde=e=>qr(e)?ig(nue(e)):sg,mde=ig(iue),lg=e=>ig(gh(M(e,og))),hde=D(e=>rg(e[0]),(e,t,n)=>e.channel.pipe(hue,fue(t,n),cue(Xr),ig)),gde=D(e=>rg(e[0]),(e,t,n)=>hde(e,e=>cl(t(e),e),n)),_de=D(2,(e,t)=>yde(e,pg(t))),vde=D(e=>rg(e[0])&&rg(e[1]),(e,t,n)=>ig(ph(og(e),og(t),n))),yde=D(2,(e,t)=>e.channel.pipe(vue(t),ig)),bde=D(2,(e,t)=>e.channel.pipe(gue(e=>t(e).channel),ig)),xde=D(2,(e,t)=>e.channel.pipe(_ue(t),ig)),ug=D(2,(e,t)=>cde(e,(e,n)=>qc(()=>{let r,i,a=Kc(()=>{if(i!==void 0){let e=i;return i=void 0,k(e)}return e}).pipe(ul(e=>(r=ws(e),xs()))),o=M(Kc(()=>t.transform(a,n)),([e,t])=>(i=t,Xr(e)));return Kc(()=>r||o)}))),dg=D(e=>rg(e[0]),(e,t)=>e.channel.pipe(mh(bue(t?.encoding)),ig)),Sde=e=>e.channel.pipe(mh(yue()),ig),fg=D(2,(e,t)=>Fae(n=>yh(e.channel,n).pipe(j(e=>Cde(t,e,n)),M(([e])=>e)))),Cde=(e,t,n)=>wue(e.transform(Sue(t),n)),wde=e=>vh(e.channel,()=>[],(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n]);return e}),pg=e=>Tue(e.channel),Tde=e=>Eue(e.channel),mg=e=>vh(e.channel,()=>``,(e,t)=>e+t.join(``)),hg=`~effect/FileSystem`,gg=mr(`effect/FileSystem`),Ede=e=>gg.of({...e,[hg]:hg,glob:Gue(e),exists:t=>Le(e.access(t),cl(!0),dl(`PlatformError`,e=>e.reason._tag===`NotFound`?k(!1):A(e))),readFileString:(t,n)=>j(e.readFile(t),e=>tl({try:()=>new TextDecoder(n).decode(e),catch:e=>Wh({module:`FileSystem`,method:`readFileString`,description:`invalid encoding`,cause:e})})),stream:N(function*(t,n){let r=yield*e.open(t,{flag:`r`}),i=n?.offset===void 0?void 0:Wu(n.offset);i&&(yield*r.seek(i,`start`));let a=n?.bytesToRead===void 0?void 0:Wu(n.bytesToRead),o=BigInt(0),s=Number(BigInt(n?.chunkSize??65536)),c=r.readAlloc(s);return ag(k(j(Kc(()=>a!==void 0&&a<=o?xs():a!==void 0&&a-o<s?r.readAlloc(Number(a-o)):c),ar({onNone:()=>xs(),onSome:e=>(o+=BigInt(e.length),k(Xr(e)))}))))},lg),sink:(t,n)=>Le(e.open(t,{...n,flag:n?.flag??`w`}),M(e=>$ue(t=>e.writeAll(t))),tde),writeFileString:(t,n,r)=>j(tl({try:()=>new TextEncoder().encode(n),catch:e=>Wh({module:`FileSystem`,method:`writeFileString`,description:`could not encode string`,cause:e})}),n=>e.writeFile(t,n,r))}),_g=`~effect/FileSystem/File`;var vg=class extends mr()(`effect/FileSystem/WatchBackend`){};const yg=`~effect/Path`,bg=mr(`effect/Path`),Dde=e=>bg.of({...e,[yg]:yg,resolveWithin(t,n){if(e.parse(n).root!==``)return O();let r=e.resolve(t),i=e.resolve(r,n),a=e.relative(r,i);return a===`..`||a.startsWith(`..${e.sep}`)||e.isAbsolute(a)?O():nr(i)}}),Ode=us,xg=e=>On(t=>e(t.getRef(Ode))),Sg=(...e)=>xg(t=>va(()=>{t.error(...e)})),Cg=(...e)=>xg(t=>va(()=>{t.log(...e)})),kde={"~effect/Ref":{_A:Me},...Qt,toJSON(){return{_id:`Ref`,ref:this.ref}}},Ade=e=>{let t=Object.create(kde);return t.ref=ah(e),t},wg=e=>qc(()=>Ade(e)),Tg=e=>qc(()=>e.ref.current),Eg=D(2,(e,t)=>qc(()=>Zle(e.ref,t)));var jde=class extends mr()(`effect/Runtime/InterruptExitCode`){};const Mde=(e,t)=>{if(Es(e))return t(0);if(gs(e.cause)){let n=-1/0;for(let r of e.cause.reasons){let e=kr(Lie(r),jde);if(e===void 0)return t(130);n=Math.max(n,e)}return t(n)}return t(Pde(vs(e.cause)))},Nde=e=>D(e=>Hc(e[0]),(t,n)=>{let r=n?.disableErrorReporting===!0?t:Aae(t,e=>gs(e)?Jc:Fde(vs(e))?Bae(e):Jc),i=n?.teardown??Mde;Ul(nl(t=>{try{let e=globalThis.setInterval(Ie,2147483647);t.addObserver(()=>{clearInterval(e)})}catch{}return e({fiber:t,teardown:i}),r}))}),Dg=`~effect/Runtime/errorExitCode`,Pde=e=>{if(typeof e==`object`&&e&&`~effect/Runtime/errorExitCode`in e){let t=e[Dg];if(typeof t==`number`)return t}return 1},Og=`~effect/Runtime/errorReported`,Fde=e=>{if(typeof e==`object`&&e&&`~effect/Runtime/errorReported`in e){let t=e[Og];if(typeof t==`boolean`)return t}return!0},kg=`~effect/Stdio`,Ide=mr(kg),Lde=e=>({[kg]:kg,stdinIsTerminal:k(!1),stdoutIsTerminal:k(!1),stderrIsTerminal:k(!1),...e}),Ag=`~effect/Terminal`,jg=`~effect/Terminal/QuitError`;var Mg=class extends th(`QuitError`)({_tag:Fm(`QuitError`)}){[jg]=jg};const Rde=e=>et(e,jg),Ng=mr(`effect/Terminal`),zde=e=>Ng.of({...e,[Ag]:Ag}),Pg=`~effect/cli/CliError`,Fg=e=>et(e,Pg),Ig=`~effect/cli/CliError/userMessage`,Bde=e=>`~effect/cli/CliError/userMessage`in e&&typeof e[`~effect/cli/CliError/userMessage`]==`string`?e[Ig]:void 0;var Lg=class extends nh(`${Pg}/UnrecognizedOption`)(`UnrecognizedOption`,{option:P,command:wm(I(P)),suggestions:I(P)}){[Pg]=Pg;get message(){let e=this.suggestions.length>0?`\n\n Did you mean this?\n ${this.suggestions.join(`
21
+ `)}`:``;return(this.command?`Unrecognized flag: ${this.option} in command ${this.command.join(` `)}`:`Unrecognized flag: ${this.option}`)+e}},Rg=class extends nh(`${Pg}/DuplicateOption`)(`DuplicateOption`,{option:P,parentCommand:P,childCommand:P}){[Pg]=Pg;get message(){return`Duplicate flag name "${this.option}" in parent command "${this.parentCommand}" and subcommand "${this.childCommand}". Parent will always claim this flag (Mode A semantics). Consider renaming one of them to avoid confusion.`}},zg=class extends nh(`${Pg}/MissingOption`)(`MissingOption`,{option:P}){[Pg]=Pg;get message(){return`Missing required flag: --${this.option}`}},Bg=class extends nh(`${Pg}/MissingArgument`)(`MissingArgument`,{argument:P}){[Pg]=Pg;get message(){return`Missing required argument: ${this.argument}`}},Vg=class extends nh(`${Pg}/UnexpectedArgument`)(`UnexpectedArgument`,{arguments:I(P)}){[Pg]=Pg;get message(){return`Unexpected positional ${this.arguments.length===1?`argument`:`arguments`}: ${this.arguments.map(e=>JSON.stringify(e)).join(`, `)}`}},Hg=class extends nh(`${Pg}/InvalidValue`)(`InvalidValue`,{option:P,value:P,expected:P,kind:Am([Tm(`flag`),Tm(`argument`)])}){[Pg]=Pg;get message(){let e=this.expected.startsWith(`Expected `)||this.expected.startsWith(`Expected:`)?this.expected:`Expected: ${this.expected}`;return this.kind===`argument`?`Invalid value for argument <${this.option}>: "${this.value}". ${e}`:this.value.length===0?`Missing value for flag --${this.option}. ${e}`:`Invalid value for flag --${this.option}: "${this.value}". ${e}`}},Ug=class extends nh(`${Pg}/UnknownSubcommand`)(`UnknownSubcommand`,{subcommand:P,parent:wm(I(P)),suggestions:I(P)}){[Pg]=Pg;get message(){let e=this.suggestions.length>0?`\n\n Did you mean this?\n ${this.suggestions.join(`
22
+ `)}`:``;return this.parent?`Unknown subcommand "${this.subcommand}" for "${this.parent.join(` `)}"${e}`:`Unknown subcommand "${this.subcommand}"${e}`}},Vde=class extends nh(`${Pg}/ValidationError`)(`ValidationError`,{message:P}){[Pg]=Pg},Wg=class extends nh(`${Pg}/UserError`)(`UserError`,{cause:Ple(),userMessage:Cm(P)}){[Pg]=Pg;[Og]=!0;get message(){return this.userMessage?this.userMessage:typeof this.cause==`string`&&this.cause?this.cause:this.cause instanceof Error&&this.cause.message?this.cause.message:`An error occurred`}get[Ig](){return this.message}};const Hde=Am([Lg,Rg,zg,Bg,Vg,Hg,Ug,Vde,Wg]);var Gg=class extends nh(`${Pg}/ShowHelp`)(`ShowHelp`,{commandPath:I(P),errors:I(Hde)}){[Pg]=Pg;[Dg]=+!!this.errors.length;[Og]=!1;get message(){return`Help requested`}};const Ude={"~effect/cli/Primitive":{_A:Me}},Wde=_m(Nm),Gde=_m(Pm),Kg=e=>e._tag===`Boolean`,qg=(e,t)=>Object.assign(Object.create(Ude),{_tag:e,parse:t}),Jg=(e,t)=>{let n=vm(qle(t));return qg(e,e=>hl(n(e),e=>e.message))},Kde=Jg(`Boolean`,Tle),qde=Jg(`Int`,Hm),Jde=qg(`String`,e=>k(e)),Yde=e=>{let t=new Map(e),n=e.map(([e])=>jt(e)).join(` | `),r=qg(`Choice`,e=>t.has(e)?k(t.get(e)):A(n));return Object.assign(r,{choiceKeys:e.map(([e])=>e)})},Yg=e=>{switch(e._tag){case`Boolean`:return`boolean`;case`String`:return`string`;case`Int`:return`integer`;case`Finite`:return`number`;case`Date`:return`date`;case`Path`:return`path`;case`Choice`:return`choice`;case`Redacted`:return`string`;case`FileText`:return`file`;case`FileParse`:return`file`;case`FileSchema`:return`file`;case`KeyValuePair`:return`key=value`;case`Never`:return`none`;default:return`value`}},Xg=e=>e._tag===`Choice`?e.choiceKeys:void 0,Zg=e=>e._tag===`Path`?e.pathType:void 0,Qg=`\x1B[1m`,$g=`\x1B[4m`,e_=`\x1B[?25l`,t_=`\x1B[31m`,n_=`\x1B[32m`,r_=`\x1B[37m`,i_=`\x1B[90m`,a_=`\x1B[96m`,o_=(e,t,...n)=>e?`${n.flat().join(``)}${t}`:t,s_=()=>{let e=globalThis.process;return typeof e==`object`&&!!e&&typeof e.stdout==`object`&&e.stdout!==null&&e.stdout.isTTY===!0&&!e.env?.NO_COLOR},c_=(...e)=>e,Xde=(e,t)=>t===void 0?`[${Math.max(e+1,0)}G`:`[${t+1};${Math.max(e+1,0)}H`,Zde=(e=1)=>`[${e}B`,Qde=(e,t=0)=>{let n=``;return t<0&&(n+=`[${-t}A`),t>0&&(n+=`[${t}B`),e>0&&(n+=`[${e}C`),e<0&&(n+=`[${-e}D`),n},$de=e=>{let t=``;for(let n=0;n<e;n++)t+=`\x1B[2K`+(n<e-1?`\x1B[1A`:``);return e>0&&(t+=`\x1B[G`),t},l_={prefix:`?`,arrowUp:`↑`,arrowDown:`↓`,checkboxOn:`☒`,checkboxOff:`☐`,tick:`✔`,ellipsis:`…`,pointerSmall:`›`,pointer:`❯`,descriptionSeparator:`- `,passwordMask:`*`,toggleSeparator:`/`,primaryColor:a_,mutedColor:i_,successColor:n_,errorColor:t_,submittedColor:r_},efe={...l_,checkboxOn:`[*]`,checkboxOff:`[ ]`,tick:`√`,ellipsis:`...`,pointerSmall:`»`,pointer:`>`},u_=Ir(`effect/cli/Prompt/Theme`,{defaultValue:e=>({...process.platform===`win32`?efe:l_,...e,colors:e?.colors??s_()})}),d_=e=>M(u_,t=>({...t,...e.theme})),f_=(e,t)=>o_(e.colors,t,c_(`\x1B[3m`,e.errorColor)),p_=(e,t,...n)=>t.length===0?``:o_(e.colors,t,...n),m_=(e,t)=>e.length===0?t:e+` `+t,tfe=(e,t,n)=>{let r=Math.max(e.arrowUp.length,e.arrowDown.length);return t?e.arrowUp.padEnd(r):n?e.arrowDown.padEnd(r):` `.repeat(r)},h_=e=>{let t={initial:!1,...e,label:{confirm:`yes`,deny:`no`,...e.label},placeholder:{defaultConfirm:`(Y/n)`,defaultDeny:`(y/N)`,...e.placeholder}},n={value:t.initial};return g_(n,{render:gfe(t),process:e=>yfe(e,t.initial),clear:pfe(t)})},g_=(e,...t)=>{let[n,r]=t.length===1?[void 0,t[0]]:[t[0],t[1]],i=Object.create(b_);return i._tag=`Loop`,i.initialState=e,i.render=r.render,i.process=r.process,i.clear=r.clear,i.events=n,i},nfe=e=>{let t={initial:new globalThis.Date,dateMask:`YYYY-MM-DD HH:mm:ss`,validate:k,...e,locales:{...Afe,...e.locales}},n=Pfe(t.dateMask,t.initial,t.locales),r={dateParts:n,typed:``,cursor:n.findIndex(e=>!e.isToken()),value:t.initial,error:O()};return g_(r,{render:jfe(t),process:Mfe(t),clear:bfe(t)})},rfe=D(2,(e,t)=>{let n=Object.create(b_);return n._tag=`OnSuccess`,n.prompt=e,n.onSuccess=t,n}),ife=e=>{let t={default:0,min:globalThis.Number.NEGATIVE_INFINITY,max:globalThis.Number.POSITIVE_INFINITY,incrementBy:1,decrementBy:1,precision:2,validate:e=>e<t.min?A(`${e} must be greater than or equal to ${t.min}`):e>t.max?A(`${e} must be less than or equal to ${t.max}`):k(e),...e},n=e.default===void 0?``:`${t.default}`,r={cursor:n.length,value:n,error:O()};return g_(r,{render:Yfe(t),process:Xfe(t),clear:A_(t)})},__=e=>{let t={default:0,min:globalThis.Number.NEGATIVE_INFINITY,max:globalThis.Number.POSITIVE_INFINITY,incrementBy:1,decrementBy:1,validate:e=>e<t.min?A(`${e} must be greater than or equal to ${t.min}`):e>t.max?A(`${e} must be less than or equal to ${t.max}`):k(e),...e},n=e.default===void 0?``:`${t.default}`,r={cursor:n.length,value:n,error:O()};return g_(r,{render:qfe(t),process:Jfe(t),clear:A_(t)})},afe=D(2,(e,t)=>rfe(e,e=>cfe(t(e)))),ofe=e=>W_(e,`password`).pipe(afe(ud)),v_=N(function*(e){let t=yield*Ng,n=yield*Lae(t.readInput);return yield*x_(e,t,n)},hl(()=>new Mg({})),jl),sfe=e=>{let t=0,n=-1;for(let t=0;t<e.length;t++)if(e[t].selected===!0){if(n!==-1)throw Error(`InvalidArgumentException: only a single choice can be selected by default for Prompt.Select`);n=t}return n!==-1&&(t=n),t},y_=e=>{let t={maxPerPage:10,...e},n=sfe(t.choices);return g_(n,{render:ipe(t),process:ope(t),clear:ape(t)})},cfe=e=>{let t=Object.create(b_);return t._tag=`Succeed`,t.value=e,t},lfe=e=>W_(e,`text`),ufe=e=>{let t={initial:!1,active:`on`,inactive:`off`,...e};return g_(t.initial,{render:Cpe(t),process:wpe,clear:()=>bpe(t)})},b_={...Fn({label:`Prompt`,evaluate(){return v_(this)}}),"~effect/cli/Prompt":{_Output:e=>e}},x_=(e,t,n)=>Kc(()=>{let r=e;switch(r._tag){case`Loop`:return j(n,e=>dfe(r,t,e));case`OnSuccess`:return j(x_(r.prompt,t,n),e=>x_(r.onSuccess(e),t,n));case`Succeed`:return k(r.value)}}),dfe=N(function*(e,t,n){let r=Hc(e.initialState)?yield*e.initialState:e.initialState,i=R.NextFrame({state:r}),a=``;for(;;){let o=yield*e.render(r,i);if(yield*gl(t.display(a+o)),a=``,e.events){let t=pu(n).pipe(M(e=>({_tag:`Input`,input:e}))),a=yield*Sl(t,pu(e.events).pipe(M(e=>({_tag:`Event`,value:e}))));i=yield*e.process(a,r)}else{let t=yield*pu(n);i=yield*e.process(t,r)}switch(i._tag){case`Beep`:continue;case`NextFrame`:a=yield*e.clear(r,i),r=i.state;continue;case`Submit`:{a=yield*e.clear(r,i);let n=yield*e.render(r,i);return yield*gl(t.display(a+n)),i.value}}}},(e,t,n)=>Pl(e,gl(n.display(`\x1B[?25h`)))),R=fne(),S_=(e,t)=>{if(t===0)return`\x1B[2K`+Xde(0);let n=0,r=e.split(w_);for(let e of r)n+=1+Math.floor(Math.max(e.length-1,0)/t);return $de(n)},ffe=(e,t)=>{let n=e.split(w_);return t===0?n.length:Le(Zr(n,e=>Math.ceil(e.length/t)),Qr(0,(e,t)=>e+t))},C_=(e,t,n)=>n!==void 0&&n.length>0?Zde(ffe(n,t))+S_(`\n${n}`,t)+S_(e,t):S_(e,t),w_=/\r?\n/,pfe=e=>N(function*(t,n){let r=yield*(yield*Ng).columns,i=yield*d_(e),a=t.value?e.placeholder.defaultConfirm:e.placeholder.defaultDeny,o=k_(a,e.message,i.prefix,i.pointerSmall,i,{plain:!0});return S_(o,r)+`\x1B[2K\x1B[G`}),mfe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.prefix,n.primaryColor),i=p_(n,n.pointerSmall,n.mutedColor),a=e.value?t.placeholder.defaultConfirm:t.placeholder.defaultDeny,o=o_(n.colors,a,n.mutedColor),s=k_(o,t.message,r,i,n);return e_+s}),hfe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.tick,n.successColor),i=p_(n,n.ellipsis,n.mutedColor),a=e?t.label.confirm:t.label.deny;return k_(a,t.message,r,i,n)+`
23
+ `}),gfe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>mfe(t,e),Submit:({value:t})=>hfe(t,e)}),_fe=/^y|t$/,vfe=/^n|f$/,yfe=(e,t)=>{let n=or(e.input,()=>``);return e.key.name===`enter`||e.key.name===`return`?k(R.Submit({value:t})):_fe.test(n.toLowerCase())?k(R.Submit({value:!0})):vfe.test(n.toLowerCase())?k(R.Submit({value:!1})):k(R.Beep())},bfe=e=>N(function*(t,n){let r=yield*(yield*Ng).columns,i=yield*d_(e),a=Qr(t.dateParts,``,(e,t)=>e+t.toString()),o=k_(a,e.message,i.prefix,i.pointerSmall,i,{plain:!0}),s=ir(t.error)?Gr(t.error.value.split(w_),{onEmpty:()=>``,onNonEmpty:e=>m_(i.pointerSmall,e.join(`
24
+ `))}):``;return C_(o,r,s)+`\x1B[2K\x1B[G`}),xfe=(e,t,n)=>{if(ir(e.error)){let r=e.error.value.split(w_);if(qr(r)){let e=p_(n,t,n.errorColor),i=Zr(r,e=>f_(n,e));return`\x1B[s
25
+ `+m_(e,i.join(`
26
+ `))+`\x1B[u`}}return``},T_=(e,t,n=!1)=>Qr(e.dateParts,``,(r,i,a)=>{let o=i.toString();if(a===e.cursor&&!n){let e=c_($g,t.primaryColor);return r+o_(t.colors,o,e)}return r+o}),Sfe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.prefix,n.primaryColor),i=p_(n,n.pointerSmall,n.mutedColor),a=T_(e,n),o=k_(a,t.message,r,i,n),s=xfe(e,n.pointerSmall,n);return e_+o+s}),Cfe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.tick,n.successColor),i=p_(n,n.ellipsis,n.mutedColor),a=T_(e,n,!0);return k_(a,t.message,r,i,n)+`
27
+ `}),wfe=e=>(e.dateParts[e.cursor].increment(),R.NextFrame({state:{...e,typed:``}})),Tfe=e=>(e.dateParts[e.cursor].decrement(),R.NextFrame({state:{...e,typed:``}})),Efe=e=>{let t=e.dateParts[e.cursor].previousPart();return ir(t)?R.NextFrame({state:{...e,typed:``,cursor:e.dateParts.indexOf(t.value)}}):R.Beep()},Dfe=e=>{let t=e.dateParts[e.cursor].nextPart();return ir(t)?R.NextFrame({state:{...e,typed:``,cursor:e.dateParts.indexOf(t.value)}}):R.Beep()},Ofe=e=>{let t=e.dateParts[e.cursor].nextPart(),n=ar(t,{onNone:()=>e.dateParts.findIndex(e=>!e.isToken()),onSome:t=>e.dateParts.indexOf(t)});return R.NextFrame({state:{...e,typed:``,cursor:n}})},kfe=(e,t)=>{if(/\d/.test(e)){let n=t.typed+e;return t.dateParts[t.cursor].setValue(n),R.NextFrame({state:{...t,typed:n}})}return R.Beep()},Afe={months:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],monthsShort:[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],weekdays:[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],weekdaysShort:[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`]},jfe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>Sfe(t,e),Submit:()=>Cfe(t,e)}),Mfe=e=>(t,n)=>{switch(t.key.name){case`left`:return k(Efe(n));case`right`:return k(Dfe(n));case`k`:case`up`:return k(wfe(n));case`j`:case`down`:return k(Tfe(n));case`tab`:return k(Ofe(n));case`enter`:case`return`:return Cl(e.validate(n.value),{onFailure:e=>R.NextFrame({state:{...n,error:nr(e)}}),onSuccess:e=>R.Submit({value:e})});default:return k(kfe(or(t.input,()=>``),n))}},Nfe=/\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g,E_={1:({token:e,...t})=>new O_({token:e.replace(/\\(.)/g,`$1`),...t}),2:e=>new zfe(e),3:e=>new Bfe(e),4:e=>new Vfe(e),5:e=>new Hfe(e),6:e=>new Rfe(e),7:e=>new Lfe(e),8:e=>new Ife(e),9:e=>new Ffe(e)},Pfe=(e,t,n)=>{let r=[],i=null;for(;i=Nfe.exec(e);){let e=i.shift(),a=i.findIndex(e=>e!==void 0);if(a in E_){let o=i[a]||e;r.push(E_[a]({token:o,date:t,parts:r,locales:n}))}else r.push(new O_({token:i[a]||e,date:t,parts:r,locales:n}))}let a=r.reduce((e,t)=>{let n=e[e.length-1];return t.isToken()&&n!==void 0&&n.isToken()?n.setValue(t.token):e.push(t),e},Yr());return r.splice(0,r.length,...a),r};var D_=class{token;date;parts;locales;constructor(e){this.token=e.token,this.locales=e.locales,this.date=e.date||new globalThis.Date,this.parts=e.parts||[this]}isToken(){return!1}nextPart(){let e=or(Jr(this.parts,e=>e===this),()=>0);return zte(this.parts.slice(e+1),e=>!e.isToken())}previousPart(){let e=Jr(this.parts,e=>e===this);return ir(e)?Bte(this.parts.slice(0,e.value),e=>!e.isToken()):O()}toString(){return globalThis.String(this.date)}},O_=class extends D_{increment(){}decrement(){}setValue(e){this.token+=e}isToken(){return!0}toString(){return this.token}},Ffe=class extends D_{increment(){this.date.setMilliseconds(this.date.getMilliseconds()+1)}decrement(){this.date.setMilliseconds(this.date.getMilliseconds()-1)}setValue(e){this.date.setMilliseconds(globalThis.Number.parseInt(e.slice(-this.token.length)))}toString(){return`${this.date.getMilliseconds()}`.padStart(4,`0`).substring(0,this.token.length)}},Ife=class extends D_{increment(){this.date.setSeconds(this.date.getSeconds()+1)}decrement(){this.date.setSeconds(this.date.getSeconds()-1)}setValue(e){this.date.setSeconds(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=`${this.date.getSeconds()}`;return this.token.length>1?e.padStart(2,`0`):e}},Lfe=class extends D_{increment(){this.date.setMinutes(this.date.getMinutes()+1)}decrement(){this.date.setMinutes(this.date.getMinutes()-1)}setValue(e){this.date.setMinutes(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=`${this.date.getMinutes()}`;return this.token.length>1?e.padStart(2,`0`):e}},Rfe=class extends D_{increment(){this.date.setHours(this.date.getHours()+1)}decrement(){this.date.setHours(this.date.getHours()-1)}setValue(e){this.date.setHours(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=/h/.test(this.token)?this.date.getHours()%12||12:this.date.getHours();return this.token.length>1?`${e}`.padStart(2,`0`):`${e}`}},zfe=class extends D_{increment(){this.date.setDate(this.date.getDate()+1)}decrement(){this.date.setDate(this.date.getDate()-1)}setValue(e){this.date.setDate(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=this.date.getDate(),t=this.date.getDay();switch(this.token){case`DD`:return`${e}`.padStart(2,`0`);case`Do`:return`${e}${this.ordinalIndicator(e)}`;case`d`:return`${t+1}`;case`ddd`:return this.locales.weekdaysShort[t];case`dddd`:return this.locales.weekdays[t];default:return`${e}`}}ordinalIndicator(e){if(e>=11&&e<=13)return`th`;switch(e%10){case 1:return`st`;case 2:return`nd`;case 3:return`rd`;default:return`th`}}},Bfe=class extends D_{increment(){this.date.setMonth(this.date.getMonth()+1)}decrement(){this.date.setMonth(this.date.getMonth()-1)}setValue(e){let t=globalThis.Number.parseInt(e.slice(-2))-1;this.date.setMonth(t<0?0:t)}toString(){let e=this.date.getMonth();switch(this.token.length){case 2:return`${e+1}`.padStart(2,`0`);case 3:return this.locales.monthsShort[e];case 4:return this.locales.months[e];default:return`${e+1}`}}},Vfe=class extends D_{increment(){this.date.setFullYear(this.date.getFullYear()+1)}decrement(){this.date.setFullYear(this.date.getFullYear()-1)}setValue(e){this.date.setFullYear(globalThis.Number.parseInt(e.slice(-4)))}toString(){let e=`${this.date.getFullYear()}`.padStart(4,`0`);return this.token.length===2?e.slice(-2):e}},Hfe=class extends D_{increment(){this.date.setHours((this.date.getHours()+12)%24)}decrement(){this.increment()}setValue(e){}toString(){let e=this.date.getHours()>=12?`pm`:`am`;return/A/.test(this.token)?e.toUpperCase():e}};const k_=(e,t,n,r,i,a)=>{let o=n.length===0?``:n+` `,s=t=>{let n=o+t;return r.length>0&&(n+=` `+r),e.length>0?n+=` `+e:r.length>0&&(n+=` `),n};return Gr(t.split(w_),{onEmpty:()=>s(``),onNonEmpty:e=>{let t=a?.plain===!0?e:Zr(e,e=>o_(i.colors,e,Qg));return s(t.join(`
28
+ `))}})},Ufe=(e,t,n,r)=>{if(!e.disabled&&e.description&&t){let t=n.descriptionSeparator+e.description;return r?.plain===!0?t:o_(n.colors,t,n.mutedColor)}return``},A_=e=>N(function*(t,n){let r=yield*(yield*Ng).columns,i=yield*d_(e),a=j_(t,i.pointerSmall,i,{plain:!0}),o=M_(t,i.prefix,i.pointerSmall,e,i,{plain:!0});return C_(o,r,a)+`\x1B[2K\x1B[G`}),Wfe=(e,t,n,r)=>{let i=e.value===``?``:`${e.value}`;if(t||r?.plain===!0)return i;let a=ir(e.error)?n.errorColor:c_($g,n.primaryColor);return o_(n.colors,i,a)},j_=(e,t,n,r)=>ir(e.error)?Gr(e.error.value.split(w_),{onEmpty:()=>``,onNonEmpty:e=>{if(r?.plain===!0)return m_(t,e.join(`
29
+ `));let i=p_(n,t,n.errorColor),a=Zr(e,e=>f_(n,e));return`\x1B[s
30
+ `+m_(i,a.join(`
31
+ `))+`\x1B[u`}}):``,M_=(e,t,n,r,i,a,o=!1)=>{let s=Wfe(e,o,i,a);return k_(s,r.message,t,n,i,a)},N_=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.prefix,n.primaryColor),i=p_(n,n.pointerSmall,n.mutedColor),a=j_(e,n.pointerSmall,n);return M_(e,r,i,t,n)+a}),P_=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.tick,n.successColor),i=p_(n,n.ellipsis,n.mutedColor);return M_(e,r,i,t,n,void 0,!0)+`
32
+ `}),F_=e=>{if(e.value.length<=0)return k(R.Beep());let t=e.value.slice(0,e.value.length-1);return k(R.NextFrame({state:{...e,value:t,error:O()}}))},I_=e=>k(R.NextFrame({state:{...e,cursor:0,value:``,error:O()}})),Gfe=(e,t)=>{if(t.value.length===0&&e===`-`)return k(R.NextFrame({state:{...t,value:`-`,error:O()}}));let n=globalThis.Number.parseInt(t.value+e);return globalThis.Number.isNaN(n)?k(R.Beep()):k(R.NextFrame({state:{...t,value:`${n}`,error:O()}}))},Kfe=(e,t)=>{if(e===`.`&&t.value.includes(`.`))return k(R.Beep());if(t.value.length===0&&e===`-`)return k(R.NextFrame({state:{...t,value:`-`,error:O()}}));let n=globalThis.Number.parseFloat(t.value+e);return globalThis.Number.isNaN(n)?k(R.Beep()):k(R.NextFrame({state:{...t,value:e===`.`?`${n}.`:t.value.includes(`.`)&&/^\d$/.test(e)?t.value+e:`${n}`,error:O()}}))},qfe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>N_(t,e),Submit:()=>P_(t,e)}),Jfe=e=>(t,n)=>{if(t.key.ctrl&&t.key.name===`u`)return I_(n);switch(t.key.name){case`backspace`:return F_(n);case`k`:case`up`:return k(R.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`${e.incrementBy}`:`${globalThis.Number.parseInt(n.value)+e.incrementBy}`,error:O()}}));case`j`:case`down`:return k(R.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`-${e.decrementBy}`:`${globalThis.Number.parseInt(n.value)-e.decrementBy}`,error:O()}}));case`enter`:case`return`:{let t=globalThis.Number.parseInt(n.value);return globalThis.Number.isNaN(t)?k(R.NextFrame({state:{...n,error:nr(`Must provide an integer value`)}})):Cl(e.validate(t),{onFailure:e=>R.NextFrame({state:{...n,error:nr(e)}}),onSuccess:e=>R.Submit({value:e})})}default:return Gfe(or(t.input,()=>``),n)}},Yfe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>N_(t,e),Submit:()=>P_(t,e)}),Xfe=e=>(t,n)=>{if(t.key.ctrl&&t.key.name===`u`)return I_(n);switch(t.key.name){case`backspace`:return F_(n);case`k`:case`up`:return k(R.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`${e.incrementBy}`:`${globalThis.Number.parseFloat(n.value)+e.incrementBy}`,error:O()}}));case`j`:case`down`:return k(R.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`-${e.decrementBy}`:`${globalThis.Number.parseFloat(n.value)-e.decrementBy}`,error:O()}}));case`enter`:case`return`:{let t=globalThis.Number.parseFloat(n.value);return globalThis.Number.isNaN(t)?k(R.NextFrame({state:{...n,error:nr(`Must provide a floating point value`)}})):j(qc(()=>lae(t,e.precision)),t=>Cl(e.validate(t),{onFailure:e=>R.NextFrame({state:{...n,error:nr(e)}}),onSuccess:e=>R.Submit({value:e})}))}default:return Kfe(or(t.input,()=>``),n)}},L_=(e,t,n,r,i)=>n.message===void 0?void 0:k_(``,n.message,e,t,r,i),R_=(e,t)=>e===void 0?t:e+`
33
+ `+t,Zfe=(e,t,n,r,i,a)=>{let o=tfe(i,r===n.startIndex&&n.startIndex>0,r===n.endIndex-1&&n.endIndex<t.length);if(a?.plain===!0)return e===r?i.pointer+o:o+` `.repeat(i.pointer.length);if(t[r].disabled){let t=c_(Qg,i.mutedColor);return e===r?p_(i,i.pointer,t)+o:o+` `.repeat(i.pointer.length)}return e===r?p_(i,i.pointer,i.primaryColor)+o:o+` `.repeat(i.pointer.length)},Qfe=(e,t,n,r)=>{if(r?.plain===!0)return e.title;let i=e.title;return t?e.disabled?o_(n.colors,i,c_($g,n.mutedColor)):o_(n.colors,i,c_($g,n.primaryColor)):e.disabled?o_(n.colors,i,c_(`\x1B[9m`,n.mutedColor)):i},z_=(e,t,n,r)=>{let i=t.choices,a=Tpe(e,i.length,t.maxPerPage),o=[];for(let t=a.startIndex;t<a.endIndex;t++){let s=i[t],c=e===t,l=Zfe(e,i,a,t,n,r),u=Qfe(s,c,n,r),d=Ufe(s,c,n,r);o.push(l+u+` `+d)}return o.join(`
34
+ `)},$fe=N(function*(e,t){let n=yield*d_(t),r=z_(e,t,n),i=p_(n,n.prefix,n.primaryColor),a=p_(n,n.pointerSmall,n.mutedColor),o=L_(i,a,t,n);return e_+R_(o,r)}),epe=N(function*(e,t){let n=yield*d_(t),r=t.choices[e].title,i=p_(n,n.tick,n.successColor),a=p_(n,n.ellipsis,n.mutedColor);return(L_(i,a,t,n)??i)+` `+o_(n.colors,r,n.submittedColor)+`
35
+ `}),tpe=(e,t)=>k(e===0?R.NextFrame({state:t.length-1}):R.NextFrame({state:e-1})),npe=(e,t)=>e===t.length-1?k(R.NextFrame({state:0})):k(R.NextFrame({state:e+1})),rpe=(e,t)=>k(R.NextFrame({state:(e+1)%t.length})),ipe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>$fe(t,e),Submit:()=>epe(t,e)}),ape=e=>N(function*(t,n){let r=yield*(yield*Ng).columns,i=yield*d_(e),a=L_(i.prefix,i.pointerSmall,e,i,{plain:!0}),o=z_(t,e,i,{plain:!0});return S_(R_(a,o),r)+`\x1B[2K\x1B[G`}),ope=e=>(t,n)=>{switch(t.key.name){case`k`:case`up`:return tpe(n,e.choices);case`j`:case`down`:return npe(n,e.choices);case`tab`:return rpe(n,e.choices);case`enter`:case`return`:{let t=e.choices[n];return t.disabled?k(R.Beep()):k(R.Submit({value:t.value}))}default:return k(R.Beep())}},spe=N(function*(e,t){let n=yield*(yield*Ng).columns,r=yield*d_(t),i=B_(e,r.pointerSmall,r,{plain:!0});return C_(V_(e,r.prefix,r.pointerSmall,t,r,{plain:!0}),n,i)+`\x1B[2K\x1B[G`}),cpe=(e,t,n,r,i)=>{let a=e.value;if(i?.plain===!0)switch(t.type){case`hidden`:return``;case`password`:return n.passwordMask.repeat(a.length);case`text`:return a}if(a.length===0)return``;let o=ir(e.error)?n.errorColor:r?n.submittedColor:c_($g,n.primaryColor);switch(t.type){case`hidden`:return``;case`password`:return p_(n,n.passwordMask.repeat(a.length),o);case`text`:return o_(n.colors,a,o)}},B_=(e,t,n,r)=>ir(e.error)?Gr(e.error.value.split(w_),{onEmpty:()=>``,onNonEmpty:e=>{if(r?.plain===!0)return m_(t,e.join(`
36
+ `));let i=p_(n,t,n.errorColor),a=Zr(e,e=>f_(n,e));return`\x1B[s
37
+ `+m_(i,a.join(`
38
+ `))+`\x1B[u`}}):``,V_=(e,t,n,r,i,a,o=!1)=>{let s=cpe(e,r,i,o,a);return k_(s,r.message,t,n,i,a)},lpe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.prefix,n.primaryColor),i=p_(n,n.pointerSmall,n.mutedColor),a=V_(e,r,i,t,n),o=B_(e,n.pointerSmall,n),s=t.type===`password`?n.passwordMask.length:1,c=(e.cursor-e.value.length)*s;return a+o+Qde(c)}),upe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.tick,n.successColor),i=p_(n,n.ellipsis,n.mutedColor);return V_(e,r,i,t,n,void 0,!0)+`
39
+ `}),dpe=e=>{if(e.cursor<=0)return k(R.Beep());let t=e.value.slice(0,e.cursor-1),n=e.value.slice(e.cursor),r=e.cursor-1,i=`${t}${n}`;return k(R.NextFrame({state:{...e,cursor:r,value:i,error:O()}}))},fpe=e=>k(R.NextFrame({state:{...e,cursor:0,value:``,error:O()}})),ppe=e=>{if(e.cursor<=0)return k(R.Beep());let t=e.cursor-1;return k(R.NextFrame({state:{...e,cursor:t,error:O()}}))},mpe=e=>{if(e.cursor>=e.value.length)return k(R.Beep());let t=Math.min(e.cursor+1,e.value.length);return k(R.NextFrame({state:{...e,cursor:t,error:O()}}))},H_=e=>k(R.NextFrame({state:{...e,cursor:0,error:O()}})),U_=e=>k(R.NextFrame({state:{...e,cursor:e.value.length,error:O()}})),hpe=(e,t)=>{if(e.value===t.default)return k(R.Beep());let n=e.value.length===0?t.default:e.value;return k(R.NextFrame({state:{...e,value:n,cursor:n.length,error:O()}}))},gpe=(e,t)=>{let n=`${t.value.slice(0,t.cursor)}${e}${t.value.slice(t.cursor)}`,r=t.cursor+e.length;return k(R.NextFrame({state:{...t,cursor:r,value:n,error:O()}}))},_pe=e=>(t,n)=>R.$match(n,{Beep:()=>k(`\x07`),NextFrame:({state:t})=>lpe(t,e),Submit:()=>upe(t,e)}),vpe=e=>(t,n)=>{if(t.key.ctrl)switch(t.key.name){case`u`:return fpe(n);case`a`:return H_(n);case`e`:return U_(n);default:return k(R.Beep())}switch(t.key.name){case`backspace`:return dpe(n);case`left`:return ppe(n);case`right`:return mpe(n);case`home`:return H_(n);case`end`:return U_(n);case`enter`:case`return`:{let t=n.value;return Cl(e.validate(t),{onFailure:e=>R.NextFrame({state:{...n,value:t,error:nr(e)}}),onSuccess:e=>R.Submit({value:e})})}case`tab`:return hpe(n,e);default:return gpe(or(t.input,()=>``),n)}},ype=e=>(t,n)=>spe(t,e),W_=(e,t)=>{let n={default:``,type:t,validate:k,...e},r={cursor:n.default.length,value:n.default,error:O()};return g_(r,{render:_pe(n),process:vpe(n),clear:ype(n)})},bpe=N(function*(e){let t=yield*(yield*Ng).columns,n=yield*d_(e),r=e.active+` `+m_(n.toggleSeparator,e.inactive),i=k_(r,e.message,n.prefix,n.pointerSmall,n,{plain:!0});return S_(i,t)+`\x1B[2K\x1B[G`}),G_=(e,t,n,r=!1)=>{let i=p_(n,n.toggleSeparator,n.mutedColor),a=c_($g,r?n.submittedColor:n.primaryColor),o=e?t.inactive:o_(n.colors,t.inactive,a);return(e?o_(n.colors,t.active,a):t.active)+` `+m_(i,o)},xpe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.prefix,n.primaryColor),i=p_(n,n.pointerSmall,n.mutedColor),a=G_(e,t,n),o=k_(a,t.message,r,i,n);return e_+o}),Spe=N(function*(e,t){let n=yield*d_(t),r=p_(n,n.tick,n.successColor),i=p_(n,n.ellipsis,n.mutedColor),a=G_(e,t,n,!0);return k_(a,t.message,r,i,n)+`
40
+ `}),K_=k(R.NextFrame({state:!0})),q_=k(R.NextFrame({state:!1})),Cpe=e=>(t,n)=>{switch(n._tag){case`Beep`:return k(`\x07`);case`NextFrame`:return xpe(t,e);case`Submit`:return Spe(t,e)}},wpe=(e,t)=>{switch(e.key.name){case`0`:case`j`:case`delete`:case`right`:case`down`:return q_;case`1`:case`k`:case`left`:case`up`:return K_;case` `:case`tab`:return t?q_:K_;case`enter`:case`return`:return k(R.Submit({value:t}));default:return k(R.Beep())}},Tpe=(e,t,n)=>{let r=n===void 0?t:n,i=Math.min(t-r,e-Math.floor(r/2));i<0&&(i=0);let a=Math.min(i+r,t);return{startIndex:i,endIndex:a}},J_=Ir(`effect/cli/TerminalCapabilities`,{defaultValue:()=>Ope()}),Y_=e=>e!==void 0&&e.length>0,Epe=e=>Y_(e)&&e!==`0`&&e.toLowerCase()!==`false`,Dpe=e=>e.term===`dumb`?{canColor:!1,canAnimate:!1,canPrompt:!1}:{canColor:!Y_(e.noColor)&&(Epe(e.forceColor)||e.stdoutIsTerminal),canAnimate:e.stdoutIsTerminal,canPrompt:e.stdinIsTerminal&&e.stdoutIsTerminal},Ope=()=>{let e=globalThis.process;return Dpe({noColor:e?.env?.NO_COLOR,forceColor:e?.env?.FORCE_COLOR,term:e?.env?.TERM,stdinIsTerminal:e?.stdin?.isTTY===!0,stdoutIsTerminal:e?.stdout?.isTTY===!0})},X_=`~effect/cli/Param`,Z_=`flag`,Q_={[X_]:{_A:Me},pipe(){return Ae(this,arguments)}},kpe=e=>et(e,X_),$_=e=>e.kind===`flag`,ev=e=>{let t=t=>e.kind===`argument`?Upe(e.name,e.primitiveType,t):Wpe(e.name,e.primitiveType,t);return Object.setPrototypeOf({_tag:`Single`,...e,description:e.description??O(),aliases:e.aliases??[],hidden:e.hidden??!1,annotations:e.annotations??Er(),parse:t},Q_)},Ape=(e,t)=>ev({name:t,primitiveType:Jde,kind:e}),jpe=(e,t)=>ev({name:t,primitiveType:Kde,kind:e}),Mpe=(e,t)=>ev({name:t,primitiveType:qde,kind:e}),tv=(e,t,n)=>ev({name:t,primitiveType:Yde(n),kind:e}),Npe=(e,t,n)=>{let r=n.map(e=>[e,e]);return tv(e,t,r)},Ppe=/^-+/,Fpe=D(2,(e,t)=>av(e,e=>ev({...e,aliases:[...e.aliases,t.replace(Ppe,``)]}))),Ipe=D(2,(e,t)=>av(e,e=>ev({...e,description:nr(t)}))),Lpe=D(2,(e,t)=>Object.assign(Object.create(Q_),{_tag:`Map`,kind:e.kind,param:e,f:t,parse:n=>M(e.parse(n),([e,n])=>[e,t(n)])})),nv=(e,t,n=[],r)=>{let i=n.map(e=>()=>e().parse);return Object.assign(Object.create(Q_),{_tag:`Transform`,kind:e.kind,param:e,alternatives:n,f:t,fallback:r,parse:t(e.parse,i)})},Rpe=D(2,(e,t)=>nv(e,e=>n=>j(e(n),([e,n])=>t(n).pipe(M(t=>[e,t]))))),rv=e=>Object.assign(Object.create(Q_),{_tag:`Optional`,kind:e.kind,param:e,parse:t=>e.parse(t).pipe(M(([e,t])=>[e,nr(t)]),Oae({MissingOption:()=>k([t.arguments,O()]),MissingArgument:()=>k([t.arguments,O()])}))}),zpe=D(2,(e,t)=>Hc(t)?nv(rv(e),e=>n=>j(e(n),([e,n])=>ar(n,{onNone:()=>M(t,t=>[e,t]),onSome:t=>k([e,t])})),[],{_tag:`DefaultEffect`}):nv(rv(e),e=>n=>M(e(n),([e,n])=>[e,or(n,()=>t)]),[],{_tag:`Default`,value:t})),Bpe=(e,t)=>{let n=sv(e);return Object.assign(Object.create(Q_),{_tag:`Variadic`,kind:e.kind,param:e,min:cr(t?.min),max:cr(t?.max),parse:r=>n.kind===`argument`?Gpe(e,n,r,t):Kpe(e,n,r,t)})},Vpe=D(2,(e,t)=>av(e,e=>ev({...e,typeName:t}))),Hpe=D(2,(e,t)=>{let n=vm(t);return Rpe(e,t=>hl(n(t),n=>{let r=sv(e);return new Hg({option:r.name,value:globalThis.String(t),expected:`Schema validation failed: ${n.message}`,kind:r.kind})}))}),Upe=N(function*(e,t,n){if(n.arguments.length===0)return yield*new Bg({argument:e});let r=n.arguments[0],i=yield*hl(t.parse(r),t=>new Hg({option:e,value:r,expected:t,kind:`argument`}));return[n.arguments.slice(1),i]}),Wpe=N(function*(e,t,n){let r=n.flags[e];if(r===void 0||r.length===0)return yield*new zg({option:e});if(r.length>1)return yield*new Hg({option:e,value:`${r.length} occurrences`,expected:`at most 1 value`,kind:`flag`});let i=r[0],a=yield*hl(t.parse(i),t=>new Hg({option:e,value:i,expected:t,kind:`flag`}));return[n.arguments,a]}),Gpe=N(function*(e,t,n,r){let i=[],a=r?.min??0,o=r?.max??1/0,s=0,c=n.arguments;for(;c.length>0&&s<o;){let[t,r]=yield*e.parse({flags:n.flags,arguments:c});i.push(r),c=t,s++}return s<a?yield*s===0?new Bg({argument:t.name}):new Hg({option:t.name,value:`${s} values`,expected:`at least ${a} value${a===1?``:`s`}`,kind:t.kind}):[c,i]}),Kpe=N(function*(e,t,n,r){let i=[],a=[t.name,...t.aliases].flatMap(e=>n.flags[e]??[]),o=a.length;if(Ze(r?.min)&&o<r.min)return yield*o===0?new zg({option:t.name}):new Hg({option:t.name,value:`${o} occurrences`,expected:`at least ${r.min} value${r.min===1?``:`s`}`,kind:t.kind});if(Ze(r?.max)&&o>r.max)return yield*new Hg({option:t.name,value:`${o} occurrences`,expected:`at most ${r.max} value${r.max===1?``:`s`}`,kind:t.kind});for(let n of a){let[,r]=yield*e.parse({flags:{[t.name]:[n]},arguments:[]});i.push(r)}return[n.arguments,i]}),iv=(e,t)=>{let n=e;switch(n._tag){case`Single`:return t.Single(n);case`Map`:return t.Map(n);case`Transform`:return t.Transform(n);case`Optional`:return t.Optional(n);case`Variadic`:return t.Variadic(n)}},av=(e,t)=>iv(e,{Single:e=>t(e),Map:e=>Lpe(av(e.param,t),e.f),Transform:e=>nv(av(e.param,t),e.f,e.alternatives.map(e=>()=>av(e(),t)),e.fallback),Optional:e=>rv(av(e.param,t)),Variadic:e=>Bpe(av(e.param,t),{min:lr(e.min),max:lr(e.max)})}),ov=e=>iv(e,{Single:e=>[e],Map:e=>ov(e.param),Transform:e=>[...ov(e.param),...e.alternatives.flatMap(e=>ov(e()))],Optional:e=>ov(e.param),Variadic:e=>ov(e.param)}),sv=e=>{let t=ov(e);if(t.length===0)throw Error(`No Single param found in param structure`);if(t.length>1)throw Error(`Multiple Single params found: ${t.map(e=>e.name).join(`, `)}`);return t[0]},cv=e=>{let t=lv(e);return{...t,isRequired:!t.isOptional&&(!t.isVariadic||fr(t.variadicMin,e=>e>0))}},lv=e=>iv(e,{Single:()=>({isOptional:!1,isVariadic:!1,variadicMin:O(),variadicMax:O()}),Map:e=>lv(e.param),Transform:e=>lv(e.param),Optional:e=>({...lv(e.param),isOptional:!0}),Variadic:e=>({...lv(e.param),isVariadic:!0,variadicMin:e.min,variadicMax:e.max})}),uv=Ir(`effect/cli/CliOutput`,{defaultValue:()=>mv()}),dv={present:N(function*(e){let t=yield*Tl(),n=kr(t,uv)??mv({colors:Mr(t,J_).canColor});switch(e._tag){case`Help`:return yield*Cg(n.formatHelpDoc(e.helpDoc));case`InvalidInvocation`:return yield*Cg(n.formatHelpDoc(e.helpDoc)),yield*Sg(n.formatErrors(e.errors));case`Version`:return yield*Cg(n.formatVersion(e.name,e.version))}})},fv=Ir(`effect/cli/CliOutput/Presenter`,{defaultValue:()=>dv}),qpe=e=>$s(fv)(e),pv=e=>e.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g,e=>`\\x${e.charCodeAt(0).toString(16).padStart(2,`0`)}`),mv=e=>{let t=e?.colors??s_(),n={inheritedFlags:e?.inheritedFlags??`full`,globalFlags:e?.globalFlags??`full`},r=t?{bold:e=>`\x1b[1m${e}\x1b[0m`,dim:e=>`\x1b[2m${e}\x1b[0m`,cyan:e=>`\x1b[36m${e}\x1b[0m`,green:e=>`\x1b[32m${e}\x1b[0m`,blue:e=>`\x1b[34m${e}\x1b[0m`,yellow:e=>`\x1b[33m${e}\x1b[0m`,magenta:e=>`\x1b[35m${e}\x1b[0m`}:{bold:e=>e,dim:e=>e,cyan:e=>e,green:e=>e,blue:e=>e,yellow:e=>e,magenta:e=>e},i=t?`\x1B[0m`:``,a=t?`\x1B[31m`:``,o=t?`\x1B[1m`:``;return{formatHelpDoc:e=>tme(e,r,n),formatCliError:e=>pv(e.message),formatError:e=>`\n${o}${a}ERROR${i}\n ${pv(e.message)}${i}`,formatErrors:e=>{if(e.length===0)return``;if(e.length===1)return`\n${o}${a}ERROR${i}\n ${pv(e[0].message)}${i}`;let t=new Map;for(let n of e){let e=n._tag??`Error`,r=t.get(e)??[];r.push(n),t.set(e,r)}let n=[];n.push(`\n${o}${a}ERRORS${i}`);for(let[,e]of t)for(let t of e)n.push(` ${pv(t.message)}${i}`);return n.join(`
41
+ `)},formatVersion:(e,t)=>`${r.bold(e)} ${r.dim(`v`)}${r.bold(t)}`}},Jpe=e=>e.replace(/\u001B\[[0-9;]*m/g,``),Ype=new Intl.Segmenter(void 0,{granularity:`grapheme`}),Xpe=/[\p{Mark}\p{Control}\p{Default_Ignorable_Code_Point}]/gu,Zpe=/\p{Emoji_Presentation}/u,Qpe=e=>e<4352?!1:e<=4447||e===9001||e===9002||e>=11904&&e<=12350||e>=12352&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=110592&&e<=111359||e>=127488&&e<=127569||e>=131072&&e<=262141,$pe=e=>{let t=e.replace(Xpe,``);return t.length===0?0:Zpe.test(e)||e.includes(`️`)||Qpe(t.codePointAt(0))?2:1},hv=e=>{let t=0;for(let{segment:n}of Ype.segment(Jpe(e)))t+=$pe(n);return t},eme=(e,t)=>{let n=hv(e),r=Math.max(0,t-n);return e+` `.repeat(r)},gv=(e,t)=>{let n=Math.max(...e.map(e=>hv(e.left)))+4,r=t===void 0?n:Math.min(n,t);return e.map(({left:e,right:t})=>` ${eme(e,Math.max(r,hv(e)+1))}${t}`).join(`
42
+ `)},_v=(e,t)=>t?`${e}, ${t}`:e,tme=(e,t,n)=>{let r=[];if(e.description&&(r.push(t.bold(`DESCRIPTION`)),r.push(` ${e.description}`),r.push(``)),r.push(t.bold(`USAGE`)),r.push(` ${t.cyan(e.usage)}`),r.push(``),e.args&&e.args.length>0){r.push(t.bold(`ARGUMENTS`));let n=e.args.map(e=>{let n=e.name;e.variadic&&(n+=`...`);let r=`${t.green(n)} ${t.dim(e.type)}`,i=e.required?``:t.dim(` (optional)`);return{left:r,right:or(e.description,()=>``)+i}});r.push(gv(n,25)),r.push(``)}let i=(e,n)=>{r.push(t.bold(e)),r.push(gv(n.map(e=>({left:[`--${e.name}`,...e.aliases].map(t.green).join(`, `)+(e.type===`boolean`?``:` ${t.dim(e.type)}`),right:or(e.description,()=>``)})))),r.push(``)},a=[],o=(e,t,n,r)=>{t&&t.length!==0&&n!==`none`&&(n===`summary`&&r&&r.length>0?a.push(`Run '${r.join(` `)} --help' for ${e.toLowerCase()}`):i(e,t))};e.flags.length>0&&i(`FLAGS`,e.flags);let s=e.commandPath;o(`INHERITED FLAGS`,e.inheritedFlags,n.inheritedFlags,s?.slice(0,-1));let c=e.globalFlagsScope??s?.slice(0,1),l=s===void 0||c?.length===s.length;if(o(`GLOBAL FLAGS`,e.globalFlags,l?`full`:n.globalFlags,c),a.length>0&&r.push(...a,``),e.subcommands&&e.subcommands.length>0){let n=e.subcommands.find(e=>e.group===void 0);n&&(r.push(t.bold(`SUBCOMMANDS`)),r.push(gv(n.commands.map(e=>({left:t.cyan(_v(e.name,e.alias)),right:e.shortDescription??e.description})),20)),e.subcommands.length>1&&r.push(``));for(let n of e.subcommands)n.group!==void 0&&(r.push(t.bold(`${n.group}:`)),r.push(gv(n.commands.map(e=>({left:t.cyan(_v(e.name,e.alias)),right:e.shortDescription??e.description})),20)),r.push(``))}if(e.examples&&e.examples.length>0){r.push(t.bold(`EXAMPLES`));let n=!0,i=!1;for(let a of e.examples)a.description?(n||r.push(``),r.push(` ${t.dim(`# ${a.description}`)}`)):i&&r.push(``),r.push(` ${t.cyan(a.command)}`),n=!1,i=!!a.description;r.push(``)}return r[r.length-1]===``&&r.pop(),r.join(`
43
+ `)},vv=`~effect/cli/Command/Config/Internal`,yv=e=>{let t=[],n=[],r=[];function i(e){let t=Object.create(null);for(let n of Object.keys(e))t[n]=a(e[n]);return t}function a(e){if(Array.isArray(e))return{_tag:`Array`,children:e.map(e=>a(e))};if(kpe(e)){let i=t.length;return t.push(e),e.kind===`argument`?r.push(e):n.push(e),{_tag:`Param`,index:i}}return{_tag:`Nested`,tree:i(e)}}return{[vv]:vv,flags:n,arguments:r,orderedParams:t,tree:i(e)}},nme=yv({}),bv=(e,t)=>{let n={};for(let t of Object.keys(e))Ht(n,t,r(e[t]));return n;function r(e){switch(e._tag){case`Param`:return t[e.index];case`Array`:return e.children.map(e=>r(e));case`Nested`:return bv(e.tree,t)}}},xv=`~effect/cli/Command`,Sv=e=>e,rme={...Fn({label:`Command`,evaluate(){return Sv(this).service}})},Cv=e=>{let t=e.config,n=e.contextConfig??nme,r=e.service??mr(`~effect/cli/Command/${e.name}`),i=e.annotations??Er(),a=e.globalFlags??[],o=e.subcommands??[],s=e.resolveExamples??ime,c=(t,n)=>Ze(e.handle)?e.handle(t,n):A(new Gg({commandPath:n,errors:[]})),l=e.parse??Tv(t),u=e.parseContext??Tv(n,{allowLeftovers:!0}),d=n=>{let r=[],a=[];for(let e of t.arguments){let t=ov(e),n=cv(e);for(let e of t)r.push({name:e.name,type:e.typeName??Yg(e.primitiveType),description:e.description,required:n.isRequired,variadic:n.isVariadic})}let c=n.length>0?n.join(` `):e.name;o.some(e=>e.commands.some(e=>!e.unlisted))&&(c+=` <subcommand>`),c+=` [flags]`;for(let e of r){let t=e.variadic?`<${e.name}...>`:`<${e.name}>`;c+=` ${e.required?t:`[${t}]`}`}for(let e of t.flags){let t=ov(e),n=cv(e);for(let e of t)e.hidden||a.push(wv(e,n))}let l=[];for(let e of o){let t=e.commands.filter(e=>!e.unlisted);t.length!==0&&l.push({group:e.group,commands:Zr(t,e=>({name:e.name,alias:e.alias,shortDescription:e.shortDescription,description:e.description??``}))})}let u=s(n);return{description:e.description??``,usage:c,flags:a,annotations:i,...r.length>0&&{args:r},...l.length>0&&{subcommands:l},...u.length>0&&{examples:u}}};return Object.assign(Object.create(rme),{[xv]:xv,name:e.name,examples:s([e.name]),resolveExamples:s,annotations:i,globalFlags:a,subcommands:o,unlisted:e.unlisted??!1,config:t,contextConfig:n,service:r,parse:l,parseContext:u,handle:c,buildHelpDoc:d,...Ze(e.description)?{description:e.description}:{},...Ze(e.shortDescription)?{shortDescription:e.shortDescription}:{},...Ze(e.alias)?{alias:e.alias}:{}})},ime=()=>[],wv=(e,t)=>{let n=e.aliases.map(e=>e.length===1?`-${e}`:`--${e}`),r=e.typeName??Yg(e.primitiveType);return{name:e.name,aliases:n,type:e.optionalValue===void 0?r:`[=${r}]`,description:ame(e.description,Xg(e.primitiveType)),required:e.primitiveType._tag!==`Boolean`&&!t.isOptional}},ame=(e,t)=>{if(t===void 0||t.length===0)return e;let n=`(choices: ${t.join(`, `)})`;return ar(e,{onNone:()=>nr(n),onSome:e=>nr(`${e} ${n}`)})},Tv=(e,t)=>N(function*(n){let r={flags:n.flags,arguments:n.arguments},[i,a]=yield*ome(r,e.orderedParams);return t?.allowLeftovers!==!0&&i.length>0?yield*new Vg({arguments:i}):bv(e.tree,a)}),ome=N(function*(e,t){let n=[],r=e.arguments;for(let i of t){let[t,a]=yield*i.parse({flags:e.flags,arguments:r});n.push(a),r=t}return[r,n]}),sme=(e,t,n)=>{let r=Sv(e),i=new Set;(e=>{for(let t of e){let e=ov(t);for(let t of e)i.add(t.name)}})((n?.contextConfig??r.contextConfig).flags);for(let n of t){let t=Sv(n);for(let r of t.config.flags){let t=ov(r);for(let r of t)if(i.has(r.name))throw new Rg({option:r.name,parentCommand:e.name,childCommand:n.name})}}},cme=e=>{switch(e.primitiveType._tag){case`Boolean`:return{_tag:`Boolean`};case`Int`:return{_tag:`Int`};case`Finite`:return{_tag:`Finite`};case`Date`:return{_tag:`Date`};case`Choice`:return{_tag:`Choice`,values:Xg(e.primitiveType)??[]};case`Path`:return{_tag:`Path`,pathType:Zg(e.primitiveType)??`either`};case`FileText`:case`FileParse`:case`FileSchema`:return{_tag:`Path`,pathType:`file`};default:return{_tag:`String`}}},lme=e=>{switch(e.primitiveType._tag){case`Int`:return{_tag:`Int`};case`Finite`:return{_tag:`Finite`};case`Date`:return{_tag:`Date`};case`Choice`:return{_tag:`Choice`,values:Xg(e.primitiveType)??[]};case`Path`:return{_tag:`Path`,pathType:Zg(e.primitiveType)??`either`};case`FileText`:case`FileParse`:case`FileSchema`:return{_tag:`Path`,pathType:`file`};default:return{_tag:`String`}}},Ev=(e,t)=>{let n=e;switch(n._tag){case`Single`:return[[n,t===!0]];case`Map`:case`Optional`:return Ev(n.param,t);case`Transform`:return[...Ev(n.param,t),...n.alternatives.flatMap(e=>Ev(e(),t))];case`Variadic`:return Ev(n.param,t??!fr(n.max,e=>e<=1))}},Dv=(e,t=[])=>{let n=Sv(e),r=n.config,i=[],a=new Set;for(let[e,n]of[...r.flags,...t].entries())for(let[t,o]of Ev(n))t.hidden||e>=r.flags.length&&a.has(t.name)||(a.add(t.name),i.push({name:t.name,aliases:t.aliases,description:lr(t.description),type:cme(t),optionalValue:t.optionalValue!==void 0,repeatable:o,negation:t.negation}));let o=[];for(let e of r.arguments){let t=ov(e),n=cv(e);for(let e of t)e.kind===`argument`&&o.push({name:e.name,description:lr(e.description),required:!n.isOptional&&(!n.isVariadic||fr(n.variadicMin,e=>e>0)),variadic:n.isVariadic,type:lme(e)})}let s=[],c=[...t,...n.contextConfig.flags];for(let t of e.subcommands)for(let e of t.commands){if(e.unlisted)continue;let t=Dv(e,c);s.push(t),e.alias&&e.alias!==e.name&&s.push({...t,name:e.alias})}return{name:e.name,description:e.shortDescription??e.description,flags:i,arguments:o,subcommands:s}},Ov=e=>e.type._tag!==`Boolean`&&e.optionalValue!==!0,kv=e=>e.type._tag!==`Boolean`||e.negation===!1?void 0:e.negation??`no-${e.name}`,Av=e=>e.replace(/'/g,`'\\''`),jv=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),Mv=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let n=kv(e);return n!==void 0&&t.push(`--${n}`),t},ume=(e,t)=>{if(e.length===0)return;let n=e.map(Mv);t.push(` local ${n.map((e,t)=>`_used_${t}=""`).join(` `)}`),t.push(` for ((i = 1; i < cword; i++)); do`),t.push(' case "${words[i]%%=*}" in'),n.forEach((e,n)=>{t.push(` ${e.join(`|`)}) _used_${n}=1 ;;`)}),t.push(` esac`),t.push(` done`),t.push(` local _filtered_flags=""`),n.forEach((n,r)=>{let i=e[r].repeatable===!0?``:`[[ -n "$_used_${r}" ]] || `;t.push(` ${i}_filtered_flags+=" ${n.join(` `)}"`)}),t.push(``)},Nv=e=>[`\\\\`,`\\"`,`\\'`].map(t=>`${e}=\${${e}//${t}/}`).join(`; `),dme=(e,t)=>{t.push(`${e}()`),t.push(`{`),t.push(` local _cur="$1" _word="$2"; shift 2`),t.push(``),t.push(' local _head="${_cur%"$_word"}"'),t.push(` local _open=""`),t.push(` case "$_head" in`),t.push(` *\\') _open="'" ;;`),t.push(` *\\") _open='"' ;;`),t.push(` esac`),t.push(``),t.push(` local _prefix="$_cur" _committed="$_head"`),t.push(` ${Nv(`_prefix`)}`),t.push(` ${Nv(`_committed`)}`),t.push(``),t.push(` COMPREPLY=()`),t.push(` local _choice _rest _match`),t.push(` for _choice in "$@"; do`),t.push(` [[ "$_choice" == "$_prefix"* ]] || continue`),t.push(' _rest="${_choice#"$_committed"}"'),t.push(` case "$_open" in`),t.push(` "'")`),t.push(` if [[ "$_head" == "'" ]]; then`),t.push(" _match=${_rest//\\'/\\'\\\\\\'\\'}"),t.push(` else`),t.push(` [[ "$_rest" == *\\'* ]] && continue`),t.push(` _match="$_rest"`),t.push(` fi`),t.push(` ;;`),t.push(` '"')`),t.push(' _match="${_rest//\\\\/\\\\\\\\}"'),t.push(' _match="${_match//\\$/\\\\$}"'),t.push(' _match="${_match//\\`/\\\\\\`}"'),t.push(' _match="${_match//\\"/\\\\\\"}"'),t.push(` ;;`),t.push(` *)`),t.push(` printf -v _match '%q' "$_rest"`),t.push(` [[ -z "$_head" && "$_match" == '~'* ]] && _match="\\\\$_match"`),t.push(` ;;`),t.push(` esac`),t.push(` [[ -n "$_open" && "$_match" == *"$_open" ]] && _match+="$_open"`),t.push(` COMPREPLY+=("$_match")`),t.push(` done`),t.push(`}`),t.push(``)},fme=(e,t)=>{t.push(`${e.paths}()`),t.push(`{`),t.push(` local _kind="$1" _cur="$2" _word="$3"`),t.push(``),t.push(' local _prefix="$_cur" _committed="${_cur%"$_word"}"'),t.push(` ${Nv(`_prefix`)}`),t.push(` ${Nv(`_committed`)}`),t.push(``),t.push(` local _typed="" _dir="$_committed" _open="" _i`),t.push(` if [[ "$_word" == */* ]]; then`),t.push(' _typed="${_word%/*}/"'),t.push(' _dir="${_prefix%/*}/"'),t.push(` if [[ "$_cur" == "$_word" ]]; then`),t.push(" for ((_i = 0; _i < ${#_typed}; _i++)); do"),t.push(' case "$_open${_typed:_i:1}" in'),t.push(` \\\\|\\"\\\\) ((_i += 1)) ;;`),t.push(` \\"|\\') _open="\${_typed:_i:1}" ;;`),t.push(` \\"\\"|\\'\\') _open="" ;;`),t.push(` esac`),t.push(` done`),t.push(` fi`),t.push(` fi`),t.push(``),t.push(' local _path _names=() _rest="${_word#"$_typed"}"'),t.push(` while IFS= read -r _path; do`),t.push(` if [[ "$_path" == "$_dir"* ]]; then`),t.push(' _names+=("$_committed${_path#"$_dir"}")'),t.push(` elif [[ -z "$_committed" ]]; then`),t.push(` _names+=("$_path")`),t.push(` _typed="" _rest="" _open=""`),t.push(` fi`),t.push(` done < <(compgen "$_kind" -- "$_prefix")`),t.push(` if [[ -n "$_open" ]]; then`),t.push(` _typed+="$_open"`),t.push(' _rest="${_prefix##*/}"'),t.push(` fi`),t.push(``),t.push(` ${e.choices} "\${_cur%"$_word"}$_rest" "$_rest" "\${_names[@]}"`),t.push(" for ((_i = 0; _i < ${#COMPREPLY[@]}; _i++)); do"),t.push(' COMPREPLY[_i]="$_typed${COMPREPLY[_i]}"'),t.push(` done`),t.push(`}`),t.push(``)},Pv=(e,t)=>`${t.choices} "$cur" "$_comp_word" ${e.map(e=>`'${Av(e)}'`).join(` `)}`,Fv=(e,t)=>{switch(e._tag){case`Choice`:return Pv(e.values,t);case`Path`:return`${t.paths} ${e.pathType===`directory`?`-d`:`-f`} "$cur" "$_comp_word"`;default:return}},Iv=(e,t,n,r)=>{let i=[...t,e.name],a=`_${i.map(jv).join(`_`)}`;n.push(`${a}()`),n.push(`{`),n.push(` local cur prev words cword i`),n.push(t.length===0?` local _command_index=0`:` local _command_index="$1"`),n.push(` _init_completion -n "$COMP_WORDBREAKS" || return`),t.length===0&&n.push(` local _comp_word="$2"`),n.push(``);let o=e.flags.filter(Ov);if(o.length>0){n.push(` # Flag value completions`),n.push(` case "$prev" in`);for(let e of o){let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let i=Fv(e.type,r);i&&(n.push(` ${t.join(`|`)})`),n.push(` ${i}`),n.push(` return`),n.push(` ;;`))}n.push(` esac`),n.push(``)}if(e.subcommands.length>0){n.push(` # Subcommand dispatch`),n.push(` local cmd _skip_next=0`),n.push(` for ((i = _command_index + 1; i < cword; i++)); do`),n.push(` if (( _skip_next )); then`),n.push(` _skip_next=0`),n.push(` continue`),n.push(` fi`),n.push(' case "${words[i]}" in');for(let t of e.flags){if(!Ov(t))continue;let e=Mv(t);n.push(` ${e.join(`|`)}) _skip_next=1 ;;`),n.push(` ${e.map(e=>`${e}=*`).join(`|`)}) ;;`)}for(let t of e.subcommands){let e=`_${[...i,t.name].map(jv).join(`_`)}`;n.push(` ${t.name})`),n.push(` ${e} "$i"`),n.push(` return`),n.push(` ;;`)}n.push(` esac`),n.push(` done`),n.push(``)}ume(e.flags,n),(e.flags.length>0||e.subcommands.length>0)&&(n.push(` # Complete flags (filtered) and subcommands`),n.push(` if [[ "$cur" == -* ]]; then`),e.flags.length>0&&n.push(` COMPREPLY=( $(compgen -W "$_filtered_flags" -- "$cur") )`),n.push(` return`),n.push(` fi`),n.push(``));let s=e.arguments.flatMap((e,t)=>{let n=Fv(e.type,r);return n===void 0?[]:[{argument:e,completion:n,index:t}]});if(s.length>0){n.push(` # Positional argument completions`),n.push(` local _position=0 _skip_next=0 _end_of_options=0`),n.push(` for ((i = _command_index + 1; i < cword; i++)); do`),n.push(` if (( _skip_next )); then`),n.push(` _skip_next=0`),n.push(` continue`),n.push(` fi`),n.push(` if (( _end_of_options )); then`),n.push(` ((_position += 1))`),n.push(` continue`),n.push(` fi`),n.push(' case "${words[i]}" in'),n.push(` --) _end_of_options=1 ;;`);for(let t of e.flags){let e=Mv(t);Ov(t)?(n.push(` ${e.join(`|`)}) _skip_next=1 ;;`),n.push(` ${e.map(e=>`${e}=*`).join(`|`)}) ;;`)):n.push(` ${e.join(`|`)}) ;;`)}n.push(` -*) ;;`),n.push(` *) ((_position += 1)) ;;`),n.push(` esac`),n.push(` done`),n.push(` case "$_position" in`);for(let{argument:e,completion:t,index:r}of s)e.variadic||(n.push(` ${r})`),n.push(` ${t}`),n.push(` return`),n.push(` ;;`));n.push(` esac`);let t=s.find(({argument:e})=>e.variadic);t!==void 0&&(n.push(` if (( _position >= ${t.index} )); then`),n.push(` ${t.completion}`),n.push(` return`),n.push(` fi`))}else e.subcommands.length>0&&n.push(` ${Pv(e.subcommands.map(e=>e.name),r)}`);n.push(`}`),n.push(``);for(let t of e.subcommands)Iv(t,i,n,r)},pme=(e,t)=>{let n=[],r=jv(e),i={choices:`_${r}--choices`,paths:`_${r}--paths`};return n.push(`###-begin-${Av(e)}-completions-###`),n.push(`#`),n.push(`# Static completion script for Bash`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${Av(e)} --completions bash >> ~/.bashrc`),n.push(`#`),n.push(``),n.push(`if ! type _init_completion &>/dev/null; then`),n.push(` _init_completion()`),n.push(` {`),n.push(` COMPREPLY=()`),n.push(` local _i _j=0 _piece _line="$COMP_LINE"`),n.push(' words=("${COMP_WORDS[0]}")'),n.push(` cword=0`),n.push(' _line="${_line#*"${COMP_WORDS[0]}"}"'),n.push(" for ((_i = 1; _i < ${#COMP_WORDS[@]}; _i++)); do"),n.push(' _piece="${COMP_WORDS[_i]}"'),n.push(` if [[ "$_line" == [[:blank:]]* ]]; then`),n.push(` ((_j++))`),n.push(` words[_j]="$_piece"`),n.push(` else`),n.push(' words[_j]="${words[_j]}$_piece"'),n.push(` fi`),n.push(` ((_i == COMP_CWORD)) && cword=$_j`),n.push(' _line="${_line#*"$_piece"}"'),n.push(` done`),n.push(' cur="${words[cword]}"'),n.push(` prev=""`),n.push(' ((cword > 0)) && prev="${words[cword-1]}"'),n.push(` return 0`),n.push(` }`),n.push(`fi`),n.push(``),dme(i.choices,n),fme(i,n),Iv(t,[],n,i),n.push(`complete -F _${r} ${Av(e)}`),n.push(`###-end-${Av(e)}-completions-###`),n.join(`
44
+ `)},Lv=e=>e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`),Rv=e=>Lv(e.replace(/[^A-Za-z0-9_.,/@%+-]/gu,`\\$&`)),mme=(e,t)=>{if(e.length===0)return t.length>0?`__fish_use_subcommand`:``;let n=e.map(e=>`__fish_seen_subcommand_from ${e}`).join(`; and `);return t.length>0?`${n}; and not __fish_seen_subcommand_from ${t.join(` `)}`:n},zv=e=>{let t=[];for(let n of e.aliases)n.length===1&&t.push(`-s ${n}`);t.push(e.name);for(let n of e.aliases)n.length>1&&t.push(n);let n=kv(e);return n!==void 0&&t.push(n),`not __fish_contains_opt ${t.join(` `)}`},hme=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);return`begin; ${zv(e)}; or contains -- (commandline -poc)[-1] ${t.join(` `)}; end`},gme=e=>{let t=[`-l ${e.name}`];for(let n of e.aliases)n.length===1?t.push(`-s ${n}`):t.push(`-l ${n}`);e.description&&t.push(`-d '${Lv(e.description)}'`);let n=Ov(e)?_me(e.type):void 0;return n&&t.push(n),t},_me=e=>{switch(e._tag){case`Boolean`:return;case`Choice`:return`-r -f -a '${e.values.map(Rv).join(` `)}'`;case`Path`:return e.pathType,`-r -F`;default:return`-r -f`}},vme=e=>{switch(e._tag){case`Choice`:return`-r -f -a '${e.values.map(Rv).join(` `)}'`;case`Path`:return`-r -F`;default:return}},Bv=(e,t,n,r)=>{let i=t.subcommands.map(e=>e.name),a=mme(n,i),o=a?`-n '${a}'`:``;if(!t.arguments.some(e=>e.type._tag===`Path`)){let t=[`complete -c ${e}`];o&&t.push(o),t.push(`-f`),r.push(t.join(` `))}for(let n of t.subcommands){let t=[`complete -c ${e}`];o&&t.push(o),t.push(`-f -a '${Lv(n.name)}'`),n.description&&t.push(`-d '${Lv(n.description)}'`),r.push(t.join(` `))}for(let n of t.flags){let t=[a,n.repeatable===!0?``:Ov(n)?hme(n):zv(n)].filter(e=>e!==``).join(`; and `),i=t?`-n '${t}'`:``,o=[`complete -c ${e}`];i&&o.push(i),o.push(...gme(n)),r.push(o.join(` `));let s=kv(n);if(s!==void 0){let t=[`complete -c ${e}`];i&&t.push(i),t.push(`-l ${s}`),n.description&&t.push(`-d '${Lv(`Disable ${n.name}`)}'`),r.push(t.join(` `))}}if(t.flags.length>0){let n=`not string match -q -- "-*" (commandline -ct)`,i=a?`${a}; and ${n}`:n;for(let n of t.flags){let t=n.repeatable===!0?i:`${i}; and ${zv(n)}`,a=kv(n),o=[`complete -c ${e}`];if(o.push(`-n '${t}'`),o.push(`-f -a '--${n.name}'`),n.description&&o.push(`-d '${Lv(n.description)}'`),r.push(o.join(` `)),a!==void 0){let i=[`complete -c ${e}`];i.push(`-n '${t}'`),i.push(`-f -a '--${a}'`),n.description&&i.push(`-d '${Lv(`Disable ${n.name}`)}'`),r.push(i.join(` `))}}}for(let n of t.arguments){let t=vme(n.type);if(t){let i=[`complete -c ${e}`];o&&i.push(o),i.push(t),n.description&&i.push(`-d '${Lv(n.description)}'`),r.push(i.join(` `))}}for(let i of t.subcommands)Bv(e,i,[...n,i.name],r)},yme=(e,t)=>{let n=[];return n.push(`###-begin-${e}-completions-###`),n.push(`#`),n.push(`# Static completion script for Fish`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${e} --completions fish > ~/.config/fish/completions/${e}.fish`),n.push(`#`),n.push(``),Bv(e,t,[],n),n.push(``),n.push(`###-end-${e}-completions-###`),n.join(`
45
+ `)},Vv=e=>{let t=[],n=``;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i>=32&&i<128){n+=e[r]===`'`?`''`:e[r];continue}(n!==``||t.length===0)&&t.push(`'${n}'`),n=``,t.push(`[char]0x${i.toString(16).toUpperCase().padStart(4,`0`)}`)}return(n!==``||t.length===0)&&t.push(`'${n}'`),t.length===1?t[0]:`(${t.join(` + `)})`},Hv=e=>`@(${e.map(Vv).join(`, `)})`,Uv=e=>e?Vv(e):`$null`,bme=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),xme=e=>[`--${e.name}`,...e.aliases.map(e=>e.length===1?`-${e}`:`--${e}`)],Wv=e=>`values = ${Hv(e._tag===`Choice`?e.values:[])}; pathType = ${e._tag===`Path`?Vv(e.pathType):`$null`}`,Sme=e=>{let t=kv(e);return`@{ name = ${Vv(e.name)}; forms = ${Hv(xme(e))}; takesValue = $${e.type._tag!==`Boolean`}; `+(t===void 0?``:`negation = ${Vv(`--${t}`)}; `)+(e.optionalValue===!0?`optionalValue = $true; `:``)+(e.repeatable===!0?`repeatable = $true; `:``)+`${Wv(e.type)}; description = ${Uv(e.description)} }`},Cme=e=>`@{ name = ${Vv(e.name)}; variadic = $${e.variadic}; ${Wv(e.type)}; description = ${Uv(e.description)} }`,Gv=(e,t,n)=>{if(n.length===0){e.push(` ${t} = @()`);return}e.push(` ${t} = @(`);for(let t of n)e.push(` ${t}`);e.push(` )`)},Kv=(e,t,n,r,i)=>{let a=n.join(` `);if(!i.has(a)){i.add(a),r.push(`${e}[${Vv(a)}] = @{`),Gv(r,`subcommands`,t.subcommands.map(e=>`@{ name = ${Vv(e.name)}; description = ${Uv(e.description)} }`)),Gv(r,`flags`,t.flags.map(Sme)),Gv(r,`arguments`,t.arguments.map(Cme)),r.push(`}`);for(let a of t.subcommands)Kv(e,a,[...n,a.name],r,i)}},wme=e=>String.raw` param($wordToComplete, $commandAst, $cursorPosition)
46
+
47
+ $spec = ${e}
48
+ $results = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()
49
+ $booleanLiterals = @('true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n')
50
+
51
+ $index = {
52
+ param($context)
53
+ $lookup = [hashtable]::new([System.StringComparer]::Ordinal)
54
+ foreach ($flag in $context.flags) {
55
+ foreach ($form in $flag.forms) { $lookup[$form] = $flag }
56
+ }
57
+ $lookup
58
+ }
59
+
60
+ $add = {
61
+ param([string]$value, [string]$type, $tooltip, [string]$typed, [string]$textPrefix)
62
+ if (-not $value.StartsWith($typed, [System.StringComparison]::OrdinalIgnoreCase)) { return }
63
+ $text = $value
64
+ if ($value -notmatch '^[\w./:%+=\\-]+$') { $text = "'" + ($value -replace "['\u2018-\u201b]", '$0$0') + "'" }
65
+ $text = $textPrefix + $text
66
+ $label = $value
67
+ if (-not $label) { $label = $text }
68
+ if (-not $tooltip) { $tooltip = $label }
69
+ $results.Add([System.Management.Automation.CompletionResult]::new($text, $label, $type, $tooltip))
70
+ }
71
+
72
+ $addValues = {
73
+ param($entry, [string]$typed, [string]$textPrefix)
74
+ foreach ($value in $entry.values) {
75
+ if ($textPrefix -eq '' -and (& $optionLike $value)) { continue }
76
+ & $add $value 'ParameterValue' $entry.description $typed $textPrefix
77
+ }
78
+ if ($entry.pathType) {
79
+ foreach ($file in [System.Management.Automation.CompletionCompleters]::CompleteFilename($typed)) {
80
+ if ($entry.pathType -eq 'directory' -and $file.ResultType -ne 'ProviderContainer') { continue }
81
+ $results.Add([System.Management.Automation.CompletionResult]::new($textPrefix + $file.CompletionText, $file.ListItemText, $file.ResultType, $file.ToolTip))
82
+ }
83
+ }
84
+ }
85
+
86
+ $addFlags = {
87
+ param([string]$typed)
88
+ foreach ($flag in $context.flags) {
89
+ if (-not $flag.repeatable -and $used.ContainsKey($flag.name)) { continue }
90
+ foreach ($form in $flag.forms) {
91
+ & $add $form 'ParameterName' $flag.description $typed ''
92
+ }
93
+ if ($flag.negation) {
94
+ $tooltip = $null
95
+ if ($flag.description) { $tooltip = 'Disable ' + $flag.name }
96
+ & $add $flag.negation 'ParameterName' $tooltip $typed ''
97
+ }
98
+ }
99
+ }
100
+
101
+ # As in the CLI lexer, nothing after '--' is an option, and negative numbers
102
+ # and a lone '-' are values.
103
+ $optionLike = {
104
+ param([string]$word)
105
+ -not $endOfOptions -and $word -match '^-.' -and $word -notmatch '^-(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$'
106
+ }
107
+
108
+ # A typed value that has no candidates completes to itself, so the engine
109
+ # does not fall back to listing files.
110
+ $keepTyped = {
111
+ if ($results.Count -eq 0 -and $current) {
112
+ $results.Add([System.Management.Automation.CompletionResult]::new($current, $current, 'ParameterValue', $current))
113
+ }
114
+ }
115
+
116
+ $path = ''
117
+ $context = $spec[$path]
118
+ $lookup = & $index $context
119
+ $used = [hashtable]::new([System.StringComparer]::Ordinal)
120
+ $pending = $null
121
+ $endOfOptions = $false
122
+ $position = 0
123
+
124
+ # The engine strips the quotes from a quoted word.
125
+ $typed = [string]$wordToComplete
126
+ if ($typed -match '^([''"])(.*?)\1?$') { $typed = $Matches[2] }
127
+ $current = $null
128
+
129
+ $elements = $commandAst.CommandElements
130
+ for ($i = 1; $i -lt $elements.Count; $i++) {
131
+ $element = $elements[$i]
132
+ $word = $element.Extent.Text
133
+ if ($element -is [System.Management.Automation.Language.StringConstantExpressionAst]) { $word = $element.Value }
134
+ if ($element.Extent.EndOffset -ge $cursorPosition) {
135
+ if ($element -is [System.Management.Automation.Language.ConstantExpressionAst] -and $element.Extent.StartOffset -le $cursorPosition) {
136
+ $current = $element.Extent.Text
137
+ if ($element.Extent.EndOffset -eq $cursorPosition) { $typed = $word }
138
+ }
139
+ break
140
+ }
141
+
142
+ # A flag takes the next word as its value unless it is an option or '--';
143
+ # a boolean flag only takes a boolean literal.
144
+ $isOption = & $optionLike $word
145
+ if ($null -ne $pending) {
146
+ $flag = $pending
147
+ $pending = $null
148
+ if ($flag.takesValue) {
149
+ if (-not $isOption) { continue }
150
+ } elseif ($booleanLiterals -ccontains $word) { continue }
151
+ }
152
+ if ($endOfOptions) { $position++; continue }
153
+ if ($word -ceq '--') { $endOfOptions = $true; continue }
154
+
155
+ if ($isOption) {
156
+ $hasValue = $word.Contains('=')
157
+ if ($hasValue) {
158
+ $forms = @($word.Substring(0, $word.IndexOf('=')))
159
+ } elseif ($word.StartsWith('--')) {
160
+ $forms = @($word)
161
+ } else {
162
+ $forms = @(foreach ($char in $word.Substring(1).ToCharArray()) { '-' + $char })
163
+ }
164
+ foreach ($form in $forms) {
165
+ $pending = $null
166
+ $flag = $lookup[$form]
167
+ # As in the CLI parser, a negation wins over an alias but not over a
168
+ # canonical name.
169
+ if ($null -eq $flag -or $form -cne ('--' + $flag.name)) {
170
+ $negated = $null
171
+ foreach ($candidate in $context.flags) {
172
+ if ($candidate.negation -ceq $form) { $negated = $candidate }
173
+ }
174
+ if ($null -ne $negated) {
175
+ $used[$negated.name] = $true
176
+ continue
177
+ }
178
+ }
179
+ if ($null -eq $flag) { continue }
180
+ $used[$flag.name] = $true
181
+ # A flag with an optional value only takes a value attached with '='.
182
+ if (-not $hasValue -and -not $flag.optionalValue) { $pending = $flag }
183
+ }
184
+ continue
185
+ }
186
+
187
+ if ($position -eq 0 -and $context.subcommands.name -ccontains $word) {
188
+ if ($path) { $path = $path + ' ' + $word } else { $path = $word }
189
+ $context = $spec[$path]
190
+ $lookup = & $index $context
191
+ $used = [hashtable]::new([System.StringComparer]::Ordinal)
192
+ continue
193
+ }
194
+ $position++
195
+ }
196
+
197
+ $typedIsOption = & $optionLike $typed
198
+ if ($null -ne $pending -and $pending.takesValue -and -not $typedIsOption) {
199
+ & $addValues $pending $typed ''
200
+ & $keepTyped
201
+ return $results
202
+ }
203
+
204
+ if ($typedIsOption) {
205
+ if ($typed -match '^(-[^=]+)=(.*)$') {
206
+ $form = $Matches[1]
207
+ $flag = $lookup[$form]
208
+ if ($null -ne $flag -and $flag.takesValue) {
209
+ & $addValues $flag $Matches[2] ($form + '=')
210
+ & $keepTyped
211
+ }
212
+ } else {
213
+ & $addFlags $typed
214
+ }
215
+ return $results
216
+ }
217
+
218
+ if (-not $endOfOptions -and $position -eq 0) {
219
+ foreach ($sub in $context.subcommands) {
220
+ & $add $sub.name 'Command' $sub.description $typed ''
221
+ }
222
+ }
223
+
224
+ $arguments = $context.arguments
225
+ if ($position -lt $arguments.Count) {
226
+ & $addValues $arguments[$position] $typed ''
227
+ } elseif ($arguments.Count -gt 0 -and $arguments[-1].variadic) {
228
+ & $addValues $arguments[-1] $typed ''
229
+ }
230
+
231
+ if (-not $endOfOptions) {
232
+ & $addFlags $typed
233
+ }
234
+ return $results`,Tme=(e,t)=>{let n=`$global:_${bme(e)}_Completions`,r=[];return r.push(`###-begin-${e}-completions-###`),r.push(`#`),r.push(`# Static completion script for PowerShell`),r.push(`#`),r.push(`# Installation:`),r.push(`# ${e} --completions powershell > ${e}-completion.ps1`),r.push(`# then add this line to your $PROFILE (use the full path to the file):`),r.push(`# . <PATH>\\${e}-completion.ps1`),r.push(`#`),r.push(``),r.push(`${n} = [hashtable]::new([System.StringComparer]::Ordinal)`),Kv(n,t,[],r,new Set),r.push(``),r.push(`Register-ArgumentCompleter -Native -CommandName ${Vv(e)} -ScriptBlock {`),r.push(wme(n)),r.push(`}`),r.push(``),r.push(`###-end-${e}-completions-###`),r.join(`
235
+ `)},qv=e=>e.replace(/\\/g,`\\\\`).replace(/'/g,`'\\''`).replace(/:/g,`\\:`),Jv=e=>qv(e).replace(/]/g,`\\]`),Yv=e=>e.replace(/[^A-Za-z0-9_.,/@%+-]/gu,`\\$&`).replace(/'/g,`'\\''`),Xv=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),Eme=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let n=kv(e);return n!==void 0&&t.push(`--${n}`),t},Zv=e=>{switch(e._tag){case`Boolean`:return``;case`Choice`:return`:value:(${e.values.map(Yv).join(` `)})`;case`Path`:return e.pathType===`directory`?`:directory:_directories`:`:file:_files`;case`Int`:return`:integer:`;case`Finite`:return`:float:`;case`Date`:return`:date:`;default:return`:value:`}},Dme=e=>{switch(e._tag){case`Choice`:return`(${e.values.map(Yv).join(` `)})`;case`Path`:return e.pathType===`directory`?`_directories`:`_files`;default:return``}},Qv=e=>{let t=[],n=e.description?`[${Jv(e.description)}]`:``,r=e.optionalValue===!0&&e.type._tag!==`Boolean`,i=r?`=-`:``,a=r?`:${Zv(e.type)}`:Zv(e.type),o=e.repeatable===!0?`*`:`(${Eme(e).join(` `)})`;t.push(`'${o}--${e.name}${i}${n}${a}'`);for(let r of e.aliases){let e=r.length===1?`-`:`--`;t.push(`'${o}${e}${r}${i}${n}${a}'`)}let s=kv(e);if(s!==void 0){let n=e.description?`[${Jv(`Disable ${e.name}`)}]`:``;t.push(`'${o}--${s}${n}'`)}return t},$v=e=>{let t=e.description?qv(e.description):e.name,n=Dme(e.type);return`'${e.variadic?`*`:``}:${t}:${n}'`},ey=(e,t,n)=>{let r=[...t,e.name],i=`_${r.map(Xv).join(`_`)}`;if(n.push(`${i}() {`),e.subcommands.length>0){n.push(` local context state state_descr line`),n.push(` typeset -A opt_args`),n.push(``),n.push(` local -a commands`),n.push(` commands=(`);for(let t of e.subcommands){let e=t.description?qv(t.description):``;n.push(` '${qv(t.name)}:${e}'`)}n.push(` )`),n.push(``),n.push(` local -a specs`),n.push(` specs=(`);for(let t of e.flags)for(let e of Qv(t))n.push(` ${e}`);if(e.arguments.length>0){n.push(` -`),n.push(` parent-arguments`);for(let t of e.arguments)n.push(` ${$v(t)}`);n.push(` -`),n.push(` subcommands`)}n.push(` '1:command:->command'`),n.push(` '*::arg:->args'`),n.push(` )`),n.push(``),n.push(' _arguments -C "${specs[@]}"'),n.push(``),n.push(` case "$state" in`),n.push(` command)`),n.push(` _describe -t commands 'commands' commands`),n.push(` ;;`),n.push(` args)`),n.push(` case "$words[1]" in`);for(let t of e.subcommands){let e=`_${[...r,t.name].map(Xv).join(`_`)}`;n.push(` ${t.name})`),n.push(` ${e}`),n.push(` ;;`)}n.push(` esac`),n.push(` ;;`),n.push(` esac`)}else{let t=[];for(let n of e.flags)t.push(...Qv(n));for(let n of e.arguments)t.push($v(n));if(t.length>0){n.push(` local -a specs`),n.push(` specs=(`);for(let e of t)n.push(` ${e}`);n.push(` )`),n.push(' _arguments "${specs[@]}"')}}n.push(`}`),n.push(``);for(let t of e.subcommands)ey(t,r,n)},Ome=(e,t)=>{let n=[],r=Xv(e);return n.push(`#compdef ${e}`),n.push(`###-begin-${e}-completions-###`),n.push(`#`),n.push(`# Static completion script for Zsh`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${e} --completions zsh > ~/.zsh/completions/_${e}`),n.push(`# then add ~/.zsh/completions to your fpath`),n.push(`#`),n.push(``),ey(t,[],n),n.push(`# Handle both direct invocation and autoload`),n.push('if [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]; then'),n.push(` _${r} "$@"`),n.push(`else`),n.push(` compdef _${r} ${e}`),n.push(`fi`),n.push(`###-end-${e}-completions-###`),n.join(`
236
+ `)},kme=e=>Dv(e),Ame=(e,t,n)=>{switch(t){case`bash`:return pme(e,n);case`zsh`:return Ome(e,n);case`fish`:return yme(e,n);case`powershell`:return Tme(e,n)}},ty=e=>Ape(Z_,e),ny=e=>jpe(Z_,e),jme=e=>Mpe(Z_,e),ry=(e,t)=>tv(Z_,e,t),Mme=(e,t)=>Npe(Z_,e,t),iy=D(2,(e,t)=>Fpe(e,t)),ay=D(2,(e,t)=>Ipe(e,t)),oy=D(2,(e,t)=>Vpe(e,t)),sy=e=>rv(e),cy=zpe,ly=D(2,(e,t)=>Hpe(e,t)),uy=e=>{let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n},dy=(e,t)=>{let n=[e],r=e;for(let e=1;e<t.length;e++){let i=t[e],a;for(let e of r.subcommands)if(a=e.commands.find(e=>e.name===i),a)break;if(!a)break;n.push(a),r=a}return n},fy=(e,t,n)=>{let r=dy(e,t).flatMap(e=>Sv(e).globalFlags);return uy([...n,...r])},Nme=e=>{let t=[],n=e=>{let r=Sv(e);for(let e of r.globalFlags)t.push(e);for(let t of e.subcommands)for(let e of t.commands)n(e)};return n(e),uy(t)},Pme=(e,t)=>{if(e.length<=1)return[];let n=new Set(t.map(e=>e.name)),r=[];for(let t of e.slice(0,-1)){let e=Sv(t);for(let t of e.contextConfig.flags){let e=ov(t),i=cv(t);for(let t of e)n.has(t.name)||t.hidden||(n.add(t.name),r.push(wv(t,i)))}}return r},Fme=(e,t)=>uy([...t,...Nme(e)]),py=(e,t,n)=>Zc(function*(){let r=dy(e,t),i=r.length>0?r[r.length-1]:e,a=Sv(i).buildHelpDoc(t),o=Pme(r,a.flags),s=fy(e,t,n),c=[];for(let e of s){let t=ov(e.flag),n=cv(e.flag);for(let e of t)e.hidden||c.push({...wv(e,n),required:!1})}let l=1;for(let e=r.length-1;e>0;e--)if(Sv(r[e]).globalFlags.length>0){l=e+1;break}return{...a,inheritedFlags:o,globalFlags:c,globalFlagsScope:t.slice(0,l),commandPath:t}}),my=e=>({_tag:`Action`,flag:e.flag,run:e.run}),Ime=e=>t=>{hy+=1;let n=mr(`effect/cli/GlobalFlag/${e}/${hy}`);return Object.assign(n,{_tag:`Setting`,id:e,flag:t.flag})};let hy=0;const Lme=my({flag:ny(`help`).pipe(iy(`h`),ay(`Show help information`),cy(!1)),run:N(function*(e,{builtIns:t,command:n,commandPath:r}){let i=yield*fv,a=yield*py(n,r,t);yield*i.present({_tag:`Help`,reason:`Requested`,commandPath:r,helpDoc:a})})}),Rme=my({flag:ny(`version`).pipe(iy(`v`),ay(`Show version information`),cy(!1)),run:N(function*(e,{command:t,version:n}){yield*(yield*fv).present({_tag:`Version`,name:t.name,version:n})})}),gy=my({flag:ny(`wizard`).pipe(ay(`Start wizard mode for a command`),cy(!1)),run:()=>Jc}),zme=my({flag:ry(`completions`,[[`bash`,`bash`],[`zsh`,`zsh`],[`fish`,`fish`],[`powershell`,`powershell`],[`sh`,`bash`],[`pwsh`,`powershell`]]).pipe(sy,oy(`<bash|zsh|fish|powershell|sh|pwsh>`),ay(`Print shell completion script`)),run:N(function*(e,{command:t}){if(rr(e))return;let n=kme(t);yield*Cg(Ame(t.name,e.value,n))})}),_y=Ime(`log-level`)({flag:ry(`log-level`,[[`all`,`All`],[`trace`,`Trace`],[`debug`,`Debug`],[`info`,`Info`],[`warn`,`Warn`],[`warning`,`Warn`],[`error`,`Error`],[`fatal`,`Fatal`],[`none`,`None`]]).pipe(sy,ay(`Sets the minimum log level`),oy(`<all|trace|debug|info|warn|warning|error|fatal|none>`))}),Bme=[Lme,Rme,gy,zme,_y];var vy=class extends Ir(`effect/cli/CliConfig`,{defaultValue:()=>Vme}){};const Vme={builtIns:Bme},Hme=Pae(e=>k(kr(e,uv)??mv({colors:Mr(e,J_).canColor})));function Ume(e){let t=e.indexOf(`--`);return t===-1?{tokens:by(e),trailingOperands:[]}:{tokens:by(e.slice(0,t)),trailingOperands:e.slice(t+1)}}const Wme=e=>{if(e._tag===`Value`)return e.value;if(e._tag===`LongOption`)return e.raw;let t=yy.test(e.raw)?`--${e.flag}`:e.raw;return e.value===void 0?t:`${t}=${e.value}`},yy=/^-(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/,by=e=>{let t=[];for(let n of e)if(!n.startsWith(`-`)||yy.test(n))t.push({_tag:`Value`,value:n});else if(n.startsWith(`--`)){let e=n.indexOf(`=`);if(e!==-1){let r=n.slice(2,e);if(r===``)t.push({_tag:`Value`,value:n});else{let i=n.slice(e+1);t.push({_tag:`LongOption`,name:r,raw:n,value:i})}}else t.push({_tag:`LongOption`,name:n.slice(2),raw:n})}else if(n.length>1){let e=n.slice(1),r=e.indexOf(`=`);if(r!==-1){let n=Array.from(e.slice(0,r)),i=n.pop()??``;for(let e of n)t.push({_tag:`ShortOption`,flag:e,raw:`-${e}`});t.push({_tag:`ShortOption`,flag:i,raw:`-${i}`,value:e.slice(r+1)})}else for(let n of e)t.push({_tag:`ShortOption`,flag:n,raw:`-${n}`})}else t.push({_tag:`Value`,value:n});return t},Gme=(e,t)=>{let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let e=0;e<=n;e++)i[e][0]=e;for(let e=0;e<=r;e++)i[0][e]=e;for(let a=1;a<=n;a++)for(let n=1;n<=r;n++){let r=e[a-1]===t[n-1]?0:1;i[a][n]=Math.min(i[a-1][n]+1,i[a][n-1]+1,i[a-1][n-1]+r)}return i[n][r]},xy=(e,t)=>{let n=t.map(t=>[Gme(e,t),t]).filter(([e])=>e<=2).sort(([e],[t])=>e-t);if(n.length===0)return[];let r=n[0][0];return n.filter(([e])=>e===r).map(([,e])=>e)},Sy=e=>ar(e.subcommand,{onNone:()=>[],onSome:e=>[e.name,...Sy(e.parsedInput)]}),Cy=(e,t,n=[])=>Zc(function*(){let{tokens:r,trailingOperands:i}=e,a=[...n,t.name],o=Hy(r,Vy(t,a));if(o._tag===`Leaf`)return{flags:o.flags,arguments:[...o.arguments,...i],subcommand:O(),...o.errors.length>0&&{errors:o.errors}};let s={tokens:o.childTokens,trailingOperands:i},c=yield*Cy(s,o.sub,a),l=[...o.errors,...c.errors??[]];return{flags:o.flags,arguments:[],subcommand:nr({name:o.sub.name,parsedInput:c}),...l.length>0&&{errors:l}}}),wy=(e,t)=>{let n=Hy(e,Vy(t,[]));return n._tag===`Leaf`?e:wy(n.childTokens,n.sub)},Ty=e=>{let t=0;return{peek:()=>e[t],take:()=>e[t++],rest:()=>e.slice(t)}},Ey=e=>!Kg(e.primitiveType)||e.negation===!1?void 0:e.negation??`no-${e.name}`,Dy=e=>{let t=new Map,n=new Map;for(let r of e){if(t.has(r.name))throw Error(`Duplicate flag name "${r.name}" in command definition`);t.set(r.name,r);for(let e of r.aliases){if(t.has(e))throw Error(`Duplicate flag/alias "${e}" in command definition (conflicts with "${t.get(e).name}")`);t.set(e,r)}let e=Ey(r);if(e!==void 0){if(n.has(e))throw Error(`Duplicate negation "${e}" in command definition (conflicts with "${n.get(e).name}")`);n.set(e,r)}}return{params:e,index:t,negations:n}},Oy=e=>{let t=new Map,n=(e,n)=>{let r=t.get(e);if(r&&r!==n)throw Error(`Duplicate subcommand name/alias "${e}" in command definition (conflicts with "${r.name}")`);t.set(e,n)};for(let t of e)for(let e of t.commands)n(e.name,e),e.alias&&e.alias!==e.name&&n(e.alias,e);return t},ky=e=>Object.fromEntries(e.map(e=>[e.name,[]])),Kme=e=>{let t=ky(e);return{add:(e,n)=>{n!==void 0&&t[e].push(n)},merge:e=>{for(let n in e){let r=e[n];if(r?.length)for(let e=0;e<r.length;e++)t[n].push(r[e])}},snapshot:()=>t}},Ay=e=>e._tag===`LongOption`||e._tag===`ShortOption`,jy=e=>e._tag===`LongOption`?e.name:e.flag,My=(e,t)=>{let n=jy(e),r=t.index.get(n);if(r&&r.name===n)return{param:r,negated:!1};let i=e._tag===`LongOption`?t.negations.get(e.name):void 0;if(i)return{param:i,negated:!0};if(r)return{param:r,negated:!1}},Ny=(e,t,n)=>new Hg({option:t.name,value:n,expected:`omit the value and use ${e.raw} by itself to set --${t.name} to false`,kind:`flag`}),qme=e=>{let t=Xg(e.primitiveType);return new Hg({option:e.name,value:``,expected:t===void 0?e.typeName??Yg(e.primitiveType):t.join(` | `),kind:`flag`})},Py=e=>e?._tag===`Value`&&(Wde(e.value)||Gde(e.value))?e.value:void 0,Fy=(e,t,n,r=!1)=>{let i=Iy(e,t,n,r);switch(i._tag){case`Value`:return{_tag:`Value`,value:i.value};case`Error`:return{_tag:`Error`,error:i.error}}},Iy=(e,t,n,r=!1)=>{if(r){if(t.value!==void 0)return{_tag:`Error`,error:Ny(t,n,t.value),tokens:[]};let r=n.optionalValue===void 0?Py(e.peek()):void 0;if(r!==void 0){let i=e.take();return{_tag:`Error`,error:Ny(t,n,r),tokens:i===void 0?[]:[i]}}return{_tag:`Value`,value:`false`,tokens:[]}}if(t.value!==void 0)return{_tag:`Value`,value:t.value,tokens:[]};if(n.optionalValue!==void 0)return{_tag:`Value`,value:n.optionalValue,tokens:[]};if(Kg(n.primitiveType)){let t=Py(e.peek()),n=t===void 0?void 0:e.take();return{_tag:`Value`,value:t??`true`,tokens:n===void 0?[]:[n]}}let i=e.peek();if(i?._tag===`Value`){let t=e.take();return{_tag:`Value`,value:i.value,tokens:t===void 0?[]:[t]}}return{_tag:`Error`,error:qme(n),tokens:[]}},Jme=(e,t)=>{let n=ky(t.params),r=[],i=[],a=Ty(e);for(let e=a.take();e;e=a.take()){if(!Ay(e)){r.push(e);continue}let o=My(e,t);if(!o){r.push(e);continue}let s=Fy(a,e,o.param,o.negated);if(s._tag===`Error`){i.push(s.error);continue}s.value!==void 0&&n[o.param.name].push(s.value)}return{flagMap:n,remainder:r,errors:i}},Ly=e=>Sv(e).config.flags.flatMap(ov).filter($_),Ry=e=>Sv(e).contextConfig.flags.flatMap(ov).filter($_),zy=(e,t)=>{for(let n of t){let t=My(e,n);if(t!==void 0)return t}},By=(e,t,n,r)=>{e.push(n);let i=Iy(t,n,r.param,r.negated);e.push(...i.tokens)},Yme=(e,t,n,r,i)=>{let a=Ty(t);Iy(a,e,n.param,n.negated);for(let e=a.take();e;e=a.take()){if(Ay(e)){let t=zy(e,i);t!==void 0&&Iy(a,e,t.param,t.negated);continue}if(e._tag===`Value`)return r.has(e.value)}return!1},Xme=(e,t,n)=>{let r=ky(n.params),i=[],a=(e,t,o)=>{let s=Dy(Ly(t)),c=Dy(Ry(t)),l=Oy(t.subcommands),u=Ty(e),d=[],f=!0;for(let e=u.take();e;e=u.take()){if(Ay(e)){let t=zy(e,o);if(t!==void 0){By(d,u,e,t);continue}let a=My(e,c);if(a!==void 0){By(d,u,e,a);continue}let p=My(e,s),m=My(e,n);if(p!==void 0&&(m===void 0||!f||!Yme(e,u.rest(),p,l,[s,c,n]))){By(d,u,e,p);continue}if(m!==void 0){let t=Iy(u,e,m.param,m.negated);if(t._tag===`Error`){i.push(t.error);continue}t.value!==void 0&&r[m.param.name].push(t.value);continue}d.push(e);continue}if(e._tag===`Value`&&f){let t=l.get(e.value);if(t!==void 0)return d.push(e),d.push(...a(u.rest(),t,[...o,c])),d;f=!1}d.push(e)}return d};return{flagMap:r,remainder:a(e,t,[]),errors:i}},Zme=(e,t,n)=>{let r=e._tag===`LongOption`?`--${e.name}`:`-${e.flag}`,i=[];for(let e of t){if(e.hidden)continue;i.push(e.name);let t=Ey(e);t!==void 0&&i.push(t);for(let t of e.aliases)i.push(t)}return new Lg({option:r,suggestions:xy(jy(e),i).map(e=>e.length===1?`-${e}`:`--${e}`),command:n})},Qme=e=>({flags:Kme(e.params),arguments:[],errors:[],mode:{_tag:`AwaitingFirstValue`}}),$me=e=>({_tag:`Leaf`,flags:e.flags.snapshot(),arguments:e.arguments,errors:e.errors}),ehe=(e,t,n,r)=>{let{command:i,commandPath:a,inheritedFlagRegistry:o,localFlagNames:s}=n,c=Oy(i.subcommands),l=c.get(e);if(l){let e=[...a,l.name],n=r.flags.snapshot();for(let t of s){let i=n[t];i!==void 0&&i.length>0&&r.errors.push(new Lg({option:`--${t}`,suggestions:[],command:e}))}let i=Jme(t.rest(),o);return r.flags.merge(i.flagMap),r.errors.push(...i.errors),{_tag:`Subcommand`,result:{_tag:`Sub`,flags:r.flags.snapshot(),sub:l,childTokens:i.remainder,errors:r.errors}}}if(!(Sv(i).config.arguments.length>0)&&c.size>0){let t=[];for(let[e,n]of c)n.unlisted||t.push(e);let n=xy(e,t);r.errors.push(new Ug({subcommand:e,parent:a,suggestions:n}))}return{_tag:`Argument`}},the=(e,t,n,r)=>{let{commandPath:i,flagRegistry:a}=n,o=My(e,a);if(!o){r.errors.push(Zme(e,a.params,i));return}let s=Fy(t,e,o.param,o.negated);if(s._tag===`Error`){r.errors.push(s.error);return}r.flags.add(o.param.name,s.value)},nhe=(e,t,n,r)=>{if(r.mode._tag===`AwaitingFirstValue`){let i=ehe(e,t,n,r);if(i._tag===`Subcommand`)return i.result;r.mode={_tag:`CollectingArguments`}}r.arguments.push(e)},Vy=(e,t)=>{let n=Ly(e),r=Ry(e),i=new Set(r.map(e=>e.name));return{command:e,commandPath:t,flagRegistry:Dy(n),inheritedFlagRegistry:Dy(r),localFlagNames:n.filter(e=>!i.has(e.name)).map(e=>e.name)}},Hy=(e,t)=>{let n=Ty(e),r=Qme(t.flagRegistry);for(let e=n.take();e;e=n.take()){if(Ay(e)){the(e,n,t,r);continue}if(e._tag===`Value`){let i=nhe(e.value,n,t,r);if(i)return i}}return $me(r)},rhe=N(function*(e,t){let n=t?.commandPath??[e.name],r=ihe(e,n),i=(t?.prefix??n).map(e=>Gy(e)),{colors:a}=yield*u_;return yield*qy(i,a),yield*Uy(r,i,r===e?`ROOT`:r.name,a),{args:i.map(e=>e.value),displayArgs:i.map(e=>e.displayValue)}}),ihe=(e,t)=>{let n=e;for(let e of t.slice(1)){let t=n.subcommands.flatMap(e=>e.commands).find(t=>t.name===e||t.alias===e);if(t===void 0)break;n=t}return n},Uy=N(function*(e,t,n,r){let i=Sv(e),a=e.subcommands.flatMap(e=>e.commands.filter(e=>!e.unlisted)),o=a.length===0?i.config:i.contextConfig;if(o.flags.length>0){yield*Cg(Jy(n,`FLAGS`,r));for(let e of o.flags)t.push(...yield*Wy(e));(o.arguments.length>0||a.length>0)&&(yield*qy(t,r))}if(o.arguments.length>0){yield*Cg(Jy(n,`ARGUMENTS`,r)),a.length===0&&t.push(Gy(`--`));for(let e of o.arguments)t.push(...yield*Wy(e));a.length>0&&(yield*qy(t,r))}if(a.length===0)return;let s=yield*v_(y_({message:`Command`,choices:a.map(e=>({title:e.name,value:e,...e.shortDescription===void 0?e.description===void 0?{}:{description:e.description}:{description:e.shortDescription}}))}));yield*Cg(),t.push(Gy(s.name)),ahe(s)&&(yield*qy(t,r)),yield*Uy(s,t,s.name,r)}),ahe=e=>e.subcommands.some(e=>e.commands.some(e=>!e.unlisted))||Sv(e).config.orderedParams.length>0,Wy=N(function*(e){let t=sv(e),n=cv(e);if(n.isOptional&&!(yield*v_(h_({message:`Set ${Ky(t)}?`,initial:!1}))))return yield*Cg(),[];let r=n.isVariadic?yield*v_(__({message:`${Ky(t)} count`,default:or(n.variadicMin,()=>0),min:or(n.variadicMin,()=>0),...ir(n.variadicMax)?{max:n.variadicMax.value}:{}})):1,i=[];for(let e=0;e<r;e++)i.push(yield*ohe(t));let a=t.kind===`flag`?{flags:{[t.name]:i.map(e=>e.value)},arguments:[]}:{flags:{},arguments:i.map(e=>e.value)};return yield*e.parse(a),yield*Cg(),t.kind===`argument`?i:i.flatMap(e=>t.optionalValue!==void 0||e.value.startsWith(`-`)&&e.value.length>1?[Gy(`--${t.name}=${e.value}`,`--${t.name}=${e.displayValue}`)]:[Gy(`--${t.name}`),e])}),ohe=e=>{let t=che(e);switch(e.primitiveType._tag){case`Boolean`:return M(v_(h_({message:t,label:{confirm:`true`,deny:`false`},placeholder:{defaultConfirm:`(T/f)`,defaultDeny:`(t/F)`}})),e=>Gy(String(e)));case`Choice`:{let n=Xg(e.primitiveType)??[];return M(v_(y_({message:t,choices:n.map(e=>({title:e,value:e}))})),Gy)}case`Date`:return M(v_(nfe({message:t})),e=>Gy(e.toISOString()));case`Finite`:return M(v_(ife({message:t})),e=>Gy(String(e)));case`Int`:return M(v_(__({message:t})),e=>Gy(String(e)));case`Redacted`:return M(v_(ofe({message:t})),e=>Gy(dd(e),`<redacted>`));default:return M(v_(lfe({message:t})),Gy)}},Gy=(e,t=e)=>({value:e,displayValue:t}),she=e=>e.kind===`flag`?`--${e.name}`:e.name,che=e=>Ky(e),Ky=e=>{let t=lr(e.description)?.trim(),n=e.kind===`flag`&&t!==void 0&&t.length<=32?t:lhe(e.name);return e.kind===`flag`?`${n} (${she(e)})`:n},lhe=e=>{let t=e.split(/[-_]+/).filter(e=>e.length>0);return t.length===0?e:[t[0][0].toUpperCase()+t[0].slice(1),...t.slice(1)].join(` `)},qy=(e,t)=>Cg(Yy(`Current command`,e.map(e=>e.displayValue),t,`\x1B[35m`)),Jy=(e,t,n)=>`${o_(n,e.toUpperCase(),Qg,a_)} ${o_(n,`·`,i_)} ${o_(n,t,Qg,r_)}`,uhe=(e,t,n,r)=>[`${o_(r,e,Qg,a_)} ${o_(r,`v${t}`,r_)} ${o_(r,`· Command wizard`,Qg,r_)}`,...n===void 0||n.length===0?[]:[n],o_(r,`Build a command interactively. Press Ctrl+C to cancel.`,i_),``].join(`
237
+ `),dhe=(e,t)=>Yy(`Command ready`,e,t,a_,n_),fhe=e=>`\n${o_(e,`Wizard cancelled.`,t_)}`,Yy=(e,t,n,r,i=r_)=>{let a=phe(t);return[o_(n,e,Qg,i),...a.map(e=>o_(n,e,r)),``].join(`
238
+ `)},phe=e=>{let t=` $ `,n=` `,r=e.map(mhe),i=[],a=t;for(let e of r){let r=a===t||a===n?``:` `;a.length+r.length+e.length>88&&a!==t?(i.push(`${a} \\`),a=`${n}${e}`):a+=`${r}${e}`}return a!==t&&i.push(a),i},mhe=e=>/^[A-Za-z0-9_./:@%+=,-]+$/.test(e)?e:`'${e.replaceAll(`'`,`'"'"'`)}'`,hhe=e=>et(e,xv),Xy=(e,t,n)=>{let r=yv(t??{});return Cv({name:e,config:r,...Ze(n)?{handle:n}:{}})},ghe=e=>{let t=[],n=new Map,r=(e,r)=>{t.push(r);let i=n.get(e);i?i.push(r):n.set(e,[r])};for(let t of e){if(hhe(t)){r(void 0,t);continue}for(let e of t.commands)r(t.group,e)}let i=[],a=n.get(void 0);a&&a.length>0&&i.push({group:void 0,commands:a});for(let[e,t]of n)e!==void 0&&i.push({group:e,commands:t});return{flat:t,groups:i}},_he=D(2,(e,t)=>{let n=ghe(t);sme(e,n.flat);let r=Sv(e),i=new Map(n.flat.map(e=>[e.name,Sv(e)])),a=Symbol(`effect/cli/SubcommandState`),o=N(function*(e){if(rr(e.subcommand))return yield*r.parse(e);let t=i.get(e.subcommand.value.name);if(!t)return yield*r.parse(e);let n=yield*r.parseContext(e),o=yield*t.parse(e.subcommand.value.parsedInput);return{...n,[a]:{name:t.name,result:o}}}),s=N(function*(e,t){let n=e[a];if(n){let a=i.get(n.name);return a?yield*a.handle(n.result,[...t,a.name]).pipe(kl(r.service,e)):yield*new Gg({commandPath:t,errors:[]})}return yield*r.handle(e,t)});return Cv({name:r.name,config:r.config,contextConfig:r.contextConfig,description:r.description,shortDescription:r.shortDescription,alias:r.alias,unlisted:r.unlisted,annotations:r.annotations,globalFlags:r.globalFlags,resolveExamples:r.resolveExamples,service:r.service,subcommands:n.groups,parse:o,parseContext:r.parseContext,handle:s})}),Zy=D(2,(e,t)=>Cv({...Sv(e),description:t})),vhe=D(2,(e,t)=>Cv({...Sv(e),resolveExamples:Ye(t)?e=>t({commandPath:e}):()=>t})),yhe=(e,t,n,r)=>{let i=new Set(t),a=[],o=new Set;for(let t of e){if(i.has(t))continue;let e=ov(t.flag);for(let t of e){let e=n[t.name];if(!e||e.length===0)continue;let i=`--${t.name}`;o.has(i)||(o.add(i),a.push(new Lg({option:i,suggestions:[],command:r})))}}return a},bhe=(e,t,n)=>Zc(function*(){let{builtIns:r}=yield*vy,i=yield*fv,{commandPath:a,errors:o}=t,s=yield*py(e,a,r);yield*i.present(n&&o.length>0?{_tag:`InvalidInvocation`,commandPath:a,helpDoc:s,errors:o}:{_tag:`Help`,reason:`Implicit`,commandPath:a,helpDoc:s})}),xhe=(e,t)=>Zc(function*(){let n=yield*Hme,r=e instanceof Wg?e:new Wg({cause:e,userMessage:t});yield*Sg(n.formatError(r)),Object.assign(e,{[Og]:!1})}),Qy=(e,t)=>{let n=Sv(e);return N(function*(r){let{builtIns:i}=yield*vy,{tokens:a,trailingOperands:o}=Ume(r),s=Fme(e,i),c=s.flatMap(e=>ov(e.flag)),l=Dy(c.filter($_)),{flagMap:u,remainder:d,errors:f}=Xme(a,e,l),p={flags:u,arguments:[]},m=yield*Cy({tokens:d,trailingOperands:o},e),h=[e.name,...Sy(m)],g=e=>e._tag===`ShowHelp`?e:new Gg({commandPath:h,errors:[e]}),_=hl(g),v={builtIns:i,command:e,commandPath:h,version:t.version},y=fy(e,h,i),b=yhe(s,y,u,h);if(b.length>0||f.length>0){let e=m.errors??[];return yield*new Gg({commandPath:h,errors:[...f,...b,...e]})}for(let n of y){if(n._tag!==`Action`||!ov(n.flag).some(e=>{let t=u[e.name];return t!==void 0&&t.length>0}))continue;let[,r]=yield*n.flag.parse(p).pipe(_);if(n===gy){let{colors:n}=yield*u_;return yield*Zc(function*(){yield*Cg(uhe(e.name,t.version,e.description,n));let r=new Set(wy(d,e)),i=[e.name,...a.filter(e=>!r.has(e)&&(e._tag!==`LongOption`||e.name!==`wizard`)).map(Wme)],o=yield*rhe(e,{commandPath:h,prefix:i});yield*Cg(dhe(o.displayArgs,n)),(yield*v_(ufe({message:`Run this command?`,initial:!0,active:`yes`,inactive:`no`})))&&(yield*Cg(),yield*Qy(e,{...t,renderErrors:!1})(o.args.slice(1)))}).pipe(dl(`QuitError`,()=>Cg(fhe(n))))}yield*n.run(r,v);return}if(m.errors&&m.errors.length>0)return yield*new Gg({commandPath:h,errors:m.errors});let ee=yield*n.parse(m).pipe(hl(e=>Fg(e)?g(e):e)),x=n.handle(ee,[e.name]),te=y.includes(_y)?(yield*_y.flag.parse(p).pipe(_))[1]:O();x=kl(x,_y,te);for(let e of y){if(e._tag!==`Setting`||e===_y)continue;let[,t]=yield*e.flag.parse(p).pipe(_);x=kl(x,e,t)}let ne=ar(te,{onNone:()=>Er(),onSome:e=>Dr(Hie,e)});yield*Dl(x,ne)},ml(e=>Fg(e)&&e._tag===`ShowHelp`?zr(e):Br(e),n=>il(bhe(e,n,t.renderErrors!==!1),A(n))),ml(e=>{if(t.renderErrors===!1||!$e(e))return Br(e);let n=Bde(e);return n===void 0?Br(e):zr({error:e,userMessage:n})},({error:e,userMessage:t})=>il(xhe(e,t),A(e))),ml(e=>Rde(e)?zr(e):Br(e),e=>Ll))},$y={client:F({name:P,version:P}),service:P,operation:P,projection:L(P)},She=F({...$y,answer:F({kind:Tm(`answered`),body:P})}),eb=F({...$y,answer:F({kind:Tm(`refused`),code:P,message:P})}),tb=Am([She,eb]),nb={reply:eb,readAt:P};var Che=class extends nh()(`InvalidGroup.NotFound`,nb){},whe=class extends nh()(`InvalidInstanceID.NotFound`,nb){},The=class extends nh()(`InvalidVolume.NotFound`,nb){},Ehe=class extends nh()(`InvalidNetworkInterfaceID.NotFound`,nb){},Dhe=class extends nh()(`AwsServiceError`,{...nb,code:P}){},rb=class extends nh()(`AwsReadError`,{operation:P,reason:jm([`process`,`filesystem`,`decode`,`client`,`budget`]),message:P,retryable:Cm(Dm),observation:Cm(F({reply:tb,readAt:P}))}){};const Ohe=new Set([`RequestLimitExceeded`,`Throttling`,`ThrottlingException`,`ThrottledException`,`RequestThrottled`,`RequestThrottledException`,`EC2ThrottledException`,`SlowDown`,`TooManyRequestsException`,`RequestTimeout`,`RequestTimeoutException`,`PriorRequestNotComplete`,`InternalError`,`InternalFailure`,`InternalServerError`,`ServiceUnavailable`,`Unavailable`,`500`,`502`,`503`,`504`]),ib=e=>e._tag===`AwsServiceError`?Ohe.has(e.code):e._tag===`AwsReadError`&&e.retryable===!0,ab=jm([`provider`,`client`,`process`,`filesystem`,`decode`,`selection`,`account`]),ob=e=>e._tag===`UsageError`?{operation:`InputValidation`,kind:`client`,code:e._tag,message:e.message}:e._tag===`AwsReadError`?{operation:e.operation,kind:e.reason===`budget`?`client`:e.reason,code:e._tag,message:e.message}:{operation:e.reply.operation,kind:`provider`,code:e.reply.answer.code,message:e.reply.answer.message},sb=e=>{let t=ob(e);return`Deadline reached while ${t.code} persisted: ${t.message}`};var cb=class extends mr()(`@openteammate/ec2-instance/Ec2Api`){},lb=class extends mr()(`@openteammate/ec2-instance/SsmApi`){},ub=class extends nh()(`UsageError`,{message:P}){exitCode=2},db=class extends nh()(`LifecycleError`,{operation:P,message:P,exitCode:jm([1,3])}){};const fb=e=>e.replace(/(?<![a-zA-Z0-9])\d{12}(?![a-zA-Z0-9])/g,`1234****5678`),pb=(e,t)=>fb(t)===t?Jc:A(new ub({message:`${e} contains an account-shaped twelve-digit value; nothing was sent.`})),mb=N(function*(e,t,n){yield*pb(`${e} path`,t),yield*pb(e,n),yield*(yield*gg).writeFileString(t,n,{mode:384})}),khe=e=>et(e,`code`)&&Ke(e.code)?e.code:void 0,Ahe=e=>{try{process.kill(e,0);return}catch(e){return e}},hb=e=>Kc(()=>{let t=Ahe(-e);if(t===void 0)return k({_tag:`Succeeded`});let n=khe(t);return n===void 0?el(t):k({_tag:`Failed`,code:n})}),gb=e=>e._tag===`Failed`&&e.code===`ESRCH`,jhe=(e,t)=>gb(e)||t._tag===`Read`&&t.processes.length>0&&t.processes.every(({state:e})=>e.startsWith(`Z`))?`observed`:e._tag===`Succeeded`?`not-observed`:`unknown`,_b=/^\d+$/,Mhe=e=>{let[t,n,r,...i]=e.trim().split(/\s+/);return t!==void 0&&n!==void 0&&r!==void 0&&i.length===0&&_b.test(t)&&_b.test(n)?{pid:Number(t),pgid:Number(n),state:r}:void 0},Nhe=(e,t)=>{let n=[];for(let r of e.split(`
239
+ `)){if(r.trim()===``)continue;let e=Mhe(r);if(e===void 0)return{_tag:`Unreadable`,why:`ps listed ${JSON.stringify(r)}, which is not a pid, a process group and a state`};e.pgid===t&&n.push({pid:e.pid,state:e.state})}return{_tag:`Read`,processes:n}},Phe=Di(10),Fhe=(e,t,n)=>Zc(function*(){let r=yield*Bl(hb(e),{schedule:zc(Phe),while:e=>!gb(e)&&M(sc,e=>e<t)});if(gb(r))return{groupGone:`observed`,evidence:{lastProbe:r,members:{_tag:`NotRead`}}};let i=yield*n,a=yield*hb(e);return{groupGone:jhe(a,i),evidence:{lastProbe:a,members:i}}}),Ihe=/^Process interrupted due to receipt of signal: '([A-Z0-9]+)'$/,Lhe=e=>{if(e instanceof Error)return Ihe.exec(e.message)?.[1]},vb=(e,t)=>({_tag:`Capture`,limitBytes:e,onExceed:t}),Rhe={_tag:`Ignore`},yb=Am([Im(`Captured`,{bytes:Lle,totalBytes:Hm,truncated:Dm,omitted:Cm(F({at:Hm,bytes:Hm})),closed:Dm}),Im(`Forwarded`,{forwardedBytes:Hm,totalBytes:Hm,truncated:Dm,closed:Dm}),Im(`Ignored`,{})]),bb=Am([Im(`Exited`,{code:Hm}),Im(`Signaled`,{signal:P})]),zhe=Am([Im(`None`,{}),Im(`Fed`,{bytesWritten:Hm,ended:jm([`source-done`,`child-closed`,`stopped`])})]),Bhe=Am([Im(`Succeeded`,{}),Im(`Failed`,{code:P})]),Vhe=Am([Im(`NotRead`,{}),Im(`Read`,{processes:I(F({pid:Hm,state:P}))}),Im(`Unreadable`,{why:P})]),xb=F({pid:Hm,executable:P,exit:bb,stdin:zhe,stdout:yb,stderr:yb,termination:F({by:L(jm([`deadline`,`stop`,`output-limit`])),reason:L(P),requestedAt:L(P),groupGone:jm([`observed`,`not-observed`,`unknown`,`not-applicable`]),confirmedAt:L(P),group:L(F({lastProbe:Bhe,members:Vhe}))}),durationMs:Hm}).annotate({identifier:`@inkeep/impulse-owned-process/ProcessRecord`}),Sb=F({pid:Hm.check(Vm({minimum:1,maximum:2**31-1})),startedAt:P.check(Um(1))});F({identity:Sb,releasedAt:P,deadlineAt:P}).annotate({identifier:`@inkeep/impulse-owned-process/HandOff`});const Hhe=Am([Im(`SpawnFailed`,{code:P}),Im(`DeadlineExceeded`,{record:xb}),Im(`OutputLimit`,{stream:jm([`stdout`,`stderr`]),limitBytes:Hm,record:xb}),Im(`ExitFailed`,{record:xb}),Im(`ReleaseRefused`,{why:jm([`exited`,`identity-unavailable`]),record:L(xb)})]),Uhe=e=>e.exit._tag===`Exited`?`exited ${e.exit.code}`:`ended by ${e.exit.signal}`,Whe=e=>{if(e._tag===`SpawnFailed`)return`SpawnFailed: ${e.code}`;if(e._tag===`ReleaseRefused`)return`ReleaseRefused: ${e.why}`;if(e._tag===`OutputLimit`)return`OutputLimit: ${e.record.executable} passed its ${e.limitBytes}-byte ${e.stream} capture`;let t=e._tag===`DeadlineExceeded`?` after its deadline`:``;return`${e._tag}: ${e.record.executable} ${Uhe(e.record)}${t}`};var Cb=class extends nh()(`ProcessError`,{reason:Hhe}){get message(){return Whe(this.reason)}};const Ghe=rh(),Khe=rh(),wb=`~effect/process/ChildProcessSpawner/ChildProcessHandle`,qhe={[wb]:wb,...Lt,toJSON(){return{_id:`ChildProcessHandle`,pid:this.pid}}},Tb=e=>Object.setPrototypeOf({...e},qhe),Jhe=e=>{let t=(t,n)=>e(t).pipe(M(e=>dg(n?.includeStderr===!0?e.all:_de(e.stdout,e.stderr))),lg),n=(e,n)=>Sde(t(e,n));return Eb.of({spawn:e,exitCode:t=>jl(j(e(t),e=>Sl(e.exitCode,il(pg(e.all),Xc)))),streamString:t,streamLines:n,lines:(e,t)=>wde(n(e,t)),string:(e,n)=>mg(t(e,n))})};var Eb=class extends mr()(`effect/process/ChildProcessSpawner`){},Db=class extends Bi(`CommandLineError`){};const Yhe=(e,t)=>{if(e.length===0)return``;let n=t?.format??`posix`;return ege(n,e.map((e,t)=>ld(e)?`<redacted>`:lge($he(n,e,t===0))))},Xhe=(e,...t)=>{let n=e.findIndex(e=>e===void 0);return n===-1?mge(e,t):Br(new Db({reason:`InvalidEscape`,message:`Template part ${n} contains an invalid escape sequence`}))},Zhe=e=>ld(e)?dd(e):String(e),Ob=e=>ld(e)?e:String(e),Qhe=new Set(`!.{.}.and.begin.case.coproc.do.done.elif.else.end.esac.fi.for.foreach.function.if.in.nocorrect.not.or.repeat.select.switch.then.time.until.while`.split(`.`)),$he=(e,t,n)=>{switch(e){case`posix`:return n&&Qhe.has(t)?`'${t}'`:nge(t);case`powershell`:return rge(t);case`windows`:return n&&!t.includes(`"`)?oge(t):age(t)}},ege=(e,t)=>e===`powershell`?`& ${t.join(` `)}`:t.join(` `),tge=/^[A-Za-z0-9_@+:,./-]+$/,nge=e=>tge.test(e)?e:`'${e.replace(/['\\]/g,e=>`'\\${e}'`)}'`,rge=e=>`'${e.replace(/['\u2018\u2019\u201A\u201B]/g,`$&$&`)}'`,ige=/[ \t\n\v"]/,age=e=>{if(e.length>0&&!ige.test(e))return e;let t=`"`,n=0;for(let r of e)r===`\\`?n++:r===`"`?(t+=`\\`.repeat(n*2+1)+`"`,n=0):(t+=`\\`.repeat(n)+r,n=0);return t+`\\`.repeat(n*2)+`"`},oge=e=>e.length>0&&!/[ \t]/.test(e)?e:`"${e}"`,sge=/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g,cge={"\n":`\\n`,"\r":`\\r`," ":`\\t`},lge=e=>e.replace(sge,e=>cge[e]??`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`),uge=/[A-Za-z_0-9{(@*#?$!'"-]/,dge=/[A-Za-z_0-9{(@*#?$!-]/,fge=/^[A-Za-z_][A-Za-z0-9_]*\+?$/,kb=e=>e===` `||e===` `||e===`
240
+ `,pge=(e,t,n)=>{if(`|&;<>()`.includes(e))return`The operator "${e}" needs a shell`;if(e==="`")return`Command substitution needs a shell`;if(e===`$`&&t!==void 0&&uge.test(t))return`The expansion "$${t}" needs a shell`;if(`*?[`.includes(e))return`The glob character "${e}" needs a shell`;if(n){if(e===`#`)return`A comment needs a shell`;if(e===`~`)return`Tilde expansion needs a shell`;if(e===`=`&&t!==void 0&&!kb(t))return`A leading "=" is expanded by zsh`}},mge=(e,t)=>{let n=[],r=[],i=!0,a=0,o,s=0,c=0,l=(e,t,n=c)=>Br(new Db({reason:e,message:`${t} in template part ${n}`})),u=()=>{if(r.length===0)return;let e=r.map(Zhe).join(``);n.push(r.length===1&&ld(r[0])?r[0]:r.some(ld)?ud(e):e),r=[],i=!0,a=0},d=e=>{for(let t=0;t<e.length;t++){let d=e[t],f=e[t+1];if(o===`'`)d===`'`?o=void 0:r.push(d);else if(o===`"`){if(d===`"`)o=void 0;else if(d===`\\`&&f!==void 0&&`$\`"\\
241
+ `.includes(f))f!==`
242
+ `&&r.push(f),t++;else if(d==="`")return l(`UnsupportedSyntax`,`Command substitution needs a shell`);else if(d===`$`&&f!==void 0&&dge.test(f))return l(`UnsupportedSyntax`,`The expansion "$${f}" needs a shell`);else r.push(d)}else if(kb(d))u();else if(d===`\\`){if(f===void 0)return l(`InvalidEscape`,`A trailing backslash escapes nothing`);f!==`
243
+ `&&(r.push(f),i=!1),t++}else if(d===`'`||d===`"`)o=d,s=c,r.push(``),i=!1;else{let e=pge(d,f,r.length===0);if(e!==void 0)return l(`UnsupportedSyntax`,e);if(d===`{`)a++;else if(d===`}`)a>0&&a--;else if(a>0&&(d===`,`||d===`.`&&f===`.`))return l(`UnsupportedSyntax`,`Brace expansion needs a shell`);else if(d===`=`&&n.length===0&&i&&fge.test(r.join(``)))return l(`UnsupportedSyntax`,`A variable assignment needs a shell`);r.push(d)}}};for(;c<e.length;c++){let a=d(e[c]);if(a!==void 0)return a;if(c===t.length)break;let o=t[c];if(Array.isArray(o)){let i=e[c+1][0];if(r.length>0||(i===void 0?c+1<t.length:!kb(i)))return l(`UnsupportedSyntax`,`An interpolated array must be a separate argument`);for(let e of o)n.push(Ob(e))}else r.push(Ob(o)),i=!1}return o===void 0?(u(),zr(n)):l(`UnterminatedQuote`,`The quote is not closed`,s)},Ab=`~effect/process/ChildProcess`,hge={...Fn({label:`Command`,evaluate(e){return jr(e.context,Eb).spawn(this)}}),[Ab]:Ab},jb=(e,t,n)=>Object.assign(Object.create(hge),{_tag:`StandardCommand`,command:e,args:t,options:n}),Mb=function(...e){if(Nb(e[0])){let[t,...n]=e,[r,i]=Fb(t,n);return jb(r,i,{})}if(typeof e[0]==`object`&&!Array.isArray(e[0])&&!Nb(e[0])){let t=e[0];return function(e,...n){if(t.shell!==void 0&&t.shell!==!1)return jb(_ge(e,n),[],t);let[r,i]=Fb(e,n);return jb(r,i,t)}}if(typeof e[0]==`string`&&!Array.isArray(e[1])){let[t,n={}]=e;return jb(t,[],n)}let[t,n=[],r={}]=e;return jb(t,n,r)},Nb=e=>Array.isArray(e)&&`raw`in e&&Array.isArray(e.raw),Pb=e=>{let t=/^fd(\d+)$/.exec(e);if(t===null)return;let n=parseInt(t[1],10);return n>=3?n:void 0},gge=e=>`fd${e}`,Fb=(e,t)=>{let[n=``,...r]=Ite(Xhe(e,...t));if(typeof n!=`string`)throw new Db({reason:`InvalidArgument`,message:`The program name of a command cannot be Redacted`});return[n,r]},_ge=(e,t)=>{if(t.length>0)throw new Db({reason:`UnsupportedSyntax`,message:`A shell template cannot interpolate values; build the script with CommandLine.quote`});let n=e[0];if(n===void 0)throw new Db({reason:`InvalidEscape`,message:`Template part 0 contains an invalid escape sequence`});return n},vge=(e,t)=>{let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n},Ib=(e,t,n)=>e.pipe(j(e=>(t.steps+=1,Wc(e,n,{discard:!0}))),zl({disableYield:!0}),wc(()=>qc(()=>{t.closed=!0})),fl(()=>Jc)),yge=(e,t,n)=>{let r={steps:0,busy:!1,closed:!1},i=[],a=0,o=[],s=0,c=0,l=!1,u=e=>{let r=t.limitBytes-s;if(r>0){let t=e.byteLength>r?e.subarray(0,r):e;o.push(t),s+=t.byteLength}return e.byteLength<=r||l?Jc:(l=!0,n)},d=t.onExceed===`keep-ends`?Math.floor(t.limitBytes/2):0,f=t.limitBytes-d,p=t.onExceed===`terminate`?u:e=>qc(()=>{let t=e.subarray(0,d-a);t.byteLength>0&&(i.push(t),a+=t.byteLength);let n=e.subarray(t.byteLength);if(n.byteLength!==0)for(o.push(n),s+=n.byteLength;s>f;){let e=o[0];if(e===void 0)return;let t=s-f;e.byteLength<=t?(o.shift(),s-=e.byteLength):(o[0]=e.subarray(t),s-=t)}});return{progress:r,run:Ib(e,r,e=>(c+=e.byteLength,p(e))),record:()=>{let e=c-a-s;return{_tag:`Captured`,bytes:vge([...i,...o],a+s),totalBytes:c,truncated:e>0,...t.onExceed===`keep-ends`&&e>0?{omitted:{at:a,bytes:e}}:{},closed:r.closed}}}},bge=(e,t,n)=>{let r={steps:0,busy:!1,closed:!1},i=0,a=0,o=!1,s=t.limitBytes??1/0,c=e=>qc(()=>{o=!0,r.closed=e}),l=Kc(()=>(r.busy=!1,s<=0?xs():kc(e,{onSuccess:e=>{r.steps+=1;let t=[];for(let n of e){if(a+=n.byteLength,s<=0)continue;let e=n.byteLength>s?n.subarray(0,s):n;t.push(e),s-=e.byteLength,i+=e.byteLength}let[n,...o]=t;return n===void 0?xs():(r.busy=!0,k([n,...o]))},onFailure:()=>il(c(!1),xs()),onDone:()=>il(c(!0),xs())}))),u=Kc(()=>o?Jc:Ib(e,r,e=>qc(()=>{a+=e.byteLength})));return{progress:r,run:fg(ag(k(l)),t.sink).pipe(Pl(qc(()=>{r.busy=!1})),fl(n),il(u)),record:()=>({_tag:`Forwarded`,forwardedBytes:i,totalBytes:a,truncated:a>i,closed:r.closed})}},xge=(e,t,n)=>j(sc,r=>{let i=ji(n.ceiling),a=il(Xl(e),qc(()=>{t.closed=!1})),o=(s,c)=>j(Jl(e).pipe(cl(!0),Sl(cl(xl(n.tick),!1))),e=>e?Jc:j(sc,e=>{let l=t.steps!==s||t.busy?0:c+1;return l>=n.idleTicks||e-r>=i?a:o(t.steps,l)}));return o(t.steps,0)}),Sge={PATH:`/usr/bin:/bin:/usr/sbin:/sbin`},Cge=(e,t)=>Mb(`/bin/sh`,[`-c`,`group=-$1 polls=$2
244
+ gone() { ! kill -s 0 -- "$group" 2>/dev/null; }
245
+ settle() { n=0; while [ "$n" -lt "$polls" ]; do gone && return 0; sleep 0.1; n=$((n + 1)); done; gone; }
246
+ read -r line && exit 0
247
+ kill -s TERM -- "$group" 2>/dev/null
248
+ settle && exit 0
249
+ kill -s KILL -- "$group" 2>/dev/null
250
+ settle`,`owned-process-tether`,String(e),String(Math.max(1,Math.ceil(Ai(t)/100)))],{env:{...Sge},extendEnv:!1,stdin:`pipe`,stdout:`ignore`,stderr:`ignore`,detached:!0,killSignal:`SIGTERM`,forceKillAfter:t}),wge=new TextEncoder().encode(`disarm
251
+ `),Tge=(e,t)=>il(yl(fg(cg(wge),e.stdin)),yl(Mae(e.exitCode,t)));F({executable:P,args:I(P),env:Sle(P,P)});const Ege=F({code:P}),Dge=Ir(`@inkeep/impulse-owned-process/internal/NodeVersion`,{defaultValue:()=>process.versions.node}),Lb=(e,t)=>{let n=vi(t);if(rr(n)||!Si(n.value))throw RangeError(`owned-process: ${e} must be a finite duration`);return n.value},Rb=(e,t)=>{if(!Number.isSafeInteger(t)||t<=0)throw RangeError(`owned-process: ${e} must be a positive integer, got ${t}`)},zb=(e,t)=>{switch(t._tag){case`Capture`:Rb(`${e}.limitBytes`,t.limitBytes);return;case`Forward`:t.limitBytes!==void 0&&Rb(`${e}.limitBytes`,t.limitBytes);return;case`Ignore`:return}},Oge=e=>{if(e.executable.length===0)throw RangeError(`owned-process: executable must be non-empty`);if(e.cwd!==void 0&&!u(e.cwd))throw RangeError(`owned-process: cwd must be absolute, got ${e.cwd}`);for(let[t,n]of Object.entries(e.env))if(typeof n!=`string`)throw TypeError(`owned-process: env.${t} must be a string`);let t=Lb(`deadline`,e.deadline);if(Ai(t)<=0)throw RangeError(`owned-process: deadline must be greater than zero`);return zb(`stdout`,e.stdout),zb(`stderr`,e.stderr),{request:e,deadline:t,terminationGrace:Lb(`terminationGrace`,e.terminationGrace),inheritGroup:e.processGroup===`inherit`}},Bb={tick:Di(250),idleTicks:8,ceiling:Oi(30)},Vb=Ai(Oi(1)),Hb=1000000n,kge=BigInt(Vb)*Hb,Ub=(e,t)=>Number((e-t)/Hb),Wb=(e,t)=>{let n=Ai(t),r=n>Vb;return{forceKillAfterMillis:n-(r?Vb:0),settleByNanos:e+ji(t)+(r?0n:kge)}},Age={Deadline:`deadline`,Stop:`stop`,OutputLimit:`output-limit`,CallerFailed:null},Gb=e=>{let t=et(e.reason,`cause`)?e.reason.cause:void 0;return new Cb({reason:{_tag:`SpawnFailed`,code:et(t,`code`)&&Ke(t.code)?t.code:e.reason._tag}})},Kb=e=>e._tag===`Ignore`?`ignore`:`pipe`,jge=e=>e.exitCode.pipe(M(e=>({_tag:`Exited`,code:Number(e)})),dl(`PlatformError`,e=>{let t=et(e.reason,`cause`)?e.reason.cause:void 0,n=Lhe(t);return n===void 0?el(e):k({_tag:`Signaled`,signal:n})})),qb=M(id,od),Mge=(e,t,n)=>{let r=0,i=`stopped`,a=(rg(e)?e:cg(e)).pipe(gde(e=>qc(()=>{r+=e.byteLength})),bde(e=>lg(cl(gs(e)?Jc:n(e),mde))));return{run:fg(a,t).pipe(wl({onSuccess:()=>qc(()=>{i=`source-done`}),onFailure:e=>{let t=Nie(e);return Vr(t)?gs(t.failure)?Jc:n(t.failure):qc(()=>{i=`child-closed`})}})),record:()=>({_tag:`Fed`,bytesWritten:r,ended:i})}},Jb={_tag:`Ignored`},Nge=g(new URL(import.meta.url.endsWith(`.ts`)?`./internal/launch.ts`:`./internal/launch.js`,import.meta.url)),Pge=(e,t)=>Zc(function*(){let{request:n,inheritGroup:r}=e,i=e=>t.spawned===void 0?Jc:Ms(t.spawned,e);if(!r){let e=sle(yield*Dge);if(Vr(e)||ule(e.success,ale({major:26,minor:10,patch:0}))||process.execve===void 0){let e=new Cb({reason:{_tag:`SpawnFailed`,code:`ENOSYS`}});return yield*i(e),yield*e}}let a=yield*Eb,o=yield*wg({groupGone:`unknown`,confirmedAt:null,group:null}),s=yield*jl(Zc(function*(){let s=yield*wg({_tag:`Unspawned`}),c=yield*Hs(yield*Al);yield*Nl(()=>Zc(function*(){let t=yield*Tg(s);if(r||t._tag===`Unspawned`||t._tag===`Released`)return;let n=t._tag===`Exited`?t.settleByNanos:t.settleByNanos??Wb(yield*sc,e.terminationGrace).settleByNanos,{groupGone:i,evidence:a}=yield*Fhe(t.pid,n,zge(t.pid,n));yield*Eg(o,{groupGone:i,confirmedAt:i===`observed`?yield*qb:null,group:a})}));let l=yield*Hs(yield*Al),u=yield*a.spawn(Mb(r?n.executable:process.execPath,r?[...n.args]:[`--no-warnings`,Nge],{cwd:n.cwd,env:r?{...n.env}:{},extendEnv:!1,stdin:n.stdin===void 0?`ignore`:`pipe`,stdout:Kb(n.stdout),stderr:Kb(n.stderr),detached:!r,killSignal:`SIGTERM`,forceKillAfter:Di(Wb(0n,e.terminationGrace).forceKillAfterMillis),additionalFds:r?void 0:{fd3:{type:`input`},fd4:{type:`output`}}})).pipe(hl(Gb),_l(i)),d=yield*oc,f=yield*sc,p=f+ji(e.deadline),m=Number(u.pid);if(yield*Eg(s,{_tag:`Running`,pid:m,settleByNanos:Wb(f,e.terminationGrace).settleByNanos}),!r){let t=yield*a.spawn(Cge(m,e.terminationGrace)).pipe(zs(c),hl(Gb),_l(i));yield*Vs(c,Tge(t,e.terminationGrace));let r=fg(cg(new TextEncoder().encode(JSON.stringify({executable:n.executable,args:n.args,env:n.env}))),u.getInputFd(3)).pipe(il(mg(dg(u.getOutputFd(4))))),o=Ub(p,yield*sc),s=()=>A(new Cb({reason:{_tag:`SpawnFailed`,code:`ETIMEDOUT`}})),l=yield*(o<=0?s():r.pipe(hl(Gb),bl({duration:Di(o),orElse:s}))).pipe(_l(i));if(l!==``){let{code:e}=yield*vm(qm(Ege))(l).pipe(gl),t=new Cb({reason:{_tag:`SpawnFailed`,code:e}});return yield*i(t),yield*t}}let h=yield*ks(),g=yield*ks(),_=yield*ks();yield*Hl(Vie(jge(u),_)),t.spawned!==void 0&&(yield*Fs(t.spawned,{pid:m,spawnedAtMillis:d,exited:Ns(_)}));let v=e=>j(Fs(h,e),t=>t||e._tag!==`OutputLimit`&&e._tag!==`CallerFailed`?Jc:ll(Fs(g,e))),y=e=>j(Bie(e),ar({onNone:()=>k(void 0),onSome:e=>M(e,e=>e)})),b=e=>v({_tag:`CallerFailed`,cause:e}),ee=Ub(p,yield*sc),x=[yield*Hl(il(ee<=0?Jc:xl(Di(ee)),v({_tag:`Deadline`})))];t.stop!==void 0&&x.push(yield*Hl(wl(t.stop,{onSuccess:e=>v({_tag:`Stop`,reason:e}),onFailure:e=>gs(e)?Jc:b(e)}))),t.release!==void 0&&x.push(yield*Hl(il(t.release,v({_tag:`Release`}))));let te=(e,t,n)=>Zc(function*(){if(t._tag===`Ignore`)return;let r=yield*Tde(n);return t._tag===`Capture`?yge(r,t,v({_tag:`OutputLimit`,stream:e,limitBytes:t.limitBytes})):bge(r,t,b)}),ne=yield*te(`stdout`,n.stdout,u.stdout),re=yield*te(`stderr`,n.stderr,u.stderr),ie=[];for(let e of[ne,re].filter(Ze))ie.push({drain:e,fiber:yield*Hl(e.run)});let ae=n.stdin===void 0?void 0:Mge(n.stdin,u.stdin,b),S=ae===void 0?void 0:yield*Vl(ae.run,l),oe=Wb(yield*sc,e.terminationGrace);yield*Eg(s,{_tag:`Running`,pid:m,settleByNanos:oe.settleByNanos});let C=yield*Sl(cl(As(_),void 0),As(h));if(C?._tag===`Release`&&!(yield*Ns(_)))return yield*yl(u.unref),yield*Eg(s,{_tag:`Released`}),{_tag:`Released`};let se=C!==void 0&&C._tag!==`Release`?C:void 0,ce=se===void 0?null:yield*qb;se===void 0&&(yield*Wc(x,Xl,{discard:!0}));let le=Wb(yield*sc,e.terminationGrace);yield*Eg(s,{_tag:`Running`,pid:m,settleByNanos:le.settleByNanos});let ue=yield*sl(u.kill({killSignal:`SIGTERM`,forceKillAfter:Di(le.forceKillAfterMillis)}));if(Es(ue))yield*yl(u.unref);else{let e=yield*sl(u.isRunning);Es(e)&&!e.value&&(yield*yl(u.unref))}let w=yield*As(_);yield*Eg(s,{_tag:`Exited`,pid:m,settleByNanos:le.settleByNanos}),yield*Wc(ie,({drain:e,fiber:t})=>xge(t,e.progress,Bb),{concurrency:`unbounded`,discard:!0}),S!==void 0&&(yield*Sl(ll(Jl(S)),il(xl(ine(Bb.tick,Bb.idleTicks)),Xl(S))));let de=se===void 0?yield*y(h):void 0,fe=de?._tag===`OutputLimit`||de?._tag===`CallerFailed`?de:yield*y(g);return{_tag:`Exited`,pid:m,spawnedAtMillis:d,spawnedAtNanos:f,exited:w,stopping:se,late:se===void 0?fe:void 0,requestedAt:ce,stdin:ae===void 0?{_tag:`None`}:ae.record(),stdout:ne===void 0?Jb:ne.record(),stderr:re===void 0?Jb:re.record()}}));if(s._tag===`Released`)return s;let c=r?{groupGone:`not-applicable`,confirmedAt:null,group:null}:yield*Tg(o),l=yield*sc,{stopping:u}=s,d=s.late?._tag===`OutputLimit`||s.late?._tag===`CallerFailed`?s.late:void 0,f=xb.make({pid:s.pid,executable:n.executable,exit:s.exited,stdin:s.stdin,stdout:s.stdout,stderr:s.stderr,termination:{by:u===void 0?null:Age[u._tag],reason:u?._tag===`Stop`?u.reason:null,requestedAt:s.requestedAt,...c},durationMs:Math.max(0,Math.round(Number(l-s.spawnedAtNanos)/Number(Hb)))}),p=u??d;return p===void 0||p._tag===`Stop`?{_tag:`Completed`,record:f}:p._tag===`CallerFailed`?yield*Qc(p.cause):yield*new Cb({reason:p._tag===`Deadline`?{_tag:`DeadlineExceeded`,record:f}:{_tag:`OutputLimit`,stream:p.stream,limitBytes:p.limitBytes,record:f}})}),Fge=e=>qc(()=>Oge(e)),Ige=e=>e._tag===`Completed`?k(e.record):el(Error(`owned-process: a run cannot be released`)),Yb=(e,t)=>j(Fge(e),e=>j(Pge(e,{stop:t?.stop}),Ige)),Lge=(e,t)=>j(Yb(e,t),e=>e.exit._tag===`Exited`&&e.exit.code===0?k(e):A(new Cb({reason:{_tag:`ExitFailed`,record:e}}))),Rge={PATH:`/usr/bin:/bin:/usr/sbin:/sbin`,LC_ALL:`C`},zge=(e,t)=>Zc(function*(){let n=Ub(t,yield*sc);return n<=Vb?{_tag:`Unreadable`,why:`termination grace exhausted before group-member read`}:yield*Lge({executable:`/bin/ps`,args:[`-A`,`-o`,`pid=,pgid=,stat=`],env:Rge,deadline:Di(n-Vb),terminationGrace:`0 millis`,processGroup:`inherit`,stdout:vb(1<<20,`terminate`),stderr:Rhe}).pipe(M(t=>Nhe(t.stdout._tag===`Captured`?new TextDecoder().decode(t.stdout.bytes):``,e)),dl(`ProcessError`,e=>k({_tag:`Unreadable`,why:e.message})))});bm(Sb.fields.pid),bm(Sb),el(Error(`owned-process: the child was released, and the package no longer holds it`)),el(Error(`owned-process: release takes only an unpiped child: no stdin, and Ignore on both outputs`));const Xb=P.check(Rm(e=>fb(e)===e,{message:`An identity must not contain an account-shaped twelve-digit number.`})),Zb=I(F({id:L(Xb),state:L(P),zone:L(P),launch:L(P),rootDevice:L(P),token:L(Xb),volumes:L(I(F({device:L(P),id:L(Xb)}))),interfaces:L(I(L(Xb))),tags:L(I(F({Key:L(P),Value:L(P)})))})),Bge=I(F({id:L(Xb),state:L(P)})),Vge=I(F({id:Xb,tags:L(I(F({Key:P,Value:P})))})),Hge=I(F({id:L(Xb)}));I(F({id:L(Xb),previousState:L(P),currentState:L(P)}));const Uge=F({InstanceId:L(Xb),UserData:L(F({Value:Cm(L(P))}))});F({Owners:I(P),ImageIds:Cm(I(P)),Filters:Cm(I(F({Name:P,Values:I(P)})))});const Wge=F({Images:I(F({ImageId:P,Name:P,CreationDate:Ym}))}),Gge=F({SecurityGroups:I(F({GroupId:P,GroupName:P,IpPermissions:I(F({IpProtocol:P}))}))}),Qb=F({Code:P,Message:P}),$b=I(F({Key:P,Value:P})),Kge=I(F({id:Xb,state:P,tags:L($b)})),ex=F({id:P,state:P,reason:L(Qb),transition:L(P),tags:Cm(L($b))}),qge=I(F({...ex.fields,token:L(Xb)}));I(F({...ex.fields,token:Cm(L(Xb))}));const Jge=I(ex),Yge=I(F({id:P,status:P,version:P})),Xge=F({instanceId:L(Xb)}),Zge=F({Key:P,Value:P}),tx=F({ImageId:Xb,InstanceType:P,MinCount:Tm(1),MaxCount:Tm(1),ClientToken:Xb,InstanceInitiatedShutdownBehavior:Tm(`terminate`),IamInstanceProfile:F({Name:Tm(`openteammate-host-ssm`)}),SecurityGroupIds:I(Xb),MetadataOptions:F({HttpTokens:Tm(`required`),HttpPutResponseHopLimit:Tm(1),HttpEndpoint:Tm(`enabled`)}),BlockDeviceMappings:I(F({DeviceName:P,Ebs:F({VolumeSize:Hm,VolumeType:Tm(`gp3`),Encrypted:Tm(!0),DeleteOnTermination:Tm(!0)})})),TagSpecifications:I(F({ResourceType:jm([`instance`,`volume`,`network-interface`]),Tags:I(Zge)}))}),nx=F({Command:F({CommandId:Xb})}),Qge=F({status:L(P),code:L(Hm),out:L(P),err:L(P),start:L(P),end:L(P)}),rx=e=>({...Object.fromEntries([`PATH`,`HOME`,`AWS_CONFIG_FILE`,`AWS_SHARED_CREDENTIALS_FILE`,`HTTP_PROXY`,`HTTPS_PROXY`,`NO_PROXY`,`http_proxy`,`https_proxy`,`no_proxy`,`AWS_CA_BUNDLE`,`REQUESTS_CA_BUNDLE`].flatMap(t=>e[t]===void 0?[]:[[t,e[t]]])),AWS_PAGER:``,AWS_CLI_AUTO_PROMPT:`off`,AWS_RETRY_MODE:`standard`,AWS_MAX_ATTEMPTS:`1`,LC_ALL:`C`}),ix=Cm(L(F({Name:Cm(L(P))}))),ax=F({TerminatingInstances:Cm(L(I(F({InstanceId:Cm(L(Xb)),PreviousState:ix,CurrentState:ix}))))}),ox=e=>(e.TerminatingInstances??[]).map(e=>({id:e.InstanceId??null,previousState:e.PreviousState?.Name??null,currentState:e.CurrentState?.Name??null})),sx=(e,t)=>t.some(t=>t.id===e&&t.previousState!==null&&[`pending`,`running`,`stopping`,`stopped`].includes(t.previousState)&&(t.currentState===`shutting-down`||t.currentState===`terminated`)),cx=e=>sc.pipe(M(t=>t+ji(e))),lx=N(function*(e){let t=yield*ux(e);return{within:Di(Math.min(12e4,Ai(t)))}}),ux=N(function*(e){let t=e-(yield*sc);return t<=0n?yield*new db({operation:`Deadline`,exitCode:1,message:`The verb's deadline expired; no further work was started.`}):Ei(t)}),dx=fae([mae(`1 second`),zc(`10 seconds`)]),fx=e=>JSON.stringify(e,(e,t)=>typeof t==`number`&&fb(String(t))!==String(t)?JSON.rawJSON(t.toExponential()):t),$ge=()=>{let e=``,t=!1;return(n,r=!1)=>{let i=e+n,a=/\d+$/.exec(i),o=!r&&a!==null&&a[0].length<=12&&!(a.index===0?t:/[a-zA-Z0-9]/.test(i.charAt(a.index-1))),s=o?i.slice(0,a.index):i;e=o?a[0]:``;let c=t?`a`:``,l=fb(c+s).slice(c.length);return s.length!==0&&(t=/[a-zA-Z0-9]/.test(s.charAt(s.length-1))),l}},e_e=e=>{let t=e.write.bind(e),n=$ge();return e.write=(e,r,i)=>{let a=typeof e==`string`?Buffer.from(e,typeof r==`string`?r:`utf8`):Buffer.from(e),o=Buffer.from(n(a.toString(`latin1`)),`latin1`);if(o.length===0){let e=typeof r==`function`?r:i;return e!==void 0&&queueMicrotask(e),!0}return typeof r==`function`?t(o,r):t(o,i)},()=>{let e=n(``,!0);e.length!==0&&t(e)}};let t_e=!1;const n_e=()=>{if(t_e)return;t_e=!0;let e=e_e(process.stdout),t=e_e(process.stderr),n=()=>{e(),t()};process.once(`beforeExit`,n),process.once(`exit`,n)},px=N(function*(e,t,n){yield*(yield*gg).writeFileString(e,fb(t),n)}),r_e=N(function*(e,t,n){let r=yield*gg,i=d(e,`steps`);yield*r.makeDirectory(i,{recursive:!0,mode:448});let a=yield*r.makeTempDirectoryScoped({directory:i,prefix:`.pending-${t}-`}),o=d(a,`result.json`);yield*px(o,fx(n)+`
252
+ `,{mode:384}),yield*(yield*r.open(o,{flag:`r`})).sync;let c=d(i,s(a).slice(9));return yield*r.rename(a,c),yield*(yield*r.open(i,{flag:`r`})).sync,d(c,`result.json`)},jl),i_e=F({name:P,writeId:Cm(Xb),startedAt:P,endedAt:P,exit:L(Hm),stdout:P,stderr:P,nativeExit:Cm(L(bb)),failure:Cm(L(P)),service:Cm(P),operation:Cm(P),query:Cm(L(P)),request:Cm(P),userData:Cm(P),awsCliVersion:Cm(P)}),a_e=ym(qm(F({InstanceIds:I(Xb)}))),o_e=ym(qm(ax)),s_e=ym(qm(nx)),c_e=ym(qm(F({Resources:I(Xb),Tags:I(F({Key:P,Value:P}))}))),mx=N(function*(e,t){let n=yield*gg,r=yield*n.readDirectory(d(e,`steps`)).pipe(dl(`PlatformError`,e=>e.reason._tag===`NotFound`?k([]):A(e))),i=new Map,a=new Map,o=new Set,s=new Set,c=new Map(t.map(e=>[e.file,e]));for(let t of r.filter(e=>e.startsWith(`aws-`)||e.startsWith(`local-`))){let r=d(`steps`,t,`result.json`),l=yield*vm(qm(i_e),{onExcessProperty:`error`})(yield*n.readFileString(d(e,r)));if(l.name===`TerminateInstances`&&l.service===`ec2`&&l.operation===`terminate-instances`){let e=a_e(l.request);if(ir(e)){let t=l.exit===0&&(l.failure??null)===null?o_e(l.stdout):O();for(let n of e.value.InstanceIds)o.add(n),ir(t)&&sx(n,ox(t.value))&&s.add(n)}}if(l.writeId!==void 0&&l.exit===0&&(l.failure??null)===null){if(l.service===`ssm`&&l.operation===`send-command`){let e=s_e(l.stdout),t=a_e(l.request);ir(e)&&ir(t)&&t.value.InstanceIds.length===1&&t.value.InstanceIds[0]!==void 0&&i.set(l.writeId,{instance:t.value.InstanceIds[0],commandId:e.value.Command.CommandId})}if(l.service===`ec2`&&l.operation===`create-tags`&&l.stdout===``){let e=c_e(l.request);ir(e)&&e.value.Tags.length===1&&e.value.Tags[0]?.Key===`ot-retire-at`&&a.set(l.writeId,{ids:e.value.Resources,to:e.value.Tags[0].Value})}}l.exit!==null&&c.set(r,{name:l.name,startedAt:l.startedAt,endedAt:l.endedAt,exit:l.exit,file:r})}return{steps:Array.from(c.values()).toSorted((e,t)=>e.startedAt.localeCompare(t.startedAt)||e.file.localeCompare(t.file)),attempted:o,acknowledged:s,commands:i,tagWrites:a}}),l_e=F({Instances:Cm(L(I(F({InstanceId:Cm(Xge.fields.instanceId)}))))}),hx=12e4,gx=3e3,u_e=(e,t=3)=>{let n=Math.min(hx,Ai(e));for(let e=t;e>=1;e--){let t=Array.from({length:e-1},(e,t)=>(Math.min(2**t,20)+5)*1e3).reduce((e,t)=>e+t,0),r=Math.floor((n-gx-t-1)/(2*e*1e3));if(r>=1)return{deadlineMs:n,attempts:e,socketSeconds:r}}},_x=e=>rc(Zc(function*(){let t=yield*gg,n=yield*Eb,r={...rx(e.environment),AWS_PROFILE:e.profile,AWS_REGION:e.region},i=N(function*(e,t,i=hx,a=1){yield*Wc(e,(e,n)=>pb(`${t} argument ${n+1}`,e));let o=yield*Yb({executable:`aws`,args:e,env:{...r,AWS_MAX_ATTEMPTS:String(a)},deadline:Di(i-gx),terminationGrace:Di(gx),processGroup:`new`,stdout:vb(8388608,`terminate`),stderr:vb(65536,`terminate`)}).pipe(kl(Eb,n),ol),s=Hr(o)?o.success:`record`in o.failure.reason?o.failure.reason.record:null;return{stdout:s?.stdout._tag===`Captured`?new TextDecoder().decode(s.stdout.bytes):``,stderr:s?.stderr._tag===`Captured`?new TextDecoder().decode(s.stderr.bytes):``,exitCode:s?.exit._tag===`Exited`?s.exit.code:null,nativeExit:s?.exit??null,failure:Vr(o)?o.failure.reason._tag:null}}),a=u_e(e.within??Di(hx),1);if(a===void 0)return yield*new rb({operation:`ClientVersion`,reason:`budget`,message:`No budget remains to read the AWS CLI version.`});let o=yield*i([`--version`],`ClientVersion`,a.deadlineMs),s=/^aws-cli\/(\S+)/.exec(o.stdout)?.[1];if(o.exitCode!==0||s===void 0)return yield*new rb({operation:`ClientVersion`,reason:`client`,message:`Cannot read the AWS client's version.`});let c={name:`aws-cli`,version:s},l=(n,r,a,o,l,u)=>{let[f,p,m]=n,h=u_e(l?.within??Di(hx),m===`SendCommand`||m===`CreateTags`?1:3);return h===void 0?A(new rb({operation:m,reason:`budget`,message:`Read budget cannot fit one bounded attempt and its stop grace; no request started.`})):jl(Zc(function*(){let n=typeof r==`string`?r:JSON.stringify(r);yield*pb(`${m} parameters`,n),u!==void 0&&(yield*pb(`${m} user data`,u));let g=yield*t.makeTempDirectoryScoped({directory:e.temporaryDirectory,prefix:`ec2-request-`}),_=d(g,`parameters.json`);yield*mb(`${m} parameters`,_,n).pipe(kl(gg,t));let v=d(g,`userdata.ps1`);u!==void 0&&(yield*mb(`${m} user data`,v,u).pipe(kl(gg,t)));let y=od(yield*id),b=yield*i([f,p,`--profile`,e.profile,`--region`,e.region,`--output`,`json`,`--no-cli-pager`,`--cli-input-json`,`file://${_}`,...o===null?[]:[`--query`,o],...u===void 0?[]:[`--user-data`,`file://${v}`],`--cli-connect-timeout`,String(h.socketSeconds),`--cli-read-timeout`,String(h.socketSeconds)],m,h.deadlineMs,h.attempts),ee={client:c,service:f,operation:m,projection:o},x=od(yield*id);if(e.evidenceDirectory!==void 0&&(yield*r_e(e.evidenceDirectory,`aws`,{name:m,...l?.writeId===void 0?{}:{writeId:l.writeId},startedAt:y,endedAt:x,exit:b.exitCode,nativeExit:b.nativeExit,failure:b.failure,service:f,operation:p,query:o,request:n,...u===void 0?{}:{userData:u},awsCliVersion:`aws-cli/${s}`,stdout:b.stdout,stderr:b.stderr}).pipe(kl(gg,t))),b.failure!==null||b.exitCode===null)return yield*new rb({operation:m,reason:`process`,retryable:b.failure===`DeadlineExceeded`,message:`AWS ${m} did not complete: ${b.failure??(b.nativeExit?._tag===`Signaled`?b.nativeExit.signal:`no native exit`)}. Captured evidence was retained when a run directory was supplied.`});if(b.exitCode!==0){let e=/^(?:aws: \[ERROR\]: )?An error occurred \(([A-Za-z0-9._-]+)\) when calling the ([A-Za-z0-9]+) operation(?: \(reached max retries: \d+\))?: ([\s\S]*)/m.exec(b.stderr),t=e?.[1]??`UnknownCliError`;if(t===`UnknownCliError`)return yield*new rb({operation:m,reason:`client`,retryable:/Could not connect to the endpoint URL|Connection was closed before we received a valid response|(?:Connect|Read) timeout on endpoint URL|Failed to connect to proxy URL/i.test(b.stderr),message:b.stderr.trim()});let n={...ee,answer:{kind:`refused`,code:t,message:e?.[3]?.trim()??b.stderr.trim()}};return t===`InvalidGroup.NotFound`?yield*new Che({reply:n,readAt:x}):t===`InvalidInstanceID.NotFound`?yield*new whe({reply:n,readAt:x}):t===`InvalidVolume.NotFound`?yield*new The({reply:n,readAt:x}):t===`InvalidNetworkInterfaceID.NotFound`?yield*new Ehe({reply:n,readAt:x}):yield*new Dhe({code:t,reply:n,readAt:x})}let te={...ee,answer:{kind:`answered`,body:b.stdout}};return{value:yield*vm(m===`CreateTags`?a:qm(a),{onExcessProperty:m===`RunInstances`||m===`SendCommand`||m===`TerminateInstances`?`ignore`:`error`})(te.answer.body).pipe(hl(e=>new rb({operation:m,reason:`decode`,observation:{reply:te,readAt:x},message:m===`RunInstances`?`RunInstances was sent; an instance may exist. Run create again with the same directory to recover it. ${e.message}`:m===`SendCommand`?`SendCommand was sent; the command may have run. Inspect the retained step evidence before retrying. ${e.message}`:m===`TerminateInstances`?`TerminateInstances was sent; the instance may already be terminating. Run retire again to verify its state. ${e.message}`:e.message}))),reply:te,readAt:x}})).pipe(dl(`PlatformError`,e=>A(new rb({operation:m,reason:`filesystem`,message:e.message}))))},u=(t,n,r,i,a)=>e.readRetryOwner===`verb`?l(t,n,r,i,a):Zc(function*(){let o=a?.within??Di(hx),s=e.retryDeadline??(yield*cx(o)),c,u=()=>new rb({operation:t[2],reason:`budget`,message:c===void 0?`The AWS read deadline expired.`:sb(c)}),d=yield*ux(s).pipe(hl(u));return yield*ux(s).pipe(hl(u),j(e=>l(t,n,r,i,{within:Pi(e,o)})),hl(e=>e._tag===`AwsReadError`&&e.reason===`budget`&&c!==void 0?u():(ib(e)&&(c=e),e)),vl({schedule:dx,while:ib}),bl({duration:d,orElse:()=>A(u())}))});return Dr(cb,{terminateInstance:(e,t)=>l([`ec2`,`terminate-instances`,`TerminateInstances`],{InstanceIds:[e]},ax,null,t).pipe(M(e=>({value:ox(e.value),reply:e.reply,readAt:e.readAt}))),setEndTags:(e,t)=>l([`ec2`,`create-tags`,`CreateTags`],{Resources:e.ids,Tags:[{Key:`ot-retire-at`,Value:e.to}]},Tm(``),null,t).pipe(M(e=>({...e,value:null}))),describeVolumeEnds:(e,t)=>u([`ec2`,`describe-volumes`,`DescribeVolumes`],{VolumeIds:e},Vge,`Volumes[].{id:VolumeId,tags:Tags}`,t),describeVolume:(e,t)=>u([`ec2`,`describe-volumes`,`DescribeVolumes`],typeof e==`string`?{VolumeIds:[e]}:{Filters:[{Name:`tag:ot-run`,Values:[e.run]}]},Bge,`Volumes[].{id:VolumeId,state:State}`,t),describeNetworkInterface:(e,t)=>u([`ec2`,`describe-network-interfaces`,`DescribeNetworkInterfaces`],typeof e==`string`?{NetworkInterfaceIds:[e]}:{Filters:[{Name:`tag:ot-run`,Values:[e.run]}]},Hge,`NetworkInterfaces[].{id:NetworkInterfaceId}`,t),describeInstanceLifetime:(e,t)=>u([`ec2`,`describe-instances`,`DescribeInstances`],{InstanceIds:[e]},Kge,`Reservations[].Instances[].{id:InstanceId,state:State.Name,tags:Tags}`,t),describeUserData:(e,t)=>u([`ec2`,`describe-instance-attribute`,`DescribeInstanceAttribute`],{InstanceId:e,Attribute:`userData`},Uge,null,t),describeInstanceResources:(e,t)=>u([`ec2`,`describe-instances`,`DescribeInstances`],e.by===`id`?{InstanceIds:[e.id]}:e.by===`client-token`?{Filters:[{Name:`client-token`,Values:[e.token]}]}:{Filters:[{Name:`tag:ot-run`,Values:[e.run]}]},Zb,`Reservations[].Instances[].{id:InstanceId,state:State.Name,zone:Placement.AvailabilityZone,launch:LaunchTime,rootDevice:RootDeviceName,volumes:BlockDeviceMappings[].{device:DeviceName,id:Ebs.VolumeId},interfaces:NetworkInterfaces[].NetworkInterfaceId,tags:Tags,token:ClientToken}`,t),describeInstanceResourcesByTokens:(e,t)=>u([`ec2`,`describe-instances`,`DescribeInstances`],{Filters:[{Name:`client-token`,Values:e}]},Zb,`Reservations[].Instances[].{id:InstanceId,state:State.Name,zone:Placement.AvailabilityZone,launch:LaunchTime,rootDevice:RootDeviceName,volumes:BlockDeviceMappings[].{device:DeviceName,id:Ebs.VolumeId},interfaces:NetworkInterfaces[].NetworkInterfaceId,tags:Tags,token:ClientToken}`,t),runInstances:(e,t)=>vm(qm(tx),{onExcessProperty:`error`})(e.parameters).pipe(hl(()=>new ub({message:`RunInstances parameters do not match the launch contract; nothing was sent.`})),j(()=>l([`ec2`,`run-instances`,`RunInstances`],e.parameters,l_e,null,t,e.userData).pipe(M(e=>({value:{instanceId:e.value.Instances?.[0]?.InstanceId??null},reply:e.reply,readAt:e.readAt}))))),describeSecurityGroups:(e,t)=>u([`ec2`,`describe-security-groups`,`DescribeSecurityGroups`],typeof e==`string`?{GroupIds:[e]}:{Filters:[{Name:`group-name`,Values:[e.name]}]},Gge,`{SecurityGroups:SecurityGroups[].{GroupId:GroupId,GroupName:GroupName,IpPermissions:IpPermissions[].{IpProtocol:IpProtocol}}}`,t),describeInstances:(e,t)=>u([`ec2`,`describe-instances`,`DescribeInstances`],e.by===`id`?{InstanceIds:[e.id]}:e.by===`client-token`?{Filters:[{Name:`client-token`,Values:[e.token]}]}:{Filters:[{Name:`tag:ot-run`,Values:[e.run]}]},e.by===`id`?Jge:qge,e.by===`id`?`Reservations[].Instances[].{id:InstanceId,state:State.Name,reason:StateReason,transition:StateTransitionReason,tags:Tags}`:`Reservations[].Instances[].{id:InstanceId,state:State.Name,reason:StateReason,transition:StateTransitionReason,tags:Tags,token:ClientToken}`,t),describeImages:(e,t)=>u([`ec2`,`describe-images`,`DescribeImages`],e,Wge,`{Images:Images[].{ImageId:ImageId,Name:Name,CreationDate:CreationDate}}`,t)}).pipe(Or(lb,{sendCommand:(e,t)=>l([`ssm`,`send-command`,`SendCommand`],{InstanceIds:[e.instanceId],DocumentName:`AWS-RunPowerShellScript`,TimeoutSeconds:e.deliverySeconds,Parameters:{commands:e.commands,executionTimeout:[String(e.executionSeconds)]}},nx,null,t),getCommandInvocation:(e,t)=>u([`ssm`,`get-command-invocation`,`GetCommandInvocation`],{InstanceId:e.instanceId,CommandId:e.commandId},Qge,`{status:Status,code:ResponseCode,out:StandardOutputContent,err:StandardErrorContent,start:ExecutionStartDateTime,end:ExecutionEndDateTime}`,t),describeInstanceInformation:(e,t)=>u([`ssm`,`describe-instance-information`,`DescribeInstanceInformation`],{Filters:[{Key:`InstanceIds`,Values:[e]}]},Yge,`InstanceInformationList[].{id:InstanceId,status:PingStatus,version:AgentVersion}`,t)}))})),vx=Xb.check(zm(/^[a-z0-9][a-z0-9-]{0,47}$/)),yx=P.check(zm(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/),Rm(e=>{let t=rd(e);return ir(t)&&od(t.value)===e.replace(/Z$/,`.000Z`)},{message:`Expected a real UTC calendar instant with whole seconds.`})),d_e=jm([`windows`,`linux`]),f_e=jm([`intended`,`requested`,`refused`,`created`,`armed`,`reachable`,`retiring`,`retired`]),bx=F({ok:Dm.annotate({description:`Whether the recorded check succeeded.`}),at:P.annotate({description:`UTC time of the check.`}),detail:P.annotate({description:`The observation supporting the check.`})}),p_e=F({value:yx.annotate({description:`End time requested by this move.`}),at:P.annotate({description:`UTC time the move was recorded.`}),by:jm([`create`,`extend`]).annotate({description:`Operation responsible for the move.`})}),m_e=F({id:Xb.annotate({description:`Identity of this extension and its tag write.`}),mode:jm([`extend`,`restore`]).annotate({description:`A requested extension or restoration to the existing EC2 tag.`}),from:yx.annotate({description:`Expected guest trigger before the move.`}),to:yx.annotate({description:`Intended trigger and EC2 tag.`}),task:Am([F({state:Tm(`planned`)}),F({state:Tm(`unknown`),writeId:Xb}),F({state:Tm(`accepted`),writeId:Xb,commandId:Xb}),F({state:Tm(`completed`)})]).annotate({description:`Guest move intent, dispatch outcome or verified task read-back.`}),tags:jm([`planned`,`unknown`,`acknowledged`]).annotate({description:`Outcome of sending the tag write. Exact read-back completes the move.`})}),xx=F({schema:Tm(`openteammate.ec2-instance/record@1`).annotate({description:`Version of the persisted EC2 custody record.`}),run:vx.annotate({description:`Run name used in resource tags and the client token.`}),owner:Xb.annotate({description:`Owner responsible for the run.`}),os:d_e.annotate({description:`Guest operating system; Linux behavior is not implemented.`}),region:P.annotate({description:`AWS region holding the recorded resources.`}),profile:Xb.annotate({description:`AWS profile name, never a credential.`}),helper:F({version:P.annotate({description:`Helper version that created the record.`}),commit:P.annotate({description:`Helper source revision.`}),awsCliVersion:P.annotate({description:`AWS CLI version used by the helper.`})}).annotate({description:`Tool provenance.`}),phase:f_e.annotate({description:`Last durably recorded lifecycle phase.`}),intent:F({attempt:Hm.check(Vm({minimum:1,maximum:9})).annotate({description:`Current create attempt, from one through nine.`}),image:F({id:Xb.annotate({description:`Selected AMI ID.`}),name:P.annotate({description:`Selected AMI name.`}),released:P.annotate({description:`AMI creation time reported by AWS.`})}).annotate({description:`Image selected before the create request.`}),instanceType:P.annotate({description:`Requested EC2 instance type.`}),rootGiB:Hm.annotate({description:`Requested root volume size in GiB.`}),retireAt:yx.annotate({description:`Intended end in the pool sweep's UTC form.`}),clientToken:Xb.annotate({description:`EC2 regional idempotency token.`}),securityGroupId:Xb.annotate({description:`Exact ot-no-ingress group ID used as the account positive control.`}),instanceProfile:Tm(`openteammate-host-ssm`).annotate({description:`Instance profile for Session Manager access.`}),userData:F({file:P.annotate({description:`Path to the exact user data sent.`}),sha256:P.annotate({description:`SHA-256 digest of those user data bytes.`}),bytes:Hm.annotate({description:`Length of the user data in bytes.`})}).annotate({description:`User data provenance, without its contents.`}),requestFile:P.annotate({description:`Path to the stored create request.`})}).annotate({description:`Create intent persisted before a request reaches AWS.`}),refusals:I(F({code:P.annotate({description:`AWS code that explicitly refused creation.`}),at:P.annotate({description:`UTC time of that refusal.`}),clientToken:Xb.annotate({description:`Token of the explicitly refused attempt.`})})).annotate({description:`Every observed create refusal, retained in order.`}),instance:Cm(F({id:Xb.annotate({description:`Observed EC2 instance ID.`}),zone:P.annotate({description:`Availability zone reported by AWS.`}),launchedAt:P.annotate({description:`Launch time reported by AWS.`}),rootVolumeId:Xb.annotate({description:`Observed root EBS volume ID.`}),volumeIds:I(Xb).annotate({description:`All observed EBS IDs.`}),networkInterfaceIds:I(Xb).annotate({description:`All observed network interface IDs.`})}).annotate({description:`Resource identities observed after creation.`})),logon:Cm(jm([`none`,`administrator`,`standard-user`]).annotate({description:`Automatic logon mode recorded by the guest preparation step.`})),checks:F({userDataDecodedOnce:Cm(bx),endOfLifeTask:Cm(bx),ssmOnline:Cm(bx),sshdValid:Cm(bx),sshReached:Cm(bx)}).annotate({description:`Observed guest and access checks, when performed.`}),pendingEnd:Cm(m_e).annotate({description:`Unfinished end move to reconcile before accepting another one.`}),ends:I(p_e).annotate({description:`Recorded end moves in order.`}),steps:I(F({name:P.annotate({description:`Operation step name.`}),startedAt:P.annotate({description:`UTC start of the step.`}),endedAt:P.annotate({description:`UTC end of the step.`}),exit:Hm.annotate({description:`Native command exit code.`}),file:P.annotate({description:`Path to the masked command evidence.`})})).annotate({description:`Completed command observations.`})});vm(xx,{onExcessProperty:`error`});const Sx=xm(xx,{onExcessProperty:`error`});var Cx=class extends nh()(`AccountCheckFailed`,{securityGroupId:P,operation:P,kind:ab,code:Cm(P),budget:Cm(Dm),retryable:Cm(Dm),message:P}){};const wx=N(function*(e,t){let n=yield*(yield*cb).describeSecurityGroups(e,t).pipe(hl(t=>t._tag===`UsageError`?t:new Cx({securityGroupId:e,operation:ob(t).operation,kind:ob(t).kind,retryable:ib(t),code:ob(t).code,budget:t._tag===`AwsReadError`&&t.reason===`budget`,message:`The recorded security group is not readable (${ob(t).code}): ${ob(t).message}`}))),r=n.value.SecurityGroups.find(t=>t.GroupId===e);return r?.GroupName===`ot-no-ingress`?r.IpPermissions.length===0?{...n,value:r}:yield*new Cx({securityGroupId:e,operation:`DescribeSecurityGroups`,kind:`account`,message:`The recorded ot-no-ingress group has inbound rules; refusing to continue.`}):yield*new Cx({securityGroupId:e,operation:`DescribeSecurityGroups`,kind:`account`,message:`The exact recorded ot-no-ingress group was not returned; account and region are unproven.`})}),Tx=e=>[...Array.from(new Set([e.intent.clientToken,...e.refusals.map(e=>e.clientToken)]),e=>({by:`client-token`,token:e})),{by:`run`,run:e.run}],Ex=(e,t)=>t.id!==e.instance?.id&&t.state===`terminated`&&t.token!==null&&![e.intent.clientToken,...e.refusals.map(e=>e.clientToken)].includes(t.token),Dx=N(function*(e,t){let n=yield*cb,r=yield*Wc(Tx(e),e=>lx(t).pipe(j(t=>n.describeInstanceResources(e,t)))),i=new Map;for(let t of r)for(let n of t.value){if(n.id===null||n.tags?.find(e=>e.Key===`ot-run`)?.Value!==e.run)return yield*new db({operation:`DescribeInstances`,exitCode:1,message:`A recovery read did not prove the instance's identity and run tag.`});Ex(e,n)||i.set(n.id,n)}if(e.instance!==void 0){let t=i.get(e.instance.id);if(t!==void 0)return t;if(i.size!==0)return yield*new db({operation:`DescribeInstances`,exitCode:1,message:`Only other instances were listed: ${Array.from(i.keys()).join(`, `)}; the recorded target remains unproven.`})}return i.size>1?yield*new db({operation:`DescribeInstances`,exitCode:1,message:`More than one instance belongs to the recorded attempts; refusing another launch.`}):Array.from(i.values())[0]}),Ox=e=>{let t=e.volumes?.find(t=>t.device===e.rootDevice)?.id;if(e.id===null||e.zone===null||e.launch===null||t==null||e.volumes===null||e.interfaces===null)return;let n=e.volumes.flatMap(e=>e.id===null?[]:[e.id]),r=e.interfaces.filter(e=>e!==null);if(n.length===e.volumes.length&&r.length===e.interfaces.length&&r.length!==0)return{id:e.id,zone:e.zone,launchedAt:e.launch,rootVolumeId:t,volumeIds:n,networkInterfaceIds:r}},kx=(e,t)=>Dx(e,t).pipe(j(e=>{let n=e?.id;return n==null?k(O()):Zc(function*(){let e=(yield*(yield*cb).describeInstanceResources({by:`id`,id:n},yield*lx(t))).value.find(e=>e.id===n);return e===void 0?O():cr(Ox(e))})}),dl(`InvalidInstanceID.NotFound`,()=>k(O())),Bl({until:ir,schedule:dx}),M(Ste)),Ax=ki(2),jx=e=>lx(e).pipe(hl(e=>new Px({operation:`Deadline`,message:e.message}))),Mx=F({reply:tb,readAt:P}),h_e=jm([`retire-at-missing`,`retire-at-invalid`,`run-tag-mismatch`,`not-found-too-soon`,`not-found-unobserved`,`listed-only-by-lookup`,`other-instance-listed`]),g_e=F({outcome:Tm(`observed`),at:P,instanceId:L(P),state:P,runTag:L(P),presence:jm([`present`,`absent`,`unknown`]),absenceProof:L(jm([`terminated`,`not-listed-after-earlier-read`,`not-found-after-earlier-read`])),problems:I(h_e),otherInstanceIds:I(P),retireAt:L(yx),secondsLeft:L(Hm),ssmPing:L(P),stateReason:L(Qb),stateTransitionReason:L(P),lastEndMove:L(p_e),accountCheck:F({securityGroupId:P,readAt:P}),reads:F({account:Mx,instance:Mx,lookups:I(Mx).annotate({description:`Filtered replies in lookup order, including tokens for history classification.`}),ssm:L(Mx)})}),Nx=xm(F({...xx.fields,now:Am([g_e,F({outcome:Tm(`failed`),at:P,operation:P,kind:ab,code:P,message:P})])}),{onExcessProperty:`error`});var Px=class extends nh()(`StatusReadFailed`,{operation:P,message:P}){};const Fx=N(function*(e,t,n){return yield*(yield*cb).describeInstances(e,yield*jx(n)).pipe(M(n=>({...n,value:e.by===`id`?n.value:n.value.filter(e=>!Ex(t,{...e,token:e.token??null})),notFound:!1})),dl(`InvalidInstanceID.NotFound`,e=>k({value:[],reply:e.reply,readAt:e.readAt,notFound:!0})))}),__e=N(function*(e,t){let n=t??(yield*cx(Ax)),r=e.instance?.id,i=yield*wx(e.intent.securityGroupId,yield*jx(n)),a=yield*lb,o=yield*Fx(r===void 0?{by:`client-token`,token:e.intent.clientToken}:{by:`id`,id:r},e,n),s=Tx(e).filter(t=>r!==void 0||t.by!==`client-token`||t.token!==e.intent.clientToken),c=yield*Wc(s,t=>Fx(t,e,n)),l=new Set([o,...c].flatMap(e=>e.value.map(e=>e.id)));if(r===void 0&&l.size>1)return yield*new Px({operation:`DescribeInstances`,message:`The attempt lookups returned unrelated or ambiguous instances.`});let u=Array.from(new Set(c.flatMap(e=>e.value.filter(e=>r!==void 0&&e.id!==r&&e.state!==`terminated`).map(e=>e.id))));if(r!==void 0){for(let e of c.flatMap(e=>e.value))if(e.id!==r&&e.state===`terminated`)return yield*new Px({operation:`DescribeInstances`,message:`The additional ended instance ${e.id} was not proved to be unrelated history.`})}let d=r===void 0?c.find(e=>e.value.length!==0)??o:o,f=r!==void 0&&!o.value.some(e=>e.id===r)?c.find(e=>e.value.some(e=>e.id===r&&e.state!==`terminated`)):void 0,p=f??d,m=r===void 0?p.value.length===1?p.value[0]:void 0:p.value.find(e=>e.id===r&&(f===void 0||e.state!==`terminated`));if(r===void 0&&o.value.length===0&&m?.state===`terminated`)return yield*new Px({operation:`DescribeInstances`,message:`An ended older attempt does not prove the unobserved current attempt absent.`});if(m===void 0&&d.value.length!==0)return yield*new Px({operation:`DescribeInstances`,message:`The provider returned unrelated or ambiguous instances.`});let h=m?.id??r;if(h===void 0&&!d.notFound)return yield*new Px({operation:`DescribeInstances`,message:`No instance ID was recorded or found; creation remains unproven.`});let g=e.instance===void 0?O():rd(e.instance.launchedAt),_=rd(d.readAt),v=d.notFound&&(rr(g)||rr(_)||ad(_.value)-ad(g.value)<3e5),y=!v&&(m===void 0||m.state===`terminated`),b=v?[e.instance===void 0?`not-found-unobserved`:`not-found-too-soon`]:[];f!==void 0&&b.push(`listed-only-by-lookup`),u.length!==0&&b.push(`other-instance-listed`);let ee=m?.tags?.find(e=>e.Key===`ot-run`)?.Value??null;m!==void 0&&(!y||ee!==null)&&ee!==e.run&&b.push(`run-tag-mismatch`);let x=m?.tags?.find(e=>e.Key===`ot-retire-at`)?.Value,te=ym(yx)(x),ne=xte(te);m!==void 0&&!y&&(x===void 0?b.push(`retire-at-missing`):rr(te)&&b.push(`retire-at-invalid`));let re=y||m===void 0?null:yield*a.describeInstanceInformation(m.id,yield*jx(n)),ie=yield*id,ae={outcome:`observed`,at:od(ie),instanceId:h??null,runTag:ee,state:m?.state??(d.notFound?`not-found`:`not-listed`),presence:f===void 0?v?`unknown`:y?`absent`:`present`:`present`,problems:b,otherInstanceIds:u,absenceProof:v?null:m===void 0?d.notFound?`not-found-after-earlier-read`:`not-listed-after-earlier-read`:m.state===`terminated`?`terminated`:null,retireAt:ne,secondsLeft:y||ne===null?null:Math.floor((ad(nd(ne))-ad(ie))/1e3),ssmPing:re===null?null:re.value.find(e=>e.id===h)?.status??`not-listed`,stateReason:m?.reason??null,stateTransitionReason:m?.transition??null,lastEndMove:e.ends.at(-1)??null,accountCheck:{securityGroupId:e.intent.securityGroupId,readAt:i.readAt},reads:{account:{reply:i.reply,readAt:i.readAt},instance:{reply:d.reply,readAt:d.readAt},lookups:c.map(e=>({reply:e.reply,readAt:e.readAt})),ssm:re===null?null:{reply:re.reply,readAt:re.readAt}}};return{...e,now:ae}}),v_e=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/,Ix=[26,10,0],y_e=(e,t)=>{let n=v_e.exec(e);if(n===null||!t)return!1;let[,r,i,a,o]=n,s=Number(r)-Ix[0]||Number(i)-Ix[1]||Number(a)-Ix[2];return s>0||s===0&&o===void 0},Lx=e=>{let t=process.versions.node,n=process.execve!==void 0;if(!y_e(t,n))return`impulse-compute: ${e} needs Node ${Ix.join(`.`)} or later, with process.execve; this is Node ${t}${n?``:`, without process.execve`}`},b_e=(e,t)=>e.filter(e=>ad(e.CreationDate)<=ad(t)-2592e5).toSorted((e,t)=>ad(t.CreationDate)-ad(e.CreationDate))[0],Rx=N(function*(e){let t=yield*gg;yield*t.makeDirectory(e,{recursive:!0,mode:448});let n=yield*t.lstat(e);(n.type!==`Directory`||n.mode&18)&&(yield*new ub({message:`The run path must be a directory, not a symbolic link, and must not be writable by group or others.`}))}),zx=N(function*(e){let t=yield*gg;return yield*vm(qm(xx),{onExcessProperty:`error`})(yield*t.readFileString(d(e,`record.json`)))}),Bx=e=>zx(e).pipe(dl(`PlatformError`,e=>e.reason._tag===`NotFound`?k(void 0):A(e))),Vx=N(function*(t){e(`node:sqlite`)||(yield*new db({operation:`RunDirectory`,exitCode:1,message:`EC2 requires node:sqlite to write the run directory. Use Node with SQLite enabled.`})),yield*Rx(t);let n=e=>new db({operation:`RunDirectory`,exitCode:1,message:`Cannot acquire the run writer lock: ${e instanceof Error?e.message:String(e)}. Let the active operation finish and retry.`}),r=yield*Ml(tl({try:()=>{let{DatabaseSync:e}=process.getBuiltinModule(`node:sqlite`);return new e(d(t,`.writer.sqlite`))},catch:n}),e=>qc(()=>e.close()));yield*tl({try:()=>r.exec(`BEGIN IMMEDIATE`),catch:n})}),Hx=N(function*(e,t){let n=yield*gg;yield*Rx(e);let r=yield*n.makeTempDirectoryScoped({directory:e,prefix:`.record-`}),i=d(r,`record.json`);return yield*px(i,fx(yield*Sx({...t,steps:(yield*mx(e,t.steps)).steps}))+`
253
+ `,{mode:384}),yield*(yield*n.open(i,{flag:`r`})).sync,yield*n.rename(i,d(e,`record.json`)),yield*(yield*n.open(e,{flag:`r`})).sync,yield*zx(e)},jl),x_e=N(function*(e,t){return(yield*(yield*gg).readFileString(g(new URL(`../guest/windows/end-of-life.ps1`,import.meta.url)))).replaceAll(`__RUN__`,e).replaceAll(`__RETIRE_AT__`,t)}),Ux=N(function*(e){return yield*(yield*td).digestHex(Foe,new TextEncoder().encode(e))},El(Ioe)),Wx=N(function*(e,t){let n=yield*gg;return`. ([scriptblock]::Create(@'\n${yield*n.readFileString(g(new URL(`../guest/windows/lib.ps1`,import.meta.url)))}\n'@))\n& ([scriptblock]::Create(@'\n${yield*n.readFileString(g(new URL(`../guest/windows/${e}.ps1`,import.meta.url)))}\n'@)) ${Object.entries(t).map(([e,t])=>`-${e} '${t.replaceAll(`'`,`''`)}'`).join(` `)}\n`}),S_e=e=>e===void 0?{Owners:[`amazon`],Filters:[{Name:`name`,Values:[`Windows_Server-2025-English-Full-Base-*`]},{Name:`architecture`,Values:[`x86_64`]},{Name:`state`,Values:[`available`]}]}:{Owners:[`amazon`],ImageIds:[e],Filters:[{Name:`platform`,Values:[`windows`]}]},Gx=N(function*(e,t,n=1){if(e.instance===void 0)return yield*new ub({message:`The record has no observed instance.`});let r=e.instance.id,i=(yield*(yield*cb).describeInstanceLifetime(e.instance.id,yield*lx(t))).value.find(e=>e.id===r);return i?.state!==`running`||i.tags?.find(e=>e.Key===`ot-run`)?.Value!==e.run?yield*new db({operation:`DescribeInstances`,exitCode:n,message:`The exact instance is not running with this run's tag; no guest command was sent.`}):{id:r,end:yield*vm(yx)(i.tags.find(e=>e.Key===`ot-retire-at`)?.Value).pipe(hl(()=>new db({operation:`RetireAt`,exitCode:n,message:`The instance has no valid UTC end tag; no guest command was sent.`})))}}),Kx=N(function*(e,t){let{id:n,end:r}=yield*Gx(e,t),i=yield*id,a=Math.floor(Math.min(Ai(yield*ux(t)),ad(nd(r))-ad(i))/1e3);return a<62?yield*new db({operation:`RetireAt`,exitCode:1,message:`The instance's end or the verb's deadline is too near for another bounded guest command.`}):{id:n,end:r,seconds:a}}),qx=N(function*(e,t,n,r){let i=yield*lb,a=Math.min(60,Math.max(30,Math.floor(e.seconds/4))),o=Math.floor(e.seconds/2);return yield*i.sendCommand({instanceId:e.id,commands:[t],deliverySeconds:a,executionSeconds:o},{...yield*lx(n),...r===void 0?{}:{writeId:r}})}),Jx=N(function*(e,t,n){let r=yield*lb,i=yield*lx(n).pipe(j(n=>r.getCommandInvocation({instanceId:e,commandId:t},n)),vl({while:e=>e._tag===`AwsServiceError`&&e.code===`InvocationDoesNotExist`,schedule:dx}),Bl({while:e=>e.value.status===`Pending`||e.value.status===`InProgress`||e.value.status===`Delayed`,schedule:dx}));return i.value.status!==`Success`||i.value.code!==0?yield*new db({operation:`GetCommandInvocation`,exitCode:1,message:`Guest command ${t} ended as ${i.value.status}/${i.value.code}: ${i.value.err??``}`}):i}),Yx=N(function*(e,t,n,r){let i=yield*Kx(t,r);yield*Hx(e,t);let a=yield*qx(i,n,r);return yield*Jx(i.id,a.value.Command.CommandId,r)}),Xx=(e,t)=>vm(qm(e),{onExcessProperty:`error`})((t??``).trim().split(/\r?\n/).at(-1)).pipe(hl(e=>new db({operation:`GuestOutput`,exitCode:1,message:e.message}))),Zx=F({utc:P,task:P,state:P,start:L(Ym),startWhenAvailable:Dm,user:L(P),logonType:L(P),action:L(P),arguments:L(P),nextRun:L(P),timeZone:P}),Qx=(e,t)=>e.state===`Ready`&&e.task===`ot-retire-${t}`&&e.startWhenAvailable&&e.user===`SYSTEM`&&e.logonType===`ServiceAccount`&&e.action?.replace(/\\+/g,`\\`).toLowerCase()===`c:\\windows\\system32\\shutdown.exe`&&e.arguments===`/s /t 0 /f`?e.start:null,C_e=N(function*(e,t,n){if(t.instance===void 0)return yield*new ub({message:`The created record has no instance identities.`});let r=yield*cb,i=yield*gg,a=yield*r.describeUserData(t.instance.id,yield*lx(n)),o=yield*i.readFileString(d(e,t.intent.userData.file)),s=a.value.UserData?.Value,c=s==null?void 0:qu(s),l=a.value.InstanceId===t.instance.id&&c!==void 0&&Hr(c)&&Buffer.from(c.success).equals(Buffer.from(o))&&Buffer.byteLength(o)===t.intent.userData.bytes&&(yield*Ux(o))===t.intent.userData.sha256,u=yield*Hx(e,{...t,checks:{...t.checks,userDataDecodedOnce:{ok:l,at:a.readAt,detail:l?`One base64 decode equals the saved user-data bytes and digest.`:`The observed user data does not decode to the saved bytes and digest.`}}});return l?u:yield*new db({operation:`UserData`,exitCode:1,message:`The user-data decode check failed; the instance remains recorded at created.`})}),$x=N(function*(e,t,n){let r=yield*C_e(e,t,n);if(r.instance===void 0)return yield*new ub({message:`The created record has no observed instance.`});let i=r.instance.id,a=yield*lb,o=yield*lx(n).pipe(j(e=>a.describeInstanceInformation(i,e)),Bl({until:e=>e.value.some(e=>e.id===i&&e.status===`Online`),schedule:dx}));r=yield*Hx(e,{...r,checks:{...r.checks,ssmOnline:{ok:!0,at:o.readAt,detail:`The exact instance reported Online.`}}});let s=yield*Wx(`read-task`,{Run:t.run}),c=yield*Yx(e,r,s,n).pipe(j(e=>Xx(Zx,e.value.out).pipe(M(t=>({value:t,readAt:e.readAt})))),Bl({until:e=>e.value.state===`Ready`,schedule:dx})),l=c.value,u=Qx(l,t.run),d=u!==null&&ad(u)===ad(nd(t.ends.at(-1)?.value??t.intent.retireAt));return r=yield*Hx(e,{...r,phase:d?`armed`:`created`,checks:{...r.checks,endOfLifeTask:{ok:d,at:c.readAt,detail:JSON.stringify(l)}}}),d?r:yield*new db({operation:`EndOfLifeTask`,exitCode:1,message:`The Ready retirement task does not match the recorded run, end, principal and shutdown action.`})}),eS=N(function*(e,t,n,r,i,a=`echo`){let o=Ai((yield*lx(i)).within);if(o<=3e3)return yield*new db({operation:t,exitCode:1,message:`No time remains for the tool and its stop grace.`});let s=od(yield*id),c=yield*Yb({executable:t,args:n,env:rx(r),deadline:Di(o-3e3),terminationGrace:Oi(3),processGroup:`new`,stdout:vb(1048576,`terminate`),stderr:vb(1048576,`terminate`)}).pipe(ol),l=Hr(c)?c.success:`record`in c.failure.reason?c.failure.reason.record:null,u=l?.stdout._tag===`Captured`?new TextDecoder().decode(l.stdout.bytes):``,d=l?.stderr._tag===`Captured`?new TextDecoder().decode(l.stderr.bytes):``;a===`echo`&&(u!==``&&(yield*Sg(u)),d!==``&&(yield*Sg(d)));let p=od(yield*id),m=l?.exit._tag===`Exited`?l.exit.code:null,h=yield*r_e(e,`local`,{name:t,startedAt:s,endedAt:p,exit:m,nativeExit:l?.exit??null,stdout:u,stderr:d,failure:Vr(c)?c.failure.reason._tag:null});return Vr(c)||m!==0?yield*new db({operation:t,exitCode:1,message:`${t} did not succeed; see ${f(e,h)}.`}):{stdout:u,step:{name:t,startedAt:s,endedAt:p,exit:m,file:f(e,h)}}}),w_e=e=>`ListenAddress 127.0.0.1
254
+ PasswordAuthentication no
255
+ `+e.split(/\r?\n/).filter(e=>!/^\s*(ListenAddress|PasswordAuthentication)\b/i.test(e)).join(`
256
+ `),tS=e=>`"${e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).replaceAll(`%`,`%%`)}"`,nS=e=>`'${e.replaceAll(`'`,`'\\''`).replaceAll(`%`,`%%`)}'`,T_e=e=>`Host ${e.instanceId}\n User Administrator\n IdentityFile ${tS(d(e.directory,`id_ed25519`))}\n IdentitiesOnly yes\n UserKnownHostsFile ${tS(d(e.directory,`known_hosts`))}\n StrictHostKeyChecking yes\n BatchMode yes\n ProxyCommand aws --profile ${nS(e.profile)} --region ${nS(e.region)} ssm start-session --target %h --document-name OT-HostSSH --parameters portNumber=22\n ServerAliveInterval 15\n ServerAliveCountMax 3\n`,rS=P.check(zm(/^ssh-ed25519 [A-Za-z0-9+/]+={0,2}(?: [^\r\n]*)?$/)),E_e=F({hostKey:rS}),D_e=F({config:P,firewallRemoved:I(F({name:P,enabled:P,profiles:P,owner:L(P)}))}),O_e=F({hostKey:rS,valid:Dm,serviceState:P,native:I(F({exit:Hm,out:P,err:P}))}),iS=e=>e.split(` `).slice(0,2).join(` `),aS=N(function*(e,t,n,r){if(t.instance===void 0||t.checks.sshdValid===void 0)return yield*new ub({message:`The record has no pinned SSH host key.`});let i=yield*vm(rS)(t.checks.sshdValid.detail).pipe(hl(()=>new ub({message:`The record's SSH host key is invalid.`})));yield*Kx(t,r),yield*mb(`SSH known hosts`,d(e,`known_hosts`),`${t.instance.id} ${i}\n`),yield*mb(`SSH configuration`,d(e,`ssh_config`),T_e({directory:e,instanceId:t.instance.id,profile:n.profile,region:t.region})),yield*Hx(e,t);let a=yield*eS(e,`ssh`,[`-F`,d(e,`ssh_config`),t.instance.id,`ver`],n.environment,r);return yield*Hx(e,{...t,phase:`reachable`,checks:{...t.checks,sshReached:{ok:!0,at:od(yield*id),detail:`ver succeeded over SSH through OT-HostSSH.`}},steps:[...t.steps,a.step]})}),oS=N(function*(e,t,n,r){let i=yield*Yx(e,t,yield*Wx(`prepare-ssh`,{}),r),a=yield*Xx(D_e,i.value.out),o=yield*gg,s=d(e,`id_ed25519`);if(!(yield*o.exists(s))){yield*Hx(e,t);let i=yield*eS(e,`ssh-keygen`,[`-q`,`-t`,`ed25519`,`-N`,``,`-C`,t.run,`-f`,s],n.environment,r);t=yield*Hx(e,{...t,steps:[...t.steps,i.step]})}let c=yield*eS(e,`ssh-keygen`,[`-y`,`-f`,s],n.environment,r),l=c.stdout.trim();yield*mb(`SSH public key`,d(e,`id_ed25519.pub`),l+`
257
+ `);let u=yield*Wx(`ssh-bootstrap`,{PublicKey:l,Configuration:Ku(w_e(a.config))}),f=yield*Yx(e,t,u,r),p=yield*Xx(O_e,f.value.out);if(!p.valid||p.serviceState!==`Running`)return yield*new db({operation:`SshBootstrap`,exitCode:1,message:`The guest did not confirm a validated, running SSH service.`});let m=yield*Hx(e,{...t,checks:{...t.checks,sshdValid:{ok:!0,at:f.readAt,detail:iS(p.hostKey)}},steps:[...t.steps,c.step]});return yield*aS(e,m,n,r)}),k_e=N(function*(e,t,n){let r=yield*Yx(e,t,yield*Wx(`read-host-key`,{}),n),i=yield*Xx(E_e,r.value.out);t.checks.sshdValid?.detail!==iS(i.hostKey)&&(yield*new db({operation:`HostKey`,exitCode:1,message:`The observed SSH host key differs from the record; access was refused.`}))}),A_e=N(function*(e,t){let n=yield*cb,r=yield*gg;yield*Rx(e.directory);let i=yield*Bx(e.directory);if(i!==void 0&&(i.run!==e.run||i.os!==`windows`||i.phase===`retiring`||i.phase===`retired`))return yield*new ub({message:`Create requires this run's Windows record before retirement has begun.`});if(i?.phase===`reachable`)return yield*wx(i.intent.securityGroupId,yield*lx(t)),i;if(yield*Vx(e.directory),!vt(i,yield*Bx(e.directory)))return yield*new db({operation:`Create`,exitCode:1,message:`The run changed during create preflight. Retry with its current record.`});if(i?.phase===`created`)return yield*wx(i.intent.securityGroupId,yield*lx(t)),yield*oS(e.directory,yield*$x(e.directory,i,t),{profile:e.profile,environment:e.environment},t);if(i?.phase===`armed`)return yield*wx(i.intent.securityGroupId,yield*lx(t)),yield*oS(e.directory,i,{profile:e.profile,environment:e.environment},t);let a=i?.phase===`intended`;if(i?.phase===`intended`){let t=yield*vm(qm(tx),{onExcessProperty:`error`})(yield*r.readFileString(d(e.directory,i.intent.requestFile)));if(a=t.ClientToken===i.intent.clientToken,!a&&!i.refusals.some(e=>e.clientToken===t.ClientToken))return yield*new ub({message:`The stored request's token does not belong to the record.`})}if(i!==void 0&&(i.phase===`requested`||a)){yield*wx(i.intent.securityGroupId,yield*lx(t));let a=yield*Dx(i,t);if(a!==void 0&&a.id!==null){let n=yield*kx(i,t),r=yield*Hx(e.directory,{...i,phase:`created`,instance:n});return yield*oS(e.directory,yield*$x(e.directory,r,t),{profile:e.profile,environment:e.environment},t)}let o=i.phase===`requested`?i:yield*Hx(e.directory,{...i,phase:`requested`});yield*n.runInstances({parameters:yield*r.readFileString(d(e.directory,i.intent.requestFile)),userData:yield*r.readFileString(d(e.directory,i.intent.userData.file))},yield*lx(t)).pipe(dl(`AwsServiceError`,t=>Zc(function*(){return t.code!==`InsufficientInstanceCapacity`&&t.code!==`VcpuLimitExceeded`&&t.code!==`IdempotentParameterMismatch`?yield*t:(yield*Hx(e.directory,{...o,phase:`refused`,refusals:[...o.refusals,{code:t.code,at:t.readAt,clientToken:o.intent.clientToken}]}),yield*new db({operation:`RunInstances`,exitCode:3,message:t.reply.answer.message}))})));let s=yield*kx(o,t),c=yield*Hx(e.directory,{...o,phase:`created`,instance:s});return yield*oS(e.directory,yield*$x(e.directory,c,t),{profile:e.profile,environment:e.environment},t)}let o=i?.intent.attempt??1;if(i?.phase===`refused`){if(o===9)return yield*new ub({message:`Nine create attempts were refused; start a new run.`});o+=1,i=yield*Hx(e.directory,{...i,phase:`intended`,intent:{...i.intent,attempt:o,clientToken:`${e.run}-instance-${o}`}})}let s=yield*n.describeSecurityGroups({by:`name`,name:`ot-no-ingress`},yield*lx(t)),c=s.value.SecurityGroups.length===1?s.value.SecurityGroups[0]:void 0;if(c===void 0)return yield*new db({operation:`DescribeSecurityGroups`,exitCode:3,message:`Exactly one ot-no-ingress group is required; nothing was requested.`});yield*wx(c.GroupId,yield*lx(t));let l=yield*n.describeInstances({by:`run`,run:e.run},yield*lx(t));if(i===void 0?l.value.length!==0:l.value.some(e=>e.state!==`terminated`))return yield*new db({operation:`DescribeInstances`,exitCode:3,message:`Run name is still listed on ${l.value.map(e=>e.id).join(`, `)}; choose another run name.`});let u=yield*n.describeImages(S_e(e.imageId),yield*lx(t)),f=yield*id,p=e.imageId===void 0?b_e(u.value.Images,f):u.value.Images.find(t=>t.ImageId===e.imageId);if(p===void 0)return yield*new db({operation:`DescribeImages`,exitCode:3,message:`No eligible Windows image was found; nothing was requested.`});let m=od(f),h=od(nd(Math.floor((ad(f)+Ai(e.need))/1e3)*1e3)).replace(`.000Z`,`Z`),g=yield*x_e(e.run,h),_=[{Key:`ot-pool`,Value:`teammates`},{Key:`ot-kind`,Value:`windows-instance`},{Key:`ot-owner`,Value:e.owner},{Key:`ot-run`,Value:e.run},{Key:`Name`,Value:`ot-${e.run}`}],v=[..._,{Key:`ot-retire-at`,Value:h}],y=o===1?`${e.run}-instance`:`${e.run}-instance-${o}`,b=JSON.stringify({ImageId:p.ImageId,InstanceType:e.instanceType,MinCount:1,MaxCount:1,ClientToken:y,InstanceInitiatedShutdownBehavior:`terminate`,IamInstanceProfile:{Name:`openteammate-host-ssm`},SecurityGroupIds:[c.GroupId],MetadataOptions:{HttpTokens:`required`,HttpPutResponseHopLimit:1,HttpEndpoint:`enabled`},BlockDeviceMappings:[{DeviceName:`/dev/sda1`,Ebs:{VolumeSize:e.rootGiB,VolumeType:`gp3`,Encrypted:!0,DeleteOnTermination:!0}}],TagSpecifications:[{ResourceType:`instance`,Tags:v},{ResourceType:`volume`,Tags:v},{ResourceType:`network-interface`,Tags:_}]}),ee=o===1?`userdata.ps1`:`userdata-${o}.ps1`,x=o===1?`requests/run-instances.json`:`requests/run-instances-${o}.json`;yield*r.makeDirectory(d(e.directory,`requests`),{recursive:!0,mode:448}),yield*mb(`user data`,d(e.directory,ee),g),yield*mb(`RunInstances parameters`,d(e.directory,x),b);let te={schema:`openteammate.ec2-instance/record@1`,run:e.run,owner:e.owner,os:`windows`,profile:e.profile,region:e.region,helper:{...e.helper,awsCliVersion:`${s.reply.client.name}/${s.reply.client.version}`},phase:`intended`,intent:{attempt:o,image:{id:p.ImageId,name:p.Name,released:od(p.CreationDate)},instanceType:e.instanceType,rootGiB:e.rootGiB,retireAt:h,clientToken:y,securityGroupId:c.GroupId,instanceProfile:`openteammate-host-ssm`,userData:{file:ee,bytes:new TextEncoder().encode(g).byteLength,sha256:yield*Ux(g)},requestFile:x},refusals:i?.refusals??[],checks:{},ends:[...i?.ends??[],{value:h,at:m,by:`create`}],steps:i?.steps??[]};yield*Hx(e.directory,te);let ne=yield*Hx(e.directory,{...te,phase:`requested`});yield*n.runInstances({parameters:b,userData:g},yield*lx(t)).pipe(dl(`AwsServiceError`,t=>Zc(function*(){return t.code!==`InsufficientInstanceCapacity`&&t.code!==`VcpuLimitExceeded`&&t.code!==`IdempotentParameterMismatch`?yield*t:(yield*Hx(e.directory,{...ne,phase:`refused`,refusals:[...ne.refusals,{code:t.code,at:t.readAt,clientToken:y}]}),yield*new db({operation:`RunInstances`,exitCode:3,message:t.reply.answer.message}))})));let re=yield*kx(ne,t),ie=yield*Hx(e.directory,{...ne,phase:`created`,instance:re});return yield*oS(e.directory,yield*$x(e.directory,ie,t),{profile:e.profile,environment:e.environment},t)},jl),j_e=(e,t)=>(t===void 0?cx(e.within):k(t)).pipe(j(t=>ux(t).pipe(j(n=>A_e(e,t).pipe(bl({duration:n,orElse:()=>A(new db({operation:`Create`,exitCode:1,message:`The create deadline expired; read the recorded phase before resuming.`}))})))))),M_e=(e,t,n)=>Zc(function*(){let r=yield*gg,i=yield*r.realPath(g(new URL(`../`,import.meta.url))),a=r=>eS(e,`git`,[`--no-optional-locks`,`-C`,i,...r],t,n,`capture`),o=yield*r.realPath((yield*a([`rev-parse`,`--show-toplevel`])).stdout.trim());return f(o,i)!==d(`scripts`,`ec2-instance`)||(yield*a([`cat-file`,`-e`,`HEAD:scripts/ec2-instance/main.ts`]),(yield*a([`status`,`--porcelain`,`--untracked-files=all`,`--`,`.`])).stdout.trim()!==``)?`unknown`:(yield*a([`rev-parse`,`HEAD`])).stdout.trim()}).pipe(ol,M(e=>Hr(e)?e.success:`unknown`)),sS=3e5,cS=e=>ad(nd(e)),lS=()=>`w`+b().replaceAll(`-`,``),uS=(e,t=1)=>new db({operation:`Extend`,exitCode:t,message:e}),dS=(e,t)=>Xx(Zx,e).pipe(j(e=>{let n=Qx(e,t);return n===null?A(uS(`The retirement task is not Ready with this run's SYSTEM shutdown action.`)):k(od(n).replace(`.000Z`,`Z`))})),N_e=N(function*(e){let{directory:t,to:n,deadline:r}=e,i=e.record,a=i.instance;if(i.os!==`windows`||a===void 0||![`created`,`armed`,`reachable`].includes(i.phase))return yield*uS(`Cannot extend the ${i.os} record at phase ${i.phase}.`,3);if(yield*Vx(t),!vt(yield*zx(t),i))return yield*uS(`The run record changed before extension acquired custody. Retry with the current record.`);yield*wx(i.intent.securityGroupId,yield*lx(r));let o=yield*cb,s=[...new Set([a.rootVolumeId,...a.volumeIds])],c=[a.id,...s],l=yield*mx(t,i.steps);i={...i,steps:l.steps};let u=i.pendingEnd!==void 0,d=e=>uS(e,u?1:3),f=N(function*(e,t){let n=ad(yield*id);(cS(e)-n<sS||cS(t)-n<sS)&&(yield*d(`Both the current and requested ends need at least five minutes remaining.`))}),p=Zc(function*(){let e=yield*Gx(i,r,u?1:3),t=yield*o.describeVolumeEnds(s,yield*lx(r)),n=[];for(let e of s){let r=t.value.find(t=>t.id===e);if(r?.tags?.find(e=>e.Key===`ot-run`)?.Value!==i.run)return yield*d(`The exact volume `+e+` does not have this run's ownership tag.`);let a=yield*vm(yx)(r.tags.find(e=>e.Key===`ot-retire-at`)?.Value).pipe(hl(()=>d(`Volume `+e+` has no valid end tag.`)));n.push(a)}return{instance:e.end,volumes:n}}),m=yield*Wx(`read-task`,{Run:i.run}),h=Zc(function*(){let e=yield*Yx(t,i,m,r);return yield*dS(e.value.out,i.run)}),g=N(function*(e){return i=yield*Hx(t,{...i,pendingEnd:e}),e}),_=N(function*(e,n){let s=e;if(s.task.state===`unknown`){let e=l.commands.get(s.task.writeId);e?.instance===a.id&&(s=yield*g({...s,task:{...s.task,state:`accepted`,commandId:e.commandId}}))}if(s.tags===`unknown`){let e=l.tagWrites.get(s.id);e?.to===s.to&&e.ids.length===c.length&&c.every(t=>e.ids.includes(t))&&(s=yield*g({...s,tags:`acknowledged`}))}if(s.task.state===`accepted`){let e=yield*Jx(a.id,s.task.commandId,r).pipe(ol);if(Vr(e)){if(e.failure._tag!==`LifecycleError`||e.failure.operation!==`GetCommandInvocation`)return yield*e.failure;s=yield*g({...s,task:{state:`planned`}})}}let _=n??(yield*h);if(_!==s.to){if(_!==s.from||s.tags===`acknowledged`)return yield*uS(`Guest task disagrees with the unfinished end move. Check the saved record and task.`);let e=yield*Kx(i,r);if(e.end!==(s.mode===`restore`?s.to:s.from))return yield*d(`The EC2 end changed before the guest move.`);yield*f(_,s.to);let t=yield*Wx(`extend`,{Run:i.run,OldEnd:s.from,NewEnd:s.to,Restore:s.mode===`restore`?`yes`:`no`}),n=lS();s=yield*g({...s,task:{state:`unknown`,writeId:n}}),u=!0;let o=yield*qx(e,t+`
258
+ `+m,r,n).pipe(ol);if(Vr(o))return yield*g(s),yield*o.failure;let c=o.success.value.Command.CommandId;s=yield*g({...s,task:{state:`accepted`,writeId:n,commandId:c}});let l=yield*Jx(a.id,c,r);if((yield*dS(l.value.out,i.run))!==s.to)return yield*uS(`The guest read-back does not show the requested shutdown instant. Run extend again to reconcile it.`)}if(s=yield*g({...s,task:{state:`completed`}}),s.mode===`restore`){if((yield*Gx(i,r)).end!==s.to)return yield*uS(`The instance end changed while the guest task was being reconciled.`);let{pendingEnd:e,...n}=i;return yield*Hx(t,n)}let v=Zc(function*(){let e=yield*p,t=[e.instance,...e.volumes];return e.instance!==s.from&&e.instance!==s.to?yield*uS(`The instance carries an end outside the unfinished move.`):e.volumes.some(e=>cS(e)>cS(s.to))?yield*uS(`A recorded volume carries a later end. Its tag cannot be shortened.`):{all:t.every(e=>e===s.to),current:e.instance}}),y=yield*v;if(!y.all){if(s.tags!==`acknowledged`){yield*f(y.current,s.to),s=yield*g({...s,tags:`unknown`}),u=!0;let e=yield*o.setEndTags({ids:c,to:s.to},{...yield*lx(r),writeId:s.id}).pipe(ol);if(Vr(e))return yield*g(s),yield*e.failure;s=yield*g({...s,tags:`acknowledged`})}yield*v.pipe(Bl({until:e=>e.all,schedule:dx}))}let{pendingEnd:b,...ee}=i,x=ee.ends.at(-1)?.value===s.to?ee.ends:[...ee.ends,{value:s.to,at:od(yield*id),by:`extend`}];return yield*Hx(t,{...ee,ends:x})});return yield*Zc(function*(){if(i.pendingEnd!==void 0){let e=i.pendingEnd;if(e.mode===`extend`&&cS(e.to)<cS(e.from))return yield*uS(`The pending extension would shorten the recorded end.`);if(yield*p,i=yield*_(e),e.to===n)return i}let e=yield*p;if([e.instance,...e.volumes].some(e=>cS(n)<cS(e)))return yield*d(`The requested end is earlier than a current instance or volume end tag.`);yield*f(e.instance,n);let t=yield*h;if(t!==e.instance){yield*f(t,e.instance);let n=yield*g({id:lS(),mode:`restore`,from:t,to:e.instance,task:{state:`planned`},tags:`planned`});i=yield*_(n,t)}if(n===e.instance&&e.volumes.every(e=>e===n)&&i.ends.at(-1)?.value===n)return i;let r=yield*g({id:lS(),mode:`extend`,from:e.instance,to:n,task:{state:`planned`},tags:`planned`});return yield*_(r,e.instance)}).pipe(bl({duration:yield*ux(r),orElse:()=>A(uS(`The extension deadline expired. Run extend again to reconcile the saved move.`))}))},jl),P_e=N(function*(e,t,n,r){let i=yield*ux(r);return yield*Zc(function*(){return t.os!==`windows`||t.phase!==`armed`&&t.phase!==`reachable`||t.checks.sshdValid?.ok!==!0?yield*new ub({message:`Run create to arm the instance and pin its SSH key before reach.`}):(yield*Vx(e),vt(t,yield*zx(e))?(yield*wx(t.intent.securityGroupId,yield*lx(r)),yield*k_e(e,t,r),yield*aS(e,t,n,r)):yield*new db({operation:`Reach`,exitCode:1,message:`The run changed during reach preflight. Retry with its current record.`}))}).pipe(bl({duration:i,orElse:()=>A(new db({operation:`Reach`,exitCode:1,message:`The reach deadline expired; the record remains available for another attempt.`}))}))},jl),fS=F({instances:I(F({id:Xb,state:L(P),token:L(Xb)})),notStarted:Cm(Tm(`deadline`)),reply:L(tb),ok:Dm,readAt:P}),pS=F({ids:I(Xb),reply:L(tb),readAt:P,ok:Dm}),F_e=F({volumes:L(pS),interfaces:L(pS)}),I_e=F({kind:jm([`ec2-instance`,`ebs-volume`,`network-interface`]).annotate({description:`Kind of the recorded resource.`}),id:Xb.annotate({description:`Exact provider resource ID.`}),attachmentInventory:Cm(Am([Tm(`observed`),F_e])).annotate({description:`For an instance, the observed inventory or the two tag searches used to recover it.`}),launchedAt:Cm(P).annotate({description:`Launch time EC2 returned for a recovered instance whose attachments could no longer be read from the instance.`}),proof:jm([`terminated`,`not-listed-after-earlier-read`,`not-found-after-earlier-read`,`InvalidVolume.NotFound`,`deleted`,`InvalidNetworkInterfaceID.NotFound`,`unproven`]).annotate({description:`Provider observation supporting absence, or unproven.`}),reply:L(tb).annotate({description:`The provider's actual reply; null when the read obtained no reply.`}),readAt:P.annotate({description:`UTC time of this provider read.`})}),L_e=F({tokens:I(Xb).check(Um(1)),byRunTag:fS,byClientToken:fS,ok:Dm}),R_e={"ec2-instance":[`terminated`,`not-listed-after-earlier-read`,`not-found-after-earlier-read`],"ebs-volume":[`InvalidVolume.NotFound`,`deleted`],"network-interface":[`InvalidNetworkInterfaceID.NotFound`]},mS=({recordPhase:e,recordedInstanceId:t,resources:n,filteredReads:r})=>{if(t!==null&&!n.some(e=>e.kind===`ec2-instance`&&e.id===t))return`unproven`;let i=[r.byRunTag,r.byClientToken];if(!r.ok||i.some(e=>!e.ok||e.notStarted!==void 0||e.reply?.answer.kind!==`answered`)||n.some(e=>e.reply===null||!R_e[e.kind].includes(e.proof)))return`unproven`;for(let e of n){if(e.kind!==`ec2-instance`)continue;let r=e.attachmentInventory;if(r===void 0)return`unproven`;if(r===`observed`){if(e.launchedAt!==void 0||t===null&&!n.some(e=>e.kind===`network-interface`))return`unproven`;continue}for(let[e,t]of[[r.volumes,`DescribeVolumes`],[r.interfaces,`DescribeNetworkInterfaces`]])if(e===null||!e.ok||e.ids.length!==0||e.reply?.operation!==t||e.reply.answer.kind!==`answered`)return`unproven`}for(let e of i)for(let t of e.instances){let e=n.find(e=>e.kind===`ec2-instance`&&e.id===t.id);if(e===void 0){if(t.state!==`terminated`||t.token===null||r.tokens.includes(t.token))return`unproven`}else if(e.proof!==`terminated`&&t.state!==`terminated`)return`unproven`}return n.length===0?(e===`intended`||e===`refused`)&&r.byClientToken.instances.length===0?`nothing-created`:`unproven`:`released`},hS=`openteammate.ec2-instance/receipt@3`,gS=F({schema:Tm(hS).annotate({description:`Version of the release receipt.`}),run:vx.annotate({description:`Run whose resources this receipt describes.`}),region:P.annotate({description:`Region in which the provider was read.`}),os:d_e.annotate({description:`Recorded guest operating system.`}),recordedInstanceId:L(Xb).annotate({description:`The record’s instance ID at verification, if observed.`}),terminationAttemptedFor:Cm(Xb).annotate({description:`Instance for which this run reached dispatch without an acknowledgement proving it caused the end.`}),recordPhase:f_e.annotate({description:`Record phase used to evaluate this release.`}),status:jm([`released`,`nothing-created`,`unproven`]).annotate({description:`Whether release or non-creation was proved, or remains unproven.`}),ended:jm([`retire`,`guest-shutdown`,`other-terminate`,`not-created`,`unknown`]).annotate({description:`Observed source of the instance's end.`}),resources:I(I_e).annotate({description:`Provider-neutral resource list with the evidence for each resource.`}),filteredReads:L_e.annotate({description:`Tokens searched and the observed identities, states and tokens from both searches.`}),accountCheck:F({securityGroupId:Xb.annotate({description:`The positive control group ID.`}),reply:tb,ok:Dm.annotate({description:`Whether that exact resource was readable.`}),readAt:P.annotate({description:`UTC time of the account check.`})}).annotate({description:`Evidence that absence reads used the intended account and region.`}),localFiles:F({removed:I(P).annotate({description:`Local key files removed.`}),absent:Dm.annotate({description:`Whether local key files were confirmed absent.`})}).annotate({description:`Local cleanup observations.`}),unproven:I(F({item:P.annotate({description:`Resource or obligation still unproven.`}),reason:P.annotate({description:`What prevented proof.`}),next:P.annotate({description:`Next action that could establish proof.`})})).annotate({description:`Outstanding release obligations and their next steps.`}),startedAt:P.annotate({description:`UTC time release verification began.`}),endedAt:P.annotate({description:`UTC time release verification ended.`})}).annotate({description:`Release evidence for the resources this run recorded or recovered.`}).check(Rm(e=>e.status===`unproven`||e.accountCheck.ok&&e.localFiles.absent&&e.unproven.length===0&&e.accountCheck.reply.answer.kind===`answered`&&e.status===mS(e),{message:`A successful release requires every resource, account, filtered-read and local-file proof.`})),z_e=vm(gS,{onExcessProperty:`error`}),_S=xm(gS,{onExcessProperty:`error`}),B_e=N(function*(e){let t=yield*gg;return yield*vm(qm(gS),{onExcessProperty:`error`})(yield*t.readFileString(d(e,`receipt.json`)))}),vS=N(function*(e,t){let n=yield*(yield*gg).readFileString(d(e,`receipt.json`)).pipe(dl(`PlatformError`,e=>e.reason._tag===`NotFound`?k(void 0):A(e)));if(n===void 0)return;let r=()=>new ub({message:`The existing receipt.json is invalid.`}),i=yield*vm(qm(Em))(n).pipe(hl(r)),a=yield*vm(F({schema:P}))(i).pipe(hl(r));if(a.schema===`openteammate.ec2-instance/receipt@1`||a.schema===`openteammate.ec2-instance/receipt@2`)return yield*new ub({message:`Unknown earlier release receipt schema version. Move the old receipt.json aside and run retire again to re-prove every resource from the record. Check any inventory: item in the old receipt by hand because the record cannot carry it forward.`});if(a.schema!==`openteammate.ec2-instance/receipt@3`)return yield*new ub({message:`Unknown release receipt schema version.`});let o=yield*z_e(i).pipe(hl(r));return o.run!==t.run||o.region!==t.region||o.os!==t.os?yield*new ub({message:`The existing receipt belongs to another run, region or operating system.`}):o}),yS=N(function*(e,t){let n=yield*gg;yield*Rx(e);let r=yield*n.makeTempDirectoryScoped({directory:e,prefix:`.receipt-`}),i=d(r,`receipt.json`);return yield*px(i,fx(yield*_S(t))+`
259
+ `,{mode:384}),yield*(yield*n.open(i,{flag:`r`})).sync,yield*n.rename(i,d(e,`receipt.json`)),yield*(yield*n.open(e,{flag:`r`})).sync,yield*B_e(e)},jl),bS=(e,t)=>Hr(e)?{reply:e.success.reply,readAt:e.success.readAt}:e.failure._tag===`AwsReadError`?e.failure.observation??{reply:null,readAt:t}:e.failure._tag===`UsageError`?{reply:null,readAt:t}:{reply:e.failure.reply,readAt:e.failure.readAt},V_e=(e,t,n,r,i)=>{let a={instances:[],ok:!1,reply:null,readAt:r},o=e=>e!==void 0&&(e.ok||e.notStarted===`deadline`)?e:a,s=i!==void 0&&i.tokens.length===t.length&&t.every(e=>i.tokens.includes(e)),c={byRunTag:o(i?.byRunTag),byClientToken:s?o(i.byClientToken):a},l={tokens:t,byRunTag:a,byClientToken:a,ok:!1},u=new Map,d=new Map;return{search:N(function*(r){let i=yield*cb,o=[],s=!1;l={...l,byRunTag:{...l.byRunTag,ok:!1},byClientToken:{...l.byClientToken,ok:!1},ok:!1};for(let f of[`byRunTag`,`byClientToken`]){let p=f===`byRunTag`?`run-tag search`:`client-token search`;d.has(p)||d.set(p,{item:p,reason:`This filtered search has not completed.`,next:`Run retire again to complete this search.`});let m=yield*lx(n);l={...l,[f]:{...a,readAt:od(yield*id)}};let h=yield*(f===`byRunTag`?i.describeInstanceResources({by:`run`,run:e},m):i.describeInstanceResourcesByTokens(t,m)).pipe(ol),g=bS(h,od(yield*id)),_;if(Vr(h)){let e=h.failure,t=e._tag===`AwsReadError`&&e.reason===`budget`;_=t?{...c[f],notStarted:`deadline`,ok:!1}:{...g,instances:[],ok:!1};let n=ob(e);d.set(p,{item:p,reason:t?u.has(p)?sb(u.get(p)??e):`No read was started for lack of time.`:`${n.operation} ${n.code}: ${n.message}`,next:`Run retire again to complete this search.`}),t&&d.set(`deadline`,{item:`deadline`,reason:`No read was started for lack of time in the retirement deadline.`,next:`Run retire again to obtain fresh proofs.`}),ib(e)?u.set(p,e):s=!0}else{u.delete(p),o.push(...h.success.value);let e=h.success.value.flatMap(({id:e,state:t,token:n})=>e===null?[]:[{id:e,state:t,token:n}]),t=e.length===h.success.value.length;_={...g,instances:e,ok:t},t?(c[f]=_,d.delete(p)):(d.set(p,{item:p,reason:`The provider listed an instance without an ID.`,next:`Repeat the search to identify every listed instance.`}),s=!0)}l={...l,[f]:_},Hr(h)&&(yield*r(h.success.value))}return l={...l,ok:l.byRunTag.ok&&l.byClientToken.ok},{listed:o,ok:l.ok,stop:s}}),reads:()=>l,issues:d,expire:()=>{for(let[e,t]of u){let n=d.get(e);n&&d.set(e,{...n,reason:sb(t)})}}}},H_e=(e,t,n,r)=>{if(Hr(t)&&t.success.value.some(t=>t.id===e&&t.state===`terminated`))return`terminated`;if(r)return`unproven`;if(Hr(t))return t.success.value.length===0?`not-listed-after-earlier-read`:`unproven`;if(t.failure._tag!==`InvalidInstanceID.NotFound`||n===void 0)return`unproven`;let i=rd(n),a=rd(t.failure.readAt);return ir(i)&&ir(a)&&ad(a.value)-ad(i.value)>=3e5?`not-found-after-earlier-read`:`unproven`},U_e=N(function*(e,t){let n=yield*cb,r=od(yield*id);if(e.kind===`ebs-volume`){let i=yield*n.describeVolume(e.id,t).pipe(ol),a=Vr(i)&&i.failure._tag===`InvalidVolume.NotFound`?`InvalidVolume.NotFound`:Hr(i)&&i.success.value.some(t=>t.id===e.id&&t.state===`deleted`)?`deleted`:`unproven`;return{resource:{...e,...bS(i,r),proof:a},error:Vr(i)&&a===`unproven`?i.failure:void 0}}let i=yield*n.describeNetworkInterface(e.id,t).pipe(ol),a=Vr(i)&&i.failure._tag===`InvalidNetworkInterfaceID.NotFound`?`InvalidNetworkInterfaceID.NotFound`:`unproven`;return{resource:{...e,...bS(i,r),proof:a},error:Vr(i)&&a===`unproven`?i.failure:void 0}}),xS=id.pipe(M(od)),SS=e=>[{kind:`ec2-instance`,id:e.id},...Array.from(new Set([e.rootVolumeId,...e.volumeIds]),e=>({kind:`ebs-volume`,id:e})),...e.networkInterfaceIds.map(e=>({kind:`network-interface`,id:e}))],W_e=e=>vS(e.directory,e.record).pipe(M(t=>K_e(e,t))),G_e=e=>rl(W_e(e)),K_e=N(function*(e,t){let{directory:n}=e,r=e.record,i=yield*gg,a=yield*cb,o=yield*xS,s=yield*cx(e.within),c,l=()=>new Cx({securityGroupId:r.intent.securityGroupId,operation:`DescribeSecurityGroups`,kind:`process`,message:`The retirement deadline expired during the account check; no termination was sent.`+(c===void 0?``:` Deadline reached while ${c.code} persisted: ${c.message}`)}),u=yield*lx(s).pipe(hl(l),j(e=>wx(r.intent.securityGroupId,e)),hl(e=>{if(e._tag===`AccountCheckFailed`){if(e.budget&&c!==void 0)return l();e.retryable&&(c=e)}return e}),vl({schedule:dx,while:e=>e._tag===`AccountCheckFailed`&&e.retryable===!0}),bl({duration:yield*ux(s).pipe(hl(l)),orElse:()=>A(l())})),f=yield*mx(n,r.steps);r={...r,steps:f.steps},r.instance!==void 0&&(r.phase===`retiring`||t?.terminationAttemptedFor===r.instance.id||t?.ended===`retire`&&t.recordedInstanceId===r.instance.id)&&f.attempted.add(r.instance.id);let p=Array.from(new Set([r.intent.clientToken,...r.refusals.map(e=>e.clientToken)])),m=V_e(r.run,p,s,o,t?.filteredReads),h=new Map;for(let e of t?.resources??[])h.set(e.id,{...e,proof:`unproven`});let g=(e,t)=>{h.has(t)||h.set(t,{kind:e,id:t,reply:null,proof:`unproven`,readAt:o,...e===`ec2-instance`?{attachmentInventory:`observed`}:{}})};if(r.instance!==void 0)for(let e of SS(r.instance))g(e.kind,e.id);let _=new Map((t?.unproven??[]).filter(e=>e.item.startsWith(`inventory:`)).map(e=>[e.item,e]));for(let e of h.values())if(typeof e.attachmentInventory==`object`){let t=`inventory:${e.id}`;_.set(t,{item:t,reason:`Attachment inventory requires fresh run-tag searches.`,next:`Run retire again to read both attachment types.`})}let v=new Set(Array.from(h.values()).filter(e=>e.kind===`ec2-instance`&&!_.has(`inventory:${e.id}`)).map(e=>e.id));r.instance?.networkInterfaceIds.length===0&&(v.delete(r.instance.id),_.set(`inventory:${r.instance.id}`,{item:`inventory:${r.instance.id}`,reason:`No interface ID was recorded.`,next:`Recover the original interface ID before claiming release.`}));let y=new Set,b=new Map,ee=new Set,x=new Map,te=new Map,ne=new Map,re=e=>{let n=ne.get(e),r=t?.resources.some(t=>t.kind===`ec2-instance`&&t.id===e)?t.ended:void 0;return f.acknowledged.has(e)?`retire`:n===`Client.InstanceInitiatedShutdown`||n===void 0&&r===`guest-shutdown`?`guest-shutdown`:!f.attempted.has(e)&&(n===`Client.UserInitiatedShutdown`||n===void 0&&r===`other-terminate`)?`other-terminate`:`unknown`},ie=()=>{let e=Array.from(h.values()).filter(e=>e.kind===`ec2-instance`).map(e=>re(e.id));return e.length>0&&e.every(t=>t===e[0])?e[0]??`unknown`:`unknown`},ae=()=>({recordPhase:r.phase,recordedInstanceId:r.instance?.id??null,resources:Array.from(h.values()),filteredReads:m.reads()}),S=()=>{let e=new Map([...te,..._,...x,...m.issues]);for(let t of h.values())t.proof===`unproven`&&!e.has(t.id)&&e.set(t.id,{item:t.id,reason:`The exact read has not established absence.`,next:`Run retire again to read this resource.`});return{schema:hS,...ae(),...r.instance!==void 0&&f.attempted.has(r.instance.id)&&!f.acknowledged.has(r.instance.id)?{terminationAttemptedFor:r.instance.id}:{},run:r.run,region:r.region,os:r.os,status:`unproven`,ended:ie(),accountCheck:{securityGroupId:r.intent.securityGroupId,ok:!0,reply:u.reply,readAt:u.readAt},localFiles:{removed:[],absent:!1},unproven:Array.from(e.values()),startedAt:o,endedAt:o}},oe=(e,t,n)=>{x.set(e,{item:e,reason:ob(t).message,next:n}),t._tag===`AwsReadError`&&t.reason===`budget`&&x.set(`deadline`,{item:`deadline`,reason:`No read was started for lack of time in the retirement deadline.`,next:`Run retire again to finish the outstanding proofs.`})},C=new Map,se=(e,t,n)=>{if(ib(t))C.set(e,t),te.set(e,{item:e,reason:ob(t).message,next:n});else{oe(e,t,n);let r=C.get(e);r!==void 0&&t._tag===`AwsReadError`&&t.reason===`budget`&&x.set(e,{item:e,reason:sb(r),next:n}),C.delete(e)}},ce=e=>lx(s).pipe(j(t=>a.describeInstances({by:`id`,id:e},t).pipe(ol))),le=N(function*(e,t,i){let o=e.id,c=i??(yield*ce(o)),l=Hr(c)?c.success.value.find(e=>e.id===o):void 0,u=r.instance?.id===o?r.instance.launchedAt:b.get(o)?.launch??e.launchedAt,d=Hr(c)?c.success.value.length===0:c.failure._tag===`InvalidInstanceID.NotFound`,p=l?.state===`terminated`?void 0:l??(d?t:void 0);if(p!==void 0&&v.has(o)){if(r.instance?.id!==o&&!b.has(o)||p.tags?.find(e=>e.Key===`ot-run`)?.Value!==r.run)x.set(o,{item:o,reason:`Termination requires this record's ID or token and its matching ot-run tag.`,next:`Verify custody before attempting retirement again.`});else if(!ee.has(o)&&!f.acknowledged.has(o)){h.set(o,{...e,...bS(c,yield*xS),proof:`unproven`}),r=yield*Hx(n,{...r,phase:`retiring`}),yield*yS(n,{...S(),endedAt:yield*xS});let t=yield*lx(s);ee.add(o),f.attempted.add(o);let i=yield*a.terminateInstance(o,t).pipe(ol);r=yield*Hx(n,r),Vr(i)?oe(o,i.failure,`Run retire again to reconcile the request; it may have reached AWS.`):sx(o,i.success.value)&&f.acknowledged.add(o),c=yield*ce(o),l=Hr(c)?c.success.value.find(e=>e.id===o):void 0}}let m=H_e(o,c,u,t!==void 0);return h.set(o,{...e,...bS(c,yield*xS),proof:m}),l?.state===`terminated`&&l.reason!==null&&ne.set(o,l.reason.Code),te.delete(o),(Hr(c)||c.failure._tag===`InvalidInstanceID.NotFound`)&&C.delete(o),Vr(c)&&(c.failure._tag===`InvalidInstanceID.NotFound`?m===`unproven`&&t===void 0&&te.set(o,{item:o,reason:`not-found-too-soon: the NotFound reply does not establish absence.`,next:`Read again after the recorded launch is at least five minutes old.`}):se(o,c.failure,`Run retire again to complete the instance proof.`)),c}),ue=N(function*(e){for(let t of h.values()){if(t.kind===`ec2-instance`||t.proof!==`unproven`||e.has(t.id))continue;e.add(t.id);let n=yield*U_e(t,yield*lx(s));h.set(t.id,n.resource),te.delete(t.id),n.error===void 0&&C.delete(t.id),n.error!==void 0&&se(t.id,n.error,`Run retire again to complete the attachment proof.`)}}),w=N(function*(e){for(let t of e){if(t.id===null)continue;let e=t.id;if(t.token!==null&&p.includes(t.token)){b.set(e,t),g(`ec2-instance`,e);let i=Ox(t);if(i!==void 0){for(let e of SS(i))g(e.kind,e.id);let t=h.get(e);if(t!==void 0){let{launchedAt:n,...r}=t;h.set(e,{...r,attachmentInventory:`observed`})}v.add(e),_.delete(`inventory:${e}`),r.instance===void 0&&(r=yield*Hx(n,{...r,instance:i,phase:`created`}))}else if(!v.has(e)&&!y.has(e)){let n=h.get(e);n!==void 0&&h.set(e,{...n,...t.launch===null?{}:{launchedAt:t.launch},attachmentInventory:typeof n.attachmentInventory==`object`?n.attachmentInventory:{volumes:null,interfaces:null}}),_.set(`inventory:${e}`,{item:`inventory:${e}`,reason:`The token lookup did not recover complete volume and interface custody.`,next:`Run retire again to recover the attachment IDs from the instance or its run tags after it ends.`})}}}}),de=N(function*(e,t){let i=e===`ebs-volume`?`volume tag search`:`interface tag search`,o=yield*lx(s),c={by:`run`,run:r.run},l=e===`ebs-volume`?yield*a.describeVolume(c,o).pipe(ol):yield*a.describeNetworkInterface(c,o).pipe(ol),u=Hr(l)?l.success.value.flatMap(e=>e.id===null?[]:[e.id]):[],d=e===`ebs-volume`?`volumes`:`interfaces`,f={...bS(l,yield*xS),ids:u,ok:Hr(l)&&u.length===l.success.value.length};for(let e of t){let t=h.get(e.id)??e,n=typeof t.attachmentInventory==`object`?t.attachmentInventory:{volumes:null,interfaces:null};h.set(t.id,{...t,attachmentInventory:{...n,[d]:f}})}if(te.delete(i),Vr(l))return se(i,l.failure,`Run retire again to complete the attachment inventory.`),!1;C.delete(i);let p=h.size;for(let t of l.success.value)t.id===null?x.set(i,{item:i,reason:`The run-tag search returned an attachment without an ID.`,next:`Read the attachment inventory again before release.`}):g(e,t.id);return h.size!==p&&(yield*yS(n,{...S(),endedAt:yield*xS})),l.success.value.length===0}),fe=yield*Zc(function*(){yield*ux(s),x.clear();let e=new Map;for(let t of h.values())t.kind===`ec2-instance`&&t.proof===`unproven`&&(t.id===r.instance?.id||b.has(t.id))&&v.has(t.id)&&e.set(t.id,yield*le(t,void 0));let t=new Set;yield*ue(t);let n=r.instance===void 0?void 0:h.get(r.instance.id),i=n===void 0?void 0:e.get(n.id),a=n?.proof===`terminated`||i!==void 0&&Hr(i)&&i.success.value.some(e=>e.id===n?.id),o=i!==void 0&&Vr(i)&&ib(i.failure);if((a||o)&&x.size===0&&_.size===0&&Array.from(h.values()).some(e=>e.proof===`unproven`&&(e.kind!==`ec2-instance`||e.id===n?.id)))return!1;let c=Zc(function*(){let n=yield*m.search(w),i=new Map;for(let e of n.listed)e.id!==null&&e.state!==`terminated`&&i.set(e.id,e);for(let e of n.listed)e.id!==null&&!h.has(e.id)&&!Ex(r,e)&&x.set(e.id,{item:e.id,reason:`other-instance-listed: this ID has neither recorded custody nor proof of foreign terminated history.`,next:`Resolve the other instance's custody without terminating it by tag.`});for(let t of h.values()){if(t.kind!==`ec2-instance`||t.proof===`terminated`)continue;let n=i.get(t.id);(n!==void 0||!e.has(t.id)&&t.proof===`unproven`)&&e.set(t.id,yield*le(t,n,e.get(t.id)))}let a=Array.from(h.values()).filter(e=>e.kind===`ec2-instance`&&e.proof!==`unproven`&&_.has(`inventory:${e.id}`)&&(b.has(e.id)||e.id!==r.instance?.id)),o=!1;if(a.length!==0){let e=yield*de(`ebs-volume`,a),t=yield*de(`network-interface`,a);o=e&&t}if(yield*ue(t),o&&Array.from(h.values()).every(e=>e.kind===`ec2-instance`||e.proof!==`unproven`))for(let e of a)y.add(e.id),_.delete(`inventory:${e.id}`);let s=Array.from(_.keys()).some(e=>!a.some(t=>`inventory:${t.id}`===e)&&!te.has(e.slice(10))&&!n.listed.some(t=>`inventory:${t.id}`===e&&t.state!==`terminated`));return{ok:n.ok,stop:n.stop||x.size!==0||n.ok&&s,needsInventory:_.size!==0}}),l=yield*c;if(l.stop)return!0;if(!l.ok||l.needsInventory)return!1;if(h.size===0)return mS(ae())===`nothing-created`||(x.set(`instance`,{item:`instance`,reason:`The requested attempt has not been found; creation remains unproven.`,next:`Run retire again to repeat every recorded token and run-tag lookup.`}),!1);if(Array.from(h.values()).some(e=>e.proof===`unproven`))return!1;let u=yield*c;return u.stop||u.ok&&!u.needsInventory&&mS(ae())===`released`}).pipe(Bl({until:e=>e,schedule:dx}),bl({duration:yield*ux(s),orElse:()=>k(!1)}),ol);if(Vr(fe)?x.set(`retirement`,{item:`retirement`,reason:fe.failure.message,next:`Resolve this failure and run retire again; preserve the record.`}):fe.success||x.set(`deadline`,{item:`deadline`,reason:`The retirement deadline of ${Ai(e.within)} ms expired before all proofs completed.`,next:`Run retire again; keep the keys until every proof succeeds.`}),(Vr(fe)||!fe.success)&&m.expire(),Vr(fe)||!fe.success)for(let[e,t]of C){let n=te.get(e);n&&te.set(e,{...n,reason:sb(t)})}let T=S(),pe=T.unproven.length===0?mS(T):`unproven`,me=[],E=pe!==`unproven`;if(E)for(let e of[`id_ed25519`,`id_ed25519.pub`]){let t=d(n,e),r=yield*i.remove(t).pipe(ol);Hr(r)?me.push(e):r.failure.reason._tag!==`NotFound`&&(E=!1,x.set(e,{item:e,reason:r.failure.message,next:`Resolve local file access and run retire again.`}));let a=yield*i.lstat(t).pipe(ol);(Hr(a)||a.failure.reason._tag!==`NotFound`)&&(E=!1,x.set(e,{item:e,reason:Hr(a)?`The key file is still present.`:a.failure.message,next:`Resolve local file access and run retire again.`}))}let he=E?pe:`unproven`;return he===`released`&&(yield*Hx(n,{...r,phase:`retired`})),yield*yS(n,{...S(),status:he,ended:he===`nothing-created`?`not-created`:ie(),localFiles:{removed:me,absent:E},endedAt:yield*xS})}),CS={version:`0.2.0`,commit:`3e82f8538f896372e1d4d6f005ed8c9b60fa0b77`},wS=Ule.check(Rm(e=>Si(e)&&Ai(e)>0,{message:`Use a positive finite duration, such as '20 minutes'.`})),q_e=wS.check(Rm(e=>Ai(e)<=Ai(tne(24)),{message:`--need must be at most 24 hours.`})),TS=Gm.check(zm(/^[^\r\n\0]+$/)),J_e=qpe({present:e=>Zc(function*(){let t=yield*uv;e._tag===`InvalidInvocation`?(yield*Sg(t.formatHelpDoc(e.helpDoc)),yield*Sg(t.formatErrors(e.errors))):e._tag===`Help`&&e.reason===`Implicit`?yield*Sg(t.formatHelpDoc(e.helpDoc)):yield*dv.present(e)})}),Y_e=N(function*(e,t){let n=yield*wg(0),r=Xy(`create`,{directory:ty(`dir`).pipe(ly(TS),ay(`Private directory for this run's durable record and access files.`)),profile:ty(`profile`).pipe(ly(TS),ay(`AWS profile alias; required.`)),region:ty(`region`).pipe(ly(TS),sy,ay(`Region for a new run; defaults to us-west-2. Resumed runs use their record.`)),run:ty(`run`).pipe(ly(vx),ay(`Unique run name, at most 48 lowercase letters, digits and hyphens.`)),owner:ty(`owner`).pipe(ly(Xb),ay(`Handle responsible for this run.`)),os:Mme(`os`,[`windows`]).pipe(ay(`Guest operating system; Windows is implemented.`)),instanceType:ty(`type`).pipe(ly(TS),ay(`EC2 instance type; for example m7i.large.`)),need:ty(`need`).pipe(ly(q_e),ay(`Lifetime, such as '4 hours'; at most 24 hours.`)),rootGiB:jme(`root-gib`).pipe(cy(100),ly(Hm.check(Rm(e=>e>0))),ay(`Encrypted gp3 root volume size; defaults to 100 GiB.`)),imageId:ty(`image`).pipe(ly(Xb),sy,ay(`Explicit Amazon AMI; otherwise select Server 2025 Full Base aged at least three days.`)),within:ty(`within`).pipe(cy(`20 minutes`),ly(wS),ay(`One deadline for all create work; defaults to '20 minutes'.`))},N(function*(e){if(fb(e.profile)!==e.profile)return yield*new ub({message:`Use a profile whose name has no account ID (an alias in ~/.aws/config).`});yield*Wc([[`directory`,e.directory],[`owner`,e.owner],[`instance type`,e.instanceType],[`root size`,String(e.rootGiB)]],([e,t])=>pb(e,t));let r=p(e.directory);yield*pb(`directory`,r);let a=yield*Bx(r).pipe(hl(()=>new ub({message:`Cannot read a valid record.json from --dir.`}))),o=or(e.region,()=>a?.region??`us-west-2`);if(yield*pb(`region`,o),a!==void 0&&(a.run!==e.run||a.region!==o))return yield*new ub({message:`The record belongs to another run or region.`});let s=yield*cx(e.within),c=yield*Zc(function*(){yield*Rx(r);let n=a?.helper??CS??{version:`0.0.0`,commit:yield*M_e(r,t,s)};return yield*j_e({directory:r,profile:e.profile,region:o,run:e.run,owner:e.owner,instanceType:e.instanceType,rootGiB:e.rootGiB,need:e.need,within:e.within,helper:n,environment:t,...ir(e.imageId)?{imageId:e.imageId.value}:{}},s).pipe(El(_x({profile:e.profile,region:o,environment:t,temporaryDirectory:t.TMPDIR??i(),within:(yield*lx(s)).within,...a?.phase===`reachable`?{}:{evidenceDirectory:r}})))}).pipe(ol);if(Hr(c))return yield*Cg(fx(yield*Sx(c.success)));{let e=c.failure;if(e._tag===`UsageError`)return yield*e;yield*Sg(e.message);let t=yield*Bx(r);return t===void 0?yield*Sg(`Nothing was requested; no record was written.`):yield*Cg(fx(yield*Sx(t))),yield*Eg(n,e._tag===`AccountCheckFailed`?3:e._tag===`LifecycleError`?e.exitCode:1)}})).pipe(Zy(`Create or resume one Windows EC2 instance, arm its end and verify SSH access. Prints the record.`)),a=Xy(`reach`,{directory:ty(`dir`).pipe(ly(TS),ay(`Private run directory containing the record and SSH key.`)),profile:ty(`profile`).pipe(ly(TS),ay(`AWS profile alias; the exact recorded group verifies the account.`))},N(function*({directory:e,profile:r}){if(fb(r)!==r)return yield*new ub({message:`Use a profile whose name has no account ID (an alias in ~/.aws/config).`});let a=p(e);yield*pb(`directory`,a);let o=yield*Bx(a).pipe(hl(()=>new ub({message:`Cannot read a valid record.json from --dir.`})));if(o===void 0)return yield*new ub({message:`reach requires record.json from create.`});yield*vm(TS)(o.region).pipe(hl(()=>new ub({message:`The recorded region is invalid.`}))),yield*pb(`region`,o.region);let s=yield*cx(ki(20)),c=yield*P_e(a,o,{profile:r,environment:t},s).pipe(El(_x({profile:r,region:o.region,environment:t,temporaryDirectory:t.TMPDIR??i(),within:(yield*lx(s)).within,evidenceDirectory:a})),ol);if(Hr(c))return yield*Cg(fx(yield*Sx(c.success)));{let e=c.failure;return e._tag===`UsageError`?yield*e:(yield*Sg(e.message),yield*Cg(fx(yield*Sx(o))),yield*Eg(n,e._tag===`AccountCheckFailed`?3:1))}})).pipe(Zy(`Recheck the end and pinned host key, rebuild access files, and verify one SSH command. Uses the record's region.`)),o=Xy(`extend`,{directory:ty(`dir`).pipe(ly(TS),ay(`Private run directory containing record.json.`)),profile:ty(`profile`).pipe(ly(TS),ay(`AWS profile for the recorded account and region.`)),to:ty(`to`).pipe(ly(yx),ay(`New UTC end, YYYY-MM-DDTHH:mm:ssZ.`))},N(function*({directory:e,profile:r,to:a}){if(fb(r)!==r)return yield*new ub({message:`Use a profile whose name has no account ID (an alias in ~/.aws/config).`});let o=p(e);yield*pb(`directory`,o);let s=yield*zx(o).pipe(hl(()=>new ub({message:`Extend requires a valid record.json from create.`})));yield*pb(`region`,s.region),yield*Rx(o);let c=yield*cx(ki(15)),l=yield*N_e({directory:o,record:s,to:a,deadline:c}).pipe(El(_x({profile:r,region:s.region,environment:t,evidenceDirectory:o,temporaryDirectory:t.TMPDIR??i(),within:(yield*lx(c)).within,retryDeadline:c})),ol);if(Vr(l)){let e=l.failure;yield*Sg(e.message),yield*Eg(n,e._tag===`LifecycleError`?e.exitCode:e._tag===`AccountCheckFailed`?3:1)}return yield*Cg(fx(yield*Sx(yield*zx(o))))})).pipe(Zy(`Move and verify the guest shutdown task, then update and verify the recorded instance and volume end tags.`)),s=Xy(`retire`,{directory:ty(`dir`).pipe(ly(Gm),ay(`Private run directory containing record.json; the receipt is written here.`)),profile:ty(`profile`).pipe(ly(Gm),ay(`AWS profile for the recorded account and region.`)),within:ty(`within`).pipe(cy(`15 minutes`),ly(wS),ay(`Bound all retirement reads and waits with one deadline.`))},N(function*({directory:e,profile:r,within:a}){fb(r)!==r&&(yield*new ub({message:`Use a profile whose name has no account ID (an alias in ~/.aws/config).`}));let o=p(e);yield*pb(`directory`,o);let s=yield*zx(o).pipe(hl(()=>new ub({message:`Retire requires a valid record.json. Read-only recovery: aws ec2 describe-instances --profile <profile> --region <region> --filters Name=tag:ot-run,Values=<run>; repeat with Name=client-token,Values=<run>-instance.`})));yield*pb(`region`,s.region),yield*Rx(o),yield*vS(o,s);let c=yield*jl(Zc(function*(){yield*Vx(o);let e=yield*zx(o);return e.run!==s.run||e.region!==s.region?yield*new ub({message:`The run identity changed during retirement preflight.`}):yield*G_e({directory:o,record:e,within:a})})).pipe(El(_x({readRetryOwner:`verb`,profile:r,region:s.region,environment:t,evidenceDirectory:o,temporaryDirectory:t.TMPDIR??i()})),ol);if(Vr(c)){let e=c.failure;yield*Sg(e.message),yield*Eg(n,e._tag===`AccountCheckFailed`?3:1)}else yield*Cg(fx(yield*_S(c.success))),yield*Eg(n,+(c.success.status===`unproven`))})).pipe(Zy(`End this run and prove every recorded resource gone before removing local keys. Prints the persisted release receipt; incomplete proof exits 1.`)),c=Xy(`status`,{directory:ty(`dir`).pipe(ly(Gm),ay(`Private run directory containing record.json. It is read without modification.`)),profile:ty(`profile`).pipe(ly(Gm),ay(`AWS CLI profile to use. Required; the recorded group ID verifies the account.`))},N(function*({directory:e,profile:r}){fb(r)!==r&&(yield*new ub({message:`Use a profile whose name has no account ID (an alias in ~/.aws/config).`}));let a=yield*(yield*gg).readFileString(d(p(e),`record.json`)).pipe(hl(()=>new ub({message:`Cannot read record.json from --dir.`}))),o=yield*vm(qm(xx),{onExcessProperty:`error`})(a).pipe(hl(()=>new ub({message:`record.json must match openteammate.ec2-instance/record@1; unknown fields are refused; identity fields must not contain an account-shaped twelve-digit number.`}))),s=yield*cx(Ax),c=yield*__e(o,s).pipe(El(_x({within:Ax,profile:r,region:o.region,environment:t,temporaryDirectory:t.TMPDIR??i()})),ol);if(Vr(c)){let e=c.failure;e._tag===`UsageError`&&(yield*e);let t=e._tag===`AccountCheckFailed`?{operation:e.operation,kind:e.kind,code:e._tag,message:e.message}:e._tag===`StatusReadFailed`?{operation:e.operation,kind:`selection`,code:e._tag,message:e.message}:ob(e),r=t.message,i=yield*Nx({...o,now:{...t,outcome:`failed`,at:od(yield*id),message:r}});yield*Cg(fx(i)),yield*Sg(r),yield*Eg(n,e._tag===`AccountCheckFailed`?3:1)}else yield*Cg(fx(yield*Nx(c.success))),yield*Eg(n,c.success.now.problems.length===0?0:1)})).pipe(Zy(`Read the instance state, end, time left, Session Manager ping and last recorded end move. Prints one JSON line. No AWS resources are changed.`),vhe([{command:`ec2 status --dir ./run --profile team`,description:`Inspect a run in the region stored in its record.`}])),l=Xy(`ec2`).pipe(Zy(`EC2 instance helper. Exits: 0 promise verified; 1 incomplete or unproven; 2 invalid usage or record; 3 blocked before a cloud change; 130 interrupted.`),_he([r,a,c,o,s]));return yield*Qy(l,{version:CS?.version??`0.0.0`})(e).pipe(El(J_e),dl(`ShowHelp`,()=>Eg(n,2)),dl(`UsageError`,e=>Sg(e.message).pipe(il(Eg(n,2))))),yield*Tg(n)}),X_e=N(function*(e,t){yield*qc(n_e);let n=Lx(`ec2`);return n===void 0?yield*Y_e(e,t):yield*Sg(n).pipe(cl(1))}),Z_e=Nde(({fiber:e,teardown:t})=>{let n=!1;e.addObserver(e=>{process.removeListener(`SIGINT`,r),process.removeListener(`SIGTERM`,r),t(e,e=>{(n||e!==0)&&process.exit(e)})});function r(){n=!0,e.interruptUnsafe(e.id)}process.on(`SIGINT`,r),process.on(`SIGTERM`,r)}),Q_e=(e,t,n)=>{let r=e.detached??n!==`win32`;return{...t,detached:r,shell:e.shell,windowsHide:e.windowsHide??!r}},ES=(e,t)=>(n,[r])=>{let i=`Unknown`;switch(n.code){case`ENOENT`:i=`NotFound`;break;case`EACCES`:case`EPERM`:i=`PermissionDenied`;break;case`EEXIST`:i=`AlreadyExists`;break;case`EISDIR`:i=`BadResource`;break;case`ENOTDIR`:i=`BadResource`;break;case`EBUSY`:i=`Busy`;break;case`ELOOP`:i=`BadResource`}return Uh({_tag:i,module:e,method:t,pathOrDescriptor:r,syscall:n.syscall,cause:n})},DS=(e,t,n)=>{if(!(`closed`in e)){t(),n?.();return}let r=()=>{clearImmediate(a),e.off(`error`,r),e.off(`close`,r),n?.()},i=()=>{e.closed?r():(a=setImmediate(i),n||a.unref())},a=setImmediate(i);n||a.unref(),e.once(`error`,r),e.once(`close`,r),t(),e.closed||e.destroy()},OS=e=>Yh(lue($_e(e),e=>[e])),$_e=e=>ch(t=>{let n=e.evaluate(),r=tve({...e,writable:n,pull:t});return k(e.endOnDone===!1?r:Fl(r,e=>Tc(e)?Jc:eve(n)))}),eve=e=>Yc(t=>{let n=()=>t(Jc);if(e.closed){let t=ae(e,{readable:!1},()=>{t(),n()})}else DS(e,Ie,n)}),tve=e=>nl(t=>{let n=t.currentDispatcher,r=Os(),i=Os(),a=t=>Is(i,Tae(()=>e.onError(t))),o=!1,s=e=>{o=!0,a(e)};e.writable.on(`error`,s);let c=ae(e.writable,{readable:!1},e=>{e?a(e):Is(r,Jc)});return e.pull.pipe(j(t=>{let r=0;return Yc(i=>{let o=!1,s=()=>n.scheduleTask(c,0),c=()=>{for(e.writable.off(`drain`,c),e.writable.off(`finish`,s);r<t.length;){if(o)return;if(!e.writable.write(t[r++],e.encoding,t=>{t&&(e.writable.closed?a(t):n.scheduleTask(()=>a(t),0))})){o||(e.writable.once(`drain`,c),e.writable.once(`finish`,s));return}}o||i(Jc)};return c(),qc(()=>{o=!0,e.writable.off(`drain`,c),e.writable.off(`finish`,s)})})}),zl({disableYield:!0}),e.endOnDone===!1?Me:wc(t=>(e.writable.end(),il(As(r),xs(t)))),Sl(As(i)),Pl(qc(()=>{c();let t=()=>{e.writable.off(`error`,s),e.writable.off(`error`,t),e.writable.off(`close`,t)};e.writable.errored&&!e.writable.closed&&!o?(e.writable.once(`error`,t),e.writable.once(`close`,t)):t()})))}),kS=e=>ig(nve(e)),nve=e=>ch((t,n)=>rve({scope:n,readable:e.evaluate(),onError:e.onError??ive,chunkSize:e.chunkSize,readSize:e.readSize,closeOnDone:e.closeOnDone})),rve=e=>{let t=e.readable,n=e.chunkSize??4096,r=e.closeOnDone??!0,i=e.exit??ah(void 0),a=e.latch??Yle(!1);function o(){a.openUnsafe()}t.on(`readable`,o);let s=ae(t,{readable:!0,writable:!1},t=>{i.current??=ws(t?e.onError(t):bs()),a.openUnsafe()}),c=Kc(function r(){let o=e.readable.read(e.readSize);if(o===null)return i.current?i.current:t.readableEnded?A(bs()):(a.closeUnsafe(),j(a.await,r));let s=Xr(o);for(;s.length<n&&(o=e.readable.read(e.readSize),o!==null);)s.push(o);return k(s)});return cl(Vs(e.scope,qc(()=>{t.off(`readable`,o),r?DS(t,s):s()})),c)},ive=e=>new Iie(e),AS=e=>e instanceof globalThis.Error?e:new globalThis.Error(String(e)),jS=(e,t,n)=>{let{commands:r}=BS(n),i=globalThis.process.platform===`win32`?`windows`:`posix`,a=r.map(e=>Yhe([e.command,...e.args],{format:i})).join(` | `);return ES(`ChildProcess`,e)(t,[a])},MS=e=>ld(e)?dd(e):e,ave=e=>{if(e.command.includes(`\0`))return`The command contains a NUL character`;let t=e.args.findIndex(e=>MS(e).includes(`\0`));if(t!==-1)return`Argument ${t+1} contains a NUL character`;for(let[t,n]of Object.entries(e.options.env??{}))if(n!==void 0&&MS(n).includes(`\0`))return`The environment variable ${t} contains a NUL character`},NS=1e3,PS=e=>{let t=()=>{};e.on(`error`,t),e.once(`close`,()=>e.off(`error`,t))},FS=e=>e.exitCode!==null||e.signalCode!==null,IS=(e,t)=>e.options.detached!==!1||!FS(t),LS=e=>e?.code===`EPERM`,RS=(e,t)=>{if(!FS(t))return!0;if(globalThis.process.platform===`win32`||!IS(e,t))return!1;try{return globalThis.process.kill(-t.pid,0),!0}catch(e){return LS(e)}},zS=(e,t=()=>{})=>{if(FS(e)){t(null);return}ee.execFile(`taskkill`,[`/pid`,String(e.pid),`/T`,`/F`],{windowsHide:!0},t)},ove=tc(Eb,Zc(function*(){let e=yield*gg,t=yield*bg,n=N(function*(n){if(!Xe(n.cwd))return yield*e.access(n.cwd),t.resolve(n.cwd)}),r=e=>{if(e.env===void 0)return;let t=e.extendEnv===!0?{...globalThis.process.env}:{};for(let[n,r]of Object.entries(e.env))r===void 0?delete t[n]:t[n]=MS(r);return t},i=e=>rg(e)?`pipe`:e,a=e=>Jh(e)?`pipe`:e,o=e=>{let t={stream:`pipe`,encoding:`utf-8`,endOnDone:!0};return Xe(e.stdin)?t:typeof e.stdin==`string`||rg(e.stdin)?{...t,stream:e.stdin}:{stream:e.stdin.stream,encoding:e.stdin.encoding??t.encoding,endOnDone:e.stdin.endOnDone??t.endOnDone}},s=(e,t)=>{let n=e[t];return Xe(n)?{stream:`pipe`}:typeof n==`string`||Jh(n)?{stream:n}:{stream:n.stream}},c=e=>{if(Xe(e.additionalFds))return[];let t=[];for(let[n,r]of Object.entries(e.additionalFds)){let e=Pb(n);Ze(e)&&t.push({fd:e,config:r})}return t.sort((e,t)=>e.fd-t.fd)},l=(e,t,n,r)=>{let o=[i(e.stream),a(t.stream),a(n.stream)];if(r.length===0)return o;let s=r.reduce((e,{fd:t})=>Math.max(e,t),2);for(let e=3;e<=s;e++)o[e]=`ignore`;for(let{fd:e}of r)o[e]=`pipe`;return o},u=(e,t,n)=>Hl(fg(xde(e,e=>Ms(n,e)),t)),d=N(function*(e,t,n,r){if(n.length===0)return{getInputFd:()=>Zh,getOutputFd:()=>sg};let i=new Map,a=new Map,o=(t,n,a)=>Kc(()=>{let o=Zh;return n&&`write`in n&&(PS(n),o=OS({evaluate:()=>n,onError:n=>jS(`fromWritable(fd${t})`,AS(n),e)})),a?M(u(a,o,r),()=>{i.set(t,o)}):(i.set(t,o),Jc)}),s=(t,n,r)=>{let i=sg;if(n&&`read`in n){let r=new ie,a;r.on(`error`,e=>{a??=e}),n.on(`error`,e=>r.destroy(e)),n.pipe(r);let o=n=>jS(`fromReadable(fd${t})`,AS(n),e);i=ude(()=>a===void 0?kS({evaluate:()=>r,onError:o}):fde(o(a)))}r&&(i=ug(i,r)),a.set(t,i)};for(let{config:e,fd:r}of n){let n=t.stdio[r];switch(e.type){case`input`:yield*o(r,n,e.stream);break;case`output`:s(r,n,e.sink);break;case`duplex`:n&&`allowHalfOpen`in n&&(n.allowHalfOpen=!0),s(r,n,e.sink),yield*o(r,n,e.stream)}}return{getInputFd:e=>i.get(e)??Zh,getOutputFd:e=>a.get(e)??sg}}),f=(e,t,n,r)=>Kc(()=>{let i=Zh;return Qe(t.stdin)&&(PS(t.stdin),i=OS({evaluate:()=>t.stdin,onError:t=>jS(`fromWritable(stdin)`,AS(t),e),endOnDone:n.endOnDone,encoding:n.encoding})),rg(n.stream)?cl(u(n.stream,i,r),i):k(i)}),p=(e,t,n,r)=>{let i=t.stdout?(()=>{let n=new ie;return t.stdout.on(`error`,e=>n.destroy(e)),t.stdout.pipe(n),kS({evaluate:()=>n,onError:t=>jS(`fromReadable(stdout)`,AS(t),e)})})():sg,a=t.stderr?(()=>{let n=new ie;return t.stderr.on(`error`,e=>n.destroy(e)),t.stderr.pipe(n),kS({evaluate:()=>n,onError:t=>jS(`fromReadable(stderr)`,AS(t),e)})})():sg;Jh(n.stream)&&(i=ug(i,n.stream)),Jh(r.stream)&&(a=ug(a,r.stream));let o=vde(i,a);return{stdout:i,stderr:a,all:o}},m=(e,t)=>Yc(n=>{let r=Os(),i=ee.spawn(e.command,e.args.map(MS),t);return i.on(`error`,t=>{e.args.some(ld)&&Object.assign(t,{spawnargs:[e.command,...e.args.map(e=>ld(e)?`<redacted>`:e)]}),n(A(jS(`spawn`,t,e)))}),i.on(`exit`,(...e)=>{Is(r,Ss(e))}),i.on(`spawn`,()=>{n(k([i,r]))}),qc(()=>{i.kill(`SIGTERM`)})}),h=(e,t,n)=>globalThis.process.platform===`win32`?Yc(n=>{zS(t,t=>{n(t?A(jS(`kill`,AS(t),e)):Jc)})}):tl({try:()=>{globalThis.process.kill(-t.pid,n)},catch:t=>jS(`kill`,AS(t),e)}),g=(e,t)=>{if(globalThis.process.platform===`win32`){zS(e);return}try{globalThis.process.kill(-e.pid,t)}catch{}},_=(e,t,n)=>Kc(()=>{if(!t.kill(n)){let t=new globalThis.Error(`Failed to kill child process`);return A(jS(`kill`,t,e))}return Jc}),v=(e,t,n)=>Yc(r=>{let i=Date.now()+n,a,o=()=>{clearTimeout(a),t.removeListener(`exit`,s)},s=()=>{if(clearTimeout(a),Date.now()>=i||!RS(e,t)){o(),r(Jc);return}a=setTimeout(s,10)};return t.on(`exit`,s),s(),qc(o)}),y=N(function*(e,t,n,r){let i=n=>IS(e,t)?h(e,t,n).pipe(ul(r=>FS(t)&&LS(r.cause)?Jc:_(e,t,n))):_(e,t,n);yield*i(r?.killSignal??`SIGTERM`),Xe(r?.forceKillAfter)?(yield*As(n),yield*v(e,t,NS)):(yield*v(e,t,Ai(r.forceKillAfter)),RS(e,t)&&(yield*i(`SIGKILL`),yield*v(e,t,NS))),yield*As(n)}),b=(e,t)=>{let n=t??`stdout`;switch(n){case`stdout`:return e.stdout;case`stderr`:return e.stderr;case`all`:return e.all;default:{let t=Pb(n);return Ze(t)?e.getOutputFd(t):e.stdout}}},x=N(function*(e){switch(e._tag){case`StandardCommand`:{if(e.options.shell!==void 0&&e.options.shell!==!1&&e.args.length>0)return yield*A(Wh({module:`ChildProcess`,method:`spawn`,description:`The shell option cannot be combined with arguments; pass the whole script as the command`}));let t=ave(e);if(t!==void 0)return yield*A(Wh({module:`ChildProcess`,method:`spawn`,description:t}));let i=o(e.options),a=s(e.options,`stdout`),u=s(e.options,`stderr`),h=c(e.options),_=!0,v=yield*n(e.options),b=r(e.options),ee=l(i,a,u,h),x=N(function*(t,n){if(yield*Ns(n)){let[r]=yield*As(n);(r!==0&&Qe(r)||_&&process.platform!==`win32`&&e.options.detached!==!1)&&(yield*yl(y(e,t,n,e.options)));return}_&&(yield*yl(y(e,t,n,e.options)))}),te=Rs(),[ne,re]=yield*Ml(m(e,Q_e(e.options,{cwd:v,env:b,stdio:ee},process.platform)),([e,t],n)=>Uc([Ws(te,n),x(e,t)],{concurrency:`unbounded`,discard:!0})),ie=Khe(ne.pid);e.options.detached!==!1&&ne.on(`exit`,t=>{t!==0&&Qe(t)&&g(ne,e.options.killSignal??`SIGTERM`)});let ae=qc(()=>{_||=(ne.ref(),!0)}),S=qc(()=>(_&&=(ne.unref(),!1),ae)),oe=Os(),C=yield*zs(te)(f(e,ne,i,oe)),{all:se,stderr:ce,stdout:le}=p(e,ne,a,u),{getInputFd:ue,getOutputFd:w}=yield*zs(te)(d(e,ne,h,oe)),de=M(Ns(re),e=>!e),fe=j(Sl(As(re),As(oe)),([t,n])=>{if(Ps(oe))return As(oe);if(Qe(t))return k(Ghe(t));let r=new globalThis.Error(`Process interrupted due to receipt of signal: '${n}'`);return A(jS(`exitCode`,r,e))});return Tb({pid:ie,exitCode:fe,isRunning:de,kill:t=>y(e,ne,re,t),stdin:C,stdout:le,stderr:ce,all:se,getInputFd:ue,getOutputFd:w,unref:S})}case`PipedCommand`:{let{commands:t,pipeOptions:n}=BS(e),[r,...i]=t,a=[yield*x(r)];for(let e=0;e<i.length;e++){let t=i[e],r=n[e]??{},s=o(t.options),c=lg(k(b(a[a.length-1],r.from))),l=r.to??`stdin`;if(l===`stdin`)a.push(yield*x(Mb(t.command,t.args,{...t.options,stdin:{...s,stream:c}})));else{let e=Pb(l);if(Ze(e)){let n=gge(e),r=t.options.additionalFds??{},i=r[n],o=i?.type===`duplex`?{...i,stream:c}:{type:`input`,stream:c};a.push(yield*x(Mb(t.command,t.args,{...t.options,additionalFds:{...r,[n]:o}})))}else a.push(yield*x(Mb(t.command,t.args,{...t.options,stdin:{...s,stream:c}})))}}let s=a[a.length-1],c=e=>Wc([...a].reverse(),t=>yl(t.kill(e)),{discard:!0}),l=Zc(function*(){let e=[];for(let t of a)e.push(yield*t.unref);return Wc([...e].reverse(),e=>e,{discard:!0})});return Tb({pid:s.pid,exitCode:s.exitCode,isRunning:s.isRunning,kill:c,stdin:a[0].stdin,stdout:s.stdout,stderr:s.stderr,all:s.all,getInputFd:s.getInputFd,getOutputFd:s.getOutputFd,unref:l})}}});return Jhe(x)})),BS=e=>{let t=[],n=[],r=e=>{switch(e._tag){case`StandardCommand`:t.push(e);break;case`PipedCommand`:r(e.left),n.push(e.options),r(e.right)}};if(r(e),t.length===0)throw Error(`flattenCommand produced empty commands array`);let[i,...a]=t;return{commands:[i,...a],pipeOptions:n}},VS=e=>t=>Wh({module:`FileSystem`,method:e,description:t.message??String(t)}),HS=(e,t)=>{let n=Number(e);if(!Number.isSafeInteger(n))throw RangeError(`${t} exceeds the safe integer range: ${e}`);return n},US=e=>dr(sr(e),boe),WS=e=>BigInt.asUintN(64,e),GS=e=>Cte(sr(e),WS),KS=(e,t)=>tl({try:()=>HS(e,`position`),catch:VS(t)}),sve=(()=>{let e=Kl(S.access,ES(`FileSystem`,`access`),VS(`access`));return(t,n)=>{let r=S.constants.F_OK;return n?.readable&&(r|=S.constants.R_OK),n?.writable&&(r|=S.constants.W_OK),e(t,r)}})(),cve=(()=>{let e=Kl(S.cp,ES(`FileSystem`,`copy`),VS(`copy`));return(t,n,r)=>e(t,n,{force:r?.overwrite??!1,preserveTimestamps:r?.preserveTimestamps??!1,recursive:!0})})(),lve=(()=>{let e=Kl(S.copyFile,ES(`FileSystem`,`copyFile`),VS(`copyFile`));return(t,n)=>e(t,n)})(),uve=(()=>{let e=Kl(S.chmod,ES(`FileSystem`,`chmod`),VS(`chmod`));return(t,n)=>e(t,n)})(),dve=(()=>{let e=Kl(S.chown,ES(`FileSystem`,`chown`),VS(`chown`));return(t,n,r)=>e(t,n,r)})(),fve=(()=>{let e=Kl(S.link,ES(`FileSystem`,`link`),VS(`link`));return(t,n)=>e(t,n)})(),pve=(()=>{let e=Kl(S.mkdir,ES(`FileSystem`,`makeDirectory`),VS(`makeDirectory`));return(t,n)=>e(t,{recursive:n?.recursive??!1,mode:n?.mode})})(),qS=e=>{let n=Kl(S.mkdtemp,ES(`FileSystem`,e),VS(e));return e=>Kc(()=>{let r=e?.prefix??``,i=typeof e?.directory==`string`?a.join(e.directory,`.`):t.tmpdir();return n(r?a.join(i,r):i+`/`)})},mve=qS(`makeTempDirectory`),JS=e=>{let t=Kl(S.rm,ES(`FileSystem`,e),VS(e));return(e,n)=>t(e,{recursive:n?.recursive??!1,force:n?.force??!1})},hve=JS(`remove`),gve=(()=>{let e=qS(`makeTempDirectoryScoped`),t=JS(`makeTempDirectoryScoped`);return n=>Ml(e(n),e=>gl(t(e,{recursive:!0,force:!0})))})(),_ve=e=>{let{O_APPEND:t,O_CREAT:n,O_EXCL:r,O_RDONLY:i,O_RDWR:a,O_TRUNC:o,O_WRONLY:s}=S.constants;switch(e){case`r`:return i;case`r+`:return a;case`w`:return o|n|s;case`wx`:return o|n|s|r;case`w+`:return o|n|a;case`wx+`:return o|n|a|r;case`a`:return t|n|s;case`ax`:return t|n|s|r;case`a+`:return t|n|a;case`ax+`:return t|n|a|r}},vve=(e,t)=>Kc(()=>{let{O_NOFOLLOW:n}=S.constants;return process.platform===`win32`||typeof n!=`number`||n===0?A(Wh({module:`FileSystem`,method:e,description:`noFollow is not supported on this platform`})):k(_ve(t)|n)}),yve=(e=>{let t=Kl(S.open,ES(`FileSystem`,e),VS(e)),n=Kl(S.close,ES(`FileSystem`,e),VS(e));return(r,i)=>Le(Ml(i?.noFollow===!0?j(vve(e,i.flag??`r`),e=>t(r,e,i.mode)):t(r,i?.flag??`r`,i?.mode),e=>gl(n(e))),M(e=>bve(e,i?.flag?.startsWith(`a`)??!1)))})(`open`),YS=e=>Wh({module:`FileSystem`,method:e,description:`Cannot read before the start of the file`}),bve=(()=>{let e=e=>Kl(S.read,ES(`FileSystem`,e),VS(e)),t=e(`read`),n=e(`readAlloc`),r=Kl(S.fstat,ES(`FileSystem`,`stat`),VS(`stat`)),i=Kl(S.ftruncate,ES(`FileSystem`,`truncate`),VS(`truncate`)),a=Kl(S.fsync,ES(`FileSystem`,`sync`),VS(`sync`)),o=e=>{let t=Kl(S.write,ES(`FileSystem`,e),VS(e));return(e,n,r)=>t(e,n,0,n.length,r)},s=o(`write`),c=o(`writeAll`);class l{[_g];fd;append;position=BigInt(0);constructor(e,t){this[_g]=_g,this.fd=e,this.append=t}get stat(){return j(r(this.fd,{bigint:!0}),QS)}get sync(){return a(this.fd)}seek(e,t){return Kc(()=>{let n=t===`start`?e:this.position+e;return n<BigInt(0)?A(Wh({module:`FileSystem`,method:`seek`,description:`Cannot seek before the start of the file`})):(this.position=n,k(n))})}read(e,n){return Kc(()=>{let r=n?.position;if(r!==void 0)return r<BigInt(0)?A(YS(`read`)):t(this.fd,{buffer:e,position:r});let i=this.position;return M(t(this.fd,{buffer:e,position:i}),e=>(this.position=i+BigInt(e),e))})}readAlloc(e,t){return Kc(()=>{try{if(!Number.isInteger(e)||e<0)throw RangeError(`size must be a non-negative integer`);let r=t?.position;if(r!==void 0&&r<BigInt(0))return A(YS(`readAlloc`));let i=Buffer.allocUnsafeSlow(e),a=r??this.position;return M(n(this.fd,{buffer:i,position:a}),t=>{if(t===0)return O();if(r===void 0&&(this.position=a+BigInt(t)),t===e)return nr(i);let n=Buffer.allocUnsafeSlow(t);return i.copy(n,0,0,t),nr(n)})}catch(e){return A(VS(`readAlloc`)(e))}})}truncate(e){return M(i(this.fd,e||void 0),()=>{if(!this.append){let t=BigInt(e??0);this.position>t&&(this.position=t)}})}write(e){return Kc(()=>{let t=this.position;return j(this.append?k(void 0):KS(t,`write`),n=>M(s(this.fd,e,n),e=>(this.append||(this.position=t+BigInt(e)),e)))})}writeAllChunk(e){return Kc(()=>{let t=this.position;return j(this.append?k(void 0):KS(t,`writeAll`),n=>j(c(this.fd,e,n),n=>n===0?A(Uh({module:`FileSystem`,method:`writeAll`,_tag:`WriteZero`,pathOrDescriptor:this.fd,description:`write returned 0 bytes written`})):(this.append||(this.position=t+BigInt(n)),n<e.length?this.writeAllChunk(e.subarray(n)):Jc)))})}writeAll(e){return e.length===0?Jc:this.writeAllChunk(e)}}return(e,t)=>new l(e,t)})(),XS=e=>{let t=qS(e);return N(function*(e){let n=yield*t(e),r=_.randomBytes(6).toString(`hex`),i=a.join(n,e?.suffix?`${r}${e.suffix}`:r);return yield*tC(i,new Uint8Array),i})},xve=XS(`makeTempFile`),Sve=(()=>{let e=XS(`makeTempFileScoped`),t=JS(`makeTempFileScoped`);return n=>Ml(e(n),e=>gl(t(a.dirname(e),{recursive:!0,force:!0})))})(),Cve=(e,t)=>Gc({try:()=>S.promises.readdir(e,t),catch:t=>ES(`FileSystem`,`readDirectory`)(t,[e])}),wve=e=>Gc({try:()=>S.promises.readdir(e,{withFileTypes:!0}),catch:t=>ES(`FileSystem`,`readDirectoryEntries`)(t,[e])}).pipe(M(e=>e.map(e=>({name:e.name,type:ZS(e)})))),Tve=e=>Yc((t,n)=>{try{S.readFile(e,{signal:n},(n,r)=>{t(n?A(ES(`FileSystem`,`readFile`)(n,[e])):k(r))})}catch(e){t(A(VS(`readFile`)(e)))}}),Eve=(()=>{let e=Kl(S.readlink,ES(`FileSystem`,`readLink`),VS(`readLink`));return t=>e(t)})(),Dve=(()=>{let e=Kl(process.platform===`win32`?S.realpath.native:S.realpath,ES(`FileSystem`,`realPath`),VS(`realPath`));return t=>e(t)})(),Ove=(()=>{let e=Kl(S.rename,ES(`FileSystem`,`rename`),VS(`rename`));return(t,n)=>e(t,n)})(),ZS=e=>e.isFile()?`File`:e.isDirectory()?`Directory`:e.isSymbolicLink()?`SymbolicLink`:e.isBlockDevice()?`BlockDevice`:e.isCharacterDevice()?`CharacterDevice`:e.isFIFO()?`FIFO`:e.isSocket()?`Socket`:`Unknown`,QS=(e,t=`stat`)=>tl({try:()=>({type:ZS(e),mtime:sr(e.mtime),atime:sr(e.atime),birthtime:sr(e.birthtime),dev:WS(e.dev),rdev:GS(e.rdev),ino:GS(e.ino),mode:HS(e.mode,`mode`),nlink:GS(e.nlink),uid:US(e.uid),gid:US(e.gid),size:Gu(e.size),blksize:e.blksize===void 0?O():nr(Gu(e.blksize)),blocks:sr(e.blocks)}),catch:VS(t)}),$S=(e,t)=>{let n=Kl(t,ES(`FileSystem`,e),VS(e));return t=>j(n(t,{bigint:!0}),t=>QS(t,e))},eC=$S(`stat`,S.stat),kve=$S(`lstat`,S.lstat),Ave=(()=>{let e=Kl(S.symlink,ES(`FileSystem`,`symlink`),VS(`symlink`));return(t,n)=>e(t,n)})(),jve=(()=>{let e=Kl(S.truncate,ES(`FileSystem`,`truncate`),VS(`truncate`));return(t,n)=>e(t,n)})(),Mve=(()=>{let e=Kl(S.utimes,ES(`FileSystem`,`utime`),VS(`utime`));return(t,n,r)=>e(t,n,r)})(),Nve=(e,t,n)=>lde(r=>Ml(qc(()=>{let i=t.type===`Directory`?e:a.dirname(e),o=S.watch(e,{recursive:n?.recursive??!1},(e,t)=>{if(t)switch(e){case`rename`:Ul(Nae(eC(a.resolve(i,t)),{onSuccess:e=>ou(r,{_tag:`Create`,path:t}),onFailure:e=>ou(r,{_tag:`Remove`,path:t})}));return;case`change`:su(r,{_tag:`Update`,path:t});return}});return o.on(`error`,t=>{lu(r,jie(Uh({module:`FileSystem`,_tag:`Unknown`,method:`watch`,pathOrDescriptor:e,cause:t})))}),o.on(`close`,()=>{uu(r)}),o}),e=>qc(()=>e.close())).pipe(al(()=>qc(()=>n?.onReady?.())))),Pve=(e,t,n)=>Uc([eC(t),Ol(vg)]).pipe(M(([r,i])=>bte(i,()=>e).pipe(dr(e=>e.register(t,r,n)),or(()=>Nve(t,r,n)))),lg),tC=(e,t,n)=>Yc((r,i)=>{try{S.writeFile(e,t,{signal:i,flag:n?.flag,mode:n?.mode},t=>{r(t?A(ES(`FileSystem`,`writeFile`)(t,[e])):Jc)})}catch(e){r(A(VS(`writeFile`)(e)))}}),Fve=M(Ol(vg),e=>Ede({access:sve,chmod:uve,chown:dve,copy:cve,copyFile:lve,link:fve,lstat:kve,makeDirectory:pve,makeTempDirectory:mve,makeTempDirectoryScoped:gve,makeTempFile:xve,makeTempFileScoped:Sve,open:yve,readDirectory:Cve,readDirectoryEntries:wve,readFile:Tve,readLink:Eve,realPath:Dve,remove:hve,rename:Ove,stat:eC,symlink:Ave,truncate:jve,utimes:Mve,watch(t,n){return Pve(e,t,n)},writeFile:tC})),Ive=tc(gg)(Fve),nC=e=>({fromFileUrl:t=>tl({try:()=>m.fileURLToPath(t,{windows:e}),catch:e=>new Vh({module:`Path`,method:`fromFileUrl`,cause:e})}),toFileUrl:t=>tl({try:()=>m.pathToFileURL(t,{windows:e}),catch:e=>new Vh({module:`Path`,method:`toFileUrl`,cause:e})})});({...a.posix,...nC(!1)}),{...a.win32,...nC(!0)};const Lve=$s(bg)(Dde({...a,...nC(void 0)})),Rve=$s(Ide,Lde({args:qc(()=>process.argv.slice(2)),stdinIsTerminal:qc(()=>process.stdin.isTTY===!0),stdoutIsTerminal:qc(()=>process.stdout.isTTY===!0),stderrIsTerminal:qc(()=>process.stderr.isTTY===!0),stdout:e=>OS({evaluate:()=>process.stdout,onError:e=>Uh({module:`Stdio`,method:`stdout`,_tag:`Unknown`,cause:e}),endOnDone:e?.endOnDone??!1}),stderr:e=>OS({evaluate:()=>process.stderr,onError:e=>Uh({module:`Stdio`,method:`stderr`,_tag:`Unknown`,cause:e}),endOnDone:e?.endOnDone??!1}),stdin:kS({evaluate:()=>process.stdin,onError:e=>Uh({module:`Stdio`,method:`stdin`,_tag:`Unknown`,cause:e}),closeOnDone:!1})})),zve=tc(Ng,N(function*(e=rC){let t=yield*iu(),n=!1,r=!1,i=()=>{n=!0,r||uu(t)},a,o=()=>(a===void 0&&(a=process.stdin,a.readableEnded?i():a.once(`end`,i)),a);yield*Nl(()=>qc(()=>a?.off(`end`,i)));let s=yield*tg({acquire:Ml(qc(()=>{let e=o(),n=he.createInterface({input:e,escapeCodeTimeout:50}),i=e=>su(t,e),a=()=>{r=!1,uu(t)};return r=!0,he.emitKeypressEvents(e,n),n.on(`line`,i),n.once(`close`,a),{rl:n,onClose:a,onLine:i}}),({rl:e,onClose:i,onLine:a})=>qc(()=>{r=!1,e.off(`line`,a),e.off(`close`,i),e.close(),n&&uu(t)})),idleTimeToLive:`10 millis`}),c=e=>qc(()=>{let t=o();t.isTTY&&t.setRawMode(e)}),l=yield*tg({acquire:Ml(c(!0),()=>c(!1)),idleTimeToLive:`10 millis`}),u=qc(()=>process.stdout.columns??0),d=qc(()=>process.stdout.rows??0),f=Zc(function*(){let e=process.stdout,t=yield*Xae(1),n=()=>su(t,{columns:e.columns??0,rows:e.rows??0});return yield*Nl(()=>qc(()=>{e.off(`resize`,n),uu(t)})),e.on(`resize`,n),n(),t}),p=Zc(function*(){let t=o(),r=yield*iu(),i=(t,n)=>{let i={input:cr(t),key:{name:n.name??``,ctrl:!!n.ctrl,meta:!!n.meta,shift:!!n.shift}};su(r,i),e(i)&&uu(r)},a=setInterval(()=>{},2147483647),c=()=>{clearInterval(a),uu(r)};return yield*Nl(()=>qc(()=>{clearInterval(a),t.off(`keypress`,i),t.off(`end`,c)})),t.on(`keypress`,i),n?c():(yield*ng(s),yield*ng(l),t.once(`end`,c)),r}),m=Kc(()=>$ae(t).pipe(j(ar({onNone:()=>jl(il(ng(s),pu(t))),onSome:k})),hl(()=>new Mg({}))));return zde({columns:u,rows:d,size:f,readInput:p,readLine:m,display:e=>Rae(Yc(t=>{process.stdout.write(e,e=>bee(e)?t(Jc):t(A(Wh({module:`Terminal`,method:`display`,description:`Failed to write prompt to stdout`,cause:e}))))}))})})(rC));function rC(e){let t=e.key;return t.name===`escape`||t.ctrl&&(t.name===`c`||t.name===`d`)}const Bve=Yie(ove,ac(Ive,Lve,Rve,zve)),Vve=e=>Z_e(e.pipe(El(Bve),fl(e=>Sg(Pie(e)).pipe(cl(1))),al(e=>qc(()=>{process.exitCode=e}))),{disableErrorReporting:!0}),iC=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}},aC={pipe(){return iC(this,arguments)}},oC=function(){function e(){}return e.prototype=aC,e}(),sC=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},cC=e=>e,lC=e=>()=>e,Hve=lC(!0),Uve=lC(!1),uC=lC(void 0),dC=uC;function fC(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i}}function pC(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i!==n&&t.set(i,i),i}}const Wve=[`line`,`column`,`sourceURL`,`originalLine`,`originalColumn`],mC=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;if(e instanceof Error){t.delete(`stack`);for(let n of Wve)Object.prototype.propertyIsEnumerable.call(e,n)||t.delete(n)}let n=Object.getPrototypeOf(e),r=n;for(;r!==null&&r!==Object.prototype;){let e=Reflect.ownKeys(r);for(let n=0;n<e.length;n++)t.add(e[n]);r=Object.getPrototypeOf(r)}return t.has(`constructor`)&&typeof e.constructor==`function`&&n===e.constructor.prototype&&t.delete(`constructor`),t},hC=new WeakSet,gC=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),_C=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer,vC=e=>{try{return new Uint8Array(e)}catch{return}};let yC=0;const Gve=()=>{yC++};function bC(e){return typeof e==`string`}function xC(e){return typeof e==`number`}function Kve(e){return typeof e==`boolean`}function qve(e){return typeof e==`symbol`}function Jve(e){return bC(e)||xC(e)||qve(e)}function SC(e){return typeof e==`function`}function Yve(e){return e!=null}function Xve(e){return!0}function CC(e){return typeof e==`object`&&!!e||SC(e)}const wC=sC(2,(e,t)=>CC(e)&&t in e),Zve=sC(2,(e,t)=>wC(e,`_tag`)&&e._tag===t),TC=`~effect/Hash`,EC=e=>{switch(typeof e){case`number`:return MC(e);case`bigint`:return NC(e.toString(10));case`string`:return NC(e);case`function`:case`object`:if(e===null)break;if(e instanceof Date)return Number.isNaN(e.getTime())?NC(`Invalid Date`):NC(e.toISOString());if(e instanceof RegExp)return NC(e.toString());{if(hC.has(e))return DC(e);let t=zC.get(e);if(t!==void 0)return t;if(BC.has(e))return Gve(),NC(`[Circular]`);BC.add(e);let n=yC,r;try{if(Qve(e))r=e[TC]();else if(typeof e==`function`)r=DC(e);else if(_C(e)){let t=vC(e);r=t===void 0?DC(e):IC(t)}else r=e instanceof DataView?IC(gC(e)):Array.isArray(e)||ArrayBuffer.isView(e)?IC(e):e instanceof Map?eye(e):e instanceof Set?tye(e):PC(e)}finally{BC.delete(e)}return n===yC&&zC.set(e,r),r}}return AC(OC(NC(String(e))))},DC=e=>(RC.has(e)||RC.set(e,AC(Math.random()*4294967296|0)),RC.get(e)),OC=e=>(e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^e>>>16),kC=sC(2,(e,t)=>OC(Math.imul(e,2654435761)+Math.imul(t,2246822507))),AC=e=>e&3221225471|e>>>1&1073741824,Qve=e=>wC(e,`~effect/Hash`)&&typeof e[`~effect/Hash`]==`function`,jC=new DataView(new ArrayBuffer(8)),MC=e=>{let t=e|0;return t===e?AC(t):(jC.setFloat64(0,e===e?e:NaN),AC(kC(jC.getInt32(0),jC.getInt32(4))))},NC=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return AC(t)},$ve=(e,t)=>{let n=12289;for(let r of t)n^=kC(EC(r),EC(e[r]));return AC(n)},PC=e=>$ve(e,mC(e)),FC=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return AC(r)},IC=e=>{let t=6151;for(let n of e)t=kC(t,EC(n));return AC(t)},eye=FC(NC(`Map`),([e,t])=>kC(EC(e),EC(t))),LC=NC(`Set`),tye=FC(LC,e=>kC(LC,EC(e))),RC=new WeakMap,zC=new WeakMap,BC=new WeakSet,VC=`~effect/Equal`;function HC(){return arguments.length===1?e=>UC(e,arguments[0]):UC(arguments[0],arguments[1])}function UC(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let n=typeof e;return n===typeof t?n===`number`&&e!==e&&t!==t?!0:n!==`object`&&n!==`function`||hC.has(e)||hC.has(t)?!1:nye(e,t):!1}function nye(e,t){let n=GC.length;for(let r=n;r-->0;)if(GC[r]===e&&KC[r]===t)return!0;if(n)return WC(e,t);let r=qC.get(e);r||qC.set(e,r=new WeakMap);let i=r.get(t);return i===void 0&&r.set(t,i=WC(e,t)),i}function WC(e,t){GC.push(e),KC.push(t);try{return rye(e,t)}finally{GC.pop(),KC.pop()}}const GC=[],KC=[],qC=new WeakMap;function rye(e,t){if(EC(e)!==EC(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let n=XC(e);if(n!==XC(t)||typeof e==`function`&&!n)return!1;if(n)return e[VC](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:iye(e,t);if(_C(e)){if(!_C(t)||e instanceof ArrayBuffer!=t instanceof ArrayBuffer)return!1;let n=vC(e),r=vC(t);return n!==void 0&&r!==void 0&&JC(n,r)}if(ArrayBuffer.isView(e)){let n=e instanceof DataView;return!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||n!==t instanceof DataView?!1:n?JC(gC(e),gC(t)):JC(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:YC(e,t,oye,sye):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:YC(e,t,EC,UC):aye(e,t)}function iye(e,t){for(let n=0;n<e.length;n++)if(!UC(e[n],t[n]))return!1;return!0}function JC(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function aye(e,t){let n=mC(e),r=mC(t);if(n.size!==r.size)return!1;for(let i of n)if(!r.has(i)||!UC(e[i],t[i]))return!1;return!0}function YC(e,t,n,r){let i=new Map,a=0;for(let e of t){let t=n(e),r=i.get(t);r?r.push(e):i.set(t,[e]),a++}outer:for(let t of e){let e=i.get(n(t));if(e){for(let n=0;n<e.length;n++)if(r(t,e[n])){e[n]=e[e.length-1],e.pop(),a--;continue outer}}return!1}return a===0}const oye=e=>EC(e[0]),sye=(e,t)=>UC(e[0],t[0])&&UC(e[1],t[1]),XC=e=>wC(e,`~effect/Equal`)&&typeof e[`~effect/Equal`]==`function`,ZC=Symbol.for(`~effect/Redactable`),cye=e=>wC(e,ZC);function QC(e){return cye(e)?$C(e):e}function $C(e){return e[ZC](globalThis[`~effect/Fiber/currentFiber`]?.context??lye)}const ew=`~effect/Fiber/currentFiber`,tw=new Map,lye={"~effect/Context":{},base:tw,depth:0,mapUnsafe:tw,pipe(){return iC(this,arguments)}};function nw(e,t){let n=t?.space??0,r=new WeakSet,i=n?typeof n==`number`?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,t=0){try{return l(e,t)}catch{return(typeof e==`object`&&e||typeof e==`function`)&&r.delete(e),`[inspection threw]`}}function l(e,n=0){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||e==null||typeof e==`boolean`||typeof e==`symbol`)return String(e);if(typeof e==`bigint`)return String(e)+`n`;if(typeof e==`object`||typeof e==`function`){if(r.has(e))return uye;r.add(e);let l;if(ZC in e)l=c($C(e),n);else if(Array.isArray(e))l=!i||e.length<=1?`[${e.map(e=>c(e,n)).join(`,`)}]`:`[\n${a(n+1)}${e.map(e=>c(e,n+1)).join(`,
260
+ `+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=fye(e);else if(!t?.ignoreToString&&wC(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=pye(e);l=e instanceof Error&&e.cause!==void 0?`${t} (cause: ${c(e.cause,n)})`:t}else if(Symbol.iterator in e)l=`${e.constructor.name}(${c(Array.from(e),n)})`;else{let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${rw(t)}:${c(iw(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${rw(t)}: ${c(iw(e,t),n+1)}`).join(`,
261
+ `)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}const uye=`[Circular]`;function rw(e){return typeof e==`string`?JSON.stringify(e):String(e)}function dye(e){return e.map(e=>`[${rw(e)}]`).join(``)}function fye(e){try{return e.toISOString()}catch{return`Invalid Date`}}function pye(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function iw(e,t){try{return e[t]}catch{return`[property access threw]`}}function aw(e,t){let n=[],r=new WeakMap;return JSON.stringify(e,function(e,t){let i=Object.getOwnPropertyDescriptor(r.get(this)??this,e)?.value,a=wC(i,ZC)?QC(i):QC(t);if(typeof a==`bigint`)return nw(a);if(typeof a!=`object`||!a)return a;let o=a instanceof Error&&!wC(a,`toJSON`)?{...a,name:a.name,message:a.message}:a;for(;n.length>0&&n[n.length-1]!==this;)n.pop();if(n.includes(a))return;if(n.push(a),o!==a&&n.push(o),!mye(o)||gye(o))return o;let s=hye(o);return r.set(s,o),n.push(s),s},t?.space)??`null`}function mye(e){for(let t of Object.getOwnPropertyNames(e))if(Object.getOwnPropertyDescriptor(e,t)?.get!==void 0)return!0;return!1}function hye(e){let t=Array.isArray(e)?[]:{},n=Array.isArray(e)?Array.from({length:e.length},(e,t)=>String(t)):Object.keys(e);for(let r of n)Object.defineProperty(t,r,{enumerable:!0,get:()=>{let t=Reflect.get(e,r);return Object.getOwnPropertyDescriptor(e,r)?.get===void 0?t:QC(t)}});return t}function gye(e){for(let t of[Number.prototype.valueOf,Boolean.prototype.valueOf,String.prototype.valueOf])try{return Reflect.apply(t,e,[]),!0}catch{}return!1}const ow=Symbol.for(`nodejs.util.inspect.custom`),sw=e=>{try{return e=QC(e),wC(e,`toJSON`)&&SC(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(sw):e}catch{return`[toJSON threw]`}},_ye=(e,t=2)=>{if(typeof e==`string`)return e;try{return typeof e==`object`?aw(e,{space:t}):nw(e,{space:t})}catch{return String(e)}},cw={toJSON(){return sw(this)},[ow](){return this.toJSON()},toString(){return nw(this.toJSON())}},vye=(()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),lw=()=>Error.stackTraceLimit,uw=e=>{vye&&(Error.stackTraceLimit=e)};var dw=class{constructor(e){this.value=e,this.done=!1}next(e){return this.done?(this.value=e,this):(this.done=!0,{value:this.value,done:!1})}};const fw=(()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}},r=lw();if(r===0)return n[e];uw(2);let i=t[e](()=>Error());return uw(r),i.stack?.includes(e)===!0?t[e]:n[e]})();function pw(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function yye(e,t){if(!Object.hasOwn(t,`__proto__`)){Object.assign(e,t);return}for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&pw(e,n,t[n])}const mw=`~effect/Effect`,hw=`~effect/Exit`,bye={_A:cC,_E:cC,_R:cC},gw=`${mw}/identifier`,_w=`${mw}/args`,vw=`${mw}/evaluate`,yw=`${mw}/successCont`,bw=`${mw}/failureCont`,xw=`${mw}/ensureCont`,Sw=Symbol.for(`effect/Effect/Yield`),Cw={pipe(){return iC(this,arguments)},toJSON(){return{...this}},toString(){return nw(this.toJSON(),{ignoreToString:!0,space:2})},[ow](){return this.toJSON()}},xye={[mw]:bye,...Cw,[Symbol.iterator](){return new dw(this)},toJSON(){return{_id:`Effect`,op:this[gw],..._w in this?{args:this[_w]}:void 0}}},ww=e=>wC(e,mw),Sye=e=>wC(e,hw),Tw=`~effect/Cause`,Ew=`~effect/Cause/Reason`,Dw=e=>wC(e,Tw);var Ow=class{constructor(e){this[Tw]=Tw,this.reasons=e}pipe(){return iC(this,arguments)}toJSON(){return{_id:`Cause`,reasons:this.reasons.map(e=>e.toJSON())}}toString(){return`Cause(${nw(this.reasons)})`}[ow](){return this.toJSON()}[VC](e){return Dw(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>HC(t,e.reasons[n]))}[TC](){return IC(this.reasons)}};const kw=new WeakMap;var Aw=class{[Ew];annotations;_tag;constructor(e,t,n){if(this[Ew]=Ew,this._tag=e,t!==jw&&typeof n==`object`&&n&&t.size>0){let e=kw.get(n);e&&(t=new Map([...e,...t])),kw.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);if(e.mapUnsafe.forEach((e,r)=>{t?.overwrite!==!0&&n.has(r)||n.set(r,e)}),t?.overwrite!==!0&&n.size===this.annotations.size)return this;let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return iC(this,arguments)}toString(){return nw(this)}[ow](){return this.toString()}};const jw=new Map;var Mw=class extends Aw{constructor(e,t=jw){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${nw(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[VC](e){return zw(e)&&HC(this.error,e.error)&&HC(this.annotations,e.annotations)}[TC](){return kC(NC(this._tag))(kC(EC(this.error))(EC(this.annotations)))}};const Nw=e=>new Ow(e),Cye=(e,t)=>{let n=new Map,r=[];for(let i of e.concat(t)){let e=EC(i),t=n.get(e);if(t===void 0)n.set(e,[i]);else if(t.some(e=>HC(e,i)))continue;else t.push(i);r.push(i)}return r},Pw=sC(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new Ow(Cye(e.reasons,t.reasons));return HC(e,n)?e:n}),Fw=(e,t)=>{let n=e.reasons.slice();for(let e of t.reasons)Vw(e)&&!n.some(t=>Vw(t)&&t.fiberId===e.fiberId&&t.annotations===e.annotations)&&n.push(e);return n.length===e.reasons.length?e:new Ow(n)},wye=new Ow([]),Tye=e=>new Ow([new Mw(e)]);var Iw=class extends Aw{constructor(e,t=jw){super(`Die`,t,e),this.defect=e}toString(){return`Die(${nw(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[VC](e){return Bw(e)&&HC(this.defect,e.defect)&&HC(this.annotations,e.annotations)}[TC](){return kC(NC(this._tag))(kC(EC(this.defect))(EC(this.annotations)))}};const Lw=e=>new Ow([new Iw(e)]),Rw=sC(e=>Dw(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new Ow(e.reasons.map(e=>e.annotate(t,n)))),zw=e=>e._tag===`Fail`,Bw=e=>e._tag===`Die`,Vw=e=>e._tag===`Interrupt`;function Eye(e){return Xw(`Effect.evaluate: Not implemented`)}const Hw=e=>({...xye,[gw]:e.op,[vw]:e[vw]??Eye,[yw]:e[yw],[bw]:e[bw],[xw]:e[xw]}),Uw=e=>{let t=Hw(e),n=function(e){this[_w]=e};return n.prototype=t,function(e){return new n(e)}},Ww=e=>{let t={[hw]:hw,_tag:e.op,get[e.prop](){return this[_w]},...Hw(e),toString(){return`${e.op}(${nw(this[_w])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[_w]}},[VC](e){return Sye(e)&&e._tag===this._tag&&HC(this[_w],e[_w])},[TC](){return kC(NC(e.op),EC(this[_w]))}},n=function(e){this[_w]=e};return n.prototype=t,function(e){return new n(e)}},Gw=Ww({op:`Success`,prop:`value`,[vw](e){let t=e.getCont(yw);return t?t[yw](this[_w],e,this):e.yieldWith(this)}}),Kw={key:`effect/Cause/StackTrace`},qw={key:`effect/Cause/InterruptorStackTrace`},Jw=Ww({op:`Failure`,prop:`cause`,[vw](e){let t=this[_w],n=!1;e.cache.stackFrame&&(t=Rw(t,{mapUnsafe:new Map([[Kw.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(bw),i=e._interruptedCause;if(i&&e.interruptible){let a=!1;for(;r&&e.interruptible;)a||=gw in r,r=e.getCont(bw);a&&(t=Nw(t.reasons.filter(e=>e._tag!==`Fail`))),t=Fw(t,i),n=!0}return r?r[bw](t,e,n?void 0:this):e.yieldWith(n?Jw(t):this)}}),Yw=e=>Jw(Tye(e)),Xw=e=>Jw(Lw(e)),Zw=Uw({op:`WithFiber`,[vw](e){return this[_w](e)}}),Dye=function(){class e extends globalThis.Error{}let t=Hw({op:`YieldableError`,[vw](){return Yw(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),Qw=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return class extends Dye{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(yye(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),$w=e=>{class t extends Qw{_tag=e}return t.prototype.name=e,t},Oye=e=>wC(e,`~effect/Cause/Done`),kye=e=>Hw({op:e.label,[vw]:e.evaluate}),eT=`~effect/Option`,tT={[eT]:{_A:e=>e},...Cw,[Symbol.iterator](){return new dw(this)}},Aye=Object.defineProperty(Object.assign(Object.create(tT),{_tag:`Some`,_op:`Some`,[VC](e){return nT(e)&&Nye(e)&&HC(this.value,e.value)},[TC](){return kC(EC(this._tag))(EC(this.value))},toString(){return`some(${nw(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:sw(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),jye=EC(`None`),Mye=Object.assign(Object.create(tT),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[VC](e){return nT(e)&&rT(e)},[TC](){return jye},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),nT=e=>wC(e,eT),rT=e=>e._tag===`None`,Nye=e=>e._tag===`Some`,Pye=Object.create(Mye),iT=function(e){this.value=e};iT.prototype=Aye;const Fye=e=>new iT(e),aT=`~effect/Result`,oT={[aT]:{_A:e=>e,_E:e=>e},...Cw,[Symbol.iterator](){return new dw(this)}},Iye=Object.assign(Object.create(oT),{_tag:`Success`,_op:`Success`,[VC](e){return sT(e)&&Rye(e)&&HC(this.success,e.success)},[TC](){return kC(EC(this._tag))(EC(this.success))},toString(){return`success(${nw(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:sw(this.success)}}}),Lye=Object.assign(Object.create(oT),{_tag:`Failure`,_op:`Failure`,[VC](e){return sT(e)&&cT(e)&&HC(this.failure,e.failure)},[TC](){return kC(EC(this._tag))(EC(this.failure))},toString(){return`failure(${nw(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:sw(this.failure)}}}),sT=e=>wC(e,aT),cT=e=>e._tag===`Failure`,Rye=e=>e._tag===`Success`,lT=function(e){this.failure=e};lT.prototype=Lye;const zye=e=>new lT(e),uT=function(e){this.success=e};uT.prototype=Iye;const Bye=e=>new uT(e);function dT(e){return(t,n)=>t===n?0:e(t,n)}const Vye=dT((e,t)=>e<t?-1:1),Hye=dT((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t)?0:globalThis.Number.isNaN(e)?-1:globalThis.Number.isNaN(t)?1:e<t?-1:1),Uye=sC(2,(e,t)=>dT((n,r)=>e(t(n),t(r)))),Wye=e=>sC(2,(t,n)=>e(t,n)===1),fT=()=>Pye,pT=Fye,Gye=rT,mT=`~effect/Context/Service`,hT=function(){function e(){}let t=e;Object.setPrototypeOf(t,Kye);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[_T]=_T,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&gT.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},Kye={[mT]:mT,...kye({label:`Service`,evaluate(e){return Gw(jT(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return DT(this,e)},use(e){return Zw(t=>e(jT(t.context,this)))},useSync(e){return Zw(t=>Gw(e(jT(t.context,this))))}},gT=new Set,_T=`~effect/Context/Reference`,vT=`~effect/Context`,yT=(e,t,n,r,i)=>{let a=Object.create(Jye);return a.cacheRoot=e??a,a.base=t,a.overlay=n,a.depth=r,a._flat=void 0,a.baseHits=0,a.maxDepth=i,a},bT=(e,t)=>{t&&(bT(e,t.parent),e.set(t.key,t.value))},xT=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return bT(t,e.overlay),e._flat=t},qye=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),yT(void 0,n,void 0,0,e.maxDepth)},ST=Symbol(),CT=(e,t)=>{let n=e;for(let e=n.overlay;e;e=e.parent)if(e.key===t)return e.value;let r=n.base.get(t);return r===void 0&&!n.base.has(t)?ST:(n.overlay&&++n.baseHits>=n.base.size&&n.baseHits>=8&&(n.base=xT(n),n.overlay=void 0,n.depth=0),r)},wT=(e,t)=>{let n=t?.maxDepth;return yT(void 0,e,void 0,0,Number.isInteger(n)&&n>=0?n:8)},Jye={get mapUnsafe(){return xT(this)},...Cw,[vT]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[VC](e){if(!TT(e))return!1;let t=this.mapUnsafe,n=e.mapUnsafe;if(t.size!==n.size)return!1;for(let[e,r]of t)if(!n.has(e)||!HC(r,n.get(e)))return!1;return!0},[TC](){return MC(this.mapUnsafe.size)}},Yye=(e,t)=>e.cacheRoot===t.cacheRoot,TT=e=>wC(e,vT),Xye=e=>!!e[_T],ET=()=>Zye,Zye=wT(new Map),DT=(e,t)=>wT(new Map([[e.key,t]])),OT=sC(3,(e,t,n)=>Qye(e,t.key,n)),Qye=(e,t,n)=>{let r=e,i=gT.has(t)?void 0:r.cacheRoot;if(r.depth>=r.maxDepth){let e=new Map(r._flat??r.base);return r._flat||bT(e,r.overlay),e.set(t,n),yT(i,e,void 0,0,r.maxDepth)}return yT(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1,r.maxDepth)},kT=sC(2,(e,t)=>AT(e,t.key)),AT=(e,t)=>{let n=CT(e,t);return n===ST?void 0:n},jT=sC(2,(e,t)=>{let n=CT(e,t.key);if(n===ST){if(Xye(t))return $ye(t);throw ebe(t)}return n}),MT=`~effect/Context/defaultValue`,$ye=e=>MT in e?e[MT]:e[MT]=e.defaultValue(),ebe=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(t.stack){let e=t.stack.split(`
262
+ `);e.splice(1,3),t.stack=e.join(`
263
+ `)}return t},tbe=sC(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:qye(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),nbe=(...e)=>{let t=new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return wT(t)},NT=hT,PT=e=>e.length>0,FT=Bye,IT=zye,LT=cT,RT=globalThis.Array,rbe=e=>RT.isArray(e)?e:RT.from(e),zT=sC(2,(e,t)=>[...e,t]);RT.isArray;const ibe=PT,abe=PT,BT=()=>[],obe=sC(2,(e,t)=>e.map(t)),VT=`~effect/Duration`,HT=BigInt(0),UT=BigInt(1),sbe=BigInt(2),cbe=BigInt(10),WT=BigInt(1e3),GT=BigInt(1e6),KT=BigInt(1e9),lbe=BigInt(6e10),ube=BigInt(36e11),dbe=BigInt(864e11),fbe=BigInt(6048e11),qT=e=>BigInt(Math.sign(e)*Math.round(Math.abs(e))),JT=e=>Number.isInteger(e)?BigInt(e)*GT:qT(e*1e6),YT=e=>rE(Number.isFinite(e)?qT(e):e),pbe=(e,t)=>{let n=Number(e);if(Number.isFinite(n))return n/t;let r=BigInt(t);return Number(e/r)+Number(e%r)/t},XT=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=cbe**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t;return mbe(r?-o:o,a)},mbe=(e,t)=>{let n=e<HT?-e:e,r=n/t+(n%t*sbe>=t?UT:HT);return e<HT?-r:r},ZT=(e,t)=>{let n=Number(e)*t;if(!Number.isFinite(n))return rE(n);let r=XT(e,BigInt(t)*GT);return rE(Number.isInteger(n)&&BigInt(n)*GT===r?n:r)},hbe=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,QT=e=>{switch(typeof e){case`number`:return xbe(e);case`bigint`:return oE(e);case`string`:{if(e===`Infinity`)return iE;if(e===`-Infinity`)return aE;let t=hbe.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return oE(XT(r,UT));if(i===`micro`||i===`micros`)return oE(XT(r,WT));switch(i){case`milli`:case`millis`:return ZT(r,1);case`second`:case`seconds`:return ZT(r,1e3);case`minute`:case`minutes`:return ZT(r,6e4);case`hour`:case`hours`:return ZT(r,36e5);case`day`:case`days`:return ZT(r,864e5);case`week`:case`weeks`:return ZT(r,6048e5)}break}case`object`:{if(e===null)break;if(VT in e)return e;if(Array.isArray(e)){if(e.length!==2||!e.every(xC))return tE(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return bbe;if(e[0]===-1/0||e[1]===-1/0)return aE;if(e[0]===1/0||e[1]===1/0)return iE;let t=e[0]*1e9+e[1];return Number.isFinite(t)&&Number.isInteger(e[0])&&Number.isInteger(e[1])?rE(BigInt(e[0])*KT+BigInt(e[1])):YT(t)}let t=e,n=0;if(t.weeks&&(n+=t.weeks*6048e5),t.days&&(n+=t.days*864e5),t.hours&&(n+=t.hours*36e5),t.minutes&&(n+=t.minutes*6e4),t.seconds&&(n+=t.seconds*1e3),t.milliseconds&&(n+=t.milliseconds),!t.microseconds&&!t.nanoseconds){if(!Number.isFinite(n))return rE(n);let e=eE(t);return e===void 0||BigInt(n)*GT===e?rE(n):rE(e)}let r=n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0),i=Number.isFinite(r)?eE(t):void 0;return i===void 0?YT(r):rE(i)}}return tE(e)},$T=e=>!e||Number.isInteger(e),eE=e=>{if(!$T(e.weeks)||!$T(e.days)||!$T(e.hours)||!$T(e.minutes)||!$T(e.seconds)||!$T(e.milliseconds)||!$T(e.microseconds)||!$T(e.nanoseconds))return;let t=HT;return e.weeks&&(t+=BigInt(e.weeks)*fbe),e.days&&(t+=BigInt(e.days)*dbe),e.hours&&(t+=BigInt(e.hours)*ube),e.minutes&&(t+=BigInt(e.minutes)*lbe),e.seconds&&(t+=BigInt(e.seconds)*KT),e.milliseconds&&(t+=BigInt(e.milliseconds)*GT),e.microseconds&&(t+=BigInt(e.microseconds)*WT),e.nanoseconds&&(t+=BigInt(e.nanoseconds)),t},tE=e=>{throw Error(`Invalid Input: ${e}`)},nE={_tag:`Millis`,millis:0},gbe={_tag:`Infinity`},_be={_tag:`NegativeInfinity`},vbe={[VT]:VT,[TC](){switch(this.value._tag){case`Millis`:return EC(JT(this.value.millis));case`Nanos`:return EC(this.value.nanos);default:return PC(this.value)}},[VC](e){return ybe(e)&&Ebe(this,e)},toString(){switch(this.value._tag){case`Infinity`:return`Infinity`;case`NegativeInfinity`:return`-Infinity`;case`Nanos`:return`${this.value.nanos} nanos`;case`Millis`:return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,nanos:String(this.value.nanos)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`};case`NegativeInfinity`:return{_id:`Duration`,_tag:`NegativeInfinity`}}},[ow](){return this.toJSON()},pipe(){return iC(this,arguments)}},rE=e=>{let t=Object.create(vbe);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?nE:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:JT(e)}:e>0?gbe:_be:e===HT?nE:{_tag:`Nanos`,nanos:e},t},ybe=e=>wC(e,VT),bbe=rE(0),iE=rE(1/0),aE=rE(-1/0),oE=e=>rE(e),xbe=e=>rE(e),Sbe=e=>Cbe(QT(e),{onMillis:cC,onNanos:e=>pbe(e,1e6),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),sE=e=>{let t=QT(e);switch(t.value._tag){case`Infinity`:case`NegativeInfinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return JT(t.value.millis)}},Cbe=sC(2,(e,t)=>{switch(e.value._tag){case`Millis`:return t.onMillis(e.value.millis);case`Nanos`:return t.onNanos(e.value.nanos);case`Infinity`:return t.onInfinity();case`NegativeInfinity`:return(t.onNegativeInfinity??t.onInfinity)()}}),wbe=sC(3,(e,t,n)=>e.value._tag===`Infinity`||e.value._tag===`NegativeInfinity`||t.value._tag===`Infinity`||t.value._tag===`NegativeInfinity`?n.onInfinity(e,t):e.value._tag===`Millis`?t.value._tag===`Millis`?n.onMillis(e.value.millis,t.value.millis):n.onNanos(sE(e),t.value.nanos):n.onNanos(e.value.nanos,sE(t))),Tbe=(e,t)=>wbe(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),Ebe=sC(2,(e,t)=>Tbe(e,t)),cE=NT(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new dE}),lE=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},Dbe=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},uE=e=>{try{return Dbe(e)}catch{return lE(e)}};var Obe=class{buckets=[];scheduleTask(e,t){let n=this.buckets,r=n.length,i,a=0;for(;a<r&&!(n[a][0]>t);a++)i=n[a];i&&i[0]===t?i[1].push(e):a===r?n.push([t,[e]]):n.splice(a,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}},dE=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?lE:uE)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new kbe(this.setImmediate)}},kbe=class{tasks=new Obe;running=void 0;setImmediate;constructor(e=uE){this.setImmediate=e}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running===void 0&&(this.running=this.setImmediate(this.afterScheduled))}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let n=e[t][1];for(let e=0;e<n.length;e++)n[e]()}}flush(){for(;this.tasks.buckets.length>0;)this.running!==void 0&&(this.running(),this.running=void 0),this.runTasks()}};const Abe=NT(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),jbe=NT(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),Mbe=$w,fE=new Uint8Array(256).fill(255);for(let e=0;e<16;e++)fE[`0123456789abcdef`.charCodeAt(e)]=e,fE[`0123456789ABCDEF`.charCodeAt(e)]=e;const Nbe=NT(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:uC}),Pbe=NT(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:Hve}),pE=NT(`effect/References/CurrentLogAnnotations`,{defaultValue:()=>({})}),Fbe=NT(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Ibe=NT(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Lbe=NT(`effect/References/UnhandledLogLevel`,{defaultValue:()=>`Error`}),Rbe=NT(`effect/References/CurrentLogSpans`,{defaultValue:()=>[]});var zbe=class extends Aw{constructor(e,t=jw){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[VC](e){return Vw(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[TC](){return NC(`${this._tag}:${this.fiberId}`)}};const Bbe=e=>new Ow([new zbe(e)]),Vbe=e=>e.reasons.some(zw),Hbe=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return FT(n.error)}return IT(e)},mE=e=>e.reasons.some(Bw),hE=e=>mE(e)&&Vbe(e)?Nw(e.reasons.map(e=>e._tag===`Fail`&&!Oye(e.error)?new Iw(e.error,e.annotations):e)):e,gE=e=>mE(e)?IT(hE(e)):Hbe(e),Ube=e=>e.reasons.some(Vw),Wbe=e=>e.reasons.length>0&&e.reasons.every(Vw),Gbe=e=>wT(e.annotations),_E=sC(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>zw(e)?(n=!0,new Mw(t(e.error),e.annotations)):e);return n?Nw(r):e}),Kbe=e=>{let t;for(let n of e.reasons){if(n._tag===`Fail`)return n.error;n._tag===`Die`&&(t??=n)}return t===void 0?e.reasons.length>0?new globalThis.Error(`All fibers interrupted without error`):new globalThis.Error(`Empty cause`):t.defect},qbe=(e,t)=>{let n=[],r=[];if(e.reasons.length===0)return n;let i=lw();i!==0&&uw(1);try{for(let i of e.reasons){if(i._tag===`Interrupt`){r.push(i);continue}n.push(vE(i._tag===`Die`?i.defect:i.error,i.annotations,t))}if(n.length===0){let e=Error(`The fiber was interrupted by:`);e.name=`InterruptCause`,e.stack=Zbe(e,r);let i=new globalThis.Error(`All fibers interrupted without error`,{cause:e});i.name=`InterruptError`,i.stack=`${i.name}: ${i.message}`,n.push(vE(i,r[0].annotations,t))}}finally{i!==0&&uw(i)}return n},vE=(e,t,n,r=new Set)=>{let i=typeof e,a;if(e&&i===`object`){r.add(e);let i=e.cause;if(a=new globalThis.Error(Jbe(e),{cause:i!==void 0&&!r.has(i)?vE(i,void 0,void 0,r):void 0}),typeof e.name==`string`&&(a.name=e.name),typeof e.stack==`string`)a.stack=Xbe(e.stack,a,t);else{let e=`${a.name}: ${a.message}`;a.stack=t?yE(e,t):e}n?.includeCauseInStack&&(a.stack=SE(a));for(let t of Object.keys(e))t in a||(a[t]=e[t])}else{a=new globalThis.Error(e?i===`string`?e:aw(e):`Unknown error: ${e}`);let n=`${a.name}: ${a.message}`;a.stack=t?yE(n,t):n}return a},Jbe=e=>{if(typeof e.message==`string`)return e.message;if(typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString)try{return e.toString()}catch{}return aw(e)},Ybe=/\((.*)\)/g,Xbe=(e,t,n)=>{let r=`${t.name}: ${t.message}`,i=(e.startsWith(r)?e.slice(r.length):e).split(`
264
+ `),a=[r];for(let e=1;e<i.length&&!/Generator\.next|~effect\/(?:Effect|Utils)/.test(i[e]);e++)a.push(i[e]);return n?yE(a.join(`
265
+ `),n):a.join(`
266
+ `)},yE=(e,t)=>{let n=t?.get(Kw.key);return n&&(e=`${e}\n${bE(n)}`),e},Zbe=(e,t)=>{let n=[`${e.name}: ${e.message}`];for(let e of t){let t=e.fiberId===void 0?`unknown`:`#${e.fiberId}`,r=e.annotations.get(qw.key);n.push(` at fiber (${t})`),r&&n.push(bE(r))}return n.join(`
267
+ `)},bE=e=>{let t=[],n=e,r=0;for(;n&&r<10;){let e=n.stack();if(e){let r=e.matchAll(Ybe),i=!1;for(let[,e]of r)i=!0,t.push(` at ${n.name} (${e})`);i||t.push(` at ${n.name} (${e.replace(/^at /,``)})`)}else t.push(` at ${n.name}`);n=n.parent,r++}return t.join(`
268
+ `)},xE=e=>qbe(e).map(SE).join(`
269
+ `),SE=e=>e.cause?`${e.stack} {\n${CE(e.cause,` `)}\n}`:e.stack,CE=(e,t)=>{let n=e.stack.split(`
270
+ `),r=`${t}[cause]: ${n[0]}`;for(let e=1,i=n.length;e<i;e++)r+=`\n${t}${n[e]}`;return e.cause&&(r+=` {\n${CE(e.cause,`${t} `)}\n${t}}`),r},Qbe={_A:cC,_E:cC},$be={id:0},wE=(()=>{try{return globalThis.process?.getBuiltinModule?.(`node:async_hooks`)?.AsyncResource}catch{return}})(),TE=()=>wE===void 0?void 0:new wE(`effect/Fiber`),EE=()=>globalThis[ew];var DE=class{constructor(e,t=!0){this.setContext(e),this.id=++$be.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._autoYielded=!1,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get"~effect/Fiber"(){return Qbe}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return jT(this.context,e)}addObserver(e){return this._exit?(e(this._exit),dC):(this._observers===void 0?this._observers=[e]:this._observers.push(e),()=>this.removeObserver(e))}removeObserver(e){if(this._exit||this._observers===void 0)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let n=Bbe(e);this.cache.stackFrame&&(n=Rw(n,DT(Kw,this.cache.stackFrame))),t&&(n=Rw(n,t)),this._interruptedCause=this._interruptedCause?Fw(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(NE(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._asyncContext!==void 0){let t=this._asyncContext;this._asyncContext=void 0;try{return t.runInAsyncScope(this.evaluate,this,e)}finally{t.emitDestroy()}}else if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===Sw){this._asyncContext=TE();return}let n=OE.interruptChildren&&OE.interruptChildren(this);if(n!==void 0)return this.evaluate($E(n,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&=(this._parent._children?.delete(this),void 0),this._observers!==void 0){let e=this._observers;this._observers=void 0;for(let n=0;n<e.length;n++)e[n](t)}this._stack.length=0,this._children=void 0,this.context=ET();let r=this.cache;(r.span!==void 0||r.stackFrame!==void 0)&&(this.cache={...r,span:void 0,stackFrame:void 0})}runLoop(e){let t=globalThis[ew];globalThis[ew]=this;let n=this._running;this._running=!0;let r=!1,i=this._autoYielded;this._autoYielded=!1;let a=e;this.currentOpCount=+!!i;try{for(;;)try{this._deferredInterrupt&&(this._deferredInterrupt=!1,a=NE(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!i&&!r&&!e.preventYield&&e.scheduler.shouldYield(this)?(r=!0,a=this.yieldNow(a,0,!0)):(i=!1,a=e.tracerContext?e.tracerContext(a,this):a[vw](this)),a===Sw){let e=this._yielded;if(hw in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return Sw}}catch(e){if(!wC(a,vw))return Xw(`Fiber.runLoop: Not a valid effect: ${String(a)}`);a=Xw(e)}}finally{this._running=n,globalThis[ew]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,txe;for(;;){let t=this._stack.pop();if(!t)return;let n=t[xw];if(n!==void 0){let r=n.call(t,this);if(r)return r[e]=r,r}if(t[e])return t}}succeedWith(e){if(!(++this.currentOpCount&nxe-1))return Gw(e);let t=this.getCont(yw);return t?t[yw](e,this):this.yieldWith(Gw(e))}yieldWith(e){return this._yielded=e,Sw}yieldNow(e,t=0,n=!1){let r=!1;return this.currentDispatcher.scheduleTask(()=>{r||(this._autoYielded=n,this.evaluate(e))},t),this.yieldWith(()=>{r=!0})}children(){return this._children??=new Set}pipe(){return iC(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Yye(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=exe(e);this.cache?.scheduler!==r.scheduler&&(this._dispatcher=void 0),this.cache=r}get currentSpanLocal(){let e=this.cache.span;return e?._tag===`Span`?e:void 0}};const exe=e=>{let t=AT(e,`effect/Tracer`);return{scheduler:jT(e,cE),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:jT(e,Pbe),span:AT(e,`effect/Tracer/ParentSpan`),logLevel:jT(e,Fbe),minimumLogLevel:jT(e,Ibe),stackFrame:jT(e,Nbe),runtimeMetrics:AT(e,`effect/Metric/FiberRuntimeMetrics`),maxOpsBeforeYield:jT(e,Abe),preventYield:jT(e,jbe)}},txe={[yw](e,t){return NE(t._interruptedCause)},[bw](e,t){return NE(t._interruptedCause)}},nxe=32,OE={interruptChildren:void 0},kE=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(qw.key,e.cache.stackFrame),wT(t)},AE=e=>BE(t=>{let n=e[Symbol.iterator](),r=[],i;function a(){let e=n.next();for(;!e.done;){if(e.value._exit){r.push(e.value._exit),e=n.next();continue}i=e.value.addObserver(e=>{r.push(e),a()});return}t(ME(r))}return a(),FE(()=>i?.())}),jE=e=>Zw(t=>{let n=kE(t),r=BT();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return QE(AE(r))}),ME=Gw,NE=Jw,PE=Yw,FE=Uw({op:`Sync`,[vw](e){let t=this[_w],n=t(),r=e.getCont(yw);return r?r[yw](n,e):e.yieldWith(Gw(n))}}),IE=Uw({op:`Suspend`,[vw](e){let t=this[_w];return t()}}),rxe=Uw({op:`Yield`,[vw](e){return e.yieldNow(rD,this[_w]??0)}})(0),ixe=e=>IE(()=>NE(e())),LE=e=>Xw(e),RE=ME(void 0),axe=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new WD(e,`An error occurred in Effect.try`):e.catch;return IE(()=>{try{return ME(t())}catch(e){return PE(n(e))}})},oxe=e=>zE(function(t,n){e(n).then(e=>t(ME(e)),e=>t(LE(e)))},e.length!==0),sxe=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new WD(e,`An error occurred in Effect.tryPromise`):e.catch;return zE(function(e,r){let i=e=>IE(()=>{try{return PE(fw(()=>n(e)))}catch(e){return LE(e)}});try{t(r).then(t=>e(ME(t)),t=>e(i(t)))}catch(t){e(i(t))}},t.length!==0)},zE=function(){let e=Hw({op:`Async`,[vw](e){let t=!1,n=!1,r=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,r=>{t||(t=!0,n?e.evaluate(r):n=r)},r?.signal);return n===!1?(n=!0,e.yieldWith(()=>{t=!0}),r===void 0&&i===void 0||e._stack.push(cxe(()=>(t=!0,r?.abort(),i??rD))),Sw):n}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),cxe=Uw({op:`AsyncFinalizer`,[xw](e){e.interruptible&&(e.interruptible=!1,e._stack.push(kD))},[bw](e,t){return Ube(e)?$E(yD(Jw(e),this[_w]()),()=>NE(e)):NE(e)}}),BE=e=>zE(e,e.length>=2),lxe=BE(dC),uxe=(...e)=>{if(e.length===1){let t=e[0];return IE(()=>WE(t()))}let[t,n]=e;return IE(()=>WE(n.call(t.self)))},VE=(e,t)=>typeof e==`function`?e:t.shift().bind(e.self),dxe=(e,...t)=>{let n=VE(e,t),r=t.length===0?function(){return IE(()=>WE(n.apply(this,arguments)))}:function(){let e=IE(()=>WE(n.apply(this,arguments)));for(let n=0;n<t.length;n++)e=t[n](e,...arguments);return e};return HE(n.length,r)},HE=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),fxe=(e,...t)=>{let n=VE(e,t);return HE(n.length,t.length===0?function(){return UE(()=>n.apply(this,arguments))}:function(){let e=UE(()=>n.apply(this,arguments));for(let n of t)e=n(e,...arguments);return e})},UE=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return ME(r.value);let i=r.value;if(i&&i._tag===`Success`){n=i.value;continue}if(i&&i._tag===`Failure`)return r.value;{let n=!0;return IE(()=>n?(n=!1,$E(r.value,e=>WE(t,e))):IE(()=>WE(e())))}}}catch(e){return LE(e)}},WE=function(){let e=Hw({op:`Iterator`,[yw](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return ME(r.value);if(!eD(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[vw](e){return this[yw](this.initial,e)}}),t=function(e,t){this.iterator=e,this.initial=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),GE=sC(2,(e,t)=>new qE(e,JE,ME(t))),KE=function(e){return e._stack.push(this),this[_w]},pxe=Hw({op:`OnSuccess`,[vw]:KE}),qE=function(e,t,n){this[_w]=e,this[yw]=t,this.payload=n};qE.prototype=pxe;const JE=function(){return this.payload},YE=function(e,t){return t.succeedWith(this.payload)},XE=(()=>{let e=lw();if(e===0)return!1;let t=`~effect/Effect/stackProbe`,n={[t]:function(){return Error()}};uw(1);let r=n[t]();return uw(e),r.stack?.includes(`[as `+t+`]`)===!0})(),mxe=function(e,t){let n=this.payload;return t.succeedWith(XE?n(e):fw(()=>n(e)))},ZE=function(e){let t=this.payload;return t(e)},hxe=function(e){let t=this.payload;return new qE(t(e),YE,e)},gxe=function(e){return new qE(this.payload,YE,e)},_xe=e=>tD(e,pT),vxe=sC(2,(e,t)=>new qE(e,ww(t)?JE:ZE,t)),yxe=sC(2,(e,t)=>new qE(e,ww(t)?gxe:hxe,t)),QE=e=>new qE(e,JE,rD),bxe=(e,t)=>Zw(n=>{let r=new Set;return ED(n,()=>r.size===0?void 0:jE(r)),BE(i=>{let a=!1,o=0;for(let s of e){if(a)break;let e=o++,c=PD(n,s,!0,!0,!1);r.add(c),c.addObserver(o=>{r.delete(c);let s=!a;a=!0,i(o),s&&(xxe(r,n),t?.onWinner?.({fiber:c,index:e,parentFiber:n}))})}})}),xxe=(e,t)=>{let n=kE(t);for(let r of e)r.interruptUnsafe(t.id,n)},Sxe=sC(e=>ww(e[1]),(e,t,n)=>bxe([e,t],n)),$E=sC(2,(e,t)=>new qE(e,ZE,t)),eD=e=>e[hw]!==void 0,Cxe=sC(2,(e,t)=>eD(e)?e._tag===`Success`?t(e.value):e:$E(e,t)),tD=sC(2,(e,t)=>new qE(e,mxe,t)),wxe=sC(2,(e,t)=>eD(e)?Txe(e,t):tD(e,t)),nD=e=>e._tag===`Success`,rD=Gw(void 0),Txe=sC(2,(e,t)=>e._tag===`Success`?Gw(t(e.value)):e),Exe=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?rD:Jw(Nw(t))},Dxe=e=>e,iD=sC(2,(e,t)=>Zw(n=>{let r=n.context,i=t(r);return r===i?e:(n.setContext(i),ED(n,()=>{n.setContext(r)}),e)})),Oxe=e=>Zw(t=>e(t.context)),aD=sC(2,(e,t)=>eD(e)?e:iD(e,tbe(t))),oD=function(){return arguments.length===1?sC(2,(e,t)=>sD(e,arguments[0],t)):sC(3,(e,t,n)=>sD(e,t,n)).apply(this,arguments)},sD=(e,t,n)=>iD(e,OT(t,n)),cD=sC(2,(e,t)=>new lD(e,t.length===1?t:e=>t(e))),kxe=Hw({op:`OnFailure`,[vw]:KE}),lD=function(e,t){this[_w]=e,this[bw]=t};lD.prototype=kxe;const Axe=sC(3,(e,t,n)=>cD(e,e=>{let r=t(e);return LT(r)?NE(r.failure):n(r.success,e)})),jxe=sC(2,(e,t)=>Axe(e,gE,e=>t(e))),Mxe=sC(2,(e,t)=>cD(e,e=>vxe(t(e),NE(e)))),Nxe=sC(e=>ww(e[0]),(e,t,n,r)=>cD(e,e=>{let i=gE(e);return LT(i)?NE(i.failure):t(i.success)?n(i.success):r?r(i.success):NE(e)})),Pxe=sC(e=>ww(e[0]),(e,t,n,r)=>{let i=Array.isArray(t)?e=>wC(e,`_tag`)&&t.includes(e._tag):Zve(t);return Nxe(e,i,n,r)}),Fxe=sC(2,(e,t)=>cD(e,e=>NE(_E(e,t)))),Ixe=sC(2,(e,t)=>jxe(e,e=>FE(()=>t(e)))),Lxe=e=>e===`Unhandled`?(...e)=>Zw(t=>{let n=t.getRef(Lbe);return n===void 0?RE:KD(n)(...e)}):KD(e===!0?void 0:e),Rxe=sC(e=>ww(e[0]),(e,t)=>{if(!t?.log)return Uxe(e,{onFailure:e=>RE,onSuccess:e=>RE});let n=Lxe(t.log);return uD(e,{onFailure(e){let r=gE(e);return LT(r)?NE(r.failure):t.message===void 0?n(e):n(t.message,e)},onSuccess:e=>RE})}),zxe=e=>Gxe(e,{onFailure:IT,onSuccess:FT}),uD=sC(2,(e,t)=>new dD(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Bxe=Hw({op:`OnSuccessAndFailure`,[vw]:KE}),dD=function(e,t,n){this[_w]=e,this[yw]=t,this[bw]=n};dD.prototype=Bxe;const Vxe=function(e,t){let n=this.payload;return t.succeedWith(XE?n.onSuccess(e):fw(()=>n.onSuccess(e)))},Hxe=((e,t)=>{let n=Hw({op:e,[vw]:KE,[yw]:Vxe,[bw]:t}),r=function(e,t){this[_w]=e,this.payload=t};return r.prototype=n,r})(`Match`,function(e,t){let n=gE(e);if(LT(n))return NE(n.failure);let r=this.payload;return t.succeedWith(XE?r.onFailure(n.success):fw(()=>r.onFailure(n.success)))}),Uxe=sC(2,(e,t)=>uD(e,{onFailure:e=>{let n=gE(e);return LT(n)?NE(n.failure):t.onFailure(n.success)},onSuccess:t.onSuccess})),Wxe=sC(2,(e,t)=>new Hxe(e,t)),Gxe=sC(2,(e,t)=>{if(eD(e)){if(e._tag===`Success`)return Gw(t.onSuccess(e.value));let n=gE(e.cause);return LT(n)?Jw(n.failure):Gw(t.onFailure(n.success))}return Wxe(e,t)}),fD=e=>eD(e)?Gw(e):Kxe(e),Kxe=Uw({op:`Exit`,[vw](e){return e._stack.push(this),this[_w]},[yw](e,t,n){return t.succeedWith(n??Gw(e))},[bw](e,t,n){return t.succeedWith(n??Jw(e))}}),qxe=sC(2,(e,t)=>$E(Jxe(e,t.duration),e=>Gye(e)?t.orElse():ME(e.value))),Jxe=sC(2,(e,t)=>Sxe(_xe(e),GE(VD(t),fT()))),pD=`~effect/Scope`,mD=`~effect/Scope/Closeable`,hD=hT(`effect/Scope`),gD=(e,t)=>Zw(n=>(cSe(n),_D(e,t)??RE)),_D=(e,t)=>{let n=e.state;if(n._tag===`Closed`||(e.state={_tag:`Closed`,exit:t},e.parent!==void 0&&Qxe(e.parent,e),n._tag===`Empty`))return;if(n.finalizer!==void 0)return vD(n.finalizer,t);let r=n.finalizers;return r.size===1?vD(r.values().next().value,t):Yxe(e,r,t)},vD=(e,t)=>{try{return e(t)}catch(e){return Xw(e)}},yD=(e,t)=>nD(e)?t:cD(t,t=>NE(hE(Pw(e.cause,t)))),Yxe=dxe(function*(e,t,n){let r=[],i=[],a=Array.from(t),o=EE();for(let t=a.length-1;t>=0;t--){let[s,c]=a[t];e.strategy===`sequential`?r.push(yield*fD(vD(c,n))):s!==o&&i.push(PD(o,vD(c,n),!0,!0,`inherit`))}return i.length>0&&(r=yield*AE(i)),yield*Exe(r)}),Xxe=(e,t)=>{let n=SD(t,e);return e.state._tag===`Closed`?(n.state=e.state,n):(bD(e,n,e=>gD(n,e)),n)},Zxe=(e,t)=>IE(()=>e.state._tag===`Closed`?t(e.state.exit):(bD(e,{},t),RE)),bD=(e,t,n)=>{if(e.state._tag===`Empty`)e.state={_tag:`Open`,finalizerKey:t,finalizer:n,finalizers:void 0};else if(e.state._tag===`Open`){let r=e.state;r.finalizer===void 0?r.finalizers.set(t,n):(r.finalizers=new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0,r.finalizers.set(t,n))}},Qxe=(e,t)=>{if(e.state._tag!==`Open`)return;let n=e.state;n.finalizerKey===t?e.state=CD:n.finalizers!==void 0&&(n.finalizers.delete(t),n.finalizers.size===0&&(e.state=CD))},xD=e=>SD(e,void 0),SD=(e=`sequential`,t)=>({[mD]:mD,[pD]:pD,strategy:e,parent:t,state:CD}),CD={_tag:`Empty`},$xe=hD,eSe=oD(hD),tSe=e=>Zw(t=>{let n=t.context,r=xD();return t.setContext(OT(t.context,hD,r)),ED(t,e=>(t.setContext(n),_D(r,e))),e}),nSe=e=>IE(()=>{let t=xD();return DD(e(t),e=>IE(()=>_D(t,e)??RE))}),rSe=(e,t,n)=>Oxe(r=>uSe(i=>$E($xe,a=>yxe(n?.interruptible?i(e):e,e=>Zxe(a,n=>aD(t(e,n),r)))))),wD=function(){let e=Hw({op:`OnExit`,[vw](e){return e._stack.push(this),this.effect},[xw](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(kD),e.interruptible=!1)},[yw](e,t,n){n??=Gw(e);let r;try{r=this.onExit(n)}catch(e){r=Xw(e)}return r?$E(r,e=>n):n},[bw](e,t,n){n??=Jw(e);let r;try{r=this.onExit(n)}catch(e){r=Xw(e)}return r?$E(yD(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,t}(),TD=(e,t,n)=>new wD(e,t,n),ED=(e,t)=>{e._stack.push(new wD(void 0,t,void 0))},DD=sC(2,TD),iSe=sC(2,(e,t)=>DD(e,e=>t)),aSe=e=>Zw(t=>t.interruptible?(t.interruptible=!1,t._stack.push(kD),e):e),OD=Uw({op:`SetInterruptible`,[xw](e){if(e.interruptible=this[_w],e._interruptedCause&&e.interruptible)return()=>NE(e._interruptedCause)}}),kD=OD(!0),oSe=OD(!1),sSe=e=>{if(e.interruptible=!0,e._stack.push(oSe),e._interruptedCause)return NE(e._interruptedCause)},cSe=e=>{let t=e;t.interruptible&&(t.interruptible=!1,t._stack.push(kD))},lSe=e=>Zw(t=>t.interruptible?e:sSe(t)??e),uSe=e=>Zw(t=>t.interruptible?(t.interruptible=!1,t._stack.push(kD),e(lSe)):e(cC)),dSe=Uw({op:`While`,[yw](e,t){return this[_w].step(e),this[_w].while()?(t._stack.push(this),this[_w].body()):rD},[vw](e){return this[_w].while()?(e._stack.push(this),this[_w].body()):rD}}),fSe=sC(e=>typeof e[1]==`function`,(e,t,n)=>IE(()=>{let r=AD(n?.concurrency);if(r===1)return pSe(e,t,n);let i=rbe(e),a=i.length;if(a===0)return n?.discard?RE:ME([]);let o=n?.discard?void 0:Array(a),s=mSe({f:t,out:o},i,{concurrency:r});return s?GE(s,o):ME(o)})),pSe=(e,t,n)=>IE(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return GE(dSe({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),AD=e=>e===`unbounded`?1/0:Math.max(1,e??1),jD=()=>e=>{let t=e.onItem,n=e.step,r=(e,t,r,a,o)=>$E(fD(o),o=>n(e,t[r],o,r)??i(e,t,r+1,a)??RE),i=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!eD(c))return r(e,i,a,o,c);let l=n(e,s,c,a);if(l)return l._tag===`Failure`?l:void 0}};return i},MD=e=>{let t=e.onItem,n=e.step;return(e,r,i)=>{let a=0,o=i.end??r.length,s=i.concurrency,c=!1,l,u,d,f,p,m=e=>{let t=Xw(e);return f=t,c=!0,u&&u.size>0?$E(aSe(jE(Array.from(u))),()=>f??t):t},h=()=>{let i=!1;for(;!f&&a<o;a++){let o=r[a],g=p??t(e,o,a);if(eD(g)){if(f=n(e,o,g,a),f)break}else if(l){p=void 0;let t=PD(l,g,!0,!0,`inherit`);if(t._exit){if(f=n(e,o,t._exit,a),f)break;continue}u.add(t);let r=a;if(t.addObserver(a=>{u.delete(t);try{if(f){if(a._tag===`Failure`){let e=a.cause.reasons.filter(e=>e._tag!==`Interrupt`);if(e.length>0){let t=Nw(e);f=Jw(f._tag===`Failure`?hE(Pw(f.cause,t)):t)}}}else{let t=n(e,o,a,r);t&&(f=t,h())}if(i){let e=h();e&&d(e)}else c&&u.size===0&&d(f??RE)}catch(e){d(m(e))}}),u.size<s)continue;i=!0,a++;return}else return BE(e=>{l=EE(),u=new Set,p=g,d=e;let t;try{t=h()}catch(t){return e(m(t))}return t?e(t):IE(()=>(f??=rD,$E(u?jE(u):RE,()=>f?._tag===`Failure`?f:RE)))})}if(c=!0,f){if(u&&u.size>0){let e=kE(l);u.forEach(t=>t.interruptUnsafe(l.id,e));return}if(d||f._tag===`Failure`)return f}else if(d){if(u)u.size===0&&d(RE);else return rD}};return h()}},ND=()=>e=>MD(e),mSe=MD({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag===`Failure`)return n;e.out&&(e.out[r]=n.value)}}),PD=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new DE(a.context,o);return r||(a.children().add(s),s._parent=a),n?s.evaluate(t):(s._asyncContext=TE(),a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),s},FD=e=>(t,n)=>{let r=new DE(n?.scheduler?OT(e,cE,n.scheduler):e,n?.uninterruptible!==!0);if(r.evaluate(t),r._exit)return r;if(n?.signal){if(n.signal.aborted)r.interruptUnsafe();else{let e=()=>r.interruptUnsafe();n.signal.addEventListener(`abort`,e,{once:!0}),r.addObserver(()=>n.signal.removeEventListener(`abort`,e))}}return n?.onFiberStart&&n.onFiberStart(r),r},hSe=FD(ET()),gSe=(e=>{let t=FD(e);return e=>{if(eD(e))return e;let n=new dE(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??Xw(new xSe(r))}})(ET()),ID=NT(`effect/Clock`,{defaultValue:()=>new _Se}),LD=2**31-1;var _Se=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=FE(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return vSe()}currentTimeNanos=FE(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return zD()}monotonicTimeNanos=FE(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(Sbe(e))}sleepMillis(e){return e<=0?rxe:Number.isFinite(e)?BE(t=>{let n=e>LD?this.sleepMillis(e-LD):RE,r=setTimeout(()=>t(n),Math.min(e,LD));return FE(()=>clearTimeout(r))}):lxe}};const RD=BigInt(1e6),zD=function(){let e=globalThis.process?.hrtime;if(typeof e?.bigint==`function`)return()=>e.bigint();if(typeof performance<`u`&&typeof performance.now==`function`)return()=>BigInt(Math.round(performance.now()*1e6));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*RD;return e>t&&(t=e),t}}(),vSe=function(){let e=BigInt(1e9),t;return()=>{let n=zD(),r=BigInt(Date.now())*RD;if(t===void 0)t=r-n;else{let i=t+n;(r>i?r-i:i-r)>e&&(t=r-n)}return t+n}}(),BD=e=>Zw(t=>e(t.getRef(ID))),VD=e=>BD(t=>t.sleep(QT(e))),ySe=BD(e=>e.currentTimeMillis),bSe=BD(e=>e.currentTimeNanos),HD=`~effect/Cause/AsyncFiberError`;var xSe=class extends $w(`AsyncFiberError`){[HD]=HD;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}};const UD=`~effect/Cause/UnknownError`;var WD=class extends $w(`UnknownError`){[UD]=UD;constructor(e,t){super({message:t,cause:e})}};const SSe=NT(`effect/Console`,{defaultValue:()=>globalThis.console}),CSe=Wye(Uye(Hye,e=>{switch(e){case`All`:return-(2**53-1);case`Fatal`:return 5e4;case`Error`:return 4e4;case`Warn`:return 3e4;case`Info`:return 2e4;case`Debug`:return 1e4;case`Trace`:return 0;case`None`:return 2**53-1}})),wSe=NT(`effect/Logger/CurrentLoggers`,{defaultValue:()=>new Set([ASe,jSe])}),TSe=NT(`effect/Logger/LogToStderr`,{defaultValue:Uve}),ESe={"~effect/Logger":{_Message:cC,_Output:cC},pipe(){return iC(this,arguments)}},GD=e=>{let t=Object.create(ESe);return t.log=e,t},DSe=e=>e.replace(/[\s="]/g,`_`),OSe=(e,t)=>`${DSe(e[0])}=${t-e[1]}ms`,KD=e=>(...t)=>{let n;for(let e=0,r=t.length;e<r;e++){let r=t[e];Dw(r)&&(n?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),n=n?Nw(n.reasons.concat(r.reasons)):r,e--)}return n===void 0&&(n=wye),Zw(r=>{let i=e??r.cache.logLevel;if(CSe(r.cache.minimumLogLevel,i))return RE;let a=r.getRef(ID),o=r.getRef(wSe);if(o.size>0){let e=new Date(a.currentTimeMillisUnsafe());for(let a of o)a.log({cause:n,fiber:r,date:e,logLevel:i,message:t})}return RE})},qD={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};qD.gray,qD.blue,qD.green,qD.yellow,qD.red,qD.bgBrightRed,qD.black;const kSe=e=>`${e.getHours().toString().padStart(2,`0`)}:${e.getMinutes().toString().padStart(2,`0`)}:${e.getSeconds().toString().padStart(2,`0`)}.${e.getMilliseconds().toString().padStart(3,`0`)}`,ASe=GD(({cause:e,date:t,fiber:n,logLevel:r,message:i})=>{let a=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&a.push(xE(e));let o=t.getTime(),s=n.getRef(Rbe),c=``;for(let e of s)c+=` ${OSe(e,o)}`;let l=n.getRef(pE);Object.keys(l).length>0&&a.push(l);let u=n.getRef(SSe);(n.getRef(TSe)?u.error:u.log)(`[${kSe(t)}] ${r.toUpperCase()} (#${n.id})${c}:`,...a)}),jSe=GD(({cause:e,fiber:t,logLevel:n,message:r})=>{let i=t.getRef(ID),a=t.getRef(pE),o=t.cache.span;if(o===void 0||o._tag===`ExternalSpan`||o.status._tag===`Ended`)return;let s={};for(let[e,t]of Object.entries(a))pw(s,e,t);s[`effect.fiberId`]=t.id,s[`effect.logLevel`]=n.toUpperCase(),e.reasons.length>0&&(s[`effect.cause`]=xE(e)),o.event(_ye(Array.isArray(r)&&r.length===1?r[0]:r),i.currentTimeNanosUnsafe(),s)}),MSe=zw,NSe=Lw,JD=Wbe,YD=_E,XD=Kbe,PSe=xE,FSe=Gbe,ISe=Gw,ZD=Jw,QD=Yw,$D=rD,eO=nD,LSe={"~effect/Deferred":{_A:cC,_E:cC},pipe(){return iC(this,arguments)}},tO=function(){this.resumes=void 0,this.effect=void 0};tO.prototype=LSe;const RSe=()=>new tO,zSe=e=>BE(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),FE(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),BSe=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let n=e.resumes;e.resumes=void 0;for(let e=0;e<n.length;e++)n[e](t)}return!0},VSe=xD,HSe=eSe,nO=Xxe,rO=gD,iO=`~effect/Layer/MemoMap`,USe=(e,t)=>{let n={observers:0,deferred:RSe(),scope:VSe(),finalizer:r=>IE(()=>--n.observers>0?RE:(e.map.delete(t),rO(n.scope,r)))};return n},aO=(e,t)=>t.state._tag!==`Closed`&&(e.observers++,bD(t,{},e.finalizer),!0),WSe={"~effect/Layer":{_ROut:cC,_E:cC,_RIn:cC},pipe(){return iC(this,arguments)}},oO=e=>{let t=Object.create(WSe);return t.build=e,t},GSe=e=>oO((t,n)=>{let r=nO(n);return DD(e(t,r),e=>e._tag===`Failure`?rO(r,e):RE)}),sO=e=>{let t=GSe((n,r)=>n.getOrElseMemoize(t,r,e));return t};var cO=class{get[iO](){return iO}parent;constructor(e){this.parent=e}map=new Map;get(e,t){let n=this.map.get(e);return n?(aO(n,t),n.deferred.effect??zSe(n.deferred)):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return IE(()=>{let r;return TD(IE(()=>{let i=this.get(e,t);if(i)return i;let a=USe(this,e);return aO(a,t)?(r=a.deferred,this.map.set(e,a),n(this,a.scope)):n(this,t)}),e=>{r&&BSe(r,e)})})}};const lO=()=>new cO,KSe=e=>new cO(e);var uO=class e extends hT()(`effect/Layer/CurrentMemoMap`){static forkOrCreate(t){let n=kT(t,e);return n?KSe(n):lO()}};const dO=sC(3,(e,t,n)=>oD(tD(IE(()=>e.build(t,n)),OT(uO,t)),uO,t)),qSe=sC(2,(e,t)=>Zw(n=>dO(e,uO.forkOrCreate(n.context),t))),JSe=function(){return arguments.length===1?e=>fO(DT(arguments[0],e)):fO(DT(arguments[0],arguments[1]))},fO=e=>oO(lC(ME(e))),YSe=function(){return arguments.length===1?e=>pO(arguments[0],e):pO(arguments[0],arguments[1])},pO=(e,t)=>XSe(tD(t,t=>DT(e,t))),XSe=e=>sO((t,n)=>HSe(e,n)),ZSe=(e,t,n)=>{let r=nO(n,`parallel`);return fSe(e,e=>e.build(t,nO(r,`sequential`)),{concurrency:e.length}).pipe(tD(e=>nbe(...e)))},QSe=(...e)=>sO((t,n)=>ZSe(e,t,n)),$Se=ySe,eCe=bSe,mO=`~effect/DateTime`,hO=`~effect/DateTime/TimeZone`,gO={[mO]:mO,pipe(){return iC(this,arguments)},[ow](){return this.toString()},toJSON(){return SO(this).toJSON()}},tCe={...gO,_tag:`Utc`,[TC](){return MC(this.epochMilliseconds)},[VC](e){return xO(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${SO(this).toJSON()})`}},nCe={...gO,_tag:`Zoned`,[TC](){return kC(MC(this.epochMilliseconds))(EC(this.zone))},[VC](e){return xO(e)&&e._tag===`Zoned`&&this.epochMilliseconds===e.epochMilliseconds&&HC(this.zone,e.zone)},toString(){return`DateTime.Zoned(${cCe(this)})`}},_O={[hO]:hO,[ow](){return this.toString()}};({..._O}),{..._O};const rCe={value:void 0,enumerable:!1,writable:!0},vO=new WeakMap,yO=(e,t)=>({get(){return Object.isExtensible(this)?void 0:vO.get(this)?.[e]},set(n){if(Object.isExtensible(this)){for(let e of t)Object.defineProperty(this,e,rCe);this[e]=n}else{let t=vO.get(this);t===void 0&&(t={},vO.set(this,t)),t[e]=n}}}),bO=[`partsUtc`,`adjustedEpochMilliseconds`,`partsAdjusted`];Object.defineProperty(tCe,"partsUtc",yO(`partsUtc`,[`partsUtc`])),Object.defineProperties(nCe,{partsUtc:yO(`partsUtc`,bO),adjustedEpochMilliseconds:yO(`adjustedEpochMilliseconds`,bO),partsAdjusted:yO(`partsAdjusted`,bO)});const xO=e=>wC(e,mO),SO=e=>new Date(e.epochMilliseconds),CO=e=>{if(e._tag===`Utc`)return new Date(e.epochMilliseconds);if(e.zone._tag===`Offset`)return new Date(e.epochMilliseconds+e.zone.offset);if(e.adjustedEpochMilliseconds!==void 0)return new Date(e.adjustedEpochMilliseconds);let t=!1,n=e.zone.format.formatToParts(e.epochMilliseconds).filter(e=>e.type===`era`?(t=e.value===`BC`,!1):e.type!==`literal`),r=Number(n[2].value),i=new Date(0);return i.setUTCFullYear(t?1-r:r,Number(n[0].value)-1,Number(n[1].value)),i.setUTCHours(Number(n[3].value),Number(n[4].value),Number(n[5].value),n[6]?.type===`fractionalSecond`?Number(n[6].value):(e.epochMilliseconds%1e3+1e3)%1e3),e.adjustedEpochMilliseconds=i.getTime(),i},iCe=e=>CO(e).getTime()-sCe(e),aCe=e=>{let t=Math.abs(e),n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r===60&&(n+=1,r=0),`${e<0?`-`:`+`}${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`},oCe=e=>aCe(iCe(e)),sCe=e=>e.epochMilliseconds,wO=e=>{let t=CO(e);return e._tag===`Utc`?t.toISOString():`${t.toISOString().slice(0,-1)}${oCe(e)}`},cCe=e=>e.zone._tag===`Offset`?wO(e):`${wO(e)}[${e.zone.id}]`,lCe=(e,t,n)=>nSe(r=>$E(n?.local?dO(t,lO(),r):qSe(t,r),t=>aD(e,t))),uCe=sC(e=>ww(e[0]),(e,t,n)=>TT(t)?aD(e,t):lCe(e,Array.isArray(t)?QSe(...t):t,n)),dCe=ww,TO=oxe,EO=sxe,DO=ME,OO=IE,kO=FE,AO=RE,jO=BE,MO=uxe,NO=PE,PO=ixe,FO=LE,IO=axe,fCe=Zw,LO=$E,RO=zxe,zO=fD,BO=tD,VO=QE,HO=Pxe,UO=cD,WO=Fxe,pCe=Mxe,GO=Rxe,KO=Ixe,qO=qxe,JO=VD,mCe=uCe,YO=Dxe,XO=tSe,hCe=rSe,gCe=iSe,_Ce=hSe,ZO=gSe,vCe=KD(`Error`),yCe=wxe,QO=Cxe,bCe=fxe;var xCe=class extends hT()(`effect/Runtime/InterruptExitCode`){};const SCe=(e,t)=>{if(eO(e))return t(0);if(JD(e.cause)){let n=-1/0;for(let r of e.cause.reasons){let e=kT(FSe(r),xCe);if(e===void 0)return t(130);n=Math.max(n,e)}return t(n)}return t(wCe(XD(e.cause)))},CCe=e=>sC(e=>dCe(e[0]),(t,n)=>{let r=n?.disableErrorReporting===!0?t:pCe(t,e=>JD(e)?AO:TCe(XD(e))?vCe(e):AO),i=n?.teardown??SCe;_Ce(fCe(t=>{try{let e=globalThis.setInterval(dC,2147483647);t.addObserver(()=>{clearInterval(e)})}catch{}return e({fiber:t,teardown:i}),r}))}),wCe=e=>{if(typeof e==`object`&&e&&`~effect/Runtime/errorExitCode`in e){let t=e[`~effect/Runtime/errorExitCode`];if(typeof t==`number`)return t}return 1},TCe=e=>{if(typeof e==`object`&&e&&`~effect/Runtime/errorReported`in e){let t=e[`~effect/Runtime/errorReported`];if(typeof t==`boolean`)return t}return!0},ECe=CCe(({fiber:e,teardown:t})=>{let n=!1;e.addObserver(e=>{process.removeListener(`SIGINT`,r),process.removeListener(`SIGTERM`,r),t(e,e=>{(n||e!==0)&&process.exit(e)})});function r(){n=!0,e.interruptUnsafe(e.id)}process.on(`SIGINT`,r),process.on(`SIGTERM`,r)}),$O=`~effect/BigDecimal`,DCe={[$O]:$O,[TC](){let e=nk(this);return kC(NC(String(e.value)),MC(e.scale))},[VC](e){return OCe(e)&&FCe(this,e)===0},toString(){return`BigDecimal(${ICe(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[ow](){return this.toJSON()},pipe(){return iC(this,arguments)}},OCe=e=>wC(e,$O),kCe=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(DCe);return n.value=e,n.scale=t,n},ek=(e,t)=>{let n=kCe(e,t);return n.normalized=n,n},tk=BigInt(0),ACe=BigInt(1),jCe=BigInt(10),MCe=ek(tk,0),nk=e=>{if(e.normalized===void 0){if(e.value===tk)e.normalized=MCe;else{let t=`${e.value}`,n=NCe(t);e.normalized=ek(BigInt(t.slice(0,t.length-n)),e.scale-n)}}return e.normalized},NCe=e=>{let t=e.length;for(;e[t-1]===`0`;)t--;return e.length-t},PCe=[ACe],rk=(e,t)=>e===t?0:e<t?-1:1,ik=(e,t)=>{let n=`${e.value<tk?-e.value:e.value}`,r=`${t.value<tk?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==tk)return i<tk?-1:1;let a=Math.max(n.length,r.length);return Vye(n.padEnd(a,`0`),r.padEnd(a,`0`))},FCe=(e,t)=>{if(e.scale===t.scale)return rk(e.value,t.value);let n=ak(e),r=ak(t);if(n!==r)return n<r?-1:1;if(n===0)return 0;let i=e.scale-t.scale,a=Math.abs(i);if(a>100)return n===-1?ik(t,e):ik(e,t);let o=PCe[a]??=jCe**BigInt(a);return i>0?rk(e.value,t.value*o):rk(e.value*o,t.value)},ak=e=>e.value===tk?0:e.value<tk?-1:1,ICe=e=>{let t=nk(e);if(Math.abs(t.scale)>=16)return LCe(t);let n=t.value<tk,r=`${n?-t.value:t.value}`,i=t.scale>0?r.padStart(t.scale+1,`0`):r.padEnd(r.length-t.scale,`0`),a=i.length-t.scale,o=t.scale>0?`${i.slice(0,a)}.${i.slice(a)}`:i;return n?`-${o}`:o},LCe=e=>{if(RCe(e))return`0e+0`;let t=nk(e),n=`${t.value}`,r=t.value<tk?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},RCe=e=>e.value===tk,ok=new Uint8Array(123).fill(255);for(let e=0;e<64;e++)ok[`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.charCodeAt(e)]=e;ok[61]=0,{...cw},{...cw},{...Cw},cw.toString,cw[ow],{...Cw};function zCe(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}const sk=`~sentinels`,ck=`~constructor`,lk=fC(e=>{let t=zCe(e)?.identifier;return typeof t==`string`?t:e.getExpected(lk)}),uk=Symbol.for(`effect/schema/parser/missing`),dk=ISe,fk=dk(uk),pk=Object.assign(dk(uk),{[uk]:!0}),mk=e=>e[uk]===!0,hk=e=>e===uk?fT():pT(e),gk=e=>e._tag===`None`?fk:dk(e.value),_k=`~effect/SchemaIssue/Issue`;function vk(e){return wC(e,_k)&&e[_k]===_k}function BCe(e){return Object.hasOwn(e,`input`)}var yk=class{[_k]=_k;constructor(e,t){t?.reportInput===!0&&e!==uk&&(this.input=e)}};const VCe=class extends yk{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},HCe=class extends yk{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},bk=class extends yk{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},xk=class extends yk{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},Sk=class extends yk{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Ck=class extends yk{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},wk=class extends yk{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Tk=class extends yk{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Ek=class extends yk{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},UCe=class extends yk{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Dk(e,t,n){if(vk(e))return e;if(typeof e==`string`)return new Tk({message:e},t,n);let r=typeof e.issue==`string`?new Tk({message:e.issue},t,n):e.issue;return new bk(e.path,r)}function WCe(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Tk(void 0,t,n):Dk(e,t,n)}function GCe(e,t,n,r){return Array.isArray(t)?abe(t)?t.length===1?Dk(t[0],n,r):new Ck(e,obe(t,e=>Dk(e,n,r)),n,r):void 0:WCe(t,n,r)}const KCe=e=>{let t=Nk(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Ak(lk(e.ast),e);case`InvalidValue`:{let t=kk(e);if(t!==void 0)return Ak(t,e);let n=Ok(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Ok(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Ok(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},qCe=e=>Nk(e)??Nk(e.issue);function Ok(e){return BCe(e)?nw(e.input):void 0}function kk(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Ak(e,t){let n=Ok(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function JCe(e,t){let n=t(e);if(n!==void 0||e.issue._tag!==`InvalidValue`)return n;let r=kk(e.issue);return r===void 0?Ak(jk(e.filter),e):Ak(r,e.issue)}function jk(e){let t=e.annotations?.expected;if(typeof t==`string`)return t;switch(e._tag){case`Filter`:return`<filter>`;case`FilterGroup`:return e.checks.map(e=>jk(e)).join(` & `)}}function YCe(){return e=>Mk(e,``)}const XCe=YCe();function Mk(e,t,n){let r;switch(e._tag){case`Filter`:return Mk(e.issue,t,n??JCe(e,qCe));case`Encoding`:return Mk(e.issue,t,n);case`Pointer`:return Mk(e.issue,t+dye(e.path),n);case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>Mk(e,t,n)).join(`
271
+ `);r=n??Nk(e)??Ak(lk(e.ast),e);break;default:r=n??KCe(e)}return t?`${r}\n at ${t}`:r}function Nk(e){if(e._tag===`Pointer`||e._tag===`Composite`)return;if(e._tag===`Encoding`)return Nk(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function Pk(e){let t;for(let n of e.reasons){if(!MSe(n)||!vk(n.error))return;t??=n.error}return t}function Fk(e,t){let n=Pk(e);if(n===void 0)throw Error(t,{cause:e});return n}const Ik=e=>Object.assign(Object.create(aC),e),ZCe=Ik({_tag:`Passthrough`});function Lk(){return ZCe}function Rk(e){return Ik({_tag:`Transform`,transform:e})}function zk(e){return Ik({_tag:`TransformEffect`,transform:e})}function QCe(){return Rk(globalThis.String)}function Bk(){return Rk(globalThis.Number)}function $Ce(e){return zk((t,n)=>IO({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Tk({expected:`a valid JSON string`},t,n)}))}function ewe(e){return zk((t,n)=>IO({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new Tk({expected:`a JSON-serializable value`},t,n)}))}const twe=Symbol.for(`~effect/Schema/content`);function nwe(e,t){return Object.defineProperty(e,twe,{value:t}),e}const rwe=class extends oC{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new rwe(this.encode,this.decode)}},Vk=`~effect/SchemaTransformation/Transformation`,Hk=class extends oC{[Vk]=Vk;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Hk(this.encode,this.decode)}};function iwe(e){return wC(e,Vk)&&e[Vk]===Vk}const awe=e=>iwe(e)?e:new Hk(e.decode,e.encode),owe=new Hk(Lk(),Lk());function swe(){return owe}const Uk=new Hk(Bk(),QCe());function cwe(e){return new Hk($Ce(e??{}),nwe(ewe(e),{mediaType:`application/json`,preserveSchema:e?.reviver===void 0&&e?.replacer===void 0}))}function Wk(e){return t=>t._tag===e}const Gk=Wk(`Declaration`),lwe=Wk(`Never`),Kk=Wk(`Literal`),qk=Wk(`UniqueSymbol`),uwe=Wk(`Arrays`),dwe=Wk(`Objects`),Jk=Wk(`Suspend`),Yk=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},Xk={},Zk=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},Qk=`~effect/Schema`;var $k=class{[Qk]=Qk;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}};const eA=class extends $k{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>{if(t===uk)return fk;e??=this.run(this.typeParameters);try{return e(t,this,n)}catch(e){return FO(e)}}}_rebuild(e,t,n,r,i){let a=ej(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new eA(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},tA=new class extends $k{_tag=`Null`;getParser(){return cj(this,null)}getExpected(){return`null`}},fwe=class extends $k{_tag=`Undefined`;getParser(){return cj(this,void 0)}toCodecJson(){return qA(this,[pwe])}getExpected(){return`undefined`}},pwe=new Yk(tA,new Hk(Rk(()=>void 0),Rk(()=>null))),nA=new fwe,rA=new class extends $k{_tag=`Unknown`;getParser(){return lj(this,Xve)}getExpected(){return`unknown`}},iA=class extends $k{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${nw(e)}`);this.literal=e}getParser(){return cj(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?aA(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:aA(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function aA(e){let t=globalThis.String(e.literal);return qA(e,[new Yk(new iA(t),new Hk(Rk(()=>e.literal),Rk(()=>t)))])}const oA=new class extends $k{_tag=`String`;getParser(){return lj(this,bC)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&pj(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},mwe=class extends $k{_tag=`Number`;getParser(){return lj(this,xC)}matchKey(e,t){return this._match(Hwe,e,t)}matchPart(e,t){return this._match(dj,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:pj(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(sA(this.checks,`effect/schema/isFinite`)||sA(this.checks,`effect/schema/isInt`))?this:qA(this,[Dwe])}toCodecStringTree(){return this.toCodecJson()===this?qA(this,[Wwe]):qA(this,[Gwe])}getExpected(){return`number`}};function sA(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&sA(e.checks,t))}const cA=new mwe,hwe=new class extends $k{_tag=`Boolean`;getParser(){return lj(this,Kve)}getExpected(){return`boolean`}},lA=class extends $k{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(rj(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(rj(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}let c=e=>{let{input:t,len:r,options:i}=e;if(n.rest.length===0&&r>a)for(let o=a;o<r;o++){let r=new Sk(n,t[o],i),a=new bk([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return NO(new Ck(n,[a],t,i))}return e.issues?NO(new Ck(n,e.issues,t,i)):dk(e.output)},l=(e,t)=>{let r=e.length,i={ast:n,getParser:s,input:e,len:r,tailThreshold:Math.max(a,r-o),output:[],issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:AD(t.concurrency),f=d===1?_we(i,e,0,u):vwe(i,e,{concurrency:d,end:u});if(!f)return c(i);if(eD(f))return QO(f,()=>c(i));let p=!0;return OO(()=>p?(p=!1,LO(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===uk)return fk;try{return Array.isArray(e)?(r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)}))),l(e,a)):NO(new wk(n,e,a))}catch(e){return FO(e)}}}_rebuild(e,t,n){let r=ej(this.elements,e),i=ej(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new lA(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function gwe(e,t,n,r){if(n._tag===`Failure`)return dA(e,e.ast,r,n);let i=mk(n)?t:n[_w];if(i!==uk)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(rj(t.ast))return;let n=new bk([r],new xk(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return QD(new Ck(e.ast,[n],e.input,e.options))}}const uA={onItem(e,t,n){let r=n<e.len?t:uk;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:gwe},_we=jD()(uA),vwe=ND()(uA),dA=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=Pk(r.cause);if(i===void 0)return ZD(YD(r.cause,r=>new Ck(t,[new bk([n],r)],e.input,e.options)));let a=new bk([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return QD(new Ck(t,[a],e.input,e.options))},fA=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[Ee][+-]?\\d+)?`;function pA(e,t,n=Xk){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(r=>Object.prototype.propertyIsEnumerable.call(e,r)&&t.matchKey(r,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(uj(oj(t)))}const mA=class{name;type;constructor(e,t){this.name=e,this.type=t}};function hA(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(hA);default:return!1}}function gA(e){let t=YA(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(gA);default:return!1}}function ywe(e){return hA(e)&&gA(e)}const _A=class{parameter;type;constructor(e,t){if(!ywe(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,rj(t)||t.encoding!==void 0&&rj(oj(t)))throw Error("Cannot use `Schema.optionalKey` or `Schema.optional` with index signatures. Index signatures already allow keys to be absent; use `Schema.UndefinedOr` to allow `undefined` values.")}},vA=class extends $k{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o}getParser(e,t=e){let n=this,r=n.propertySignatures.length,i=n.indexSignatures.length;if(!r&&!i)return lj(n,Yve);let a,o,s=()=>(a||(a=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type,ownOnly:MA(e.name)})),o=i?n.indexSignatures.map(n=>({is:n,parserKey:e(uj(n.parameter)),parserValue:t(n.type)})):void 0),a),c=()=>{let e=new Set(n.propertySignatures.map(e=>typeof e.name==`number`?globalThis.String(e.name):e.name)),t=(t,i,a,o,s)=>{if(s._tag===`Failure`)return dA(t,n,i,s)??$D;let c=mk(s)?o:s[_w];if(a!==uk&&c!==uk){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return $D;pw(t.out,a,c)}return $D},c=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!eD(t))return LO(zO(t),t=>c(e,r,i,t));a=t}if(a._tag===`Failure`)return dA(e,n,r,a)??$D;let o=mk(a)?r:a[_w],s=e.input[r],l=i.parserValue(s,e.options);return eD(l)?t(e,r,o,s,l):LO(zO(l),n=>t(e,r,o,s,n))},l=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return eD(a)?t(e,n,n,i,a):LO(zO(a),r=>t(e,n,n,i,r))},u=i?ND()({onItem:(e,[t,n])=>n.is.parameter===oA?l(e,t,n):c(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return bCe(function*(t,d){if(t===uk)return uk;if(typeof t!=`object`||!t||Array.isArray(t))return yield*NO(new wk(n,t,d));s();let f=t,p={},m={ast:n,input:f,out:p,issues:void 0,options:d},h=d.errors===`all`,g=d.onExcessProperty===`error`,_=d.concurrency===void 0?1:AD(d.concurrency),v=i&&g?n.indexSignatures.map(e=>pA(f,e.parameter,d)):void 0;if(g){let r=v?new Set(e):e;if(v)for(let e of v)for(let t of e)r.add(t);let i=Reflect.ownKeys(f);for(let e=0;e<i.length;e++){let a=i[e];if(!r.has(a)&&Object.prototype.propertyIsEnumerable.call(f,a)){let e=new Sk(n,f[a],d),r=new bk([a],e);if(h){m.issues?m.issues.push(r):m.issues=[r];continue}return yield*NO(new Ck(n,[r],t,d))}}}if(r){let e=_===1?xA(m,a):bwe(m,a,{concurrency:_});e&&(yield*e)}if(i&&_===1)for(let e=0;e<i;e++){let t=o[e],n=t.is.parameter===oA?l:c,r=v?.[e]??(t.is.parameter===oA?Object.keys(f):pA(f,t.is.parameter,d));for(let e=0;e<r.length;e++){let i=n(m,r[e],t);if(!eD(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(u){let e=BT();for(let t=0;t<i;t++){let n=o[t],r=v?.[t]??(n.is.parameter===oA?Object.keys(f):pA(f,n.is.parameter,d));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=u(m,e,{concurrency:_});t&&(yield*t)}return m.issues?yield*NO(new Ck(n,m.issues,t,d)):p})};if(i)return c();let l,u=(e,t,n)=>{let r=a[t];return LO(zO(n),n=>{let i={...e,out:{...e.out}},o=yA(i,r,n);if(o)return o;let s=()=>dk(i.out),c=xA(i,a.slice(t+1));return c?QO(c,s):s()})};return(e,t)=>{if(e===uk)return fk;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&AD(t.concurrency)!==1)return(l??=c())(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return NO(new wk(n,e,t));let r=s(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=n.ownOnly?Object.hasOwn(i,s):s in i,l=c?i[s]:uk,d=n.parser(l,t);if(!eD(d))return u(o,e,d);if(mk(d)){c&&pw(a,s,l);continue}let f=yA(o,n,d);if(f)return f}}catch(e){return FO(e)}return dk(a)}}_rebuild(e,t,n,r){let i=ej(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new mA(t.name,n)}),a=ej(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new _A(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new vA(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function yA(e,t,n){if(n._tag===`Failure`)return dA(e,e.ast,t.name,n);if(mk(n))return;let r=n[_w];if(r!==uk){pw(e.out,t.name,r);return}if(delete e.out[t.name],!rj(t.type)){let n=new bk([t.name],new xk(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return QD(new Ck(e.ast,[n],e.input,e.options))}}const bA={onItem(e,t){if(!(t.ownOnly?Object.hasOwn(e.input,t.name):t.name in e.input))return t.parser(uk,e.options);let n=e.input[t.name];return pw(e.out,t.name,n),t.parser(n,e.options)},step:yA},xA=jD()(bA),bwe=ND()(bA);function SA(e,t){return e?t?[...e,...t]:e:t}function CA(e,t,n){return new vA(Reflect.ownKeys(e).map(t=>new mA(t,e[t].ast)),[],n,t)}function xwe(e){return e.ast}function wA(e,t=void 0){return new lA(!1,e.map(e=>e.ast),[],void 0,t)}function TA(e,t,n){return new PA(e.map(xwe),t,void 0,n)}const EA=pC(e=>{for(;;){if(Jk(e))return rA;let t=e.encoding;if(!t)return e.recur?.(EA,cC)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==cC))return rA;e=t[t.length-1].to}});function DA(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(DA)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function OA(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[sk];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!rj(t)){if(Kk(t))return[{key:e.name,literal:t.literal}];if(qk(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!rj(e)){if(Kk(e))return[{key:t,literal:e.literal}];if(qk(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>OA(EA(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return OA(e.thunk())}}const kA=new WeakMap,AA=Object.freeze([]),jA=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,Swe=new Set(Reflect.ownKeys(Object.prototype)).add(`__proto__`),MA=e=>Swe.has(typeof e==`number`?globalThis.String(e):e),NA=(e,t)=>Object.hasOwn(e,t)||t in e&&!MA(t);function Cwe(e){let t=kA.get(e);if(t)return t;let n,r=0,i,a,o=!0,s=[];for(let t=0;t<e.length;t++){let c=e[t],l=EA(c);if(lwe(l))continue;if(Kk(l)||qk(l)){a??=new Map;let e=Kk(l)?l.literal:l.symbol;s[t]=e;let n=a.get(e);n||a.set(e,n=[]),n.push(t)}else o=!1;let u=OA(l);if(u.length){n??=new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=DA(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??AA);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??AA;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=new Map;for(let[e,t]of i)a.set(e,Object.freeze(Array.from(t)));let o=Object.freeze(e.map((e,t)=>t));t=(e,t)=>{if(CC(e)){let n=NA(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??AA;if(t)return o}return AA}}else if(n){let e;for(let t of n)(!e||t[1][0].size>e[1][0].size)&&t[1][1].size===r&&(e=t);t=(t,r)=>{let a=jA(t);if(!CC(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=NA(t,n),u=c?t[n]:void 0;if(c&&(!r||u!==void 0)){let e=i.get(u);if(!e)return l(a);for(let t of e)o.add(t);s=n}}if(s===void 0)for(let[e,[i,a]]of n){let n=NA(t,e),s=n?t[e]:void 0;if(n&&(!r||s!==void 0)){let e=i.get(s);if(e)for(let t of e)o.add(t)}else if(r)for(let e of a)o.add(e)}for(let[e,[i,a]]of n){if(e===s)continue;let n=NA(t,e),c=n?t[e]:void 0;if(n&&(!r||c!==void 0)){let e=i.get(c);for(let t of o)a.has(t)&&!e?.has(t)&&o.delete(t)}}return Array.from(o).sort((e,t)=>e-t)}}else t=e=>{let t=l(jA(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return kA.set(e,t),t}const PA=class extends $k{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this,r=t!==void 0,i=[],a=t=>i[t]??=e(n.types[t]),o;return(e,t)=>{if(e===uk)return fk;let i=(o??=Cwe(n.types))(e,r);if(i.length===0)return NO(new Ek(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:eD(r)?FA(n,r.cause,e,t):wwe(n,r,e,t)}return IA(n,a,i,e,t)}}_rebuild(e,t,n){let r=ej(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new PA(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=oj(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Kk);if(t.length>0)return`${zA(n.isMutable)}[ ${t.map(t=>e(t)+BA(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Kk(e.type));if(t.length>0)return`{ ${t.map(t=>`${zA(t.type.context?.isMutable)}${rw(t.name)}${BA(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function FA(e,t,n,r){let i=Pk(t);return i?QD(new Ek(e,[i],n,r)):ZD(t)}function wwe(e,t,n,r){return UO(t,t=>FA(e,t,n,r))}function IA(e,t,n,r,i){let a={ast:e,parser:t,input:r,out:void 0,successes:e.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},o=Twe(a,n);if(!o)return a.out?a.out:NO(new Ek(e,a.issues??[],r,i));if(eD(o))return LA(o,a);let s=!0;return OO(()=>s?(s=!1,LA(o,a)):IA(e,t,n,r,i))}function LA(e,t){return QO(e,e=>t.out?mk(t.out)?DO(t.input):t.out:NO(new Ek(t.ast,t.issues??[],t.input,t.options)))}const Twe=jD()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=Pk(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(e.ast.types[t]),QD(new UCe(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return $D}}}),RA=new PA([new iA(`Infinity`),new iA(`-Infinity`),new iA(`NaN`)]);function zA(e){return e?``:`readonly `}function BA(e){return e?`?`:``}const VA=class extends oC{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new VA(this.run,{...this.annotations,...e},this.aborted)}abort(){return new VA(this.run,this.annotations,!0)}and(e,t){return new HA([this,e],t)}},HA=class extends oC{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new HA(this.checks,{...this.annotations,...e})}and(e,t){return new HA([this,e],t)}};function UA(e,t,n=!1){return new VA((t,n,r)=>GCe(n,e(t,n,r),t,r),t,n)}function Ewe(e){return UA(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}const Dwe=new Yk(new PA([QA(cA,[Ewe()]),RA]),new Hk(Bk(),Rk(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function Owe(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return UA(e=>(n.lastIndex=0,n.test(e)),{expected:`a string matching the RegExp ${r.source}`,representation:{id:`effect/schema/isPattern`,payload:r},toJsonSchema:()=>[{},!0],arbitraryConstraint:{patterns:[r]},...t})}const WA=new WeakMap;function GA(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&WA.set(n,KA(e)),n}function KA(e){let t=WA.get(e);if(t!==void 0)return t;if(e.encoding===void 0)return e;let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,{encoding:void 0});return WA.set(e,n),n}function qA(e,t){return e.encoding===t?e:GA(e,{encoding:t})}function JA(e,t){if(e.context===t)return e;let n=KA(e);return n.context===t&&n.encoding===e.encoding?n:GA(e,{context:t})}function YA(e){return e.encoding?YA(e.encoding[e.encoding.length-1].to):e}function XA(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return ZA(e,zT(e.checks.slice(0,-1),n.annotate(t)))}return GA(e,{annotations:{...e.annotations,...t}})}function ZA(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:GA(e,{checks:t})}function QA(e,t){return ZA(e,SA(e.checks,t))}function kwe(e,t){let n=t(e.to);return n===e.to?e:new Yk(n,e.transformation)}function $A(e,t){let n=e,r=n[n.length-1],i=kwe(r,t);return i===r?e:zT(e.slice(0,e.length-1),i)}function Awe(e){return t=>t.encoding?qA(t,$A(t.encoding,e)):t}function jwe(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:qA(r,$A(r.encoding,n))}return e(r)}return pC(n)}function Mwe(e,t,n){let r=new Yk(e,t);return qA(n,n.encoding?[...n.encoding,r]:[r])}function ej(e,t){let n;for(let r=0;r<e.length;r++){let i=e[r],a=t(i);if(n)n[r]=a;else if(a!==i){n=Array(e.length);for(let t=0;t<r;t++)n[t]=e[t];n[r]=a}}return n??e}function tj(e,t){return JA(e,e.context?new Zk(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new Zk(!1,!1,void 0,t))}const nj=pC(e=>{let t=e.context?e.context.isOptional===!1?new Zk(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new Zk(!0,!1);return Nwe(JA(e,t))}),Nwe=Awe(nj),Pwe=fC(e=>nj(new PA([e,nA])));function Fwe(e,t){return JA(e,e.context?new Zk(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new Zk(!1,!1,t))}function Iwe(e,t,n){return Mwe(e,n,t)}function Lwe(e){let t=[],n=[];function r(e){t.includes(e)||t.push(e)}function i(e){switch(e._tag){case`Literal`:Jve(e.literal)&&r(e.literal);return;case`UniqueSymbol`:r(e.symbol);return;case`Enum`:for(let[,t]of e.enums)r(t);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)i(e.types[t]);return;default:n.push(e)}}return i(e),{literals:t,parameters:n}}function Rwe(e,t){let{literals:n,parameters:r}=Lwe(e);return new vA(n.map(e=>new mA(e,t)),r.map(e=>new _A(e,t)))}function rj(e){return e.context?.isOptional??!1}function ij(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(ij)}function zwe(e){function t(e){return ij(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return ibe(n)?n:void 0}function Bwe(e){let t=!0;function n(e){return t=t&&!e.encoding&&!Jk(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}const aj=pC(e=>{let t=KA(e);if(t!==e){let n=aj(t);return n===t&&e.encoding===void 0?e:JA(n,e.context)}let n=`recur`in e?e.recur(aj):e;return`encodingChecks`in n&&n.encodingChecks?GA(n,{encodingChecks:void 0,checks:SA(Bwe(e)?n.encodingChecks:uwe(n)||dwe(n)||Gk(n)&&n.typeParameters.length>0?zwe(n.encodingChecks):void 0,n.checks)}):n}),oj=pC(e=>aj(sj(e)));function Vwe(e,t){let n=t,r=n.length,i=n[r-1],a=[new Yk(sj(qA(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new Yk(sj(n[e-1].to),n[e].transformation.flip()));let o=sj(i.to);return o.encoding?qA(o,[...o.encoding,...a]):qA(o,a)}const sj=fC(e=>{if(e.encoding)return Vwe(e,e.encoding);let t=KA(e);if(t!==e){let n=sj(t);return n===t?e:JA(n,e.context)}return`flip`in e?e.flip(sj):`recur`in e?e.recur(sj):e});function cj(e,t){let n=t===0?pk:dk(t);return(r,i)=>r===uk?fk:r===t?n:NO(new wk(e,r,i))}function lj(e,t){return(n,r)=>n===uk?fk:t(n)?pk:NO(new wk(e,n,r))}const uj=jwe(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(uj)}}),dj=new globalThis.RegExp(`^${fA}$`),Hwe=new globalThis.RegExp(`^(?:${fA}|Infinity|-Infinity|NaN)$`);function Uwe(e){return Owe(dj,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:dj.source}),...e})}const fj=QA(oA,[Uwe()]),Wwe=new Yk(fj,Uk),Gwe=new Yk(new PA([fj,RA]),Uk);function pj(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=pj(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new VCe(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function mj(e){if(!Gk(e))return;let t=e.annotations?.[ck];return SC(t)?t(e.typeParameters):void 0}const hj=(e,t,n)=>mk(e)?n(t):QO(e,n);function gj(e){let t=Kwe(e);return(e,n,r)=>{try{return t(e,n,r)}catch(e){return FO(e)}}}function Kwe(e){if(e._tag===`Middleware`)return(t,n,r)=>{let i=mk(t)?e.decode(dk(hk(n)),r):e.decode(yCe(t,hk),r);return _j(i)};let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>mk(e)?dk(t):e;case`Transform`:{let e=e=>e===uk?fk:dk(t.transform(e));return(t,n)=>hj(t,n,e)}case`TransformOptional`:{let e=e=>gk(t.transform(hk(e)));return(t,n)=>hj(t,n,e)}case`TransformEffect`:return(e,n,r)=>hj(e,n,e=>e===uk?fk:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>hj(e,n,e=>_j(t.transform(hk(e),r)))}}const _j=e=>QO(e,gk),vj=(e,t,n,r)=>UO(r,r=>PO(()=>YD(r,r=>new HCe(e,r,t,n))));function qwe(e,t){let n=gj(e.link.transformation),r;return(i,a)=>{if(i===uk)return fk;if(e.isConstructed(i))return pk;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function Jwe(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==uk&&r!==void 0)return t(r,i);let a=n;if(eD(a)&&a._tag===`Success`){let e=t(a[_w],i);return mk(e)?a:e}return QO(vj(e,r,i,a),e=>{let n=t(e,i);return mk(n)?dk(e):n})}}function Ywe(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:Jwe(e,n)}function yj(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?mj(e):void 0,o=a?qwe(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>gj(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);try{if(u&&!n.disableChecks){if(eD(r)){if(r._tag===`Success`){let i=mk(r)?t:r[_w];if(t!==uk&&i!==uk){let i=pj(u,t,void 0,e,n);i&&(r=NO(new Ck(e,i,t,n)))}}}else r=LO(r,r=>{if(t!==uk&&r!==uk){let r=pj(u,t,void 0,e,n);if(r)return NO(new Ck(e,r,t,n))}return DO(r)})}if(s&&!n.disableChecks){if(eD(r)){if(r._tag===`Success`){let i=mk(r)?t:r[_w];if(i===uk)return r;let a=pj(s,i,void 0,e,n);a&&(r=NO(new Ck(e,a,i,n)))}}else r=LO(r,t=>{if(t!==uk){let r=pj(s,t,void 0,e,n);if(r)return NO(new Ck(e,r,t,n))}return DO(t)})}return r}catch(e){return FO(e)}},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[_w],o=t(a,r)):o=QO(o,e=>{let n=t(e,r);return mk(n)?dk(e):n})}if(o._tag===`Success`){let e=o[_w],t=p(e,r);return mk(t)?o:t}return o=vj(e,n,r,o),QO(o,e=>{let t=p(e,r);return mk(t)?dk(e):t})}:p}const Xwe=Symbol(),bj=new WeakMap,Zwe=e=>Sj(e).parser,xj=e=>Sj(e).makeEffect,Qwe=e=>Ywe(e,xj);var $we=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=yj(this.ast,Zwe)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=yj(this.ast,xj,Qwe)}};function Sj(e){let t=bj.get(e);if(t!==void 0)return t;let n=new $we(e);return bj.set(e,n),n}function Cj(e){let t=e.ast,n;return(e,r)=>(n??=Ej(lTe,aj(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function wj(e){let t=Cj(e);return(e,n)=>{let r=ZO(t(e,n));return eO(r)?pT(r.value):(Fk(r.cause,`Option adapter can only return none for schema issues`),fT())}}function eTe(e){return oTe(aj(e.ast))}function tTe(e,t){let n=rTe(e.ast);return t===void 0?n:(e,r)=>n(e,nTe(t,r))}const nTe=(e,t)=>t?{...e,...t}:e,Tj=e=>e===uk?NO(new Tk):DO(e);function rTe(e){return Ej(cTe,e)}function iTe(e,t){return mk(e)?DO(t):eD(e)?e[_w]===uk?Tj(uk):e:QO(e,Tj)}function Ej(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??Xk);return mk(a)?DO(r):eD(a)?a[_w]===uk?Tj(uk):a:QO(a,Tj)}}function aTe(e,t){let n=ZO(e);if(eO(n))return n.value;let r=Fk(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}const Dj=`Constructor adapter can only throw schema issues`;function Oj(e){throw Error(Dj,{cause:NSe(e)})}function oTe(e){let t;return(n,r)=>kj(t??=Sj(e),n,r)}function kj(e,t,n){let r=n?.disableChecks?n.parseOptions?{...n.parseOptions,disableChecks:!0}:{disableChecks:!0}:n?.parseOptions??Xk,i=e.make;if(i!==void 0&&t!==uk){let e;try{e=i(t,r)}catch(e){Oj(e)}if(e!==Xwe&&e!==uk)return e}return aTe(iTe(e.makeEffect(t,r),t),Dj)}function sTe(e,t,n,r){let i=Sj(e),a=mj(e);if(a===void 0||i.make!==void 0||i.compiledMakeEffect!==void 0)return kj(i,t,n);if(a.isConstructed(t))return t;let o=kj((i.resolve??Sj)(a.link.to),t,n);try{return r(o)}catch(e){Oj(e)}}const cTe=e=>Sj(e).parser,lTe=e=>Sj(e).makeEffect,Aj=`~effect/Schema/Schema`,jj=Symbol(),uTe={[Aj]:Aj,get make(){let e=eTe(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=Cj(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=wj(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return iC(this,arguments)},annotate(e){return this.rebuild(XA(this.ast,e))},annotateKey(e){return this.rebuild(tj(this.ast,e))},check(...e){return this.rebuild(QA(this.ast,e))},rebuild(e){return Mj(e,this[jj])}};function Mj(e,t){function n(){}let r=Object.setPrototypeOf(n,uTe);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r[jj]=t,r.ast=e,r}const Nj=e=>e,Pj=`~effect/Schema/SchemaError`;({...cw}),{...cw},{...cw},{...cw},{...cw},{...cw},{...cw},{...cw};const Fj=Aj;var Ij=class extends Mbe(`SchemaError`){[Pj]=Pj;constructor(e){let t=lw();uw(0);try{super({issue:e})}finally{uw(t)}}get message(){return XCe(this.issue)}toJSON(){return{_tag:this._tag,message:this.message}}[ow](){return this.toJSON()}toString(){return`SchemaError(${this.message})`}};function dTe(e){return eD(e)?fTe(e):UO(e,e=>PO(()=>YD(e,e=>new Ij(e))))}function fTe(e){return eO(e)?e:ZD(YD(e.cause,e=>new Ij(e)))}function pTe(e,t){let n=tTe(e,t);return(e,t)=>dTe(n(e,t))}const Lj=Mj;function mTe(e){return wC(e,Fj)&&e[Fj]===Fj}const Rj=Nj(e=>{let t=_Te(e);return Lj(Pwe(e.ast),{schema:t})});function zj(e){let t=Lj(new iA(e),{literal:e,transform(n){return t.pipe(eM(zj(n),{decode:Rk(()=>n),encode:Rk(()=>e)}))}});return t}const Bj=Lj(rA),hTe=Lj(tA),gTe=Lj(nA),Vj=Lj(oA),Hj=Lj(cA),Uj=Lj(hwe);function Wj(e,t){return Lj(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Wj(CA(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Gj(e){return Wj(CA(e,void 0),e)}function Kj(e,t){return Lj(Rwe(e.ast,t.ast),{key:e,value:t})}function qj(e,t){return Lj(e,{elements:t,mapElements(e,t){let n=e(this.elements);return qj(wA(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Jj(e){return qj(wA(e),e)}const Yj=Nj(e=>Lj(new lA(!1,[],[e.ast]),{value:e}));function Xj(e,t){return Lj(e,{members:t,mapMembers(e,t){let n=e(this.members);return Xj(TA(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Zj(e,t){return Xj(TA(e,t,void 0),e)}function Qj(e){let t=e.map(zj);return Lj(TA(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return Zj(e(this.members))},pick(e){return Qj(e)},transform(e){return Zj(t.map((t,n)=>t.transform(e[n])))}})}const $j=Nj(e=>Zj([e,hTe])),_Te=Nj(e=>Zj([e,gTe]));function eM(e,t){return n=>Lj(Iwe(n.ast,e.ast,t?awe(t):swe()),{from:n,to:e})}function vTe(e){return t=>Lj(Fwe(t.ast,e),{schema:t})}function tM(e){return zj(e).pipe(vTe(DO(e)))}function yTe(e,t){return Gj({_tag:tM(e),...t})}globalThis.RegExp,globalThis.URL;const bTe=Vj.annotate({expected:`a string that will be decoded as JSON`});function xTe(e,t){return bTe.pipe(eM(e,cwe(t)))}globalThis.File,globalThis.URLSearchParams,globalThis.Uint8Array;const STe=globalThis.Symbol.for(`immer-draftable`),nM={};function rM(e,t,n,r,i){let a=wTe(n,t,r),o=aM(t),s=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===nM?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:nM,value:i}})}static[Fj]=Fj;get[o](){return o}static[STe]=!0;static identifier=t;static fields=n.fields;static get ast(){return a(this).ast}static pipe(){return iC(this,arguments)}static rebuild(e){return a(this).rebuild(e)}static make(e,t){return sTe(aj(a(this).ast),e??{},t,e=>iM(this,e))}static makeOption(e,t){return wj(a(this))(e??{},t)}static makeEffect(e,t){return a(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(XA(this.ast,e))}static annotateKey(e){return this.rebuild(tj(this.ast,e))}static check(...e){return this.rebuild(QA(this.ast,e))}static extend(e){return(t,r)=>{let a=oM(t)?t:Gj(t),o={...n.fields,...a.fields},s=CA(o,n.ast.checks,{identifier:e});return rM(this,e,Wj(QA(s,a.ast.checks),o),r,i)}}static mapFields(e,t){return n.mapFields(e,t)}};return i!==void 0&&Object.assign(s.prototype,i(t)),s}function iM(e,t){return new e(t,{"~payload":{token:nM,value:t}})}function CTe(e){return new Hk(Rk(t=>iM(e,t)),Lk())}function aM(e){return`~effect/Schema/Class/${e}`}function wTe(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=aM(t),o=e=>e instanceof i||wC(e,a),s=CTe(i);return r=eM(Lj(new eA([e.ast],()=>(e,t,n)=>o(e)?DO(e):NO(new wk(t,e,n)),{identifier:t,[ck]:([e])=>({isConstructed:o,link:new Yk(e,s)}),toCodec:([e])=>new Yk(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[sk]:OA(e.ast),...n})),s)(e)}}function oM(e){return mTe(e)}const TTe=e=>(t,n)=>{let r=oM(t)?t:Gj(t);return rM(Qw,e,r,n,e=>({name:e}))},sM=e=>(t,n,r)=>{let i=oM(n)?n.mapFields(e=>({_tag:tM(t),...e}),{unsafePreserveChecks:!0}):yTe(t,n);return TTe(e??t)(i,r)};var cM=class extends sM()(`GuestError`,{operation:Vj,detail:Vj,timedOut:Rj(Uj),notStarted:Rj(Uj)}){get message(){return`guest ${this.operation}: ${this.detail}`}},lM=class extends hT()(`use-cloud-vms/linux-desktop/Guest`){};const ETe=String.raw`
272
+ for pid in "$@"; do
273
+ case $pid in ''|*[!0-9]*) printf '%s invalid\n' "$pid"; continue;; esac
274
+ if [ "$pid" -le 1 ]; then printf '%s invalid\n' "$pid"; continue; fi
275
+ if [ -r /proc/sys/kernel/random/boot_id ]; then
276
+ boot=$(cat /proc/sys/kernel/random/boot_id) || exit 3
277
+ if line=$(cat "/proc/$pid/stat" 2>/dev/null); then
278
+ rest=$(printf '%s\n' "$line" | sed 's/^.*) //')
279
+ set -- $rest
280
+ state=$1; ppid=$2; shift 19
281
+ printf '%s linux %s %s %s %s\n' "$pid" "$boot" "$state" "$ppid" "$1"
282
+ else
283
+ printf '%s absent\n' "$pid"
284
+ fi
285
+ else
286
+ if out=$(LC_ALL=C ps -o stat= -o ppid= -o lstart= -p "$pid" 2>/dev/null) && [ -n "$out" ]; then
287
+ set -- $out
288
+ state=$1; ppid=$2; shift 2
289
+ printf '%s ps - %s %s %s\n' "$pid" "$state" "$ppid" "$*"
290
+ else
291
+ printf '%s absent\n' "$pid"
292
+ fi
293
+ fi
294
+ done
295
+ `,DTe=String.raw`
296
+ pid=$1; want=$2; sig=$3
297
+ case $pid in ''|*[!0-9]*) echo invalid; exit 0;; esac
298
+ if [ "$pid" -le 1 ]; then echo invalid; exit 0; fi
299
+ if [ -r /proc/sys/kernel/random/boot_id ]; then
300
+ boot=$(cat /proc/sys/kernel/random/boot_id) || exit 3
301
+ line=$(cat "/proc/$pid/stat" 2>/dev/null) || { echo gone; exit 0; }
302
+ rest=$(printf '%s\n' "$line" | sed 's/^.*) //')
303
+ set -- $rest
304
+ state=$1; shift 19; have="$boot $1"
305
+ else
306
+ out=$(LC_ALL=C ps -o stat= -o ppid= -o lstart= -p "$pid" 2>/dev/null)
307
+ [ -n "$out" ] || { echo gone; exit 0; }
308
+ set -- $out
309
+ state=$1; shift 2; have="- $*"
310
+ fi
311
+ case $state in Z*) echo gone; exit 0;; esac
312
+ [ "$have" = "$want" ] || { echo changed; exit 0; }
313
+ if kill -s "$sig" "$pid" 2>/dev/null; then echo sent; else echo gone; fi
314
+ `,OTe=String.raw`
315
+ pid=$1; n=0
316
+ while [ "$pid" -gt 1 ] 2>/dev/null && [ "$n" -lt 64 ]; do
317
+ printf '%s\n' "$pid"
318
+ if [ -r "/proc/$pid/stat" ]; then
319
+ line=$(cat "/proc/$pid/stat" 2>/dev/null) || exit 0
320
+ rest=$(printf '%s\n' "$line" | sed 's/^.*) //')
321
+ set -- $rest
322
+ pid=$2
323
+ else
324
+ pid=$(LC_ALL=C ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')
325
+ [ -n "$pid" ] || exit 0
326
+ fi
327
+ n=$((n + 1))
328
+ done
329
+ `,kTe=String.raw`
330
+ for path in "$@"; do
331
+ if [ -e "$path" ] || [ -L "$path" ]; then printf 'present\n'; else printf 'absent\n'; fi
332
+ done
333
+ `,ATe=String.raw`
334
+ dir=$1; shift
335
+ for name in "$@"; do
336
+ resolved=$(readlink -f -- "$dir/$name" 2>/dev/null) || { printf 'missing %s\n' "$name"; exit 3; }
337
+ if [ -f "$resolved" ] && [ -x "$resolved" ]; then
338
+ printf 'tool %s %s\n' "$name" "$resolved"
339
+ else
340
+ printf 'missing %s\n' "$name"; exit 3
341
+ fi
342
+ done
343
+ `,jTe=String.raw`
344
+ lock=$1
345
+ content=$(head -c 64 -- "$lock") || exit 3
346
+ owner=$(LC_ALL=C ls -ln -- "$lock" | awk '{print $3}')
347
+ printf '%s\n%s\n' "$owner" "$content"
348
+ `,MTe=String.raw`
349
+ pid=$1; shift
350
+ [ -r "/proc/$pid/environ" ] || exit 0
351
+ tr '\000' '\n' < "/proc/$pid/environ" | while IFS= read -r line; do
352
+ for key in "$@"; do
353
+ case $line in "$key"=*) printf '%s\n' "$line";; esac
354
+ done
355
+ done
356
+ `,uM=(e,t)=>[`sh`,`-c`,e,`sh`,...t],NTe=(e,t)=>t.exitCode===0&&!t.timedOut?DO(t):NO(new cM({operation:e,detail:t.timedOut?`timed out`:`exit ${t.exitCode}: ${t.stderr.trim()||t.stdout.trim()}`,...t.timedOut?{timedOut:!0}:{}})),dM=(e,t,n,r)=>LO(YO(lM),i=>LO(i.run(uM(t,n),{timeoutMs:r}),t=>NTe(e,t))),fM=e=>`${e.boot} ${e.start}`,pM=(e,t)=>LO(dM(`identity`,ETe,e.map(String),t),t=>{let n=t.stdout.split(`
357
+ `).filter(e=>e.length>0);if(n.length!==e.length)return NO(new cM({operation:`identity`,detail:`expected ${e.length} records`}));let r=[];for(let[t,i]of n.entries()){let n=i.split(` `),a=e[t]??0;if(n[0]!==String(a))return NO(new cM({operation:`identity`,detail:`record for ${n[0]}`}));if(n[1]===`absent`)r.push({kind:`absent`});else if(n[1]===`invalid`)r.push({kind:`invalid`});else if((n[1]===`linux`||n[1]===`ps`)&&n.length>=6){let e=n[2]??``,t=n[3]??``,i=Number(n[4]),o={pid:a,start:n.slice(5).join(` `),boot:e};r.push(t.startsWith(`Z`)?{kind:`zombie`,identity:o}:{kind:`running`,identity:o,ppid:i})}else return NO(new cM({operation:`identity`,detail:`unreadable record ${i}`}))}return DO(r)}),PTe=(e,t,n)=>LO(dM(`signal`,DTe,[String(e.pid),fM(e),t],n),e=>{let t=e.stdout.trim();return t===`sent`||t===`gone`||t===`changed`||t===`invalid`?DO(t):NO(new cM({operation:`signal`,detail:`unreadable outcome ${t}`}))}),FTe=(e,t)=>BO(dM(`ancestry`,OTe,[String(e)],t),e=>e.stdout.split(`
358
+ `).filter(e=>/^\d+$/u.test(e)).map(Number)),mM=(e,t)=>LO(dM(`paths`,kTe,e,t),t=>{let n=t.stdout.split(`
359
+ `).filter(e=>e.length>0);return n.length===e.length&&n.every(e=>e===`present`||e===`absent`)?DO(n.map(e=>e===`present`)):NO(new cM({operation:`paths`,detail:`unreadable path states`}))}),ITe=(e,t,n)=>LO(YO(lM),r=>LO(r.run(uM(ATe,[e,...t]),{timeoutMs:n}),e=>{let n=e.stdout.split(`
360
+ `).filter(e=>e.length>0),r=n.find(e=>e.startsWith(`missing `));if(e.exitCode===3&&r!==void 0)return DO({kind:`missing`,name:r.slice(8)});if(e.exitCode!==0||e.timedOut)return NO(new cM({operation:`tools`,detail:`exit ${e.exitCode}`}));let i={};for(let e of n){let[,t,...n]=e.split(` `);t!==void 0&&(i[t]=n.join(` `))}return t.every(e=>i[e]!==void 0)?DO({kind:`resolved`,tools:i}):NO(new cM({operation:`tools`,detail:`incomplete tool list`}))})),hM=(e,t)=>BO(dM(`lock`,jTe,[e],t),e=>{let[t=``,...n]=e.stdout.split(`
361
+ `);return{ownerUid:t,content:n.join(`
362
+ `)}}),LTe=(e,t,n)=>BO(dM(`environ`,MTe,[String(e),...t],n),e=>{let t={};for(let n of e.stdout.split(`
363
+ `)){let e=n.indexOf(`=`);e>0&&(t[n.slice(0,e)]=n.slice(e+1))}return t}),RTe=e=>BO(dM(`uid`,`id -u`,[],e),e=>e.stdout.trim()),gM=(e,t,n)=>VO(dM(`mkdir`,t?`mkdir -p -- "$1" && chmod 700 "$1"`:`mkdir -m 700 -- "$1"`,[e],n)),zTe=(e,t)=>VO(dM(`rm`,`rm -f -- "$1"`,[e],t)),BTe=Gj({path:Vj,bytes:Hj,sha256:Vj});var _M=class extends sM()(`Unavailable`,{reason:Vj,nativeExit:Rj(Hj),deadline:Rj(Uj),retire:Rj(Uj),log:Rj(BTe)}){};const z=(e,t)=>NO(new _M(t===void 0?{reason:e}:{reason:e,nativeExit:t})),vM=e=>new _M({reason:e.reason,retire:!0,...e.nativeExit===void 0?{}:{nativeExit:e.nativeExit},...e.deadline===void 0?{}:{deadline:e.deadline}}),yM=Gj({pid:Hj,start:Vj,boot:Vj});Gj({id:Vj,pid:Hj,title:Vj,x:Hj,y:Hj,width:Hj,height:Hj,gtk_frame_extents:Jj([Hj,Hj,Hj,Hj]),net_frame_extents:Jj([Hj,Hj,Hj,Hj])});const bM={argv:Yj(Vj),home:Vj,log:Vj,launched_at:Vj},xM={...bM,identity:yM,phase:Qj([`running`,`closed`,`ended`,`terminated`,`unresolved`]),ended:Rj(Bj)},SM=Gj(xM),VTe=Zj([Gj({...xM,previous:Rj(Yj(SM))}),Gj({...bM,pid:$j(Hj),phase:zj(`unidentified`),reason:Vj,previous:Rj(Yj(SM))})]),CM={dir:Vj,log:Vj},HTe=Gj({...CM,phase:zj(`ready`),address:Vj,processes:Gj({holder:yM,bus:yM,daemon:yM}),ready_at:Vj}),UTe=Gj({pid:$j(Hj),reason:Vj}),WTe=Zj([HTe,Gj({...CM,phase:Qj([`starting`,`stopping`,`stopped`,`failed`]),address:Rj(Vj),processes:Kj(Vj,yM),unidentified:Rj(Kj(Vj,UTe)),reason:Rj(Vj),ended:Rj(Bj)})]),GTe=pTe(xTe(Gj({schema:zj(`use-cloud-vms/linux-desktop/session@1`),run_id:Vj,guest:Vj,kind:Qj([`owned`,`adopted`]),phase:Qj([`starting`,`ready`,`stopping`,`stopped`,`released`,`failed`]),display:Vj,dimensions:Jj([Hj,Hj]),geometry:Vj,x11_dir:Vj,guest_dir:Vj,tools:Kj(Vj,Vj),probe_timeout_s:Hj,ready_timeout_s:Hj,shutdown_timeout_s:Hj,lock_owner_uid:Vj,children:Kj(Vj,yM),x_server:Rj(yM),window_manager:Rj(yM),xfce:Rj(yM),connection:Kj(Vj,Vj),apps:Kj(Vj,VTe),keyring:Rj(WTe),observed:Rj(Bj),ready_at:Rj(Vj),reason:Rj(Vj),ended:Rj(Bj),guest_retirement_required:Uj}))),wM=e=>d(e,`session.json`),TM=e=>TO(async()=>{try{return await _e(e),!0}catch(e){if(e instanceof Error&&`code`in e&&e.code===`ENOENT`)return!1;throw e}}),EM=e=>EO({try:async()=>{await ve(e,{mode:448}),await ve(d(e,`probes`),{mode:448})},catch:e=>new _M({reason:`could not create the state directory: ${String(e)}`})}),DM=(e,t)=>EO({try:async()=>{let n=d(l(e),`.${s(e)}.${b()}`);try{await Ce(n,`${JSON.stringify(t,null,2)}\n`,{flag:`wx`,mode:384}),await be(n,e)}finally{await Se(n).catch(()=>void 0)}},catch:t=>new _M({reason:`could not write ${e}: ${String(t)}`})}),OM=(e,t)=>EO({try:async()=>{let n=d(l(e),`.${s(e)}.${b()}`);await Ce(n,t,{flag:`wx`,mode:384});try{await ge(n,e)}finally{await Se(n)}},catch:t=>new _M({reason:`could not publish ${e}: ${String(t)}`})}),kM=(e,t)=>OM(e,new TextEncoder().encode(`${JSON.stringify(t,null,2)}\n`)),AM=e=>LO(EO({try:()=>ye(wM(e),`utf8`),catch:e=>new _M({reason:`no readable session record: ${String(e)}`})}),e=>GTe(e).pipe(WO(()=>new _M({reason:`session record is not a linux-desktop session`})))),jM=(e,t)=>DM(wM(e),t),MM=BO($Se,e=>new Date(e).toISOString()),NM=BO(eCe,e=>Number(e/1000000n)),PM=e=>BO(NM,t=>({endMs:t+e*1e3})),FM=(e,t)=>LO(NM,n=>{let r=e.endMs-n;return r<=0?NO(new _M({reason:`operation deadline exhausted`,deadline:!0})):DO(Math.min(t*1e3,r))}),KTe=e=>t=>HO(t,`Unavailable`,t=>NO(t.deadline===!0?new _M({reason:e,deadline:!0}):t)),IM=[`dbus-daemon`,`gnome-keyring-daemon`,`dbus-send`],qTe=String.raw`
364
+ dir=$1; run=$2; bus_tool=$3; daemon_tool=$4
365
+ umask 077
366
+ bus=
367
+ daemon=
368
+ finish() {
369
+ for pid in $daemon $bus; do kill -TERM "$pid" 2>/dev/null; done
370
+ wait
371
+ exit "$1"
372
+ }
373
+ trap 'finish 143' TERM INT HUP
374
+ services=$XDG_DATA_HOME/dbus-1/services
375
+ mkdir -p -- "$HOME" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" "$services" "$XDG_RUNTIME_DIR" "$dir/control" || exit 70
376
+ for name in ${[`org.freedesktop.secrets`,`org.gnome.keyring`,`org.freedesktop.impl.portal.Secret`,`org.gnome.keyring.SystemPrompter`,`org.gnome.keyring.PrivatePrompter`].join(` `)}; do
377
+ printf '[D-BUS Service]\nName=%s\nExec=/bin/false\n' "$name" > "$services/$name.service" || exit 70
378
+ done
379
+ mkfifo "$dir/bus.fifo" || exit 70
380
+ "$bus_tool" --session --nofork --print-address=3 3> "$dir/bus.fifo" &
381
+ bus=$!
382
+ head -n 1 < "$dir/bus.fifo" > "$dir/bus.address" &
383
+ wait $!
384
+ IFS= read -r address < "$dir/bus.address" || address=
385
+ [ -n "$address" ] || finish 70
386
+ DBUS_SESSION_BUS_ADDRESS=$address
387
+ export DBUS_SESSION_BUS_ADDRESS
388
+ head -c 32 /dev/urandom | base64 | "$daemon_tool" --foreground --components=secrets --control-directory "$dir/control" --unlock &
389
+ daemon=$!
390
+ tmp="$dir/.connection.$$"
391
+ {
392
+ printf 'RUN_ID=%s\n' "$run"
393
+ printf 'HOLDER=%s\n' "$$"
394
+ printf 'BUS=%s\n' "$bus"
395
+ printf 'DAEMON=%s\n' "$daemon"
396
+ printf 'ADDRESS=%s\n' "$address"
397
+ } > "$tmp" && mv -f "$tmp" "$dir/connection" || finish 70
398
+ wait "$daemon"
399
+ printf '%s\n' "$?" > "$dir/daemon.exit"
400
+ daemon=
401
+ kill -TERM "$bus" 2>/dev/null
402
+ wait "$bus"
403
+ exit 0
404
+ `,JTe=String.raw`
405
+ send=$1; daemon=$2; reply_ms=$3; mode=$4
406
+ last() { awk 'NF { v = $NF } END { print v }'; }
407
+ call() { "$send" --session --print-reply=literal --reply-timeout="$reply_ms" "$@" 2>&1; }
408
+ report() {
409
+ if [ "$3" -eq 0 ]; then
410
+ printf '%s %s\n' "$1" "$(printf '%s\n' "$2" | last)"
411
+ else
412
+ error=$(printf '%s\n' "$2" | sed -n 's/^Error \([^:]*\):.*$/\1/p' | head -n 1)
413
+ [ -n "$error" ] || error=unreachable
414
+ printf '%s !%s\n' "$1" "$error"
415
+ fi
416
+ }
417
+ out=$(call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetConnectionUnixProcessID string:org.freedesktop.DBus)
418
+ report bus "$out" $?
419
+ out=$(call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.freedesktop.secrets)
420
+ rc=$?; report owner "$out" $rc; [ "$rc" -eq 0 ] || exit 0
421
+ name=$(printf '%s\n' "$out" | last)
422
+ out=$(call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetConnectionUnixProcessID "string:$name")
423
+ rc=$?; report owner_pid "$out" $rc; [ "$rc" -eq 0 ] || exit 0
424
+ [ "$(printf '%s\n' "$out" | last)" = "$daemon" ] || exit 0
425
+ for alias in default login; do
426
+ out=$(call --dest=org.freedesktop.secrets /org/freedesktop/secrets org.freedesktop.Secret.Service.ReadAlias "string:$alias")
427
+ report "alias_$alias" "$out" $?
428
+ done
429
+ out=$(call --dest=org.freedesktop.secrets /org/freedesktop/secrets/collection/login org.freedesktop.DBus.Properties.Get string:org.freedesktop.Secret.Collection string:Locked)
430
+ report locked "$out" $?
431
+ if [ "$mode" = start ]; then
432
+ out=$(call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.StartServiceByName string:org.gnome.keyring.SystemPrompter uint32:0)
433
+ report prompter "$out" $?
434
+ fi
435
+ `,LM=e=>e===void 0||e.startsWith(`!`)?void 0:e,RM=(e,t,n)=>{let r=LM(e.bus);if(r===void 0)return{kind:`pending`,reason:`the keyring bus did not answer (${e.bus??`no reply`})`};if(r!==String(t.bus.pid))return{kind:`wrong`,reason:`the keyring bus address answers as process ${r}, not the bus the holder started (${t.bus.pid})`};let i=LM(e.owner_pid);if(LM(e.owner)===void 0||i===void 0)return{kind:`pending`,reason:`no process owns org.freedesktop.secrets on the keyring bus`};if(i!==String(t.daemon.pid))return{kind:`wrong`,reason:`org.freedesktop.secrets on the keyring bus is owned by process ${i}, not the keyring daemon ${t.daemon.pid}`};for(let t of[`default`,`login`])if(e[`alias_${t}`]!==`/org/freedesktop/secrets/collection/login`)return{kind:`pending`,reason:`the ${t} alias does not name the login collection`};return e.locked===`false`?n===`start`&&e.prompter!==`!org.freedesktop.DBus.Error.Spawn.ChildExited`?{kind:`wrong`,reason:`the keyring bus could start an unlock prompter (${e.prompter??`no reply`}): its service masks are not in effect`}:{kind:`ready`}:{kind:`pending`,reason:`the login collection is not unlocked`}},zM=(e,t,n,r,i,a)=>MO(function*(){let o=yield*lM,s=yield*FM(r,e.probe_timeout_s),c=yield*o.run(uM(JTe,[e.tools[`dbus-send`]??``,String(n.pid),String(Math.max(1,Math.floor(s/2))),a]),{timeoutMs:s,env:{DBUS_SESSION_BUS_ADDRESS:t,LC_ALL:`C`},unsetEnv:i}).pipe(WO(UM(`keyring check could not run`)));if(c.timedOut||c.exitCode!==0)return yield*z(`keyring check failed (exit ${c.exitCode})`);let l={};for(let e of c.stdout.split(`
436
+ `)){let t=e.indexOf(` `);t>0&&(l[e.slice(0,t)]=e.slice(t+1))}return l}),BM=e=>({dir:d(e,`keyring`),log:d(e,`logs`,`keyring.log`)}),VM=(e,t)=>{let n=d(t,`home`);return{...e.DISPLAY===void 0?{}:{DISPLAY:e.DISPLAY},...e.XAUTHORITY===void 0?{}:{XAUTHORITY:e.XAUTHORITY},HOME:n,XDG_CONFIG_HOME:d(n,`.config`),XDG_CACHE_HOME:d(n,`.cache`),XDG_DATA_HOME:d(n,`.local/share`),XDG_RUNTIME_DIR:d(t,`runtime`)}},YTe=e=>{let t={};for(let n of e.split(`
437
+ `)){let e=n.indexOf(`=`);e>0&&(t[n.slice(0,e)]=n.slice(e+1))}return t},HM=e=>{let t=Number(e);return Number.isInteger(t)&&t>1?t:void 0},UM=e=>t=>new _M({reason:`${e}: ${t.message}`}),WM=(e,t,n)=>LO(FM(t,n),t=>pM(e,t).pipe(WO(UM(`keyring process identity read failed`)))),GM=e=>MO(function*(){let t=yield*lM,{stateDir:n,deadline:r,session:i}=e,{dir:a,log:o}=BM(i.guest_dir),s=(e,t)=>({...i,keyring:{phase:`starting`,dir:a,log:o,processes:e,...t===void 0?{}:{unidentified:{holder:t}}}});yield*gM(a,!1,yield*FM(r,i.probe_timeout_s)).pipe(WO(UM(`keyring directory setup failed`))),yield*jM(n,s({},{pid:null,reason:`its start was requested, but no process id was recorded`}));let c=yield*RO(t.start([`/bin/sh`,`-c`,qTe,`sh`,a,i.run_id,i.tools[`dbus-daemon`]??``,i.tools[`gnome-keyring-daemon`]??``],{env:e.env,unsetEnv:e.unsetEnv,cwd:a,logPath:o}));if(c._tag===`Failure`){if(c.failure.notStarted===!0)return yield*jM(n,s({})).pipe(GO),yield*z(`keyring holder could not start: ${c.failure.message}`);let e=`its start may have run, but returned no process id: ${c.failure.message}`;return yield*jM(n,s({},{pid:null,reason:e})).pipe(GO),yield*NO(new _M({reason:`keyring holder: ${e}; it cannot be signalled, so the guest must be retired`,retire:!0}))}return yield*XTe(e,s,c.success).pipe(WO(vM))}),XTe=(e,t,n)=>MO(function*(){let r=yield*lM,{stateDir:i,deadline:a,session:o}=e,s=o.probe_timeout_s,{dir:c,log:l}=BM(o.guest_dir);yield*jM(i,t({},{pid:n,reason:`its identity was not read yet`})).pipe(GO);let u=yield*RO(WM([n],a,s));if(u._tag===`Failure`){let e=u.failure.reason;return yield*jM(i,t({},{pid:n,reason:e})).pipe(GO),yield*z(`keyring holder started as process ${n}, but its identity could not be read (${e}); it cannot be signalled, so the guest must be retired`)}let[f]=u.success;if(f?.kind!==`running`)return yield*jM(i,t({})).pipe(GO),yield*z(`keyring holder exited at once; see its log ${l}`);let p=f.identity;yield*jM(i,t({holder:p}));let m;for(;m===void 0;){let e=yield*RO(r.readFile(d(c,`connection`),yield*FM(a,s)));if(e._tag===`Success`){m=YTe(new TextDecoder().decode(e.success));break}let t=a.endMs-(yield*NM);if(t<=0)return yield*z(`keyring session did not become ready`);yield*JO(Math.min(50,t))}let h=HM(m.BUS),g=HM(m.DAEMON),_=m.ADDRESS??``;if(h===void 0||g===void 0||_.length===0)return yield*z(`keyring connection data is incomplete`);let[v,y]=yield*WM([h,g],a,s);if(v?.kind!==`running`||y?.kind!==`running`)return yield*z(`keyring bus or daemon is not running; see its log ${l}`);let b={holder:p,bus:v.identity,daemon:y.identity};if(yield*jM(i,{...o,keyring:{phase:`starting`,dir:c,log:l,address:_,processes:b}}),v.ppid!==p.pid||y.ppid!==p.pid)return yield*z(`keyring bus or daemon is not a child of the keyring holder`);for(;;){let t=yield*RO(zM(o,_,b.daemon,a,e.unsetEnv,`start`)),n=t._tag===`Success`?RM(t.success,b,`start`):{kind:`pending`,reason:t.failure.reason};if(n.kind===`ready`)break;if(n.kind===`wrong`)return yield*z(n.reason);let r=a.endMs-(yield*NM);if(r<=0)return yield*z(`keyring session did not become ready: ${n.reason}`);yield*JO(Math.min(50,r))}let ee={phase:`ready`,dir:c,log:l,address:_,processes:b,ready_at:yield*MM};return{...o,keyring:ee}}),KM=[`daemon`,`bus`,`holder`],ZTe=(e,t,n,r)=>MO(function*(){let i=KM.map(e=>[e,t.processes[e]]),a=yield*WM(i.map(([,e])=>e.pid),n,e.probe_timeout_s);for(let[e,[t,n]]of i.entries()){let r=a[e];if(r?.kind!==`running`||fM(r.identity)!==fM(n))return yield*z(`keyring ${t} (process ${n.pid}) is no longer running; the keyring session has ended`)}let o=yield*zM(e,t.address,t.processes.daemon,n,r,`check`),s=RM(o,t.processes,`check`);if(s.kind!==`ready`)return yield*z(s.reason)}),qM=e=>{if(e===void 0)return[];let t=e.processes;return KM.flatMap(e=>{let n=t[e];return n===void 0?[]:[[`keyring:${e}`,n]]})},JM=e=>Object.fromEntries(Object.entries(e===void 0||e.phase===`ready`?{}:e.unidentified??{}).map(([e,t])=>[`keyring:${e}`,{outcome:`unresolved`,reason:t.pid===null?`${t.reason}; no signal sent`:`process ${t.pid} was never identified; no signal sent`}])),YM=(e,t)=>{let n=Object.fromEntries(Object.entries(t).filter(([e])=>e.startsWith(`keyring:`))),r=Object.values(n).some(e=>e.outcome===`unresolved`);return{...e,phase:r?`stopping`:`stopped`,ended:n}},XM=(e,t,n)=>({...YM(e,t),phase:`failed`,reason:n}),ZM=e=>({address:e.address,processes:e.processes}),QM=[`Xvfb`,`dbus-run-session`,`startxfce4`,`xdpyinfo`,`wmctrl`,`xprop`,`scrot`,`xwininfo`],$M=[`xdpyinfo`,`wmctrl`,`xprop`,`scrot`,`xwininfo`],eN=[`DISPLAY`,`HOME`,`XDG_CONFIG_HOME`,`XDG_CACHE_HOME`,`XDG_DATA_HOME`,`XDG_RUNTIME_DIR`,`XDG_CURRENT_DESKTOP`,`XDG_SESSION_TYPE`,`DBUS_SESSION_BUS_ADDRESS`],tN=[...eN,`DBUS_SESSION_BUS_PID`,`SESSION_MANAGER`,`XAUTHORITY`,`WAYLAND_DISPLAY`,`XDG_SESSION_ID`,`DESKTOP_SESSION`],QTe=[`DBUS_SESSION_BUS_ADDRESS`,`XDG_RUNTIME_DIR`,`XAUTHORITY`],$Te=String.raw`
438
+ dir=$1; run=$2; xfce=$3
439
+ umask 077
440
+ tmp="$dir/.connection.$$"
441
+ {
442
+ printf 'RUN_ID=%s\n' "$run"
443
+ printf 'PID=%s\n' "$$"
444
+ for key in DISPLAY HOME XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_CURRENT_DESKTOP XDG_SESSION_TYPE DBUS_SESSION_BUS_ADDRESS; do
445
+ value=$(printenv "$key" || true)
446
+ printf '%s=%s\n' "$key" "$value"
447
+ done
448
+ } > "$tmp" && mv -f "$tmp" "$dir/connection" || exit 70
449
+ exec "$xfce"
450
+ `,nN=(e,t)=>{let n=t.slice(1);return{lock:d(e,`.X${n}-lock`),socket:d(e,`.X11-unix`,`X${n}`)}},rN=e=>({home:d(e,`home`),runtime:d(e,`runtime`),logs:d(e,`logs`),captures:d(e,`captures`),connection:d(e,`connection`)}),iN=e=>{if(e.kind===`adopted`)return{...e.connection};let t=rN(e.guest_dir);return{DISPLAY:e.display,HOME:t.home,XDG_CONFIG_HOME:d(t.home,`.config`),XDG_CACHE_HOME:d(t.home,`.cache`),XDG_DATA_HOME:d(t.home,`.local/share`),XDG_RUNTIME_DIR:t.runtime,XDG_CURRENT_DESKTOP:`XFCE`,XDG_SESSION_TYPE:`x11`,DESKTOP_SESSION:`xfce`}},eEe=e=>e.kind===`owned`?rN(e.guest_dir).home:e.guest_dir,aN=(e,t,n,r,i,a,o=t.probe_timeout_s)=>MO(function*(){let s=yield*lM,c=yield*FM(i,o),l=c<o*1e3,u=t.tools[n];if(u===void 0)return yield*z(`no resolved tool named ${n}`);let f=yield*s.run([u,...r],{timeoutMs:c,env:{...a,LC_ALL:`C`},unsetEnv:tN,cwd:eEe(t)}).pipe(WO(e=>new _M({reason:`${n} read could not run: ${e.message}`}))),p=d(e,`probes`,`${n}.json`),m=yield*MM;return f.timedOut?(yield*DM(p,{timed_out:!0,timeout_seconds:c/1e3,observed_at:m}),yield*NO(new _M({reason:`${n} read timed out; see private probes/${n}.json`,...l?{deadline:!0}:{}}))):(yield*DM(p,{native_exit:f.exitCode,stdout:f.stdout,stderr:f.stderr,observed_at:m}),f.exitCode===0?f.stdout:yield*z(`${n} read failed; see private probes/${n}.json`,f.exitCode))}),oN=e=>t=>new _M({reason:`${e}: ${t.message}`}),sN=(e,t,n=!1)=>pM(e,t).pipe(WO(e=>new _M({reason:`process identity read failed: ${e.message}`,...n&&e.timedOut===!0?{deadline:!0}:{}}))),cN=(e,t,n)=>LO(FM(t,n),t=>sN(e,t,t<n*1e3)),lN=(e,t)=>e?.kind===`running`&&fM(e.identity)===fM(t),uN=(e,t)=>MO(function*(){let n=Object.entries(e.children),r=[];e.xfce!==void 0&&r.push([`xfce`,e.xfce]),e.x_server!==void 0&&r.push([`X server`,e.x_server]);let i=[...n,...r];if(i.length===0)return;for(let[e,t]of i)if(!Number.isInteger(t.pid)||t.pid<=1)return yield*z(`${e} has a reserved or malformed recorded process identity`);let a=yield*cN(i.map(([,e])=>e.pid),t,e.probe_timeout_s);for(let[e,[t,n]]of i.entries())if(!lN(a[e],n))return yield*z(`${t} launch identity changed`)}),dN=(e,t,n)=>MO(function*(){let{lock:r}=nN(e.x11_dir,e.display),i=yield*hM(r,yield*FM(t,e.probe_timeout_s)).pipe(WO(oN(`display lock read failed`)));if(!/^\s*\d+\s*$/u.test(i.content)||Number(i.content.trim())!==n)return yield*z(`display lock does not identify the held X server`);if(i.ownerUid!==e.lock_owner_uid)return yield*z(`display lock belongs to another user`)}),tEe=e=>{let t={};for(let n of e.split(`
451
+ `)){let e=n.indexOf(`=`);e>0&&(t[n.slice(0,e)]=n.slice(e+1))}return t},nEe=(e,t)=>MO(function*(){let n=yield*(yield*lM).readFile(rN(e.guest_dir).connection,yield*FM(t,e.probe_timeout_s)).pipe(WO(oN(`session connection data is not readable yet`))),r=tEe(new TextDecoder().decode(n));if(r.RUN_ID!==e.run_id)return yield*z(`connection belongs to another launch`);let i=Number(r.PID);if(!Number.isInteger(i)||i<=1)return yield*z(`connection names no XFCE process`);let a=iN(e);for(let e of eN){if(r[e]===void 0)return yield*z(`session connection data is incomplete`);if(e!==`DBUS_SESSION_BUS_ADDRESS`&&r[e]!==a[e])return yield*z(`session connection data changed`)}return(r.DBUS_SESSION_BUS_ADDRESS??``).startsWith(`unix:`)?{pid:i,bus:r.DBUS_SESSION_BUS_ADDRESS??``}:yield*z(`dbus-run-session did not provide a local bus`)}),fN=e=>({...iN(e),...e.kind===`owned`&&e.connection.DBUS_SESSION_BUS_ADDRESS!==void 0?{DBUS_SESSION_BUS_ADDRESS:e.connection.DBUS_SESSION_BUS_ADDRESS}:{}}),rEe=e=>{let t=/dimensions:\s+(\d+)x(\d+)\s+pixels/u.exec(e);return t?[Number(t[1]),Number(t[2])]:void 0},pN=(e,t,n)=>MO(function*(){let r=t,i=()=>FM(n,r.probe_timeout_s);yield*uN(r,n);let a=r.kind===`owned`?r.children.xvfb?.pid:r.x_server?.pid;if(a===void 0)return yield*z(`session records no X server`);yield*dN(r,n,a);let o=r.kind===`adopted`||r.children.session!==void 0;if(r.kind===`owned`&&o){let e=yield*nEe(r,n);if(r.xfce===void 0){let[t]=yield*cN([e.pid],n,r.probe_timeout_s);if(t?.kind!==`running`)return yield*z(`XFCE launch identity changed`);r={...r,xfce:t.identity,connection:{...r.connection,DBUS_SESSION_BUS_ADDRESS:e.bus}}}else if(e.pid!==r.xfce.pid)return yield*z(`XFCE launch identity changed`)}let s=fN(r),c=yield*aN(e,r,`xdpyinfo`,[],n,s),l=rEe(c);if(l===void 0||l[0]!==r.dimensions[0]||l[1]!==r.dimensions[1])return yield*z(`X display dimensions do not match the requested geometry`);if(!o)return{observation:{dimensions:r.dimensions},session:r};let u=yield*aN(e,r,`xprop`,[`-root`,`_NET_SUPPORTING_WM_CHECK`],n,s),d=/window id # (0x[0-9a-fA-F]+)\s*$/u.exec(u);if(d?.[1]===void 0||Number.parseInt(d[1],16)===0)return yield*z(`X root has no supporting window manager`);let f=d[1],p=yield*aN(e,r,`xprop`,[`-id`,f,`_NET_SUPPORTING_WM_CHECK`,`_NET_WM_PID`],n,s),m=/_NET_SUPPORTING_WM_CHECK\(WINDOW\): window id # (0x[0-9a-fA-F]+)/u.exec(p),h=/_NET_WM_PID\(CARDINAL\)\s*=\s*(\d+)/u.exec(p);if(m?.[1]===void 0||Number.parseInt(m[1],16)!==Number.parseInt(f,16)||h?.[1]===void 0||Number(h[1])<=1)return yield*z(`window manager support window is stale or incomplete`);let g=yield*aN(e,r,`wmctrl`,[`-m`],n,s),_=/^Name:\s*(.+)$/mu.exec(g),v=/^PID:\s*(\d+)\s*$/mu.exec(g);if(_?.[1]?.trim()!==`Xfwm4`||v?.[1]===void 0||Number(v[1])!==Number(h[1]))return yield*z(`wmctrl does not identify the same Xfwm4 window manager`);let[y]=yield*cN([Number(h[1])],n,r.probe_timeout_s);if(y?.kind!==`running`)return yield*z(`window manager process is not running`);if(r.kind===`owned`){let e=r.children.session?.pid,t=yield*FTe(y.identity.pid,yield*i()).pipe(WO(oN(`window manager ancestry read failed`)));if(e===void 0||!t.includes(e))return yield*z(`window manager does not descend from the held XFCE launch`)}else if(r.window_manager!==void 0&&fM(r.window_manager)!==fM(y.identity))return yield*z(`window manager identity changed`);return yield*uN(r,n),yield*dN(r,n,a),r.keyring?.phase===`ready`&&(yield*ZTe(r,r.keyring,n,tN)),{observation:{dimensions:r.dimensions,window_manager:{name:`Xfwm4`,window:f,identity:y.identity}},session:r}}),mN=(e,t,n,r)=>MO(function*(){let i=`no completed readiness observation`;for(;;){let a=Object.entries(t.children);if(a.length>0){let e=yield*cN(a.map(([,e])=>e.pid),n,t.probe_timeout_s);for(let[t,[n,r]]of a.entries())if(!lN(e[t],r))return yield*z(`${n} exited before or during readiness`)}let o=yield*RO(pN(e,t,n));if(o._tag===`Success`)return o.success;i=o.failure.reason;let s=yield*NM,c=n.endMs-s;if(c<=0)return yield*z(`readiness expired after ${r}s: ${i}`);yield*JO(Math.min(100,c))}}),iEe=(e,t)=>e===void 0||e.kind===`absent`||e.kind===`zombie`||e.kind===`running`&&fM(e.identity)!==fM(t),hN=(e,t,n)=>XO(MO(function*(){let r=yield*lM,i={},a=yield*PM(t),o={endMs:a.endMs-t*1e3/2},s=new Map;for(let[n,i]of e){let e=yield*RO(r.watchExit(i.pid,t*1e3));e._tag===`Success`&&s.set(n,e.success)}let c=new Map(e),l=new Map,u=new Set,d=e=>MO(function*(){for(let[t,r]of c){let o=yield*PTe(r,e,Math.min(n*1e3,Math.max(1,a.endMs-(yield*NM)))).pipe(KO(()=>`error`));o===`sent`?l.set(t,e):o===`gone`?(c.delete(t),i[t]={outcome:`ended`,by:l.get(t)??`already`}):o===`changed`?(c.delete(t),u.add(t),i[t]={outcome:`ended`,by:l.get(t)??`already`,reason:`its process id now names another process, which was sent no signal`}):(c.delete(t),i[t]={outcome:`unresolved`,reason:o===`invalid`?`reserved or malformed process identity; no signal sent`:`the identity-checked signal could not be sent`})}}),f=e=>MO(function*(){for(;;){if(c.size===0)return;let t=[...c],r=yield*sN(t.map(([,e])=>e.pid),Math.min(n*1e3,Math.max(1,a.endMs-(yield*NM)))).pipe(KO(()=>[]));for(let[e,[n,a]]of t.entries())r.length===t.length&&iEe(r[e],a)&&(c.delete(n),i[n]={outcome:`ended`,by:l.get(n)??`already`});if(c.size===0||(yield*NM)>=e.endMs)return;yield*JO(100)}});yield*d(`TERM`),yield*f(o),c.size>0&&(yield*d(`KILL`),yield*f(a));for(let[e]of c)i[e]={outcome:`unresolved`,reason:`still running after the shutdown budget`};for(let[e,t]of Object.entries(i)){let n=s.get(e);if(t.outcome===`ended`&&n!==void 0&&!u.has(e)){let r=yield*RO(qO(n,{duration:2e3,orElse:()=>DO(void 0)}));i[e]={...t,exit_code:r._tag===`Success`?r.success??null:null}}else t.outcome===`ended`&&(i[e]={...t,exit_code:null})}return i})),gN=(e,t)=>MO(function*(){if(yield*TM(e.stateDir))return yield*z(`fresh-only launch refuses existing path: ${e.stateDir}`);let n=yield*mM(e.guestPaths,t).pipe(WO(oN(`path check failed`))),r=e.guestPaths.find((e,t)=>n[t]===!0);if(r!==void 0)return yield*z(`fresh-only launch refuses existing path: ${r}`)}),_N=(e,t,n)=>MO(function*(){let r=yield*ITe(e,t,n).pipe(WO(oN(`tool check failed`)));return r.kind===`missing`?yield*z(`tool directory contains a missing or non-executable prerequisite: ${r.name}`):r.tools}),vN=(e,t,n,r,i,a)=>MO(function*(){let o=yield*(yield*lM).start(t,{env:n,unsetEnv:tN,cwd:r,logPath:i}).pipe(WO(oN(`${e} could not start`))),[s]=yield*sN([o],a);return s?.kind===`running`?s.identity:yield*z(`${e} exited before or during readiness`)}),aEe=e=>MO(function*(){let t=yield*lM,n=e.probeTimeout*1e3,r=rN(e.guestDir),i=nN(e.x11Dir,e.display);yield*gN({stateDir:e.stateDir,guestPaths:[e.guestDir,i.lock,i.socket]},n);let a=yield*_N(e.toolDir,e.keyring?[...QM,...IM]:QM,n),[o,s]=e.geometry.split(`x`).map(Number);yield*EM(e.stateDir);for(let[t,i]of[[e.guestDir,!0],[r.home,!1],[r.runtime,!1],[r.logs,!1],[r.captures,!1]])yield*gM(t,i,n).pipe(WO(oN(`guest directory setup failed`)));let c=yield*RTe(n).pipe(WO(oN(`uid read failed`))),l={schema:`use-cloud-vms/linux-desktop/session@1`,run_id:b().replaceAll(`-`,``),guest:t.name,kind:`owned`,phase:`starting`,display:e.display,dimensions:[o??0,s??0],geometry:e.geometry,x11_dir:e.x11Dir,guest_dir:e.guestDir,tools:a,probe_timeout_s:e.probeTimeout,ready_timeout_s:e.readyTimeout,shutdown_timeout_s:e.shutdownTimeout,lock_owner_uid:c,children:{},connection:{},apps:{},guest_retirement_required:!0};yield*jM(e.stateDir,l);let u=yield*PM(e.readyTimeout),f=iN(l),p=MO(function*(){let t=yield*vN(`xvfb`,[a.Xvfb??``,e.display,`-screen`,`0`,e.geometry,`-nolisten`,`tcp`,`-ac`,`+extension`,`RANDR`],f,r.home,d(r.logs,`xvfb.log`),n);l={...l,children:{xvfb:t}},yield*jM(e.stateDir,l),yield*mN(e.stateDir,l,u,e.readyTimeout);let i=yield*vN(`session`,[a[`dbus-run-session`]??``,`--`,`/bin/sh`,`-c`,$Te,`sh`,e.guestDir,l.run_id,a.startxfce4??``],f,r.home,d(r.logs,`xfce.log`),n);l={...l,children:{...l.children,session:i}},yield*jM(e.stateDir,l);let o=yield*mN(e.stateDir,l,u,e.readyTimeout);return l=o.session,e.keyring&&(l=yield*GM({stateDir:e.stateDir,session:l,deadline:u,env:VM(fN(l),BM(l.guest_dir).dir),unsetEnv:tN})),l={...l,phase:`ready`,observed:o.observation,ready_at:yield*MM},yield*jM(e.stateDir,l),o.observation}),m=yield*RO(p);if(m._tag===`Success`)return{status:`ready`,state_dir:e.stateDir,run_id:l.run_id,guest:l.guest,observed:m.success,...l.keyring?.phase===`ready`?{keyring:ZM(l.keyring)}:{}};let h=e.keyring?yield*RO(AM(e.stateDir)):void 0,g=h?._tag===`Success`&&h.success.run_id===l.run_id?h.success.keyring:l.keyring,_=Object.entries(l.children),v={...yield*hN([...qM(g),..._.toReversed()],e.shutdownTimeout,e.probeTimeout),...JM(g)};return l={...l,...g===void 0?{}:{keyring:XM(g,v,m.failure.reason)},phase:`failed`,reason:m.failure.reason,ended:{direct_children:v,at:yield*MM}},yield*jM(e.stateDir,l).pipe(GO),yield*NO(m.failure)}),oEe=(e,t,n,r)=>MO(function*(){let i=yield*RO(GM({stateDir:e,session:t,deadline:n,env:VM(fN(t),BM(t.guest_dir).dir),unsetEnv:tN}).pipe(LO(e=>r(e).pipe(WO(vM)))));if(i._tag===`Success`)return i.success;let a=yield*RO(AM(e)),o=a._tag===`Success`?a.success.keyring:void 0,s={...yield*hN(qM(o),t.shutdown_timeout_s,t.probe_timeout_s),...JM(o)};return o!==void 0&&a._tag===`Success`&&(yield*jM(e,{...a.success,phase:`failed`,reason:i.failure.reason,keyring:XM(o,s,i.failure.reason)}).pipe(GO)),yield*NO(i.failure)}),sEe=e=>MO(function*(){let t=yield*lM,n=e.probeTimeout*1e3,r=rN(e.guestDir);yield*gN({stateDir:e.stateDir,guestPaths:[e.guestDir]},n);let i=yield*_N(e.toolDir,e.keyring?[...$M,...IM]:$M,n),[a,o]=e.geometry.split(`x`).map(Number),s=yield*PM(Math.max(e.probeTimeout*8,1)),{lock:c}=nN(e.x11Dir,e.display),l=yield*hM(c,yield*FM(s,e.probeTimeout)).pipe(WO(oN(`display lock read failed`)));if(!/^\s*\d+\s*$/u.test(l.content))return yield*z(`display lock does not name an X server`);let[u]=yield*sN([Number(l.content.trim())],yield*FM(s,e.probeTimeout));if(u?.kind!==`running`)return yield*z(`display lock names no running X server`);yield*EM(e.stateDir);for(let[t,i]of[[e.guestDir,!0],[r.logs,!1],[r.captures,!1]])yield*gM(t,i,n).pipe(WO(oN(`guest directory setup failed`)));let d={schema:`use-cloud-vms/linux-desktop/session@1`,run_id:b().replaceAll(`-`,``),guest:t.name,kind:`adopted`,phase:`starting`,display:e.display,dimensions:[a??0,o??0],geometry:e.geometry,x11_dir:e.x11Dir,guest_dir:e.guestDir,tools:i,probe_timeout_s:e.probeTimeout,ready_timeout_s:e.probeTimeout,shutdown_timeout_s:e.probeTimeout*2,lock_owner_uid:l.ownerUid,children:{},x_server:u.identity,connection:{DISPLAY:e.display},apps:{},guest_retirement_required:e.keyring};yield*jM(e.stateDir,d);let f=yield*pN(e.stateDir,d,s),p=f.observation.window_manager;if(p===void 0)return yield*z(`adopted display has no window manager`);let m=yield*LTe(p.identity.pid,QTe,yield*FM(s,e.probeTimeout)).pipe(WO(oN(`window manager environment read failed`)));d={...d,window_manager:p.identity,connection:{...m,DISPLAY:e.display},observed:f.observation};let h=t=>MO(function*(){let n={...t,phase:`ready`,ready_at:yield*MM};return yield*jM(e.stateDir,n),n});return d=e.keyring?yield*oEe(e.stateDir,d,s,h):yield*h(d),{status:`ready`,state_dir:e.stateDir,run_id:d.run_id,guest:d.guest,observed:f.observation,connection_keys:Object.keys(d.connection).toSorted(),...d.keyring?.phase===`ready`?{keyring:ZM(d.keyring)}:{}}}),yN=(e,t)=>MO(function*(){let n=yield*PM(t),r=yield*AM(e);if(r.phase!==`ready`)return yield*z(`session is not in its ready phase`);let i={...r,probe_timeout_s:Math.min(r.probe_timeout_s,t)},a=yield*pN(e,i,n),o=yield*AM(e);return o.phase!==`ready`||o.run_id!==r.run_id?yield*z(`session changed while readiness was inspected`):{session:r,observation:a.observation,deadline:n}}),cEe=(e,t)=>MO(function*(){let n=yield*AM(e);if(n.phase===`stopped`||n.phase===`released`)return{status:n.phase,already:!0,run_id:n.run_id};let r=[],i=t=>jM(e,t).pipe(HO(`Unavailable`,e=>kO(()=>void r.push(e.reason))));n={...n,phase:`stopping`},yield*i(n);let a=Object.entries(n.apps).flatMap(([e,t])=>t.phase===`running`||t.phase===`unresolved`?[[`app:${e}`,t.identity]]:[]),o=n.kind===`owned`?Object.entries(n.children).toReversed():[],s={...yield*hN([...a,...qM(n.keyring),...o],t,n.probe_timeout_s),...JM(n.keyring)},c={...n.apps};for(let[e,t]of Object.entries(n.apps)){let n=s[`app:${e}`];t.phase===`unidentified`?s[`app:${e}`]={outcome:`unresolved`,reason:t.pid===null?`${t.reason}; no signal sent`:`process ${t.pid} was never identified; no signal sent`}:n!==void 0&&(c[e]={...t,phase:n.outcome===`ended`?`terminated`:`unresolved`,ended:n})}let l=Object.values(s).some(e=>e.outcome===`unresolved`),u=n.kind===`owned`?`stopped`:`released`;return n={...n,apps:c,...n.keyring===void 0?{}:{keyring:YM(n.keyring,s)},phase:l?`stopping`:u,ended:{direct_children:s,at:yield*MM}},yield*i(n),{status:n.phase,run_id:n.run_id,direct_children:s,guest_retirement_required:n.guest_retirement_required||l,state_write_errors:r,failed:l||r.length>0}}),lEe=e=>e.split(`
452
+ `).map(e=>/^(0x[0-9a-fA-F]+)\s+(-?\d+)\s+(\d+)\s+(\S+)\s?(.*)$/u.exec(e)).filter(e=>e!==null).map(e=>({id:e[1]??``,pid:Number(e[3]),title:e[5]??``})),bN=(e,t)=>{let n=RegExp(`^\\s*${t}:\\s*(-?\\d+)\\s*$`,`mu`).exec(e);return n?.[1]===void 0?void 0:Number(n[1])},xN=(e,t)=>{let n=RegExp(`^${t}\\(CARDINAL\\) = (\\d+), (\\d+), (\\d+), (\\d+)$`,`mu`).exec(e);return n===null?RegExp(`^${t}:\\s+not found\\.$`,`mu`).test(e)?[0,0,0,0]:void 0:[Number(n[1]),Number(n[2]),Number(n[3]),Number(n[4])]},SN=(e,t,n,r)=>MO(function*(){if(!/^0x[0-9a-fA-F]+$/u.test(n))return yield*z(`window id ${n} is not an X window id`);let i=yield*aN(e,t,`xwininfo`,[`-id`,n],r,fN(t)),a=bN(i,`Absolute upper-left X`),o=bN(i,`Absolute upper-left Y`),s=bN(i,`Width`),c=bN(i,`Height`);if(a===void 0||o===void 0||s===void 0||c===void 0)return yield*z(`xwininfo did not report the window's geometry`);let l=yield*aN(e,t,`xprop`,[`-id`,n,`_GTK_FRAME_EXTENTS`,`_NET_FRAME_EXTENTS`],r,fN(t)),u=xN(l,`_GTK_FRAME_EXTENTS`);if(u===void 0)return yield*z(`xprop reported an unreadable _GTK_FRAME_EXTENTS`);let d=xN(l,`_NET_FRAME_EXTENTS`);if(d===void 0)return yield*z(`xprop reported an unreadable _NET_FRAME_EXTENTS`);let[f,p,m,h]=u,[g,_,v,y]=d;return{x:a+f-g,y:o+m-v,width:s-f-p+g+_,height:c-m-h+v+y,viewable:/Map State:\s*IsViewable/u.test(i),gtk_frame_extents:u,net_frame_extents:d}}),uEe=/^_NET_CLIENT_LIST_STACKING\(WINDOW\): window id # (.*)$/mu,dEe=(e,t,n)=>MO(function*(){let r=yield*aN(e,t,`xprop`,[`-root`,`_NET_CLIENT_LIST_STACKING`],n,fN(t)),i=uEe.exec(r)?.[1]?.split(`,`).map(e=>e.trim());return i===void 0||!i.every(e=>/^0x[0-9a-fA-F]+$/u.test(e))?yield*z(`xprop reported an unreadable _NET_CLIENT_LIST_STACKING`):i}),fEe=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,pEe=(e,t,n,r,i)=>MO(function*(){let a=yield*dEe(e,t,i),o=a.findIndex(e=>Number.parseInt(e,16)===Number.parseInt(n,16));if(o<0)return yield*z(`window ${n} is not in the window manager's stacking order`);let s=[];for(let n of a.slice(o+1)){let a=yield*SN(e,t,n,i);a.viewable&&fEe(a,r)&&s.push(n)}return s}),CN=(e,t,n,r)=>MO(function*(){let i=yield*aN(e,t,`wmctrl`,[`-lp`],r,fN(t)),a=lEe(i).filter(e=>n===void 0||e.pid===n),o=[];for(let n of a){let i=yield*SN(e,t,n.id,r);o.push({...n,x:i.x,y:i.y,width:i.width,height:i.height,gtk_frame_extents:i.gtk_frame_extents,net_frame_extents:i.net_frame_extents})}return o}),mEe=/^[a-z0-9][a-z0-9-]{0,62}$/u,hEe=(e,t)=>{let n=e.connection.XDG_RUNTIME_DIR??fN(e).XDG_RUNTIME_DIR;return{...fN(e),...e.keyring?.phase===`ready`?{DBUS_SESSION_BUS_ADDRESS:e.keyring.address}:{},HOME:t,XDG_CONFIG_HOME:d(t,`.config`),XDG_CACHE_HOME:d(t,`.cache`),XDG_DATA_HOME:d(t,`.local/share`),XDG_RUNTIME_DIR:n??d(t,`.runtime`)}},wN=(e,t,n,r)=>MO(function*(){let i=n=>d(e.guest_dir,`logs`,n<=1?`app-${t}.log`:`app-${t}-${n}.log`);for(let t=n;;t+=1){let[n]=yield*mM([i(t)],yield*FM(r,e.probe_timeout_s)).pipe(WO(e=>new _M({reason:`log path check failed: ${e.message}`})));if(n===!1)return i(t)}}),TN=(e,t,n)=>MO(function*(){let r=yield*AM(e),i=Object.fromEntries(Object.entries(r.apps).filter(([e])=>e!==t));yield*jM(e,{...r,apps:n===void 0?i:{...i,[t]:n}})}),EN=(e,t,n)=>MO(function*(){let r=yield*AM(e),i=r.apps[t];if(i===void 0)return yield*z(`no app named ${t}`);if(i.phase===`unidentified`)return yield*z(`app ${t} was never identified`);yield*jM(e,{...r,apps:{...r.apps,[t]:n(i)}})}),DN=(e,t,n,r,i,a=`app ${n} is no longer running`)=>MO(function*(){let[o]=yield*cN([r.identity.pid],i,t.probe_timeout_s);if(o?.kind!==`running`||fM(o.identity)!==fM(r.identity))return yield*EN(e,n,e=>({...e,phase:`ended`})),yield*z(a)}),ON=(e,t,n)=>new _M({reason:`app ${e} started as process ${t}, but ${n}; it cannot be signalled, so the guest must be retired`,retire:!0}),gEe=(e,t,n,r,i,a)=>MO(function*(){let o=yield*RO(TN(e,n,{...i,pid:r,phase:`unidentified`,reason:`its identity was not read yet`})),s=yield*RO(sN([r],t.probe_timeout_s*1e3));if(s._tag===`Failure`)return o._tag===`Failure`?yield*NO(ON(n,r,`it could not be recorded (${o.failure.reason}) and its identity could not be read (${s.failure.reason})`)):(yield*TN(e,n,{...i,pid:r,phase:`unidentified`,reason:s.failure.reason}).pipe(GO),yield*NO(ON(n,r,`its identity could not be read (${s.failure.reason})`)));let[c]=s.success;if(c?.kind!==`running`)return yield*TN(e,n,a).pipe(GO),yield*z(`app exited at once; see its log ${i.log}`);let l=yield*RO(TN(e,n,{...i,identity:c.identity,phase:`running`}));return l._tag===`Success`?c.identity:(yield*hN([[`app:${n}`,c.identity]],t.shutdown_timeout_s,t.probe_timeout_s))[`app:${n}`]?.outcome===`ended`?(yield*TN(e,n,a).pipe(GO),yield*z(`app ${n} started as process ${r} was ended because its record could not be written: ${l.failure.reason}`)):yield*NO(ON(n,r,`its record could not be written (${l.failure.reason}) and it could not be ended`))}),_Ee=(e,t,n,r,i)=>MO(function*(){if(r.notStarted===!0)return yield*TN(e,t,i).pipe(GO),yield*z(`app could not start: ${r.message}`);let a=`its start may have run, but returned no process id: ${r.message}`;return yield*TN(e,t,{...n,pid:null,phase:`unidentified`,reason:a}).pipe(GO),yield*NO(new _M({reason:`app ${t}: ${a}; it cannot be signalled, so the guest must be retired`,retire:!0}))}),vEe=e=>MO(function*(){if(!mEe.test(e.name))return yield*z(`app name must be lowercase letters, digits and hyphens`);if(!u(e.home))return yield*z(`app home must be an absolute guest path`);if(e.argv.length===0)return yield*z(`app launch needs a command after --`);let t=yield*AM(e.stateDir),{session:n,deadline:r}=yield*yN(e.stateDir,t.ready_timeout_s);if(n.apps[e.name]!==void 0)return yield*z(`an app named ${e.name} was already launched`);let i=yield*FM(r,n.probe_timeout_s),[a]=yield*mM([e.home],i).pipe(WO(e=>new _M({reason:`path check failed: ${e.message}`})));if(a===!0)return yield*z(`fresh-only launch refuses existing path: ${e.home}`);for(let t of[e.home,d(e.home,`.config`),d(e.home,`.cache`),d(e.home,`.local`),d(e.home,`.local/share`)])yield*gM(t,t===e.home,i).pipe(WO(e=>new _M({reason:`app home setup failed: ${e.message}`})));n.connection.XDG_RUNTIME_DIR===void 0&&n.kind===`adopted`&&(yield*gM(d(e.home,`.runtime`),!1,i).pipe(WO(e=>new _M({reason:`app home setup failed: ${e.message}`}))));let o={argv:[...e.argv],home:e.home,log:yield*wN(n,e.name,1,r),launched_at:yield*MM};return yield*kN(e.stateDir,n,e.name,o,e.timeout,void 0)}),kN=(e,t,n,r,i,a)=>MO(function*(){let o=yield*lM;yield*TN(e,n,{...r,pid:null,phase:`unidentified`,reason:`its start was requested, but no process id was recorded`}).pipe(WO(e=>new _M({reason:`app ${n} was not started, because it could not be recorded first: ${e.reason}`})));let s=yield*NM,c=yield*RO(o.start(r.argv,{env:hEe(t,r.home),unsetEnv:tN,cwd:r.home,logPath:r.log}));if(c._tag===`Failure`)return yield*_Ee(e,n,r,c.failure,a);let l=yield*gEe(e,t,n,c.success,r,a),u={...r,identity:l,phase:`running`},d=yield*PM(i);return yield*MO(function*(){for(;;){let a=yield*CN(e,t,l.pid,d);if(yield*DN(e,t,n,u,d,`app exited before it showed a window; see its log ${r.log}`),a.length>0)return{status:`launched`,app:n,identity:l,home:r.home,log:r.log,windows:a,launch_to_window_ms:(yield*NM)-s};let o=d.endMs-(yield*NM);if(o<=0)return yield*z(`app showed no window within ${i}s`);yield*JO(Math.min(250,o))}}).pipe(KTe(`app showed no window within ${i}s`))}),yEe=e=>MO(function*(){let t=yield*AM(e.stateDir),{session:n,deadline:r}=yield*yN(e.stateDir,t.ready_timeout_s),i=n.apps[e.name];if(i===void 0)return yield*z(`no app named ${e.name}`);if(i.phase===`running`)return yield*z(`app ${e.name} is running`);if(i.phase===`unidentified`||i.phase===`unresolved`)return yield*z(`app ${e.name} is ${i.phase}, so it may still be running; it cannot be relaunched`);let{previous:a=[],...o}=i,s={argv:i.argv,home:i.home,log:yield*wN(n,e.name,a.length+2,r),launched_at:yield*MM,previous:[...a,o]};return yield*kN(e.stateDir,n,e.name,s,e.timeout,i)}),AN=(e,t)=>MO(function*(){let n=e.apps[t];return n===void 0?yield*z(`no app named ${t}`):n.phase===`running`?n:yield*z(`app ${t} is ${n.phase}`)}),bEe=(e,t,n)=>MO(function*(){let{session:r,deadline:i}=yield*yN(e,n),a=yield*AN(r,t),o=yield*CN(e,r,a.identity.pid,i);return yield*DN(e,r,t,a,i),{status:`windows`,app:t,identity:a.identity,windows:o}}),xEe=(e,t,n)=>XO(MO(function*(){let r=yield*lM,i=yield*AM(e),{session:a,deadline:o}=yield*yN(e,i.ready_timeout_s),s=yield*AN(a,t),c=yield*CN(e,a,s.identity.pid,o);if(yield*DN(e,a,t,s,o),c.length===0)return yield*z(`app ${t} has no window to close`);let l=yield*RO(r.watchExit(s.identity.pid,n*1e3)),u=yield*NM,d=yield*MM;for(let t of c)yield*aN(e,a,`wmctrl`,[`-i`,`-c`,t.id],o,fN(a));let f=yield*PM(n);for(;;){let e=f.endMs-(yield*NM);if(e<=0)return yield*z(`app ${t} was asked to close and is still running after ${n}s`);let r=yield*RO(sN([s.identity.pid],Math.min(a.probe_timeout_s*1e3,e)));if(r._tag===`Failure`)return yield*z(`app ${t} was asked to close, but whether it ended could not be read: ${r.failure.reason}`);let[i]=r.success;if(i===void 0||i.kind===`absent`||i.kind===`zombie`||i.kind===`running`&&fM(i.identity)!==fM(s.identity))break;yield*JO(Math.max(0,Math.min(100,f.endMs-(yield*NM))))}let p=yield*NM,m=l._tag===`Success`?yield*l.success.pipe(qO({duration:2e3,orElse:()=>DO(void 0)}),KO(()=>void 0)):void 0,h=yield*CN(e,a,s.identity.pid,yield*PM(a.ready_timeout_s)),g={outcome:`closed`,windows_closed:c.map(e=>e.id),windows_left:h.map(e=>e.id),exit_code:m??null,close_requested_at:d,close_to_exit_ms:p-u};return yield*EN(e,t,e=>({...e,phase:`closed`,ended:g})),h.length>0?yield*z(`app ${t} ended but windows with its process id remain`):{status:`closed`,app:t,identity:s.identity,...g}})),jN=(e,t,n={})=>{let r={},i=0;for(;i<e.length;){let a=e[i]??``;if(a===`--`)return n.allowRest===!0?MN(r,t,e.slice(i+1)):{ok:!1,reason:`unexpected --`};let o=t[a];if(!a.startsWith(`--`)||o===void 0)return{ok:!1,reason:`unrecognized argument ${JSON.stringify(a)}`};if(r[a]!==void 0)return{ok:!1,reason:`${a} given more than once`};let s=e.slice(i+1,i+1+o.arity);if(s.length<o.arity||s.some(e=>e===`--`))return{ok:!1,reason:`${a} needs ${o.arity} value${o.arity===1?``:`s`}`};r[a]=s,i+=1+o.arity}return n.allowRest===!0?{ok:!1,reason:`missing -- before the command`}:MN(r,t,[])},MN=(e,t,n)=>{for(let[n,r]of Object.entries(t))if(r.required===!0&&e[n]===void 0)return{ok:!1,reason:`${n} is required`};return{ok:!0,values:e,rest:n}},SEe=e=>/^[+-]?\d+$/u.test(e)&&Number.isSafeInteger(Number(e))?Number(e):void 0;var NN=Oe(((e,t)=>{t.exports=ree.default})),PN=Oe(((e,t)=>{t.exports=ne.default})),FN=Oe(((e,t)=>{t.exports=eee.default})),IN=Oe(((e,t)=>{let n=NN(),r=PN(),i=t.exports=function(){r.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};n.inherits(i,r),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},i.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),LN=Oe((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),RN=Oe(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),zN=Oe(((e,t)=>{let n=LN(),r=RN();function i(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let a=t.exports=function(e,t){let r=e.width,a=e.height,o=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=n.getImagePasses(r,a);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(r,s,c),height:a,lineIndex:0});this._xComparison=c===8?s:c===16?s*2:1};a.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},a.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++){let n=e[1+a],o=a>i?t[a-r]:0;t[a]=n+o}},a.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++){let n=e[1+i],a=r?r[i]:0;t[i]=n+a}},a.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0,l=Math.floor((c+s)/2);t[o]=n+l}},a.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0,d=r(l,c,u);t[s]=n+d}},a.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),CEe=Oe(((e,t)=>{let n=NN(),r=IN(),i=zN(),a=t.exports=function(e){r.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};n.inherits(a,r)})),BN=Oe(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),VN=Oe(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),HN=Oe(((e,t)=>{let n=BN(),r=VN(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),UN=Oe((e=>{let t=LN(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function i(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a)}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function a(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function o(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,s=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=i(e,c));let f;f=c<=8?Buffer.alloc(r*s*4):new Uint16Array(r*s*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,s),g=t.getInterlaceIterator(r,s);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:s}]}for(let t=0;t<h.length;t++)c===8?m=a(h[t],f,g,l,e,m):o(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),WN=Oe(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),wEe=Oe(((e,t)=>{let n=NN(),r=FN(),i=IN(),a=CEe(),o=HN(),s=UN(),c=WN(),l=t.exports=function(e){i.call(this),this._parser=new o(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};n.inherits(l,i),l.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},l.prototype._inflateData=function(e){if(!this._inflate){if(this._bitmapInfo.interlace)this._inflate=r.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,r.Z_MIN_CHUNK);this._inflate=r.createInflate({chunkSize:t});let n=e,i=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&i(e)}),this._filter.on(`complete`,this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,a(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}}this._inflate.write(e)},l.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new a(this._bitmapInfo)},l.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},l.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},l.prototype._simpleTransparency=function(){this._metaData.alpha=!0},l.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},l.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},l.prototype._complete=function(e){if(this.errord)return;let t;try{let n=s.dataToBitMap(e,this._bitmapInfo);t=c(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),TEe=Oe(((e,t)=>{let n=BN();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),EEe=Oe(((e,t)=>{let n=RN();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function a(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function o(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function s(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function c(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function l(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function u(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function d(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function f(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let p={0:r,1:a,2:s,3:l,4:d},m={0:i,1:o,2:c,3:u,4:f};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=m[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,p[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),GN=Oe(((e,t)=>{let n=BN(),r=VN(),i=TEe(),a=EEe(),o=FN(),s=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||o.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:n.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:n.COLORTYPE_COLOR_ALPHA,[n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};s.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},s.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},s.prototype.filterData=function(e,t,r){let o=i(e,t,r,this._options),s=n.COLORTYPE_TO_BPP_MAP[this._options.colorType];return a(o,t,r,this._options,s)},s.prototype._packChunk=function(e,t){let n=t?t.length:0,i=Buffer.alloc(n+12);return i.writeUInt32BE(n,0),i.writeUInt32BE(e,4),t&&t.copy(i,8),i.writeInt32BE(r.crc32(i.slice(4,i.length-4)),i.length-4),i},s.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*n.GAMMA_DIVISION),0),this._packChunk(n.TYPE_gAMA,t)},s.prototype.packIHDR=function(e,t){let r=Buffer.alloc(13);return r.writeUInt32BE(e,0),r.writeUInt32BE(t,4),r[8]=this._options.bitDepth,r[9]=this._options.colorType,r[10]=0,r[11]=0,r[12]=0,this._packChunk(n.TYPE_IHDR,r)},s.prototype.packIDAT=function(e){return this._packChunk(n.TYPE_IDAT,e)},s.prototype.packIEND=function(){return this._packChunk(n.TYPE_IEND,null)}})),DEe=Oe(((e,t)=>{let n=NN(),r=PN(),i=BN(),a=GN(),o=t.exports=function(e){r.call(this);let t=e||{};this._packer=new a(t),this._deflate=this._packer.createDeflate(),this.readable=!0};n.inherits(o,r),o.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(i.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let a=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(a)}})),OEe=Oe(((e,t)=>{t.exports=iee.default})),kEe=Oe(((e,t)=>{t.exports=aee.default})),AEe=Oe(((e,t)=>{let n=OEe().ok,r=FN(),i=NN(),a=kEe().kMaxLength;function o(e){if(!(this instanceof o))return new o(e);e&&e.chunkSize<r.Z_MIN_CHUNK&&(e.chunkSize=r.Z_MIN_CHUNK),r.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function s(e){return new o(e)}function c(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}o.prototype._processChunk=function(e,t,i){if(typeof i==`function`)return r.Inflate._processChunk.call(this,e,t,i);let o=this,s=e&&e.length,l=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(o._hadError)return;let r=l-t;if(n(r>=0,`have should not go down`),r>0){let e=o._buffer.slice(o._offset,o._offset+r);if(o._offset+=r,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||o._offset>=o._chunkSize)&&(l=o._chunkSize,o._offset=0,o._buffer=Buffer.allocUnsafe(o._chunkSize)),t===0&&(d+=s-e,s=e,!0)}n(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,l),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=a)throw c(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+a.toString(16)+` bytes`);let _=Buffer.concat(f,p);return c(this),_},i.inherits(o,r.Inflate);function l(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=r.Z_FINISH,e._processChunk(t,n)}function u(e,t){return l(new o(t),e)}t.exports=e=u,e.Inflate=o,e.createInflate=s,e.inflateSync=u})),KN=Oe(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),jEe=Oe((e=>{let t=KN(),n=zN();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),MEe=Oe(((e,t)=>{let n=!0,r=FN(),i=AEe();r.deflateSync||(n=!1);let a=KN(),o=jEe(),s=HN(),c=UN(),l=WN();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let u;function d(e){u=e}let f;function p(e){f=e}function m(e){f.transColor=e}function h(e){f.palette=e}function g(){f.alpha=!0}let _;function v(e){_=e}let y=[];function b(e){y.push(e)}let ee=new a(e);if(new s(t,{read:ee.read.bind(ee),error:d,metadata:p,gamma:v,palette:h,transColor:m,inflateData:b,simpleTransparency:g}).start(),ee.process(),u)throw u;let x=Buffer.concat(y);y.length=0;let te;if(f.interlace)te=r.inflateSync(x);else{let e=((f.width*f.bpp*f.depth+7>>3)+1)*f.height;te=i(x,{chunkSize:e,maxLength:e})}if(x=null,!te||!te.length)throw Error(`bad png - invalid inflate data response`);let ne=o.process(te,f);x=null;let re=c.dataToBitMap(ne,f);ne=null;let ie=l(re,f,t.skipRescale);return f.data=ie,f.gamma=_||0,f}})),NEe=Oe(((e,t)=>{let n=!0,r=FN();r.deflateSync||(n=!1);let i=BN(),a=GN();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let o=new a(t||{}),s=[];s.push(Buffer.from(i.PNG_SIGNATURE)),s.push(o.packIHDR(e.width,e.height)),e.gamma&&s.push(o.packGAMA(e.gamma));let c=o.filterData(e.data,e.width,e.height),l=r.deflateSync(c,o.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(o.packIDAT(l)),s.push(o.packIEND()),Buffer.concat(s)}})),PEe=Oe((e=>{let t=MEe(),n=NEe();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),qN=Oe((e=>{let t=NN(),n=PN(),r=wEe(),i=DEe(),a=PEe(),o=e.PNG=function(e){n.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new r(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new i(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};t.inherits(o,n),o.sync=a,o.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},o.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},o.prototype.write=function(e){return this._parser.write(e),!0},o.prototype.end=function(e){this._parser.end(e)},o.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},o.prototype._gamma=function(e){this.gamma=e},o.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},o.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},o.prototype.bitblt=function(e,t,n,r,i,a,s){return o.bitblt(this,e,t,n,r,i,a,s),this},o.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},o.prototype.adjustGamma=function(){o.adjustGamma(this)}}))();const JN=Uint8Array.of(137,80,78,71,13,10,26,10),FEe=(e,t)=>{switch(e){case 0:return t===16?`I;16`:`L`;case 2:return`RGB`;case 3:return`P`;case 4:return`LA`;case 6:return`RGBA`;default:return`color-type-${e}`}},YN=(e,t)=>(e[t]??0)*16777216+((e[t+1]??0)<<16)+((e[t+2]??0)<<8)+(e[t+3]??0)>>>0,IEe=(e,t)=>String.fromCharCode(...e.subarray(t,t+4)),LEe=e=>e>=65&&e<=90||e>=97&&e<=122,REe=[[0,0,8,8],[4,0,8,8],[0,4,4,8],[2,0,4,4],[0,2,2,4],[1,0,2,2],[0,1,1,2]],zEe=(e,t)=>{let n=(e,n)=>n>0?e*(1+n*t):0;return e.interlace===0?n(e.height,e.width):REe.reduce((t,[r,i,a,o])=>t+n(Math.ceil(Math.max(0,e.height-i)/o),Math.ceil(Math.max(0,e.width-r)/a)),0)},BEe=(e,t)=>{try{return nee(Buffer.concat(e),{maxOutputLength:t+1}).length===t}catch{return!1}},XN=e=>{if(e.length<JN.length||JN.some((t,n)=>e[n]!==t))return{ok:!1,reason:`invalid_png`};let t=JN.length,n,r=!1,i=!1,a=!1,o=!1,s=!1,c=[];for(;t<e.length;){if(s||e.length-t<12)return{ok:!1,reason:`invalid_png`,...n?{header:n}:{}};let l=YN(e,t),u=t+4,d=IEe(e,u),f=e.subarray(u,u+4);if(l>2147483647||!f.every(LEe))return{ok:!1,reason:`invalid_png`,...n?{header:n}:{}};let p=u+4+l;if(p+4>e.length)return{ok:!1,reason:`invalid_png`,...n?{header:n}:{}};let m=YN(e,p);if(tee(e.subarray(u,p))>>>0!==m)return{ok:!1,reason:`invalid_png`,...n?{header:n}:{}};let h=e.subarray(u+4,p);if(n===void 0){if(d!==`IHDR`||l!==13)return{ok:!1,reason:`invalid_png`};if(n={width:YN(h,0),height:YN(h,4),bitDepth:h[8]??0,colorType:h[9]??0,interlace:h[12]??0,mode:FEe(h[9]??0,h[8]??0)},n.width===0||n.height===0||h[10]!==0||h[11]!==0||n.interlace!==0&&n.interlace!==1)return{ok:!1,reason:`invalid_png`,header:n}}else if(d===`IHDR`)return{ok:!1,reason:`invalid_png`,header:n};else if(d===`IDAT`){if(a)return{ok:!1,reason:`invalid_png`,header:n};r=!0,c.push(h)}else if(d===`PLTE`){if(r||i||l===0||l%3!=0||l>768)return{ok:!1,reason:`invalid_png`,header:n};i=!0}else if(r&&(a=!0),d===`acTL`)o=!0;else if(d===`IEND`){if(l!==0||!r)return{ok:!1,reason:`invalid_png`,header:n};s=!0}else if((f[0]??0)<=90)return{ok:!1,reason:`invalid_png`,header:n};t=p+4}return!s||n===void 0?{ok:!1,reason:`invalid_png`,...n?{header:n}:{}}:o?{ok:!1,reason:`multiple_frames`,header:n}:n.bitDepth!==8||n.colorType!==2&&n.colorType!==6?{ok:!1,reason:`unsupported_sample_format`,header:n}:BEe(c,zEe(n,n.colorType===6?4:3))?{ok:!0,header:n}:{ok:!1,reason:`invalid_png`,header:n}},ZN=e=>{let t=qN.PNG.sync.read(Buffer.from(e.buffer,e.byteOffset,e.byteLength),{checkCRC:!0});return{width:t.width,height:t.height,data:new Uint8Array(t.data)}},VEe=e=>{let t=new qN.PNG({width:e.width,height:e.height});return t.data=Buffer.from(e.data),new Uint8Array(qN.PNG.sync.write(t,{colorType:6,inputHasAlpha:!0}))},QN=(e,t)=>{let n=t.right-t.left,r=t.bottom-t.top,i=new Uint8Array(n*r*4);for(let a=0;a<r;a++){let r=((t.top+a)*e.width+t.left)*4;i.set(e.data.subarray(r,r+n*4),a*n*4)}return{width:n,height:r,data:i}},HEe=(e,t)=>{let n=new Set;for(let r=0;r<e.data.length&&(n.add(((e.data[r]??0)<<24)+((e.data[r+1]??0)<<16)+((e.data[r+2]??0)<<8)+(e.data[r+3]??0)),!(n.size>=t));r+=4);return n.size},$N=e=>{if(!(e instanceof Error))return{name:void 0,code:void 0,errno:void 0};let t=`code`in e&&typeof e.code==`string`?e.code:void 0,n=`errno`in e&&typeof e.errno==`number`?e.errno:void 0;return{name:e.name,code:t,errno:n}};var eP=class extends Error{reason;subject;errorType;errno;constructor(e,t,n){super(e),this.reason=e,this.subject=t;let r=$N(n);this.errorType=n===void 0?void 0:r.code??r.name,this.errno=r.errno}};const tP=e=>y(`sha256`).update(e).digest(`hex`),nP=async(e,t,n)=>{n.path=e;let r;try{if(!(await xe(e)).isFile())throw new eP(`missing_or_non_file`,t);r=await ye(e)}catch(e){if(e instanceof eP)throw e;let{code:n}=$N(e);throw n===`ENOENT`||n===`ENOTDIR`?new eP(`missing_or_non_file`,t,e):new eP(`unreadable_file`,t,e)}n.file_bytes=r.length,n.file_sha256=tP(r);let i=XN(r);if(i.header!==void 0||i.ok){let e=(i.ok,i.header);e!==void 0&&(n.width=e.width,n.height=e.height,n.mode=e.mode,n.bit_depth=e.bitDepth)}if(!i.ok)throw new eP(i.reason,t);let a;try{a=ZN(r)}catch{throw new eP(`invalid_png`,t)}return n.rgba_sha256=tP(a.data),a},UEe=(e,t,n,r,i)=>{let[a=0,o=0,s=0,c=0]=t;if(!(a>=0&&a<s&&o>=0&&o<c))throw new eP(`invalid_content_box`);if(s>r||c>i)throw new eP(`content_box_out_of_bounds`);if(n.some(e=>e<0))throw new eP(`invalid_min_margins`);let[l=0,u=0,d=0,f=0]=e,p={top:n[0]??0,right:n[1]??0,bottom:n[2]??0,left:n[3]??0},m={top:o-u,right:d-s,bottom:f-c,left:a-l};return{source:`caller_supplied`,box:[...t],minimum_margins:p,observed_margins:m,content_contained:Object.values(m).every(e=>e>=0),margins_satisfied:m.top>=p.top&&m.right>=p.right&&m.bottom>=p.bottom&&m.left>=p.left}},WEe={"--raw":{arity:1,required:!0},"--crop":{arity:1,required:!0},"--box":{arity:4,required:!0},"--content-box":{arity:4},"--min-margins":{arity:4}},rP=e=>{if(e===void 0)return;let t=e.map(SEe);if(t.some(e=>e===void 0))throw new eP(`invalid_arguments`);return t.filter(e=>e!==void 0)},iP=e=>TO(async()=>{let t={status:`uncheckable`,reason:null,box:null,comparison_mode:`RGBA8`,decoder:`pngjs@7.0.0`,raw:{},crop:{},expected:{},dimensions_equal:null,pixels_equal:null},n={},r={};t.raw=n,t.crop=r;try{let i=jN(e,WEe);if(!i.ok)throw new eP(`invalid_arguments`);let a=rP(i.values[`--box`])??[],o=rP(i.values[`--content-box`]),s=rP(i.values[`--min-margins`]);if(t.box=[...a],o===void 0!=(s===void 0))throw new eP(`incomplete_content_bounds_arguments`);let[c=0,l=0,u=0,d=0]=a;if(!(c>=0&&c<u&&l>=0&&l<d))throw new eP(`invalid_box`);let f=await nP(i.values[`--raw`]?.[0]??``,`raw`,n);if(u>f.width||d>f.height)throw new eP(`box_out_of_bounds`);let p;o!==void 0&&s!==void 0&&(p=UEe(a,o,s,f.width,f.height),t.content_bounds=p);let m=await nP(i.values[`--crop`]?.[0]??``,`crop`,r),h=QN(f,{left:c,top:l,right:u,bottom:d});t.expected={width:h.width,height:h.height,rgba_sha256:tP(h.data)};let g=m.width===h.width&&m.height===h.height;if(t.dimensions_equal=g,!g)return{report:{...t,status:`mismatch`,reason:`dimensions_differ`},exitCode:1};let _=Buffer.compare(Buffer.from(m.data),Buffer.from(h.data))===0;return t.pixels_equal=_,_?p!==void 0&&p.content_contained!==!0?{report:{...t,status:`mismatch`,reason:`content_cut`},exitCode:1}:p!==void 0&&p.margins_satisfied!==!0?{report:{...t,status:`mismatch`,reason:`content_margins_insufficient`},exitCode:1}:{report:{...t,status:`exact`,reason:`pixels_equal`},exitCode:0}:{report:{...t,status:`mismatch`,reason:`pixels_differ`},exitCode:1}}catch(e){if(!(e instanceof eP))throw e;let n={...t,reason:e.reason};return e.subject!==void 0&&(n.subject=e.subject),e.errorType!==void 0&&(n.error_type=e.errorType),e.errno!==void 0&&(n.errno=e.errno),{report:n,exitCode:2}}}),GEe=e=>JSON.stringify(aP(e)),aP=e=>{if(Array.isArray(e))return e.map(aP);if(typeof e==`object`&&e){let t=Object.entries(e).toSorted(([e],[t])=>e<t?-1:1);return Object.fromEntries(t.map(([e,t])=>[e,aP(t)]))}return e},oP=e=>y(`sha256`).update(e).digest(`hex`),sP=e=>MO(function*(){let t=yield*TO(async()=>{try{return(await _e(l(e))).isDirectory()}catch{return!1}});if(!u(e)||!e.toLowerCase().endsWith(`.png`)||!t||(yield*TM(e))||(yield*TM(`${e}.json`)))return yield*z(`capture requires a fresh absolute .png path with an existing parent`)}),KEe=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height&&e.viewable===t.viewable,qEe=e=>MO(function*(){if(yield*sP(e.output),e.window!==void 0&&(yield*sP(e.window.output),e.window.output===e.output))return yield*z(`window output must differ from the raw output`);let t=yield*lM,{session:n,observation:r,deadline:i}=yield*yN(e.stateDir,e.timeout),a=(t,r)=>MO(function*(){let a=yield*pEe(e.stateDir,n,t,r,i);if(a.length>0)return yield*z(`window is covered by ${a.join(`, `)}`)}),o=e.window===void 0?void 0:yield*SN(e.stateDir,n,e.window.id,i);e.window!==void 0&&o!==void 0&&(yield*a(e.window.id,o));let s=d(n.guest_dir,`captures`,`${b()}.png`),c=yield*MM,l=yield*NM,u=yield*gCe(MO(function*(){return yield*aN(e.stateDir,n,`scrot`,[s],i,fN(n),e.timeout).pipe(HO(`Unavailable`,e=>NO(new _M({reason:e.reason.replace(/^scrot read/u,`scrot`),...e.nativeExit===void 0?{}:{nativeExit:e.nativeExit}})))),yield*t.readFile(s,yield*FM(i,e.timeout)).pipe(WO(e=>new _M({reason:`capture could not be read back: ${e.message}`})))}),zTe(s,n.probe_timeout_s*1e3).pipe(GO)),f=XN(u);if(!f.ok&&f.reason===`invalid_png`)return yield*z(`scrot did not produce a PNG screen capture`);let p=(f.ok,f.header);if(p===void 0||p.width!==r.dimensions[0]||p.height!==r.dimensions[1])return yield*z(`raw capture dimensions differ from the inspected display`);let m=yield*yN(e.stateDir,Math.max(.001,(i.endMs-(yield*NM))/1e3));if(m.session.run_id!==n.run_id||JSON.stringify(m.observation)!==JSON.stringify(r))return yield*z(`session or window manager changed during capture`);let h;if(e.window!==void 0&&o!==void 0){if(h=yield*SN(e.stateDir,n,e.window.id,i),!KEe(o,h))return yield*z(`window moved or changed during capture`);yield*a(e.window.id,h)}let g={run_id:n.run_id,output:e.output,bytes:u.length,sha256:oP(u),dimensions:[p.width,p.height],capture_started_at:c,capture_completed_at:yield*MM,capture_ms:(yield*NM)-l,window_manager:m.observation.window_manager??null,transformations:[]},_=h===void 0?void 0:{left:h.x,top:h.y,right:h.x+h.width,bottom:h.y+h.height};if(h!==void 0&&_!==void 0){if(!h.viewable)return yield*z(`window is not viewable`);if(_.left<0||_.top<0||_.right>p.width||_.bottom>p.height||_.left>=_.right||_.top>=_.bottom)return yield*z(`window is not entirely on the screen`);if(!f.ok)return yield*z(`raw capture is not an 8-bit RGB or RGBA PNG: ${f.reason}`)}if(yield*OM(e.output,u),yield*kM(`${e.output}.json`,g),e.window===void 0||_===void 0||!f.ok)return g;let v=QN(ZN(u),_),y=VEe(v);yield*OM(e.window.output,y);let ee=yield*iP([`--raw`,e.output,`--crop`,e.window.output,`--box`,String(_.left),String(_.top),String(_.right),String(_.bottom)]),x={run_id:n.run_id,window:e.window.id,raw:e.output,output:e.window.output,box:[_.left,_.top,_.right,_.bottom],bytes:y.length,sha256:oP(y),distinct_colors:HEe(v,4096),exact_crop:ee.report};return yield*kM(`${e.window.output}.json`,x),ee.exitCode===0?{...g,window:x}:yield*z(`window crop did not verify as an exact crop of the raw capture`)}),JEe=/\{[^{}]+\}/g,YEe=()=>typeof process==`object`&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function XEe(){return Math.random().toString(36).slice(2,11)}function cP(e){let{baseUrl:t=``,Request:n=globalThis.Request,fetch:r=globalThis.fetch,querySerializer:i,bodySerializer:a,pathSerializer:o,headers:s,requestInitExt:c=void 0,...l}={...e};c=YEe()?c:void 0,t=mP(t);let u=[];async function d(e,d){let{baseUrl:f,fetch:p=r,Request:m=n,headers:h,params:g={},parseAs:_=`json`,querySerializer:v,bodySerializer:y=a??QEe,pathSerializer:b,body:ee,middleware:x=[],...te}=d||{},ne=t;f&&(ne=mP(f)??t);let re=typeof i==`function`?i:fP(i);v&&(re=typeof v==`function`?v:fP({...typeof i==`object`?i:{},...v}));let ie=b||o||ZEe,ae=ee===void 0?void 0:y(ee,pP(s,h,g.header)),S=pP(ae===void 0||ae instanceof FormData?{}:{"Content-Type":`application/json`},s,h,g.header),oe=[...u,...x],C={redirect:`follow`,...l,...te,body:ae,headers:S},se,ce,le=new m($Ee(e,{baseUrl:ne,params:g,querySerializer:re,pathSerializer:ie}),C),ue;for(let e in te)e in le||(le[e]=te[e]);if(oe.length){se=XEe(),ce=Object.freeze({baseUrl:ne,fetch:p,parseAs:_,querySerializer:re,bodySerializer:y,pathSerializer:ie});for(let t of oe)if(t&&typeof t==`object`&&typeof t.onRequest==`function`){let n=await t.onRequest({request:le,schemaPath:e,params:g,options:ce,id:se});if(n){if(n instanceof m)le=n;else if(n instanceof Response){ue=n;break}else throw Error(`onRequest: must return new Request() or Response() when modifying the request`)}}}if(!ue){try{ue=await p(le,c)}catch(t){let n=t;if(oe.length)for(let t=oe.length-1;t>=0;t--){let r=oe[t];if(r&&typeof r==`object`&&typeof r.onError==`function`){let t=await r.onError({request:le,error:n,schemaPath:e,params:g,options:ce,id:se});if(t){if(t instanceof Response){n=void 0,ue=t;break}if(t instanceof Error){n=t;continue}throw Error(`onError: must return new Response() or instance of Error`)}}}if(n)throw n}if(oe.length)for(let t=oe.length-1;t>=0;t--){let n=oe[t];if(n&&typeof n==`object`&&typeof n.onResponse==`function`){let t=await n.onResponse({request:le,response:ue,schemaPath:e,params:g,options:ce,id:se});if(t){if(!(t instanceof Response))throw Error(`onResponse: must return new Response() when modifying the response`);ue=t}}}}let w=ue.headers.get(`Content-Length`);if(ue.status===204||le.method===`HEAD`||w===`0`&&!ue.headers.get(`Transfer-Encoding`)?.includes(`chunked`))return ue.ok?{data:void 0,response:ue}:{error:void 0,response:ue};if(ue.ok)return{data:await(async()=>{if(_===`stream`)return ue.body;if(_===`json`&&!w){let e=await ue.text();return e?JSON.parse(e):void 0}return await ue[_]()})(),response:ue};let de=await ue.text();try{de=JSON.parse(de)}catch{}return{error:de,response:ue}}return{request(e,t,n){return d(t,{...n,method:e.toUpperCase()})},GET(e,t){return d(e,{...t,method:`GET`})},PUT(e,t){return d(e,{...t,method:`PUT`})},POST(e,t){return d(e,{...t,method:`POST`})},DELETE(e,t){return d(e,{...t,method:`DELETE`})},OPTIONS(e,t){return d(e,{...t,method:`OPTIONS`})},HEAD(e,t){return d(e,{...t,method:`HEAD`})},PATCH(e,t){return d(e,{...t,method:`PATCH`})},TRACE(e,t){return d(e,{...t,method:`TRACE`})},use(...e){for(let t of e)if(t){if(typeof t!=`object`||!(`onRequest`in t||`onResponse`in t||`onError`in t))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");u.push(t)}},eject(...e){for(let t of e){let e=u.indexOf(t);e!==-1&&u.splice(e,1)}}}}function lP(e,t,n){if(t==null)return``;if(typeof t==`object`)throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${n?.allowReserved===!0?t:encodeURIComponent(t)}`}function uP(e,t,n){if(!t||typeof t!=`object`)return``;let r=[],i={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`;if(n.style!==`deepObject`&&n.explode===!1){for(let e in t)r.push(e,n.allowReserved===!0?t[e]:encodeURIComponent(t[e]));let i=r.join(`,`);switch(n.style){case`form`:return`${e}=${i}`;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return i}}for(let i in t){let a=n.style===`deepObject`?`${e}[${i}]`:i;r.push(lP(a,t[i],n))}let a=r.join(i);return n.style===`label`||n.style===`matrix`?`${i}${a}`:a}function dP(e,t,n){if(!Array.isArray(t))return``;if(n.explode===!1){let r={form:`,`,spaceDelimited:`%20`,pipeDelimited:`|`}[n.style]||`,`,i=(n.allowReserved===!0?t:t.map(e=>encodeURIComponent(e))).join(r);switch(n.style){case`simple`:return i;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return`${e}=${i}`}}let r={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`,i=[];for(let r of t)n.style===`simple`||n.style===`label`?i.push(n.allowReserved===!0?r:encodeURIComponent(r)):i.push(lP(e,r,n));return n.style===`label`||n.style===`matrix`?`${r}${i.join(r)}`:i.join(r)}function fP(e){return function(t){let n=[];if(t&&typeof t==`object`)for(let r in t){let i=t[r];if(i!=null){if(Array.isArray(i)){if(i.length===0)continue;n.push(dP(r,i,{style:`form`,explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==`object`){n.push(uP(r,i,{style:`deepObject`,explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}n.push(lP(r,i,e))}}return n.join(`&`)}}function ZEe(e,t){let n=e;for(let r of e.match(JEe)??[]){let e=r.substring(1,r.length-1),i=!1,a=`simple`;if(e.endsWith(`*`)&&(i=!0,e=e.substring(0,e.length-1)),e.startsWith(`.`)?(a=`label`,e=e.substring(1)):e.startsWith(`;`)&&(a=`matrix`,e=e.substring(1)),!t||t[e]===void 0||t[e]===null)continue;let o=t[e];if(Array.isArray(o)){n=n.replace(r,dP(e,o,{style:a,explode:i}));continue}if(typeof o==`object`){n=n.replace(r,uP(e,o,{style:a,explode:i}));continue}if(a===`matrix`){n=n.replace(r,`;${lP(e,o)}`);continue}n=n.replace(r,a===`label`?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return n}function QEe(e,t){return e instanceof FormData?e:t&&(t.get instanceof Function?t.get(`Content-Type`)??t.get(`content-type`):t[`Content-Type`]??t[`content-type`])===`application/x-www-form-urlencoded`?new URLSearchParams(e).toString():JSON.stringify(e)}function $Ee(e,t){let n=`${t.baseUrl}${e}`;t.params?.path&&(n=t.pathSerializer(n,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith(`?`)&&(r=r.substring(1)),r&&(n+=`?${r}`),n}function pP(...e){let t=new Headers;for(let n of e){if(!n||typeof n!=`object`)continue;let e=n instanceof Headers?n.entries():Object.entries(n);for(let[n,r]of e)if(r===null)t.delete(n);else if(Array.isArray(r))for(let e of r)t.append(n,e);else r!==void 0&&t.set(n,r)}return t}function mP(e){return e.endsWith(`/`)?e.substring(0,e.length-1):e}var eDe=Oe(((e,t)=>{(function(){var n={function:!0,object:!0},r=n[typeof window]&&window||this,i=n[typeof e]&&e,a=n[typeof t]&&t&&!t.nodeType&&t,o=i&&a&&typeof global==`object`&&global;o&&(o.global===o||o.window===o||o.self===o)&&(r=o);var s=2**53-1,c=/\bOpera/,l=Object.prototype,u=l.hasOwnProperty,d=l.toString;function f(e){return e=String(e),e.charAt(0).toUpperCase()+e.slice(1)}function p(e,t,n){var r={"10.0":`10`,"6.4":`10 Technical Preview`,"6.3":`8.1`,"6.2":`8`,"6.1":`Server 2008 R2 / 7`,"6.0":`Server 2008 / Vista`,"5.2":`Server 2003 / XP 64-bit`,"5.1":`XP`,"5.01":`2000 SP1`,"5.0":`2000`,"4.0":`NT`,"4.90":`ME`};return t&&n&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])&&(e=`Windows `+r),e=String(e),t&&n&&(e=e.replace(RegExp(t,`i`),n)),e=h(e.replace(/ ce$/i,` CE`).replace(/\bhpw/i,`web`).replace(/\bMacintosh\b/,`Mac OS`).replace(/_PowerPC\b/i,` OS`).replace(/\b(OS X) [^ \d]+/i,`$1`).replace(/\bMac (OS X)\b/,`$1`).replace(/\/(\d)/,` $1`).replace(/_/g,`.`).replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,``).replace(/\bx86\.64\b/gi,`x86_64`).replace(/\b(Windows Phone) OS\b/,`$1`).replace(/\b(Chrome OS \w+) [\d.]+\b/,`$1`).split(` on `)[0]),e}function m(e,t){var n=-1,r=e?e.length:0;if(typeof r==`number`&&r>-1&&r<=s)for(;++n<r;)t(e[n],n,e);else g(e,t)}function h(e){return e=ee(e),/^(?:webOS|i(?:OS|P))/.test(e)?e:f(e)}function g(e,t){for(var n in e)u.call(e,n)&&t(e[n],n,e)}function _(e){return e==null?f(e):d.call(e).slice(8,-1)}function v(e,t){var n=e==null?`number`:typeof e[t];return!/^(?:boolean|number|string|undefined)$/.test(n)&&(n!=`object`||!!e[t])}function y(e){return String(e).replace(/([ -])(?!$)/g,`$1?`)}function b(e,t){var n=null;return m(e,function(r,i){n=t(n,r,i,e)}),n}function ee(e){return String(e).replace(/^ +| +$/g,``)}function x(e){var t=r,n=e&&typeof e==`object`&&_(e)!=`String`;n&&(t=e,e=null);var i=t.navigator||{},a=i.userAgent||``;e||=a;var o=n?!!i.likeChrome:/\bChrome\b/.test(e)&&!/internal|\n/i.test(d.toString()),s=`Object`,l=n?s:`ScriptBridgingProxyObject`,u=n?s:`Environment`,f=n&&t.java?`JavaPackage`:_(t.java),m=n?s:`RuntimeObject`,te=/\bJava/.test(f)&&t.java,ne=te&&_(t.environment)==u,re=te?`a`:`α`,ie=te?`b`:`β`,ae=t.document||{},S=t.operamini||t.opera,oe=c.test(oe=n&&S?S[`[[Class]]`]:_(S))?oe:S=null,C,se=e,ce=[],le=null,ue=e==a,w=ue&&S&&typeof S.version==`function`&&S.version(),de,fe=he([{label:`EdgeHTML`,pattern:`Edge`},`Trident`,{label:`WebKit`,pattern:`AppleWebKit`},`iCab`,`Presto`,`NetFront`,`Tasman`,`KHTML`,`Gecko`]),T=_e([`Adobe AIR`,`Arora`,`Avant Browser`,`Breach`,`Camino`,`Electron`,`Epiphany`,`Fennec`,`Flock`,`Galeon`,`GreenBrowser`,`iCab`,`Iceweasel`,`K-Meleon`,`Konqueror`,`Lunascape`,`Maxthon`,{label:`Microsoft Edge`,pattern:`(?:Edge|Edg|EdgA|EdgiOS)`},`Midori`,`Nook Browser`,`PaleMoon`,`PhantomJS`,`Raven`,`Rekonq`,`RockMelt`,{label:`Samsung Internet`,pattern:`SamsungBrowser`},`SeaMonkey`,{label:`Silk`,pattern:`(?:Cloud9|Silk-Accelerated)`},`Sleipnir`,`SlimBrowser`,{label:`SRWare Iron`,pattern:`Iron`},`Sunrise`,`Swiftfox`,`Vivaldi`,`Waterfox`,`WebPositive`,{label:`Yandex Browser`,pattern:`YaBrowser`},{label:`UC Browser`,pattern:`UCBrowser`},`Opera Mini`,{label:`Opera Mini`,pattern:`OPiOS`},`Opera`,{label:`Opera`,pattern:`OPR`},`Chromium`,`Chrome`,{label:`Chrome`,pattern:`(?:HeadlessChrome)`},{label:`Chrome Mobile`,pattern:`(?:CriOS|CrMo)`},{label:`Firefox`,pattern:`(?:Firefox|Minefield)`},{label:`Firefox for iOS`,pattern:`FxiOS`},{label:`IE`,pattern:`IEMobile`},{label:`IE`,pattern:`MSIE`},`Safari`]),pe=ye([{label:`BlackBerry`,pattern:`BB10`},`BlackBerry`,{label:`Galaxy S`,pattern:`GT-I9000`},{label:`Galaxy S2`,pattern:`GT-I9100`},{label:`Galaxy S3`,pattern:`GT-I9300`},{label:`Galaxy S4`,pattern:`GT-I9500`},{label:`Galaxy S5`,pattern:`SM-G900`},{label:`Galaxy S6`,pattern:`SM-G920`},{label:`Galaxy S6 Edge`,pattern:`SM-G925`},{label:`Galaxy S7`,pattern:`SM-G930`},{label:`Galaxy S7 Edge`,pattern:`SM-G935`},`Google TV`,`Lumia`,`iPad`,`iPod`,`iPhone`,`Kindle`,{label:`Kindle Fire`,pattern:`(?:Cloud9|Silk-Accelerated)`},`Nexus`,`Nook`,`PlayBook`,`PlayStation Vita`,`PlayStation`,`TouchPad`,`Transformer`,{label:`Wii U`,pattern:`WiiU`},`Wii`,`Xbox One`,{label:`Xbox 360`,pattern:`Xbox`},`Xoom`]),me=ge({Apple:{iPad:1,iPhone:1,iPod:1},Alcatel:{},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},Huawei:{},Lenovo:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Oppo:{},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1},Xiaomi:{Mi:1,Redmi:1}}),E=ve([`Windows Phone`,`KaiOS`,`Android`,`CentOS`,{label:`Chrome OS`,pattern:`CrOS`},`Debian`,{label:`DragonFly BSD`,pattern:`DragonFly`},`Fedora`,`FreeBSD`,`Gentoo`,`Haiku`,`Kubuntu`,`Linux Mint`,`OpenBSD`,`Red Hat`,`SuSE`,`Ubuntu`,`Xubuntu`,`Cygwin`,`Symbian OS`,`hpwOS`,`webOS `,`webOS`,`Tablet OS`,`Tizen`,`Linux`,`Mac OS X`,`Macintosh`,`Mac`,`Windows 98;`,`Windows `]);function he(t){return b(t,function(t,n){return t||RegExp(`\\b`+(n.pattern||y(n))+`\\b`,`i`).exec(e)&&(n.label||n)})}function ge(t){return b(t,function(t,n,r){return t||(n[pe]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(pe)]||RegExp(`\\b`+y(r)+`(?:\\b|\\w*\\d)`,`i`).exec(e))&&r})}function _e(t){return b(t,function(t,n){return t||RegExp(`\\b`+(n.pattern||y(n))+`\\b`,`i`).exec(e)&&(n.label||n)})}function ve(t){return b(t,function(t,n){var r=n.pattern||y(n);return!t&&(t=RegExp(`\\b`+r+`(?:/[\\d.]+|[ \\w.]*)`,`i`).exec(e))&&(t=p(t,r,n.label||n)),t})}function ye(t){return b(t,function(t,n){var r=n.pattern||y(n);return!t&&(t=RegExp(`\\b`+r+` *\\d+[.\\w_]*`,`i`).exec(e)||RegExp(`\\b`+r+` *\\w+-[\\w]*`,`i`).exec(e)||RegExp(`\\b`+r+`(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)`,`i`).exec(e))&&((t=String(n.label&&!RegExp(r,`i`).test(n.label)?n.label:t).split(`/`))[1]&&!/[\d.]+/.test(t[0])&&(t[0]+=` `+t[1]),n=n.label||n,t=h(t[0].replace(RegExp(r,`i`),n).replace(RegExp(`; *(?:`+n+`[_-])?`,`i`),` `).replace(RegExp(`(`+n+`)[-_.]?(\\w)`,`i`),`$1 $2`))),t})}function be(t){return b(t,function(t,n){return t||(RegExp(n+`(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)`,`i`).exec(e)||0)[1]||null})}function xe(){return this.description||``}if(fe&&=[fe],/\bAndroid\b/.test(E)&&!pe&&(C=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(e))&&(pe=ee(C[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,``)||null),me&&!pe?pe=ye([me]):me&&pe&&(pe=pe.replace(RegExp(`^(`+y(me)+`)[-_.\\s]`,`i`),me+` `).replace(RegExp(`^(`+y(me)+`)[-_.]?(\\w)`,`i`),me+` $2`)),(C=/\bGoogle TV\b/.exec(pe))&&(pe=C[0]),/\bSimulator\b/i.test(e)&&(pe=(pe?pe+` `:``)+`Simulator`),T==`Opera Mini`&&/\bOPiOS\b/.test(e)&&ce.push(`running in Turbo/Uncompressed mode`),T==`IE`&&/\blike iPhone OS\b/.test(e)?(C=x(e.replace(/like iPhone OS/,``)),me=C.manufacturer,pe=C.product):/^iP/.test(pe)?(T||=`Safari`,E=`iOS`+((C=/ OS ([\d_]+)/i.exec(e))?` `+C[1].replace(/_/g,`.`):``)):T==`Konqueror`&&/^Linux\b/i.test(E)?E=`Kubuntu`:me&&me!=`Google`&&(/Chrome/.test(T)&&!/\bMobile Safari\b/i.test(e)||/\bVita\b/.test(pe))||/\bAndroid\b/.test(E)&&/^Chrome/.test(T)&&/\bVersion\//i.test(e)?(T=`Android Browser`,E=/\bAndroid\b/.test(E)?E:`Android`):T==`Silk`?(/\bMobi/i.test(e)||(E=`Android`,ce.unshift(`desktop mode`)),/Accelerated *= *true/i.test(e)&&ce.unshift(`accelerated`)):T==`UC Browser`&&/\bUCWEB\b/.test(e)?ce.push(`speed mode`):T==`PaleMoon`&&(C=/\bFirefox\/([\d.]+)\b/.exec(e))?ce.push(`identifying as Firefox `+C[1]):T==`Firefox`&&(C=/\b(Mobile|Tablet|TV)\b/i.exec(e))?(E||=`Firefox OS`,pe||=C[1]):!T||(C=!/\bMinefield\b/i.test(e)&&/\b(?:Firefox|Safari)\b/.exec(T))?(T&&!pe&&/[\/,]|^[^(]+?\)/.test(e.slice(e.indexOf(C+`/`)+8))&&(T=null),(C=pe||me||E)&&(pe||me||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(E))&&(T=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(E)?E:C)+` Browser`)):T==`Electron`&&(C=(/\bChrome\/([\d.]+)\b/.exec(e)||0)[1])&&ce.push(`Chromium `+C),w||=be([`(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)`,`Version`,y(T),`(?:Firefox|Minefield|NetFront)`]),(C=fe==`iCab`&&parseFloat(w)>3&&`WebKit`||/\bOpera\b/.test(T)&&(/\bOPR\b/.test(e)?`Blink`:`Presto`)||/\b(?:Midori|Nook|Safari)\b/i.test(e)&&!/^(?:Trident|EdgeHTML)$/.test(fe)&&`WebKit`||!fe&&/\bMSIE\b/i.test(e)&&(E==`Mac OS`?`Tasman`:`Trident`)||fe==`WebKit`&&/\bPlayStation\b(?! Vita\b)/i.test(T)&&`NetFront`)&&(fe=[C]),T==`IE`&&(C=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(e)||0)[1])?(T+=` Mobile`,E=`Windows Phone `+(/\+$/.test(C)?C:C+`.x`),ce.unshift(`desktop mode`)):/\bWPDesktop\b/i.test(e)?(T=`IE Mobile`,E=`Windows Phone 8.x`,ce.unshift(`desktop mode`),w||=(/\brv:([\d.]+)/.exec(e)||0)[1]):T!=`IE`&&fe==`Trident`&&(C=/\brv:([\d.]+)/.exec(e))&&(T&&ce.push(`identifying as `+T+(w?` `+w:``)),T=`IE`,w=C[1]),ue){if(v(t,`global`)){if(te&&(C=te.lang.System,se=C.getProperty(`os.arch`),E||=C.getProperty(`os.name`)+` `+C.getProperty(`os.version`)),ne){try{w=(()=>{throw Error(`impulse-compute loads no package at run time`)})().version.join(`.`),T=`RingoJS`}catch{(C=t.system)&&C.global.system==t.system&&(T=`Narwhal`,E||=C[0].os||null)}T||=`Rhino`}else typeof t.process==`object`&&!t.process.browser&&(C=t.process)&&(typeof C.versions==`object`&&(typeof C.versions.electron==`string`?(ce.push(`Node `+C.versions.node),T=`Electron`,w=C.versions.electron):typeof C.versions.nw==`string`&&(ce.push(`Chromium `+w,`Node `+C.versions.node),T=`NW.js`,w=C.versions.nw)),T||(T=`Node.js`,se=C.arch,E=C.platform,w=/[\d.]+/.exec(C.version),w=w?w[0]:null))}else _(C=t.runtime)==l?(T=`Adobe AIR`,E=C.flash.system.Capabilities.os):_(C=t.phantom)==m?(T=`PhantomJS`,w=(C=C.version||null)&&C.major+`.`+C.minor+`.`+C.patch):typeof ae.documentMode==`number`&&(C=/\bTrident\/(\d+)/i.exec(e))?(w=[w,ae.documentMode],(C=+C[1]+4)!=w[1]&&(ce.push(`IE `+w[1]+` mode`),fe&&(fe[1]=``),w[1]=C),w=T==`IE`?String(w[1].toFixed(1)):w[0]):typeof ae.documentMode==`number`&&/^(?:Chrome|Firefox)\b/.test(T)&&(ce.push(`masking as `+T+` `+w),T=`IE`,w=`11.0`,fe=[`Trident`],E=`Windows`);E&&=h(E)}if(w&&(C=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(w)||/(?:alpha|beta)(?: ?\d)?/i.exec(e+`;`+(ue&&i.appMinorVersion))||/\bMinefield\b/i.test(e)&&`a`)&&(le=/b/i.test(C)?`beta`:`alpha`,w=w.replace(RegExp(C+`\\+?$`),``)+(le==`beta`?ie:re)+(/\d+\+?/.exec(C)||``)),T==`Fennec`||T==`Firefox`&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(E))T=`Firefox Mobile`;else if(T==`Maxthon`&&w)w=w.replace(/\.[\d.]+/,`.x`);else if(/\bXbox\b/i.test(pe))pe==`Xbox 360`&&(E=null),pe==`Xbox 360`&&/\bIEMobile\b/.test(e)&&ce.unshift(`mobile mode`);else if((/^(?:Chrome|IE|Opera)$/.test(T)||T&&!pe&&!/Browser|Mobi/.test(T))&&(E==`Windows CE`||/Mobi/i.test(e)))T+=` Mobile`;else if(T==`IE`&&ue)try{t.external===null&&ce.unshift(`platform preview`)}catch{ce.unshift(`embedded`)}else(/\bBlackBerry\b/.test(pe)||/\bBB10\b/.test(e))&&(C=(RegExp(pe.replace(/ +/g,` *`)+`/([.\\d]+)`,`i`).exec(e)||0)[1]||w)?(C=[C,/BB10/.test(e)],E=(C[1]?(pe=null,me=`BlackBerry`):`Device Software`)+` `+C[0],w=null):this!=g&&pe!=`Wii`&&(ue&&S||/Opera/.test(T)&&/\b(?:MSIE|Firefox)\b/i.test(e)||T==`Firefox`&&/\bOS X (?:\d+\.){2,}/.test(E)||T==`IE`&&(E&&!/^Win/.test(E)&&w>5.5||/\bWindows XP\b/.test(E)&&w>8||w==8&&!/\bTrident\b/.test(e)))&&!c.test(C=x.call(g,e.replace(c,``)+`;`))&&C.name&&(C=`ing as `+C.name+((C=C.version)?` `+C:``),c.test(T)?(/\bIE\b/.test(C)&&E==`Mac OS`&&(E=null),C=`identify`+C):(C=`mask`+C,T=oe?h(oe.replace(/([a-z])([A-Z])/g,`$1 $2`)):`Opera`,/\bIE\b/.test(C)&&(E=null),ue||(w=null)),fe=[`Presto`],ce.push(C));(C=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(e)||0)[1])&&(C=[parseFloat(C.replace(/\.(\d)$/,`.0$1`)),C],T==`Safari`&&C[1].slice(-1)==`+`?(T=`WebKit Nightly`,le=`alpha`,w=C[1].slice(0,-1)):(w==C[1]||w==(C[2]=(/\bSafari\/([\d.]+\+?)/i.exec(e)||0)[1]))&&(w=null),C[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(e)||0)[1],C[0]==537.36&&C[2]==537.36&&parseFloat(C[1])>=28&&fe==`WebKit`&&(fe=[`Blink`]),!ue||!o&&!C[1]?(fe&&(fe[1]=`like Safari`),C=(C=C[0],C<400?1:C<500?2:C<526?3:C<533?4:C<534?`4+`:C<535?5:C<537?6:C<538?7:C<601?8:C<602?9:C<604?10:C<606?11:C<608?12:`12`)):(fe&&(fe[1]=`like Chrome`),C=C[1]||(C=C[0],C<530?1:C<532?2:C<532.05?3:C<533?4:C<534.03?5:C<534.07?6:C<534.1?7:C<534.13?8:C<534.16?9:C<534.24?10:C<534.3?11:C<535.01?12:C<535.02?`13+`:C<535.07?15:C<535.11?16:C<535.19?17:C<536.05?18:C<536.1?19:C<537.01?20:C<537.11?`21+`:C<537.13?23:C<537.18?24:C<537.24?25:C<537.36?26:fe==`Blink`?`28`:`27`)),fe&&(fe[1]+=` `+(C+=typeof C==`number`?`.x`:/[.+]/.test(C)?``:`+`)),T==`Safari`&&(!w||parseInt(w)>45)?w=C:T==`Chrome`&&/\bHeadlessChrome/i.test(e)&&ce.unshift(`headless`)),T==`Opera`&&(C=/\bzbov|zvav$/.exec(E))?(T+=` `,ce.unshift(`desktop mode`),C==`zvav`?(T+=`Mini`,w=null):T+=`Mobile`,E=E.replace(RegExp(` *`+C+`$`),``)):T==`Safari`&&/\bChrome\b/.exec(fe&&fe[1])?(ce.unshift(`desktop mode`),T=`Chrome Mobile`,w=null,/\bOS X\b/.test(E)?(me=`Apple`,E=`iOS 4.3+`):E=null):/\bSRWare Iron\b/.test(T)&&!w&&(w=be(`Chrome`)),w&&w.indexOf(C=/[\d.]+$/.exec(E))==0&&e.indexOf(`/`+C+`-`)>-1&&(E=ee(E.replace(C,``))),E&&E.indexOf(T)!=-1&&!RegExp(T+` OS`).test(E)&&(E=E.replace(RegExp(` *`+y(T)+` *`),``)),fe&&!/\b(?:Avant|Nook)\b/.test(T)&&(/Browser|Lunascape|Maxthon/.test(T)||T!=`Safari`&&/^iOS/.test(E)&&/\bSafari\b/.test(fe[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(T)&&fe[1])&&(C=fe[fe.length-1])&&ce.push(C),ce.length&&(ce=[`(`+ce.join(`; `)+`)`]),me&&pe&&pe.indexOf(me)<0&&ce.push(`on `+me),pe&&ce.push((/^on /.test(ce[ce.length-1])?``:`on `)+pe),E&&=(C=/ ([\d.+]+)$/.exec(E),de=C&&E.charAt(E.length-C[0].length-1)==`/`,{architecture:32,family:C&&!de?E.replace(C[0],``):E,version:C?C[1]:null,toString:function(){var e=this.version;return this.family+(e&&!de?` `+e:``)+(this.architecture==64?` 64-bit`:``)}}),(C=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(se))&&!/\bi686\b/i.test(se)?(E&&(E.architecture=64,E.family=E.family.replace(RegExp(` *`+C),``)),T&&(/\bWOW64\b/i.test(e)||ue&&/\w(?:86|32)$/.test(i.cpuClass||i.platform)&&!/\bWin64; x64\b/i.test(e))&&ce.unshift(`32-bit`)):E&&/^OS X/.test(E.family)&&T==`Chrome`&&parseFloat(w)>=39&&(E.architecture=64),e||=null;var Se={};return Se.description=e,Se.layout=fe&&fe[0],Se.manufacturer=me,Se.name=T,Se.prerelease=le,Se.product=pe,Se.ua=e,Se.version=T&&w,Se.os=E||{architecture:null,family:null,version:null,toString:function(){return`null`}},Se.parse=x,Se.toString=xe,Se.version&&ce.unshift(w),Se.name&&ce.unshift(T),E&&T&&(E!=String(E).split(` `)[0]||E!=T.split(` `)[0]&&!pe)&&ce.push(pe?`(`+E+`)`:`on `+E),ce.length&&(Se.description=ce.join(` `)),Se}var te=x();typeof define==`function`&&typeof define.amd==`object`&&define.amd?(r.platform=te,define(function(){return te})):i&&a?g(te,function(e,t){i[t]=e}):r.platform=te}).call(e)}));const tDe=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,hP=e=>{if(typeof e!=`string`)throw TypeError(`Invalid argument expected string`);let t=e.match(tDe);if(!t)throw Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},gP=e=>e===`*`||e===`x`||e===`X`,_P=e=>{let t=parseInt(e,10);return isNaN(t)?e:t},nDe=(e,t)=>typeof e==typeof t?[e,t]:[String(e),String(t)],rDe=(e,t)=>{if(gP(e)||gP(t))return 0;let[n,r]=nDe(_P(e),_P(t));return n>r?1:n<r?-1:0},vP=(e,t)=>{for(let n=0;n<Math.max(e.length,t.length);n++){let r=rDe(e[n]||`0`,t[n]||`0`);if(r!==0)return r}return 0},yP=(e,t)=>{let n=hP(e),r=hP(t),i=n.pop(),a=r.pop(),o=vP(n,r);return o===0?i&&a?vP(i.split(`.`),a.split(`.`)):i||a?i?-1:1:0:o};var B;(function(e){e[e.Canceled=1]=`Canceled`,e[e.Unknown=2]=`Unknown`,e[e.InvalidArgument=3]=`InvalidArgument`,e[e.DeadlineExceeded=4]=`DeadlineExceeded`,e[e.NotFound=5]=`NotFound`,e[e.AlreadyExists=6]=`AlreadyExists`,e[e.PermissionDenied=7]=`PermissionDenied`,e[e.ResourceExhausted=8]=`ResourceExhausted`,e[e.FailedPrecondition=9]=`FailedPrecondition`,e[e.Aborted=10]=`Aborted`,e[e.OutOfRange=11]=`OutOfRange`,e[e.Unimplemented=12]=`Unimplemented`,e[e.Internal=13]=`Internal`,e[e.Unavailable=14]=`Unavailable`,e[e.DataLoss=15]=`DataLoss`,e[e.Unauthenticated=16]=`Unauthenticated`})(B||={});function bP(e,t){return typeof e==`object`&&e&&`$typeName`in e&&typeof e.$typeName==`string`?t===void 0||t.typeName===e.$typeName:!1}var V;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`})(V||={});function iDe(){let e=this.buf,t=this.pos,n=0,r=0;for(let i=0;i<28;i+=7){let a=e[t++];if(n|=(a&127)<<i,!(a&128)){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}let i=e[t++];if(n|=(i&15)<<28,r=(i&112)>>4,!(i&128)){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}for(let i=3;i<=31;i+=7){let a=e[t++];if(r|=(a&127)<<i,!(a&128)){this.pos=t,this.assertBounds(),this.varint64Lo=n,this.varint64Hi=r;return}}throw Error(`invalid varint`)}const xP=4294967296;function SP(e){let t=e[0]===`-`;t&&(e=e.slice(1));let n=1e6,r=0,i=0;function a(t,a){let o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=xP&&(i+=r/xP|0,r%=xP)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?TP(r,i):wP(r,i)}function aDe(e,t){let n=wP(e,t),r=n.hi&2147483648;r&&(n=TP(n.lo,n.hi));let i=CP(n.lo,n.hi);return r?`-`+i:i}function CP(e,t){if({lo:e,hi:t}=oDe(e,t),t<=2097151)return String(xP*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,i=t>>16&65535,a=n+r*6777216+i*6710656,o=r+i*8147497,s=i*2,c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+EP(o)+EP(a)}function oDe(e,t){return{lo:e>>>0,hi:t>>>0}}function wP(e,t){return{lo:e|0,hi:t|0}}function TP(e,t){return t=~t,e?e=~e+1:t+=1,wP(e,t)}const EP=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function sDe(e,t){if(e>>>0<128){t.push(e);return}if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function cDe(){let e=this.buf[this.pos++];if(!(e&128))return this.assertBounds(),e;let t=e&127;if(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let t=5;e&128&&t<10;t++)e=this.buf[this.pos++];if(e&128)throw Error(`invalid varint`);return this.assertBounds(),t>>>0}const DP=lDe();function lDe(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt==`function`&&typeof e.getBigInt64==`function`&&typeof e.getBigUint64==`function`&&typeof e.setBigInt64==`function`&&typeof e.setBigUint64==`function`&&(globalThis.Deno||globalThis.Bun||typeof process!=`object`||typeof process.env!=`object`||process.env.BUF_BIGINT_DISABLE!==`1`)){let t=BigInt(`-9223372036854775808`),n=BigInt(`9223372036854775807`),r=BigInt(`0`),i=BigInt(`18446744073709551615`);return{zero:BigInt(0),supported:!0,parse(e){let r=typeof e==`bigint`?e:BigInt(e);if(r>n||r<t)throw Error(`invalid int64: ${e}`);return r},uParse(e){let t=typeof e==`bigint`?e:BigInt(e);if(t>i||t<r)throw Error(`invalid uint64: ${e}`);return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)},uDec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0)}}}return{zero:`0`,supported:!1,parse(e){return typeof e!=`string`&&(e=e.toString()),OP(e),e},uParse(e){return typeof e!=`string`&&(e=e.toString()),kP(e),e},enc(e){return typeof e!=`string`&&(e=e.toString()),OP(e),SP(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),kP(e),SP(e)},dec(e,t){return aDe(e,t)},uDec(e,t){return CP(e,t)}}}function OP(e){if(!/^-?[0-9]+$/.test(e))throw Error(`invalid int64: `+e)}function kP(e){if(!/^[0-9]+$/.test(e))throw Error(`invalid uint64: `+e)}function AP(e,t){switch(e){case V.STRING:return``;case V.BOOL:return!1;case V.DOUBLE:case V.FLOAT:return 0;case V.INT64:case V.UINT64:case V.SFIXED64:case V.FIXED64:case V.SINT64:return t?`0`:DP.zero;case V.BYTES:return new Uint8Array;default:return 0}}function uDe(e,t){switch(e){case V.BOOL:return t===!1;case V.STRING:return t===``;case V.BYTES:return t instanceof Uint8Array&&!t.byteLength;case V.DOUBLE:case V.FLOAT:return Object.is(t,0);default:return t==0}}const jP=Symbol.for(`reflect unsafe local`);function dDe(e,t){let n=e[t.localName].case;return n===void 0?n:t.fields.find(e=>e.localName===n)}function fDe(e,t){let n=t.localName;if(t.oneof)return e[t.oneof.localName].case===n;if(t.presence!=2)return e[n]!==void 0&&Object.prototype.hasOwnProperty.call(e,n);switch(t.fieldKind){case`list`:return e[n].length>0;case`map`:return Object.keys(e[n]).length>0;case`scalar`:return!uDe(t.scalar,e[n]);case`enum`:return e[n]!==t.enum.values[0].number}throw Error(`message field with implicit presence`)}function MP(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&e[t]!==void 0}function pDe(e,t){if(t.oneof){let n=e[t.oneof.localName];return n.case===t.localName?n.value:void 0}return e[t.localName]}function mDe(e,t,n){t.oneof?e[t.oneof.localName]={case:t.localName,value:n}:e[t.localName]=n}function NP(e,t,n){t===`__proto__`?Object.defineProperty(e,"__proto__",{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function hDe(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function gDe(e,t){let n=t.localName;if(t.oneof){let r=t.oneof.localName;e[r].case===n&&(e[r]={case:void 0})}else if(t.presence!=2)delete e[n];else switch(t.fieldKind){case`map`:e[n]={};break;case`list`:e[n]=[];break;case`enum`:e[n]=t.enum.values[0].number;break;case`scalar`:e[n]=AP(t.scalar,t.longAsString)}}function PP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function FP(e,t){if(PP(e)&&jP in e&&`add`in e&&`field`in e&&typeof e.field==`function`){if(t!==void 0){let n=t,r=e.field();return n.listKind==r.listKind&&n.scalar===r.scalar&&n.message?.typeName===r.message?.typeName&&n.enum?.typeName===r.enum?.typeName}return!0}return!1}function IP(e,t){if(PP(e)&&jP in e&&`has`in e&&`field`in e&&typeof e.field==`function`){if(t!==void 0){let n=t,r=e.field();return n.mapKey===r.mapKey&&n.mapKind==r.mapKind&&n.scalar===r.scalar&&n.message?.typeName===r.message?.typeName&&n.enum?.typeName===r.enum?.typeName}return!0}return!1}function LP(e,t){return PP(e)&&jP in e&&`desc`in e&&PP(e.desc)&&e.desc.kind===`message`&&(t===void 0||e.desc.typeName==t.typeName)}function _De(e){return BP(e.$typeName)}function RP(e){let t=e.fields[0];return BP(e.typeName)&&t!==void 0&&t.fieldKind==`scalar`&&t.name==`value`&&t.number==1}function zP(e){switch(e.typeName){case`google.protobuf.Any`:case`google.protobuf.Timestamp`:case`google.protobuf.Duration`:case`google.protobuf.FieldMask`:case`google.protobuf.Struct`:case`google.protobuf.Value`:case`google.protobuf.ListValue`:return!0;default:return RP(e)}}const vDe=new Set([`google.protobuf.DoubleValue`,`google.protobuf.FloatValue`,`google.protobuf.Int64Value`,`google.protobuf.UInt64Value`,`google.protobuf.Int32Value`,`google.protobuf.UInt32Value`,`google.protobuf.BoolValue`,`google.protobuf.StringValue`,`google.protobuf.BytesValue`]);function BP(e){return vDe.has(e)}function VP(e,t){return bP(t,e)?t:UP(e)(t)}const HP=new WeakMap;function UP(e){let t=HP.get(e);return t===void 0&&(t=yDe(e),HP.set(e,t)),t}function yDe(e){let t=e.typeName,{properties:n,prototype:r}=bDe(e);return e=>{let i;r===void 0?i={$typeName:t}:(i=Object.create(r),i.$typeName=t);for(let t=0;t<n.length;t++){let r=n[t],a=r.name,o=e?.[a];switch(r.kind){case 0:o==null?r.constant!==void 0&&(i[a]=r.constant):i[a]=r.convert===void 0?o:r.convert(o);break;case 1:i[a]=r.convert!==void 0&&Array.isArray(o)?o.map(r.convert):o??[];break;case 2:if(r.convert===void 0||!PP(o))i[a]=o??{};else{let e={},t=Object.keys(o);for(let n=0;n<t.length;n++)NP(e,t[n],r.convert(o[t[n]]));i[a]=e}break;case 3:{let e=o;if(e?.case!=null){let t=r.convert.get(e.case);if(t!==void 0){i[a]={case:e.case,value:t(e.value)};break}}i[a]={case:void 0};break}}}return i}}function bDe(e){let t=[],n={},r=SDe(e);for(let i of e.members){let e=i.localName;if(i.kind==`oneof`){t.push({name:e,kind:3,constant:void 0,convert:xDe(i)});continue}switch(i.fieldKind){case`message`:t.push({name:e,kind:0,constant:void 0,convert:WP(i)});break;case`list`:t.push({name:e,kind:1,constant:void 0,convert:i.listKind==`message`?WP(i)??(e=>e):i.scalar==V.BYTES?GP:void 0});break;case`map`:t.push({name:e,kind:2,constant:void 0,convert:i.mapKind==`message`?WP(i)??(e=>e):i.scalar==V.BYTES?GP:void 0});break;default:{let a=CDe(i);t.push({name:e,kind:0,constant:i.presence==2?a:void 0,convert:i.fieldKind==`scalar`&&i.scalar==V.BYTES?GP:void 0}),r&&(n[e]=a);break}}}return{properties:t,prototype:r?n:void 0}}function xDe(e){let t=new Map;for(let n of e.fields){let e;n.fieldKind==`message`?e=WP(n):n.fieldKind==`scalar`&&n.scalar==V.BYTES&&(e=GP),t.set(n.localName,e??(e=>e))}return t}function WP(e){if(e.fieldKind==`message`&&!e.oneof&&RP(e.message))return e.message.fields[0].scalar==V.BYTES?GP:void 0;if(e.message.typeName==`google.protobuf.Struct`&&e.parent.typeName!==`google.protobuf.Value`)return;let t=e.message,n;return e=>!PP(e)||bP(e,t)?e:(n??=UP(t),n(e))}function GP(e){return Array.isArray(e)?new Uint8Array(e):e}function SDe(e){switch(e.file.edition){case 999:return!1;case 998:return!0;default:return e.fields.some(e=>e.presence!=2&&e.fieldKind!=`message`&&!e.oneof)}}function CDe(e){let t=e.getDefaultValue();return t===void 0?e.fieldKind==`scalar`?AP(e.scalar,e.longAsString):e.enum.values[0].number:e.fieldKind==`scalar`&&e.longAsString?t.toString():t}const wDe=[`FieldValueInvalidError`,`FieldListRangeError`,`ForeignFieldError`];var KP=class extends Error{constructor(e,t,n=`FieldValueInvalidError`){super(t),this.name=n,this.field=()=>e}};function TDe(e){return e instanceof Error&&wDe.includes(e.name)&&`field`in e&&typeof e.field==`function`}let qP;function EDe(e){qP=Object.assign(Object.assign({},e),{encodeUtf8Into:e.encodeUtf8Into??YP(e.encodeUtf8.bind(e))})}function JP(){if(!qP){let e=globalThis;if(!e.TextEncoder||!e.TextDecoder)throw Error(`encoding API missing: install TextEncoder and TextDecoder on globalThis`);let t=new e.TextEncoder,n=new e.TextDecoder(`utf-8`,{ignoreBOM:!0}),r,i={encodeUtf8(e){return t.encode(e)},decodeUtf8(t,i){return i?(r||=new e.TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}),r.decode(t)):n.decode(t)},checkUtf8(e){try{return!0}catch{return!1}}};t.encodeInto&&(i.encodeUtf8Into=t.encodeInto.bind(t));let a=String.prototype.isWellFormed;a&&(i.checkUtf8=e=>a.call(e)),EDe(i)}return qP}function YP(e){return(t,n)=>{let r=e(t);return n.set(r),{written:r.byteLength}}}var XP;(function(e){e[e.Varint=0]=`Varint`,e[e.Bit64=1]=`Bit64`,e[e.LengthDelimited=2]=`LengthDelimited`,e[e.StartGroup=3]=`StartGroup`,e[e.EndGroup=4]=`EndGroup`,e[e.Bit32=5]=`Bit32`})(XP||={});var ZP=class{constructor(e){this.stackPos=[],this.encodeUtf8Into=e?YP(e):JP().encodeUtf8Into,this.buffer=$P,this.viewCache=ODe,this.pos=0}ensureCapacity(e){let t=this.pos+e;if(t>this.buffer.length){let e=this.buffer.length||DDe;for(;e<t;)e*=2;let n=new Uint8Array(e);this.pos>0&&n.set(this.buffer),this.buffer=n}}view(){let e=this.buffer,t=this.viewCache;if(t.byteLength===e.byteLength)return t;let n=new DataView(e.buffer);return this.viewCache=n,n}finish(){let e=this.buffer.slice(0,this.pos);return this.pos=0,this.stackPos=[],e}fork(){return this.stackPos.push(this.pos),this.ensureCapacity(QP),this.buffer[this.pos++]=0,this}join(){let e=this.stackPos.pop();if(e===void 0)throw Error(`invalid state, fork stack empty`);let t=this.pos-e-QP,n=eF(t);return n>QP&&(this.ensureCapacity(n-QP),this.buffer.copyWithin(e+n,e+QP,this.pos)),this.pos=e,this.uint32(t),this.pos+=t,this}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.ensureCapacity(e.length),this.buffer.set(e,this.pos),this.pos+=e.length,this}uint32(e){if(rF(e),this.ensureCapacity(5),e<128)return this.buffer[this.pos++]=e,this;for(;e>127;)this.buffer[this.pos++]=e&127|128,e>>>=7;return this.buffer[this.pos++]=e,this}int32(e){if(nF(e),e>=0)return this.uint32(e);this.ensureCapacity(10);for(let t=0;t<9;t++)this.buffer[this.pos++]=e&127|128,e>>=7;return this.buffer[this.pos++]=1,this}bool(e){return this.ensureCapacity(1),this.buffer[this.pos++]=+!!e,this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){typeof e!=`string`&&(e=String(e));let t=e.length;if(t<=kDe){this.ensureCapacity(t+1);let n=this.buffer,r=this.pos;n[r++]=t;let i=0;for(;i<t;i++){let t=e.charCodeAt(i);if(t>127)break;n[r++]=t}if(i==t)return this.pos=r,this}this.ensureCapacity(t*3+5);let n=eF(t),r=this.buffer,i=this.pos,{written:a}=this.encodeUtf8Into(e,r.subarray(i+n)),o=eF(a);return o!=n&&r.copyWithin(i+o,i+n,i+n+a),this.uint32(a),this.pos+=a,this}float(e){return ADe(e),this.ensureCapacity(4),this.view().setFloat32(this.pos,e,!0),this.pos+=4,this}double(e){return this.ensureCapacity(8),this.view().setFloat64(this.pos,e,!0),this.pos+=8,this}fixed32(e){return rF(e),this.ensureCapacity(4),this.view().setUint32(this.pos,e,!0),this.pos+=4,this}sfixed32(e){return nF(e),this.ensureCapacity(4),this.view().setInt32(this.pos,e,!0),this.pos+=4,this}sint32(e){return nF(e),this.uint32((e<<1^e>>31)>>>0)}sfixed64(e){let t=DP.enc(e);this.ensureCapacity(8);let n=this.view();return n.setInt32(this.pos,t.lo,!0),n.setInt32(this.pos+4,t.hi,!0),this.pos+=8,this}fixed64(e){let t=DP.uEnc(e);this.ensureCapacity(8);let n=this.view();return n.setInt32(this.pos,t.lo,!0),n.setInt32(this.pos+4,t.hi,!0),this.pos+=8,this}int64(e){let t=DP.enc(e);return this.writeVarint64(t.lo,t.hi)}sint64(e){let t=DP.enc(e),n=t.hi>>31,r=t.lo<<1^n,i=(t.hi<<1|t.lo>>>31)^n;return this.writeVarint64(r,i)}uint64(e){let t=DP.uEnc(e);return this.writeVarint64(t.lo,t.hi)}writeVarint64(e,t){this.ensureCapacity(10);let n=this.buffer,r=this.pos;for(let i=0;i<28;i+=7){let a=e>>>i,o=!(!(a>>>7)&&t==0);if(n[r++]=(o?a|128:a)&255,!o)return this.pos=r,this}let i=e>>>28&15|(t&7)<<4,a=!!(t>>3);if(n[r++]=(a?i|128:i)&255,!a)return this.pos=r,this;for(let e=3;e<31;e+=7){let i=t>>>e,a=!!(i>>>7);if(n[r++]=(a?i|128:i)&255,!a)return this.pos=r,this}return n[r++]=t>>>31&1,this.pos=r,this}};const DDe=128,QP=1,$P=new Uint8Array,ODe=new DataView($P.buffer),kDe=32;function eF(e){return e<128?1:e<16384?2:e<2097152?3:e<268435456?4:5}var tF=class{constructor(e,t=JP().decodeUtf8){this.decodeUtf8=t,this.varint64Lo=0,this.varint64Hi=0,this.varint64=iDe,this.uint32=cDe,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength)}tag(){let e=this.pos,t=this.uint32(),n=this.pos-e;if(n>5||n==5&&this.buf[this.pos-1]>15)throw Error(`illegal tag: varint overflows uint32`);let r=t>>>3,i=t&7;if(r<=0||i>5)throw Error(`illegal tag: field no `+r+` wire type `+i);return[r,i]}skip(e,t,n=100){let r=this.pos;switch(e){case XP.Varint:for(;this.buf[this.pos++]&128;);break;case XP.Bit64:this.pos+=4;case XP.Bit32:this.pos+=4;break;case XP.LengthDelimited:let r=this.uint32();this.pos+=r;break;case XP.StartGroup:if(n<=0)throw Error(`maximum recursion depth reached`);for(;;){let[e,r]=this.tag();if(r===XP.EndGroup){if(t!==void 0&&e!==t)throw Error(`invalid end group tag`);break}this.skip(r,e,n-1)}break;default:throw Error(`cant skip wire type `+e)}return this.assertBounds(),this.buf.subarray(r,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError(`premature EOF`)}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return this.varint64(),DP.dec(this.varint64Lo,this.varint64Hi)}uint64(){return this.varint64(),DP.uDec(this.varint64Lo,this.varint64Hi)}sint64(){this.varint64();let e=this.varint64Lo,t=this.varint64Hi,n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,DP.dec(e,t)}bool(){let e=this.buf[this.pos];return e<128?(this.pos++,e!==0):(this.varint64(),this.varint64Lo!==0||this.varint64Hi!==0)}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return DP.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return DP.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(e){let t=this.uint32(),n=this.pos;this.pos+=t,this.assertBounds();let r=this.buf;if(t<=32){let i=Array(t);for(let a=0;a<t;a++){let t=r[n+a];if(t>127)return this.decodeUtf8(r.subarray(n,this.pos),e);i[a]=t}return String.fromCharCode.apply(String,i)}return this.decodeUtf8(r.subarray(n,this.pos),e)}};function nF(e){if(typeof e==`string`)e=Number(e);else if(typeof e!=`number`)throw Error(`invalid int32: `+typeof e);if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw Error(`invalid int32: `+e)}function rF(e){if(typeof e==`string`)e=Number(e);else if(typeof e!=`number`)throw Error(`invalid uint32: `+typeof e);if(!Number.isInteger(e)||e>4294967295||e<0)throw Error(`invalid uint32: `+e)}function ADe(e){if(typeof e==`string`){let t=e;if(e=Number(e),Number.isNaN(e)&&t!==`NaN`)throw Error(`invalid float32: `+t)}else if(typeof e!=`number`)throw Error(`invalid float32: `+typeof e);if(!Number.isFinite(Math.fround(e))&&Number.isFinite(e))throw Error(`invalid float32: `+e)}function iF(e,t){let n=e.fieldKind==`list`?FP(t,e):e.fieldKind==`map`?IP(t,e):oF(e,t);if(n===!0)return;let r;switch(e.fieldKind){case`list`:r=`expected ${dF(e)}, got ${lF(t)}`;break;case`map`:r=`expected ${fF(e)}, got ${lF(t)}`;break;default:r=cF(e,t,n)}return new KP(e,r)}function aF(e,t,n){let r=oF(e,n);if(r!==!0)return new KP(e,`list item #${t+1}: ${cF(e,n,r)}`)}function jDe(e,t,n){let r=sF(e.mapKey)(t);if(r!==!0)return new KP(e,`invalid map key: ${cF({scalar:e.mapKey},t,r)}`);let i=oF(e,n);if(i!==!0)return new KP(e,`map entry ${lF(t)}: ${cF(e,n,i)}`)}function oF(e,t){return e.scalar===void 0?e.enum===void 0?LP(t,e.message):e.enum.open?sF(V.INT32)(t):e.enum.values.some(e=>e.number===t):sF(e.scalar)(t)}function sF(e){switch(e){case V.DOUBLE:return e=>typeof e==`number`;case V.FLOAT:return e=>typeof e==`number`?!Number.isFinite(Math.fround(e))&&Number.isFinite(e)?`${e.toFixed()} out of range`:!0:!1;case V.INT32:case V.SFIXED32:case V.SINT32:return e=>typeof e!=`number`||!Number.isInteger(e)?!1:e>2147483647||e<-2147483648?`${e.toFixed()} out of range`:!0;case V.FIXED32:case V.UINT32:return e=>typeof e!=`number`||!Number.isInteger(e)?!1:e>4294967295||e<0?`${e.toFixed()} out of range`:!0;case V.BOOL:return e=>typeof e==`boolean`;case V.STRING:return e=>typeof e==`string`?JP().checkUtf8(e)||`invalid UTF8`:!1;case V.BYTES:return e=>e instanceof Uint8Array;case V.INT64:case V.SFIXED64:case V.SINT64:return e=>{if(typeof e==`bigint`||typeof e==`number`||typeof e==`string`&&e.length>0)try{return DP.parse(e),!0}catch{return`${e} out of range`}return!1};case V.FIXED64:case V.UINT64:return e=>{if(typeof e==`bigint`||typeof e==`number`||typeof e==`string`&&e.length>0)try{return DP.uParse(e),!0}catch{return`${e} out of range`}return!1}}}function cF(e,t,n){return n=typeof n==`string`?`: ${n}`:`, got ${lF(t)}`,e.scalar===void 0?e.enum===void 0?`expected ${uF(e.message)}`+n:`expected ${e.enum.toString()}`+n:`expected ${MDe(e.scalar)}`+n}function lF(e){switch(typeof e){case`object`:return e===null?`null`:e instanceof Uint8Array?`Uint8Array(${e.length})`:Array.isArray(e)?`Array(${e.length})`:FP(e)?dF(e.field()):IP(e)?fF(e.field()):LP(e)?uF(e.desc):bP(e)?`message ${e.$typeName}`:`object`;case`string`:return e.length>30?`string`:`"${e.split(`"`).join(`\\"`)}"`;case`boolean`:return String(e);case`number`:return String(e);case`bigint`:return String(e)+`n`;default:return typeof e}}function uF(e){return`ReflectMessage (${e.typeName})`}function dF(e){switch(e.listKind){case`message`:return`ReflectList (${e.message.toString()})`;case`enum`:return`ReflectList (${e.enum.toString()})`;case`scalar`:return`ReflectList (${V[e.scalar]})`}}function fF(e){switch(e.mapKind){case`message`:return`ReflectMap (${V[e.mapKey]}, ${e.message.toString()})`;case`enum`:return`ReflectMap (${V[e.mapKey]}, ${e.enum.toString()})`;case`scalar`:return`ReflectMap (${V[e.mapKey]}, ${V[e.scalar]})`}}function MDe(e){switch(e){case V.STRING:return`string`;case V.BOOL:return`boolean`;case V.INT64:case V.SINT64:case V.SFIXED64:return`bigint (int64)`;case V.UINT64:case V.FIXED64:return`bigint (uint64)`;case V.BYTES:return`Uint8Array`;case V.DOUBLE:return`number (float64)`;case V.FLOAT:return`number (float32)`;case V.FIXED32:case V.UINT32:return`number (uint32)`;case V.INT32:case V.SFIXED32:case V.SINT32:return`number (int32)`}}function pF(e){if(NDe(e))return{toMessage:e=>mF(e),toLocal:e=>hF(e)};if(e.fieldKind==`message`&&!e.oneof&&RP(e.message)){let t=e.message,n=t.fields[0].localName;return{toMessage:e=>{let r=VP(t);return e!==void 0&&(r[n]=e),r},toLocal:e=>e[n]}}let t=e.message;return{toMessage:e=>e===void 0?VP(t):e,toLocal:e=>e}}function NDe(e){return e.message.typeName==`google.protobuf.Struct`&&e.parent.typeName!=`google.protobuf.Value`}function mF(e){let t={$typeName:`google.protobuf.Struct`,fields:{}};if(PP(e))for(let n of Object.keys(e))NP(t.fields,n,_F(e[n]));return t}function hF(e){let t={};for(let n of Object.keys(e.fields))NP(t,n,gF(e.fields[n]));return t}function gF(e){switch(e.kind.case){case`structValue`:return hF(e.kind.value);case`listValue`:return e.kind.value.values.map(gF);case`nullValue`:case void 0:return null;default:return e.kind.value}}function _F(e){let t={$typeName:`google.protobuf.Value`,kind:{case:void 0}};switch(typeof e){case`number`:t.kind={case:`numberValue`,value:e};break;case`string`:t.kind={case:`stringValue`,value:e};break;case`boolean`:t.kind={case:`boolValue`,value:e};break;case`object`:if(e===null)t.kind={case:`nullValue`,value:0};else if(Array.isArray(e)){let n={$typeName:`google.protobuf.ListValue`,values:[]};if(Array.isArray(e))for(let t of e)n.values.push(_F(t));t.kind={case:`listValue`,value:n}}else t.kind={case:`structValue`,value:mF(e)}}return t}function PDe(e,t,n=!0){return new yF(e,t,n)}const vF=new WeakMap;var yF=class{get sortedFields(){let e=vF.get(this.desc);if(e)return e;let t=this.desc.fields.concat().sort((e,t)=>e.number-t.number);return vF.set(this.desc,t),t}constructor(e,t,n=!0){this.lists=new Map,this.maps=new Map,this.check=n,this.desc=e,this.message=this[jP]=t??VP(e),this.fields=e.fields,this.oneofs=e.oneofs,this.members=e.members}findNumber(e){return this._fieldsByNumber||=new Map(this.desc.fields.map(e=>[e.number,e])),this._fieldsByNumber.get(e)}oneofCase(e){return bF(this.message,e),dDe(this.message,e)}isSet(e){return bF(this.message,e),fDe(this.message,e)}clear(e){bF(this.message,e),gDe(this.message,e)}get(e){bF(this.message,e);let t=pDe(this.message,e);switch(e.fieldKind){case`list`:let n=this.lists.get(e);return(!n||n[jP]!==t)&&this.lists.set(e,n=new FDe(e,t,this.check)),n;case`map`:let r=this.maps.get(e);return(!r||r[jP]!==t)&&this.maps.set(e,r=new IDe(e,t,this.check)),r;case`message`:return SF(e,t,this.check);case`scalar`:return t===void 0?AP(e.scalar,!1):OF(e,t);case`enum`:return t??e.enum.values[0].number}}set(e,t){if(bF(this.message,e),this.check){let n=iF(e,t);if(n)throw n}let n;n=e.fieldKind==`message`?xF(e,t):IP(t)||FP(t)?t[jP]:kF(e,t),mDe(this.message,e,n)}getUnknown(){return this.message.$unknown}setUnknown(e){this.message.$unknown=e}};function bF(e,t){if(t.parent.typeName!==e.$typeName)throw new KP(t,`cannot use ${t.toString()} with message ${e.$typeName}`,`ForeignFieldError`)}var FDe=class{field(){return this._field}get size(){return this._arr.length}constructor(e,t,n){this._field=e,this._arr=this[jP]=t,this.check=n}get(e){let t=this._arr[e];return t===void 0?void 0:wF(this._field,t,this.check)}set(e,t){if(e<0||e>=this._arr.length)throw new KP(this._field,`list item #${e+1}: out of range`);if(this.check){let n=aF(this._field,e,t);if(n)throw n}this._arr[e]=CF(this._field,t)}add(e){if(this.check){let t=aF(this._field,this._arr.length,e);if(t)throw t}this._arr.push(CF(this._field,e))}clear(){this._arr.splice(0,this._arr.length)}[Symbol.iterator](){return this.values()}keys(){return this._arr.keys()}*values(){for(let e of this._arr)yield wF(this._field,e,this.check)}*entries(){for(let e=0;e<this._arr.length;e++)yield[e,wF(this._field,this._arr[e],this.check)]}},IDe=class{constructor(e,t,n=!0){this.obj=this[jP]=t??{},this.check=n,this._field=e}field(){return this._field}set(e,t){if(this.check){let n=jDe(this._field,e,t);if(n)throw n}return NP(this.obj,EF(e),LDe(this._field,t)),this}delete(e){let t=EF(e),n=Object.prototype.hasOwnProperty.call(this.obj,t);return n&&delete this.obj[t],n}clear(){for(let e of Object.keys(this.obj))delete this.obj[e]}get(e){let t=hDe(this.obj,EF(e));return t!==void 0&&(t=TF(this._field,t,this.check)),t}has(e){return Object.prototype.hasOwnProperty.call(this.obj,EF(e))}*keys(){for(let e of Object.keys(this.obj))yield DF(e,this._field.mapKey)}*entries(){for(let e of Object.entries(this.obj))yield[DF(e[0],this._field.mapKey),TF(this._field,e[1],this.check)]}[Symbol.iterator](){return this.entries()}get size(){return Object.keys(this.obj).length}*values(){for(let e of Object.values(this.obj))yield TF(this._field,e,this.check)}forEach(e,t){for(let n of this.entries())e.call(t,n[1],n[0],this)}};function xF(e,t){return LP(t)?_De(t.message)&&!e.oneof&&e.fieldKind==`message`?t.message.value:t.desc.typeName==`google.protobuf.Struct`&&e.parent.typeName!=`google.protobuf.Value`?hF(t.message):t.message:t}function SF(e,t,n){return t!==void 0&&(RP(e.message)&&!e.oneof&&e.fieldKind==`message`?t={$typeName:e.message.typeName,value:OF(e.message.fields[0],t)}:e.message.typeName==`google.protobuf.Struct`&&e.parent.typeName!=`google.protobuf.Value`&&PP(t)&&(t=mF(t))),new yF(e.message,t,n)}function CF(e,t){return e.listKind==`message`?xF(e,t):kF(e,t)}function wF(e,t,n){return e.listKind==`message`?SF(e,t,n):OF(e,t)}function LDe(e,t){return e.mapKind==`message`?xF(e,t):kF(e,t)}function TF(e,t,n){return e.mapKind==`message`?SF(e,t,n):t}function EF(e){return typeof e==`string`||typeof e==`number`?e:String(e)}function DF(e,t){switch(t){case V.STRING:return e;case V.INT32:case V.FIXED32:case V.UINT32:case V.SFIXED32:case V.SINT32:{let t=Number.parseInt(e);if(Number.isFinite(t))return t;break}case V.BOOL:switch(e){case`true`:return!0;case`false`:return!1}break;case V.UINT64:case V.FIXED64:try{return DP.uParse(e)}catch{}break;default:try{return DP.parse(e)}catch{}}return e}function OF(e,t){switch(e.scalar){case V.INT64:case V.SFIXED64:case V.SINT64:`longAsString`in e&&e.longAsString&&typeof t==`string`&&(t=DP.parse(t));break;case V.FIXED64:case V.UINT64:`longAsString`in e&&e.longAsString&&typeof t==`string`&&(t=DP.uParse(t))}return t}function kF(e,t){switch(e.scalar){case V.INT64:case V.SFIXED64:case V.SINT64:`longAsString`in e&&e.longAsString?t=String(t):(typeof t==`string`||typeof t==`number`)&&(t=DP.parse(t));break;case V.FIXED64:case V.UINT64:`longAsString`in e&&e.longAsString?t=String(t):(typeof t==`string`||typeof t==`number`)&&(t=DP.uParse(t))}return t}const AF=Uint8Array.prototype.setFromBase64;function jF(e){let t=e.length,n=t-(t+3>>2);!(t&3)&&e[t-1]==`=`&&(n-=e[t-2]==`=`?2:1);let r=new Uint8Array(n),i=-1;if(AF)try{let n=AF.call(r,e);n.read==t&&(i=n.written)}catch{}return i<0&&(i=RDe(r,e)),i==n?r:r.subarray(0,i)}function RDe(e,t){let n=BDe(),r=0,i=0,a,o=0;for(let s=0;s<t.length;s++){if(a=n[t.charCodeAt(s)],a===void 0)switch(t[s]){case`=`:i=0;case`
453
+ `:case`\r`:case` `:case` `:continue;default:throw Error(`invalid base64 string`)}switch(i){case 0:o=a,i=1;break;case 1:e[r++]=o<<2|(a&48)>>4,o=a,i=2;break;case 2:e[r++]=(o&15)<<4|(a&60)>>2,o=a,i=3;break;case 3:e[r++]=(o&3)<<6|a,i=0}}if(i==1)throw Error(`invalid base64 string`);return r}const MF=Uint8Array.prototype.toBase64,zDe={std:{alphabet:`base64`,omitPadding:!1},std_raw:{alphabet:`base64`,omitPadding:!0},url:{alphabet:`base64url`,omitPadding:!0}};function NF(e,t=`std`){if(MF)return MF.call(e,zDe[t]);let n=LF(t),r=t==`std`,i=``,a=0,o,s=0;for(let t=0;t<e.length;t++)switch(o=e[t],a){case 0:i+=n[o>>2],s=(o&3)<<4,a=1;break;case 1:i+=n[s|o>>4],s=(o&15)<<2,a=2;break;case 2:i+=n[s|o>>6],i+=n[o&63],a=0}return a&&(i+=n[s],r&&(i+=`=`,a==1&&(i+=`=`))),i}let PF,FF,IF;function LF(e){return PF||(PF=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),FF=PF.slice(0,-2).concat(`-`,`_`)),e==`url`?FF:PF}function BDe(){if(!IF){IF=[];let e=LF(`std`);for(let t=0;t<e.length;t++)IF[e[t].charCodeAt(0)]=t;IF[45]=e.indexOf(`+`),IF[95]=e.indexOf(`/`)}return IF}function RF(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case`_`:t=!0;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join(``)}function zF(e){return e.replace(/[A-Z]/g,e=>`_`+e.toLowerCase())}const VDe=new Set([`constructor`,`toString`,`toJSON`,`valueOf`]);function BF(e){return VDe.has(e)?e+`$`:e}function VF(e){for(let t of e.field)MP(t,`jsonName`)||(t.jsonName=RF(t.name));e.nestedType.forEach(VF)}function HDe(e,t){let n=e.values.find(e=>e.name===t);if(!n)throw Error(`cannot parse ${e} default value: ${t}`);return n.number}function UDe(e,t){switch(e){case V.STRING:return t;case V.BYTES:{let n=WDe(t);if(n===!1)throw Error(`cannot parse ${V[e]} default value: ${t}`);return n}case V.INT64:case V.SFIXED64:case V.SINT64:return DP.parse(t);case V.UINT64:case V.FIXED64:return DP.uParse(t);case V.DOUBLE:case V.FLOAT:switch(t){case`inf`:return 1/0;case`-inf`:return-1/0;case`nan`:return NaN;default:return parseFloat(t)}case V.BOOL:return t===`true`;case V.INT32:case V.UINT32:case V.SINT32:case V.FIXED32:case V.SFIXED32:return parseInt(t,10)}}function WDe(e){let t=[],n={tail:e,c:``,next(){return this.tail.length!=0&&(this.c=this.tail[0],this.tail=this.tail.substring(1),!0)},take(e){if(this.tail.length>=e){let t=this.tail.substring(0,e);return this.tail=this.tail.substring(e),t}return!1}};for(;n.next();)switch(n.c){case`\\`:if(n.next())switch(n.c){case`\\`:t.push(n.c.charCodeAt(0));break;case`b`:t.push(8);break;case`f`:t.push(12);break;case`n`:t.push(10);break;case`r`:t.push(13);break;case`t`:t.push(9);break;case`v`:t.push(11);break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:{let e=n.c,r=n.take(2);if(r===!1)return!1;let i=parseInt(e+r,8);if(Number.isNaN(i))return!1;t.push(i);break}case`x`:{let e=n.c,r=n.take(2);if(r===!1)return!1;let i=parseInt(e+r,16);if(Number.isNaN(i))return!1;t.push(i);break}case`u`:{let e=n.c,r=n.take(4);if(r===!1)return!1;let i=parseInt(e+r,16);if(Number.isNaN(i))return!1;let a=new Uint8Array(4);new DataView(a.buffer).setInt32(0,i,!0),t.push(a[0],a[1],a[2],a[3]);break}case`U`:{let e=n.c,r=n.take(8);if(r===!1)return!1;let i=DP.uEnc(e+r),a=new Uint8Array(8),o=new DataView(a.buffer);o.setInt32(0,i.lo,!0),o.setInt32(4,i.hi,!0),t.push(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);break}}break;default:t.push(n.c.charCodeAt(0))}return new Uint8Array(t)}function*HF(e){switch(e.kind){case`file`:for(let t of e.messages)yield t,yield*HF(t);yield*e.enums,yield*e.services,yield*e.extensions;break;case`message`:for(let t of e.nestedMessages)yield t,yield*HF(t);yield*e.nestedEnums,yield*e.nestedExtensions}}function UF(e,t){return GDe([e,t])}function GDe(e,t){let n=KDe();if(!e.length)return n;if(`$typeName`in e[0]&&e[0].$typeName==`google.protobuf.FileDescriptorSet`){for(let r of e[0].file)t?.(r),GF(r,n);return n}if(`$typeName`in e[0]){let r=e[0],i=e[1],a=new Set;function o(e){let t=[];for(let r of e.dependency){if(n.getFile(r)!=null||a.has(r))continue;let o=i(r);if(!o)throw Error(`Unable to resolve ${r}, imported by ${e.name}`);`kind`in o?n.addFile(o,!1,!0):(a.add(o.name),t.push(o))}return t.concat(...t.map(o))}for(let e of[r,...o(r)].reverse())t?.(e),GF(e,n)}else for(let t of e)for(let e of t.files)n.addFile(e);return n}function KDe(){let e=new Map,t=new Map,n=new Map;return{kind:`registry`,types:e,extendees:t,[Symbol.iterator](){return e.values()},get files(){return n.values()},addFile(e,t,r){if(n.set(e.proto.name,e),!t)for(let t of HF(e))this.add(t);if(r)for(let n of e.dependencies)this.addFile(n,t,r)},add(n){if(n.kind==`extension`){let e=t.get(n.extendee.typeName);e||t.set(n.extendee.typeName,e=new Map),e.set(n.number,n)}e.set(n.typeName,n)},get(t){return e.get(t)},getFile(e){return n.get(e)},getMessage(t){let n=e.get(t);return n?.kind==`message`?n:void 0},getEnum(t){let n=e.get(t);return n?.kind==`enum`?n:void 0},getExtension(t){let n=e.get(t);return n?.kind==`extension`?n:void 0},getExtensionFor(e,n){return t.get(e.typeName)?.get(n)},getService(t){let n=e.get(t);return n?.kind==`service`?n:void 0}}}const WF={998:{fieldPresence:1,enumType:2,repeatedFieldEncoding:2,utf8Validation:3,messageEncoding:1,jsonFormat:2,enforceNamingStyle:2,defaultSymbolVisibility:1,enforceProtoLimits:1},999:{fieldPresence:2,enumType:1,repeatedFieldEncoding:1,utf8Validation:2,messageEncoding:1,jsonFormat:1,enforceNamingStyle:2,defaultSymbolVisibility:1,enforceProtoLimits:1},1e3:{fieldPresence:1,enumType:1,repeatedFieldEncoding:1,utf8Validation:2,messageEncoding:1,jsonFormat:1,enforceNamingStyle:2,defaultSymbolVisibility:1,enforceProtoLimits:1},1001:{fieldPresence:1,enumType:1,repeatedFieldEncoding:1,utf8Validation:2,messageEncoding:1,jsonFormat:1,enforceNamingStyle:1,defaultSymbolVisibility:2,enforceProtoLimits:1},1002:{fieldPresence:1,enumType:1,repeatedFieldEncoding:1,utf8Validation:2,messageEncoding:1,jsonFormat:1,enforceNamingStyle:3,defaultSymbolVisibility:4,enforceProtoLimits:2}};function GF(e,t){let n={kind:`file`,proto:e,deprecated:e.options?.deprecated??!1,edition:XDe(e),name:e.name.replace(/\.proto$/,``),dependencies:ZDe(e,t),enums:[],messages:[],extensions:[],services:[],toString(){return`file ${e.name}`}},r=new Map,i={get(e){return r.get(e)},add(e){tI(e.proto.options?.mapEntry===!0),r.set(e.typeName,e)}};for(let r of e.enumType)JF(r,n,void 0,t);for(let r of e.messageType)YF(r,n,void 0,t,i);for(let r of e.service)qDe(r,n,t);KF(n,t);for(let e of r.values())qF(e,t,i);for(let e of n.messages)qF(e,t,i),KF(e,t);t.addFile(n,!0)}function KF(e,t){switch(e.kind){case`file`:for(let n of e.proto.extension){let r=XF(n,e,t);e.extensions.push(r),t.add(r)}break;case`message`:for(let n of e.proto.extension){let r=XF(n,e,t);e.nestedExtensions.push(r),t.add(r)}for(let n of e.nestedMessages)KF(n,t)}}function qF(e,t,n){let r=e.proto.oneofDecl.map(t=>YDe(t,e)),i=new Set;for(let a of e.proto.field){let o=tOe(a,r),s=XF(a,e,t,o,n);e.fields.push(s),e.field[s.localName]=s,o===void 0?e.members.push(s):(o.fields.push(s),i.has(o)||(i.add(o),e.members.push(o)))}for(let t of r.filter(e=>i.has(e)))e.oneofs.push(t);for(let r of e.nestedMessages)qF(r,t,n)}function JF(e,t,n,r){var i,a;let o=QDe(e.name,e.value),s={kind:`enum`,proto:e,deprecated:e.options?.deprecated??!1,file:t,parent:n,open:!0,name:e.name,typeName:ZF(e,n,t),value:{},values:[],sharedPrefix:o,toString(){return`enum ${this.typeName}`}};s.open=aOe(s),r.add(s);for(let t of e.value){let e=t.name,n={kind:`enum_value`,proto:t,deprecated:t.options?.deprecated??!1,parent:s,name:e,localName:BF(o==null?e:e.substring(o.length)),number:t.number,jsonName:$De(t)??e,toString(){return`enum value ${s.typeName}.${e}`}};s.values.push(n),(i=s.value)[a=t.number]??(i[a]=n)}(n?.nestedEnums??t.enums).push(s)}function YF(e,t,n,r,i){let a={kind:`message`,proto:e,deprecated:e.options?.deprecated??!1,file:t,parent:n,name:e.name,typeName:ZF(e,n,t),fields:[],field:{},oneofs:[],members:[],nestedEnums:[],nestedMessages:[],nestedExtensions:[],toString(){return`message ${this.typeName}`}};e.options?.mapEntry===!0?i.add(a):((n?.nestedMessages??t.messages).push(a),r.add(a));for(let n of e.enumType)JF(n,t,a,r);for(let n of e.nestedType)YF(n,t,a,r,i)}function qDe(e,t,n){let r={kind:`service`,proto:e,deprecated:e.options?.deprecated??!1,file:t,name:e.name,typeName:ZF(e,void 0,t),methods:[],method:{},toString(){return`service ${this.typeName}`}};t.services.push(r),n.add(r);for(let t of e.method){let e=JDe(t,r,n);r.methods.push(e),r.method[e.localName]=e}}function JDe(e,t,n){let r;r=e.clientStreaming&&e.serverStreaming?`bidi_streaming`:e.clientStreaming?`client_streaming`:e.serverStreaming?`server_streaming`:`unary`;let i=n.getMessage(QF(e.inputType)),a=n.getMessage(QF(e.outputType));tI(i,`invalid MethodDescriptorProto: input_type ${e.inputType} not found`),tI(a,`invalid MethodDescriptorProto: output_type ${e.inputType} not found`);let o=e.name;return{kind:`rpc`,proto:e,deprecated:e.options?.deprecated??!1,parent:t,name:o,localName:BF(o.length?BF(o[0].toLowerCase()+o.substring(1)):o),methodKind:r,input:i,output:a,idempotency:e.options?.idempotencyLevel??0,toString(){return`rpc ${t.typeName}.${o}`}}}function YDe(e,t){return{kind:`oneof`,proto:e,deprecated:!1,parent:t,fields:[],name:e.name,localName:BF(RF(e.name)),toString(){return`oneof ${t.typeName}.${this.name}`}}}function XF(e,t,n,r,i){let a=i===void 0,o={kind:`field`,proto:e,deprecated:e.options?.deprecated??!1,name:e.name,number:e.number,scalar:void 0,message:void 0,enum:void 0,presence:nOe(e,r,a,t),utf8Validation:oOe(e,t),listKind:void 0,mapKind:void 0,mapKey:void 0,delimitedEncoding:void 0,packed:void 0,longAsString:!1,getDefaultValue:void 0},s;if(a){let r=t.kind==`file`?t:t.file,i=t.kind==`file`?void 0:t,a=ZF(e,i,r);o.kind=`extension`,o.file=r,o.parent=i,o.oneof=void 0,o.typeName=a,o.jsonName=`[${a}]`,s=()=>`extension ${a}`;let c=n.getMessage(QF(e.extendee));tI(c,`invalid FieldDescriptorProto: extendee ${e.extendee} not found`),o.extendee=c}else{let n=t;tI(n.kind==`message`),o.parent=n,o.oneof=r,o.localName=r?RF(e.name):BF(RF(e.name)),o.jsonName=e.jsonName,s=()=>`field ${n.typeName}.${e.name}`}Object.defineProperty(o,"toString",{value:s,writable:!0,enumerable:!0,configurable:!0});let c=e.label,l=e.type,u=e.options?.jstype;if(c===3){let r=l==11?i?.get(QF(e.typeName)):void 0;if(r){o.fieldKind=`map`;let{key:e,value:t}=iOe(r);return o.mapKey=e.scalar,o.mapKind=t.fieldKind,o.message=t.message,o.delimitedEncoding=!1,o.enum=t.enum,o.scalar=t.scalar,o}switch(o.fieldKind=`list`,l){case 11:case 10:o.listKind=`message`,o.message=n.getMessage(QF(e.typeName)),tI(o.message),o.delimitedEncoding=$F(e,t);break;case 14:o.listKind=`enum`,o.enum=n.getEnum(QF(e.typeName)),tI(o.enum);break;default:o.listKind=`scalar`,o.scalar=l,o.longAsString=u==1}return o.packed=rOe(e,t),o}switch(l){case 11:case 10:o.fieldKind=`message`,o.message=n.getMessage(QF(e.typeName)),tI(o.message,`invalid FieldDescriptorProto: type_name ${e.typeName} not found`),o.delimitedEncoding=$F(e,t),o.getDefaultValue=()=>void 0;break;case 14:{let t=n.getEnum(QF(e.typeName));tI(t!==void 0,`invalid FieldDescriptorProto: type_name ${e.typeName} not found`),o.fieldKind=`enum`,o.enum=n.getEnum(QF(e.typeName)),o.getDefaultValue=()=>MP(e,`defaultValue`)?HDe(t,e.defaultValue):void 0;break}default:o.fieldKind=`scalar`,o.scalar=l,o.longAsString=u==1,o.getDefaultValue=()=>MP(e,`defaultValue`)?UDe(l,e.defaultValue):void 0}return o}function XDe(e){switch(e.syntax){case``:case`proto2`:return 998;case`proto3`:return 999;case`editions`:if(e.edition===9999)return 1002;if(e.edition in WF)return e.edition;throw Error(`${e.name}: unsupported edition`);default:throw Error(`${e.name}: unsupported syntax "${e.syntax}"`)}}function ZDe(e,t){return e.dependency.map(n=>{let r=t.getFile(n);if(!r)throw Error(`Cannot find ${n}, imported by ${e.name}`);return r})}function QDe(e,t){let n=eOe(e)+`_`;for(let e of t){if(!e.name.toLowerCase().startsWith(n))return;let t=e.name.substring(n.length);if(t.length==0||/^\d/.test(t))return}return n}function $De(e){let t;for(let n of e.options?.$unknown??[]){if(n.no!==998||n.wireType!==XP.LengthDelimited)continue;let e=new tF(new tF(n.data).bytes());for(;e.pos<e.len;){let[n,r]=e.tag();n===1&&r===XP.LengthDelimited?t=e.string():e.skip(r,n)}}return t}function eOe(e){return(e.substring(0,1)+e.substring(1).replace(/[A-Z]/g,e=>`_`+e)).toLowerCase()}function ZF(e,t,n){let r;return r=t?`${t.typeName}.${e.name}`:n.proto.package.length>0?`${n.proto.package}.${e.name}`:`${e.name}`,r}function QF(e){return e.startsWith(`.`)?e.substring(1):e}function tOe(e,t){if(!MP(e,`oneofIndex`)||e.proto3Optional)return;let n=t[e.oneofIndex];return tI(n,`invalid FieldDescriptorProto: oneof #${e.oneofIndex} for field #${e.number} not found`),n}function nOe(e,t,n,r){if(e.label==2)return 3;if(e.label==3)return 2;if(t||e.proto3Optional||n)return 1;let i=eI(`fieldPresence`,{proto:e,parent:r});return i==2&&(e.type==11||e.type==10)?1:i}function rOe(e,t){if(e.label!=3)return!1;switch(e.type){case 9:case 12:case 10:case 11:return!1}let n=e.options;return n&&MP(n,`packed`)?n.packed:eI(`repeatedFieldEncoding`,{proto:e,parent:t})==1}function iOe(e){let t=e.fields.find(e=>e.number===1),n=e.fields.find(e=>e.number===2);return tI(t&&t.fieldKind==`scalar`&&t.scalar!=V.BYTES&&t.scalar!=V.FLOAT&&t.scalar!=V.DOUBLE&&n&&n.fieldKind!=`list`&&n.fieldKind!=`map`),{key:t,value:n}}function aOe(e){return eI(`enumType`,{proto:e.proto,parent:e.parent??e.file})==1}function $F(e,t){return e.type==10||eI(`messageEncoding`,{proto:e,parent:t})==2}function oOe(e,t){return eI(`utf8Validation`,{proto:e,parent:t})==2}function eI(e,t){let n=t.proto.options?.features;if(n){let t=n[e];if(t!=0)return t}if(`kind`in t){if(t.kind==`message`)return eI(e,t.parent??t.file);let n=WF[t.edition];if(!n)throw Error(`feature default for edition ${t.edition} not found`);return n[e]}return eI(e,t.parent)}function tI(e,t){if(!e)throw Error(t)}function sOe(e){let t=cOe(e);return t.messageType.forEach(VF),UF(t,()=>void 0).getFile(t.name)}function cOe(e){return Object.assign(Object.create({syntax:``,edition:0}),Object.assign(Object.assign({$typeName:`google.protobuf.FileDescriptorProto`,dependency:[],publicDependency:[],weakDependency:[],optionDependency:[],service:[],extension:[]},e),{messageType:e.messageType.map(nI),enumType:e.enumType.map(rI)}))}function nI(e){return Object.assign(Object.create({visibility:0}),{$typeName:`google.protobuf.DescriptorProto`,name:e.name,field:e.field?.map(lOe)??[],extension:[],nestedType:e.nestedType?.map(nI)??[],enumType:e.enumType?.map(rI)??[],extensionRange:e.extensionRange?.map(e=>Object.assign({$typeName:`google.protobuf.DescriptorProto.ExtensionRange`},e))??[],oneofDecl:[],reservedRange:[],reservedName:[]})}function lOe(e){return Object.assign(Object.create({label:1,typeName:``,extendee:``,defaultValue:``,oneofIndex:0,jsonName:``,proto3Optional:!1}),Object.assign(Object.assign({$typeName:`google.protobuf.FieldDescriptorProto`},e),{options:e.options?uOe(e.options):void 0}))}function uOe(e){return Object.assign(Object.create({ctype:0,packed:!1,jstype:0,lazy:!1,unverifiedLazy:!1,deprecated:!1,weak:!1,debugRedact:!1,retention:0}),Object.assign(Object.assign({$typeName:`google.protobuf.FieldOptions`},e),{targets:e.targets??[],editionDefaults:e.editionDefaults?.map(e=>Object.assign({$typeName:`google.protobuf.FieldOptions.EditionDefault`},e))??[],uninterpretedOption:[]}))}function rI(e){return Object.assign(Object.create({visibility:0}),{$typeName:`google.protobuf.EnumDescriptorProto`,name:e.name,reservedName:[],reservedRange:[],value:e.value.map(e=>Object.assign({$typeName:`google.protobuf.EnumValueDescriptorProto`},e))})}function iI(e,t,...n){return n.reduce((e,t)=>e.nestedMessages[t],e.messages[t])}const dOe=iI(sOe({name:`google/protobuf/descriptor.proto`,package:`google.protobuf`,messageType:[{name:`FileDescriptorSet`,field:[{name:`file`,number:1,type:11,label:3,typeName:`.google.protobuf.FileDescriptorProto`}],extensionRange:[{start:536e6,end:536000001}]},{name:`FileDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`package`,number:2,type:9,label:1},{name:`dependency`,number:3,type:9,label:3},{name:`public_dependency`,number:10,type:5,label:3},{name:`weak_dependency`,number:11,type:5,label:3},{name:`option_dependency`,number:15,type:9,label:3},{name:`message_type`,number:4,type:11,label:3,typeName:`.google.protobuf.DescriptorProto`},{name:`enum_type`,number:5,type:11,label:3,typeName:`.google.protobuf.EnumDescriptorProto`},{name:`service`,number:6,type:11,label:3,typeName:`.google.protobuf.ServiceDescriptorProto`},{name:`extension`,number:7,type:11,label:3,typeName:`.google.protobuf.FieldDescriptorProto`},{name:`options`,number:8,type:11,label:1,typeName:`.google.protobuf.FileOptions`},{name:`source_code_info`,number:9,type:11,label:1,typeName:`.google.protobuf.SourceCodeInfo`},{name:`syntax`,number:12,type:9,label:1},{name:`edition`,number:14,type:14,label:1,typeName:`.google.protobuf.Edition`}]},{name:`DescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`field`,number:2,type:11,label:3,typeName:`.google.protobuf.FieldDescriptorProto`},{name:`extension`,number:6,type:11,label:3,typeName:`.google.protobuf.FieldDescriptorProto`},{name:`nested_type`,number:3,type:11,label:3,typeName:`.google.protobuf.DescriptorProto`},{name:`enum_type`,number:4,type:11,label:3,typeName:`.google.protobuf.EnumDescriptorProto`},{name:`extension_range`,number:5,type:11,label:3,typeName:`.google.protobuf.DescriptorProto.ExtensionRange`},{name:`oneof_decl`,number:8,type:11,label:3,typeName:`.google.protobuf.OneofDescriptorProto`},{name:`options`,number:7,type:11,label:1,typeName:`.google.protobuf.MessageOptions`},{name:`reserved_range`,number:9,type:11,label:3,typeName:`.google.protobuf.DescriptorProto.ReservedRange`},{name:`reserved_name`,number:10,type:9,label:3},{name:`visibility`,number:11,type:14,label:1,typeName:`.google.protobuf.SymbolVisibility`}],nestedType:[{name:`ExtensionRange`,field:[{name:`start`,number:1,type:5,label:1},{name:`end`,number:2,type:5,label:1},{name:`options`,number:3,type:11,label:1,typeName:`.google.protobuf.ExtensionRangeOptions`}]},{name:`ReservedRange`,field:[{name:`start`,number:1,type:5,label:1},{name:`end`,number:2,type:5,label:1}]}]},{name:`ExtensionRangeOptions`,field:[{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`},{name:`declaration`,number:2,type:11,label:3,typeName:`.google.protobuf.ExtensionRangeOptions.Declaration`,options:{retention:2}},{name:`features`,number:50,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`verification`,number:3,type:14,label:1,typeName:`.google.protobuf.ExtensionRangeOptions.VerificationState`,defaultValue:`UNVERIFIED`,options:{retention:2}}],nestedType:[{name:`Declaration`,field:[{name:`number`,number:1,type:5,label:1},{name:`full_name`,number:2,type:9,label:1},{name:`type`,number:3,type:9,label:1},{name:`reserved`,number:5,type:8,label:1},{name:`repeated`,number:6,type:8,label:1}]}],enumType:[{name:`VerificationState`,value:[{name:`DECLARATION`,number:0},{name:`UNVERIFIED`,number:1}]}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`FieldDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`number`,number:3,type:5,label:1},{name:`label`,number:4,type:14,label:1,typeName:`.google.protobuf.FieldDescriptorProto.Label`},{name:`type`,number:5,type:14,label:1,typeName:`.google.protobuf.FieldDescriptorProto.Type`},{name:`type_name`,number:6,type:9,label:1},{name:`extendee`,number:2,type:9,label:1},{name:`default_value`,number:7,type:9,label:1},{name:`oneof_index`,number:9,type:5,label:1},{name:`json_name`,number:10,type:9,label:1},{name:`options`,number:8,type:11,label:1,typeName:`.google.protobuf.FieldOptions`},{name:`proto3_optional`,number:17,type:8,label:1}],enumType:[{name:`Type`,value:[{name:`TYPE_DOUBLE`,number:1},{name:`TYPE_FLOAT`,number:2},{name:`TYPE_INT64`,number:3},{name:`TYPE_UINT64`,number:4},{name:`TYPE_INT32`,number:5},{name:`TYPE_FIXED64`,number:6},{name:`TYPE_FIXED32`,number:7},{name:`TYPE_BOOL`,number:8},{name:`TYPE_STRING`,number:9},{name:`TYPE_GROUP`,number:10},{name:`TYPE_MESSAGE`,number:11},{name:`TYPE_BYTES`,number:12},{name:`TYPE_UINT32`,number:13},{name:`TYPE_ENUM`,number:14},{name:`TYPE_SFIXED32`,number:15},{name:`TYPE_SFIXED64`,number:16},{name:`TYPE_SINT32`,number:17},{name:`TYPE_SINT64`,number:18}]},{name:`Label`,value:[{name:`LABEL_OPTIONAL`,number:1},{name:`LABEL_REPEATED`,number:3},{name:`LABEL_REQUIRED`,number:2}]}]},{name:`OneofDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`options`,number:2,type:11,label:1,typeName:`.google.protobuf.OneofOptions`}]},{name:`EnumDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`value`,number:2,type:11,label:3,typeName:`.google.protobuf.EnumValueDescriptorProto`},{name:`options`,number:3,type:11,label:1,typeName:`.google.protobuf.EnumOptions`},{name:`reserved_range`,number:4,type:11,label:3,typeName:`.google.protobuf.EnumDescriptorProto.EnumReservedRange`},{name:`reserved_name`,number:5,type:9,label:3},{name:`visibility`,number:6,type:14,label:1,typeName:`.google.protobuf.SymbolVisibility`}],nestedType:[{name:`EnumReservedRange`,field:[{name:`start`,number:1,type:5,label:1},{name:`end`,number:2,type:5,label:1}]}]},{name:`EnumValueDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`number`,number:2,type:5,label:1},{name:`options`,number:3,type:11,label:1,typeName:`.google.protobuf.EnumValueOptions`}]},{name:`ServiceDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`method`,number:2,type:11,label:3,typeName:`.google.protobuf.MethodDescriptorProto`},{name:`options`,number:3,type:11,label:1,typeName:`.google.protobuf.ServiceOptions`}]},{name:`MethodDescriptorProto`,field:[{name:`name`,number:1,type:9,label:1},{name:`input_type`,number:2,type:9,label:1},{name:`output_type`,number:3,type:9,label:1},{name:`options`,number:4,type:11,label:1,typeName:`.google.protobuf.MethodOptions`},{name:`client_streaming`,number:5,type:8,label:1,defaultValue:`false`},{name:`server_streaming`,number:6,type:8,label:1,defaultValue:`false`}]},{name:`FileOptions`,field:[{name:`java_package`,number:1,type:9,label:1},{name:`java_outer_classname`,number:8,type:9,label:1},{name:`java_multiple_files`,number:10,type:8,label:1,defaultValue:`false`,options:{}},{name:`java_generate_equals_and_hash`,number:20,type:8,label:1,options:{deprecated:!0}},{name:`java_string_check_utf8`,number:27,type:8,label:1,defaultValue:`false`},{name:`optimize_for`,number:9,type:14,label:1,typeName:`.google.protobuf.FileOptions.OptimizeMode`,defaultValue:`SPEED`},{name:`go_package`,number:11,type:9,label:1},{name:`cc_generic_services`,number:16,type:8,label:1,defaultValue:`false`},{name:`java_generic_services`,number:17,type:8,label:1,defaultValue:`false`},{name:`py_generic_services`,number:18,type:8,label:1,defaultValue:`false`},{name:`deprecated`,number:23,type:8,label:1,defaultValue:`false`},{name:`cc_enable_arenas`,number:31,type:8,label:1,defaultValue:`true`,options:{}},{name:`objc_class_prefix`,number:36,type:9,label:1},{name:`csharp_namespace`,number:37,type:9,label:1},{name:`swift_prefix`,number:39,type:9,label:1},{name:`php_class_prefix`,number:40,type:9,label:1},{name:`php_namespace`,number:41,type:9,label:1},{name:`php_metadata_namespace`,number:44,type:9,label:1},{name:`ruby_package`,number:45,type:9,label:1},{name:`features`,number:50,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],enumType:[{name:`OptimizeMode`,value:[{name:`SPEED`,number:1},{name:`CODE_SIZE`,number:2},{name:`LITE_RUNTIME`,number:3}]}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`MessageOptions`,field:[{name:`message_set_wire_format`,number:1,type:8,label:1,defaultValue:`false`},{name:`no_standard_descriptor_accessor`,number:2,type:8,label:1,defaultValue:`false`},{name:`deprecated`,number:3,type:8,label:1,defaultValue:`false`},{name:`map_entry`,number:7,type:8,label:1},{name:`deprecated_legacy_json_field_conflicts`,number:11,type:8,label:1,options:{deprecated:!0}},{name:`features`,number:12,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`FieldOptions`,field:[{name:`ctype`,number:1,type:14,label:1,typeName:`.google.protobuf.FieldOptions.CType`,defaultValue:`STRING`},{name:`packed`,number:2,type:8,label:1},{name:`jstype`,number:6,type:14,label:1,typeName:`.google.protobuf.FieldOptions.JSType`,defaultValue:`JS_NORMAL`},{name:`lazy`,number:5,type:8,label:1,defaultValue:`false`},{name:`unverified_lazy`,number:15,type:8,label:1,defaultValue:`false`},{name:`deprecated`,number:3,type:8,label:1,defaultValue:`false`},{name:`weak`,number:10,type:8,label:1,defaultValue:`false`,options:{deprecated:!0}},{name:`debug_redact`,number:16,type:8,label:1,defaultValue:`false`},{name:`retention`,number:17,type:14,label:1,typeName:`.google.protobuf.FieldOptions.OptionRetention`},{name:`targets`,number:19,type:14,label:3,typeName:`.google.protobuf.FieldOptions.OptionTargetType`},{name:`edition_defaults`,number:20,type:11,label:3,typeName:`.google.protobuf.FieldOptions.EditionDefault`},{name:`features`,number:21,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`feature_support`,number:22,type:11,label:1,typeName:`.google.protobuf.FieldOptions.FeatureSupport`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],nestedType:[{name:`EditionDefault`,field:[{name:`edition`,number:3,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`value`,number:2,type:9,label:1}]},{name:`FeatureSupport`,field:[{name:`edition_introduced`,number:1,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`edition_deprecated`,number:2,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`deprecation_warning`,number:3,type:9,label:1},{name:`edition_removed`,number:4,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`removal_error`,number:5,type:9,label:1}]}],enumType:[{name:`CType`,value:[{name:`STRING`,number:0},{name:`CORD`,number:1},{name:`STRING_PIECE`,number:2}]},{name:`JSType`,value:[{name:`JS_NORMAL`,number:0},{name:`JS_STRING`,number:1},{name:`JS_NUMBER`,number:2}]},{name:`OptionRetention`,value:[{name:`RETENTION_UNKNOWN`,number:0},{name:`RETENTION_RUNTIME`,number:1},{name:`RETENTION_SOURCE`,number:2}]},{name:`OptionTargetType`,value:[{name:`TARGET_TYPE_UNKNOWN`,number:0},{name:`TARGET_TYPE_FILE`,number:1},{name:`TARGET_TYPE_EXTENSION_RANGE`,number:2},{name:`TARGET_TYPE_MESSAGE`,number:3},{name:`TARGET_TYPE_FIELD`,number:4},{name:`TARGET_TYPE_ONEOF`,number:5},{name:`TARGET_TYPE_ENUM`,number:6},{name:`TARGET_TYPE_ENUM_ENTRY`,number:7},{name:`TARGET_TYPE_SERVICE`,number:8},{name:`TARGET_TYPE_METHOD`,number:9}]}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`OneofOptions`,field:[{name:`features`,number:1,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`EnumOptions`,field:[{name:`allow_alias`,number:2,type:8,label:1},{name:`deprecated`,number:3,type:8,label:1,defaultValue:`false`},{name:`deprecated_legacy_json_field_conflicts`,number:6,type:8,label:1,options:{deprecated:!0}},{name:`features`,number:7,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`EnumValueOptions`,field:[{name:`deprecated`,number:1,type:8,label:1,defaultValue:`false`},{name:`features`,number:2,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`debug_redact`,number:3,type:8,label:1,defaultValue:`false`},{name:`feature_support`,number:4,type:11,label:1,typeName:`.google.protobuf.FieldOptions.FeatureSupport`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`ServiceOptions`,field:[{name:`features`,number:34,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`deprecated`,number:33,type:8,label:1,defaultValue:`false`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`MethodOptions`,field:[{name:`deprecated`,number:33,type:8,label:1,defaultValue:`false`},{name:`idempotency_level`,number:34,type:14,label:1,typeName:`.google.protobuf.MethodOptions.IdempotencyLevel`,defaultValue:`IDEMPOTENCY_UNKNOWN`},{name:`features`,number:35,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`uninterpreted_option`,number:999,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption`}],enumType:[{name:`IdempotencyLevel`,value:[{name:`IDEMPOTENCY_UNKNOWN`,number:0},{name:`NO_SIDE_EFFECTS`,number:1},{name:`IDEMPOTENT`,number:2}]}],extensionRange:[{start:990,end:999},{start:1e3,end:536870912}]},{name:`UninterpretedOption`,field:[{name:`name`,number:2,type:11,label:3,typeName:`.google.protobuf.UninterpretedOption.NamePart`},{name:`identifier_value`,number:3,type:9,label:1},{name:`positive_int_value`,number:4,type:4,label:1},{name:`negative_int_value`,number:5,type:3,label:1},{name:`double_value`,number:6,type:1,label:1},{name:`string_value`,number:7,type:12,label:1},{name:`aggregate_value`,number:8,type:9,label:1}],nestedType:[{name:`NamePart`,field:[{name:`name_part`,number:1,type:9,label:2},{name:`is_extension`,number:2,type:8,label:2}]}]},{name:`FeatureSet`,field:[{name:`field_presence`,number:1,type:14,label:1,typeName:`.google.protobuf.FeatureSet.FieldPresence`,options:{retention:1,targets:[4,1],editionDefaults:[{value:`EXPLICIT`,edition:900},{value:`IMPLICIT`,edition:999},{value:`EXPLICIT`,edition:1e3}]}},{name:`enum_type`,number:2,type:14,label:1,typeName:`.google.protobuf.FeatureSet.EnumType`,options:{retention:1,targets:[6,1],editionDefaults:[{value:`CLOSED`,edition:900},{value:`OPEN`,edition:999}]}},{name:`repeated_field_encoding`,number:3,type:14,label:1,typeName:`.google.protobuf.FeatureSet.RepeatedFieldEncoding`,options:{retention:1,targets:[4,1],editionDefaults:[{value:`EXPANDED`,edition:900},{value:`PACKED`,edition:999}]}},{name:`utf8_validation`,number:4,type:14,label:1,typeName:`.google.protobuf.FeatureSet.Utf8Validation`,options:{retention:1,targets:[4,1],editionDefaults:[{value:`NONE`,edition:900},{value:`VERIFY`,edition:999}]}},{name:`message_encoding`,number:5,type:14,label:1,typeName:`.google.protobuf.FeatureSet.MessageEncoding`,options:{retention:1,targets:[4,1],editionDefaults:[{value:`LENGTH_PREFIXED`,edition:900}]}},{name:`json_format`,number:6,type:14,label:1,typeName:`.google.protobuf.FeatureSet.JsonFormat`,options:{retention:1,targets:[3,6,1],editionDefaults:[{value:`LEGACY_BEST_EFFORT`,edition:900},{value:`ALLOW`,edition:999}]}},{name:`enforce_naming_style`,number:7,type:14,label:1,typeName:`.google.protobuf.FeatureSet.EnforceNamingStyle`,options:{retention:2,targets:[1,2,3,4,5,6,7,8,9],editionDefaults:[{value:`STYLE_LEGACY`,edition:900},{value:`STYLE2024`,edition:1001},{value:`STYLE2026`,edition:1002}]}},{name:`default_symbol_visibility`,number:8,type:14,label:1,typeName:`.google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility`,options:{retention:2,targets:[1],editionDefaults:[{value:`EXPORT_ALL`,edition:900},{value:`EXPORT_TOP_LEVEL`,edition:1001},{value:`STRICT`,edition:1002}]}},{name:`enforce_proto_limits`,number:9,type:14,label:1,typeName:`.google.protobuf.FeatureSet.ProtoLimitsFeature.EnforceProtoLimits`,options:{retention:2,targets:[6,3,4,5],editionDefaults:[{value:`LEGACY_NO_EXPLICIT_LIMITS`,edition:900},{value:`PROTO_LIMITS2026`,edition:1002}]}}],nestedType:[{name:`VisibilityFeature`,enumType:[{name:`DefaultSymbolVisibility`,value:[{name:`DEFAULT_SYMBOL_VISIBILITY_UNKNOWN`,number:0},{name:`EXPORT_ALL`,number:1},{name:`EXPORT_TOP_LEVEL`,number:2},{name:`LOCAL_ALL`,number:3},{name:`STRICT`,number:4}]}]},{name:`ProtoLimitsFeature`,enumType:[{name:`EnforceProtoLimits`,value:[{name:`PROTO_LIMITS_UNKNOWN`,number:0},{name:`LEGACY_NO_EXPLICIT_LIMITS`,number:1},{name:`PROTO_LIMITS2026`,number:2}]}]}],enumType:[{name:`FieldPresence`,value:[{name:`FIELD_PRESENCE_UNKNOWN`,number:0},{name:`EXPLICIT`,number:1},{name:`IMPLICIT`,number:2},{name:`LEGACY_REQUIRED`,number:3}]},{name:`EnumType`,value:[{name:`ENUM_TYPE_UNKNOWN`,number:0},{name:`OPEN`,number:1},{name:`CLOSED`,number:2}]},{name:`RepeatedFieldEncoding`,value:[{name:`REPEATED_FIELD_ENCODING_UNKNOWN`,number:0},{name:`PACKED`,number:1},{name:`EXPANDED`,number:2}]},{name:`Utf8Validation`,value:[{name:`UTF8_VALIDATION_UNKNOWN`,number:0},{name:`VERIFY`,number:2},{name:`NONE`,number:3}]},{name:`MessageEncoding`,value:[{name:`MESSAGE_ENCODING_UNKNOWN`,number:0},{name:`LENGTH_PREFIXED`,number:1},{name:`DELIMITED`,number:2}]},{name:`JsonFormat`,value:[{name:`JSON_FORMAT_UNKNOWN`,number:0},{name:`ALLOW`,number:1},{name:`LEGACY_BEST_EFFORT`,number:2}]},{name:`EnforceNamingStyle`,value:[{name:`ENFORCE_NAMING_STYLE_UNKNOWN`,number:0},{name:`STYLE2024`,number:1},{name:`STYLE_LEGACY`,number:2},{name:`STYLE2026`,number:3}]}],extensionRange:[{start:1e3,end:9995},{start:9995,end:1e4},{start:1e4,end:10001}]},{name:`FeatureSetDefaults`,field:[{name:`defaults`,number:1,type:11,label:3,typeName:`.google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault`},{name:`minimum_edition`,number:4,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`maximum_edition`,number:5,type:14,label:1,typeName:`.google.protobuf.Edition`}],nestedType:[{name:`FeatureSetEditionDefault`,field:[{name:`edition`,number:3,type:14,label:1,typeName:`.google.protobuf.Edition`},{name:`overridable_features`,number:4,type:11,label:1,typeName:`.google.protobuf.FeatureSet`},{name:`fixed_features`,number:5,type:11,label:1,typeName:`.google.protobuf.FeatureSet`}]}]},{name:`SourceCodeInfo`,field:[{name:`location`,number:1,type:11,label:3,typeName:`.google.protobuf.SourceCodeInfo.Location`}],nestedType:[{name:`Location`,field:[{name:`path`,number:1,type:5,label:3,options:{packed:!0}},{name:`span`,number:2,type:5,label:3,options:{packed:!0}},{name:`leading_comments`,number:3,type:9,label:1},{name:`trailing_comments`,number:4,type:9,label:1},{name:`leading_detached_comments`,number:6,type:9,label:3}]}],extensionRange:[{start:536e6,end:536000001}]},{name:`GeneratedCodeInfo`,field:[{name:`annotation`,number:1,type:11,label:3,typeName:`.google.protobuf.GeneratedCodeInfo.Annotation`}],nestedType:[{name:`Annotation`,field:[{name:`path`,number:1,type:5,label:3,options:{packed:!0}},{name:`source_file`,number:2,type:9,label:1},{name:`begin`,number:3,type:5,label:1},{name:`end`,number:4,type:5,label:1},{name:`semantic`,number:5,type:14,label:1,typeName:`.google.protobuf.GeneratedCodeInfo.Annotation.Semantic`}],enumType:[{name:`Semantic`,value:[{name:`NONE`,number:0},{name:`SET`,number:1},{name:`ALIAS`,number:2}]}]}]}],enumType:[{name:`Edition`,value:[{name:`EDITION_UNKNOWN`,number:0},{name:`EDITION_LEGACY`,number:900},{name:`EDITION_PROTO2`,number:998},{name:`EDITION_PROTO3`,number:999},{name:`EDITION_2023`,number:1e3},{name:`EDITION_2024`,number:1001},{name:`EDITION_2026`,number:1002},{name:`EDITION_UNSTABLE`,number:9999},{name:`EDITION_1_TEST_ONLY`,number:1},{name:`EDITION_2_TEST_ONLY`,number:2},{name:`EDITION_99997_TEST_ONLY`,number:99997},{name:`EDITION_99998_TEST_ONLY`,number:99998},{name:`EDITION_99999_TEST_ONLY`,number:99999},{name:`EDITION_MAX`,number:2147483647}]},{name:`SymbolVisibility`,value:[{name:`VISIBILITY_UNSET`,number:0},{name:`VISIBILITY_LOCAL`,number:1},{name:`VISIBILITY_EXPORT`,number:2}]}]}),1);var fOe;(function(e){e[e.DECLARATION=0]=`DECLARATION`,e[e.UNVERIFIED=1]=`UNVERIFIED`})(fOe||={});var pOe;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.GROUP=10]=`GROUP`,e[e.MESSAGE=11]=`MESSAGE`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.ENUM=14]=`ENUM`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`})(pOe||={});var mOe;(function(e){e[e.OPTIONAL=1]=`OPTIONAL`,e[e.REPEATED=3]=`REPEATED`,e[e.REQUIRED=2]=`REQUIRED`})(mOe||={});var hOe;(function(e){e[e.SPEED=1]=`SPEED`,e[e.CODE_SIZE=2]=`CODE_SIZE`,e[e.LITE_RUNTIME=3]=`LITE_RUNTIME`})(hOe||={});var gOe;(function(e){e[e.STRING=0]=`STRING`,e[e.CORD=1]=`CORD`,e[e.STRING_PIECE=2]=`STRING_PIECE`})(gOe||={});var _Oe;(function(e){e[e.JS_NORMAL=0]=`JS_NORMAL`,e[e.JS_STRING=1]=`JS_STRING`,e[e.JS_NUMBER=2]=`JS_NUMBER`})(_Oe||={});var vOe;(function(e){e[e.RETENTION_UNKNOWN=0]=`RETENTION_UNKNOWN`,e[e.RETENTION_RUNTIME=1]=`RETENTION_RUNTIME`,e[e.RETENTION_SOURCE=2]=`RETENTION_SOURCE`})(vOe||={});var yOe;(function(e){e[e.TARGET_TYPE_UNKNOWN=0]=`TARGET_TYPE_UNKNOWN`,e[e.TARGET_TYPE_FILE=1]=`TARGET_TYPE_FILE`,e[e.TARGET_TYPE_EXTENSION_RANGE=2]=`TARGET_TYPE_EXTENSION_RANGE`,e[e.TARGET_TYPE_MESSAGE=3]=`TARGET_TYPE_MESSAGE`,e[e.TARGET_TYPE_FIELD=4]=`TARGET_TYPE_FIELD`,e[e.TARGET_TYPE_ONEOF=5]=`TARGET_TYPE_ONEOF`,e[e.TARGET_TYPE_ENUM=6]=`TARGET_TYPE_ENUM`,e[e.TARGET_TYPE_ENUM_ENTRY=7]=`TARGET_TYPE_ENUM_ENTRY`,e[e.TARGET_TYPE_SERVICE=8]=`TARGET_TYPE_SERVICE`,e[e.TARGET_TYPE_METHOD=9]=`TARGET_TYPE_METHOD`})(yOe||={});var aI;(function(e){e[e.IDEMPOTENCY_UNKNOWN=0]=`IDEMPOTENCY_UNKNOWN`,e[e.NO_SIDE_EFFECTS=1]=`NO_SIDE_EFFECTS`,e[e.IDEMPOTENT=2]=`IDEMPOTENT`})(aI||={});var bOe;(function(e){e[e.DEFAULT_SYMBOL_VISIBILITY_UNKNOWN=0]=`DEFAULT_SYMBOL_VISIBILITY_UNKNOWN`,e[e.EXPORT_ALL=1]=`EXPORT_ALL`,e[e.EXPORT_TOP_LEVEL=2]=`EXPORT_TOP_LEVEL`,e[e.LOCAL_ALL=3]=`LOCAL_ALL`,e[e.STRICT=4]=`STRICT`})(bOe||={});var xOe;(function(e){e[e.PROTO_LIMITS_UNKNOWN=0]=`PROTO_LIMITS_UNKNOWN`,e[e.LEGACY_NO_EXPLICIT_LIMITS=1]=`LEGACY_NO_EXPLICIT_LIMITS`,e[e.PROTO_LIMITS2026=2]=`PROTO_LIMITS2026`})(xOe||={});var SOe;(function(e){e[e.FIELD_PRESENCE_UNKNOWN=0]=`FIELD_PRESENCE_UNKNOWN`,e[e.EXPLICIT=1]=`EXPLICIT`,e[e.IMPLICIT=2]=`IMPLICIT`,e[e.LEGACY_REQUIRED=3]=`LEGACY_REQUIRED`})(SOe||={});var COe;(function(e){e[e.ENUM_TYPE_UNKNOWN=0]=`ENUM_TYPE_UNKNOWN`,e[e.OPEN=1]=`OPEN`,e[e.CLOSED=2]=`CLOSED`})(COe||={});var wOe;(function(e){e[e.REPEATED_FIELD_ENCODING_UNKNOWN=0]=`REPEATED_FIELD_ENCODING_UNKNOWN`,e[e.PACKED=1]=`PACKED`,e[e.EXPANDED=2]=`EXPANDED`})(wOe||={});var TOe;(function(e){e[e.UTF8_VALIDATION_UNKNOWN=0]=`UTF8_VALIDATION_UNKNOWN`,e[e.VERIFY=2]=`VERIFY`,e[e.NONE=3]=`NONE`})(TOe||={});var EOe;(function(e){e[e.MESSAGE_ENCODING_UNKNOWN=0]=`MESSAGE_ENCODING_UNKNOWN`,e[e.LENGTH_PREFIXED=1]=`LENGTH_PREFIXED`,e[e.DELIMITED=2]=`DELIMITED`})(EOe||={});var DOe;(function(e){e[e.JSON_FORMAT_UNKNOWN=0]=`JSON_FORMAT_UNKNOWN`,e[e.ALLOW=1]=`ALLOW`,e[e.LEGACY_BEST_EFFORT=2]=`LEGACY_BEST_EFFORT`})(DOe||={});var OOe;(function(e){e[e.ENFORCE_NAMING_STYLE_UNKNOWN=0]=`ENFORCE_NAMING_STYLE_UNKNOWN`,e[e.STYLE2024=1]=`STYLE2024`,e[e.STYLE_LEGACY=2]=`STYLE_LEGACY`,e[e.STYLE2026=3]=`STYLE2026`})(OOe||={});var kOe;(function(e){e[e.NONE=0]=`NONE`,e[e.SET=1]=`SET`,e[e.ALIAS=2]=`ALIAS`})(kOe||={});var AOe;(function(e){e[e.EDITION_UNKNOWN=0]=`EDITION_UNKNOWN`,e[e.EDITION_LEGACY=900]=`EDITION_LEGACY`,e[e.EDITION_PROTO2=998]=`EDITION_PROTO2`,e[e.EDITION_PROTO3=999]=`EDITION_PROTO3`,e[e.EDITION_2023=1e3]=`EDITION_2023`,e[e.EDITION_2024=1001]=`EDITION_2024`,e[e.EDITION_2026=1002]=`EDITION_2026`,e[e.EDITION_UNSTABLE=9999]=`EDITION_UNSTABLE`,e[e.EDITION_1_TEST_ONLY=1]=`EDITION_1_TEST_ONLY`,e[e.EDITION_2_TEST_ONLY=2]=`EDITION_2_TEST_ONLY`,e[e.EDITION_99997_TEST_ONLY=99997]=`EDITION_99997_TEST_ONLY`,e[e.EDITION_99998_TEST_ONLY=99998]=`EDITION_99998_TEST_ONLY`,e[e.EDITION_99999_TEST_ONLY=99999]=`EDITION_99999_TEST_ONLY`,e[e.EDITION_MAX=2147483647]=`EDITION_MAX`})(AOe||={});var jOe;(function(e){e[e.VISIBILITY_UNSET=0]=`VISIBILITY_UNSET`,e[e.VISIBILITY_LOCAL=1]=`VISIBILITY_LOCAL`,e[e.VISIBILITY_EXPORT=2]=`VISIBILITY_EXPORT`})(jOe||={});function oI(e){return Object.assign(Object.assign({readUnknownFields:!0,recursionLimit:100},e),{depth:0})}function sI(e,t,n){let r=VP(e);return lI(e).read(r,new tF(t),oI(n),t.byteLength),r}const cI=new WeakMap;function lI(e){let t=cI.get(e);return t===void 0&&(t=MOe(e)),t}function MOe(e){let t=String(e),n=new Map,r={read:NOe(t,n),readGroup:POe(t,n)};cI.set(e,r);for(let t of e.fields)n.set(t.number,uI(t));return r}function NOe(e,t){return(n,r,i,a)=>{if(++i.depth>i.recursionLimit)throw Error(`cannot decode ${e} from binary: maximum recursion depth of ${i.recursionLimit} reached`);let o=r.pos+a,s=n.$unknown??[];for(;r.pos<o;){let[e,a]=r.tag(),o=t.get(e);if(o===void 0){let t=r.skip(a,e,i.recursionLimit-i.depth);i.readUnknownFields&&s.push({no:e,wireType:a,data:t});continue}o(n,r,i,a)}s.length>0&&(n.$unknown=s),i.depth--}}function POe(e,t){return(n,r,i,a)=>{if(++i.depth>i.recursionLimit)throw Error(`cannot decode ${e} from binary: maximum recursion depth of ${i.recursionLimit} reached`);let o,s,c=n.$unknown??[];for(;r.pos<r.len&&([o,s]=r.tag(),s!=XP.EndGroup);){let e=t.get(o);if(e===void 0){let e=r.skip(s,o,i.recursionLimit-i.depth);i.readUnknownFields&&c.push({no:o,wireType:s,data:e});continue}e(n,r,i,s)}if(s!=XP.EndGroup||o!==a)throw Error(`invalid end group tag`);c.length>0&&(n.$unknown=c),i.depth--}}function FOe(e,t,n,r,i){uI(n)(e[jP],t,i,r)}function uI(e){switch(e.fieldKind){case`scalar`:return IOe(e);case`enum`:return LOe(e);case`message`:return ROe(e);case`list`:return zOe(e);case`map`:return BOe(e)}}function IOe(e){let t=fI(e.scalar,e.utf8Validation,e.longAsString),n=e.localName;if(e.oneof){let r=e.oneof.localName;return(e,i)=>{e[r]={case:n,value:t(i)}}}return(e,r)=>{e[n]=t(r)}}function LOe(e){let t=e.localName,n=e.oneof?.localName;if(e.enum.open)return n===void 0?(e,n)=>{e[t]=n.int32()}:(e,r)=>{e[n]={case:t,value:r.int32()}};let r=e.enum.values,i=e.number;return(e,a,o,s)=>{let c=a.int32();if(r.some(e=>e.number===c))n===void 0?e[t]=c:e[n]={case:t,value:c};else if(o.readUnknownFields){let t=[];sDe(c,t);let n=e.$unknown??[];n.push({no:i,wireType:s,data:new Uint8Array(t)}),e.$unknown=n}}}function ROe(e){let t=e.localName,{toMessage:n,toLocal:r}=pF(e),i=dI(e);if(e.oneof){let a=e.oneof.localName;return(e,o,s)=>{let c=e[a],l=n(c.case===t?c.value:void 0);i(l,o,s),e[a]={case:t,value:r(l)}}}return(e,a,o)=>{let s=n(e[t]);i(s,a,o),e[t]=r(s)}}function dI(e){let t=lI(e.message);if(e.delimitedEncoding){let n=e.number;return(e,r,i)=>t.readGroup(e,r,i,n)}return(e,n,r)=>t.read(e,n,r,n.uint32())}function zOe(e){let t=e.localName;if(e.listKind==`message`){let{toMessage:n,toLocal:r}=pF(e),i=dI(e);return(e,a,o)=>{let s=n(void 0);i(s,a,o),e[t].push(r(s))}}let n=e.listKind==`enum`?V.INT32:e.scalar,r=e.listKind==`scalar`&&e.longAsString,i=fI(n,e.utf8Validation,r),a=n!=V.STRING&&n!=V.BYTES;return(e,n,r,o)=>{let s=e[t];if(o==XP.LengthDelimited&&a){let e=n.uint32()+n.pos;for(;n.pos<e;)s.push(i(n))}else s.push(i(n))}}function BOe(e){let t=e.localName,n=fI(e.mapKey,e.utf8Validation,!1),r=AP(e.mapKey,!1),i,a;switch(e.mapKind){case`scalar`:{let t=e.scalar,n=fI(t,e.utf8Validation,!1);if(i=e=>n(e),t==V.BYTES)a=()=>new Uint8Array;else{let e=AP(t,!1);a=()=>e}break}case`enum`:{let t=e.enum.values[0].number;i=e=>e.int32(),a=()=>t;break}case`message`:{let{toMessage:t,toLocal:n}=pF(e),r=lI(e.message).read;i=(e,i,a)=>{let o=t(a);return r(o,e,i,e.uint32()),n(o)},a=()=>n(t(void 0));break}}return(e,o,s)=>{let c=e[t],l,u,d=o.uint32(),f=o.pos+d;for(;o.pos<f;){let[e,t]=o.tag();switch(e){case 1:l=n(o);break;case 2:u=i(o,s,u);break;default:o.skip(t,e,s.recursionLimit-s.depth)}}l===void 0&&(l=r),u===void 0&&(u=a()),NP(c,l,u)}}function fI(e,t,n){switch(e){case V.STRING:return e=>e.string(t);case V.BOOL:return e=>e.bool();case V.DOUBLE:return e=>e.double();case V.FLOAT:return e=>e.float();case V.INT32:return e=>e.int32();case V.INT64:return n?e=>String(e.int64()):e=>e.int64();case V.UINT64:return n?e=>String(e.uint64()):e=>e.uint64();case V.FIXED64:return n?e=>String(e.fixed64()):e=>e.fixed64();case V.BYTES:return e=>e.bytes();case V.FIXED32:return e=>e.fixed32();case V.SFIXED32:return e=>e.sfixed32();case V.SFIXED64:return n?e=>String(e.sfixed64()):e=>e.sfixed64();case V.SINT64:return n?e=>String(e.sint64()):e=>e.sint64();case V.UINT32:return e=>e.uint32();case V.SINT32:return e=>e.sint32()}}function pI(e,t){let n=sI(dOe,jF(e));return n.messageType.forEach(VF),n.dependency=t?.map(e=>e.proto.name)??[],UF(n,e=>t?.find(t=>t.proto.name===e)).getFile(n.name)}const VOe=pI(`Ch9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnByb3RvEg9nb29nbGUucHJvdG9idWYiKwoJVGltZXN0YW1wEg8KB3NlY29uZHMYASABKAMSDQoFbmFub3MYAiABKAVChQEKE2NvbS5nb29nbGUucHJvdG9idWZCDlRpbWVzdGFtcFByb3RvUAFaMmdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3RpbWVzdGFtcHBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM`),HOe=iI(pI(`Chlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYiJgoDQW55EhAKCHR5cGVfdXJsGAEgASgJEg0KBXZhbHVlGAIgASgMQnYKE2NvbS5nb29nbGUucHJvdG9idWZCCEFueVByb3RvUAFaLGdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL2FueXBiogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM`),0),mI={writeUnknownFields:!0};function UOe(e){return e?Object.assign(Object.assign({},mI),e):mI}function hI(e,t,n){let r=new ZP;return _I(e)(r,UOe(n),t),r.finish()}const gI=new WeakMap;function _I(e){let t=gI.get(e);return t===void 0&&(t=WOe(e)),t}function WOe(e){let t=e.typeName,n=e.fields.concat().sort((e,t)=>e.number-t.number),r=n[0],i=[],a=(e,n,a)=>{if(a.$typeName!==t&&r!==void 0)throw new KP(r,`cannot use ${r} with message ${a.$typeName}`,`ForeignFieldError`);for(let t=0;t<i.length;t++)i[t](e,n,a);let o=a.$unknown;if(o!==void 0&&n.writeUnknownFields)for(let t=0;t<o.length;t++){let{no:n,wireType:r,data:i}=o[t];e.tag(n,r).raw(i)}};gI.set(e,a);for(let e of n)i.push(vI(e));return a}function vI(e){switch(e.fieldKind){case`message`:case`scalar`:case`enum`:return GOe(e);case`list`:return qOe(e);case`map`:return JOe(e)}}function GOe(e){let t=KOe(e),n=e.localName;if(e.oneof){let r=e.oneof.localName;return(e,i,a)=>{let o=a[r];o.case===n&&t(e,i,o.value)}}if(e.presence!=2){let r=e.presence==3?`cannot encode ${e} to binary: required field not set`:void 0;return(e,i,a)=>{let o=a[n];if(o!==void 0&&Object.prototype.hasOwnProperty.call(a,n))t(e,i,o);else if(r!==void 0)throw Error(r)}}if(e.fieldKind==`enum`){let r=e.enum.values[0].number;return(e,i,a)=>{let o=a[n];o!==r&&t(e,i,o)}}switch(e.scalar){case V.BOOL:return(e,r,i)=>{let a=i[n];a!==!1&&t(e,r,a)};case V.STRING:return(e,r,i)=>{let a=i[n];a!==``&&t(e,r,a)};case V.BYTES:return(e,r,i)=>{let a=i[n];(!(a instanceof Uint8Array)||a.byteLength>0)&&t(e,r,a)};case V.DOUBLE:case V.FLOAT:return(e,r,i)=>{let a=i[n];Object.is(a,0)||t(e,r,a)};default:return(e,r,i)=>{let a=i[n];a!=0&&t(e,r,a)}}}function KOe(e){switch(e.fieldKind){case`message`:{let{toMessage:t}=pF(e),n=bI(e);return(e,r,i)=>{n(e,r,t(i))}}case`scalar`:case`enum`:{let t=e.fieldKind==`enum`?V.INT32:e.scalar,n=e.number,r=xI(t),i=yI(t,e.parent.typeName,e.name);return(e,t,a)=>{e.tag(n,r),i(e,a)}}}}function qOe(e){let t=e.localName,n=e.number;switch(e.listKind){case`message`:{let{toMessage:n}=pF(e),r=bI(e);return(e,i,a)=>{let o=a[t];for(let t=0;t<o.length;t++)r(e,i,n(o[t]))}}case`scalar`:case`enum`:{let r=e.listKind==`enum`?V.INT32:e.scalar,i=yI(r,e.parent.typeName,e.name);if(e.packed)return(e,r,a)=>{let o=a[t];if(o.length!=0){e.tag(n,XP.LengthDelimited).fork();for(let t=0;t<o.length;t++)i(e,o[t]);e.join()}};let a=xI(r);return(e,r,o)=>{let s=o[t];for(let t=0;t<s.length;t++)e.tag(n,a),i(e,s[t])}}}}function JOe(e){let t=e.localName,n=e.number,r=YOe(e);if(e.mapKind==`message`){let{toMessage:i}=pF(e),a=_I(e.message);return(e,o,s)=>{let c=s[t],l=Object.keys(c);for(let t=0;t<l.length;t++){let s=l[t];e.tag(n,XP.LengthDelimited).fork(),r(e,s),e.tag(2,XP.LengthDelimited).fork(),a(e,o,i(c[s])),e.join(),e.join()}}}let i=e.mapKind==`enum`?V.INT32:e.scalar,a=xI(i),o=yI(i,e.parent.typeName,e.name);return(e,i,s)=>{let c=s[t],l=Object.keys(c);for(let t=0;t<l.length;t++){let i=l[t];e.tag(n,XP.LengthDelimited).fork(),r(e,i),e.tag(2,a),o(e,c[i]),e.join()}}}function YOe(e){let t=xI(e.mapKey),n=yI(e.mapKey,e.parent.typeName,e.name),r=XOe(e.mapKey);return(e,i)=>{e.tag(1,t),n(e,r(i))}}function XOe(e){switch(e){case V.STRING:return e=>e;case V.BOOL:return e=>e===`true`||e!==`false`&&e;case V.UINT64:case V.FIXED64:return e=>{try{return DP.uParse(e)}catch{return e}};case V.INT64:case V.SFIXED64:case V.SINT64:return e=>{try{return DP.parse(e)}catch{return e}};default:return e=>{let t=Number.parseInt(e);return Number.isFinite(t)?t:e}}}function yI(e,t,n){let r=ZOe(e);return(e,i)=>{try{r(e,i)}catch(e){throw e instanceof Error?Error(`cannot encode field ${t}.${n} to binary: ${e.message}`):e}}}function ZOe(e){switch(e){case V.STRING:return(e,t)=>e.string(t);case V.BOOL:return(e,t)=>e.bool(t);case V.DOUBLE:return(e,t)=>e.double(t);case V.FLOAT:return(e,t)=>e.float(t);case V.INT32:return(e,t)=>e.int32(t);case V.INT64:return(e,t)=>e.int64(t);case V.UINT64:return(e,t)=>e.uint64(t);case V.FIXED64:return(e,t)=>e.fixed64(t);case V.BYTES:return(e,t)=>e.bytes(t);case V.FIXED32:return(e,t)=>e.fixed32(t);case V.SFIXED32:return(e,t)=>e.sfixed32(t);case V.SFIXED64:return(e,t)=>e.sfixed64(t);case V.SINT64:return(e,t)=>e.sint64(t);case V.UINT32:return(e,t)=>e.uint32(t);case V.SINT32:return(e,t)=>e.sint32(t)}}function QOe(e,t,n,r){vI(r)(e,t,n[jP])}function bI(e){let t=e.number,n=_I(e.message);return e.delimitedEncoding?(e,r,i)=>{e.tag(t,XP.StartGroup),n(e,r,i),e.tag(t,XP.EndGroup)}:(e,r,i)=>{e.tag(t,XP.LengthDelimited).fork(),n(e,r,i),e.join()}}function xI(e){switch(e){case V.BYTES:case V.STRING:return XP.LengthDelimited;case V.DOUBLE:case V.FIXED64:case V.SFIXED64:return XP.Bit64;case V.FIXED32:case V.SFIXED32:case V.FLOAT:return XP.Bit32;default:return XP.Varint}}function $Oe(e,t,n){let r=!1;return n||(n=VP(HOe),r=!0),n.value=hI(e,t),n.typeUrl=nke(t.$typeName),r?n:void 0}function eke(e,t){return e.typeUrl!==``&&(typeof t==`string`?t:t.typeName)===SI(e.typeUrl)}function tke(e,t){if(e.typeUrl===``)return;let n=t.kind==`message`?t:t.getMessage(SI(e.typeUrl));if(n&&eke(e,n))return sI(n,e.value)}function nke(e){return`type.googleapis.com/${e}`}function SI(e){let t=e.lastIndexOf(`/`),n=t>=0?e.substring(t+1):e;if(!n.length)throw Error(`invalid type url: ${e}`);return n}const CI=pI(`Chxnb29nbGUvcHJvdG9idWYvc3RydWN0LnByb3RvEg9nb29nbGUucHJvdG9idWYihAEKBlN0cnVjdBIzCgZmaWVsZHMYASADKAsyIy5nb29nbGUucHJvdG9idWYuU3RydWN0LkZpZWxkc0VudHJ5GkUKC0ZpZWxkc0VudHJ5EgsKA2tleRgBIAEoCRIlCgV2YWx1ZRgCIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZToCOAEi6gEKBVZhbHVlEjAKCm51bGxfdmFsdWUYASABKA4yGi5nb29nbGUucHJvdG9idWYuTnVsbFZhbHVlSAASFgoMbnVtYmVyX3ZhbHVlGAIgASgBSAASFgoMc3RyaW5nX3ZhbHVlGAMgASgJSAASFAoKYm9vbF92YWx1ZRgEIAEoCEgAEi8KDHN0cnVjdF92YWx1ZRgFIAEoCzIXLmdvb2dsZS5wcm90b2J1Zi5TdHJ1Y3RIABIwCgpsaXN0X3ZhbHVlGAYgASgLMhouZ29vZ2xlLnByb3RvYnVmLkxpc3RWYWx1ZUgAQgYKBGtpbmQiMwoJTGlzdFZhbHVlEiYKBnZhbHVlcxgBIAMoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZSobCglOdWxsVmFsdWUSDgoKTlVMTF9WQUxVRRAAQn8KE2NvbS5nb29nbGUucHJvdG9idWZCC1N0cnVjdFByb3RvUAFaL2dvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2tub3duL3N0cnVjdHBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM`),rke=iI(CI,0),wI=iI(CI,1),ike=iI(CI,2);var TI;(function(e){e[e.NULL_VALUE=0]=`NULL_VALUE`})(TI||={});function ake(e,t,n){DI(t,e);let r=ske(e.$unknown,t),[i,a,o]=EI(t),s=oI(n);for(let e of r)FOe(i,new tF(e.data),a,e.wireType,s);return o()}function oke(e,t,n){DI(t,e);let r=(e.$unknown??[]).filter(e=>e.no!==t.number),[i,a]=EI(t,n),o=new ZP;QOe(o,{writeUnknownFields:!0},i,a);let s=new tF(o.finish());for(;s.pos<s.len;){let[e,t]=s.tag(),n=s.skip(t,e);r.push({no:e,wireType:t,data:n})}e.$unknown=r}function ske(e,t){if(e===void 0)return[];if(t.fieldKind===`enum`||t.fieldKind===`scalar`){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.number)return[e[n]];return[]}return e.filter(e=>e.no===t.number)}function EI(e,t){let n=e.typeName,r=Object.assign(Object.assign({},e),{kind:`field`,parent:e.extendee,localName:n}),i=Object.assign(Object.assign({},e.extendee),{fields:[r],members:[r],oneofs:[]}),a=VP(i,t===void 0?void 0:{[n]:t});return[PDe(i,a),r,()=>{let t=a[n];if(t===void 0){let t=e.message;return RP(t)?AP(t.fields[0].scalar,t.fields[0].longAsString):VP(t)}return t}]}function DI(e,t){if(e.extendee.typeName!=t.$typeName)throw Error(`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}const OI=Date.parse(`0001-01-01T00:00:00Z`),kI=Date.parse(`9999-12-31T23:59:59Z`),AI={alwaysEmitImplicit:!1,enumAsInteger:!1,useProtoFieldName:!1};function cke(e){return e?Object.assign(Object.assign({},AI),e):AI}function jI(e,t,n){return NI(e)(cke(n),t)}function lke(e,t,n){let r=jI(e,t,n);return JSON.stringify(r,null,n?.prettySpaces??0)}const MI=new WeakMap;function NI(e){let t=MI.get(e);return t===void 0&&(t=uke(e)),t}function uke(e){let t=e.typeName,n=fke(e);if(n!==void 0){let r=e.fields[0],i=(e,i)=>{if(i.$typeName!==t&&r!==void 0)throw new KP(r,`cannot use ${r} with message ${i.$typeName}`,`ForeignFieldError`);return n(e,i)};return MI.set(e,i),i}let r=e.fields.concat().sort((e,t)=>e.number-t.number),i=r[0],a=[],o=(n,r)=>{if(r.$typeName!==t&&i!==void 0)throw new KP(i,`cannot use ${i} with message ${r.$typeName}`,`ForeignFieldError`);let o={};for(let e=0;e<a.length;e++)a[e](n,r,o);return n.registry&&vke(o,n,n.registry,r,e),o};MI.set(e,o);for(let e of r){let t=pke(e);a.push(e.jsonName===`__proto__`||e.name===`__proto__`?dke(t):t)}return o}function dke(e){return(t,n,r)=>{let i=Object.create(null);e(t,n,i);for(let e of Object.keys(i))NP(r,e,i[e])}}function fke(e){if(e.typeName.startsWith(`google.protobuf.`))switch(e.typeName){case`google.protobuf.Any`:return(e,t)=>yke(t,e);case`google.protobuf.Timestamp`:return(e,t)=>Cke(t);case`google.protobuf.Duration`:return(e,t)=>bke(t);case`google.protobuf.FieldMask`:return(e,t)=>xke(t);case`google.protobuf.Struct`:return(e,t)=>HI(t);case`google.protobuf.Value`:return(e,t)=>UI(t);case`google.protobuf.ListValue`:return(e,t)=>Ske(t);default:if(RP(e)){let t=e.fields[0],n=t.localName,r=AP(t.scalar,!1),i=BI(t);return(e,t)=>{let a=t[n];return i(e,a===void 0?r:a)}}return}}function pke(e){switch(e.fieldKind){case`scalar`:case`enum`:case`message`:return mke(e);case`list`:case`map`:{let t=e.fieldKind==`list`?II(e):LI(e),n=e.name,r=e.jsonName,i=e.localName;return(e,a,o)=>{let s=t(e,a[i]);s!==void 0&&(o[e.useProtoFieldName?n:r]=s)}}}}function mke(e){let t=PI(e),n=e.name,r=e.jsonName,i=e.localName;if(e.oneof){let a=e.oneof.localName;return(e,o,s)=>{let c=o[a];c.case===i&&(s[e.useProtoFieldName?n:r]=t(e,c.value))}}if(e.presence!=2){let a=e.presence==3?`cannot encode ${e} to JSON: required field not set`:void 0;return(e,o,s)=>{let c=o[i];if(c!==void 0&&Object.prototype.hasOwnProperty.call(o,i))s[e.useProtoFieldName?n:r]=t(e,c);else if(a!==void 0)throw Error(a)}}if(e.fieldKind==`enum`){let a=e.enum.values[0].number;return(e,o,s)=>{let c=o[i];(c!==a||e.alwaysEmitImplicit)&&(s[e.useProtoFieldName?n:r]=t(e,c))}}switch(e.scalar){case V.BOOL:return(e,a,o)=>{let s=a[i];(s!==!1||e.alwaysEmitImplicit)&&(o[e.useProtoFieldName?n:r]=t(e,s))};case V.STRING:return(e,a,o)=>{let s=a[i];(s!==``||e.alwaysEmitImplicit)&&(o[e.useProtoFieldName?n:r]=t(e,s))};case V.BYTES:return(e,a,o)=>{let s=a[i];(!(s instanceof Uint8Array)||s.byteLength>0||e.alwaysEmitImplicit)&&(o[e.useProtoFieldName?n:r]=t(e,s))};case V.DOUBLE:case V.FLOAT:return(e,a,o)=>{let s=a[i];(!Object.is(s,0)||e.alwaysEmitImplicit)&&(o[e.useProtoFieldName?n:r]=t(e,s))};default:return(e,a,o)=>{let s=a[i];(s!=0||e.alwaysEmitImplicit)&&(o[e.useProtoFieldName?n:r]=t(e,s))}}}function hke(e){switch(e.fieldKind){case`scalar`:case`enum`:case`message`:return PI(e);case`list`:return II(e);case`map`:return LI(e)}}function PI(e){switch(e.fieldKind){case`scalar`:return BI(e);case`enum`:return RI(e);case`message`:return FI(e)}}function FI(e){let{toMessage:t}=pF(e),n=NI(e.message);return(e,r)=>n(e,t(r))}function II(e){let t=gke(e);return(e,n)=>{let r=n;if(r.length==0&&!e.alwaysEmitImplicit)return;let i=[];for(let n=0;n<r.length;n++)i.push(t(e,r[n]));return i}}function gke(e){switch(e.listKind){case`scalar`:return BI(e);case`enum`:return RI(e);case`message`:return FI(e)}}function LI(e){let t=_ke(e);return(e,n)=>{let r=n,i=Object.keys(r);if(i.length==0&&!e.alwaysEmitImplicit)return;let a={};for(let n=0;n<i.length;n++){let o=i[n];NP(a,o,t(e,r[o]))}return a}}function _ke(e){switch(e.mapKind){case`scalar`:return BI(e);case`enum`:return RI(e);case`message`:return FI(e)}}function RI(e){let t=e.enum;return t.typeName==`google.protobuf.NullValue`?(e,n)=>{if(typeof n!=`number`)throw zI(t,n);return null}:(e,n)=>{if(typeof n!=`number`)throw zI(t,n);return e.enumAsInteger?n:t.value[n]?.jsonName??n}}function zI(e,t){return Error(`cannot encode ${e} to JSON: expected number, got ${lF(t)}`)}function BI(e){switch(e.scalar){case V.INT32:case V.SFIXED32:case V.SINT32:case V.FIXED32:case V.UINT32:return(t,n)=>{if(typeof n!=`number`)throw VI(e,n);return n};case V.FLOAT:case V.DOUBLE:return(t,n)=>{if(typeof n!=`number`)throw VI(e,n);return Number.isNaN(n)?`NaN`:n===1/0?`Infinity`:n===-1/0?`-Infinity`:n};case V.STRING:return(t,n)=>{if(typeof n!=`string`)throw VI(e,n);return n};case V.BOOL:return(t,n)=>{if(typeof n!=`boolean`)throw VI(e,n);return n};case V.UINT64:case V.FIXED64:case V.INT64:case V.SFIXED64:case V.SINT64:return(t,n)=>{if(typeof n==`bigint`||typeof n==`string`||typeof n==`number`&&Number.isInteger(n))return n.toString();throw VI(e,n)};case V.BYTES:return(t,n)=>{if(n instanceof Uint8Array)return NF(n);throw VI(e,n)}}}function VI(e,t){return Error(`cannot encode ${e} to JSON: ${iF(e,t)?.message}`)}function vke(e,t,n,r,i){let a=r.$unknown;if(a===void 0)return;let o=new Set;for(let s=0;s<a.length;s++){let{no:c}=a[s];if(!o.has(c)){o.add(c);let a=n.getExtensionFor(i,c);if(!a)continue;let[s,l]=EI(a,ake(r,a)),u=s[jP],d=hke(l)(t,u[l.localName]);d!==void 0&&(e[a.jsonName]=d)}}}function yke(e,t){if(e.typeUrl===``)return{};let{registry:n}=t,r,i;if(n&&(r=tke(e,n),r&&(i=n.getMessage(r.$typeName))),!i||!r)throw Error(`cannot encode message ${e.$typeName} to JSON: "${e.typeUrl}" is not in the type registry`);let a=zP(i)?{value:NI(i)(t,r)}:NI(i)(t,r);return a[`@type`]=e.typeUrl,a}function bke(e){let t=Number(e.seconds),n=e.nanos;if(t>315576e6||t<-315576e6)throw Error(`cannot encode message ${e.$typeName} to JSON: value out of range`);if(t>0&&n<0||t<0&&n>0)throw Error(`cannot encode message ${e.$typeName} to JSON: nanos sign must match seconds sign`);let r=e.seconds.toString();if(n!==0){let e=Math.abs(n).toString();e=`0`.repeat(9-e.length)+e,e.substring(3)===`000000`?e=e.substring(0,3):e.substring(6)===`000`&&(e=e.substring(0,6)),r+=`.`+e,n<0&&t==0&&(r=`-`+r)}return r+`s`}function xke(e){return e.paths.map(t=>{if(zF(RF(t))!==t)throw Error(`cannot encode message ${e.$typeName} to JSON: lowerCamelCase of path name "${t}" is irreversible`);return RF(t)}).join(`,`)}function HI(e){let t={},n=Object.keys(e.fields);for(let r=0;r<n.length;r++){let i=n[r];NP(t,i,UI(e.fields[i]))}return t}function UI(e){switch(e.kind.case){case`nullValue`:return null;case`numberValue`:if(!Number.isFinite(e.kind.value))throw Error(`${e.$typeName} cannot be NaN or Infinity`);return e.kind.value;case`boolValue`:return e.kind.value;case`stringValue`:return e.kind.value;case`structValue`:return HI(e.kind.value);case`listValue`:return Ske(e.kind.value);default:throw Error(`${e.$typeName} must have a value`)}}function Ske(e){return e.values.map(UI)}function Cke(e){let t=Number(e.seconds)*1e3;if(t<OI||t>kI)throw Error(`cannot encode message ${e.$typeName} to JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);if(e.nanos<0)throw Error(`cannot encode message ${e.$typeName} to JSON: nanos must not be negative`);if(e.nanos>999999999)throw Error(`cannot encode message ${e.$typeName} to JSON: nanos must not be greater than 999999999`);let n=`Z`;if(e.nanos>0){let t=(e.nanos+1e9).toString().substring(1);n=t.substring(3)===`000000`?`.`+t.substring(0,3)+`Z`:t.substring(6)===`000`?`.`+t.substring(0,6)+`Z`:`.`+t+`Z`}return new Date(t).toISOString().replace(`.000Z`,n)}function wke(e){return Object.assign(Object.assign({ignoreUnknownFields:!1,recursionLimit:100},e),{depth:0})}function Tke(e,t,n){return Eke(e,Vke(t,e.typeName),n)}function Eke(e,t,n){let r=VP(e);return Dke(e,r,t,n),r}function Dke(e,t,n,r){try{GI(e)(t,n,wke(r))}catch(e){throw TDe(e)?Error(`cannot decode ${e.field()} from JSON: ${e.message}`,{cause:e}):e}}const WI=new WeakMap;function GI(e){let t=WI.get(e);return t===void 0&&(t=Oke(e)),t}function Oke(e){let t=String(e),n=kke(e);if(n!==void 0){let r=(e,r,i)=>{if(++i.depth>i.recursionLimit)throw Error(`cannot decode ${t} from JSON: maximum recursion depth of ${i.recursionLimit} reached`);n(e,r,i),i.depth--};return WI.set(e,r),r}let r=e.typeName,i=new Map,a=(e,n,a)=>{if(++a.depth>a.recursionLimit)throw Error(`cannot decode ${t} from JSON: maximum recursion depth of ${a.recursionLimit} reached`);if(n==null||Array.isArray(n)||typeof n!=`object`)throw Error(`cannot decode ${t} from JSON: ${lF(n)}`);let o=new Map,s=new Set,c=Object.keys(n);for(let l=0;l<c.length;l++){let u=c[l],d=n[u],f=i.get(u);if(f!==void 0){let t=f.field;if(s.has(t))throw new KP(t,`set multiple times`);if(s.add(t),f.oneofScalarNullSkip&&d===null)continue;if(f.oneof){let e=o.get(f.oneof);if(e!==void 0)throw new KP(f.oneof,`oneof set multiple times by ${e.name} and ${t.name}`);o.set(f.oneof,t)}f.read(e,d,a)}else{let n=u.startsWith(`[`)&&u.endsWith(`]`)?a.registry?.getExtension(u.substring(1,u.length-1)):void 0;if(n?.extendee.typeName==r){let[t,r,i]=EI(n);Ake(r)(t[jP],d,a),oke(e,n,i())}if(n===void 0&&!a.ignoreUnknownFields)throw Error(`cannot decode ${t} from JSON: key "${u}" is unknown`)}}a.depth--};WI.set(e,a);for(let t of e.fields){let e={read:Ake(t),field:t,oneof:t.oneof,oneofScalarNullSkip:t.oneof!==void 0&&t.fieldKind==`scalar`};i.set(t.name,e).set(t.jsonName,e)}return a}function kke(e){if(e.typeName.startsWith(`google.protobuf.`))switch(e.typeName){case`google.protobuf.Any`:return(e,t,n)=>Uke(e,t,n);case`google.protobuf.Timestamp`:return(e,t)=>Wke(e,t);case`google.protobuf.Duration`:return(e,t)=>Gke(e,t);case`google.protobuf.FieldMask`:return(e,t)=>Kke(e,t);case`google.protobuf.Struct`:return(e,t,n)=>qke(e,t,n);case`google.protobuf.Value`:return(e,t,n)=>ZI(e,t,n);case`google.protobuf.ListValue`:return(e,t,n)=>Jke(e,t,n);default:if(RP(e)){let t=e.fields[0],n=t.localName,r=t.scalar,i=t.longAsString,a=Rke(t);return(e,t)=>{t===null?e[n]=AP(r,i):e[n]=a(t)}}return}}function Ake(e){switch(e.fieldKind){case`scalar`:return jke(e);case`enum`:return Nke(e);case`message`:return Pke(e);case`list`:return Fke(e);case`map`:return Lke(e)}}function jke(e){let t=Rke(e),n=e.localName;if(e.oneof){let r=e.oneof.localName;return(e,i)=>{e[r]={case:n,value:t(i)}}}let r=Mke(e);return(e,i)=>{i===null?r(e):e[n]=t(i)}}function Mke(e){let t=e.localName;if(e.presence!=2)return e=>{delete e[t]};if(e.fieldKind==`enum`){let n=e.enum.values[0].number;return e=>{e[t]=n}}let n=e.scalar,r=e.longAsString;return e=>{e[t]=AP(n,r)}}function Nke(e){let t=qI(e.enum),n=JI(e.enum),r=e.localName,i=e.enum.typeName!=`google.protobuf.NullValue`;if(e.oneof){let a=e.oneof.localName;return(o,s,c)=>{if(s===null&&i){o[a].case===r&&(o[a]={case:void 0});return}let l=t(s,c.ignoreUnknownFields);if(l===KI)return;let u=n(l);if(u!==!0)throw new KP(e,cF(e,l,u));o[a]={case:r,value:l}}}let a=Mke(e);return(o,s,c)=>{if(s===null&&i){a(o);return}let l=t(s,c.ignoreUnknownFields);if(l===KI)return;let u=n(l);if(u!==!0)throw new KP(e,cF(e,l,u));o[r]=l}}function Pke(e){let t=e.localName,{toMessage:n,toLocal:r}=pF(e),i=GI(e.message),a=e.message.typeName!=`google.protobuf.Value`;if(e.oneof){let o=e.oneof.localName;return(e,s,c)=>{let l=e[o];if(s===null&&a){l.case===t&&(e[o]={case:void 0});return}let u=n(l.case===t?l.value:void 0);i(u,s,c),e[o]={case:t,value:r(u)}}}return(e,o,s)=>{if(o===null&&a){delete e[t];return}let c=n(e[t]);i(c,o,s),e[t]=r(c)}}function Fke(e){let t=e.localName,n=Ike(e);return(r,i,a)=>{if(i===null)return;if(!Array.isArray(i))throw new KP(e,`expected Array, got `+lF(i));let o=r[t];for(let e=0;e<i.length;e++){let t=n(i[e],a,o.length);t!==KI&&o.push(t)}}}function Ike(e){switch(e.listKind){case`scalar`:{let t=YI(e),n=sF(e.scalar),r=XI(e);return(i,a,o)=>{if(i===null)throw new KP(e,`list item must not be null`);let s=t(i),c=n(s);if(c!==!0)throw new KP(e,`list item #${o+1}: ${cF(e,s,c)}`);return r(s)}}case`enum`:{let t=qI(e.enum),n=JI(e.enum),r=e.enum.typeName!=`google.protobuf.NullValue`;return(i,a,o)=>{if(i===null&&r)throw new KP(e,`list item must not be null`);let s=t(i,a.ignoreUnknownFields);if(s===KI)return s;let c=n(s);if(c!==!0)throw new KP(e,`list item #${o+1}: ${cF(e,s,c)}`);return s}}case`message`:{let{toMessage:t,toLocal:n}=pF(e),r=GI(e.message),i=e.message.typeName!=`google.protobuf.Value`;return(a,o)=>{if(a===null&&i)throw new KP(e,`list item must not be null`);let s=t(void 0);return r(s,a,o),n(s)}}}}function Lke(e){let t=e.localName,n=e.mapKey,r=zke(n),i=sF(n),a,o,s=e=>e,c=!0;switch(e.mapKind){case`scalar`:a=YI(e),o=sF(e.scalar),s=XI(e);break;case`enum`:{let t=qI(e.enum);a=(e,n)=>t(e,n.ignoreUnknownFields),o=JI(e.enum),c=e.enum.typeName!=`google.protobuf.NullValue`;break}case`message`:{let{toMessage:t,toLocal:n}=pF(e),r=GI(e.message);c=e.message.typeName!=`google.protobuf.Value`,a=(e,i)=>{let a=t(void 0);return r(a,e,i),n(a)};break}}return(l,u,d)=>{if(u===null)return;if(typeof u!=`object`||Array.isArray(u))throw new KP(e,`expected object, got `+lF(u));let f=l[t],p=new Set,m=Object.keys(u);for(let t=0;t<m.length;t++){let l=m[t],h=u[l],g=r(l);if(p.has(g))throw new KP(e,`duplicate map key "${l}"`);if(p.add(g),h===null&&c)throw new KP(e,`map value must not be null`);let _=a(h,d);if(_===KI)continue;let v=i(g);if(v!==!0)throw new KP(e,`invalid map key: ${cF({scalar:n},g,v)}`);if(o!==void 0){let t=o(_);if(t!==!0)throw new KP(e,`map entry ${lF(g)}: ${cF(e,_,t)}`)}NP(f,g,s(_))}}}const KI=Symbol();function qI(e){let t=e.values[0].number,n=new Map;for(let t of e.values)n.set(t.jsonName,t.number);for(let t of e.values)n.set(t.name,t.number);return(r,i)=>{if(r===null)return t;switch(typeof r){case`number`:if(Number.isInteger(r))return r;break;case`string`:{let e=n.get(r);if(e!==void 0)return e;if(i)return KI;break}}throw Error(`cannot decode ${e} from JSON: ${lF(r)}`)}}function JI(e){if(e.open)return sF(V.INT32);let t=e.values;return e=>t.some(t=>t.number===e)}function Rke(e){let t=YI(e),n=sF(e.scalar),r=XI(e);return i=>{let a=t(i),o=n(a);if(o!==!0)throw new KP(e,cF(e,a,o));return r(a)}}function YI(e){switch(e.scalar){case V.DOUBLE:case V.FLOAT:return t=>{if(t===`NaN`)return NaN;if(t===`Infinity`)return 1/0;if(t===`-Infinity`)return-1/0;if(typeof t==`number`){if(Number.isNaN(t))throw new KP(e,`unexpected NaN number`);if(!Number.isFinite(t))throw new KP(e,`unexpected infinite number`);return t}if(typeof t==`string`){if(t===``||t.trim().length!==t.length)return t;let e=Number(t);return Number.isFinite(e)?e:t}return t};case V.INT32:case V.FIXED32:case V.SFIXED32:case V.SINT32:case V.UINT32:return Bke;case V.BYTES:return t=>{if(typeof t==`string`){if(t===``)return new Uint8Array;try{return jF(t)}catch(t){throw new KP(e,t instanceof Error?t.message:String(t))}}return t};default:return e=>e}}function XI(e){let t=e.fieldKind!==`map`&&e.longAsString;switch(e.scalar){case V.INT64:case V.SFIXED64:case V.SINT64:return t?e=>String(e):e=>typeof e==`string`||typeof e==`number`?DP.parse(e):e;case V.FIXED64:case V.UINT64:return t?e=>String(e):e=>typeof e==`string`||typeof e==`number`?DP.uParse(e):e;default:return e=>e}}function zke(e){switch(e){case V.BOOL:return e=>{switch(e){case`true`:return!0;case`false`:return!1}return e};case V.INT32:case V.FIXED32:case V.UINT32:case V.SFIXED32:case V.SINT32:return Bke;case V.INT64:case V.SINT64:case V.SFIXED64:case V.UINT64:case V.FIXED64:return e=>/^-?0+$/.test(e)?`0`:e.replace(/^(-?)0+(?=\d)/,`$1`);default:return e=>e}}function Bke(e){if(typeof e==`string`){if(e===``||e.trim().length!==e.length)return e;let t=Number(e);return Number.isNaN(t)?e:t}return e}function Vke(e,t){let n;try{n=JSON.parse(e)}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`cannot decode message ${t} from JSON: ${n}`,{cause:e})}return Hke(e,t),n}function Hke(e,t){let n=[],r=!1,i=0;for(;i<e.length;)switch(e[i]){case`{`:n.push(new Set),r=!0,i++;break;case`[`:n.push(null),r=!1,i++;break;case`}`:case`]`:n.pop(),r=!1,i++;break;case`,`:r=n[n.length-1]!=null,i++;break;case`:`:r=!1,i++;break;case`"`:{let a=i++,o=!1;for(;i<e.length;){if(e[i]==`\\`){o=!0,i+=2;continue}if(e[i]==`"`)break;i++}let s=i++,c=n[n.length-1];if(r&&c){let n=o?JSON.parse(e.substring(a,s+1)):e.substring(a+1,s);if(c.has(n))throw Error(`cannot decode message ${t} from JSON: duplicate object key "${n}"`);c.add(n)}r=!1;break}default:i++}}function Uke(e,t,n){if(t===null||Array.isArray(t)||typeof t!=`object`)throw Error(`cannot decode message ${e.$typeName} from JSON: expected object but got ${lF(t)}`);if(Object.keys(t).length==0)return;let r=t[`@type`];if(typeof r!=`string`||r==``)throw Error(`cannot decode message ${e.$typeName} from JSON: "@type" is empty`);let i=r.includes(`/`)?r.substring(r.lastIndexOf(`/`)+1):r;if(!i.length)throw Error(`cannot decode message ${e.$typeName} from JSON: "@type" is invalid`);let a=n.registry?.getMessage(i);if(!a)throw Error(`cannot decode message ${e.$typeName} from JSON: ${r} is not in the type registry`);let o=VP(a);if(zP(a)&&Object.prototype.hasOwnProperty.call(t,`value`))GI(a)(o,t.value,n);else{let e={};for(let n of Object.keys(t))n!==`@type`&&NP(e,n,t[n]);GI(a)(o,e,n)}$Oe(a,o,e)}function Wke(e,t){if(typeof t!=`string`)throw Error(`cannot decode message ${e.$typeName} from JSON: ${lF(t)}`);let n=t.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]{1,9}))?(?:Z|([+-][0-9][0-9]:[0-9][0-9]))$/);if(!n)throw Error(`cannot decode message ${e.$typeName} from JSON: invalid RFC 3339 string`);let r=Date.parse(n[1]+`-`+n[2]+`-`+n[3]+`T`+n[4]+`:`+n[5]+`:`+n[6]+(n[8]?n[8]:`Z`));if(Number.isNaN(r))throw Error(`cannot decode message ${e.$typeName} from JSON: invalid RFC 3339 string`);if(r<OI||r>kI)throw Error(`cannot decode message ${e.$typeName} from JSON: must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive`);e.seconds=DP.parse(r/1e3),e.nanos=0,n[7]&&(e.nanos=parseInt(`1`+n[7]+`0`.repeat(9-n[7].length))-1e9)}function Gke(e,t){if(typeof t!=`string`)throw Error(`cannot decode message ${e.$typeName} from JSON: ${lF(t)}`);let n=t.match(/^(-?[0-9]+)(?:\.([0-9]+))?s/);if(n===null)throw Error(`cannot decode message ${e.$typeName} from JSON: ${lF(t)}`);let r=Number(n[1]);if(r>315576e6||r<-315576e6)throw Error(`cannot decode message ${e.$typeName} from JSON: ${lF(t)}`);if(e.seconds=DP.parse(r),typeof n[2]!=`string`)return;let i=n[2]+`0`.repeat(9-n[2].length);e.nanos=parseInt(i),(r<0||Object.is(r,-0))&&(e.nanos=-e.nanos)}function Kke(e,t){if(typeof t!=`string`)throw Error(`cannot decode message ${e.$typeName} from JSON: ${lF(t)}`);t!==``&&(e.paths=t.split(`,`).map(t=>{if(t.includes(`_`))throw Error(`cannot decode message ${e.$typeName} from JSON: path names must be lowerCamelCase`);return zF(t)}))}function qke(e,t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`cannot decode message ${e.$typeName} from JSON ${lF(t)}`);let r=Object.keys(t);for(let i=0;i<r.length;i++){let a=r[i],o=VP(wI);ZI(o,t[a],n),NP(e.fields,a,o)}}function ZI(e,t,n){if(++n.depth>n.recursionLimit)throw Error(`cannot decode ${e.$typeName} from JSON: maximum recursion depth of ${n.recursionLimit} reached`);switch(typeof t){case`number`:e.kind={case:`numberValue`,value:t};break;case`string`:e.kind={case:`stringValue`,value:t};break;case`boolean`:e.kind={case:`boolValue`,value:t};break;case`object`:if(t===null)e.kind={case:`nullValue`,value:TI.NULL_VALUE};else if(Array.isArray(t)){let r=VP(ike);Jke(r,t,n),e.kind={case:`listValue`,value:r}}else{let r=VP(rke);qke(r,t,n),e.kind={case:`structValue`,value:r}}break;default:throw Error(`cannot decode message ${e.$typeName} from JSON ${lF(t)}`)}return n.depth--,e}function Jke(e,t,n){if(!Array.isArray(t))throw Error(`cannot decode message ${e.$typeName} from JSON ${lF(t)}`);for(let r=0;r<t.length;r++){let i=VP(wI);ZI(i,t[r],n),e.values.push(i)}}function QI(e){let t=B[e];return typeof t==`string`?t[0].toLowerCase()+t.substring(1).replace(/[A-Z]/g,e=>`_`+e.toLowerCase()):e.toString()}let $I;function Yke(e){if(!$I){$I={};for(let e of Object.values(B))typeof e!=`string`&&($I[QI(e)]=e)}return $I[e]}var eL=class e extends Error{constructor(e,t=B.Unknown,n,r,i){super(Xke(e,t)),this.name=`ConnectError`,this.isWireError=!1,Object.setPrototypeOf(this,new.target.prototype),this.rawMessage=e,this.code=t,this.metadata=new Headers(n??{}),this.details=r??[],this.cause=i}static from(t,n=B.Unknown){return t instanceof e?t:t instanceof Error?t.name==`AbortError`||t.name==`TimeoutError`?new e(t.message,B.Canceled):new e(t.message,n,void 0,void 0,t):new e(String(t),n,void 0,void 0,t)}static[Symbol.hasInstance](t){return t instanceof Error?Object.getPrototypeOf(t)===e.prototype||t.name===`ConnectError`&&`code`in t&&typeof t.code==`number`&&`metadata`in t&&`details`in t&&Array.isArray(t.details)&&`rawMessage`in t&&typeof t.rawMessage==`string`&&`cause`in t:!1}findDetails(e){let t=e.kind===`message`?{getMessage:t=>t===e.typeName?e:void 0}:e,n=[];for(let e of this.details){if(`desc`in e){t.getMessage(e.desc.typeName)&&n.push(VP(e.desc,e.value));continue}let r=t.getMessage(e.type);if(r)try{n.push(sI(r,e.value))}catch{}}return n}};function Xke(e,t){return e.length?`[${QI(t)}] ${e}`:`[${QI(t)}]`}function Zke(...e){let t=new Headers;for(let n of e)n.forEach((e,n)=>{t.append(n,e)});return t}function Qke(e,t){let n={};for(let r of e.methods){let e=t(r);e!=null&&(n[r.localName]=e)}return n}function $ke(e,t){if(t>e)throw new eL(`message size ${t} is larger than configured writeMaxBytes ${e}`,B.ResourceExhausted)}function tL(e,t,n=!1){if(t>e){let r=`message size is larger than configured readMaxBytes ${e}`;throw n&&(r=`message size ${t} is larger than configured readMaxBytes ${e}`),new eL(r,B.ResourceExhausted)}}function eAe(e){return new tAe(e)}var tAe=class{constructor(e){this.readMaxBytes=e,this.header=new Uint8Array(5),this.headerView=new DataView(this.header.buffer),this.buf=[]}get byteLength(){return this.buf.reduce((e,t)=>e+t.byteLength,0)}decode(e){this.buf.push(e);let t=[];for(;;){let e=this.pop();if(!e)break;t.push(e)}return t}pop(){if(!(!this.env&&(this.env=this.head(),!this.env))&&this.cons(this.env.data)){let e=this.env;return this.env=void 0,e}}head(){if(!this.cons(this.header))return;let e=this.headerView.getUint8(0),t=this.headerView.getUint32(1);return tL(this.readMaxBytes,t,!0),{flags:e,data:new Uint8Array(t)}}cons(e){let t=e.byteLength;if(this.byteLength<t)return!1;let n=0;for(;n<t;){let r=this.buf.shift();r.byteLength>t-n?(e.set(r.subarray(0,t-n),n),this.buf.unshift(r.subarray(t-n)),n+=t-n):(e.set(r,n),n+=r.byteLength)}return!0}};function nAe(e){let t,n=eAe(4294967295);return new ReadableStream({start(){t=e.getReader()},async pull(e){let r=!1;for(;!r;){let i=await t.read();if(i.done)n.byteLength>0&&e.error(new eL(`protocol error: incomplete envelope`,B.InvalidArgument)),e.close();else for(let t of n.decode(i.value))e.enqueue(t),r=!0}}})}async function rAe(e,t,n){let{flags:r,data:i}=e;if((r&1)==1)throw new eL(`invalid envelope, already compressed`,B.Internal);return t&&i.byteLength>=n&&(i=await t.compress(i),r|=1),{data:i,flags:r}}async function iAe(e,t,n){let{flags:r,data:i}=e;if((r&1)==1){if(!t)throw new eL(`received compressed envelope, but do not know how to decompress`,B.Internal);i=await t.decompress(i,n),r^=1}return{data:i,flags:r}}function aAe(e,t){let n=new Uint8Array(t.length+5);n.set(t,5);let r=new DataView(n.buffer,n.byteOffset,n.byteLength);return r.setUint8(0,e),r.setUint32(1,t.length),n}var nL=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},rL=function(e){return this instanceof rL?(this.v=e,this):new rL(e)},iL=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof rL?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}},oAe=function(e){var t={},n;return r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:rL(e[r](t)),done:!1}:i?i(t):t}:i}};function sAe(e,...t){let[n,r,i]=cAe(t),a=e,o;return i?.propagateDownStreamError===!0&&(a=o=yAe(a)),a=aL(a,...n,{propagateDownStreamError:!1}),r(a).catch(e=>o?o.abort(e).then(()=>Promise.reject(e)):Promise.reject(e))}function cAe(e){let t;return typeof e[e.length-1]!=`function`&&(t=e.pop()),[e,e.pop(),t]}function lAe(e,t){return async n=>await _Ae(n,e,t)}function aL(e,...t){return iL(this,arguments,function*(){var n;let[r,i]=uAe(t),a,o=e[Symbol.asyncIterator](),s={[Symbol.asyncIterator](){return o}};i?.propagateDownStreamError===!0&&(s=a=yAe(s));for(let e of r)s=e(s);let c=s[Symbol.asyncIterator]();try{for(;;){let e=yield rL(c.next());if(e.done===!0)break;if(!a){yield yield rL(e.value);continue}try{yield yield rL(e.value)}catch(e){throw yield rL(a.abort(e)),e}}}finally{i?.propagateDownStreamError===!0&&((n=o.return)==null||n.call(o).catch(()=>{}))}})}function uAe(e){let t;return typeof e[e.length-1]!=`function`&&(t=e.pop()),[e,t]}function dAe(e,t,n){return t===void 0||n===void 0?function(t){return iL(this,arguments,function*(){var n,r,i,a;try{for(var o=!0,s=nL(t),c;c=yield rL(s.next()),n=c.done,!n;o=!0){a=c.value,o=!1;let t=a;yield yield rL({flags:0,data:e.serialize(t)})}}catch(e){r={error:e}}finally{try{!o&&!n&&(i=s.return)&&(yield rL(i.call(s)))}finally{if(r)throw r.error}}})}:function(r){return iL(this,arguments,function*(){var i,a,o,s;try{for(var c=!0,l=nL(r),u;u=yield rL(l.next()),i=u.done,!i;c=!0){s=u.value,c=!1;let r=s,i,a=0;r.end?(a|=t,i=n.serialize(r.value)):i=e.serialize(r.value),yield yield rL({flags:a,data:i})}}catch(e){a={error:e}}finally{try{!c&&!i&&(o=l.return)&&(yield rL(o.call(l)))}finally{if(a)throw a.error}}})}}function fAe(e,t,n){return n&&t!==void 0?function(r){return iL(this,arguments,function*(){var i,a,o,s;try{for(var c=!0,l=nL(r),u;u=yield rL(l.next()),i=u.done,!i;c=!0){s=u.value,c=!1;let{flags:r,data:i}=s;(r&t)===t?yield yield rL({value:n.parse(i),end:!0}):yield yield rL({value:e.parse(i),end:!1})}}catch(e){a={error:e}}finally{try{!c&&!i&&(o=l.return)&&(yield rL(o.call(l)))}finally{if(a)throw a.error}}})}:function(r){return iL(this,arguments,function*(){var i,a,o,s;try{for(var c=!0,l=nL(r),u;u=yield rL(l.next()),i=u.done,!i;c=!0){s=u.value,c=!1;let{flags:r,data:i}=s;if(t!==void 0&&(r&t)===t){if(n===null)throw new eL(`unexpected end flag`,B.InvalidArgument);continue}yield yield rL(e.parse(i))}}catch(e){a={error:e}}finally{try{!c&&!i&&(o=l.return)&&(yield rL(o.call(l)))}finally{if(a)throw a.error}}})}}function pAe(e,t){return function(n){return iL(this,arguments,function*(){var r,i,a,o;try{for(var s=!0,c=nL(n),l;l=yield rL(c.next()),r=l.done,!r;s=!0)o=l.value,s=!1,yield yield rL(yield rL(rAe(o,e,t)))}catch(e){i={error:e}}finally{try{!s&&!r&&(a=c.return)&&(yield rL(a.call(c)))}finally{if(i)throw i.error}}})}}function mAe(e,t){return function(n){return iL(this,arguments,function*(){var r,i,a,o;try{for(var s=!0,c=nL(n),l;l=yield rL(c.next()),r=l.done,!r;s=!0)o=l.value,s=!1,yield yield rL(yield rL(iAe(o,e,t)))}catch(e){i={error:e}}finally{try{!s&&!r&&(a=c.return)&&(yield rL(a.call(c)))}finally{if(i)throw i.error}}})}}function hAe(){return function(e){return iL(this,arguments,function*(){var t,n,r,i;try{for(var a=!0,o=nL(e),s;s=yield rL(o.next()),t=s.done,!t;a=!0){i=s.value,a=!1;let{flags:e,data:t}=i;yield yield rL(aAe(e,t))}}catch(e){n={error:e}}finally{try{!a&&!t&&(r=o.return)&&(yield rL(r.call(o)))}finally{if(n)throw n.error}}})}}function gAe(e){return function(t){return iL(this,arguments,function*(){var n,r,i,a;let o=eAe(e);try{for(var s=!0,c=nL(t),l;l=yield rL(c.next()),n=l.done,!n;s=!0){a=l.value,s=!1;let e=a;for(let t of o.decode(e))yield yield rL(t)}}catch(e){r={error:e}}finally{try{!s&&!n&&(i=c.return)&&(yield rL(i.call(c)))}finally{if(r)throw r.error}}if(o.byteLength>0)throw new eL(`protocol error: incomplete envelope`,B.InvalidArgument)})}}async function _Ae(e,t,n){var r,i,a,o,s,c,l,u;let[d,f]=vAe(n);if(d){f>t&&tL(t,f,!0);let n=new Uint8Array(f),s=0;try{for(var p=!0,m=nL(e),h;h=await m.next(),r=h.done,!r;p=!0){o=h.value,p=!1;let e=o;if(s+e.byteLength>f)throw new eL(`protocol error: promised ${f} bytes, received ${s+e.byteLength}`,B.InvalidArgument);n.set(e,s),s+=e.byteLength}}catch(e){i={error:e}}finally{try{!p&&!r&&(a=m.return)&&await a.call(m)}finally{if(i)throw i.error}}if(s<f)throw new eL(`protocol error: promised ${f} bytes, received ${s}`,B.InvalidArgument);return n}let g=[],_=0;try{for(var v=!0,y=nL(e),b;b=await y.next(),s=b.done,!s;v=!0){u=b.value,v=!1;let e=u;_+=e.byteLength,tL(t,_),g.push(e)}}catch(e){c={error:e}}finally{try{!v&&!s&&(l=y.return)&&await l.call(y)}finally{if(c)throw c.error}}let ee=new Uint8Array(_),x=0;for(let e=g.shift();e;e=g.shift())ee.set(e,x),x+=e.byteLength;return ee}function vAe(e){if(e==null)return[!1,0];let t=typeof e==`string`?parseInt(e,10):e;return!Number.isSafeInteger(t)||t<0?[!1,t]:[!0,t]}function yAe(e){let t=e[Symbol.asyncIterator]();if(t.throw===void 0)throw Error(`AsyncIterable does not implement throw`);let n=t,r,i,a={next(){return i=n.next().finally(()=>{i=void 0}),i},throw(e){return n.throw(e)}};t.return!==void 0&&(a=Object.assign(Object.assign({},a),{return(e){return n.return(e)}}));let o=!1;return{abort(e){if(r)return r.state;let t=()=>n.throw(e).then(e=>e.done===!0?`completed`:`caught`,()=>`rethrown`);return i?(r={reason:e,state:i.then(t,t)},r.state):(r={reason:e,state:t()},r.state)},[Symbol.asyncIterator](){if(o)throw Error(`AsyncIterable cannot be re-used`);return o=!0,a}}}function bAe(e){return iL(this,arguments,function*(){yield rL(yield*oAe(nL(e)))})}var xAe=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},oL=function(e){return this instanceof oL?(this.v=e,this):new oL(e)},SAe=function(e){var t={},n;return r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:oL(e[r](t)),done:!1}:i?i(t):t}:i}},CAe=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof oL?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function sL(e,t){return Qke(e,e=>{switch(e.methodKind){case`unary`:return wAe(t,e);case`server_streaming`:return TAe(t,e);case`client_streaming`:return EAe(t,e);case`bidi_streaming`:return DAe(t,e);default:return null}})}function wAe(e,t){return async(n,r)=>{var i,a;let o=await e.unary(t,r?.signal,r?.timeoutMs,r?.headers,n,r?.contextValues);return(i=r?.onHeader)==null||i.call(r,o.header),(a=r?.onTrailer)==null||a.call(r,o.trailer),o.message}}function TAe(e,t){return(n,r)=>cL(e.stream(t,r?.signal,r?.timeoutMs,r?.headers,bAe([n]),r?.contextValues),r)}function EAe(e,t){return async(n,r)=>{var i,a,o,s,c,l;let u=await e.stream(t,r?.signal,r?.timeoutMs,r?.headers,n,r?.contextValues);(c=r?.onHeader)==null||c.call(r,u.header);let d,f=0;try{for(var p=!0,m=xAe(u.message),h;h=await m.next(),i=h.done,!i;p=!0)s=h.value,p=!1,d=s,f++}catch(e){a={error:e}}finally{try{!p&&!i&&(o=m.return)&&await o.call(m)}finally{if(a)throw a.error}}if(!d)throw new eL(`protocol error: missing response message`,B.Unimplemented);if(f>1)throw new eL(`protocol error: received extra messages for client streaming method`,B.Unimplemented);return(l=r?.onTrailer)==null||l.call(r,u.trailer),d}}function DAe(e,t){return(n,r)=>cL(e.stream(t,r?.signal,r?.timeoutMs,r?.headers,n,r?.contextValues),r)}function cL(e,t){return(function(){return CAe(this,arguments,function*(){var n,r;let i=yield oL(e);(n=t?.onHeader)==null||n.call(t,i.header),yield oL(yield*SAe(xAe(i.message))),(r=t?.onTrailer)==null||r.call(t,i.trailer)})})()}function OAe(...e){let t=new AbortController,n=e.filter(e=>e!==void 0).concat(t.signal);for(let e of n){if(e.aborted){r.apply(e);break}e.addEventListener(`abort`,r)}function r(){t.signal.aborted||t.abort(lL(this));for(let e of n)e.removeEventListener(`abort`,r)}return t}function kAe(e){let t=new AbortController,n=()=>{t.abort(new eL(`the operation timed out`,B.DeadlineExceeded))},r;return e!==void 0&&(e<=0?n():r=setTimeout(n,e)),{signal:t.signal,cleanup:()=>clearTimeout(r)}}function lL(e){if(!e.aborted)return;if(e.reason!==void 0)return e.reason;let t=Error(`This operation was aborted`);return t.name=`AbortError`,t}function uL(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,t){return this[e.id]=t,this},delete(e){return delete this[e.id],this}}}function dL(e,t,...n){if(n.length>0)throw Error();return e.services[t]}const fL=`Content-Type`,pL=`Content-Length`,mL=`Content-Encoding`,hL=`Connect-Content-Encoding`,gL=`Accept-Encoding`,_L=`Connect-Accept-Encoding`,vL=`Connect-Timeout-Ms`,yL=`Connect-Protocol-Version`,bL=`User-Agent`,AAe=new Set([fL,pL,mL,`Host`,bL,`Trailer`,`Date`,gL,`Trailer-`,hL,_L,vL,yL,`Grpc-Encoding`,`Grpc-Accept-Encoding`,`Grpc-Timeout`,`Grpc-Status`,`Grpc-Message`,`Grpc-Status-Details-Bin`].map(e=>e.toLowerCase()));function jAe(e,t){t.forEach((t,n)=>{AAe.has(n.toLowerCase())||e.append(n,t)})}function xL(e,t){return e.toString().replace(/\/?$/,`/${t.parent.typeName}/${t.name}`)}function SL(e,t){return VP(e,t)}function MAe(e,t){function n(t){return t.done===!0?t:{done:t.done,value:SL(e,t.value)}}return{[Symbol.asyncIterator](){let e=t[Symbol.asyncIterator](),r={next:()=>e.next().then(n)};return e.throw!==void 0&&(r.throw=t=>e.throw(t).then(n)),e.return!==void 0&&(r.return=t=>e.return(t).then(n)),r}}}function CL(e,t){if(!t)return e;for(let n of t.concat().reverse())e=n(e);return e}function wL(e){let t=Object.assign({},e);return t.ignoreUnknownFields??=!0,t}function TL(e,t,n,r){let i=DL(OL(e.input,t),r),a=DL(kL(e.input,n),r),o=DL(OL(e.output,t),r),s=DL(kL(e.output,n),r);return{getI(e){return e?i:a},getO(e){return e?o:s}}}function EL(e,t,n,r){let i=t?OL(e.input,r):kL(e.input,n);return{parse:(t?OL(e.output,r):kL(e.output,n)).parse,serialize:i.serialize}}function DL(e,t){return{serialize(n){let r=e.serialize(n);return $ke(t.writeMaxBytes,r.byteLength),r},parse(n){return tL(t.readMaxBytes,n.byteLength,!0),e.parse(n)}}}function OL(e,t){return{parse(n){try{return sI(e,n,t)}catch(e){throw new eL(`parse binary: ${e instanceof Error?e.message:String(e)}`,B.Internal)}},serialize(n){try{return hI(e,n,t)}catch(e){throw new eL(`serialize binary: ${e instanceof Error?e.message:String(e)}`,B.Internal)}}}}function kL(e,t){let n=t?.textEncoder??new TextEncoder,r=t?.textDecoder??new TextDecoder,i=wL(t);return{parse(t){try{return Tke(e,r.decode(t),i)}catch(e){throw eL.from(e,B.InvalidArgument)}},serialize(t){try{let r=lke(e,t,i);return n.encode(r)}catch(e){throw eL.from(e,B.Internal)}}}}const NAe=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i;function PAe(e){let t=e?.match(NAe);if(t)return{stream:!!t[1],binary:!!t[3]}}var FAe=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};function AL(e,t,n){if(t&&new Headers(t).forEach((e,t)=>n.metadata.append(t,e)),typeof e!=`object`||!e||Array.isArray(e))throw n;let r=n.code;`code`in e&&typeof e.code==`string`&&(r=Yke(e.code)??r);let i=e.message;if(i!=null&&typeof i!=`string`)throw n;let a=new eL(i??``,r,t);if(a.isWireError=!0,`details`in e&&Array.isArray(e.details))for(let t of e.details){if(typeof t!=`object`||!t||Array.isArray(t)||typeof t.type!=`string`||typeof t.value!=`string`)throw n;try{a.details.push({type:t.type,value:jF(t.value),debug:t.debug})}catch{throw n}}return a}function IAe(e,t,n){let r;try{r=JSON.parse(new TextDecoder().decode(e))}catch{throw n}return AL(r,t,n)}function LAe(e,t){let n={code:QI(e.code)};return e.rawMessage.length>0&&(n.message=e.rawMessage),e.details.length>0&&(n.details=e.details.map(e=>{if(`desc`in e){let n=VP(e.desc,e.value),r={type:e.desc.typeName,value:hI(e.desc,n)};try{r.debug=jI(e.desc,n,t)}catch{}return r}return e}).map(e=>{var{value:t}=e,n=FAe(e,[`value`]);return Object.assign(Object.assign({},n),{value:NF(t,`std_raw`)})})),n}function jL(e){let t=new eL(`invalid end stream`,B.Unknown),n;try{n=JSON.parse(typeof e==`string`?e:new TextDecoder().decode(e))}catch{throw t}if(typeof n!=`object`||!n||Array.isArray(n))throw t;let r=new Headers;if(`metadata`in n){if(typeof n.metadata!=`object`||n.metadata==null||Array.isArray(n.metadata))throw t;for(let[e,i]of Object.entries(n.metadata)){if(!Array.isArray(i)||i.some(e=>typeof e!=`string`))throw t;for(let t of i)r.append(e,t)}}return{metadata:r,error:`error`in n&&n.error!=null?AL(n.error,r,t):void 0}}function RAe(e,t,n){let r={};t!==void 0&&(r.error=LAe(t,n),t.isWireError||jAe(e,t.metadata));let i=!1,a={};return e.forEach((e,t)=>{i=!0,a[t]=[e]}),i&&(r.metadata=a),r}function zAe(e){let t=new TextEncoder;return{serialize(n){try{let r=RAe(n.metadata,n.error,e),i=JSON.stringify(r);return t.encode(i)}catch(e){throw new eL(`failed to serialize EndStreamResponse: ${e instanceof Error?e.message:String(e)}`,B.Internal)}},parse(e){try{return jL(e)}catch(e){throw new eL(`failed to parse EndStreamResponse: ${e instanceof Error?e.message:String(e)}`,B.InvalidArgument)}}}}function BAe(e){switch(e){case 400:return B.Internal;case 401:return B.Unauthenticated;case 403:return B.PermissionDenied;case 404:return B.Unimplemented;case 429:return B.Unavailable;case 502:return B.Unavailable;case 503:return B.Unavailable;case 504:return B.Unavailable;default:return B.Unknown}}function ML(e){let t=new Headers,n=new Headers;return e.forEach((e,r)=>{r.toLowerCase().startsWith(`trailer-`)?n.append(r.substring(8),e):t.append(r,e)}),[t,n]}function NL(e,t,n,r,i){let a=new Headers(r??{});return n!==void 0&&a.set(vL,`${n}`),a.set(fL,e==`unary`?t?`application/proto`:`application/json`:t?`application/connect+proto`:`application/connect+json`),a.set(yL,`1`),!a.has(`User-Agent`)&&i&&a.set(bL,`connect-es/2.3.0`),a}function PL(e,t,n,r,i,a,o){let s=NL(e,t,n,r,o);if(a!=null){let t=e==`unary`?mL:hL;s.set(t,a.name)}if(i.length>0){let t=e==`unary`?gL:_L;s.set(t,i.map(e=>e.name).join(`,`))}return s}function FL(e,t,n,r){let i=r.get(fL),a=PAe(i);if(n!==200){let t=new eL(`HTTP ${n}`,BAe(n),r);if(e==`unary`&&a&&!a.binary)return{isUnaryError:!0,unaryError:t};throw t}let o={binary:t,stream:e!==`unary`};if(a?.binary!==o.binary||a.stream!==o.stream)throw new eL(`unsupported content type ${i}`,a===void 0?B.Unknown:B.Internal,r);return{isUnaryError:!1}}function IL(e,t,n,r,i){let a,o=i.get(e==`unary`?mL:hL);if(o!=null&&o.toLowerCase()!==`identity`&&(a=t.find(e=>e.name===o),!a))throw new eL(`unsupported response encoding "${o}"`,B.Internal,i);return Object.assign({compression:a},FL(e,n,r,i))}function VAe(e,t){return t?NF(e,`url`):encodeURIComponent(new TextDecoder().decode(e))}function LL(e,t,n){let r=`?connect=v1`,i=``,a=e.header.get(mL);a!==null&&a!==`identity`&&(i=`&compression=`+encodeURIComponent(a),n=!0),n&&(r+=`&base64=1`),r+=i;let o=e.header.get(fL);o?.indexOf(`application/`)===0&&(r+=`&encoding=`+encodeURIComponent(o.slice(12))),r+=`&message=`+VAe(t,n);let s=e.url+r,c=new Headers(e.header);for(let e of[yL,fL,pL,mL,gL])c.delete(e);return Object.assign(Object.assign({},e),{requestMethod:`GET`,url:s,header:c})}function RL(e){let t=CL(e.next,e.interceptors),[n,r,i]=BL(e);return t(Object.assign(Object.assign({},e.req),{message:SL(e.req.method.input,e.req.message),signal:n})).then(e=>(i(),e),r)}function zL(e){let[t,n,r]=BL(e),i=!1,a=new Promise(e=>{t.aborted?e():t.addEventListener(`abort`,()=>e())});return a.then(()=>{var n,r;let a=e.req.message[Symbol.asyncIterator]();if(!i){let e=eL.from(lL(t),B.Canceled);(n=a.throw)==null||n.call(a,e).catch(()=>{})}(r=a.return)==null||r.call(a).catch(()=>{})}),CL(async r=>{let o=await e.next(r),s=o.message[Symbol.asyncIterator]();return a.then(()=>s.return?.call(s).catch(()=>{})),Object.assign(Object.assign({},o),{message:{[Symbol.asyncIterator]:()=>({next:async()=>{let e=t.aborted?void 0:await Promise.race([s.next(),a]);return e===void 0?i?{done:!0,value:void 0}:n(lL(t)):e}})}})},e.interceptors)(Object.assign(Object.assign({},e.req),{message:MAe(e.req.method.input,e.req.message),signal:t})).then(e=>{let o=e.message[Symbol.asyncIterator](),s=a.then(async()=>{try{for(;(await o.next()).done!==!0;);}catch{}});return Object.assign(Object.assign({},e),{message:{[Symbol.asyncIterator]:()=>({async next(){if(t.aborted)return await s,i?{done:!0,value:void 0}:n(lL(t));try{let e=await o.next();return e.done===!0&&(i=!0,r()),e}catch(e){return n(e)}},async return(e){return t.aborted||(i=!0,r()),await s,{done:!0,value:e}},async throw(e){if(i)throw eL.from(e);try{return await n(e)}finally{await s}}})}})},n)}function BL(e){let{signal:t,cleanup:n}=kAe(e.timeoutMs),r=OAe(e.signal,t);return[r.signal,function(e){let t=r.signal.aborted?eL.from(lL(r.signal),B.Canceled):eL.from(e);return r.abort(t),n(),Promise.reject(t)},function(){n(),r.abort()}]}var HAe=function(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values==`function`?__values(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}},VL=function(e){return this instanceof VL?(this.v=e,this):new VL(e)},UAe=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof VL?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};function WAe(e){return{async unary(t,n,r,i,a,o){let s=TL(t,e.binaryOptions,e.jsonOptions,e);return r=r===void 0?e.defaultTimeoutMs:r<=0?void 0:r,await RL({interceptors:e.interceptors,signal:n,timeoutMs:r,req:{stream:!1,service:t.parent,method:t,requestMethod:`POST`,url:xL(e.baseUrl,t),header:PL(t.methodKind,e.useBinaryFormat,r,i,e.acceptCompression,e.sendCompression,!0),contextValues:o??uL(),message:a},next:async n=>{let r=s.getI(e.useBinaryFormat).serialize(n.message);e.sendCompression&&r.byteLength>e.compressMinBytes?(r=await e.sendCompression.compress(r),n.header.set(mL,e.sendCompression.name)):n.header.delete(mL);let i=e.useHttpGet===!0&&t.idempotency===aI.NO_SIDE_EFFECTS,a;i?n=LL(n,r,e.useBinaryFormat):a=bAe([r]);let o=await e.httpClient({url:n.url,method:n.requestMethod,header:n.header,signal:n.signal,body:a}),{compression:c,isUnaryError:l,unaryError:u}=IL(t.methodKind,e.acceptCompression,e.useBinaryFormat,o.status,o.header),[d,f]=ML(o.header),p=await sAe(o.body,lAe(e.readMaxBytes,o.header.get(pL)),{propagateDownStreamError:!1});if(c&&(p=await c.decompress(p,e.readMaxBytes)),l)throw IAe(p,Zke(d,f),u);return{stream:!1,service:t.parent,method:t,header:d,message:s.getO(e.useBinaryFormat).parse(p),trailer:f}}})},async stream(t,n,r,i,a,o){let s=TL(t,e.binaryOptions,e.jsonOptions,e),c=zAe(e.jsonOptions);return r=r===void 0?e.defaultTimeoutMs:r<=0?void 0:r,zL({interceptors:e.interceptors,signal:n,timeoutMs:r,req:{stream:!0,service:t.parent,method:t,requestMethod:`POST`,url:xL(e.baseUrl,t),header:PL(t.methodKind,e.useBinaryFormat,r,i,e.acceptCompression,e.sendCompression,!0),contextValues:o??uL(),message:a},next:async n=>{let r=await e.httpClient({url:n.url,method:`POST`,header:n.header,signal:n.signal,body:aL(n.message,dAe(s.getI(e.useBinaryFormat)),pAe(e.sendCompression,e.compressMinBytes),hAe(),{propagateDownStreamError:!0})}),{compression:i}=IL(t.methodKind,e.acceptCompression,e.useBinaryFormat,r.status,r.header),a=Object.assign(Object.assign({},n),{header:r.header,trailer:new Headers,message:aL(r.body,gAe(e.readMaxBytes),mAe(i??null,e.readMaxBytes),fAe(s.getO(e.useBinaryFormat),2,c),function(e){return UAe(this,arguments,function*(){var t,n,i,o;let s=!1;try{for(var c=!0,l=HAe(e),u;u=yield VL(l.next()),t=u.done,!t;c=!0){o=u.value,c=!1;let e=o;if(e.end){if(s)throw new eL(`protocol error: received extra EndStreamResponse`,B.InvalidArgument);if(s=!0,e.value.error){let t=e.value.error;throw r.header.forEach((e,n)=>{t.metadata.append(n,e)}),t}e.value.metadata.forEach((e,t)=>a.trailer.set(t,e));continue}if(s)throw new eL(`protocol error: received extra message after EndStreamResponse`,B.InvalidArgument);yield yield VL(e.value)}}catch(e){n={error:e}}finally{try{!c&&!t&&(i=l.return)&&(yield VL(i.call(l)))}finally{if(n)throw n.error}}if(!s)throw new eL(`protocol error: missing EndStreamResponse`,B.InvalidArgument)})},{propagateDownStreamError:!0})});return a}})}}}function GAe(){try{new Headers}catch{throw Error(`connect-web requires the fetch API. Are you running on an old version of Node.js?`)}}var HL=function(e){return this instanceof HL?(this.v=e,this):new HL(e)},KAe=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof HL?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}};const UL={redirect:`error`};function qAe(e){GAe();let t=e.useBinaryFormat??!1;return{async unary(n,r,i,a,o,s){let{serialize:c,parse:l}=EL(n,t,e.jsonOptions,e.binaryOptions);return i=i===void 0?e.defaultTimeoutMs:i<=0?void 0:i,await RL({interceptors:e.interceptors,signal:r,timeoutMs:i,req:{stream:!1,service:n.parent,method:n,requestMethod:`POST`,url:xL(e.baseUrl,n),header:NL(n.methodKind,t,i,a,!1),contextValues:s??uL(),message:o},next:async r=>{let i=e.useHttpGet===!0&&n.idempotency===aI.NO_SIDE_EFFECTS,a=null;i?r=LL(r,c(r.message),t):a=c(r.message);let o=await(e.fetch??globalThis.fetch)(r.url,Object.assign(Object.assign({},UL),{method:r.requestMethod,headers:r.header,signal:r.signal,body:a})),{isUnaryError:s,unaryError:u}=FL(n.methodKind,t,o.status,o.headers);if(s)throw AL(await o.json(),Zke(...ML(o.headers)),u);let[d,f]=ML(o.headers);return{stream:!1,service:n.parent,method:n,header:d,message:t?l(new Uint8Array(await o.arrayBuffer())):Eke(n.output,await o.json(),wL(e.jsonOptions)),trailer:f}}})},async stream(n,r,i,a,o,s){let{serialize:c,parse:l}=EL(n,t,e.jsonOptions,e.binaryOptions);function u(e,t,n,r){return KAe(this,arguments,function*(){let r=nAe(e).getReader(),i=!1;for(;;){let e=yield HL(r.read());if(e.done)break;let{flags:a,data:o}=e.value;if((a&1)==1)throw new eL(`protocol error: received unsupported compressed output`,B.Internal);if((a&2)==2){i=!0;let e=jL(o);if(e.error){let t=e.error;throw n.forEach((e,n)=>{t.metadata.append(n,e)}),t}e.metadata.forEach((e,n)=>t.set(n,e));continue}yield yield HL(l(o))}if(!i)throw`missing EndStreamResponse`})}async function d(e){if(n.methodKind!=`server_streaming`)throw`The fetch API does not support streaming request bodies`;let t=await e[Symbol.asyncIterator]().next();if(t.done==1)throw`missing request message`;return aAe(0,c(t.value))}return i=i===void 0?e.defaultTimeoutMs:i<=0?void 0:i,await zL({interceptors:e.interceptors,timeoutMs:i,signal:r,req:{stream:!0,service:n.parent,method:n,requestMethod:`POST`,url:xL(e.baseUrl,n),header:NL(n.methodKind,t,i,a,!1),contextValues:s??uL(),message:o},next:async r=>{let i=await(e.fetch??globalThis.fetch)(r.url,Object.assign(Object.assign({},UL),{method:r.requestMethod,headers:r.header,signal:r.signal,body:await d(r.message)}));if(FL(n.methodKind,t,i.status,i.headers),i.body===null)throw`missing response body`;let a=new Headers;return Object.assign(Object.assign({},r),{header:i.headers,trailer:a,message:u(i.body,a,i.headers,r.signal)})}})}}}var WL=dee(eDe(),1);const GL=(e=0)=>t=>`\u001B[${t+e}m`,KL=(e=0)=>t=>`\u001B[${38+e};5;${t}m`,qL=(e=0)=>(t,n,r)=>`\u001B[${38+e};2;${t};${n};${r}m`,JL={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(JL.modifier);const JAe=Object.keys(JL.color),YAe=Object.keys(JL.bgColor);[...JAe,...YAe];function XAe(){let e=new Map;for(let[t,n]of Object.entries(JL)){for(let[t,r]of Object.entries(n))JL[t]={open:`\u001B[${r[0]}m`,close:`\u001B[${r[1]}m`},n[t]=JL[t],e.set(r[0],r[1]);Object.defineProperty(JL,t,{value:n,enumerable:!1})}return Object.defineProperty(JL,"codes",{value:e,enumerable:!1}),JL.color.close=`\x1B[39m`,JL.bgColor.close=`\x1B[49m`,JL.color.ansi=GL(),JL.color.ansi256=KL(),JL.color.ansi16m=qL(),JL.bgColor.ansi=GL(10),JL.bgColor.ansi256=KL(10),JL.bgColor.ansi16m=qL(10),Object.defineProperties(JL,{rgbToAnsi256:{value(e,t,n){return e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=Number.parseInt(n,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:e=>JL.rgbToAnsi256(...JL.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,r;if(e>=232)t=((e-232)*10+8)/255,n=t,r=t;else{e-=16;let i=e%36;t=Math.floor(e/36)/5,n=Math.floor(i/6)/5,r=i%6/5}let i=Math.max(t,n,r)*2;if(i===0)return 30;let a=30+(Math.round(r)<<2|Math.round(n)<<1|Math.round(t));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>JL.ansi256ToAnsi(JL.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>JL.ansi256ToAnsi(JL.hexToAnsi256(e)),enumerable:!1}}),JL}const YL=XAe();function XL(e,t=globalThis.Deno?globalThis.Deno.args:we.argv){let n=e.startsWith(`-`)?``:e.length===1?`-`:`--`,r=t.indexOf(n+e),i=t.indexOf(`--`);return r!==-1&&(i===-1||r<i)}const{env:ZL}=we;let QL;XL(`no-color`)||XL(`no-colors`)||XL(`color=false`)||XL(`color=never`)?QL=0:(XL(`color`)||XL(`colors`)||XL(`color=true`)||XL(`color=always`))&&(QL=1);function ZAe(){if(`FORCE_COLOR`in ZL)return ZL.FORCE_COLOR===`true`?1:ZL.FORCE_COLOR===`false`?0:ZL.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(ZL.FORCE_COLOR,10),3)}function QAe(e){return e!==0&&{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function $Ae(e,{streamIsTTY:t,sniffFlags:r=!0}={}){let i=ZAe();i!==void 0&&(QL=i);let a=r?QL:i;if(a===0)return 0;if(r){if(XL(`color=16m`)||XL(`color=full`)||XL(`color=truecolor`))return 3;if(XL(`color=256`))return 2}if(`TF_BUILD`in ZL&&`AGENT_NAME`in ZL)return 1;if(e&&!t&&a===void 0)return 0;let o=a||0;if(ZL.TERM===`dumb`)return o;if(we.platform===`win32`){let e=n.release().split(`.`);return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if(`CI`in ZL)return[`GITHUB_ACTIONS`,`GITEA_ACTIONS`,`CIRCLECI`].some(e=>e in ZL)?3:[`TRAVIS`,`APPVEYOR`,`GITLAB_CI`,`BUILDKITE`,`DRONE`].some(e=>e in ZL)||ZL.CI_NAME===`codeship`?1:o;if(`TEAMCITY_VERSION`in ZL)return+!!/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(ZL.TEAMCITY_VERSION);if(ZL.COLORTERM===`truecolor`||ZL.TERM===`xterm-kitty`||ZL.TERM===`xterm-ghostty`||ZL.TERM===`wezterm`)return 3;if(`TERM_PROGRAM`in ZL){let e=Number.parseInt((ZL.TERM_PROGRAM_VERSION||``).split(`.`)[0],10);switch(ZL.TERM_PROGRAM){case`iTerm.app`:return e>=3?3:2;case`Apple_Terminal`:return 2}}return/-256(color)?$/i.test(ZL.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(ZL.TERM)||`COLORTERM`in ZL?1:o}function $L(e,t={}){return QAe($Ae(e,{streamIsTTY:e&&e.isTTY,...t}))}const eje={stdout:$L({isTTY:Te.isatty(1)}),stderr:$L({isTTY:Te.isatty(2)})};function tje(e,t,n){let r=e.indexOf(t);if(r===-1)return e;let i=t.length,a=0,o=``;do o+=e.slice(a,r)+t+n,a=r+i,r=e.indexOf(t,a);while(r!==-1);return o+=e.slice(a),o}function nje(e,t,n,r){let i=0,a=``;do{let o=e[r-1]===`\r`;a+=e.slice(i,o?r-1:r)+t+(o?`\r
454
+ `:`
455
+ `)+n,i=r+1,r=e.indexOf(`
456
+ `,i)}while(r!==-1);return a+=e.slice(i),a}const{stdout:eR,stderr:tR}=eje,nR=Symbol(`GENERATOR`),rR=Symbol(`STYLER`),iR=Symbol(`IS_EMPTY`),aR=[`ansi`,`ansi`,`ansi256`,`ansi16m`],oR=Object.create(null),rje=(e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw Error("The `level` option should be an integer from 0 to 3");let n=eR?eR.level:0;e.level=t.level===void 0?n:t.level},ije=e=>{let t=(...e)=>e.join(` `);return rje(t,e),Object.setPrototypeOf(t,sR.prototype),t};function sR(e){return ije(e)}Object.setPrototypeOf(sR.prototype,Function.prototype);for(let[e,t]of Object.entries(YL))oR[e]={get(){let n=uR(this,lR(t.open,t.close,this[rR]),this[iR]);return Object.defineProperty(this,e,{value:n}),n}};oR.visible={get(){let e=uR(this,this[rR],!0);return Object.defineProperty(this,"visible",{value:e}),e}};const cR=(e,t,n,...r)=>e===`rgb`?t===`ansi16m`?YL[n].ansi16m(...r):t===`ansi256`?YL[n].ansi256(YL.rgbToAnsi256(...r)):YL[n].ansi(YL.rgbToAnsi(...r)):e===`hex`?cR(`rgb`,t,n,...YL.hexToRgb(...r)):YL[n][e](...r);for(let e of[`rgb`,`hex`,`ansi256`]){oR[e]={get(){let{level:t}=this;return function(...n){let r=lR(cR(e,aR[t],`color`,...n),YL.color.close,this[rR]);return uR(this,r,this[iR])}}};let t=`bg`+e[0].toUpperCase()+e.slice(1);oR[t]={get(){let{level:t}=this;return function(...n){let r=lR(cR(e,aR[t],`bgColor`,...n),YL.bgColor.close,this[rR]);return uR(this,r,this[iR])}}}}const aje=Object.defineProperties(()=>{},{...oR,level:{enumerable:!0,get(){return this[nR].level},set(e){this[nR].level=e}}}),lR=(e,t,n)=>{let r,i;return n===void 0?(r=e,i=t):(r=n.openAll+e,i=t+n.closeAll),{open:e,close:t,openAll:r,closeAll:i,parent:n}},uR=(e,t,n)=>{let r=(...e)=>oje(r,e.length===1?``+e[0]:e.join(` `));return Object.setPrototypeOf(r,aje),r[nR]=e,r[rR]=t,r[iR]=n,r},oje=(e,t)=>{if(e.level<=0||!t)return e[iR]?``:t;let n=e[rR];if(n===void 0)return t;let{openAll:r,closeAll:i}=n;if(t.includes(`\x1B`))for(;n!==void 0;)t=tje(t,n.close,n.open),n=n.parent;let a=t.indexOf(`
457
+ `);return a!==-1&&(t=nje(t,i,r,a)),r+t+i};Object.defineProperties(sR.prototype,oR);const dR=sR();sR({level:tR?tR.level:0});function fR(e){"@babel/helpers - typeof";return fR=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},fR(e)}function sje(e,t){if(fR(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(fR(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function cje(e){var t=sje(e,`string`);return fR(t)==`symbol`?t:t+``}function pR(e,t,n){return(t=cje(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function mR(e){return RegExp(`^[\\t\\n\\v\\f\\r \\u0085\\u00a0\\p{Z}]$`,`u`).test(e)}function lje(e){return RegExp(`^\\p{L}$`,`u`).test(e)}function hR(e){return RegExp(`^\\p{Nd}$`,`u`).test(e)}function uje(e){return`@*#?-$!0`.includes(e)}var dje=class{constructor(e){pR(this,`chars`,void 0),pR(this,`pos`,0),this.chars=Array.from(e)}peek(){return this.pos<this.chars.length?this.chars[this.pos]:null}next(){return this.pos<this.chars.length?this.chars[this.pos++]:null}},fje=class{constructor(){pR(this,`words`,[]),pR(this,`buf`,``),pR(this,`inWord`,!1)}addChar(e){mR(e)&&this.inWord?this.buf.length!==0&&(this.words.push(this.buf),this.buf=``,this.inWord=!1):mR(e)||this.addRawChar(e)}addRawChar(e){this.buf+=e,this.inWord=!0}addString(e){for(let t of e)this.addChar(t)}addRawString(e){this.buf+=e,this.inWord=!0}getWords(){return this.buf.length>0&&(this.words.push(this.buf),this.buf=``,this.inWord=!1),this.words}},gR=class{constructor(e,t={}){pR(this,`escapeToken`,void 0),pR(this,`rawQuotes`,void 0),pR(this,`rawEscapes`,void 0),pR(this,`skipProcessQuotes`,void 0),pR(this,`env`,void 0),pR(this,`skipUnsetEnv`,void 0),this.escapeToken=e,this.rawQuotes=t.rawQuotes??!1,this.rawEscapes=t.rawEscapes??!1,this.skipProcessQuotes=t.skipProcessQuotes??!1,this.env=t.env??new Map,this.skipUnsetEnv=t.skipUnsetEnv??!0}processWord(e){return this.process(e).result}processWords(e){return this.process(e).words}process(e){let t=new pje(new dje(e),this.escapeToken,this.rawQuotes,this.rawEscapes,this.skipProcessQuotes,this.env,this.skipUnsetEnv);try{return t.processStopOn(null,this.rawEscapes)}catch(t){let n=t instanceof Error?t.message:String(t);throw Error(`failed to process ${JSON.stringify(e)}: ${n}`)}}},pje=class{constructor(e,t,n,r,i,a,o){this.scanner=e,this.escapeToken=t,this.rawQuotes=n,this.rawEscapes=r,this.skipProcessQuotes=i,this.env=a,this.skipUnsetEnv=o}processStopOn(e,t){let n=``,r=new fje,i=this.rawEscapes;this.rawEscapes=t;try{for(;this.scanner.peek()!==null;){let t=this.scanner.peek();if(e!==null&&t===e)return this.scanner.next(),{result:n,words:r.getWords()};let i=this.specialHandler(t);if(i){let e=i();n+=e,t===`$`?r.addString(e):r.addRawString(e);continue}if(t=this.scanner.next(),t===this.escapeToken){this.rawEscapes&&(r.addRawChar(t),n+=t);let e=this.scanner.next();if(e===null)break;t=e,r.addRawChar(t)}else r.addChar(t);n+=t}}finally{this.rawEscapes=i}if(e!==null)throw Error(`unexpected end of statement while looking for matching ${e}`);return{result:n,words:r.getWords()}}specialHandler(e){switch(e){case`$`:return()=>this.processDollar();case`<`:return()=>this.processPossibleHeredoc();case`'`:return this.skipProcessQuotes?void 0:()=>this.processSingleQuote();case`"`:return this.skipProcessQuotes?void 0:()=>this.processDoubleQuote();default:return}}processSingleQuote(){let e=``,t=this.scanner.next();for(this.rawQuotes&&(e+=t);;){let n=this.scanner.next();if(n===null)throw Error(`unexpected end of statement while looking for matching single-quote`);if(t=n,t===`'`)return this.rawQuotes&&(e+=t),e;e+=t}}processDoubleQuote(){let e=``,t=this.scanner.next();for(this.rawQuotes&&(e+=t);;){let t=this.scanner.peek();if(t===null)throw Error(`unexpected end of statement while looking for matching double-quote`);if(t===`"`){let t=this.scanner.next();return this.rawQuotes&&(e+=t),e}if(t===`$`){e+=this.processDollar();continue}let n=this.scanner.next();if(n===this.escapeToken){this.rawEscapes&&(e+=n);let t=this.scanner.peek();if(t===null)continue;(t===`"`||t===`$`||t===this.escapeToken)&&(n=this.scanner.next())}e+=n}}processDollar(){if(this.scanner.next(),this.scanner.peek()!==`{`){let e=this.processName();if(e===``)return`$`;let t=this.env.get(e);return t===void 0&&this.skipUnsetEnv?`$`+e:t??``}this.scanner.next();let e=this.scanner.peek();if(e===null)throw Error(`syntax error: missing '}'`);if(e===`{`||e===`}`||e===`:`)throw Error(`syntax error: bad substitution`);let t=this.processName(),n=this.scanner.next();if(n===null)throw Error(`syntax error: missing '}'`);let r=n,i=this.env.get(t);if(n===`}`)return i===void 0&&this.skipUnsetEnv?"${"+t+`}`:i??``;let a=!1;if(n===`:`){a=!0;let e=this.scanner.next();if(e===null)throw Error(`syntax error: missing '}'`);n=e,r+=n}if(!a){if(n===`/`)return this.processDollarReplace(t);if(!`+-?#%`.includes(n))throw Error(`unsupported modifier (${r}) in substitution`)}let o=n===`#`||n===`%`;if(a&&o)throw Error(`unsupported modifier (${r}) in substitution`);let s=this.processStopOnOrMissingBrace(`}`,o);if(i===void 0&&this.skipUnsetEnv)return"${"+t+r+s+`}`;let c=i===void 0||a&&i===``;switch(n){case`-`:return c?s:i;case`+`:return c?``:s;case`?`:if(i===void 0)throw Error(`${t}: ${s||`is not allowed to be unset`}`);if(c)throw Error(`${t}: ${s||`is not allowed to be empty`}`);return i;case`#`:case`%`:{let e=s.startsWith(n),t=e?s.slice(1):s;return n===`%`?hje(t,i??``,e):vR(t,i??``,e)}default:throw Error(`unsupported modifier (${r}) in substitution`)}}processDollarReplace(e){let t=`/`;this.scanner.peek()===`/`&&(this.scanner.next(),t=`//`);let n;try{n=this.processStopOn(`/`,!0).result}catch(e){throw this.scanner.peek()===null?Error("syntax error: missing '/' in ${}"):e}let r=this.processStopOnOrMissingBrace(`}`,!0),i=this.env.get(e);if(i===void 0&&this.skipUnsetEnv)return"${"+e+t+n+`/`+r+`}`;let a=_R(n,!0,!1,t===`//`);return(i??``).replace(a,()=>r)}processStopOnOrMissingBrace(e,t){try{return this.processStopOn(e,t).result}catch(e){throw this.scanner.peek()===null?Error(`syntax error: missing '}'`):e}}processName(){let e=``;for(;;){let t=this.scanner.peek();if(t===null)break;if(e.length===0&&hR(t)){let e=``;for(;;){let t=this.scanner.peek();if(t===null||!hR(t))break;e+=this.scanner.next()}return e}if(e.length===0&&uje(t))return this.scanner.next();if(!lje(t)&&!hR(t)&&t!==`_`)break;e+=this.scanner.next()}return e}processPossibleHeredoc(){if(this.scanner.next(),this.scanner.peek()!==`<`)return`<`;this.scanner.next();let e=``;for(;;){let t=this.scanner.peek();if(t!==` `&&t!==`\r`&&t!==` `)break;e+=this.scanner.next()}return`<<`+e}};function _R(e,t,n,r=!1){let i=Array.from(e),a=n?`^`:``,o=t?`.*`:`.*?`;for(let t=0;t<i.length;t++){let n=i[t];if(n===`*`){a+=o;continue}if(n===`?`){a+=`.`;continue}if(n===`\\`){let r=i[t+1];if(r===`}`||r===`/`)continue;if(t++,r!==`*`&&r!==`?`&&r!==`\\`)throw Error(`invalid pattern (${e}) in substitution: invalid escape '\\${r??``}'`);n=r}`[]{}.+()|^$*?\\`.includes(n)&&(a+=`\\`),a+=n}return new RegExp(a,r?`gu`:`u`)}function vR(e,t,n){return t.replace(_R(e,n,!0),``)}function mje(e){let t=Array.from(e),n=[];for(let e=0;e<t.length;e++)t[e]===`\\`&&e+1<t.length?(n.unshift(t[e],t[e+1]),e++):n.unshift(t[e]);return n.join(``)}function yR(e){return Array.from(e).reverse().join(``)}function hje(e,t,n){return yR(vR(mje(e),yR(t),n))}var bR=class extends Error{constructor(e,t){super(t===void 0?`Dockerfile parse error: ${e}`:`Dockerfile parse error on line ${t}: ${e}`),this.line=t,this.name=`DockerfileSyntaxError`}};function xR(e,t){try{return t()}catch(t){throw t instanceof bR?t:new bR(t instanceof Error?t.message:String(t),e)}}const SR=/[\t\v\f\r ]+/,gje=/^#\s*([a-zA-Z][a-zA-Z0-9]*)\s*=\s*(.+?)\s*$/,_je=new Set([`syntax`,`escape`,`check`]),vje=new Set([`ADD`,`COPY`,`RUN`]);function CR(e){let t=e.length;for(;t>0&&(e[t-1]===`
458
+ `||e[t-1]===`\r`);)t--;return e.slice(0,t)}function wR(e){return e.replace(RegExp(`^[\\t\\n\\v\\f\\r \\u0085\\u00a0\\p{Z}]+`,`u`),``)}function TR(e){return wR(e).startsWith(`#`)}function yje(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function bje(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}var xje=class{constructor(){pR(this,`escapeToken`,`\\`),pR(this,`continuation`,this.buildContinuationRegex(`\\`)),pR(this,`done`,!1),pR(this,`seen`,new Set)}possibleParserDirective(e){if(this.done)return!1;let t=gje.exec(e);if(!t)return this.done=!0,!1;let n=t[1].toLowerCase();if(!_je.has(n))return this.done=!0,!1;if(this.seen.has(n))throw Error(`only one ${n} parser directive can be used`);return this.seen.add(n),n===`escape`&&this.setEscapeToken(t[2]),!0}trimContinuation(e){return this.continuation.test(e)?{line:e.replace(this.continuation,`$1`),isEndOfLine:!1}:{line:e,isEndOfLine:!0}}setEscapeToken(e){if(e!=="`"&&e!==`\\`)throw Error(`invalid escape token '${e}' does not match \` or \\`);this.escapeToken=e,this.continuation=this.buildContinuationRegex(e)}buildContinuationRegex(e){let t=yje(e);return RegExp(`([^${t}])${t}[ \\t]*$|^${t}[ \\t]*$`)}};function ER(e){return{args:e===``?[]:[e],json:!1}}function Sje(){return{args:[],json:!1}}function DR(e){return e===``?{args:[],json:!1}:{args:e.split(SR),json:!1}}var OR=class extends Error{},kR=class extends Error{};function AR(e){if(e=wR(e),!e.startsWith(`[`))throw new OR;let t;try{t=JSON.parse(e)}catch{throw new OR}if(!Array.isArray(t))throw new OR;for(let e of t)if(typeof e!=`string`)throw new kR(`Only strings are supported in JSON arrays`);return t}function jR(e){if(e===``)return{args:[],json:!1};try{return{args:AR(e),json:!0}}catch(t){if(t instanceof kR)throw t;return{args:[e],json:!1}}}function Cje(e){let t=Array.from(e),n=0;for(;n<t.length&&!mR(t[n]);)n++;let r=n;for(;r<t.length&&mR(t[r]);)r++;if(n===0)return{args:[],json:!1};let{args:i,json:a}=jR(t.slice(r).join(``));return{args:[t.slice(0,n).join(``),...i],json:a}}function wje(e){try{return{args:AR(e),json:!0}}catch(t){if(t instanceof kR)throw t;return DR(e)}}function MR(e,t){let n=Array.from(e),r=[],i=`spaces`,a=``,o=!1,s=``;for(let e=0;e<=n.length;e++){let c=n[e];if(i===`spaces`){if(e===n.length)break;if(mR(c))continue;i=`word`}if(e===n.length){(o||s.length>0)&&r.push(s);break}if(i===`word`){if(mR(c)){i=`spaces`,(o||s.length>0)&&r.push(s),s=``,o=!1;continue}if((c===`'`||c===`"`)&&(a=c,o=!0,i=`quote`),c===t){if(e+1===n.length)continue;s+=c,e++,s+=n[e];continue}s+=c;continue}if(c===a&&(i=`word`),c===t&&a!==`'`){if(e+1===n.length){i=`word`;continue}s+=c,e++,s+=n[e];continue}s+=c}return r}function NR(e,t){try{return{args:AR(e),json:!0}}catch(n){if(n instanceof kR)throw n;return{args:MR(e,t),json:!1}}}function Tje(e,t){return{args:MR(e,t),json:!1}}function PR(e){return(t,n)=>{let r=MR(t,n);if(r.length===0)return{args:[],json:!1};if(!r[0].includes(`=`)){let n=SR.exec(t);if(!n)throw Error(`${e} must have two arguments`);return{args:[t.slice(0,n.index),t.slice(n.index+n[0].length),``],json:!1}}let i=[];for(let e of r){if(!e.includes(`=`))throw Error(`Syntax error - can't find = in "${e}". Must be of the form: name=value`);let t=e.indexOf(`=`);i.push(e.slice(0,t),e.slice(t+1),`=`)}return{args:i,json:!1}}}const Eje={ADD:NR,ARG:Tje,CMD:jR,COPY:NR,ENTRYPOINT:jR,ENV:PR(`ENV`),EXPOSE:DR,FROM:DR,HEALTHCHECK:Cje,LABEL:PR(`LABEL`),MAINTAINER:ER,ONBUILD:Sje,RUN:jR,SHELL:jR,STOPSIGNAL:ER,USER:ER,VOLUME:wje,WORKDIR:ER};function Dje(e,t){let n=Array.from(e),r=[],i=`spaces`,a=``,o=!1,s=``;for(let e=0;e<=n.length;e++){let c=n[e];if(i===`spaces`){if(e===n.length)break;if(mR(c))continue;if(c!==`-`||e+1===n.length||n[e+1]!==`-`)return{rest:n.slice(e).join(``),flags:r};i=`word`}if(e===n.length){s!==`--`&&(o||s.length>0)&&r.push(s);break}if(i===`word`){if(mR(c)){if(i=`spaces`,s===`--`)return{rest:n.slice(e).join(``),flags:r};(o||s.length>0)&&r.push(s),s=``,o=!1;continue}if(c===`'`||c===`"`){a=c,o=!0,i=`quote`;continue}if(c===t){if(e+1===n.length)continue;e++,s+=n[e];continue}s+=c;continue}if(c===a){i=`word`;continue}if(c===t){if(e+1===n.length){i=`word`;continue}e++,s+=n[e];continue}s+=c}return{rest:``,flags:r}}function Oje(e,t){let n=e.trim(),r=SR.exec(n);if(!r)return{command:n,flags:[],rest:``};let i=n.slice(0,r.index),{rest:a,flags:o}=Dje(n.slice(r.index+r[0].length),t);return{command:i,flags:o,rest:a.trim()}}function kje(e){let t=0;for(;t<e.length&&e[t]>=`0`&&e[t]<=`9`;)t++;if(!e.startsWith(`<<`,t))return;let n=e.slice(0,t);t+=2;let r=e[t]===`-`;for(r&&t++;t<e.length&&`
459
+ \f\r `.includes(e[t]);)t++;let i=e.slice(t);if(!i.includes(`<`))return{fileDescriptor:n,chomp:r,rest:i}}function FR(e){let t=kje(e);if(!t)return;let n=t.fileDescriptor===``?0:parseInt(t.fileDescriptor,10),{chomp:r,rest:i}=t;if(i.length===0)return;let a=new gR(`\\`).processWords(i);if(a.length!==1)return;let o=new gR(`\\`,{rawQuotes:!0}).processWords(i);if(o.length!==a.length)throw Error(`internal lexing of heredoc produced inconsistent results: ${i}`);let s=e=>(e.match(/'/g)??[]).length+(e.match(/"/g)??[]).length,c=s(a[0])===s(o[0]);return{name:a[0],content:``,chomp:r,expand:c,fileDescriptor:n}}function Aje(e){let t;try{t=new gR(`\\`,{rawQuotes:!0,rawEscapes:!0}).processWords(e)}catch{return[]}let n=[];for(let e of t){let t=FR(e);t&&n.push(t)}return n}function IR(e){return e.replace(/^\t+/gm,``)}function jje(e){let t=new xje,n=bje(e.replace(/^\uFEFF/,``)),r=[],i=[],a=0,o=0,s=(e,n)=>{let r=CR(e);return n&&(r=wR(r)),xR(a+1,()=>t.possibleParserDirective(r)),TR(r)?``:r};for(;o<n.length;){let e=n[o++],c=s(e,!0);a++;let l=a,u=t.trimContinuation(c);c=u.line;let d=u.isEndOfLine;if(d&&c.length===0)continue;let f=!1;for(;!d&&o<n.length;){let e=n[o++],r=s(e,!1);if(a++,TR(e))continue;if(wR(CR(e)).length===0){f=!0;continue}let i=t.trimContinuation(r);d=i.isEndOfLine,c+=i.line}f&&i.push({message:`Empty continuation line found in: ${c}`,line:a});let{command:p,flags:m,rest:h}=Oje(c,t.escapeToken),g=p.toUpperCase(),_=Eje[g];if(!_)throw new bR(`unknown instruction: ${p}`,l);let v=xR(l,()=>_(h,t.escapeToken)),y={name:g,original:c,flags:m,args:v.args,json:v.json,heredocs:[],startLine:l,endLine:a};if(vje.has(g)&&!v.json&&c.includes(`<<`)){let e=xR(l,()=>Aje(c));for(let t of e){let e=!1;for(;o<n.length;){let r=n[o++];a++;let i=CR(r);if(t.chomp&&(i=i.replace(/^\t+/,``)),i===t.name){e=!0;break}t.content+=r}if(!e)throw new bR(`unterminated heredoc`,l);y.heredocs.push(t)}y.endLine=a}r.push(y)}return{instructions:r,escapeToken:t.escapeToken,warnings:i}}const Mje=new Set([`.`,`+`,`(`,`)`,`|`,`{`,`}`,`$`,`^`]),Nje=/[*?[\\]/;function Pje(e){return e.replace(/[.*+?^${}()|[\]\\/]/g,`\\$&`)}const Fje=new Set(`dDsSwWfnrtv`),LR={a:`\\x07`,b:`\\x08`},RR={x:2,u:4,U:8},Ije=new Set(`^$\\.*+?()[]{}|/-`);function Lje(e,t){let n=``,r=0;for(;r<e.length;){let i=e[r++];if(i!==`\\`)n+=i;else if(!t||r>=e.length)n+=`\\\\`;else{let t=e[r++];if(Fje.has(t))n+=`\\`+t;else if(t in LR)n+=LR[t];else if(t in RR){let i=RR[t],a=e.slice(r,r+i);if(a.length<i||!/^[0-9a-fA-F]+$/.test(a))throw Error(`incomplete escape \\${t}${a}`);let o=parseInt(a,16);if(o>1114111)throw Error(`bad escape \\${t}${a}`);n+=`\\u{${o.toString(16)}}`,r+=i}else if(/[0-7]/.test(t)){let i=t;for(;i.length<3&&/[0-7]/.test(e[r]??``);)i+=e[r++];let a=parseInt(i,8);if(a>255)throw Error(`octal escape value \\${i} outside of range 0-0o377`);n+=`\\u{${a.toString(16)}}`}else if(/[A-Za-z0-9]/.test(t))throw Error(`bad escape \\${t}`);else n+=Ije.has(t)?`\\`+t:t}}return n}function Rje(e){let t=e.startsWith(`/`),n=[];for(let r of e.split(`/`))if(r!==``&&r!==`.`){if(r===`..`){n.length>0&&n[n.length-1]!==`..`?n.pop():t||n.push(`..`);continue}n.push(r)}let r=(t?`/`:``)+n.join(`/`);return r===``?`.`:r}const zR=`syntax error in pattern`;function BR(e,t,n){let r=e.length;if(t>=r||e[t]===`-`||e[t]===`]`||e[t]===`\\`&&n&&(t++,t>=r)||(t+=e.codePointAt(t)>65535?2:1,t>=r))throw Error(zR);return t}function zje(e,t){let n=e.length,r=0;for(;r<n;){let i=e[r++];if(i===`\\`&&t){if(r>=n)throw Error(zR);r++}else if(i===`[`){e[r]===`^`&&r++;let n=0;for(;!(n>0&&e[r]===`]`);)r=BR(e,r,t),e[r]===`-`&&(r=BR(e,r+1,t)),n++;r++}}}function Bje(e,t){zje(e,t);let n=`^`,r=`exact`,i=e.length,a=0;for(;a<i;){let o=a===0,s=e[a++];if(s===`*`)e[a]===`*`?(a++,e[a]===`/`&&a++,a>=i?(n+=`.*`,r=r===`exact`?`prefix`:`regex`):(n+=`(.*/)?`,r=`regex`),o&&(r=`suffix`)):(n+=`[^/]*`,r=`regex`);else if(s===`?`)n+=`[^/]`,r=`regex`;else if(s===`[`){let o=a;for(e[o]===`^`&&o++;o<i&&e[o]!==`]`;)e[o]===`\\`&&t&&o++,o++;n+=`[`+Lje(e.slice(a,Math.min(o,i)),t)+(o<i?`]`:``),a=o+1,r=`regex`}else s===`]`?(n+=`\\]`,r=`regex`):Mje.has(s)?n+=`\\`+s:s===`\\`&&t?a<i?(n+=Pje(e[a++]),r=`regex`):n+=`\\\\`:n+=s}switch(r){case`exact`:return t=>t===e;case`prefix`:{let t=e.slice(0,-2);return e=>e.startsWith(t)}case`suffix`:{let t=e.slice(2);return e=>e.endsWith(t)||t[0]===`/`&&e===t.slice(1)}case`regex`:{let e=RegExp(n+`$`,`u`);return t=>e.test(t)}}}var Vje=class{constructor(e,t={}){pR(this,`compiled`,[]),pR(this,`backslashIsSeparator`,void 0),pR(this,`patterns`,[]);let n=t.backslashIsSeparator??!1;this.backslashIsSeparator=n;for(let t of e){if(t.startsWith(`#`))continue;let e=t.trim();if(!e)continue;let r=e.startsWith(`!`);if(r&&(e=e.slice(1).trim(),!e))throw Error(`Invalid ignore pattern '${t}': illegal exclusion pattern`);n&&(e=e.replace(/\\/g,`/`)),e=Rje(e),e.length>1&&e.startsWith(`/`)&&(e=e.slice(1));let i;try{i=Bje(e,!n)}catch(e){throw Error(`Invalid ignore pattern '${t}': ${e.message}`)}this.compiled.push({exclusion:r,dirs:e.split(`/`),match:i}),this.patterns.push((r?`!`:``)+e)}}toSlash(e){return this.backslashIsSeparator?e.replace(/\\/g,`/`):e}matches(e){let t=this.toSlash(e).split(`/`),n=[],r=!1;for(let e=1;e<=t.length;e++){let i=t.slice(0,e).join(`/`);r=!1,n=this.compiled.map((e,t)=>{let a=n[t]??!1;if(!a){if(e.exclusion!==r)return!1;a=e.match(i)}return a&&(r=!e.exclusion),a})}return r}mayMatchUnder(e){let t=this.toSlash(e).split(`/`);return this.compiled.some(e=>e.exclusion&&Hje(e,t))}};function Hje(e,t){for(let n=0;n<t.length;n++){if(n>=e.dirs.length)return!1;let r=e.dirs[n];if(r.includes(`**`))return!0;if(!Nje.test(r)&&r!==t[n])return!1}return e.dirs.length>t.length}var VR=`2.63.0`;function HR(e){"@babel/helpers - typeof";return HR=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},HR(e)}function Uje(e,t){if(HR(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(HR(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Wje(e){var t=Uje(e,`string`);return HR(t)==`symbol`?t:t+``}function H(e,t,n){return(t=Wje(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function UR(e){return e.includes(`was not found`)}function WR(e){return e.includes(`port is not open`)}function GR(e){return UR(e)?new QR(`${e}: The sandbox was killed or reached its timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`):WR(e)?new $R(`${e}: The sandbox is running but envd inside it could not be reached (e.g. its network is down). Check the sandbox state with 'Sandbox.getInfo()'.`):new $R(`${e}: The sandbox could not be reached and its state is unknown — it may have been killed or reached its timeout, or the connection to it was lost. Check the sandbox state with 'Sandbox.getInfo()'.`)}var KR=class extends Error{constructor(e){super(e),H(this,`statusCode`,void 0),this.name=`SandboxError`}},qR=class extends KR{constructor(e){super(e),this.name=`TimeoutError`}},JR=class extends KR{constructor(e,t){super(e),this.name=`InvalidArgumentError`,t&&(this.stack=t)}},Gje=class extends KR{constructor(e){super(e),this.name=`NotEnoughSpaceError`}},YR=class extends KR{constructor(e){super(e),this.name=`NotFoundError`}},XR=class extends YR{constructor(e){super(e),this.name=`FileNotFoundError`}},ZR=class extends YR{constructor(e){super(e),this.name=`SandboxNotFoundError`}},QR=class extends qR{constructor(e,t){super(e),this.name=`SandboxNotRunningError`,t?.cause!==void 0&&(this.cause=t.cause)}},$R=class extends qR{constructor(e,t){super(e),this.name=`SandboxUnreachableError`,t?.cause!==void 0&&(this.cause=t.cause)}},ez=class extends Error{constructor(e){super(e),this.name=`AuthenticationError`}},tz=class extends ez{constructor(e){super(e),this.name=`GitAuthError`}},nz=class extends KR{constructor(e){super(e),this.name=`GitUpstreamError`}},rz=class extends KR{constructor(e,t){super(e),this.name=`TemplateError`,t&&(this.stack=t)}},iz=class extends KR{constructor(e){super(e),this.name=`RateLimitError`,this.statusCode=429}},Kje=class extends Error{constructor(e){super(e),H(this,`statusCode`,503),this.name=`ServiceBusyError`}},az=class extends KR{constructor(e){super(e),this.name=`GuestUnresponsiveError`,this.statusCode=409}};H(az,`code`,`sandbox_snapshot_guest_agent_unresponsive`);var oz=class extends Error{constructor(e,t){super(e),this.name=`BuildError`,t&&(this.stack=t)}},sz=class extends oz{constructor(e,t){super(e,t),this.name=`FileUploadError`}};function cz(e){return typeof e==`object`&&!!e}function qje(e){return Object.prototype.toString.call(e).slice(8,-1)}function Jje(e){return e instanceof Request||cz(e)&&typeof e.url==`string`&&typeof e.method==`string`&&typeof e.clone==`function`}function Yje(e){if(e instanceof Blob)return!0;if(!cz(e))return!1;let t=qje(e);return(t===`Blob`||t===`File`)&&typeof e.arrayBuffer==`function`}function lz(e){return e instanceof ReadableStream||cz(e)&&typeof e.getReader==`function`&&typeof e.tee==`function`&&typeof e.cancel==`function`}function uz(e){return cz(e)&&typeof e[Symbol.asyncIterator]==`function`}function Xje(){var e;return globalThis.Bun?{runtime:`bun`,version:globalThis.Bun.version}:globalThis.Deno?{runtime:`deno`,version:globalThis.Deno.version.deno}:typeof EdgeRuntime==`string`?{runtime:`vercel-edge`,version:`unknown`}:globalThis.navigator?.userAgent===`Cloudflare-Workers`?{runtime:`cloudflare-worker`,version:`unknown`}:((e=globalThis.process)==null||(e=e.release)==null?void 0:e.name)===`node`?{runtime:`node`,version:WL.default.version||`unknown`}:typeof window<`u`?{runtime:`browser`,version:WL.default.version||`unknown`}:{runtime:`unknown`,version:`unknown`}}const{runtime:dz,version:Zje}=Xje();async function Qje(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t),r=new Uint8Array(n);return btoa(String.fromCharCode(...r))}function fz(e){return Math.ceil(e/1e3)}async function pz(e){if(dz===`browser`)throw Error(`Browser runtime is not supported for dynamic import`);return await Promise.reject(Error(`impulse-compute loads no package at run time`))}function $je({onlyFirst:e=!1}={}){return RegExp(`(?:\\u001B[\\]PX^_][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]`,e?void 0:`g`)}function eMe(e){return e.replace($je(),``)}function mz(){try{var e;let t=(e=new Blob).stream?.call(e);if(t)return t.constructor}catch{}return ReadableStream}function hz(e){let t=mz();if(e instanceof t)return e;let n=e.getReader();return new t({async pull(e){let{done:t,value:r}=await n.read();if(t){e.close();return}e.enqueue(r)},cancel(e){return n.cancel(e)}})}function gz(e){return e instanceof mz()||Symbol.asyncIterator in e?e:hz(e)}function _z(e){return lz(e)||uz(e)}function tMe(e){if(e instanceof Uint8Array||ArrayBuffer.isView(e)&&Object.prototype.toString.call(e)===`[object Uint8Array]`)return new Uint8Array(e);throw new JR(`AsyncIterable upload data must yield Uint8Array chunks, got ${e===null?`null`:typeof e==`object`?e.constructor?.name??`object`:typeof e}`)}function nMe(e,t){let n=e[Symbol.asyncIterator]();return new(mz())({async pull(e){let{done:r,value:i}=await n.next();if(r){e.close();return}let a;try{a=tMe(i)}catch(e){throw await n.return?.call(n).catch(()=>{}),t(e),e}e.enqueue(a)},async cancel(e){await n.return?.call(n,e)}})}async function vz(e){return e instanceof Blob?e:Yje(e)?new Blob([await e.arrayBuffer()],{type:e.type}):new Blob([e])}const rMe=/[^\w@%+=:,./-]/;function yz(e){return e===``?`''`:rMe.test(e)?`'`+e.replace(/'/g,`'"'"'`)+`'`:e}function iMe(){let e=!1,t=mz(),n=new Request(`https://e2b.invalid`,{body:new t,method:`POST`,get duplex(){return e=!0,`half`}}).headers.has(`Content-Type`);return e&&!n}async function aMe(e,t){if(_z(e)){if(dz===`browser`&&!iMe())throw new JR("This browser can't stream request bodies, and stream data is never buffered. Pass the data as a `Blob` instead, e.g. `await new Response(stream).blob()`.");let n,r=uz(e)&&!lz(e)?nMe(e,e=>{n=e}):t||dz===`browser`?hz(e):gz(e);return{body:t?r.pipeThrough(new CompressionStream(`gzip`)):r,streamed:!0,sourceError:()=>n}}let n=()=>void 0;if(t){let t=(await vz(e)).stream().pipeThrough(new CompressionStream(`gzip`));return dz===`browser`?{body:await new Response(t).blob(),streamed:!1,sourceError:n}:{body:t,streamed:!0,sourceError:n}}return{body:await vz(e),streamed:!1,sourceError:n}}const oMe={browser:typeof window<`u`&&WL.default.name||`unknown`,lang:`js`,lang_version:Zje,package_version:VR,publisher:`e2b`,sdk_runtime:dz,system:WL.default.os?.family||`unknown`};function bz(e){return dz===`deno`?Deno.env.get(e):typeof process>`u`?``:process.env[e]}function sMe(e,t){let n=bz(e);if(!n)return t;let r=Number.parseInt(n,10);if(!Number.isFinite(r))throw Error(`Invalid ${e}=${JSON.stringify(n)}: expected an integer.`);return r}function xz(e,t){let n=sMe(e,t);if(n<1)throw Error(`Invalid ${e}=${n}: expected a positive integer.`);return n}const cMe=new Set([429,502,503,504]),lMe=new Set([`ECONNREFUSED`,`ENOTFOUND`,`EAI_AGAIN`,`EHOSTUNREACH`,`ENETUNREACH`,`ENETDOWN`,`EHOSTDOWN`,`UND_ERR_CONNECT_TIMEOUT`,`ConnectionRefused`]),uMe=new Set([`connect`,`getaddrinfo`]),dMe=/client error \(Connect\)/,fMe=/^(Failed to fetch|Load failed|NetworkError when attempting to fetch resource\.?)$/;function pMe(e){if(!Number.isInteger(e)||e<0)throw new JR(`Invalid retries=${e}: expected a non-negative integer.`);return e}const mMe=/^[a-z0-9-]{1,255}$/;function hMe(e){if(e!==void 0){if(e.length<1||e.length>255)throw new JR(`Invalid idempotencyKey: expected 1-255 characters, got ${e.length}.`);if(!mMe.test(e))throw new JR(`Invalid idempotencyKey: only lowercase letters, digits and hyphens are allowed.`);return e}}function gMe(e){if(!e)return;let t=e.trim();if(!/^\d+$/.test(t))return;let n=Number(t);return Number.isSafeInteger(n)&&n<=2147483?n:void 0}function Sz(e,t=0){if(!(e instanceof Error)||t>4)return!1;let{code:n,syscall:r}=e;return typeof n==`string`&&lMe.has(n)||typeof r==`string`&&uMe.has(r)||dMe.test(e.message)?!0:e instanceof AggregateError?e.errors.some(e=>Sz(e,t+1)):Sz(e.cause,t+1)}function Cz(e){return Sz(e)?!0:e instanceof Error&&fMe.test(e.message)}function _Me(e){return e instanceof DOMException?!1:Sz(e)}function vMe(e,t){return t.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=()=>{clearTimeout(a),r(t.reason)},a=setTimeout(()=>{t.removeEventListener(`abort`,i),n()},e);t.addEventListener(`abort`,i,{once:!0})})}function wz(e,t){let n=Math.min(100*2**e,1e4);return Math.floor(n*(.5+t()*.5))}function yMe(e,t,n){let r=e.headers.get(`Should-Retry`);if(!(r===null?cMe.has(e.status):r.trim().toLowerCase()===`true`))return;let i=gMe(e.headers.get(`Retry-After`));return i===void 0?wz(t,n):i*1e3}function bMe(e,t,n,r={}){let i=r.monotonic??(()=>performance.now()),a=r.sleep??vMe,o=r.random??Math.random;return(async(r,s)=>{if(t===0||lz(s?.body))return e(r,s);let c=r instanceof Request&&s===void 0?r:new Request(r,s),l=i()+(n||6e4);for(let n=0;;n++){var u;let r;try{r=await e(n===t?c:c.clone())}catch(e){if(n===t||c.signal.aborted||!_Me(e))throw e;let r=wz(n,o);if(i()+r>=l)throw e;await a(r,c.signal);continue}if(n===t)return r;let s=yMe(r,n,o);if(s===void 0||i()+s>=l)return r;(u=r.body)==null||u.cancel().catch(()=>{}),await a(s,c.signal)}})}function Tz(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function U(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Tz(Object(n),!0).forEach(function(t){H(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Tz(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}const xMe=[`e2b.app`,`e2b.dev`,`e2b.pro`,`e2b-staging.dev`,`e2b-tango.dev`,`e2b-juliett.dev`,`foxtrot-2.e2b.dev`],Ez=`Keepalive-Ping-Interval`;function SMe(e){let t=`httpVersion`;if(e===void 0&&(t=`E2B_HTTP_VERSION`,e=bz(`E2B_HTTP_VERSION`)||`2`),e!==`1.1`&&e!==`2`)throw new JR(`${t} must be '1.1' or '2', got '${e}'`);return e}function Dz(e,t){let n=e?AbortSignal.timeout(e):void 0;return n&&t?AbortSignal.any([n,t]):n??t}function Oz(e,t){let n=new AbortController,r=()=>kz(n,t?.reason);t&&(t.aborted?kz(n,t.reason):t.addEventListener(`abort`,r,{once:!0}));let i=e?setTimeout(()=>kz(n,new DOMException(`Request handshake timed out after ${e}ms`,`TimeoutError`)),e):void 0,a=()=>{i&&=(clearTimeout(i),void 0)},o=!1;return{controller:n,clearStartTimeout:a,cleanup:()=>{o||(o=!0,t?.removeEventListener(`abort`,r),a(),n.abort())}}}function CMe(e,t,n){let r,i=()=>{r&&=(clearTimeout(r),void 0)};return{arm:()=>{t&&(i(),r=setTimeout(()=>kz(e,new DOMException(`${n} idle for ${t}ms`,`TimeoutError`)),t))},clear:i}}function kz(e,t){e.signal.aborted||(e.__e2bAbortReason=t,e.abort(t))}function wMe(e,{clearStartTimeout:t,cleanup:n,controller:r,idleTimeoutMs:i}){if(t(),!e)return n(),new Blob([]).stream();let a=e.getReader(),o=CMe(r,i,`Stream`),s=!1,c=()=>{s||(s=!0,o.clear(),n())};return new ReadableStream({async pull(e){o.arm();try{let{done:t,value:n}=await a.read();o.clear(),t?(c(),e.close()):e.enqueue(n)}catch(t){c(),e.error(t)}},async cancel(e){try{await a.cancel(e)}finally{c()}}})}var Az=class e{static buildUserAgent(){let t=[`${e.sdkUserAgentPrefix}${VR}`];return e.integration&&t.push(e.integration),t.join(` `)}static applyUserAgent(t){let n=t[`User-Agent`];(n===void 0||n.startsWith(e.sdkUserAgentPrefix))&&(t[`User-Agent`]=e.buildUserAgent())}static setIntegration(t){e.integration=t}constructor(t){H(this,`debug`,void 0),H(this,`domain`,void 0),H(this,`apiUrl`,void 0),H(this,`sandboxUrl`,void 0),H(this,`logger`,void 0),H(this,`requestTimeoutMs`,void 0),H(this,`retries`,void 0),H(this,`apiKey`,void 0),H(this,`validateApiKey`,void 0),H(this,`headers`,void 0),H(this,`proxy`,void 0),H(this,`httpVersion`,void 0),this.apiKey=t?.apiKey||e.apiKey,this.validateApiKey=t?.validateApiKey,this.debug=t?.debug??e.debug,this.domain=t?.domain||e.domain,this.requestTimeoutMs=t?.requestTimeoutMs??6e4,this.retries=pMe(t?.retries??3),this.logger=t?.logger,this.headers=U(U({},t?.headers??{}),t?.apiHeaders??{}),e.applyUserAgent(this.headers),this.proxy=t?.proxy,this.httpVersion=SMe(t?.httpVersion),this.apiUrl=t?.apiUrl||e.apiUrl||(this.debug?`http://localhost:3000`:`https://api.${this.domain}`),this.sandboxUrl=t?.sandboxUrl||e.sandboxUrl}static mergeOpts(e,t){if(!e)return t;let n=U({},e);for(let[e,r]of Object.entries(t??{}))r!==void 0&&Object.defineProperty(n,e,{value:r,enumerable:!0,writable:!0,configurable:!0});return n}static get domain(){return bz(`E2B_DOMAIN`)||`e2b.app`}static get apiUrl(){return bz(`E2B_API_URL`)}static get sandboxUrl(){return bz(`E2B_SANDBOX_URL`)}static get debug(){return(bz(`E2B_DEBUG`)||`false`).toLowerCase()===`true`}static get apiKey(){return bz(`E2B_API_KEY`)}getSignal(e,t){return Dz(e??this.requestTimeoutMs,t)}getSandboxUrl(e,t){if(this.sandboxUrl)return this.sandboxUrl;if(this.debug)return`http://${this.getHost(e,t.envdPort,t.sandboxDomain)}`;let n=t.sandboxDomain??this.domain;return dz!==`browser`&&xMe.includes(n)?`https://sandbox.${n}`:`https://${this.getHost(e,t.envdPort,n)}`}getSandboxDirectUrl(e,t){return this.sandboxUrl?this.sandboxUrl:this.debug?`http://${this.getHost(e,t.envdPort,t.sandboxDomain)}`:`https://${this.getHost(e,t.envdPort,t.sandboxDomain)}`}getHost(e,t,n){return this.debug?`localhost:${t}`:`${t}-${e}.${n??this.domain}`}};H(Az,`envdPort`,49983),H(Az,`integration`,void 0),H(Az,`sdkUserAgentPrefix`,`e2b-js-sdk/`);var jz=class{static resolveOpts(e){return Az.mergeOpts(this.boundOpts,e)}};H(jz,`boundOpts`,void 0);const Mz=`user`,TMe=/NGHTTP2_(ENHANCE_YOUR_CALM|INTERNAL_ERROR)\b/;function EMe(e){if(!(e instanceof Error)||!(e.cause instanceof Error))return!1;let t=e.cause;return t.code===`ERR_HTTP2_STREAM_ERROR`&&TMe.test(t.message)}async function Nz(e=(()=>{var e;return(e=globalThis.process)==null||(e=e.versions)==null?void 0:e.node})()){if(!(!e||yP(e,`22.19.0`)<0))try{return await pz(`undici`)}catch{return}}function Pz(){return((e,t)=>globalThis.fetch(e,t))}function Fz(e,t){if(e!==`node`)return Pz();let n;return(async(e,r)=>{let i=n??=t(),a;try{a=await i}catch(e){throw n===i&&(n=void 0),e}return a(e,r)})}async function Iz(e){let t=await(e.loadUndici??Nz)();if(!t)return Pz();let{Agent:n,ProxyAgent:r,fetch:i}=t,a={allowH2:(e.httpVersion??`2`)===`2`,connections:e.connections},o=()=>e.proxy?new r(U(U({uri:e.proxy},a),{},{proxyTunnel:!0})):new n(a),s=i,c=o();return(async(e,t)=>{let n=DMe(e,t),r=c;try{return await s(n.input,U(U({},n.init),{},{dispatcher:r}))}catch(e){throw r===c&&EMe(e)&&(c=o(),r.close().catch(()=>{})),e}})}function DMe(e,t){if(!Jje(e))return{input:e,init:t};let n=U({body:lz(e.body)?gz(e.body):e.body,cache:e.cache,credentials:e.credentials,headers:e.headers,integrity:e.integrity,keepalive:e.keepalive,method:e.method,mode:e.mode,redirect:e.redirect,referrer:e.referrer,referrerPolicy:e.referrerPolicy,signal:e.signal},t);return n.body&&(n.duplex=`half`),{input:e.url,init:n}}const Lz=new Map;function OMe({proxy:e,httpVersion:t=`2`}={}){let n=`${t}:${e??``}`,r=Lz.get(n);if(r)return r;let i=kMe(dz,{proxy:e,httpVersion:t});return Lz.set(n,i),i}function kMe(e=dz,t={}){return Fz(e,()=>Iz({connections:t.connectionLimit??AMe(),proxy:t.proxy,httpVersion:t.httpVersion,loadUndici:t.loadUndici}))}function AMe(){return xz(`E2B_API_CONNECTIONS`,100)}function Rz(e){var t,n,r,i=2;for(typeof Symbol<`u`&&(n=Symbol.asyncIterator,r=Symbol.iterator);i--;){if(n&&(t=e[n])!=null)return t.call(e);if(r&&(t=e[r])!=null)return new zz(t.call(e));n=`@@asyncIterator`,r=`@@iterator`}throw TypeError(`Object is not async iterable`)}function zz(e){function t(e){if(Object(e)!==e)return Promise.reject(TypeError(e+` is not an object.`));var t=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:t}})}return zz=function(e){this.s=e,this.n=e.next},zz.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return n===void 0?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return n===void 0?Promise.reject(e):t(n.apply(this.s,arguments))}},new zz(e)}function Bz(e,t){this.v=e,this.k=t}function Vz(e){return new Bz(e,0)}function Hz(e){return function(){return new Uz(e.apply(this,arguments))}}function Uz(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Bz;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`?`return`:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(a.done?`return`:`normal`,n)},function(e){r(`throw`,e)})}catch(e){i(`throw`,e)}}function i(e,i){switch(e){case`return`:t.resolve({value:i,done:!0});break;case`throw`:t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Uz.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Uz.prototype.next=function(e){return this._invoke(`next`,e)},Uz.prototype.throw=function(e){return this._invoke(`throw`,e)},Uz.prototype.return=function(e){return this._invoke(`return`,e)};function Wz(e){return JSON.parse(JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t))}function jMe(e){function t(e){return n.apply(this,arguments)}function n(){return n=Hz(function*(t){var n=!1,r=!1,i;try{for(var a=Rz(t),o;n=!(o=yield Vz(a.next())).done;n=!1){let t=o.value;var s;(s=e.debug)==null||s.call(e,`Response stream:`,Wz(t)),yield t}}catch(e){r=!0,i=e}finally{try{n&&a.return!=null&&(yield Vz(a.return()))}finally{if(r)throw i}}}),n.apply(this,arguments)}return n=>async r=>{var i;(i=e.info)==null||i.call(e,`Request: POST ${r.url}`);let a=await n(r);if(a.stream)return U(U({},a),{},{message:t(a.message)});var o;return(o=e.info)==null||o.call(e,`Response:`,Wz(a.message)),a}}function Gz(e){return{async onRequest({request:t}){var n;return(n=e.info)==null||n.call(e,`Request ${t.method} ${t.url}`),t},async onResponse({response:t}){if(t.status>=400){var n;(n=e.error)==null||n.call(e,`Response:`,t.status,t.statusText)}else{var r;(r=e.info)==null||r.call(e,`Response:`,t.status,t.statusText)}return t}}}function Kz(e,t,n=KR,r){if(e===401){let e=`Unauthorized, please check your credentials.`;return new ez(t?`${e} - ${t}`:e)}if(e===429){let e=`Rate limit exceeded, please try again later`;return new iz(t?`${e} - ${t}`:e)}if(e===503){let e=`Service temporarily unavailable, please retry`;return new Kje(t?`${e} - ${t}`:e)}let i=new n(`${e}: ${t}`,r);return i instanceof KR&&(i.statusCode=e),i}function qz(e,t=KR,n){if(e.response.ok)return;let r=e.response.status;return e.error?.error_code===az.code?new az(`${e.error.message}. Resume the sandbox with \`onResume: 'reboot'\`.`):r===401||r===429||r===503?Kz(r,e.error?.message??e.error,t,n):Kz(r,e.error?.message||e.error||e.response.statusText,t,n)}var Jz=class{constructor(e,t={}){if(H(this,`api`,void 0),(t.requireApiKey??!0)&&!e.apiKey)throw new ez("API key is required, please visit the API Keys tab at https://e2b.dev/dashboard?tab=keys to get your API key. You can either set the environment variable `E2B_API_KEY` or you can pass it directly to the sandbox like Sandbox.create({ apiKey: 'e2b_...' })");this.api=cP({baseUrl:e.apiUrl,fetch:bMe(OMe(e),e.retries,e.requestTimeoutMs),headers:U(U(U({},oMe),e.apiKey&&{"X-API-KEY":e.apiKey}),e.headers),querySerializer:{array:{style:`form`,explode:!1}}}),e.logger&&this.api.use(Gz(e.logger))}};async function Yz({path:e,operation:t,user:n,expirationInSeconds:r,envdAccessToken:i}){if(!i)throw Error(`Access token is not set and signature cannot be generated!`);let a=r==null?null:Math.floor(Date.now()/1e3)+r,o;return n??=``,o=a===null?`${e}:${t}:${n}:${i}`:`${e}:${t}:${n}:${i}:${a.toString()}`,{signature:`v1_`+(await Qje(o)).replace(/=+$/,``),expiration:a}}const Xz=new Map,Zz=new Map,Qz=new Map;function $z(e=dz,t={}){return Fz(e,()=>Iz({connections:t.connectionLimit??10,proxy:t.proxy,httpVersion:t.httpVersion,loadUndici:t.loadUndici}))}function eB(e,t){return`${t}:${e??``}`}function MMe({proxy:e,httpVersion:t=`2`}={}){let n=eB(e,t),r=Xz.get(n);if(r)return r;let i=$z(dz,{proxy:e,httpVersion:t});return Xz.set(n,i),i}function NMe({proxy:e,httpVersion:t=`2`}={}){let n=eB(e,t),r=Zz.get(n);if(r)return r;let i=$z(dz,{connectionLimit:PMe(),proxy:e,httpVersion:t});return Zz.set(n,i),i}function PMe(){return xz(`E2B_ENVD_RPC_CONNECTIONS`,200)}function FMe({proxy:e}={}){let t=eB(e,`1.1`),n=Qz.get(t);if(n)return n;let r=$z(dz,{connectionLimit:IMe(),proxy:e,httpVersion:`1.1`});return Qz.set(t,r),r}function IMe(){return xz(`E2B_ENVD_UPLOAD_CONNECTIONS`,50)}const tB=`99.99.99`,nB=`0.5.7`,rB=pI(`ChVwcm9jZXNzL3Byb2Nlc3MucHJvdG8SB3Byb2Nlc3MiSgoDUFRZEh8KBHNpemUYASABKAsyES5wcm9jZXNzLlBUWS5TaXplGiIKBFNpemUSDAoEY29scxgBIAEoDRIMCgRyb3dzGAIgASgNIqEBCg1Qcm9jZXNzQ29uZmlnEgsKA2NtZBgBIAEoCRIMCgRhcmdzGAIgAygJEi4KBGVudnMYAyADKAsyIC5wcm9jZXNzLlByb2Nlc3NDb25maWcuRW52c0VudHJ5EhAKA2N3ZBgEIAEoCUgAiAEBGisKCUVudnNFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBQgYKBF9jd2QiDQoLTGlzdFJlcXVlc3QiXAoLUHJvY2Vzc0luZm8SJgoGY29uZmlnGAEgASgLMhYucHJvY2Vzcy5Qcm9jZXNzQ29uZmlnEgsKA3BpZBgCIAEoDRIQCgN0YWcYAyABKAlIAIgBAUIGCgRfdGFnIjcKDExpc3RSZXNwb25zZRInCglwcm9jZXNzZXMYASADKAsyFC5wcm9jZXNzLlByb2Nlc3NJbmZvIpcBCgxTdGFydFJlcXVlc3QSJwoHcHJvY2VzcxgBIAEoCzIWLnByb2Nlc3MuUHJvY2Vzc0NvbmZpZxIeCgNwdHkYAiABKAsyDC5wcm9jZXNzLlBUWUgAiAEBEhAKA3RhZxgDIAEoCUgBiAEBEhIKBXN0ZGluGAQgASgISAKIAQFCBgoEX3B0eUIGCgRfdGFnQggKBl9zdGRpbiJiCg1VcGRhdGVSZXF1ZXN0EikKB3Byb2Nlc3MYASABKAsyGC5wcm9jZXNzLlByb2Nlc3NTZWxlY3RvchIeCgNwdHkYAiABKAsyDC5wcm9jZXNzLlBUWUgAiAEBQgYKBF9wdHkiEAoOVXBkYXRlUmVzcG9uc2UirwMKDFByb2Nlc3NFdmVudBIxCgVzdGFydBgBIAEoCzIgLnByb2Nlc3MuUHJvY2Vzc0V2ZW50LlN0YXJ0RXZlbnRIABIvCgRkYXRhGAIgASgLMh8ucHJvY2Vzcy5Qcm9jZXNzRXZlbnQuRGF0YUV2ZW50SAASLQoDZW5kGAMgASgLMh4ucHJvY2Vzcy5Qcm9jZXNzRXZlbnQuRW5kRXZlbnRIABI0CglrZWVwYWxpdmUYBCABKAsyHy5wcm9jZXNzLlByb2Nlc3NFdmVudC5LZWVwQWxpdmVIABoZCgpTdGFydEV2ZW50EgsKA3BpZBgBIAEoDRpICglEYXRhRXZlbnQSEAoGc3Rkb3V0GAEgASgMSAASEAoGc3RkZXJyGAIgASgMSAASDQoDcHR5GAMgASgMSABCCAoGb3V0cHV0GlsKCEVuZEV2ZW50EhEKCWV4aXRfY29kZRgBIAEoERIOCgZleGl0ZWQYAiABKAgSDgoGc3RhdHVzGAMgASgJEhIKBWVycm9yGAQgASgJSACIAQFCCAoGX2Vycm9yGgsKCUtlZXBBbGl2ZUIHCgVldmVudCI1Cg1TdGFydFJlc3BvbnNlEiQKBWV2ZW50GAEgASgLMhUucHJvY2Vzcy5Qcm9jZXNzRXZlbnQiNwoPQ29ubmVjdFJlc3BvbnNlEiQKBWV2ZW50GAEgASgLMhUucHJvY2Vzcy5Qcm9jZXNzRXZlbnQiYwoQU2VuZElucHV0UmVxdWVzdBIpCgdwcm9jZXNzGAEgASgLMhgucHJvY2Vzcy5Qcm9jZXNzU2VsZWN0b3ISJAoFaW5wdXQYAiABKAsyFS5wcm9jZXNzLlByb2Nlc3NJbnB1dCITChFTZW5kSW5wdXRSZXNwb25zZSI3CgxQcm9jZXNzSW5wdXQSDwoFc3RkaW4YASABKAxIABINCgNwdHkYAiABKAxIAEIHCgVpbnB1dCLCAgoSU3RyZWFtSW5wdXRSZXF1ZXN0EjcKBXN0YXJ0GAEgASgLMiYucHJvY2Vzcy5TdHJlYW1JbnB1dFJlcXVlc3QuU3RhcnRFdmVudEgAEjUKBGRhdGEYAiABKAsyJS5wcm9jZXNzLlN0cmVhbUlucHV0UmVxdWVzdC5EYXRhRXZlbnRIABI6CglrZWVwYWxpdmUYAyABKAsyJS5wcm9jZXNzLlN0cmVhbUlucHV0UmVxdWVzdC5LZWVwQWxpdmVIABo3CgpTdGFydEV2ZW50EikKB3Byb2Nlc3MYASABKAsyGC5wcm9jZXNzLlByb2Nlc3NTZWxlY3RvchoxCglEYXRhRXZlbnQSJAoFaW5wdXQYAiABKAsyFS5wcm9jZXNzLlByb2Nlc3NJbnB1dBoLCglLZWVwQWxpdmVCBwoFZXZlbnQiFQoTU3RyZWFtSW5wdXRSZXNwb25zZSJfChFTZW5kU2lnbmFsUmVxdWVzdBIpCgdwcm9jZXNzGAEgASgLMhgucHJvY2Vzcy5Qcm9jZXNzU2VsZWN0b3ISHwoGc2lnbmFsGAIgASgOMg8ucHJvY2Vzcy5TaWduYWwiFAoSU2VuZFNpZ25hbFJlc3BvbnNlIj4KEUNsb3NlU3RkaW5SZXF1ZXN0EikKB3Byb2Nlc3MYASABKAsyGC5wcm9jZXNzLlByb2Nlc3NTZWxlY3RvciIUChJDbG9zZVN0ZGluUmVzcG9uc2UiOwoOQ29ubmVjdFJlcXVlc3QSKQoHcHJvY2VzcxgBIAEoCzIYLnByb2Nlc3MuUHJvY2Vzc1NlbGVjdG9yIjsKD1Byb2Nlc3NTZWxlY3RvchINCgNwaWQYASABKA1IABINCgN0YWcYAiABKAlIAEIKCghzZWxlY3RvcipICgZTaWduYWwSFgoSU0lHTkFMX1VOU1BFQ0lGSUVEEAASEgoOU0lHTkFMX1NJR1RFUk0QDxISCg5TSUdOQUxfU0lHS0lMTBAJMpEECgdQcm9jZXNzEjMKBExpc3QSFC5wcm9jZXNzLkxpc3RSZXF1ZXN0GhUucHJvY2Vzcy5MaXN0UmVzcG9uc2USPgoHQ29ubmVjdBIXLnByb2Nlc3MuQ29ubmVjdFJlcXVlc3QaGC5wcm9jZXNzLkNvbm5lY3RSZXNwb25zZTABEjgKBVN0YXJ0EhUucHJvY2Vzcy5TdGFydFJlcXVlc3QaFi5wcm9jZXNzLlN0YXJ0UmVzcG9uc2UwARI5CgZVcGRhdGUSFi5wcm9jZXNzLlVwZGF0ZVJlcXVlc3QaFy5wcm9jZXNzLlVwZGF0ZVJlc3BvbnNlEkoKC1N0cmVhbUlucHV0EhsucHJvY2Vzcy5TdHJlYW1JbnB1dFJlcXVlc3QaHC5wcm9jZXNzLlN0cmVhbUlucHV0UmVzcG9uc2UoARJCCglTZW5kSW5wdXQSGS5wcm9jZXNzLlNlbmRJbnB1dFJlcXVlc3QaGi5wcm9jZXNzLlNlbmRJbnB1dFJlc3BvbnNlEkUKClNlbmRTaWduYWwSGi5wcm9jZXNzLlNlbmRTaWduYWxSZXF1ZXN0GhsucHJvY2Vzcy5TZW5kU2lnbmFsUmVzcG9uc2USRQoKQ2xvc2VTdGRpbhIaLnByb2Nlc3MuQ2xvc2VTdGRpblJlcXVlc3QaGy5wcm9jZXNzLkNsb3NlU3RkaW5SZXNwb25zZUJXCgtjb20ucHJvY2Vzc0IMUHJvY2Vzc1Byb3RvUAGiAgNQWFiqAgdQcm9jZXNzygIHUHJvY2Vzc+ICE1Byb2Nlc3NcR1BCTWV0YWRhdGHqAgdQcm9jZXNzYgZwcm90bzM`),iB=iI(rB,14),aB=dL(rB,0),LMe=[`terminated`,`The socket connection was closed unexpectedly`,`error reading a body from connection`,`Network connection lost`,`network error`];function oB(e){return e?LMe.some(t=>e.includes(t)):!1}function RMe(e){return e instanceof eL&&e.code===B.Unknown&&oB(e.rawMessage)}function zMe(e){return RMe(e)?!0:e instanceof eL&&e.code===B.Unknown&&Cz(e.cause)}function BMe(e){return e instanceof eL&&e.code===B.Unavailable&&!UR(e.rawMessage)&&!WR(e.rawMessage)}function VMe(e,t){if(t instanceof $R)return t.cause=e,t;let n=t instanceof Error?t.message:String(t);return new $R(`${e.message}: The sandbox could not be reached and its health probe failed too (${n}). It was not confirmed to be stopped — this is likely a network issue or envd inside the sandbox not being up yet; check the sandbox state with 'Sandbox.getInfo()'.`,{cause:e})}async function sB(e,t){let n;try{n=await t()}catch(t){return VMe(e,t)}if(n===!1)return new QR(`${e.message}: The sandbox was killed or reached its end of life while the request was in flight.`,{cause:e})}const cB={[B.InvalidArgument]:e=>new JR(e),[B.Unauthenticated]:e=>new ez(e),[B.NotFound]:e=>new YR(e),[B.ResourceExhausted]:e=>new iz(`${e}: Rate limit exceeded, please try again later.`),[B.Unavailable]:GR,[B.Canceled]:e=>new qR(`${e}: This error is likely due to exceeding 'requestTimeoutMs'. You can pass the request timeout value as an option when making the request.`),[B.DeadlineExceeded]:e=>new qR(`${e}: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.`)};function HMe(e,t){return e instanceof eL?t&&e.code in t?t[e.code](e.message):e.code in cB?cB[e.code](e.message):new KR(`${e.code}: ${e.message}`):e}async function lB(e,t,n){if(t&&(zMe(e)||BMe(e))){let n=await sB(e,t);if(n)return n}return HMe(e,n)}async function uB(e,t,n,r){try{return await e.sendSignal({process:{selector:{case:`pid`,value:t}},signal:9},{signal:n}),!0}catch(e){if(e instanceof eL&&e.code===B.NotFound)return!1;throw await lB(e,r)}}function UMe(e){switch(dz){case`deno`:return btoa(e);case`node`:return Buffer.from(e).toString(`base64`);case`bun`:return Buffer.from(e).toString(`base64`);default:return btoa(e)}}function dB(e,t){return t==null&&yP(e,`0.4.0`)<0&&(t=Mz),t?{Authorization:`Basic ${UMe(`${t}:`)}`}:{}}async function WMe(e){if(e.status!==502)return e;let t=``;try{t=await e.text()}catch{}try{let n=JSON.parse(t);if(typeof n?.code==`string`&&Yke(n.code)!==void 0)return new Response(t,{status:e.status,statusText:e.statusText,headers:e.headers});typeof n?.message==`string`&&(t=n.message)}catch{}throw new eL(t||`HTTP ${e.status}`,B.Unavailable)}const fB={400:e=>new JR(e),401:e=>new ez(e),404:e=>new YR(e),429:e=>new iz(`${e}: The requests are being rate limited.`),502:GR,507:e=>new Gje(e)};async function pB(e){let t=await e.api.GET(`/health`,{signal:AbortSignal.timeout(5e3)});if(t.response.status===502){let e=GR(await hB(t));if(e instanceof QR)return!1;throw e}if(t.response.ok)return!0}function GMe(e){return e instanceof Error&&(oB(e.message)||Cz(e))}async function mB(e,t){if(t&&GMe(e)){let n=await sB(e,t);if(n)return n}return e}async function hB(e){let t=(typeof e.error==`string`?e.error:e.error?.message)??``;if(!t&&!e.response.bodyUsed)try{t=await e.response.text()}catch{}return t||e.response.statusText}async function gB(e,t){if(e.response.ok)return;let n=await hB(e);return t&&e.response.status in t?t[e.response.status]?.call(t,n):e.response.status in fB?fB[e.response.status]?.call(fB,n):new KR(`${e.response.status}: ${n}`)}async function _B(e){let t=(await e[Symbol.asyncIterator]().next()).value;if(t.event?.event.case!==`start`)throw Error(`Expected start event`);return t.event.event.value.pid}async function KMe(e){let t=(await e[Symbol.asyncIterator]().next()).value;if(t.event?.case!==`start`)throw Error(`Expected start event`);return t.event.value}var qMe=class{constructor(e,t){H(this,`api`,void 0),H(this,`version`,void 0),this.api=cP({baseUrl:e.apiUrl,fetch:e?.fetch,headers:U(U({},e?.headers),e.envdAccessToken&&{"X-Access-Token":e.envdAccessToken})}),this.version=t.version,e.logger&&this.api.use(Gz(e.logger))}};const JMe=dL(pI(`ChtmaWxlc3lzdGVtL2ZpbGVzeXN0ZW0ucHJvdG8SCmZpbGVzeXN0ZW0iMgoLTW92ZVJlcXVlc3QSDgoGc291cmNlGAEgASgJEhMKC2Rlc3RpbmF0aW9uGAIgASgJIjQKDE1vdmVSZXNwb25zZRIkCgVlbnRyeRgBIAEoCzIVLmZpbGVzeXN0ZW0uRW50cnlJbmZvIh4KDk1ha2VEaXJSZXF1ZXN0EgwKBHBhdGgYASABKAkiNwoPTWFrZURpclJlc3BvbnNlEiQKBWVudHJ5GAEgASgLMhUuZmlsZXN5c3RlbS5FbnRyeUluZm8iHQoNUmVtb3ZlUmVxdWVzdBIMCgRwYXRoGAEgASgJIhAKDlJlbW92ZVJlc3BvbnNlIhsKC1N0YXRSZXF1ZXN0EgwKBHBhdGgYASABKAkiNAoMU3RhdFJlc3BvbnNlEiQKBWVudHJ5GAEgASgLMhUuZmlsZXN5c3RlbS5FbnRyeUluZm8i+QIKCUVudHJ5SW5mbxIMCgRuYW1lGAEgASgJEiIKBHR5cGUYAiABKA4yFC5maWxlc3lzdGVtLkZpbGVUeXBlEgwKBHBhdGgYAyABKAkSDAoEc2l6ZRgEIAEoAxIMCgRtb2RlGAUgASgNEhMKC3Blcm1pc3Npb25zGAYgASgJEg0KBW93bmVyGAcgASgJEg0KBWdyb3VwGAggASgJEjEKDW1vZGlmaWVkX3RpbWUYCSABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wEhsKDnN5bWxpbmtfdGFyZ2V0GAogASgJSACIAQESNQoIbWV0YWRhdGEYCyADKAsyIy5maWxlc3lzdGVtLkVudHJ5SW5mby5NZXRhZGF0YUVudHJ5EhIKCmlzX3N5bWxpbmsYDCABKAgaLwoNTWV0YWRhdGFFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBQhEKD19zeW1saW5rX3RhcmdldCItCg5MaXN0RGlyUmVxdWVzdBIMCgRwYXRoGAEgASgJEg0KBWRlcHRoGAIgASgNIjkKD0xpc3REaXJSZXNwb25zZRImCgdlbnRyaWVzGAEgAygLMhUuZmlsZXN5c3RlbS5FbnRyeUluZm8iZwoPV2F0Y2hEaXJSZXF1ZXN0EgwKBHBhdGgYASABKAkSEQoJcmVjdXJzaXZlGAIgASgIEhUKDWluY2x1ZGVfZW50cnkYAyABKAgSHAoUYWxsb3dfbmV0d29ya19tb3VudHMYBCABKAgieQoPRmlsZXN5c3RlbUV2ZW50EgwKBG5hbWUYASABKAkSIwoEdHlwZRgCIAEoDjIVLmZpbGVzeXN0ZW0uRXZlbnRUeXBlEikKBWVudHJ5GAMgASgLMhUuZmlsZXN5c3RlbS5FbnRyeUluZm9IAIgBAUIICgZfZW50cnki4AEKEFdhdGNoRGlyUmVzcG9uc2USOAoFc3RhcnQYASABKAsyJy5maWxlc3lzdGVtLldhdGNoRGlyUmVzcG9uc2UuU3RhcnRFdmVudEgAEjEKCmZpbGVzeXN0ZW0YAiABKAsyGy5maWxlc3lzdGVtLkZpbGVzeXN0ZW1FdmVudEgAEjsKCWtlZXBhbGl2ZRgDIAEoCzImLmZpbGVzeXN0ZW0uV2F0Y2hEaXJSZXNwb25zZS5LZWVwQWxpdmVIABoMCgpTdGFydEV2ZW50GgsKCUtlZXBBbGl2ZUIHCgVldmVudCJsChRDcmVhdGVXYXRjaGVyUmVxdWVzdBIMCgRwYXRoGAEgASgJEhEKCXJlY3Vyc2l2ZRgCIAEoCBIVCg1pbmNsdWRlX2VudHJ5GAMgASgIEhwKFGFsbG93X25ldHdvcmtfbW91bnRzGAQgASgIIisKFUNyZWF0ZVdhdGNoZXJSZXNwb25zZRISCgp3YXRjaGVyX2lkGAEgASgJIi0KF0dldFdhdGNoZXJFdmVudHNSZXF1ZXN0EhIKCndhdGNoZXJfaWQYASABKAkiRwoYR2V0V2F0Y2hlckV2ZW50c1Jlc3BvbnNlEisKBmV2ZW50cxgBIAMoCzIbLmZpbGVzeXN0ZW0uRmlsZXN5c3RlbUV2ZW50IioKFFJlbW92ZVdhdGNoZXJSZXF1ZXN0EhIKCndhdGNoZXJfaWQYASABKAkiFwoVUmVtb3ZlV2F0Y2hlclJlc3BvbnNlKmkKCEZpbGVUeXBlEhkKFUZJTEVfVFlQRV9VTlNQRUNJRklFRBAAEhIKDkZJTEVfVFlQRV9GSUxFEAESFwoTRklMRV9UWVBFX0RJUkVDVE9SWRACEhUKEUZJTEVfVFlQRV9TWU1MSU5LEAMqmAEKCUV2ZW50VHlwZRIaChZFVkVOVF9UWVBFX1VOU1BFQ0lGSUVEEAASFQoRRVZFTlRfVFlQRV9DUkVBVEUQARIUChBFVkVOVF9UWVBFX1dSSVRFEAISFQoRRVZFTlRfVFlQRV9SRU1PVkUQAxIVChFFVkVOVF9UWVBFX1JFTkFNRRAEEhQKEEVWRU5UX1RZUEVfQ0hNT0QQBTKfBQoKRmlsZXN5c3RlbRI5CgRTdGF0EhcuZmlsZXN5c3RlbS5TdGF0UmVxdWVzdBoYLmZpbGVzeXN0ZW0uU3RhdFJlc3BvbnNlEkIKB01ha2VEaXISGi5maWxlc3lzdGVtLk1ha2VEaXJSZXF1ZXN0GhsuZmlsZXN5c3RlbS5NYWtlRGlyUmVzcG9uc2USOQoETW92ZRIXLmZpbGVzeXN0ZW0uTW92ZVJlcXVlc3QaGC5maWxlc3lzdGVtLk1vdmVSZXNwb25zZRJCCgdMaXN0RGlyEhouZmlsZXN5c3RlbS5MaXN0RGlyUmVxdWVzdBobLmZpbGVzeXN0ZW0uTGlzdERpclJlc3BvbnNlEj8KBlJlbW92ZRIZLmZpbGVzeXN0ZW0uUmVtb3ZlUmVxdWVzdBoaLmZpbGVzeXN0ZW0uUmVtb3ZlUmVzcG9uc2USRwoIV2F0Y2hEaXISGy5maWxlc3lzdGVtLldhdGNoRGlyUmVxdWVzdBocLmZpbGVzeXN0ZW0uV2F0Y2hEaXJSZXNwb25zZTABElQKDUNyZWF0ZVdhdGNoZXISIC5maWxlc3lzdGVtLkNyZWF0ZVdhdGNoZXJSZXF1ZXN0GiEuZmlsZXN5c3RlbS5DcmVhdGVXYXRjaGVyUmVzcG9uc2USXQoQR2V0V2F0Y2hlckV2ZW50cxIjLmZpbGVzeXN0ZW0uR2V0V2F0Y2hlckV2ZW50c1JlcXVlc3QaJC5maWxlc3lzdGVtLkdldFdhdGNoZXJFdmVudHNSZXNwb25zZRJUCg1SZW1vdmVXYXRjaGVyEiAuZmlsZXN5c3RlbS5SZW1vdmVXYXRjaGVyUmVxdWVzdBohLmZpbGVzeXN0ZW0uUmVtb3ZlV2F0Y2hlclJlc3BvbnNlQmkKDmNvbS5maWxlc3lzdGVtQg9GaWxlc3lzdGVtUHJvdG9QAaICA0ZYWKoCCkZpbGVzeXN0ZW3KAgpGaWxlc3lzdGVt4gIWRmlsZXN5c3RlbVxHUEJNZXRhZGF0YeoCCkZpbGVzeXN0ZW1iBnByb3RvMw`,[VOe]),0);function YMe(e){switch(e){case 5:return`chmod`;case 1:return`create`;case 3:return`remove`;case 4:return`rename`;case 2:return`write`}}var XMe=class{constructor(e,t,n,r,i){this.handleStop=e,this.events=t,this.onEvent=n,this.onExit=r,this.checkHealth=i,H(this,`stopped`,!1),this.handleEvents()}async stop(){var e=this;e.stopped=!0,e.handleStop()}iterateEvents(){var e=this;return Hz(function*(){try{var t=!1,n=!1,r;try{for(var i=Rz(e.events),a;t=!(a=yield Vz(i.next())).done;t=!1){let e=a.value;e.event.case===`filesystem`&&(yield e.event)}}catch(e){n=!0,r=e}finally{try{t&&i.return!=null&&(yield Vz(i.return()))}finally{if(n)throw r}}}catch(t){if(e.stopped)return;throw yield Vz(lB(t,e.checkHealth))}})()}async handleEvents(){var e=this;let t;try{var n=!1,r=!1,i;try{for(var a=Rz(e.iterateEvents()),o;n=!(o=await a.next()).done;n=!1){let t=o.value;{let n=YMe(t.value.type);if(n===void 0)continue;await e.onEvent?.call(e,{name:t.value.name,type:n,entry:t.value.entry?SB(t.value.entry):void 0})}}}catch(e){r=!0,i=e}finally{try{n&&a.return!=null&&await a.return()}finally{if(r)throw i}}}catch(e){t=e}try{t?await e.onExit?.call(e,t):await e.onExit?.call(e)}catch{}finally{e.handleStop()}}};const ZMe={404:e=>new XR(e)},QMe={[B.NotFound]:e=>new XR(e)};async function vB(e,t){return lB(e,t,QMe)}function yB(e){return gB(e,ZMe)}function bB(e){switch(e){case 2:return`dir`;case 1:return`file`;case 3:return`symlink`}}function $Me(e){if(e)return new Date(Number(e.seconds)*1e3+Math.floor(e.nanos/1e6))}function xB(e){if(e)return Object.keys(e).length===0?void 0:e}const eNe=/^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/,tNe=/^[\x20-\x7e]*$/;function nNe(e){if(e)for(let[t,n]of Object.entries(e)){if(!eNe.test(t))throw new JR(`Invalid metadata key ${JSON.stringify(t)}: keys must be non-empty and use only HTTP token characters (letters, digits and !#$%&'*+-.^_\`|~).`);if(!tNe.test(n))throw new JR(`Invalid metadata value for key ${JSON.stringify(t)}: values must be printable US-ASCII.`)}}function rNe(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e))t[`X-Metadata-${n}`]=r;return t}function SB(e){return{name:e.name,type:e.isSymlink?`symlink`:bB(e.type),path:e.path,size:Number(e.size),mode:e.mode,permissions:e.permissions,owner:e.owner,group:e.group,modifiedTime:$Me(e.modifiedTime),symlinkTarget:e.symlinkTarget,metadata:xB(e.metadata)}}var iNe=class{constructor(e,t,n){this.envdApi=t,this.connectionConfig=n,H(this,`rpc`,void 0),H(this,`defaultWatchTimeout`,6e4),H(this,`defaultWatchRecursive`,!1),H(this,`checkHealth`,void 0),H(this,`uploadFetch`,void 0);let r=FMe({proxy:n.proxy});this.uploadFetch=e=>r(e),this.rpc=sL(JMe,e),this.checkHealth=()=>pB(this.envdApi)}async read(e,t){var n=this;let r=t?.format??`text`,i=t?.user;i==null&&yP(n.envdApi.version,`0.4.0`)<0&&(i=Mz);let a={};if(t?.gzip&&(a[`Accept-Encoding`]=`gzip`),r===`stream`){let r=t?.requestTimeoutMs??n.connectionConfig.requestTimeoutMs,{controller:o,clearStartTimeout:s,cleanup:c}=Oz(r,t?.signal);try{let l=await n.envdApi.api.GET(`/files`,{params:{query:{path:e,username:i}},parseAs:`stream`,signal:o.signal,headers:a}).catch(async e=>{throw await mB(e,n.checkHealth)}),u=await yB(l);if(u)throw l.response.body&&!l.response.bodyUsed&&await l.response.body.cancel().catch(()=>{}),c(),u;return wMe(l.data,{clearStartTimeout:s,cleanup:c,controller:o,idleTimeoutMs:t?.streamIdleTimeoutMs??r})}catch(e){throw c(),e}}let o=await n.envdApi.api.GET(`/files`,{params:{query:{path:e,username:i}},parseAs:r===`bytes`?`arrayBuffer`:r,signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal),headers:a}).catch(async e=>{throw await mB(e,n.checkHealth)}),s=await yB(o);if(s)throw s;return o.response.headers.get(`content-length`)===`0`?r===`bytes`?new Uint8Array:r===`blob`?new Blob([]):``:r===`bytes`?new Uint8Array(o.data):o.data}async write(e,t,n){var r=this;if(typeof e!=`string`&&!Array.isArray(e))throw Error(`Path or files are required`);if(typeof e==`string`&&Array.isArray(t))throw Error(`Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files.`);let{path:i,writeOpts:a,writeFiles:o}=typeof e==`string`?{path:e,writeOpts:n,writeFiles:[{data:t}]}:{path:void 0,writeOpts:t,writeFiles:e};if(o.length===0)return[];let s=a?.user;s==null&&yP(r.envdApi.version,`0.4.0`)<0&&(s=Mz);let c=a?.gzip===!0;if(c&&a?.useOctetStream===!1)throw new JR("`gzip` requires the octet-stream upload and can't be combined with `useOctetStream: false`.");let l=yP(r.envdApi.version,nB)>=0,u=o.some(e=>_z(e.data)),d=((a?.useOctetStream??u)||c)&&l;if(u&&!d)throw l?new JR("Stream data (`ReadableStream` / `AsyncIterable`) is only uploaded with octet-stream; `useOctetStream: false` is not supported for it."):new rz(`Uploading stream data requires envd ${nB} or later.`);let f=a?.metadata;if(nNe(f),f&&Object.keys(f).length>0&&yP(r.envdApi.version,`0.6.2`)<0)throw new rz(`File metadata requires envd 0.6.2 or later.`);let p=rNe(f),m=[];if(d){let e=U({"Content-Type":`application/octet-stream`},p);c&&(e[`Content-Encoding`]=`gzip`);let t=await Promise.all(o.map(async t=>{let n=i??t.path,{body:o,streamed:l,sourceError:u}=await aMe(t.data,c),d=l?a?.signal:r.connectionConfig.getSignal(a?.requestTimeoutMs,a?.signal),f=await r.envdApi.api.POST(`/files`,U({params:{query:{path:n,username:s}},bodySerializer:()=>o,headers:e,signal:d,body:{},fetch:r.uploadFetch},l&&{duplex:`half`})).catch(async e=>{throw u()||await mB(e,r.checkHealth)}),p=await yB(f);if(p)throw p;let m=f.data;if(!m||m.length===0)throw Error(`Expected to receive information about written file`);for(let e of m)e.metadata=xB(e.metadata);return m}));for(let e of t)m.push(...e)}else{let e=new FormData;for(let t of o)e.append(`file`,await vz(t.data),t.path??i);let t=await r.envdApi.api.POST(`/files`,{params:{query:{path:i,username:s}},bodySerializer:()=>e,headers:p,signal:r.connectionConfig.getSignal(a?.requestTimeoutMs,a?.signal),body:{},fetch:r.uploadFetch}).catch(async e=>{throw await mB(e,r.checkHealth)}),n=await yB(t);if(n)throw n;let c=t.data;if(!c||c.length===0)throw Error(`Expected to receive information about written file`);for(let e of c)e.metadata=xB(e.metadata);m.push(...c)}return m.length===1&&i?m[0]:m}async writeFiles(e,t){return this.write(e,t)}async list(e,t){var n=this;if(typeof t?.depth==`number`&&t.depth<1)throw new JR(`depth should be at least one`);try{let r=await n.rpc.listDir({path:e,depth:t?.depth??1},{headers:dB(n.envdApi.version,t?.user),signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)}),i=[];for(let e of r.entries)bB(e.type)&&i.push(SB(e));return i}catch(e){throw await vB(e,n.checkHealth)}}async makeDir(e,t){var n=this;try{return await n.rpc.makeDir({path:e},{headers:dB(n.envdApi.version,t?.user),signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)}),!0}catch(e){if(e instanceof eL&&e.code===B.AlreadyExists)return!1;throw await vB(e,n.checkHealth)}}async rename(e,t,n){var r=this;try{let i=(await r.rpc.move({source:e,destination:t},{headers:dB(r.envdApi.version,n?.user),signal:r.connectionConfig.getSignal(n?.requestTimeoutMs,n?.signal)})).entry;if(!i)throw Error(`Expected to receive information about moved object`);return SB(i)}catch(e){throw await vB(e,r.checkHealth)}}async remove(e,t){var n=this;try{await n.rpc.remove({path:e},{headers:dB(n.envdApi.version,t?.user),signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)})}catch(e){throw await vB(e,n.checkHealth)}}async exists(e,t){var n=this;try{return await n.rpc.stat({path:e},{headers:dB(n.envdApi.version,t?.user),signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)}),!0}catch(e){if(e instanceof eL&&e.code===B.NotFound)return!1;throw await vB(e,n.checkHealth)}}async getInfo(e,t){var n=this;try{let r=await n.rpc.stat({path:e},{headers:dB(n.envdApi.version,t?.user),signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)});if(!r.entry)throw Error(`Expected to receive information about the file or directory`);return SB(r.entry)}catch(e){throw await vB(e,n.checkHealth)}}async watchDir(e,t,n){var r=this;if(n?.recursive&&r.envdApi.version&&yP(r.envdApi.version,`0.1.4`)<0)throw new rz(`You need to update the template to use recursive watching.`);if(n?.includeEntry&&r.envdApi.version&&yP(r.envdApi.version,`0.6.3`)<0)throw new rz(`You need to update the template to include entry info in watch events.`);if(n?.allowNetworkMounts&&r.envdApi.version&&yP(r.envdApi.version,`0.6.4`)<0)throw new rz(`You need to update the template to watch directories on network mounts.`);let{controller:i,clearStartTimeout:a,cleanup:o}=Oz(n?.requestTimeoutMs??r.connectionConfig.requestTimeoutMs,n?.signal),s=r.rpc.watchDir({path:e,recursive:n?.recursive??r.defaultWatchRecursive,includeEntry:n?.includeEntry??!1,allowNetworkMounts:n?.allowNetworkMounts??!1},{headers:U(U({},dB(r.envdApi.version,n?.user)),{},{[Ez]:`50`}),signal:i.signal,timeoutMs:n?.timeoutMs??r.defaultWatchTimeout});try{return await KMe(s),a(),new XMe(o,s,t,n?.onExit,r.checkHealth)}catch(e){throw o(),await vB(e,r.checkHealth)}}};function CB(e){var t={},n=!1;function r(t,r){return n=!0,r=new Promise(function(n){n(e[t](r))}),{done:!1,value:new Bz(r,1)}}return t[typeof Symbol<`u`&&Symbol.iterator||`@@iterator`]=function(){return this},t.next=function(e){return n?(n=!1,e):r(`next`,e)},typeof e.throw==`function`&&(t.throw=function(e){if(n)throw n=!1,e;return r(`throw`,e)}),typeof e.return==`function`&&(t.return=function(e){return n?(n=!1,e):r(`return`,e)}),t}var wB=class extends KR{constructor(e){super(e.error),this.result=e,this.name=`CommandExitError`}get exitCode(){return this.result.exitCode}get error(){return this.result.error}get stdout(){return this.result.stdout}get stderr(){return this.result.stderr}},TB=class{constructor(e,t,n,r,i,a,o,s,c,l,u=!0){this.pid=e,this.handleDisconnect=t,this.handleKill=n,this.events=r,this.onStdout=i,this.onStderr=a,this.onPty=o,this.handleSendStdin=s,this.handleCloseStdin=c,this.checkHealth=l,H(this,`_stdout`,void 0),H(this,`_stderr`,void 0),H(this,`stdoutDecoder`,new TextDecoder),H(this,`stderrDecoder`,new TextDecoder),H(this,`result`,void 0),H(this,`iterationError`,void 0),H(this,`disconnected`,!1),H(this,`_wait`,void 0),u&&(this._stdout=``,this._stderr=``),this._wait=this.handleEvents()}get exitCode(){return this.result?.exitCode}get error(){return this.result?.error}get stderr(){return this._stderr}get stdout(){return this._stdout}async wait(){var e=this;if(await e._wait,e.iterationError)throw e.iterationError;if(!e.result)throw new KR(`Process exited without a result`);if(e.result.exitCode!==0)throw new wB(e.result);return e.result}async disconnect(){var e=this;e.disconnected=!0,e.handleDisconnect()}async kill(){return await this.handleKill()}async sendStdin(e,t){var n=this;if(!n.handleSendStdin)throw new KR(`Sending stdin is not supported for this command handle.`);await n.handleSendStdin(e,t)}async closeStdin(e){var t=this;if(!t.handleCloseStdin)throw new KR(`Closing stdin is not supported for this command handle.`);await t.handleCloseStdin(e)}appendStdout(e){this._stdout!==void 0&&(this._stdout+=e)}appendStderr(e){this._stderr!==void 0&&(this._stderr+=e)}*flushDecoders(){let e=this.stdoutDecoder.decode();e&&(this.appendStdout(e),yield[e,null,null]);let t=this.stderrDecoder.decode();t&&(this.appendStderr(t),yield[null,t,null])}iterateEvents(){var e=this;return Hz(function*(){try{var t=!1,n=!1,r;try{for(var i=Rz(e.events),a;t=!(a=yield Vz(i.next())).done;t=!1){let t=a.value;{var o;let n=t==null||(o=t.event)==null?void 0:o.event,r;switch(n?.case){case`data`:switch(n.value.output.case){case`stdout`:r=e.stdoutDecoder.decode(n.value.output.value,{stream:!0}),r&&(e.appendStdout(r),yield[r,null,null]);break;case`stderr`:r=e.stderrDecoder.decode(n.value.output.value,{stream:!0}),r&&(e.appendStderr(r),yield[null,r,null]);break;case`pty`:yield[null,null,n.value.output.value]}break;case`end`:{let t=[...e.flushDecoders()];e.result={exitCode:n.value.exitCode,error:n.value.error,stdout:e.stdout,stderr:e.stderr};for(let e of t)yield e;break}}}}}catch(e){n=!0,r=e}finally{try{t&&i.return!=null&&(yield Vz(i.return()))}finally{if(n)throw r}}}catch(t){throw yield*CB(Rz(e.flushDecoders())),t}e.result===void 0&&(yield*CB(Rz(e.flushDecoders())))})()}async handleEvents(){var e=this;try{var t=!1,n=!1,r;try{for(var i=Rz(e.iterateEvents()),a;t=!(a=await i.next()).done;t=!1){let[t,n,r]=a.value;if(e.disconnected)break;t===null?n===null?r&&await e.onPty?.call(e,r):await e.onStderr?.call(e,n):await e.onStdout?.call(e,t)}}catch(e){n=!0,r=e}finally{try{t&&i.return!=null&&await i.return()}finally{if(n)throw r}}}catch(t){e.iterationError=await lB(t,e.checkHealth)}finally{e.handleDisconnect()}}};const EB=Symbol(`close`);var DB=class{constructor(e,t,n,r,i,a=5e4){var o=this;this.rpc=e,this.pid=t,this.inputKind=n,this.checkHealth=i,H(this,`queue`,[]),H(this,`completion`,void 0),H(this,`keepaliveIntervalMs`,void 0),H(this,`wake`,void 0),H(this,`closing`,!1),H(this,`stopped`,!1),H(this,`failure`,void 0),H(this,`closePromise`,void 0),this.keepaliveIntervalMs=a,this.completion=this.rpc.streamInput(this.requests(),{signal:r.signal,timeoutMs:r.timeoutMs??6e4}).then(()=>{this.stopped=!0,this.notify()}).catch(async e=>{throw o.failure=await lB(e,o.checkHealth),o.stopped=!0,o.notify(),o.failure}),this.completion.catch(()=>void 0)}async send(e){var t=this;if(t.failure)throw t.failure;if(t.closing||t.stopped)throw new KR("Cannot send input after the input handle is closed. Open a new one with `sandbox.commands.streamInput(pid)` or `sandbox.pty.streamInput(pid)`.");t.queue.push(e instanceof Uint8Array?e.slice():e),t.notify()}close(){return this.closePromise?this.closePromise:(this.closing=!0,this.queue.push(EB),this.notify(),this.closePromise=this.completion,this.closePromise)}notify(){var e;(e=this.wake)==null||e.call(this)}waitForInput(){return new Promise(e=>{let t=!1,n=setTimeout(()=>{t=!0,this.wake=void 0,e(!1)},this.keepaliveIntervalMs);this.wake=()=>{t||(t=!0,clearTimeout(n),this.wake=void 0,e(!0))}})}requests(){var e=this;return Hz(function*(){for(yield VP(iB,{event:{case:`start`,value:{process:{selector:{case:`pid`,value:e.pid}}}}});!e.stopped;){if(e.queue.length>0){let t=e.queue.shift();if(t===EB)return;let n=typeof t==`string`?new TextEncoder().encode(t):t;yield VP(iB,{event:{case:`data`,value:{input:{input:{case:e.inputKind,value:n}}}}});continue}!(yield Vz(e.waitForInput()))&&!e.stopped&&e.queue.length===0&&(yield VP(iB,{event:{case:`keepalive`,value:{}}}))}})()}},OB=class{constructor(e,t,n){H(this,`opts`,void 0),H(this,`limit`,void 0),H(this,`_hasNext`,void 0),H(this,`_nextToken`,void 0),this.opts=e,this.limit=t,this._hasNext=!0,this._nextToken=n}get hasNext(){return this._hasNext}get nextToken(){return this._nextToken}updatePagination(e){this._nextToken=e.headers.get(`x-next-token`)||void 0,this._hasNext=!!this._nextToken}};function kB(e,t,n){if(!t&&!n)return e;if(!t||!n)throw new JR(`Both username and password are required when using Git credentials.`);let r;try{r=new URL(e)}catch{throw new JR(`Invalid Git URL: ${e}`)}if(r.protocol!==`http:`&&r.protocol!==`https:`)throw new JR(`Only http(s) Git URLs support username/password credentials.`);return r.username=t,r.password=n,r.toString()}function aNe(e){let t;try{t=new URL(e)}catch{return e}return t.protocol!==`http:`&&t.protocol!==`https:`||!t.username&&!t.password?e:(t.username=``,t.password=``,t.toString())}function oNe(e){let t;try{t=new URL(e)}catch{return}let n=t.pathname.replace(/\/+$/,``).split(`/`).pop();if(n)return n.endsWith(`.git`)?n.slice(0,-4):n}function AB(e,t){let n=[`git`];return t&&n.push(`-C`,t),n.push(...e),n.map(e=>yz(e)).join(` `)}function jB(e,t){let{remote:n,branch:r,setUpstream:i}=t,a=[`push`],o=e??n;return i&&o&&a.push(`--set-upstream`),o&&a.push(o),r&&a.push(r),a}function sNe(e){if(!e)return{ahead:0,behind:0};let t=0,n=0;if(e.includes(`ahead`))try{t=Number.parseInt(e.split(`ahead`)[1].split(`,`)[0].trim(),10)}catch{t=0}if(e.includes(`behind`))try{n=Number.parseInt(e.split(`behind`)[1].split(`,`)[0].trim(),10)}catch{n=0}return{ahead:t,behind:n}}function cNe(e){return e.startsWith(`HEAD (detached at `)?e.replace(`HEAD (detached at `,``).replace(/\)$/,``):e.replace(`HEAD (no branch)`,`HEAD`).replace(`No commits yet on `,``).replace(`Initial commit on `,``)}function lNe(e,t){let n=new Set([e,t]);return n.has(`U`)?`conflict`:n.has(`R`)?`renamed`:n.has(`C`)?`copied`:n.has(`D`)?`deleted`:n.has(`A`)?`added`:n.has(`M`)?`modified`:n.has(`T`)?`typechange`:n.has(`?`)?`untracked`:`unknown`}function uNe(e){let t=e.split(`
460
+ `).map(e=>e.replace(/\r$/,``)).filter(e=>e.trim().length>0),n,r,i=0,a=0,o=!1,s=[];if(t.length===0)return{currentBranch:n,upstream:r,ahead:i,behind:a,detached:o,fileStatus:s,isClean:!0,hasChanges:!1,hasStaged:!1,hasUntracked:!1,hasConflicts:!1,totalCount:0,stagedCount:0,unstagedCount:0,untrackedCount:0,conflictCount:0};let c=t[0];if(c.startsWith(`## `)){let e=c.slice(3),t=e.indexOf(` [`),s=t===-1?e:e.slice(0,t),l=t===-1?void 0:e.slice(t+2,-1),u=cNe(s),d=s;if(d.startsWith(`HEAD (detached at `)||d.includes(`detached`)||u.startsWith(`HEAD`))o=!0;else if(u.includes(`...`)){let[e,t]=u.split(`...`);n=e||void 0,r=t||void 0}else n=u||void 0;let f=sNe(l);i=f.ahead,a=f.behind}for(let e of t.slice(1)){if(e.startsWith(`?? `)){let t=e.slice(3);s.push({name:t,status:`untracked`,indexStatus:`?`,workingTreeStatus:`?`,staged:!1});continue}if(e.length<3)continue;let t=e[0],n=e[1],r=e.slice(3),i,a=r;if(r.includes(` -> `)){let e=r.split(` -> `);i=e[0],a=e.slice(1).join(` -> `)}s.push(U({name:a,status:lNe(t,n),indexStatus:t,workingTreeStatus:n,staged:t!==` `&&t!==`?`},i?{renamedFrom:i}:{}))}let l=s.length,u=s.filter(e=>e.staged).length,d=s.filter(e=>e.status===`untracked`).length,f=s.filter(e=>e.status===`conflict`).length,p=l-u;return{currentBranch:n,upstream:r,ahead:i,behind:a,detached:o,fileStatus:s,isClean:l===0,hasChanges:l>0,hasStaged:u>0,hasUntracked:d>0,hasConflicts:f>0,totalCount:l,stagedCount:u,unstagedCount:p,untrackedCount:d,conflictCount:f}}function dNe(e){let t=[],n,r=e.split(`
461
+ `).map(e=>e.trim()).filter(e=>e.length>0);for(let e of r){let r=e.split(` `),i=r[0];t.push(i),r.length>1&&r[1]===`*`&&(n=i)}return{branches:t,currentBranch:n}}function MB(e){if(!(e instanceof wB))return!1;let t=`${e.stderr}\n${e.stdout}`.toLowerCase();return[`authentication failed`,`terminal prompts disabled`,`could not read username`,`invalid username or password`,`access denied`,`permission denied`,`not authorized`].some(e=>t.includes(e))}function NB(e){if(e!==`global`&&e!==`local`&&e!==`system`)throw new JR(`Git config scope must be one of: global, local, system.`);return`--${e}`}function PB(e){if(!(e instanceof wB))return!1;let t=`${e.stderr}\n${e.stdout}`.toLowerCase();return[`has no upstream branch`,`no upstream branch`,`no upstream configured`,`no tracking information for the current branch`,`no tracking information`,`set the remote as upstream`,`set the upstream branch`,`please specify which branch you want to merge with`].some(e=>t.includes(e))}function FB(e,t){return t?`Git ${e} requires a password/token for private repositories.`:`Git ${e} requires credentials for private repositories.`}function IB(e){return e===`push`?`Git push failed because no upstream branch is configured. Set upstream once with { setUpstream: true } (and optional remote/branch), or pass remote and branch explicitly.`:`Git pull failed because no upstream branch is configured. Pass remote and branch explicitly, or set upstream once (push with { setUpstream: true } or run: git branch --set-upstream-to=origin/<branch> <branch>).`}function LB(e,t){if(e===`local`){if(!t)throw new JR(`A repository path is required when using scope "local".`);return t}}function fNe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function RB(e,t){if(e==null)return{};var n,r,i=fNe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}const pNe=[`username`,`password`,`branch`,`depth`,`path`,`dangerouslyStoreCredentials`],mNe=[`bare`,`initialBranch`],hNe=[`fetch`,`overwrite`],gNe=[`force`],_Ne=[`files`,`all`],vNe=[`authorName`,`authorEmail`,`allowEmpty`],yNe=[`mode`,`target`,`paths`],bNe=[`paths`,`staged`,`worktree`,`source`],xNe=[`remote`,`branch`,`setUpstream`,`username`,`password`],SNe=[`remote`,`branch`,`username`,`password`],CNe=[`username`,`password`,`host`,`protocol`],wNe=[`envs`],TNe=[`envs`],zB={GIT_TERMINAL_PROMPT:`0`};var ENe=class{constructor(e){this.commands=e}async clone(e,t){var n=this;let r=t??{},{username:i,password:a,branch:o,depth:s,path:c,dangerouslyStoreCredentials:l}=r,u=RB(r,pNe);if(a&&!i)throw new JR(`Username is required when using a password or token for git clone.`);let d=async(t,r)=>{let i=t&&r?kB(e,t,r):e,a=aNe(i),d=!l&&a!==i,f=d?c??oNe(e):c;if(d&&!f)throw new JR(`A destination path is required when using credentials without storing them.`);let p=[`clone`,i];o&&p.push(`--branch`,o,`--single-branch`),s&&p.push(`--depth`,s.toString()),f&&p.push(f);let m=await n.runGit(p,void 0,u);return d&&await n.runGit([`remote`,`set-url`,`origin`,a],f,u),m};try{return await d(i,a)}catch(e){throw MB(e)?new tz(FB(`clone`,!!i&&!a)):e}}async init(e,t){var n=this;let r=t??{},{bare:i,initialBranch:a}=r,o=RB(r,mNe),s=[`init`];return a&&s.push(`--initial-branch`,a),i&&s.push(`--bare`),s.push(e),n.runGit(s,void 0,o)}async remoteAdd(e,t,n,r){var i=this;if(!t||!n)throw new JR(`Both remote name and URL are required to add a git remote.`);let a=r??{},{fetch:o,overwrite:s}=a,c=RB(a,hNe),l=[`remote`,`add`];if(o&&l.push(`-f`),l.push(t,n),!s)return i.runGit(l,e,c);let u=`${AB(l,e)} || ${AB([`remote`,`set-url`,t,n],e)}`;if(o){let n=AB([`fetch`,t],e);u=`(${u}) && ${n}`}return i.runShell(u,c)}async remoteGet(e,t,n){var r=this;if(!t)throw new JR(`Remote name is required.`);let i=`${AB([`remote`,`get-url`,t],e)} || true`,a=(await r.runShell(i,n)).stdout.trim();return a.length>0?a:void 0}async status(e,t){return uNe((await this.runGit([`status`,`--porcelain=1`,`-b`],e,t)).stdout)}async branches(e,t){return dNe((await this.runGit([`branch`,`--format=%(refname:short) %(HEAD)`],e,t)).stdout)}async createBranch(e,t,n){return this.runGit([`checkout`,`-b`,t],e,n)}async checkoutBranch(e,t,n){return this.runGit([`checkout`,t],e,n)}async deleteBranch(e,t,n){var r=this;let i=n??{},{force:a}=i,o=RB(i,gNe),s=[`branch`,a?`-D`:`-d`,t];return r.runGit(s,e,o)}async add(e,t){var n=this;let r=t??{},{files:i,all:a=!0}=r,o=RB(r,_Ne),s=[`add`];return!i||i.length===0?s.push(a?`-A`:`.`):s.push(`--`,...i),n.runGit(s,e,o)}async commit(e,t,n){var r=this;let i=n??{},{authorName:a,authorEmail:o,allowEmpty:s}=i,c=RB(i,vNe),l=[`commit`,`-m`,t];s&&l.push(`--allow-empty`);let u=[];return a&&u.push(`-c`,`user.name=${a}`),o&&u.push(`-c`,`user.email=${o}`),r.runGit([...u,...l],e,c)}async reset(e,t){var n=this;let r=t??{},{mode:i,target:a,paths:o}=r,s=RB(r,yNe),c=[`soft`,`mixed`,`hard`,`merge`,`keep`];if(i&&!c.includes(i))throw new JR(`Reset mode must be one of ${c.join(`, `)}.`);let l=[`reset`];return i&&l.push(`--${i}`),a&&l.push(a),o&&o.length>0&&l.push(`--`,...o),n.runGit(l,e,s)}async restore(e,t){var n=this;let{paths:r,staged:i,worktree:a,source:o}=t,s=RB(t,bNe);if(!r||r.length===0)throw new JR(`At least one path is required.`);let c=i,l=a;if(i===void 0&&a===void 0?l=!0:i===!0&&a===void 0?l=!1:i===void 0&&a!==void 0&&(c=!1),c===!1&&l===!1)throw new JR(`At least one of staged or worktree must be true.`);let u=[`restore`];return l&&u.push(`--worktree`),c&&u.push(`--staged`),o&&u.push(`--source`,o),u.push(`--`,...r),n.runGit(u,e,s)}async push(e,t){var n=this;let r=t??{},{remote:i,branch:a,setUpstream:o=!0,username:s,password:c}=r,l=RB(r,xNe);if(c&&!s)throw new JR(`Username is required when using a password or token for git push.`);if(s&&c){let t=await n.resolveRemoteName(e,i,l);return n.withRemoteCredentials(e,t,s,c,l,()=>n.runGit(jB(t,{remote:i,branch:a,setUpstream:o}),e,l))}try{return await n.runGit(jB(void 0,{remote:i,branch:a,setUpstream:o}),e,l)}catch(e){throw MB(e)?new tz(FB(`push`,!!s&&!c)):PB(e)?new nz(IB(`push`)):e}}async pull(e,t){var n=this;let r=t??{},{remote:i,branch:a,username:o,password:s}=r,c=RB(r,SNe);if(s&&!o)throw new JR(`Username is required when using a password or token for git pull.`);if(!i&&!a&&!await n.hasUpstream(e,c))throw new nz(IB(`pull`));let l=e=>{let t=[`pull`],n=e??i;return n&&t.push(n),a&&t.push(a),t};if(o&&s){let t=await n.resolveRemoteName(e,i,c);return n.withRemoteCredentials(e,t,o,s,c,()=>n.runGit(l(t),e,c))}try{return await n.runGit(l(),e,c)}catch(e){throw MB(e)?new tz(FB(`pull`,!!o&&!s)):PB(e)?new nz(IB(`pull`)):e}}async setConfig(e,t,n){var r=this;if(!e)throw new JR(`Git config key is required.`);let i=n?.scope??`global`,a=NB(i),o=LB(i,n?.path);return r.runGit([`config`,a,e,t],o,n)}async getConfig(e,t){var n=this;if(!e)throw new JR(`Git config key is required.`);let r=t?.scope??`global`,i=NB(r),a=LB(r,t?.path),o=`${AB([`config`,i,`--get`,e],a)} || true`,s=(await n.runShell(o,t)).stdout.trim();return s.length>0?s:void 0}async dangerouslyAuthenticate(e){var t=this;let{username:n,password:r,host:i,protocol:a}=e,o=RB(e,CNe);if(!n||!r)throw new JR(`Both username and password are required to authenticate git.`);let s=(i??`github.com`).trim(),c=[`protocol=${(a??`https`).trim()}`,`host=${s}`,`username=${n}`,`password=${r}`,``,``].join(`
462
+ `);await t.runGit([`config`,`--global`,`credential.helper`,`store`],void 0,o);let l=`printf %s ${yz(c)} | ${AB([`credential`,`approve`])}`;return t.runShell(l,o)}async configureUser(e,t,n){var r=this;if(!e||!t)throw new JR(`Both name and email are required.`);let i=n?.scope??`global`,a=U(U({},n),{},{scope:i});return await r.setConfig(`user.name`,e,a),r.setConfig(`user.email`,t,a)}async runGit(e,t,n){var r=this;let i=n??{},{envs:a}=i,o=RB(i,wNe),s=AB(e,t),c=U(U({},zB),a??{});return r.commands.run(s,U(U({},o),{},{envs:c}))}async runShell(e,t){var n=this;let r=t??{},{envs:i}=r,a=RB(r,TNe),o=U(U({},zB),i??{});return n.commands.run(e,U(U({},a),{},{envs:o}))}async getRemoteUrl(e,t,n){let r=(await this.runGit([`remote`,`get-url`,t],e,n)).stdout.trim();if(!r)throw new JR(`Remote "${t}" URL not found in repository.`);return r}async resolveRemoteName(e,t,n){var r=this;if(t)return t;let i=(await r.runGit([`remote`],e,n)).stdout.split(`
463
+ `).map(e=>e.trim()).filter(Boolean);if(i.length===1)return i[0];throw new JR(`Remote is required when using username/password and the repository has multiple remotes.`)}async withRemoteCredentials(e,t,n,r,i,a){var o=this;let s=await o.getRemoteUrl(e,t,i),c=kB(s,n,r);await o.runGit([`remote`,`set-url`,t,c],e,i);let l,u;try{l=await a()}catch(e){u=e}let d;try{await o.runGit([`remote`,`set-url`,t,s],e,i)}catch(e){d=e}if(u)throw u;if(d)throw d;return l}async hasUpstream(e,t){var n=this;try{return(await n.runGit([`rev-parse`,`--abbrev-ref`,`--symbolic-full-name`,`@{u}`],e,t)).stdout.trim().length>0}catch{return!1}}};function DNe(e){let t=e[Symbol.asyncIterator]();return new ReadableStream({async pull(e){try{let{done:n,value:r}=await t.next();n?e.close():e.enqueue(r)}catch(t){e.error(t)}},async cancel(e){await t.return?.call(t,e)}})}function ONe(e){return{[Symbol.asyncIterator](){return Hz(function*(){if(!e)return;let t=e.getReader();try{for(;;){let{done:e,value:n}=yield Vz(t.read());if(e)return;yield n}}finally{t.releaseLock()}})()}}}function kNe(e){return async t=>{let n=await e(t.url,{method:t.method,headers:t.header,body:t.body?DNe(t.body):void 0,signal:t.signal,duplex:`half`});return{status:n.status,header:n.headers,body:ONe(n.body),trailer:new Headers}}}function ANe({baseUrl:e,fetch:t,interceptors:n=[]}){return WAe({baseUrl:e,httpClient:kNe(t),useBinaryFormat:!1,interceptors:n,acceptCompression:[],sendCompression:null,compressMinBytes:1024,readMaxBytes:4294967295,writeMaxBytes:4294967295})}var jNe=class{constructor(e,t,n,r){this.transport=e,this.envdApi=t,this.connectionConfig=n,H(this,`rpc`,void 0),H(this,`streamingRpc`,void 0),H(this,`envdVersion`,void 0),H(this,`checkHealth`,void 0),H(this,`defaultPtyConnectionTimeout`,6e4),this.rpc=sL(aB,this.transport),this.streamingRpc=sL(aB,r),this.envdVersion=t.version,this.checkHealth=()=>pB(this.envdApi)}async create(e){var t=this;let n=e?.requestTimeoutMs??t.connectionConfig.requestTimeoutMs,r=U({},e?.envs??{});r.TERM=r.TERM??`xterm-256color`,r.LANG=r.LANG??`C.UTF-8`,r.LC_ALL=r.LC_ALL??`C.UTF-8`;let{controller:i,clearStartTimeout:a,cleanup:o}=Oz(n,e?.signal),s=t.rpc.start({process:{cmd:`/bin/bash`,args:[`-i`,`-l`],envs:r,cwd:e?.cwd},pty:{size:{cols:e.cols,rows:e.rows}}},{headers:U(U({},dB(t.envdVersion,e?.user)),{},{[Ez]:`50`}),signal:i.signal,timeoutMs:e?.timeoutMs??t.defaultPtyConnectionTimeout});try{let n=await _B(s);return a(),new TB(n,o,()=>t.kill(n),s,void 0,void 0,e.onData,void 0,void 0,t.checkHealth)}catch(e){throw o(),await lB(e,t.checkHealth)}}async connect(e,t){var n=this;let{controller:r,clearStartTimeout:i,cleanup:a}=Oz(t?.requestTimeoutMs??n.connectionConfig.requestTimeoutMs,t?.signal),o=n.rpc.connect({process:{selector:{case:`pid`,value:e}}},{signal:r.signal,headers:{[Ez]:`50`},timeoutMs:t?.timeoutMs??n.defaultPtyConnectionTimeout});try{let e=await _B(o);return i(),new TB(e,a,()=>n.kill(e),o,void 0,void 0,t?.onData,void 0,void 0,n.checkHealth)}catch(e){throw a(),await lB(e,n.checkHealth)}}async sendInput(e,t,n){var r=this;try{await r.rpc.sendInput({input:{input:{case:`pty`,value:t}},process:{selector:{case:`pid`,value:e}}},{signal:r.connectionConfig.getSignal(n?.requestTimeoutMs,n?.signal)})}catch(e){throw await lB(e,r.checkHealth)}}streamInput(e,t={}){return new DB(this.streamingRpc,e,`pty`,t,this.checkHealth)}async resize(e,t,n){var r=this;try{await r.rpc.update({process:{selector:{case:`pid`,value:e}},pty:{size:t}},{signal:r.connectionConfig.getSignal(n?.requestTimeoutMs,n?.signal)})}catch(e){throw await lB(e,r.checkHealth)}}async kill(e,t){var n=this;return uB(n.rpc,e,n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal),n.checkHealth)}},MNe=class{constructor(e,t,n,r){this.envdApi=t,this.connectionConfig=n,H(this,`rpc`,void 0),H(this,`streamingRpc`,void 0),H(this,`defaultProcessConnectionTimeout`,6e4),H(this,`envdVersion`,void 0),H(this,`checkHealth`,void 0),this.rpc=sL(aB,e),this.streamingRpc=sL(aB,r),this.envdVersion=t.version,this.checkHealth=()=>pB(this.envdApi)}get supportsStdinClose(){return yP(this.envdVersion,`0.5.2`)>=0}async list(e){var t=this;try{return(await t.rpc.list({},{signal:t.connectionConfig.getSignal(e?.requestTimeoutMs,e?.signal)})).processes.map(e=>U(U({pid:e.pid},e.tag&&{tag:e.tag}),{},{args:e.config.args,envs:e.config.envs,cmd:e.config.cmd},e.config.cwd&&{cwd:e.config.cwd}))}catch(e){throw await lB(e,t.checkHealth)}}async sendStdin(e,t,n){var r=this;try{let i=typeof t==`string`?new TextEncoder().encode(t):t;await r.rpc.sendInput({process:{selector:{case:`pid`,value:e}},input:{input:{case:`stdin`,value:i}}},{signal:r.connectionConfig.getSignal(n?.requestTimeoutMs,n?.signal)})}catch(e){throw await lB(e,r.checkHealth)}}streamInput(e,t={}){return new DB(this.streamingRpc,e,`stdin`,t,this.checkHealth)}async closeStdin(e,t){var n=this;if(!n.supportsStdinClose)throw new KR(`Sandbox envd version ${n.envdVersion} doesn't support closeStdin. Please rebuild your template to pick up the latest sandbox version.`);try{await n.rpc.closeStdin({process:{selector:{case:`pid`,value:e}}},{signal:n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal)})}catch(e){throw await lB(e,n.checkHealth)}}async kill(e,t){var n=this;return uB(n.rpc,e,n.connectionConfig.getSignal(t?.requestTimeoutMs,t?.signal),n.checkHealth)}async connect(e,t){var n=this;let{controller:r,clearStartTimeout:i,cleanup:a}=Oz(t?.requestTimeoutMs??n.connectionConfig.requestTimeoutMs,t?.signal),o=n.rpc.connect({process:{selector:{case:`pid`,value:e}}},{signal:r.signal,headers:{[Ez]:`50`},timeoutMs:t?.timeoutMs??n.defaultProcessConnectionTimeout});return n.createHandle(o,i,a,t)}async run(e,t){let n=await this.start(e,t);return t?.background?n:n.wait()}async start(e,t){var n=this;if(t?.stdin===!1&&yP(n.envdVersion,`0.3.0`)<0)throw new KR(`Sandbox envd version ${n.envdVersion} can't specify stdin, it's always turned on. Please rebuild your template if you need this feature.`);let{controller:r,clearStartTimeout:i,cleanup:a}=Oz(t?.requestTimeoutMs??n.connectionConfig.requestTimeoutMs,t?.signal),o=n.rpc.start({process:{cmd:`/bin/bash`,cwd:t?.cwd,envs:t?.envs,args:[`-l`,`-c`,e]},stdin:t?.stdin||!1},{headers:U(U({},dB(n.envdVersion,t?.user)),{},{[Ez]:`50`}),signal:r.signal,timeoutMs:t?.timeoutMs??n.defaultProcessConnectionTimeout});return n.createHandle(o,i,a,t)}async createHandle(e,t,n,r){var i=this;try{let a=await _B(e);return t(),new TB(a,n,()=>i.kill(a),e,r?.onStdout,r?.onStderr,void 0,(e,t)=>i.sendStdin(a,e,t),e=>i.closeStdin(a,e),i.checkHealth,r?.retainOutput??!0)}catch(e){throw n(),await lB(e,i.checkHealth)}}};const NNe=RegExp(`[{}\\p{Cc}]`,`u`),PNe=new Set([`toJSON`,`then`,`toString`,`valueOf`]);function FNe(e,t,n){let r=e===`toString`?()=>Object.prototype.toString.call(t()):e===`valueOf`?()=>t():{};return Object.defineProperty(r,Symbol.toPrimitive,{value:n}),Object.defineProperty(r,"toJSON",{value:n,enumerable:!0})}function BB(e){if(e.length===0||NNe.test(e))throw new JR(`iam token name ${JSON.stringify(e)} is not usable: a token name cannot be empty or contain '{', '}' or control characters, because it is interpolated into the '\${e2b.identity.tokens.<name>}' placeholder the egress proxy resolves.`)}function VB(e){return BB(e),`\${e2b.identity.tokens.${e}}`}function INe(e,{validate:t}){let n={};for(let t of e)n[t]=VB(t);let r=n=>{if(!t)return VB(n);throw new JR(`Network transform references iam token '${n}', which is not registered. ${e.length===0?`Pass it to Sandbox.create as iam: { tokens: { '${n}': Secret.iamToken({ audience, tokenType }) } }.`:`Registered tokens: ${e.map(e=>`'${e}'`).join(`, `)}.`}`)},i=new Proxy(n,{get(e,t,n){return typeof t==`string`&&!Object.hasOwn(e,t)?PNe.has(t)?FNe(t,()=>i,()=>r(t)):r(t):Reflect.get(e,t,n)},has(e,t){return Object.hasOwn(e,t)}});return i}const HB=[`full`,`filesystem`];function UB(e,t,n){if(t!=null&&n!=null)throw new JR(`Pass either ${e} or the deprecated keepMemory, not both.`);if(t==null)return n??void 0;if(!HB.includes(t))throw new JR(`${e} must be one of: ${HB.join(`, `)} (got ${JSON.stringify(t)}).`);return t===`full`}function LNe(e){if(e!==void 0&&(!Number.isInteger(e)||e<1||e>20))throw new JR(`count must be an integer between 1 and 20`)}function WB(e){return{sandboxId:e.sandboxID,sandboxDomain:e.domain||void 0,envdVersion:e.envdVersion,envdAccessToken:e.envdAccessToken,trafficAccessToken:e.trafficAccessToken||void 0}}function GB(e,t){if(e!==void 0)return typeof e==`function`?e({allTraffic:`0.0.0.0/0`,rules:t}):e}function KB(e,{validate:t}){return{iam:{tokens:INe(e,{validate:t})}}}function qB(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function RNe(e){return e===null?`null`:typeof e==`object`?Array.isArray(e)?`array`:e.constructor?.name??`object`:typeof e}function zNe(e,t){let n={};for(let[r,i]of e)n[r]=i.map(e=>{if(e.transform==null)return{};if(typeof e.transform!=`function`)return{transform:e.transform};let n=e.transform(t);if(typeof n?.then==`function`)throw Promise.resolve(n).catch(()=>{}),new JR(`Network transform callback for '${r}' must be synchronous, it returned a promise. Resolve the value before creating the sandbox.`);if(!qB(n))throw new JR(`Network transform callback for '${r}' must return a transform object, got ${RNe(n)}.`);return{transform:n}});return n}function BNe(e){if(!qB(e)||typeof e.address!=`string`)throw new JR(`network egressProxy must be an object with a string 'address' (e.g. 'proxy.example.com:1080').`);let t=e.tls;if(t!=null&&typeof t!=`boolean`&&!qB(t))throw new JR(`network egressProxy tls must be a boolean or an object.`);if(qB(t)&&Object.prototype.hasOwnProperty.call(t,`enabled`))throw new JR(`network egressProxy tls takes no 'enabled'; pass tls: true or tls: false instead.`);let n=t===!0?{enabled:!0}:typeof t==`object`&&t?U(U({enabled:!0},t.serverName==null?{}:{serverName:t.serverName}),t.caCert==null?{}:{caCert:t.caCert}):void 0;return U(U(U({address:e.address},e.username==null?{}:{username:e.username}),e.password==null?{}:{password:e.password}),n===void 0?{}:{tls:n})}function JB(e,t){let n=e.rules instanceof Map?e.rules:new Map(Object.entries(e.rules??{})),r=GB(e.allowOut,n),i=GB(e.denyOut,n);return U(U(U(U(U({},r===void 0?{}:{allowOut:r}),i===void 0?{}:{denyOut:i}),e.egressProxy==null?{}:{egressProxy:BNe(e.egressProxy)}),e.dnsServers==null?{}:{dnsServers:[...e.dnsServers]}),e.rules===void 0?{}:{rules:zNe(n,t)})}function VNe(e){if(e)return U(U({address:e.address},e.username===void 0?{}:{username:e.username}),e.tls?.enabled===!0?{tls:U({},e.tls.serverName===void 0?{}:{serverName:e.tls.serverName})}:{})}function HNe(e,t){if(e)return U(U(U(U({},JB(e,KB(Object.keys(t?.tokens??{}),{validate:!0}))),e.allowPublicTraffic===void 0?{}:{allowPublicTraffic:e.allowPublicTraffic}),e.maskRequestHost===void 0?{}:{maskRequestHost:e.maskRequestHost}),e.httpsPorts===void 0?{}:{httpsPorts:e.httpsPorts})}function UNe(e){let t={};for(let[n,r]of Object.entries(e?.tokens??{}))if(r){if(typeof r.audience!=`string`||typeof r.tokenType!=`string`)throw new JR(`iam token '${n}' must have string 'audience' and 'tokenType' properties.`);BB(n),t[n]={audience:r.audience,tokenType:r.tokenType}}if(Object.keys(t).length!==0)return{tokens:t}}function WNe(e){return U(U({},JB(e,KB([],{validate:!1}))),e.allowInternetAccess===void 0?{}:{allow_internet_access:e.allowInternetAccess})}var YB=class extends jz{constructor(){super()}static async kill(e,t){let n=this.resolveOpts(t),r=new Az(n);if(r.debug)return!0;let i=await new Jz(r).api.DELETE(`/sandboxes/{sandboxID}`,{params:{path:{sandboxID:e}},signal:r.getSignal(n?.requestTimeoutMs,n?.signal)});if(i.error?.code===404)return!1;let a=qz(i);if(a)throw a;return!0}static async getInfo(e,t){let n=this.resolveOpts(t),r=new Az(n),i=await new Jz(r).api.GET(`/sandboxes/{sandboxID}`,{params:{path:{sandboxID:e}},signal:r.getSignal(n?.requestTimeoutMs,n?.signal)});if(i.error?.code===404)throw new ZR(`Sandbox ${e} not found`);let a=qz(i);if(a)throw a;if(!i.data)throw Error(`Sandbox not found`);return U(U({sandboxId:i.data.sandboxID,templateId:i.data.templateID},i.data.alias&&{name:i.data.alias}),{},{metadata:i.data.metadata??{},allowInternetAccess:i.data.allowInternetAccess??void 0,envdVersion:i.data.envdVersion,startedAt:new Date(i.data.startedAt),endAt:new Date(i.data.endAt),state:i.data.state,cpuCount:i.data.cpuCount,memoryMB:i.data.memoryMB,network:i.data.network?U(U({allowOut:i.data.network.allowOut,denyOut:i.data.network.denyOut,rules:i.data.network.rules??void 0,egressProxy:VNe(i.data.network.egressProxy)},i.data.network.dnsServers===void 0?{}:{dnsServers:i.data.network.dnsServers}),{},{allowPublicTraffic:i.data.network.allowPublicTraffic??void 0,maskRequestHost:i.data.network.maskRequestHost,httpsPorts:i.data.network.httpsPorts}):void 0,lifecycle:i.data.lifecycle?{onTimeout:i.data.lifecycle.onTimeout,autoResume:i.data.lifecycle.autoResume}:void 0,sandboxDomain:i.data.domain||void 0,volumeMounts:i.data.volumeMounts??[],envdUnresponsiveAtPause:i.data.envdUnresponsiveAtPause||void 0})}static async getFullInfo(e,t){return await this.getInfo(e,t)}static async getMetrics(e,t){let n=this.resolveOpts(t),r=new Az(n);if(r.debug)return[];let i=new Jz(r),a=n?.start?Math.round(n.start.getTime()/1e3):void 0,o=n?.end?Math.round(n.end.getTime()/1e3):void 0,s=await i.api.GET(`/sandboxes/{sandboxID}/metrics`,{params:{path:{sandboxID:e},query:{start:a,end:o}},signal:r.getSignal(n?.requestTimeoutMs,n?.signal)});if(s.error?.code===404)throw new ZR(`Sandbox ${e} not found`);let c=qz(s);if(c)throw c;return s.data?.map(e=>({timestamp:new Date(e.timestamp),cpuUsedPct:e.cpuUsedPct,cpuCount:e.cpuCount,memUsed:e.memUsed,memTotal:e.memTotal,memCache:e.memCache,diskUsed:e.diskUsed,diskTotal:e.diskTotal}))??[]}static async setTimeout(e,t,n){let r=this.resolveOpts(n),i=new Az(r),a=await new Jz(i).api.POST(`/sandboxes/{sandboxID}/timeout`,{params:{path:{sandboxID:e}},body:{timeout:fz(t)},signal:i.getSignal(r?.requestTimeoutMs,r?.signal)});if(a.error?.code===404)throw new ZR(`Sandbox ${e} not found`);let o=qz(a);if(o)throw o}static async updateNetwork(e,t,n){let r=this.resolveOpts(n),i=new Az(r),a=await new Jz(i).api.PUT(`/sandboxes/{sandboxID}/network`,{params:{path:{sandboxID:e}},body:WNe(t),signal:i.getSignal(r?.requestTimeoutMs,r?.signal)});if(a.error?.code===404)throw new ZR(`Sandbox ${e} not found`);let o=qz(a);if(o)throw o}static async pause(e,t){let n=this.resolveOpts(t),r=UB(`mode`,n?.mode,n?.keepMemory),i=new Az(n),a=await new Jz(i).api.POST(`/sandboxes/{sandboxID}/pause`,{params:{path:{sandboxID:e}},body:{memory:r,requireHealthyGuest:n?.strict?!0:void 0},signal:i.getSignal(n?.requestTimeoutMs,n?.signal)});if(a.error?.code===404)throw new ZR(`Sandbox ${e} not found`);if(a.error?.code===409)return!1;let o=qz(a);if(o)throw o;return!0}static async betaPause(e,t){return this.pause(e,t)}static async createSnapshot(e,t){let n=this.resolveOpts(t),r=new Az(n),i=await new Jz(r).api.POST(`/sandboxes/{sandboxID}/snapshots`,{params:{path:{sandboxID:e}},body:U(U({},n?.name?{name:n.name}:{}),{},{memory:UB(`mode`,n?.mode)}),signal:r.getSignal(n?.requestTimeoutMs,n?.signal)});if(i.error?.code===404)throw new ZR(`Sandbox ${e} not found`);let a=qz(i);if(a)throw a;return{snapshotId:i.data.snapshotID,names:i.data.names??[]}}static listSnapshots(e){return new KNe(this.resolveOpts(e))}static async deleteSnapshot(e,t){let n=this.resolveOpts(t),r=new Az(n),i=await new Jz(r).api.DELETE(`/templates/{templateID}`,{params:{path:{templateID:e}},signal:r.getSignal(n?.requestTimeoutMs,n?.signal)});if(i.error?.code===404)return!1;let a=qz(i);if(a)throw a;return!0}static async createSandbox(e,t,n){var r=this,i,a;let o=hMe(n?.idempotencyKey),s=n==null||(i=n.lifecycle)==null?void 0:i.onTimeout,c=s!=null,l=s??`kill`,u=typeof l==`string`?l:l.action,d=[`pause`,`kill`];if(c&&!d.includes(u))throw new JR(`${typeof l==`string`?`onTimeout`:`onTimeout.action`} must be one of: ${d.join(`, `)} (got ${JSON.stringify(u)}).`);let f=typeof l==`string`?{}:l,p=`mode`in f||`keepMemory`in f,m=(n==null||(a=n.lifecycle)==null?void 0:a.autoResume)??void 0;if(p&&u!==`pause`)throw new JR(`onTimeout.mode is only allowed when action is 'pause'.`);let h=UB(`onTimeout.mode`,f.mode,f.keepMemory);if(m&&u!==`pause`)throw new JR(`autoResume can only be true when onTimeout action is 'pause'.`);if(h===!1&&m)throw new JR(`autoResume: true is not a valid value with mode: 'filesystem' - a filesystem-only snapshot cannot be auto-resumed by traffic and must be resumed explicitly using Sandbox.connect().`);let g=UNe(n?.iam),_={templateID:e,metadata:n?.metadata,mcp:n?.mcp,envVars:n?.envs,timeout:t===void 0?void 0:fz(t),allow_internet_access:n?.allowInternetAccess,network:HNe(n?.network,g),iam:g,autoPause:c?u===`pause`:void 0,autoPauseMemory:u===`pause`?h:void 0,autoResume:m===void 0?void 0:{enabled:m}};n?.volumeMounts&&(_.volumeMounts=Object.entries(n.volumeMounts).map(([e,t])=>({name:typeof t==`string`?t:t.name,path:e})));let v=r.resolveOpts(n),y=new Az(v),b=await new Jz(y).api.POST(`/v2/sandboxes`,{body:_,params:o===void 0?void 0:{header:{"Idempotency-Key":o}},signal:y.getSignal(v?.requestTimeoutMs,v?.signal)}),ee=qz(b);if(ee)throw ee;if(yP(b.data.envdVersion,`0.1.0`)<0)throw await r.kill(b.data.sandboxID,v),new rz(`You need to update the template to use the new SDK.`);return WB(b.data)}static async forkSandbox(e,t,n,r){var i=this;LNe(n);let a=i.resolveOpts(r),o=new Az(a),s=await new Jz(o).api.POST(`/sandboxes/{sandboxID}/fork`,{params:{path:{sandboxID:e}},body:{timeout:t===void 0?void 0:fz(t),count:n},signal:o.getSignal(a?.requestTimeoutMs,a?.signal)});if(s.response.status===404)throw new ZR(s.error?.message??`Sandbox ${e} not found`);let c=qz(s);if(c)throw c;return(s.data??[]).map(e=>e.error||!e.sandbox?e.error?e.error.code===404?new YR(`${e.error.code}: ${e.error.message}`):Kz(e.error.code,e.error.message):new KR(`Failed to start forked sandbox`):WB(e.sandbox))}static async connectSandbox(e,t){let n=this.resolveOpts(t),r=n?.timeoutMs,i=n?.onResume??void 0,a=[`restore`,`reboot`];if(i!==void 0&&!a.includes(i))throw new JR(`onResume must be one of: ${a.join(`, `)} (got ${JSON.stringify(i)}).`);let o=new Az(n),s=await new Jz(o).api.POST(`/v2/sandboxes/{sandboxID}/connect`,{params:{path:{sandboxID:e}},body:{timeout:r===void 0?void 0:fz(r),memory:i!==`reboot`&&void 0},signal:o.getSignal(n?.requestTimeoutMs,n?.signal)});if(s.error?.code===404)throw new ZR(`Paused sandbox ${e} not found`);let c=qz(s);if(c)throw c;return WB(s.data)}},GNe=class extends OB{constructor(e){super(e,e?.limit,e?.nextToken),H(this,`query`,void 0),H(this,`order`,void 0),this.query=e?.query,this.order=e?.order}async nextItems(e){var t=this,n;if(!t.hasNext)throw Error(`No more items to fetch`);let r;if(t.query?.metadata){let e=Object.fromEntries(Object.entries(t.query.metadata).map(([e,t])=>[encodeURIComponent(e),encodeURIComponent(t)]));r=new URLSearchParams(e).toString()}let i=Az.mergeOpts(t.opts,e),a=new Az(i),o=await new Jz(a).api.GET(`/v2/sandboxes`,{params:{query:{metadata:r,state:t.query?.state,startedAfter:(n=t.query)==null||(n=n.startedAfter)==null?void 0:n.toISOString(),template:t.query?.template||void 0,order:t.order,limit:t.limit,nextToken:t.nextToken}},signal:a.getSignal(i?.requestTimeoutMs,i?.signal)}),s=qz(o);if(s)throw s;return t.updatePagination(o.response),(o.data??[]).map(e=>U(U({sandboxId:e.sandboxID,templateId:e.templateID},e.alias&&{name:e.alias}),{},{metadata:e.metadata??{},startedAt:new Date(e.startedAt),endAt:new Date(e.endAt),state:e.state,cpuCount:e.cpuCount,memoryMB:e.memoryMB,envdVersion:e.envdVersion,volumeMounts:e.volumeMounts??[],envdUnresponsiveAtPause:e.envdUnresponsiveAtPause||void 0}))}},KNe=class extends OB{constructor(e){super(e,e?.limit,e?.nextToken),H(this,`sandboxId`,void 0),H(this,`name`,void 0),this.sandboxId=e?.sandboxId,this.name=e?.name}async nextItems(e){var t=this;if(!t.hasNext)throw Error(`No more items to fetch`);let n=Az.mergeOpts(t.opts,e),r=new Az(n),i=await new Jz(r).api.GET(`/snapshots`,{params:{query:{sandboxID:t.sandboxId,name:t.name,limit:t.limit,nextToken:t.nextToken}},signal:r.getSignal(n?.requestTimeoutMs,n?.signal)}),a=qz(i);if(a)throw a;return t.updatePagination(i.response),(i.data??[]).map(e=>({snapshotId:e.snapshotID,names:e.names??[]}))}},XB=class extends YB{constructor(e){super(),H(this,`files`,void 0),H(this,`commands`,void 0),H(this,`pty`,void 0),H(this,`git`,void 0),H(this,`sandboxId`,void 0),H(this,`sandboxDomain`,void 0),H(this,`trafficAccessToken`,void 0),H(this,`envdPort`,49983),H(this,`mcpPort`,50005),H(this,`connectionConfig`,void 0),H(this,`envdAccessToken`,void 0),H(this,`envdApiUrl`,void 0),H(this,`envdDirectUrl`,void 0),H(this,`envdApi`,void 0),H(this,`mcpToken`,void 0),this.connectionConfig=new Az(e),this.sandboxId=e.sandboxId,this.sandboxDomain=e.sandboxDomain??this.connectionConfig.domain,this.envdAccessToken=e.envdAccessToken,this.trafficAccessToken=e.trafficAccessToken,this.envdApiUrl=this.connectionConfig.getSandboxUrl(this.sandboxId,{sandboxDomain:this.sandboxDomain,envdPort:this.envdPort}),this.envdDirectUrl=this.connectionConfig.getSandboxDirectUrl(this.sandboxId,{sandboxDomain:this.sandboxDomain,envdPort:this.envdPort});let t={"E2b-Sandbox-Id":this.sandboxId,"E2b-Sandbox-Port":this.envdPort.toString()},n=MMe(this.connectionConfig),r=NMe(this.connectionConfig),i=e?.logger?[jMe(e.logger)]:void 0,a=(e,n)=>{let i=new Headers({"User-Agent":this.connectionConfig.headers?.[`User-Agent`]??``});return new Headers(n?.headers).forEach((e,t)=>i.append(t,e)),new Headers(t).forEach((e,t)=>i.append(t,e)),this.envdAccessToken&&i.append(`X-Access-Token`,this.envdAccessToken),n=U(U({},n??{}),{},{headers:i,redirect:`follow`}),r(e,n).then(WMe)},o=qAe({baseUrl:this.envdApiUrl,useBinaryFormat:!1,interceptors:i,fetch:a}),s=ANe({baseUrl:this.envdApiUrl,fetch:a,interceptors:i});this.envdApi=new qMe({apiUrl:this.envdApiUrl,logger:e?.logger,envdAccessToken:this.envdAccessToken,headers:U({"User-Agent":this.connectionConfig.headers?.[`User-Agent`]??``},t),fetch:e=>n(e)},{version:e.envdVersion}),this.files=new iNe(o,this.envdApi,this.connectionConfig),this.commands=new MNe(o,this.envdApi,this.connectionConfig,s),this.pty=new jNe(o,this.envdApi,this.connectionConfig,s),this.git=new ENe(this.commands)}static list(e){return new GNe(this.resolveOpts(e))}static async create(e,t){var n=this;let{template:r,sandboxOpts:i}=typeof e==`string`?{template:e,sandboxOpts:t}:{template:e?.template??(e?.mcp?n.defaultMcpTemplate:n.defaultTemplate),sandboxOpts:e},a=n.resolveOpts(i),o=new Az(a);if(o.debug)return new n(U({sandboxId:`debug_sandbox_id`,envdVersion:tB},o));let s=new n(U(U({},await n.createSandbox(r,a?.timeoutMs,a)),o));if(i?.mcp){s.mcpToken=crypto.randomUUID();try{await s.commands.run(`mcp-gateway --config ${yz(JSON.stringify(i.mcp))}`,{user:`root`,envs:{GATEWAY_ACCESS_TOKEN:s.mcpToken??``}})}catch(e){throw await s.kill().catch(()=>void 0),e instanceof wB?new KR(`Failed to start MCP gateway: ${e.stderr}`):e}}return s}static async connect(e,t){var n=this;let r=n.resolveOpts(t),i=new Az(r);if(i.debug)return new n(U({sandboxId:e,envdVersion:tB},i));let a=await n.connectSandbox(e,r);return new n(U({sandboxId:e,sandboxDomain:a.sandboxDomain,envdAccessToken:a.envdAccessToken,trafficAccessToken:a.trafficAccessToken,envdVersion:a.envdVersion},i))}static async fork(e,t){var n=this;let r=n.resolveOpts(t),i=new Az(r);return(await n.forkSandbox(e,r?.timeoutMs,r?.count,r)).map(e=>e instanceof Error?e:new n(U(U({},e),i)))}async connect(e){var t=this;return t.connectionConfig.debug||await YB.connectSandbox(t.sandboxId,t.resolveApiOpts(e)),t}async fork(e){var t=this;return await t.constructor.fork(t.sandboxId,t.resolveApiOpts(e))}getHost(e){return this.connectionConfig.getHost(this.sandboxId,e,this.sandboxDomain)}async isRunning(e){var t=this;let n=t.connectionConfig.getSignal(e?.requestTimeoutMs,e?.signal),r=await t.envdApi.api.GET(`/health`,{signal:n});if(r.response.status==502)return!1;let i=await gB(r);if(i)throw i;return!0}async setTimeout(e,t){var n=this;n.connectionConfig.debug||await YB.setTimeout(n.sandboxId,e,n.resolveApiOpts(t))}async updateNetwork(e,t){var n=this;await YB.updateNetwork(n.sandboxId,e,n.resolveApiOpts(t))}async kill(e){var t=this;return t.connectionConfig.debug?!0:await YB.kill(t.sandboxId,t.resolveApiOpts(e))}async pause(e){var t=this;return await YB.pause(t.sandboxId,t.resolveApiOpts(e))}async betaPause(e){var t=this;return await YB.betaPause(t.sandboxId,t.resolveApiOpts(e))}async createSnapshot(e){var t=this;return await YB.createSnapshot(t.sandboxId,U(U({},t.resolveApiOpts(e)),{},{name:e?.name,mode:e?.mode}))}listSnapshots(e){return YB.listSnapshots(U(U({},this.resolveApiOpts(e)),{},{sandboxId:this.sandboxId}))}getMcpUrl(){return`https://${this.getHost(this.mcpPort)}/mcp`}async getMcpToken(){var e=this;return e.mcpToken||=await e.files.read(`/etc/mcp-gateway/.token`,{user:`root`}),e.mcpToken}async uploadUrl(e,t){var n=this;t??={};let r=!!n.envdAccessToken;if(!r&&t.useSignatureExpiration!=null)throw new JR(`Signature expiration can be used only when sandbox is created as secured.`);let i=t.user;i==null&&yP(n.envdApi.version,`0.4.0`)<0&&(i=Mz);let a=e??``,o=n.fileUrl(a,i);if(r){let e=new URL(o),r=await Yz({path:a,operation:`write`,user:i,expirationInSeconds:t.useSignatureExpiration,envdAccessToken:n.envdAccessToken});return e.searchParams.set(`signature`,r.signature),r.expiration&&e.searchParams.set(`signature_expiration`,r.expiration.toString()),e.toString()}return o}async downloadUrl(e,t){var n=this;t??={};let r=!!n.envdAccessToken;if(!r&&t.useSignatureExpiration!=null)throw new JR(`Signature expiration can be used only when sandbox is created as secured.`);let i=t.user;i==null&&yP(n.envdApi.version,`0.4.0`)<0&&(i=Mz);let a=n.fileUrl(e,i);if(r){let r=new URL(a),o=await Yz({path:e,operation:`read`,user:i,expirationInSeconds:t.useSignatureExpiration,envdAccessToken:n.envdAccessToken});return r.searchParams.set(`signature`,o.signature),o.expiration&&r.searchParams.set(`signature_expiration`,o.expiration.toString()),r.toString()}return a}async getInfo(e){var t=this;return await YB.getInfo(t.sandboxId,t.resolveApiOpts(e))}async getMetrics(e){var t=this;if(t.connectionConfig.debug)return[];if(t.envdApi.version){if(yP(t.envdApi.version,`0.1.5`)<0)throw new rz(`You need to update the template to use the new SDK.`);if(yP(t.envdApi.version,`0.2.4`)<0){var n,r;(n=t.connectionConfig.logger)==null||(r=n.warn)==null||r.call(n,`Disk metrics are not supported in this version of the sandbox, please rebuild the template to get disk metrics.`)}}return await YB.getMetrics(t.sandboxId,t.resolveApiOpts(e))}resolveApiOpts(e){return Az.mergeOpts(this.connectionConfig,e)}fileUrl(e,t){let n=new URL(`/files`,this.envdDirectUrl);return t&&n.searchParams.set(`username`,t),e&&n.searchParams.set(`path`,e),n.toString()}};H(XB,`defaultTemplate`,`base`),H(XB,`defaultMcpTemplate`,`mcp-gateway`);function qNe(e){let t=new WeakMap;return new Proxy(e,{apply(e,t,n){return new e(...n)},get(e,n,r){let i=Reflect.get(e,n,r);if(n===`prototype`||typeof i!=`function`)return i;let a=typeof r==`function`?r:e,o=t.get(a);o||(o=new Map,t.set(a,o));let s=o.get(n);return s||(s=i.bind(a),o.set(n,s)),s}})}var ZB=class{constructor(e,t,n){H(this,`timestamp`,void 0),H(this,`level`,void 0),H(this,`message`,void 0),this.timestamp=e,this.level=t,this.message=eMe(n)}toString(){return`[${this.timestamp.toISOString()}] [${this.level}] ${this.message}`}},JNe=class extends ZB{constructor(e,t){super(e,`debug`,t)}},YNe=class extends ZB{constructor(e,t){super(e,`debug`,t)}};dR.red(`ERROR`),dR.hex(`#FF4400`)(`WARN `),dR.hex(`#FF8800`)(`INFO `),dR.gray(`DEBUG`);const XNe=/(^|@)\S+:\d+/,QB=/^\s*at .*(\S+:\d+|\(native\))/m,ZNe=/^(eval@)?(\[native code\])?$/;function QNe(e,t){if(e.stacktrace!==void 0||e[`opera#sourceloc`]!==void 0)return rPe(e,t);if(e.stack&&QB.test(e.stack))return $Ne(e,t);if(e.stack)return tPe(e,t);if(t?.allowEmpty)return[];throw Error(`Cannot parse given Error object`)}function $B(e){if(!e.includes(`:`))return[e,void 0,void 0];let t=/(.+?)(?::(\d+))?(?::(\d+))?$/.exec(e.replace(/[()]/g,``));return[t[1],t[2]||void 0,t[3]||void 0]}function eV(e,t){return t&&t.slice!=null?Array.isArray(t.slice)?e.slice(t.slice[0],t.slice[1]):e.slice(0,t.slice):e}function $Ne(e,t){return ePe(e.stack,t)}function ePe(e,t){return eV(e.split(`
464
+ `).filter(e=>!!e.match(QB)),t).map(e=>{e.includes(`(eval `)&&(e=e.replace(/eval code/g,`eval`).replace(/(\(eval at [^()]*)|(,.*$)/g,``));let t=e.replace(/^\s+/,``).replace(/\(eval code/g,`(`).replace(/^.*?\s+/,``),n=t.match(/ (\(.+\)$)/);t=n?t.replace(n[0],``):t;let r=$B(n?n[1]:t);return{function:n&&t||void 0,file:[`eval`,`<anonymous>`].includes(r[0])?void 0:r[0],line:r[1]?+r[1]:void 0,col:r[2]?+r[2]:void 0,raw:e}})}function tPe(e,t){return nPe(e.stack,t)}function nPe(e,t){return eV(e.split(`
465
+ `).filter(e=>!e.match(ZNe)),t).map(e=>{if(e.includes(` > eval`)&&(e=e.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,`:$1`)),!e.includes(`@`)&&!e.includes(`:`))return{function:e};{let t=/(([^\n\r"\u2028\u2029]*".[^\n\r"\u2028\u2029]*"[^\n\r@\u2028\u2029]*(?:@[^\n\r"\u2028\u2029]*"[^\n\r@\u2028\u2029]*)*(?:[\n\r\u2028\u2029][^@]*)?)?[^@]*)@/,n=e.match(t),r=n&&n[1]?n[1]:void 0,i=$B(e.replace(t,``));return{function:r,file:i[0],line:i[1]?+i[1]:void 0,col:i[2]?+i[2]:void 0,raw:e}}})}function rPe(e,t){return!e.stacktrace||e.message.includes(`
466
+ `)&&e.message.split(`
467
+ `).length>e.stacktrace.split(`
468
+ `).length?iPe(e):e.stack?oPe(e,t):aPe(e)}function iPe(e,t){let n=/Line (\d+).*script (?:in )?(\S+)/i,r=e.message.split(`
469
+ `),i=[];for(let e=2,t=r.length;e<t;e+=2){let t=n.exec(r[e]);t&&i.push({file:t[2],line:+t[1],raw:r[e]})}return eV(i,t)}function aPe(e,t){let n=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,r=e.stacktrace.split(`
470
+ `),i=[];for(let e=0,t=r.length;e<t;e+=2){let t=n.exec(r[e]);t&&i.push({function:t[3]||void 0,file:t[2],line:t[1]?+t[1]:void 0,raw:r[e]})}return eV(i,t)}function oPe(e,t){return eV(e.stack.split(`
471
+ `).filter(e=>!!e.match(XNe)&&!e.match(/^Error created at/)),t).map(e=>{let t=e.split(`@`),n=$B(t.pop()),r=t.shift()||``,i=r.replace(/<anonymous function(: (\w+))?>/,`$2`).replace(/\([^)]*\)/g,``)||void 0,a;return/\([^)]*\)/.test(r)&&(a=r.replace(/^[^(]+\(([^)]*)\)$/,`$1`)),{function:i,args:a===void 0||a===`[arguments not available]`?void 0:a.split(`,`),file:n[0],line:n[1]?+n[1]:void 0,col:n[2]?+n[2]:void 0,raw:e}})}function sPe(e){return e.map(e=>({functionName:e.function,args:e.args,fileName:e.file,lineNumber:e.line,columnNumber:e.col,source:e.raw}))}function cPe(e,t){return sPe(QNe(e,t))}const lPe=[`alias`];function uPe(e,t){if(o.isAbsolute(e))throw new rz(`Invalid source path "${e}": absolute paths are not allowed. Use a relative path within the context directory.`,t);let n=o.normalize(e);if(n===`..`||n.startsWith(`..`+o.sep))throw new rz(`Invalid source path "${e}": path escapes the context directory. The path must stay within the context directory.`,t)}function tV(e,t){let n,r;if(typeof e==`string`)n=e,r=t??{};else{let{alias:t}=e,i=RB(e,lPe);n=t,r=i}if(!n||n.length===0)throw new rz(`Name must be provided`);return{name:n,buildOptions:r}}function nV(e){let t=o.join(e,`.dockerignore`);return oe.existsSync(t)?oe.readFileSync(t,`utf-8`).replace(/^\uFEFF/,``).split(`
472
+ `).filter(e=>!e.startsWith(`#`)).map(e=>e.trim()).filter(e=>e):[]}function dPe(e){return e.replace(/\\/g,`/`)}function fPe(e,t){let n=e.trim(),r=n.startsWith(`!`);if(r&&(n=n.slice(1).trim()),o.isAbsolute(n)){let e=o.relative(t,n);e!==``&&e!==`..`&&!e.startsWith(`..${o.sep}`)&&!o.isAbsolute(e)&&(n=e)}return(r?`!`:``)+n}function pPe(e,t){let n=o.resolve(t),r;try{r=new Vje(e.map(e=>fPe(e,n)),{backslashIsSeparator:o.sep===`\\`})}catch(e){throw new rz(e.message)}let i=e=>{let t=e.relativePosix();return t!==``&&r.matches(t)};return{ignored:i,childrenIgnored:e=>i(e)&&!r.mayMatchUnder(e.relativePosix())}}async function rV(e,t,n,r=!0){let{glob:i}=await pz(`glob`),a=new Map,s=pPe(n,t),c=await i(e,{ignore:s,withFileTypes:!0,dot:!0,cwd:t}),l=e=>{let t=e.relativePosix();return t===``?0:t.split(`/`).length};c.sort((e,t)=>l(e)-l(t));let u=new Set,d=e=>{if(u.has(``))return!0;for(let t=o.posix.dirname(e);t!==`.`&&t!==`/`;t=o.posix.dirname(t))if(u.has(t))return!0;return!1};for(let e of c)d(e.relativePosix())||(e.isDirectory()?(u.add(e.relativePosix()),r&&a.set(e.fullpath(),e),(await i(dPe(o.join(e.relative()||`.`,`**/*`)),{ignore:s,withFileTypes:!0,dot:!0,cwd:t})).forEach(e=>a.set(e.fullpath(),e))):a.set(e.fullpath(),e));return Array.from(a.values()).sort((e,t)=>e.fullpath()<t.fullpath()?-1:+(e.fullpath()>t.fullpath()))}function mPe(e,t,n){let r=oe.openSync(t,`r`);try{let t;for(;(t=oe.readSync(r,n,0,n.length,null))>0;)e.update(n.subarray(0,t))}finally{oe.closeSync(r)}}async function hPe(e,t,n,r,i,a){let s=o.join(n,e),c=v.createHash(`sha256`),l=`COPY ${e} ${t}`;c.update(l);let u=await rV(e,n,r,!0);if(u.length===0){let e=Error(`No files found in ${s}`);throw a&&(e.stack=a),e}let d=e=>{c.update(e.mode.toString()),e.isDirectory()||c.update(e.size.toString())},f=Buffer.allocUnsafe(1048576);for(let e of u){let t=e.relativePosix();if(c.update(t),e.isSymbolicLink()){let t=oe.statSync(e.fullpath(),{throwIfNoEntry:!1});if(!(i&&(t?.isFile()||t?.isDirectory()))){d(oe.lstatSync(e.fullpath()));let t=oe.readlinkSync(e.fullpath());c.update(t);continue}}let n=oe.statSync(e.fullpath());d(n),n.isFile()&&mPe(c,e.fullpath(),f)}return c.digest(`hex`)}function iV(e){return e.startsWith(`file:`)?h.fileURLToPath(e):e}function gPe(e,t){if(e.startsWith(`node:`)||e===`native`)return!1;try{let n=o.relative(t,o.dirname(iV(e)));return n!==``&&(n.startsWith(`..`)||o.isAbsolute(n))}catch{return!1}}function aV(){let e=cPe(Error(),{allowEmpty:!0}),t=e[0]?.fileName;if(!t)return{frames:e,userFrameIndex:-1};let n=o.dirname(iV(t));return{frames:e,userFrameIndex:e.findIndex(e=>e.fileName!==void 0&&gPe(e.fileName,n))}}function oV(){let{frames:e,userFrameIndex:t}=aV();if(t!==-1)return e.slice(t).map(e=>e.source).filter(e=>e!==void 0).join(`
473
+ `)}function _Pe(){let{frames:e,userFrameIndex:t}=aV(),n=t===-1?void 0:e[t].fileName;if(n)return o.dirname(iV(n))}function sV(e){return e.toString(8).padStart(4,`0`)}async function vPe(e,t,r,i,a){let{create:s}=await pz(`tar`),c=(await rV(e,t,r,!0)).map(e=>e.relativePosix()),l=await oe.promises.mkdtemp(o.join(n.tmpdir(),`e2b-template-`)),u=o.join(l,`context.tar.gz`),d=()=>oe.promises.rm(l,{recursive:!0,force:!0}).catch(()=>{});try{await s({gzip:a,cwd:t,follow:i,noDirRecurse:!0,file:u},c);let{size:e}=await oe.promises.stat(u);return{path:u,size:e,cleanup:d}}catch(e){throw await d(),e}}function yPe(e,t){return e===`base`?0:e===`finalize`?t-1:Number(e)}function bPe(e,t){return typeof t==`string`?oe.readFileSync(o.join(e,t),`utf-8`):JSON.stringify(t)}async function xPe(e,{name:t,tags:n,cpuCount:r,memoryMB:i,minFreeDiskMb:a},o){let s=await e.api.POST(`/v3/templates`,{body:{name:t,tags:n,cpuCount:r,memoryMB:i,minFreeDiskMb:a},signal:o}),c=qz(s,oz);if(c)throw c;if(!s.data)throw new oz(`Failed to request build`);return s.data}async function SPe(e,{templateID:t,filesHash:n},r,i){let a=await e.api.GET(`/templates/{templateID}/files/{hash}`,{params:{path:{templateID:t,hash:n}},signal:i}),o=qz(a,sz,r);if(o)throw o;if(!a.data)throw new sz(`Failed to get file upload link`,r);return a.data}async function CPe(e,t,n){let{fileName:r,url:i,headers:a,fileContextPath:o,ignorePatterns:s,resolveSymlinks:c,gzip:l}=e,u;try{let e=await vPe(r,o,s,c,l);u=e.cleanup;let d=Dz(n?.requestTimeoutMs??36e5,n?.signal),f=await wPe(i,e.path,e.size,d,a);if(!f.ok)throw new sz(`Failed to upload file: ${f.statusText}`,t)}catch(e){throw e instanceof sz?e:new sz(`Failed to upload file: ${e}`,t)}finally{await u?.()}}async function wPe(e,t,n,r,i){return await((await Nz())?.fetch??fetch)(e,{method:`PUT`,body:re.Readable.toWeb(oe.createReadStream(t)),headers:U(U({},Object.fromEntries(Object.entries(i??{}).filter(([e])=>e.toLowerCase()!==`content-length`))),{},{"Content-Length":n.toString()}),duplex:`half`,signal:r})}async function TPe(e,{templateID:t,buildID:n,template:r},i){let a=qz(await e.api.POST(`/v2/templates/{templateID}/builds/{buildID}`,{params:{path:{templateID:t,buildID:n}},body:r,signal:i}),oz);if(a)throw a}function cV(e){return new ZB(new Date(e.timestamp),e.level,e.message)}function EPe(e){if(e)return{message:e.message,step:e.step,logEntries:(e.logEntries??[]).map(cV)}}async function lV(e,{templateID:t,buildID:n,logsOffset:r},i){let a=await e.api.GET(`/templates/{templateID}/builds/{buildID}/status`,{params:{path:{templateID:t,buildID:n},query:{logsOffset:r}},signal:i}),o=qz(a,oz);if(o)throw o;if(!a.data)throw new oz(`Failed to get build status`);return{buildID:a.data.buildID,templateID:a.data.templateID,status:a.data.status,logEntries:a.data.logEntries.map(cV),logs:a.data.logs,reason:EPe(a.data.reason)}}async function DPe(e,{alias:t},n){let r=await e.api.GET(`/templates/aliases/{alias}`,{params:{path:{alias:t}},signal:n});if(r.response.status===404)return!1;if(r.response.status===403)return!0;let i=qz(r,rz);if(i)throw i;return r.data!==void 0}async function OPe(e,{templateID:t,buildID:n,onBuildLogs:r,logsRefreshFrequency:i,stackTraces:a,signal:o,requestTimeoutMs:s}){let c=0,l=`building`,u=async()=>{let i=await lV(e,{templateID:t,buildID:n,logsOffset:c},Dz(s,o));return c+=i.logEntries.length,i.logEntries.forEach(e=>r?.(e)),i};for(;l===`building`||l===`waiting`;){o?.throwIfAborted();let e=await u();switch(l=e.status,l){case`ready`:case`error`:{var d;let t=e;for(;t.logEntries.length>0;)o?.throwIfAborted(),t=await u();if(l===`ready`)return;let n;throw e.reason?.step!==void 0&&(n=a[yPe(e.reason.step,a.length)]),new oz((e==null||(d=e.reason)==null?void 0:d.message)??`Unknown error`,n)}}await new Promise(e=>setTimeout(e,i))}throw new oz(`Unknown build error occurred.`)}async function kPe(e,{targetName:t,tags:n},r){let i=await e.api.POST(`/templates/tags`,{body:{target:t,tags:n},signal:r}),a=qz(i,rz);if(a)throw a;if(!i.data)throw new rz(`Failed to assign tags`);return{buildId:i.data.buildID,tags:i.data.tags}}async function APe(e,{name:t,tags:n},r){let i=qz(await e.api.DELETE(`/templates/tags`,{body:{name:t,tags:n},signal:r}),rz);if(i)throw i}async function jPe(e,{templateID:t},n){let r=await e.api.GET(`/templates/{templateID}/tags`,{params:{path:{templateID:t}},signal:n}),i=qz(r,rz);if(i)throw i;if(!r.data)throw new rz(`Failed to get template tags`);return r.data.map(e=>({tag:e.tag,buildId:e.buildID,createdAt:new Date(e.createdAt)}))}var uV=class{constructor(e){H(this,`cmd`,void 0),this.cmd=e}getCmd(){return this.cmd}};function MPe(e){return new uV(`[ -f ${yz(e)} ]`)}function NPe(e){return new uV(`sleep ${Math.max(1,Math.floor(e/1e3))}`)}const PPe={mount:{type:`string`,ignored:!0},network:{type:`string`,ignored:!0},security:{type:`string`,ignored:!0},device:{type:`string`,ignored:!0}},dV={chown:{type:`string`},chmod:{type:`string`},from:{type:`string`},link:{type:`bool`,ignored:!0},exclude:{type:`string`,ignored:!0},parents:{type:`bool`,ignored:!0}},FPe=U(U({},dV),{},{"keep-git-dir":{type:`bool`,ignored:!0},checksum:{type:`string`,ignored:!0},unpack:{type:`bool`,ignored:!0}}),IPe={platform:{type:`string`,ignored:!0}},LPe=new Set([`EXPOSE`,`VOLUME`,`LABEL`,`MAINTAINER`]);function fV(e,t){let n=`E2B_HEREDOC_${e.replace(/[^A-Za-z0-9_]/g,`_`)}`;for(;t.includes(n);)n+=`_`;return n}function pV(e){return e===``||e.endsWith(`
474
+ `)?e:e+`
475
+ `}const mV=RegExp(`\\p{Nd}+|[@*#?\\-$!0]|[\\p{L}\\p{Nd}_]+`,`uy`);function RPe(e,t){return e===`\\`||e==="`"||e===`$`||e===t?`\\`+e:e}function zPe(e,t){let n=0;function r(e){throw new bR(`syntax error: missing ${e===`/`?"'/' in ${}":`'}'`}`,t)}function i(){mV.lastIndex=n;let t=mV.exec(e);return t?(n+=t[0].length,t[0]):``}function a(){if(e[n]!==`{`){let e=i();return e===``?`\\$`:`$`+e}if(n++,n>=e.length&&r(`}`),e[n]===`{`||e[n]===`}`||e[n]===`:`)throw new bR(`syntax error: bad substitution`,t);let a=i();n>=e.length&&r(`}`);let s=e[n++];if(s===`}`)return`\${${a}}`;if(s===`/`){e[n]===`/`&&(s+=e[n++]);let t=o(`/`,!0);return`\${${a}${s}${t}/${o(`}`,!0)}}`}s===`:`&&(n>=e.length&&r(`}`),s+=e[n++]);let c=s[s.length-1],l=c===`#`||c===`%`;if(!`+-?#%`.includes(c)||s.length===2&&l)throw new bR(`unsupported modifier (${s}) in substitution`,t);return`\${${a}${s}${o(`}`,l)}}`}function o(t,i=!1){let o=``;for(;n<e.length;){let r=e[n++];if(r===t)return o;if(r===`\\`){if(n<e.length){let r=e[n++];o+=i?`\\`+r:RPe(r,t)}}else o+=r===`$`?a():r==="`"?"\\`":r}return t!==void 0&&r(t),o}return o()}function hV(e){return e.map(yz).join(` `)}var BPe=class{constructor(e,t){this.templateBuilder=e,H(this,`lex`,void 0),H(this,`envLex`,void 0),H(this,`vars`,new Map),H(this,`userChanged`,!1),H(this,`workdirChanged`,!1),H(this,`cmd`,void 0),H(this,`entrypoint`,void 0),this.lex=new gR(t),this.envLex=new gR(t,{env:this.vars,skipUnsetEnv:!1})}convert(e){let t=e.filter(e=>e.name===`FROM`);if(t.length>1)throw new bR(`Multi-stage Dockerfiles are not supported`);if(t.length===0)throw new bR(`Dockerfile must contain a FROM instruction`);let n=t[0],r=this.handleFrom(n);this.templateBuilder.setUser(`root`),this.templateBuilder.setWorkdir(`/`);for(let t of e)if(t.name!==`FROM`){if(t.startLine<n.startLine&&t.name!==`ARG`)throw new bR(`${t.name} must be preceded by a FROM instruction`,t.startLine);this.handleInstruction(t)}return this.applyStartCmd(),this.userChanged||this.templateBuilder.setUser(`user`),this.workdirChanged||this.templateBuilder.setWorkdir(`/home/user`),{baseImage:r}}handleInstruction(e){switch(e.name){case`RUN`:this.handleRun(e);break;case`COPY`:this.handleCopy(e,dV);break;case`ADD`:this.handleCopy(e,FPe);break;case`WORKDIR`:this.templateBuilder.setWorkdir(this.expandSingle(e)),this.workdirChanged=!0;break;case`USER`:this.templateBuilder.setUser(this.expandSingle(e)),this.userChanged=!0;break;case`ENV`:this.handleEnv(e);break;case`ARG`:this.handleArg(e);break;case`CMD`:this.parseFlags(e,{}),this.cmd={json:e.json,args:e.args};break;case`ENTRYPOINT`:this.parseFlags(e,{}),this.entrypoint={json:e.json,args:e.args};break;default:LPe.has(e.name)||console.warn(`Unsupported instruction: ${e.name}`)}}expand(e,t,n=this.lex){try{return n.processWord(t)}catch(t){throw new bR(t instanceof Error?t.message:String(t),e.startLine)}}expandSingle(e){if(this.parseFlags(e,{}),e.args.length!==1)throw new bR(`${e.name} requires exactly one argument`,e.startLine);return this.expand(e,e.args[0])}parseFlags(e,t){let n={};for(let r of e.flags){if(!r.startsWith(`--`))throw new bR(`arg should start with -- : ${r}`,e.startLine);let i=r.slice(2),a=i.indexOf(`=`),o=a===-1?i:i.slice(0,a),s=a===-1?void 0:i.slice(a+1),c=Object.hasOwn(t,o)?t[o]:void 0;if(!c)throw new bR(`unknown flag: ${o}`,e.startLine);if(o in n)throw new bR(`duplicate flag specified: ${o}`,e.startLine);let l;if(c.type===`bool`){if(s===void 0||s===``||s===`true`)l=`true`;else if(s===`false`)l=`false`;else throw new bR(`expecting boolean value for flag ${o}, not: ${s}`,e.startLine)}else{if(s===void 0)throw new bR(`missing a value on flag: ${o}`,e.startLine);l=s}if(c.ignored){console.warn(`Ignoring unsupported ${e.name} flag --${o} (line ${e.startLine})`);continue}n[o]=l}return n}handleFrom(e){this.parseFlags(e,IPe);let t=e.args;if((t.length!==3||t[1].toLowerCase()!==`as`)&&t.length!==1)throw new bR(`FROM requires either one or three arguments`,e.startLine);return this.expand(e,t[0])}handleRun(e){this.parseFlags(e,PPe);let{args:t,json:n,heredocs:r}=e;if(t.length===0)throw new bR(`RUN requires at least one argument`,e.startLine);let i;i=n?hV(t):r.length>0?this.runWithHeredocs(t[0],r):t[0],this.templateBuilder.runCmd(i)}runWithHeredocs(e,t){let n=e=>e.chomp?IR(e.content):e.content;if(t.length===1&&FR(e.trim())){let e=t[0],r=n(e);if(!r.startsWith(`#!`))return r;let i=yz(`/tmp/${e.name}`),a=fV(e.name,r);return`cat <<'${a}' >${i}\n`+pV(r)+`${a}\nchmod +x ${i} && ${i}\nE2B_EXIT=$?; rm -f ${i}; exit $E2B_EXIT`}let r=e;for(let e of t)r+=`
476
+ `+e.content+e.name;return r}handleCopy(e,t){let n=this.parseFlags(e,t);if(e.args.length<2)throw new bR(`${e.name} requires at least two arguments`,e.startLine);if(n.from!==void 0)throw new bR(`${e.name} --from is not supported (multi-stage builds are not supported)`,e.startLine);let r=n.chown===void 0?void 0:this.expand(e,n.chown),i;if(n.chmod!==void 0){let t=this.expand(e,n.chmod),r=this.expand(e,n.chmod,this.envLex);if(!/^[0-7]{3,4}$/.test(r))throw new bR(`invalid chmod value "${t}"${r===t?``:` (resolves to "${r}")`}, expected an octal mode such as 0755`,e.startLine);i=parseInt(r,8)}let a=e.args[e.args.length-1];if(FR(a))throw new bR(`${e.name} cannot accept a heredoc as a destination`,e.startLine);let o=this.expand(e,a),s=new Map(e.heredocs.map(e=>[e.name,e]));for(let t of e.args.slice(0,-1)){let n=FR(t);if(n){let t=s.get(n.name);if(!t)throw new bR(`missing heredoc content for ${n.name}`,e.startLine);this.copyHeredoc(t,o,r,i,e.startLine);continue}let a=this.expand(e,t);if(e.name===`ADD`&&/^[a-z][a-z0-9+.-]*:\/\//i.test(a))throw new bR(`ADD from a remote URL is not supported: ${a}`,e.startLine);this.templateBuilder.copy(a,o,{user:r,mode:i})}}copyHeredoc(e,t,n,r,i){let a=e.chomp?IR(e.content):e.content;e.expand&&(a=zPe(a,i));let o=fV(e.name,a),s=e.expand?o:`'${o}'`,c=`"$E2B_HEREDOC_DEST"`,l=t.endsWith(`/`)?`E2B_HEREDOC_DEST=${yz(t+e.name)}\n`:`E2B_HEREDOC_DEST=${yz(t)}\nif [ -d ${c} ]; then E2B_HEREDOC_DEST=${c}/${yz(e.name)}; fi\n`;l+=`mkdir -p "$(dirname ${c})" && cat <<${s} >${c}\n`+pV(a)+o,n!==void 0&&(l+=`\nchown ${yz(n)} ${c}`),r!==void 0&&(l+=`\nchmod ${r.toString(8)} ${c}`),this.templateBuilder.runCmd(l,{user:`root`})}handleEnv(e){this.parseFlags(e,{});let{args:t}=e;if(t.length===0)throw new bR(`ENV requires at least one argument`,e.startLine);let n={};for(let r=0;r+2<t.length;r+=3){let i=this.expand(e,t[r]);if(i===``)throw new bR(`ENV names can not be blank`,e.startLine);n[i]=this.expand(e,t[r+1]),this.vars.set(i,this.expand(e,t[r+1],this.envLex))}this.templateBuilder.setEnvs(n)}handleArg(e){this.parseFlags(e,{});let{args:t}=e;if(t.length===0)throw new bR(`ARG requires at least one argument`,e.startLine);let n={};for(let r of t){let t=r.indexOf(`=`),i=this.expand(e,t===-1?r:r.slice(0,t));if(i===``)throw new bR(`ARG names can not be blank`,e.startLine);let a=r.slice(t+1);n[i]=t===-1?``:this.expand(e,a),this.vars.set(i,t===-1?``:this.expand(e,a,this.envLex))}this.templateBuilder.setEnvs(n)}applyStartCmd(){let{cmd:e,entrypoint:t}=this,n;if(t){if(t.json){let r=[...t.args];e&&(e.json?r.push(...e.args):e.args.length>0&&r.push(`/bin/sh`,`-c`,e.args[0])),n=r.length>0?hV(r):void 0}else n=t.args.length>0?t.args[0]:void 0}else e&&(n=e.json?e.args.length>0?hV(e.args):void 0:e.args.length>0?e.args[0]:void 0);n!==void 0&&n.trim()!==``&&this.templateBuilder.setStartCmd(n,NPe(2e4))}};function VPe(e){try{if(oe.existsSync(e)&&oe.statSync(e).isFile())return oe.readFileSync(e,`utf-8`)}catch{}return e}function HPe(e,t){let n=jje(VPe(e));for(let e of n.warnings)console.warn(`${e.message} (line ${e.line})`);return new BPe(t,n.escapeToken).convert(n.instructions)}qNe(class extends jz{constructor(e){super(),H(this,`defaultBaseImage`,`e2bdev/base`),H(this,`baseImage`,this.defaultBaseImage),H(this,`baseTemplate`,void 0),H(this,`registryConfig`,void 0),H(this,`startCmd`,void 0),H(this,`readyCmd`,void 0),H(this,`force`,!1),H(this,`forceNextLayer`,!1),H(this,`instructions`,[]),H(this,`fileContextPath`,void 0),H(this,`fileIgnorePatterns`,[]),H(this,`logsRefreshFrequency`,200),H(this,`stackTraces`,[]),this.fileContextPath=e?.fileContextPath??(dz===`browser`?`.`:_Pe()??`.`),this.fileIgnorePatterns=e?.fileIgnorePatterns??this.fileIgnorePatterns}static toJSON(e,t=!0){return e.toJSON(t)}static toDockerfile(e){return e.toDockerfile()}static async build(e,t,n){var r=this;let{name:i,buildOptions:a}=tV(t,n),o=r.resolveOpts(a)??{};try{var s,c;(s=o.onBuildLogs)==null||s.call(o,new JNe(new Date,`Build started`));let t=e,n=new Az(o),r=new Jz(n),a=await t.build(r,n,i,o);return(c=o.onBuildLogs)==null||c.call(o,new ZB(new Date,`info`,`Waiting for logs...`)),await OPe(r,{templateID:a.templateId,buildID:a.buildId,onBuildLogs:o.onBuildLogs,logsRefreshFrequency:t.logsRefreshFrequency,stackTraces:t.stackTraces,signal:o.signal,requestTimeoutMs:n.requestTimeoutMs}),a}finally{var l;(l=o.onBuildLogs)==null||l.call(o,new YNe(new Date,`Build finished`))}}static async buildInBackground(e,t,n){var r=this;let{name:i,buildOptions:a}=tV(t,n),o=r.resolveOpts(a)??{},s=new Az(o),c=new Jz(s);return e.build(c,s,i,o)}static async getBuildStatus(e,t){let n=new Az(this.resolveOpts(t));return await lV(new Jz(n),{templateID:e.templateId,buildID:e.buildId,logsOffset:t?.logsOffset},n.getSignal(void 0,t?.signal))}static async exists(e,t){return this.aliasExists(e,t)}static async aliasExists(e,t){let n=new Az(this.resolveOpts(t));return DPe(new Jz(n),{alias:e},n.getSignal(void 0,t?.signal))}static async assignTags(e,t,n){let r=new Az(this.resolveOpts(n));return kPe(new Jz(r),{targetName:e,tags:Array.isArray(t)?t:[t]},r.getSignal(void 0,n?.signal))}static async removeTags(e,t,n){let r=new Az(this.resolveOpts(n));return APe(new Jz(r),{name:e,tags:Array.isArray(t)?t:[t]},r.getSignal(void 0,n?.signal))}static async getTags(e,t){let n=new Az(this.resolveOpts(t));return jPe(new Jz(n),{templateID:e},n.getSignal(void 0,t?.signal))}fromDebianImage(e=`stable`){return this.fromImage(`debian:${e}`)}fromUbuntuImage(e=`latest`){return this.fromImage(`ubuntu:${e}`)}fromFedoraImage(e=`44`){return this.fromImage(`fedora:${e}`)}fromAlpineImage(e=`3.24`){return this.fromImage(`alpine:${e}`)}fromArchImage(e=`latest`){return this.fromImage(`archlinux:${e}`)}fromPythonImage(e=`3`){return this.fromImage(`python:${e}`)}fromNodeImage(e=`lts`){return this.fromImage(`node:${e}`)}fromBunImage(e=`latest`){return this.fromImage(`oven/bun:${e}`)}fromBaseImage(){return this.fromImage(this.defaultBaseImage)}fromImage(e,t){if(t&&(!t.username||!t.password))throw new JR(`Both username and password are required when providing registry credentials`,oV());return this.baseImage=e,this.baseTemplate=void 0,t&&(this.registryConfig={type:`registry`,username:t.username,password:t.password}),this.forceNextLayer&&(this.force=!0),this.collectStackTrace(),this}fromTemplate(e){return this.baseTemplate=e,this.baseImage=void 0,this.forceNextLayer&&(this.force=!0),this.collectStackTrace(),this}fromDockerfile(e){let{baseImage:t}=HPe(e,this);return this.baseImage=t,this.baseTemplate=void 0,this.forceNextLayer&&(this.force=!0),this.collectStackTrace(),this}fromAWSRegistry(e,t){return this.baseImage=e,this.baseTemplate=void 0,this.registryConfig={type:`aws`,awsAccessKeyId:t.accessKeyId,awsSecretAccessKey:t.secretAccessKey,awsRegion:t.region},this.forceNextLayer&&(this.force=!0),this.collectStackTrace(),this}fromGCPRegistry(e,t){return this.baseImage=e,this.baseTemplate=void 0,this.registryConfig={type:`gcp`,serviceAccountJson:bPe(this.fileContextPath.toString(),t.serviceAccountJSON)},this.forceNextLayer&&(this.force=!0),this.collectStackTrace(),this}copy(e,t,n){if(dz===`browser`)throw Error(`Browser runtime is not supported for copy`);let r=Array.isArray(e)?e:[e],i=oV();for(let e of r){let r=e.toString();uPe(r,i);let a=[r,t.toString(),n?.user??``,n?.mode===void 0?``:sV(n.mode)];this.instructions.push({type:`COPY`,args:a,force:n?.forceUpload||this.forceNextLayer,forceUpload:n?.forceUpload,resolveSymlinks:n?.resolveSymlinks,gzip:n?.gzip}),this.collectStackTrace()}return this}copyItems(e){if(dz===`browser`)throw Error(`Browser runtime is not supported for copyItems`);let t=oV();for(let n of e)try{this.copy(n.src,n.dest,{forceUpload:n.forceUpload,user:n.user,mode:n.mode,resolveSymlinks:n.resolveSymlinks,gzip:n.gzip})}catch(e){let n=e;throw n.stack=t,n}return this}remove(e,t){let n=Array.isArray(e)?e:[e],r=[`rm`];return t?.recursive&&r.push(`-r`),t?.force&&r.push(`-f`),r.push(...n.map(e=>yz(e.toString()))),this.runCmd(r.join(` `),{user:t?.user})}rename(e,t,n){let r=[`mv`,yz(e.toString()),yz(t.toString())];return n?.force&&r.push(`-f`),this.runCmd(r.join(` `),{user:n?.user})}makeDir(e,t){let n=Array.isArray(e)?e:[e],r=[`mkdir`,`-p`];return t?.mode!==void 0&&r.push(`-m ${sV(t.mode)}`),r.push(...n.map(e=>yz(e.toString()))),this.runCmd(r.join(` `),{user:t?.user})}makeSymlink(e,t,n){let r=[`ln`,`-s`];return n?.force&&r.push(`-f`),r.push(yz(e.toString()),yz(t.toString())),this.runCmd(r.join(` `),{user:n?.user})}runCmd(e,t){let n=[(Array.isArray(e)?e:[e]).join(` && `)];return t?.user&&n.push(t.user),this.instructions.push({type:`RUN`,args:n,force:this.forceNextLayer}),this.collectStackTrace(),this}setWorkdir(e){return this.instructions.push({type:`WORKDIR`,args:[e.toString()],force:this.forceNextLayer}),this.collectStackTrace(),this}setUser(e){return this.instructions.push({type:`USER`,args:[e],force:this.forceNextLayer}),this.collectStackTrace(),this}pipInstall(e,t){let n=t?.g??!0,r=[`pip`,`install`],i=e?Array.isArray(e)?e:[e]:void 0;return n===!1&&r.push(`--user`),i?r.push(...i):r.push(`.`),this.runCmd(r.join(` `),{user:n?`root`:void 0})}npmInstall(e,t){let n=[`npm`,`install`],r=e?Array.isArray(e)?e:[e]:void 0;return t?.g&&n.push(`-g`),t?.dev&&n.push(`--save-dev`),r&&n.push(...r),this.runCmd(n.join(` `),{user:t?.g?`root`:void 0})}bunInstall(e,t){let n=[`bun`,`install`],r=e?Array.isArray(e)?e:[e]:void 0;return t?.g&&n.push(`-g`),t?.dev&&n.push(`--dev`),r&&n.push(...r),this.runCmd(n.join(` `),{user:t?.g?`root`:void 0})}aptInstall(e,t){let n=Array.isArray(e)?e:[e];return this.runCmd([`apt-get update`,`DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes apt-get install -y ${t?.noInstallRecommends?`--no-install-recommends `:``}${t?.fixMissing?`--fix-missing `:``}${n.join(` `)}`],{user:`root`})}addMcpServer(e){if(this.baseTemplate!==`mcp-gateway`)throw new oz(`MCP servers can only be added to mcp-gateway template`,oV());let t=Array.isArray(e)?e:[e];return this.runCmd(`mcp-gateway pull ${t.join(` `)}`,{user:`root`})}gitClone(e,t,n){let r=[`git`,`clone`,yz(e)];return n?.branch&&(r.push(`--branch ${yz(n.branch)}`),r.push(`--single-branch`)),n?.depth&&r.push(`--depth ${n.depth}`),t&&r.push(yz(t.toString())),this.runCmd(r.join(` `),{user:n?.user})}setStartCmd(e,t){return this.startCmd=e,this.readyCmd=t instanceof uV?t.getCmd():t,this.collectStackTrace(),this}setReadyCmd(e){return this.readyCmd=e instanceof uV?e.getCmd():e,this.collectStackTrace(),this}setEnvs(e){return Object.keys(e).length===0?this:(this.instructions.push({type:`ENV`,args:Object.entries(e).flatMap(([e,t])=>[e,t]),force:this.forceNextLayer}),this.collectStackTrace(),this)}skipCache(){return this.forceNextLayer=!0,this}betaDevContainerPrebuild(e){if(this.baseTemplate!==`devcontainer`)throw new oz(`Devcontainers can only used in the devcontainer template`,oV());return this.runCmd(`devcontainer build --workspace-folder ${yz(e)}`,{user:`root`})}betaSetDevContainerStart(e){if(this.baseTemplate!==`devcontainer`)throw new oz(`Devcontainers can only used in the devcontainer template`,oV());let t=yz(e);return this.setStartCmd(`sudo devcontainer up --workspace-folder ${t} && sudo /prepare-exec.sh ${t} | sudo tee /devcontainer.sh > /dev/null && sudo chmod +x /devcontainer.sh && sudo touch /devcontainer.up`,MPe(`/devcontainer.up`))}collectStackTrace(){return this.stackTraces.push(oV()),this}async toJSON(e){var t=this;let n=t.instructions;return e&&(n=await t.instructionsWithHashes()),JSON.stringify(t.serialize(n),void 0,2)}toDockerfile(){if(this.baseTemplate!==void 0)throw Error(`Cannot convert template built from another template to Dockerfile. Templates based on other templates can only be built using the E2B API.`);if(this.baseImage===void 0)throw Error(`No base image specified for template`);let e=`FROM ${this.baseImage}\n`;for(let t of this.instructions){if(t.type===`RUN`){e+=`RUN ${t.args[0]}\n`;continue}if(t.type===`COPY`){e+=`COPY ${t.args[0]} ${t.args[1]}\n`;continue}if(t.type===`ENV`){let n=[];for(let e=0;e<t.args.length;e+=2)n.push(`${t.args[e]}=${t.args[e+1]}`);e+=`ENV ${n.join(` `)}\n`;continue}e+=`${t.type} ${t.args.join(` `)}\n`}return this.startCmd&&(e+=`ENTRYPOINT ${this.startCmd}\n`),e}async build(e,t,n,r){var i=this,a,o,s,c;r.skipCache&&(i.force=!0),(a=r.onBuildLogs)==null||a.call(r,new ZB(new Date,`info`,`Requesting build for template: ${n}${r.tags&&r.tags.length>0?` with tags ${r.tags.join(`, `)}`:``}`));let{templateID:l,buildID:u,tags:d}=await xPe(e,{name:n,tags:r.tags,cpuCount:r.cpuCount,memoryMB:r.memoryMB,minFreeDiskMb:r.minFreeDiskMb},t.getSignal(void 0,r.signal));(o=r.onBuildLogs)==null||o.call(r,new ZB(new Date,`info`,`Template created with ID: ${l}, Build ID: ${u}`));let f=await i.instructionsWithHashes(),p=f.map(async(n,a)=>{if(n.type!==`COPY`)return;let o=n.args.length>0?n.args[0]:null,s=n.filesHash??null;if(o===null||s===null)throw Error(`Source path and files hash are required`);let c=n.forceUpload,u;a+1>=0&&a+1<i.stackTraces.length&&(u=i.stackTraces[a+1]);let{present:d,url:f,headers:p}=await SPe(e,{templateID:l,filesHash:s},u,t.getSignal(void 0,r.signal));if(c&&f!=null||d===!1&&f!=null){var m;await CPe({fileName:o,fileContextPath:i.fileContextPath.toString(),url:f,headers:p,ignorePatterns:[...nV(i.fileContextPath.toString()),...i.fileIgnorePatterns],resolveSymlinks:n.resolveSymlinks??!1,gzip:n.gzip??!0},u,{signal:r.signal,requestTimeoutMs:r.requestTimeoutMs}),(m=r.onBuildLogs)==null||m.call(r,new ZB(new Date,`info`,`Uploaded '${o}'`))}else{var h;(h=r.onBuildLogs)==null||h.call(r,new ZB(new Date,`info`,`Skipping upload of '${o}', already cached`))}});return await Promise.all(p),(s=r.onBuildLogs)==null||s.call(r,new ZB(new Date,`info`,`All file uploads completed`)),(c=r.onBuildLogs)==null||c.call(r,new ZB(new Date,`info`,`Starting building...`)),await TPe(e,{templateID:l,buildID:u,template:i.serialize(f)},t.getSignal(void 0,r.signal)),{alias:n,name:n,tags:d,templateId:l,buildId:u}}async instructionsWithHashes(){var e=this;return Promise.all(e.instructions.map(async(t,n)=>{if(t.type!==`COPY`)return t;let r=t.args.length>0?t.args[0]:null,i=t.args.length>1?t.args[1]:null;if(r===null||i===null)throw Error(`Source path and destination path are required`);let a;return n+1>=0&&n+1<e.stackTraces.length&&(a=e.stackTraces[n+1]),U(U({},t),{},{filesHash:await hPe(r,i,e.fileContextPath.toString(),[...dz===`browser`?[]:nV(e.fileContextPath.toString()),...e.fileIgnorePatterns],t.resolveSymlinks??!1,a)})}))}serialize(e){let t={startCmd:this.startCmd,readyCmd:this.readyCmd,steps:e,force:this.force};return this.baseImage!==void 0&&(t.fromImage=this.baseImage),this.baseTemplate!==void 0&&(t.fromTemplate=this.baseTemplate),this.registryConfig!==void 0&&(t.fromImageRegistry=this.registryConfig),t}});const gV=3e4,_V=1e3,vV=e=>`'${e.replaceAll(`'`,`'\\''`)}'`,yV=(e,t)=>(e??[]).flatMap(e=>t?.[e]===void 0?[`-u`,e]:[]),bV=e=>typeof e==`string`?e:``,xV=e=>e instanceof Error?`${e.name}: ${e.message}`:String(e),UPe=e=>EO({try:async()=>{let t=await XB.getInfo(e,{requestTimeoutMs:gV});if(t.state!==`running`)throw Error(`sandbox ${e} is ${t.state}, not running`);if(t.endAt.getTime()-Date.now()<=_V)throw Error(`sandbox ${e} has reached its end`);return XB.connect(e,{timeoutMs:_V,requestTimeoutMs:gV})},catch:e=>new cM({operation:`connect`,detail:xV(e)})}),WPe=e=>BO(UPe(e),t=>lM.of({name:`e2b:${e}`,run:(e,n)=>EO({try:async r=>{let i=Math.max(.001,n.timeoutMs/1e3).toFixed(3),a=[`exec`,`env`,...yV(n.unsetEnv,n.env),`LC_ALL=C`,`timeout`,`--verbose`,`-k`,`1s`,`${i}s`,...e].map((e,t)=>t<2?e:vV(e)).join(` `);try{let e=await t.commands.run(a,{timeoutMs:n.timeoutMs+5e3,requestTimeoutMs:gV,signal:r,...n.env===void 0?{}:{envs:{...n.env}},...n.cwd===void 0?{}:{cwd:n.cwd}});return{exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr,timedOut:!1}}catch(e){if(!(e instanceof wB))throw e;let t=bV(e.stderr),n=(e.exitCode===124||e.exitCode===137)&&t.includes(`timeout: sending signal`);return{exitCode:e.exitCode,stdout:bV(e.stdout),stderr:t,timedOut:n}}},catch:t=>new cM({operation:`run`,detail:`${e[0]??``}: ${xV(t)}`})}),start:(e,n)=>EO({try:async()=>{let r=[`set -C;`,`exec`,`env`,...yV(n.unsetEnv,n.env).map(vV),...e.map(vV),`>${vV(n.logPath)}`,`2>&1`,`</dev/null`].join(` `),i=await t.commands.run(r,{background:!0,timeoutMs:0,retainOutput:!1,requestTimeoutMs:gV,...n.env===void 0?{}:{envs:{...n.env}},...n.cwd===void 0?{}:{cwd:n.cwd}}),a=i.pid;return await i.disconnect(),a},catch:t=>new cM({operation:`start`,detail:`${e[0]??``}: ${xV(t)}`})}),readFile:(e,n)=>EO({try:async()=>t.files.read(e,{format:`bytes`,requestTimeoutMs:n}),catch:t=>new cM({operation:`readFile`,detail:`${e}: ${xV(t)}`})}),watchExit:(e,n)=>hCe(EO({try:async()=>{try{return await t.commands.connect(e,{timeoutMs:0,retainOutput:!1,requestTimeoutMs:gV})}catch(e){if(e instanceof YR)return;throw e}},catch:t=>new cM({operation:`watchExit`,detail:`${e}: ${xV(t)}`})}),e=>e===void 0?AO:TO(()=>e.disconnect())).pipe(BO(t=>t===void 0?DO(void 0):EO({try:async()=>{try{return(await t.wait()).exitCode}catch(e){if(e instanceof wB)return e.exitCode;throw e}},catch:t=>new cM({operation:`watchExit`,detail:`${e}: ${xV(t)}`})}).pipe(qO({duration:Math.max(1,n),orElse:()=>DO(void 0)}))))})),SV=e=>YSe(lM,WPe(e)),CV=(e,t,n)=>{let r={};for(let[n,i]of Object.entries(e))i!==void 0&&!(t??[]).includes(n)&&(r[n]=i);return{...r,...n}},GPe=e=>e?128+r.signals[e]:1,wV=JSe(lM,lM.of({name:`local`,run:(e,t)=>jO((n,r)=>{let[i,...a]=e;if(i===void 0){n(NO(new cM({operation:`run`,detail:`empty argv`})));return}x(i,a,{env:CV(process.env,t.unsetEnv,t.env),...t.cwd===void 0?{}:{cwd:t.cwd},timeout:Math.max(1,Math.ceil(t.timeoutMs)),killSignal:`SIGKILL`,maxBuffer:67108864,encoding:`utf8`,signal:r},(e,t,r)=>{if(e===null){n(DO({exitCode:0,stdout:t,stderr:r,timedOut:!1}));return}if(typeof e.code==`string`){n(NO(new cM({operation:`run`,detail:`${i}: ${e.code}`})));return}let a=e.killed===!0,o=typeof e.code==`number`?e.code:GPe(e.signal);n(DO({exitCode:o,stdout:t,stderr:r,timedOut:a}))})}),start:(e,t)=>jO(n=>{let[r,...i]=e;if(r===void 0){n(NO(new cM({operation:`start`,detail:`empty argv`,notStarted:!0})));return}let a;try{a=fe(t.logPath,`wx`,384)}catch(e){n(NO(new cM({operation:`start`,detail:`log ${String(e)}`,notStarted:!0})));return}let o=te(r,i,{detached:!0,stdio:[`ignore`,a,a],env:CV(process.env,t.unsetEnv,t.env),...t.cwd===void 0?{}:{cwd:t.cwd}});ce(a),o.once(`error`,e=>{n(NO(new cM({operation:`start`,detail:`${r}: ${e.message}`,notStarted:!0})))}),o.once(`spawn`,()=>{o.unref();let e=o.pid;n(e===void 0?NO(new cM({operation:`start`,detail:`${r}: no pid`})):DO(e))})}),readFile:e=>EO({try:async()=>new Uint8Array(await ye(e)),catch:t=>new cM({operation:`readFile`,detail:`${e}: ${String(t)}`})}),watchExit:()=>DO(DO(void 0))})),TV=[`xvfb`,`xfce4`,`dbus-x11`,`x11-utils`,`xdg-utils`,`xdotool`,`wmctrl`,`scrot`,`fonts-inter`,`fonts-dejavu`,`fonts-liberation`,`fonts-noto-color-emoji`,`libnss3`,`libgbm1`,`libnotify4`,`libsecret-1-0`,`libxss1`,`libxtst6`,`libxkbcommon0`,`libdrm2`],KPe={"22.04":[...TV,`libgtk-3-0`,`libasound2`],"24.04":[...TV,`libgtk-3-0t64`,`libasound2t64`]},qPe=String.raw`
477
+ receipt=$1; shift
478
+ if [ -e "$receipt" ] || [ -L "$receipt" ]; then
479
+ printf 'fresh-only install refuses an existing receipt directory\n' >&2; exit 64
480
+ fi
481
+ if [ "$(uname -s)" != Linux ] || [ ! -r /etc/os-release ]; then
482
+ printf 'prerequisite package lists target Ubuntu Linux\n' >&2; exit 65
483
+ fi
484
+ . /etc/os-release
485
+ release=$1; shift
486
+ if [ "$ID" != ubuntu ] || [ "$VERSION_ID" != "$release" ]; then
487
+ printf 'this guest is %s %s, not Ubuntu %s\n' "$ID" "$VERSION_ID" "$release" >&2; exit 66
488
+ fi
489
+ set -eu
490
+ umask 077
491
+ mkdir "$receipt"
492
+ log=$receipt/install.log
493
+ step() { printf '== %s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" >> "$log"; }
494
+ step 'apt-get update'
495
+ sudo -n env DEBIAN_FRONTEND=noninteractive apt-get update -q >> "$log" 2>&1
496
+ step 'apt-get install'
497
+ sudo -n env DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=300 install -y -q "$@" >> "$log" 2>&1
498
+ step 'dpkg-query'
499
+ dpkg-query -W -f='$'"{Package}\t"'$'"{Version}\n" "$@" > "$receipt/packages.tsv.tmp" 2>> "$log"
500
+ mv "$receipt/packages.tsv.tmp" "$receipt/packages.tsv"
501
+ printf 'desktop_prereqs=installed\nos=ubuntu\nversion=%s\n' "$VERSION_ID" > "$receipt/installed.tmp"
502
+ mv "$receipt/installed.tmp" "$receipt/installed"
503
+ step done
504
+ printf 'log %s %s\n' "$(wc -c < "$log" | tr -d ' ')" "$(sha256sum "$log" | cut -d ' ' -f 1)"
505
+ cat "$receipt/packages.tsv"
506
+ `,JPe=String.raw`
507
+ log=$1
508
+ if [ -f "$log" ]; then
509
+ printf 'log %s %s\n' "$(wc -c < "$log" | tr -d ' ')" "$(sha256sum "$log" | cut -d ' ' -f 1)"
510
+ tail -n 3 "$log"
511
+ else
512
+ printf 'absent\n'
513
+ fi
514
+ `,YPe=new Set([64,65,66]),EV=(e,t)=>{let n=/^log (\d+) ([0-9a-f]{64})$/u.exec(t??``);return n?.[1]===void 0||n[2]===void 0?void 0:{path:e,bytes:Number(n[1]),sha256:n[2]}},DV=e=>e.split(`
515
+ `).filter(e=>e.trim().length>0).slice(-3).join(` | `),XPe=(e,t)=>MO(function*(){if(!u(e))return yield*z(`receipt directory must be absolute`);let n=yield*lM,r=d(e,`install.log`),[i]=yield*mM([e],1e4).pipe(WO(e=>new _M({reason:`path check failed: ${e.message}`})));if(i===!0)return yield*z(`fresh-only install refuses an existing receipt directory`);let a=(yield*n.run([`sh`,`-c`,`sed -n 's/^VERSION_ID="\\{0,1\\}\\([^"]*\\)"\\{0,1\\}$/\\1/p' /etc/os-release`],{timeoutMs:1e4}).pipe(WO(e=>new _M({reason:`os-release read failed: ${e.message}`})))).stdout.trim(),o=KPe[a];if(o===void 0)return yield*z(`prerequisite package lists cover Ubuntu 22.04 and 24.04; this guest reports ${JSON.stringify(a)}`);let s=yield*n.run(uM(qPe,[e,a,...o]),{timeoutMs:t*1e3}).pipe(WO(e=>new _M({reason:`install could not run: ${e.message}`})));if(s.timedOut||s.exitCode!==0){let e=s.timedOut||!YPe.has(s.exitCode)?yield*RO(n.run(uM(JPe,[r]),{timeoutMs:1e4})):void 0,[i,...a]=e?._tag===`Success`?e.success.stdout.split(`
516
+ `):[],o=EV(r,i),c=o===void 0?DV(s.stderr)||`no output; see ${r}`:DV(a.join(`
517
+ `));return yield*NO(new _M({reason:s.timedOut?`install did not finish within ${t}s`:`install failed: ${c}`,...s.timedOut?{}:{nativeExit:s.exitCode},...o===void 0?{}:{log:o}}))}let c=s.stdout.split(`
518
+ `),l=EV(r,c.find(e=>e.startsWith(`log `)));return l===void 0?yield*FO(Error(`install reported no log facts`)):{status:`installed`,receipt_dir:e,ubuntu:a,packages:c.map(e=>e.split(` `)).filter(e=>e.length===2).map(([e,t])=>({name:e,version:t})),log:l}}),OV=`usage: impulse-compute linux-desktop <command> [flags]
519
+
520
+ Own or adopt an X11 desktop session in a Linux guest, launch and close apps in it,
521
+ capture raw screens and exact window crops, and verify exact crops. The guest is
522
+ an E2B sandbox (--sandbox <id>, with E2B_API_KEY set) or this machine. Paths named
523
+ --guest-dir, --tool-dir, --home and --receipt-dir are on the guest; --state-dir,
524
+ --output and --window-output are on this machine.
525
+
526
+ Each command prints one JSON object: on stdout when it completes, on stderr when it
527
+ refuses. crop verify prints its report on stdout whatever its verdict. Read the
528
+ JSON's "status" together with the exit code:
529
+ 0 done
530
+ 1 refused; or crop verify's "mismatch"; or a session stop that could not
531
+ confirm that everything it set out to end has ended (status "stopping",
532
+ on stdout: run the stop again)
533
+ 1-255 a refusal caused by a guest tool's failure exits with that tool's exit
534
+ code, which "native_exit" also gives
535
+ 2 a usage error, or crop verify's "uncheckable"
536
+ 70 a defect in this helper
537
+ "guest_retirement_required": true means retire the guest: something this helper
538
+ started there may still be running and cannot be ended safely.
539
+
540
+ session start --state-dir DIR --guest-dir DIR --tool-dir DIR --display :N
541
+ --geometry WxHxD --ready-timeout S --probe-timeout S
542
+ --shutdown-timeout S [--x11-dir DIR] [--sandbox ID] [--keyring]
543
+ Start a fresh Xvfb display and an XFCE session under its own
544
+ D-Bus session bus, and wait until both are ready.
545
+ session adopt --state-dir DIR --guest-dir DIR --tool-dir DIR --display :N
546
+ --geometry WxH --probe-timeout S [--x11-dir DIR] [--sandbox ID]
547
+ [--keyring]
548
+ Adopt a display that is already running, such as E2B Desktop's :0.
549
+ session inspect --state-dir DIR --timeout S
550
+ session stop --state-dir DIR --timeout S
551
+ End the apps it launched, then a keyring session's daemon, bus and
552
+ holder, then (owned session) its Xvfb and XFCE launches.
553
+ capture --state-dir DIR --output FILE.png --timeout S
554
+ [--window 0xID --window-output FILE.png]
555
+ Capture the raw screen and, with --window, an exact crop of that window's
556
+ visible frame, with the window manager's title bar and borders. A window
557
+ another managed window covers is refused; menus, tooltips and other
558
+ override-redirect windows are not checked.
559
+ app launch --state-dir DIR --name NAME --home DIR --timeout S -- COMMAND [ARGS...]
560
+ app relaunch --state-dir DIR --name NAME --timeout S
561
+ Start an app that has ended again, with the command and home of
562
+ its first launch.
563
+ app windows --state-dir DIR --name NAME --timeout S
564
+ app close --state-dir DIR --name NAME --timeout S
565
+ crop verify --raw RAW.png --crop CROP.png --box L T R B
566
+ [--content-box L T R B --min-margins T R B L]
567
+ prereqs install --receipt-dir DIR --timeout S [--sandbox ID]
568
+ Install Ubuntu 22.04's or 24.04's Xvfb, XFCE, capture, font and
569
+ Electron runtime packages with sudo -n apt-get, recording them in
570
+ DIR, which must not exist yet and whose parent must, and apt-get's
571
+ output and every step's errors in DIR/install.log.
572
+
573
+ --x11-dir is where the X server keeps its .X<n>-lock and .X11-unix socket: /tmp on Linux.
574
+
575
+ --keyring also starts a test keyring for the apps the session launches: a private
576
+ D-Bus session bus whose Secret Service daemon (gnome-keyring-daemon, run with
577
+ dbus-daemon and dbus-send from --tool-dir) holds an unlocked login collection,
578
+ under a password generated in the guest. It lasts until session stop, and the
579
+ session reports guest_retirement_required: true. Any process of the guest's user
580
+ can read that collection, so store only made-up secrets in it.
581
+ `;var kV=class extends Error{reason;constructor(e){super(e),this.reason=e}};const AV=e=>`${JSON.stringify(e)}\n`,jV=(e,t)=>{let n=e[t]?.[0]??``;if(!u(n))throw new kV(`${t}: must be an absolute path`);return p(n)},MV=(e,t,n)=>e[t]===void 0?n:jV(e,t),NV=(e,t)=>{let n=e[t]?.[0]??``,r=/^\s*[+]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$/u.test(n)?Number(n):NaN;if(!Number.isFinite(r)||r<=0)throw new kV(`${t}: must be finite and greater than zero`);return r},PV=e=>{let t=e[`--display`]?.[0]??``;if(!/^:\d+$/u.test(t))throw new kV(`--display: must be a local display such as :99`);return`:${Number(t.slice(1))}`},FV=(e,t)=>{let n=e[`--geometry`]?.[0]??``;if(!(t?/^[1-9]\d*x[1-9]\d*x[1-9]\d*$/u:/^[1-9]\d*x[1-9]\d*$/u).test(n))throw new kV(`--geometry: must be positive ${t?`WIDTHxHEIGHTxDEPTH`:`WIDTHxHEIGHT`}`);return n},IV=(e,t,n=!1)=>{let r=jN(e,t,{allowRest:n});if(!r.ok)throw new kV(r.reason);return r},LV=(e=1)=>({arity:e,required:!0}),RV=(e=1)=>({arity:e}),zV=e=>e===void 0?wV:SV(e),BV=e=>BO(AM(e),e=>e.guest===`local`?wV:SV(e.guest.slice(4))),VV=(e,t)=>LO(e,e=>t.pipe(mCe(e),HO(`GuestError`,e=>NO(new _M({reason:e.message}))))),HV=(e,t=0)=>({stdout:AV(e),exitCode:t}),UV=e=>{let t=e[`--sandbox`]?.[0];if(t!==void 0&&!/^[a-z0-9]+$/u.test(t))throw new kV(`--sandbox: must be an E2B sandbox id`);return t},WV={"session start":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--guest-dir":LV(),"--tool-dir":LV(),"--display":LV(),"--geometry":LV(),"--ready-timeout":LV(),"--probe-timeout":LV(),"--shutdown-timeout":LV(),"--x11-dir":RV(),"--sandbox":RV(),"--keyring":RV(0)}),n={stateDir:jV(t,`--state-dir`),guestDir:jV(t,`--guest-dir`),toolDir:jV(t,`--tool-dir`),x11Dir:MV(t,`--x11-dir`,`/tmp`),display:PV(t),geometry:FV(t,!0),readyTimeout:NV(t,`--ready-timeout`),probeTimeout:NV(t,`--probe-timeout`),shutdownTimeout:NV(t,`--shutdown-timeout`),keyring:t[`--keyring`]!==void 0};return BO(VV(DO(zV(UV(t))),aEe(n)),e=>HV(e))},"session adopt":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--guest-dir":LV(),"--tool-dir":LV(),"--display":LV(),"--geometry":LV(),"--probe-timeout":LV(),"--x11-dir":RV(),"--sandbox":RV(),"--keyring":RV(0)}),n={stateDir:jV(t,`--state-dir`),guestDir:jV(t,`--guest-dir`),toolDir:jV(t,`--tool-dir`),x11Dir:MV(t,`--x11-dir`,`/tmp`),display:PV(t),geometry:FV(t,!1),probeTimeout:NV(t,`--probe-timeout`),keyring:t[`--keyring`]!==void 0};return BO(VV(DO(zV(UV(t))),sEe(n)),e=>HV(e))},"session inspect":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--timeout":LV()}),n=jV(t,`--state-dir`),r=NV(t,`--timeout`);return BO(VV(BV(n),yN(n,r)),e=>HV({status:`ready`,run_id:e.session.run_id,guest:e.session.guest,observed:e.observation,connection:e.session.connection,...e.session.keyring?.phase===`ready`?{keyring:ZM(e.session.keyring)}:{}}))},"session stop":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--timeout":LV()}),n=jV(t,`--state-dir`),r=NV(t,`--timeout`);return BO(VV(BV(n),cEe(n,r)),e=>HV(e,`failed`in e&&e.failed?1:0))},capture:e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--output":LV(),"--timeout":LV(),"--window":RV(),"--window-output":RV()}),n=jV(t,`--state-dir`),r=jV(t,`--output`),i=NV(t,`--timeout`),a=t[`--window`]?.[0],o=t[`--window-output`]===void 0?void 0:jV(t,`--window-output`);if(a===void 0!=(o===void 0))throw new kV(`--window and --window-output go together`);return BO(VV(BV(n),qEe({stateDir:n,output:r,timeout:i,...a!==void 0&&o!==void 0?{window:{id:a,output:o}}:{}})),e=>HV(e))},"app launch":e=>{let{values:t,rest:n}=IV(e,{"--state-dir":LV(),"--name":LV(),"--home":LV(),"--timeout":LV()},!0),r=jV(t,`--state-dir`),i={stateDir:r,name:t[`--name`]?.[0]??``,home:jV(t,`--home`),timeout:NV(t,`--timeout`),argv:n};if(n.length===0)throw new kV(`app launch needs a command after --`);return BO(VV(BV(r),vEe(i)),e=>HV(e))},"app relaunch":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--name":LV(),"--timeout":LV()}),n=jV(t,`--state-dir`);return BO(VV(BV(n),yEe({stateDir:n,name:t[`--name`]?.[0]??``,timeout:NV(t,`--timeout`)})),e=>HV(e))},"app windows":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--name":LV(),"--timeout":LV()}),n=jV(t,`--state-dir`);return BO(VV(BV(n),bEe(n,t[`--name`]?.[0]??``,NV(t,`--timeout`))),e=>HV(e))},"app close":e=>{let{values:t}=IV(e,{"--state-dir":LV(),"--name":LV(),"--timeout":LV()}),n=jV(t,`--state-dir`);return BO(VV(BV(n),xEe(n,t[`--name`]?.[0]??``,NV(t,`--timeout`))),e=>HV(e))},"prereqs install":e=>{let{values:t}=IV(e,{"--receipt-dir":LV(),"--timeout":LV(),"--sandbox":RV()}),n=jV(t,`--receipt-dir`),r=NV(t,`--timeout`);return BO(VV(DO(zV(UV(t))),XPe(n,r)),e=>HV(e))}},ZPe=(e,t)=>{let n=t.nativeExit;return{stderr:AV({status:`unavailable`,reason:t.reason,native_exit:n??null,guest_retirement_required:e===`session start`||t.retire===!0,...t.log===void 0?{}:{log:t.log}}),exitCode:n!==void 0&&n>0&&n<256?n:1}},QPe=e=>{if(e.length===0)return DO({stderr:OV,exitCode:2});if(e[0]===`--help`||e[0]===`-h`||e[0]===`help`)return DO({stdout:OV,exitCode:0});if(e[0]===`crop`&&e[1]===`verify`)return BO(iP(e.slice(2)),e=>({stdout:`${GEe(e.report)}\n`,exitCode:e.exitCode}));let t=e.length>=2&&WV[`${e[0]} ${e[1]}`]!==void 0?`${e[0]} ${e[1]}`:e[0]??``,n=WV[t];if(n===void 0)return DO({stderr:AV({status:`usage`,reason:`unknown command ${JSON.stringify(t)}`}),exitCode:2});let r=e.slice(t.split(` `).length);return OO(()=>{try{return n(r)}catch(e){if(e instanceof kV)return DO({stderr:AV({status:`usage`,reason:e.reason}),exitCode:2});throw e}}).pipe(HO(`Unavailable`,e=>DO(ZPe(t,e))),UO(e=>DO({stderr:AV({status:`error`,reason:PSe(e)}),exitCode:70})))},$Pe=e=>ECe(LO(QPe(e),e=>kO(()=>{e.stdout!==void 0&&process.stdout.write(e.stdout),e.stderr!==void 0&&process.stderr.write(e.stderr),process.exitCode=e.exitCode}))),GV={done:0,failure:1,usage:2,blocked:3,notInstalled:77},KV=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}},qV={pipe(){return KV(this,arguments)}},JV=function(){function e(){}return e.prototype=qV,e}(),W=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},YV=e=>e,XV=e=>()=>e,ZV=XV(!0),QV=XV(!1),$V=XV(void 0),eH=$V;function tH(e,...t){return KV(e,t)}function nH(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i}}function rH(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i!==n&&t.set(i,i),i}}const eFe=[`line`,`column`,`sourceURL`,`originalLine`,`originalColumn`],iH=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;if(e instanceof Error){t.delete(`stack`);for(let n of eFe)Object.prototype.propertyIsEnumerable.call(e,n)||t.delete(n)}let n=Object.getPrototypeOf(e),r=n;for(;r!==null&&r!==Object.prototype;){let e=Reflect.ownKeys(r);for(let n=0;n<e.length;n++)t.add(e[n]);r=Object.getPrototypeOf(r)}return t.has(`constructor`)&&typeof e.constructor==`function`&&n===e.constructor.prototype&&t.delete(`constructor`),t},aH=new WeakSet,oH=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),sH=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer,cH=e=>{try{return new Uint8Array(e)}catch{return}};let lH=0;const tFe=()=>{lH++};function uH(e){return typeof e==`string`}function dH(e){return typeof e==`number`}function fH(e){return typeof e==`boolean`}function nFe(e){return typeof e==`symbol`}function rFe(e){return uH(e)||dH(e)||nFe(e)}function pH(e){return typeof e==`function`}function mH(e){return e===void 0}function hH(e){return e!==void 0}function gH(e){return e!==null}function iFe(e){return e==null}function aFe(e){return e!=null}function oFe(e){return!0}function _H(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vH(e){return typeof e==`object`&&!!e||pH(e)}const yH=W(2,(e,t)=>vH(e)&&t in e),bH=W(2,(e,t)=>yH(e,`_tag`)&&e._tag===t);function sFe(e){return e instanceof Error}function cFe(e){return yH(e,Symbol.iterator)||uH(e)}const xH=`~effect/Hash`,SH=e=>{switch(typeof e){case`number`:return OH(e);case`bigint`:return kH(e.toString(10));case`string`:return kH(e);case`function`:case`object`:if(e===null)break;if(e instanceof Date)return Number.isNaN(e.getTime())?kH(`Invalid Date`):kH(e.toISOString());if(e instanceof RegExp)return kH(e.toString());{if(aH.has(e))return CH(e);let t=FH.get(e);if(t!==void 0)return t;if(IH.has(e))return tFe(),kH(`[Circular]`);IH.add(e);let n=lH,r;try{if(lFe(e))r=e[xH]();else if(typeof e==`function`)r=CH(e);else if(sH(e)){let t=cH(e);r=t===void 0?CH(e):MH(t)}else r=e instanceof DataView?MH(oH(e)):Array.isArray(e)||ArrayBuffer.isView(e)?MH(e):e instanceof Map?dFe(e):e instanceof Set?fFe(e):AH(e)}finally{IH.delete(e)}return n===lH&&FH.set(e,r),r}}return EH(wH(kH(String(e))))},CH=e=>(PH.has(e)||PH.set(e,EH(Math.random()*4294967296|0)),PH.get(e)),wH=e=>(e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^e>>>16),TH=W(2,(e,t)=>wH(Math.imul(e,2654435761)+Math.imul(t,2246822507))),EH=e=>e&3221225471|e>>>1&1073741824,lFe=e=>yH(e,`~effect/Hash`)&&typeof e[`~effect/Hash`]==`function`,DH=new DataView(new ArrayBuffer(8)),OH=e=>{let t=e|0;return t===e?EH(t):(DH.setFloat64(0,e===e?e:NaN),EH(TH(DH.getInt32(0),DH.getInt32(4))))},kH=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return EH(t)},uFe=(e,t)=>{let n=12289;for(let r of t)n^=TH(SH(r),SH(e[r]));return EH(n)},AH=e=>uFe(e,iH(e)),jH=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return EH(r)},MH=e=>{let t=6151;for(let n of e)t=TH(t,SH(n));return EH(t)},dFe=jH(kH(`Map`),([e,t])=>TH(SH(e),SH(t))),NH=kH(`Set`),fFe=jH(NH,e=>TH(NH,SH(e))),PH=new WeakMap,FH=new WeakMap,IH=new WeakSet,LH=`~effect/Equal`;function RH(){return arguments.length===1?e=>zH(e,arguments[0]):zH(arguments[0],arguments[1])}function zH(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let n=typeof e;return n===typeof t?n===`number`&&e!==e&&t!==t?!0:n!==`object`&&n!==`function`||aH.has(e)||aH.has(t)?!1:pFe(e,t):!1}function pFe(e,t){let n=VH.length;for(let r=n;r-->0;)if(VH[r]===e&&HH[r]===t)return!0;if(n)return BH(e,t);let r=UH.get(e);r||UH.set(e,r=new WeakMap);let i=r.get(t);return i===void 0&&r.set(t,i=BH(e,t)),i}function BH(e,t){VH.push(e),HH.push(t);try{return mFe(e,t)}finally{VH.pop(),HH.pop()}}const VH=[],HH=[],UH=new WeakMap;function mFe(e,t){if(SH(e)!==SH(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let n=KH(e);if(n!==KH(t)||typeof e==`function`&&!n)return!1;if(n)return e[LH](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:hFe(e,t);if(sH(e)){if(!sH(t)||e instanceof ArrayBuffer!=t instanceof ArrayBuffer)return!1;let n=cH(e),r=cH(t);return n!==void 0&&r!==void 0&&WH(n,r)}if(ArrayBuffer.isView(e)){let n=e instanceof DataView;return!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||n!==t instanceof DataView?!1:n?WH(oH(e),oH(t)):WH(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:GH(e,t,_Fe,vFe):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:GH(e,t,SH,zH):gFe(e,t)}function hFe(e,t){for(let n=0;n<e.length;n++)if(!zH(e[n],t[n]))return!1;return!0}function WH(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function gFe(e,t){let n=iH(e),r=iH(t);if(n.size!==r.size)return!1;for(let i of n)if(!r.has(i)||!zH(e[i],t[i]))return!1;return!0}function GH(e,t,n,r){let i=new Map,a=0;for(let e of t){let t=n(e),r=i.get(t);r?r.push(e):i.set(t,[e]),a++}outer:for(let t of e){let e=i.get(n(t));if(e){for(let n=0;n<e.length;n++)if(r(t,e[n])){e[n]=e[e.length-1],e.pop(),a--;continue outer}}return!1}return a===0}const _Fe=e=>SH(e[0]),vFe=(e,t)=>zH(e[0],t[0])&&zH(e[1],t[1]),KH=e=>yH(e,`~effect/Equal`)&&typeof e[`~effect/Equal`]==`function`,qH=Symbol.for(`~effect/Redactable`),yFe=e=>yH(e,qH);function JH(e){return yFe(e)?YH(e):e}function YH(e){return e[qH](globalThis[`~effect/Fiber/currentFiber`]?.context??bFe)}const XH=`~effect/Fiber/currentFiber`,ZH=new Map,bFe={"~effect/Context":{},base:ZH,depth:0,mapUnsafe:ZH,pipe(){return KV(this,arguments)}};function QH(e,t){let n=t?.space??0,r=new WeakSet,i=n?typeof n==`number`?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,t=0){try{return l(e,t)}catch{return(typeof e==`object`&&e||typeof e==`function`)&&r.delete(e),`[inspection threw]`}}function l(e,n=0){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||e==null||typeof e==`boolean`||typeof e==`symbol`)return String(e);if(typeof e==`bigint`)return String(e)+`n`;if(typeof e==`object`||typeof e==`function`){if(r.has(e))return xFe;r.add(e);let l;if(qH in e)l=c(YH(e),n);else if(Array.isArray(e))l=!i||e.length<=1?`[${e.map(e=>c(e,n)).join(`,`)}]`:`[\n${a(n+1)}${e.map(e=>c(e,n+1)).join(`,
582
+ `+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=CFe(e);else if(!t?.ignoreToString&&yH(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=wFe(e);l=e instanceof Error&&e.cause!==void 0?`${t} (cause: ${c(e.cause,n)})`:t}else if(Symbol.iterator in e)l=`${e.constructor.name}(${c(Array.from(e),n)})`;else{let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${$H(t)}:${c(eU(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${$H(t)}: ${c(eU(e,t),n+1)}`).join(`,
583
+ `)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}const xFe=`[Circular]`;function $H(e){return typeof e==`string`?JSON.stringify(e):String(e)}function SFe(e){return e.map(e=>`[${$H(e)}]`).join(``)}function CFe(e){try{return e.toISOString()}catch{return`Invalid Date`}}function wFe(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function eU(e,t){try{return e[t]}catch{return`[property access threw]`}}function tU(e,t){let n=[],r=new WeakMap;return JSON.stringify(e,function(e,t){let i=Object.getOwnPropertyDescriptor(r.get(this)??this,e)?.value,a=yH(i,qH)?JH(i):JH(t);if(typeof a==`bigint`)return QH(a);if(typeof a!=`object`||!a)return a;let o=a instanceof Error&&!yH(a,`toJSON`)?{...a,name:a.name,message:a.message}:a;for(;n.length>0&&n[n.length-1]!==this;)n.pop();if(n.includes(a))return;if(n.push(a),o!==a&&n.push(o),!TFe(o)||DFe(o))return o;let s=EFe(o);return r.set(s,o),n.push(s),s},t?.space)??`null`}function TFe(e){for(let t of Object.getOwnPropertyNames(e))if(Object.getOwnPropertyDescriptor(e,t)?.get!==void 0)return!0;return!1}function EFe(e){let t=Array.isArray(e)?[]:{},n=Array.isArray(e)?Array.from({length:e.length},(e,t)=>String(t)):Object.keys(e);for(let r of n)Object.defineProperty(t,r,{enumerable:!0,get:()=>{let t=Reflect.get(e,r);return Object.getOwnPropertyDescriptor(e,r)?.get===void 0?t:JH(t)}});return t}function DFe(e){for(let t of[Number.prototype.valueOf,Boolean.prototype.valueOf,String.prototype.valueOf])try{return Reflect.apply(t,e,[]),!0}catch{}return!1}const nU=Symbol.for(`nodejs.util.inspect.custom`),rU=e=>{try{return e=JH(e),yH(e,`toJSON`)&&pH(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(rU):e}catch{return`[toJSON threw]`}},OFe=(e,t=2)=>{if(typeof e==`string`)return e;try{return typeof e==`object`?tU(e,{space:t}):QH(e,{space:t})}catch{return String(e)}},iU={toJSON(){return rU(this)},[nU](){return this.toJSON()},toString(){return QH(this.toJSON())}},kFe=(()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),aU=()=>Error.stackTraceLimit,oU=e=>{kFe&&(Error.stackTraceLimit=e)};var sU=class{constructor(e){this.value=e,this.done=!1}next(e){return this.done?(this.value=e,this):(this.done=!0,{value:this.value,done:!1})}};const cU=(()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}},r=aU();if(r===0)return n[e];oU(2);let i=t[e](()=>Error());return oU(r),i.stack?.includes(e)===!0?t[e]:n[e]})();function lU(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function AFe(e,t){if(!Object.hasOwn(t,`__proto__`)){Object.assign(e,t);return}for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&lU(e,n,t[n])}const uU=`~effect/Effect`,dU=`~effect/Exit`,jFe={_A:YV,_E:YV,_R:YV},fU=`${uU}/identifier`,pU=`${uU}/args`,mU=`${uU}/evaluate`,hU=`${uU}/successCont`,gU=`${uU}/failureCont`,_U=`${uU}/ensureCont`,vU=Symbol.for(`effect/Effect/Yield`),yU={pipe(){return KV(this,arguments)},toJSON(){return{...this}},toString(){return QH(this.toJSON(),{ignoreToString:!0,space:2})},[nU](){return this.toJSON()}},MFe={[uU]:jFe,...yU,[Symbol.iterator](){return new sU(this)},toJSON(){return{_id:`Effect`,op:this[fU],...pU in this?{args:this[pU]}:void 0}}},bU=e=>yH(e,uU),xU=e=>yH(e,dU),SU=`~effect/Cause`,CU=`~effect/Cause/Reason`,wU=e=>yH(e,SU);var TU=class{constructor(e){this[SU]=SU,this.reasons=e}pipe(){return KV(this,arguments)}toJSON(){return{_id:`Cause`,reasons:this.reasons.map(e=>e.toJSON())}}toString(){return`Cause(${QH(this.reasons)})`}[nU](){return this.toJSON()}[LH](e){return wU(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>RH(t,e.reasons[n]))}[xH](){return MH(this.reasons)}};const EU=new WeakMap;var DU=class{[CU];annotations;_tag;constructor(e,t,n){if(this[CU]=CU,this._tag=e,t!==OU&&typeof n==`object`&&n&&t.size>0){let e=EU.get(n);e&&(t=new Map([...e,...t])),EU.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);if(e.mapUnsafe.forEach((e,r)=>{t?.overwrite!==!0&&n.has(r)||n.set(r,e)}),t?.overwrite!==!0&&n.size===this.annotations.size)return this;let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return KV(this,arguments)}toString(){return QH(this)}[nU](){return this.toString()}};const OU=new Map;var kU=class extends DU{constructor(e,t=OU){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${QH(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[LH](e){return LU(e)&&RH(this.error,e.error)&&RH(this.annotations,e.annotations)}[xH](){return TH(kH(this._tag))(TH(SH(this.error))(SH(this.annotations)))}};const AU=e=>new TU(e),NFe=(e,t)=>{let n=new Map,r=[];for(let i of e.concat(t)){let e=SH(i),t=n.get(e);if(t===void 0)n.set(e,[i]);else if(t.some(e=>RH(e,i)))continue;else t.push(i);r.push(i)}return r},jU=W(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new TU(NFe(e.reasons,t.reasons));return RH(e,n)?e:n}),MU=(e,t)=>{let n=e.reasons.slice();for(let e of t.reasons)zU(e)&&!n.some(t=>zU(t)&&t.fiberId===e.fiberId&&t.annotations===e.annotations)&&n.push(e);return n.length===e.reasons.length?e:new TU(n)},PFe=new TU([]),NU=e=>new TU([new kU(e)]);var PU=class extends DU{constructor(e,t=OU){super(`Die`,t,e),this.defect=e}toString(){return`Die(${QH(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[LH](e){return RU(e)&&RH(this.defect,e.defect)&&RH(this.annotations,e.annotations)}[xH](){return TH(kH(this._tag))(TH(SH(this.defect))(SH(this.annotations)))}};const FU=e=>new TU([new PU(e)]),IU=W(e=>wU(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new TU(e.reasons.map(e=>e.annotate(t,n)))),LU=e=>e._tag===`Fail`,RU=e=>e._tag===`Die`,zU=e=>e._tag===`Interrupt`;function FFe(e){return JU(`Effect.evaluate: Not implemented`)}const BU=e=>({...MFe,[fU]:e.op,[mU]:e[mU]??FFe,[hU]:e[hU],[gU]:e[gU],[_U]:e[_U]}),VU=e=>{let t=BU(e),n=function(e){this[pU]=e};return n.prototype=t,function(e){return new n(e)}},HU=e=>{let t={[dU]:dU,_tag:e.op,get[e.prop](){return this[pU]},...BU(e),toString(){return`${e.op}(${QH(this[pU])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[pU]}},[LH](e){return xU(e)&&e._tag===this._tag&&RH(this[pU],e[pU])},[xH](){return TH(kH(e.op),SH(this[pU]))}},n=function(e){this[pU]=e};return n.prototype=t,function(e){return new n(e)}},UU=HU({op:`Success`,prop:`value`,[mU](e){let t=e.getCont(hU);return t?t[hU](this[pU],e,this):e.yieldWith(this)}}),WU={key:`effect/Cause/StackTrace`},GU={key:`effect/Cause/InterruptorStackTrace`},KU=HU({op:`Failure`,prop:`cause`,[mU](e){let t=this[pU],n=!1;e.cache.stackFrame&&(t=IU(t,{mapUnsafe:new Map([[WU.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(gU),i=e._interruptedCause;if(i&&e.interruptible){let a=!1;for(;r&&e.interruptible;)a||=fU in r,r=e.getCont(gU);a&&(t=AU(t.reasons.filter(e=>e._tag!==`Fail`))),t=MU(t,i),n=!0}return r?r[gU](t,e,n?void 0:this):e.yieldWith(n?KU(t):this)}}),qU=e=>KU(NU(e)),JU=e=>KU(FU(e)),YU=VU({op:`WithFiber`,[mU](e){return this[pU](e)}}),IFe=function(){class e extends globalThis.Error{}let t=BU({op:`YieldableError`,[mU](){return qU(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),XU=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return class extends IFe{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(AFe(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),ZU=e=>{class t extends XU{_tag=e}return t.prototype.name=e,t},QU=`~effect/Cause/Done`,$U=e=>yH(e,QU),eW={[QU]:QU,_tag:`Done`,value:void 0},tW=e=>e===void 0?eW:{[QU]:QU,_tag:`Done`,value:e},LFe=qU(eW),RFe=e=>e===void 0?LFe:qU(tW(e)),nW=e=>BU({op:e.label,[mU]:e.evaluate}),rW=e=>(t,n)=>t===n||e(t,n),zFe=(e,t)=>e===t,BFe=()=>zFe;function VFe(e){return rW((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e(t[r],n[r]))return!1;return!0})}const iW=`~effect/Option`,aW={[iW]:{_A:e=>e},...yU,[Symbol.iterator](){return new sU(this)}},HFe=Object.defineProperty(Object.assign(Object.create(aW),{_tag:`Some`,_op:`Some`,[LH](e){return oW(e)&&cW(e)&&RH(this.value,e.value)},[xH](){return TH(SH(this._tag))(SH(this.value))},toString(){return`some(${QH(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:rU(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),UFe=SH(`None`),WFe=Object.assign(Object.create(aW),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[LH](e){return oW(e)&&sW(e)},[xH](){return UFe},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),oW=e=>yH(e,iW),sW=e=>e._tag===`None`,cW=e=>e._tag===`Some`,GFe=Object.create(WFe),lW=function(e){this.value=e};lW.prototype=HFe;const KFe=e=>new lW(e),uW=`~effect/Result`,dW={[uW]:{_A:e=>e,_E:e=>e},...yU,[Symbol.iterator](){return new sU(this)}},qFe=Object.assign(Object.create(dW),{_tag:`Success`,_op:`Success`,[LH](e){return fW(e)&&mW(e)&&RH(this.success,e.success)},[xH](){return TH(SH(this._tag))(SH(this.success))},toString(){return`success(${QH(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:rU(this.success)}}}),JFe=Object.assign(Object.create(dW),{_tag:`Failure`,_op:`Failure`,[LH](e){return fW(e)&&pW(e)&&RH(this.failure,e.failure)},[xH](){return TH(SH(this._tag))(SH(this.failure))},toString(){return`failure(${QH(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:rU(this.failure)}}}),fW=e=>yH(e,uW),pW=e=>e._tag===`Failure`,mW=e=>e._tag===`Success`,hW=function(e){this.failure=e};hW.prototype=JFe;const YFe=e=>new hW(e),gW=function(e){this.success=e};gW.prototype=qFe;const XFe=e=>new gW(e);function _W(e){return(t,n)=>t===n?0:e(t,n)}const vW=_W((e,t)=>e<t?-1:1),yW=_W((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t)?0:globalThis.Number.isNaN(e)?-1:globalThis.Number.isNaN(t)?1:e<t?-1:1),bW=W(2,(e,t)=>_W((n,r)=>e(t(n),t(r)))),xW=e=>W(2,(t,n)=>e(t,n)===-1),SW=e=>W(2,(t,n)=>e(t,n)===1),ZFe=e=>W(2,(t,n)=>e(t,n)!==1),QFe=e=>W(2,(t,n)=>e(t,n)!==-1),G=()=>GFe,CW=KFe,$Fe=oW,wW=sW,TW=cW,EW=W(2,(e,{onNone:t,onSome:n})=>wW(e)?t():n(e.value)),DW=W(2,(e,t)=>wW(e)?t():e.value),eIe=W(2,(e,t)=>wW(e)?t():e),OW=e=>e==null?G():CW(e),kW=e=>e===void 0?G():CW(e),AW=DW($V),tIe=e=>(...t)=>{try{return CW(e(...t))}catch{return G()}},nIe=W(2,(e,t)=>wW(e)?G():CW(t(e.value))),jW=W(2,(e,t)=>wW(e)?G():t(e.value)),MW=W(2,(e,t)=>!wW(e)&&t(e.value)),NW=`~effect/Context/Service`,PW=function(){function e(){}let t=e;Object.setPrototypeOf(t,rIe);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[IW]=IW,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&FW.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},rIe={[NW]:NW,...nW({label:`Service`,evaluate(e){return UU(QW(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return qW(this,e)},use(e){return YU(t=>e(QW(t.context,this)))},useSync(e){return YU(t=>UU(e(QW(t.context,this))))}},FW=new Set,IW=`~effect/Context/Reference`,LW=`~effect/Context`,RW=(e,t,n,r,i)=>{let a=Object.create(aIe);return a.cacheRoot=e??a,a.base=t,a.overlay=n,a.depth=r,a._flat=void 0,a.baseHits=0,a.maxDepth=i,a},zW=(e,t)=>{t&&(zW(e,t.parent),e.set(t.key,t.value))},BW=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return zW(t,e.overlay),e._flat=t},iIe=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),RW(void 0,n,void 0,0,e.maxDepth)},VW=Symbol(),HW=(e,t)=>{let n=e;for(let e=n.overlay;e;e=e.parent)if(e.key===t)return e.value;let r=n.base.get(t);return r===void 0&&!n.base.has(t)?VW:(n.overlay&&++n.baseHits>=n.base.size&&n.baseHits>=8&&(n.base=BW(n),n.overlay=void 0,n.depth=0),r)},UW=(e,t)=>{let n=t?.maxDepth;return RW(void 0,e,void 0,0,Number.isInteger(n)&&n>=0?n:8)},aIe={get mapUnsafe(){return BW(this)},...yU,[LW]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[LH](e){if(!WW(e))return!1;let t=this.mapUnsafe,n=e.mapUnsafe;if(t.size!==n.size)return!1;for(let[e,r]of t)if(!n.has(e)||!RH(r,n.get(e)))return!1;return!0},[xH](){return OH(this.mapUnsafe.size)}},oIe=(e,t)=>e.cacheRoot===t.cacheRoot,WW=e=>yH(e,LW),GW=e=>!!e[IW],KW=()=>sIe,sIe=UW(new Map),qW=(e,t)=>UW(new Map([[e.key,t]])),JW=W(3,(e,t,n)=>cIe(e,t.key,n)),cIe=(e,t,n)=>{let r=e,i=FW.has(t)?void 0:r.cacheRoot;if(r.depth>=r.maxDepth){let e=new Map(r._flat??r.base);return r._flat||zW(e,r.overlay),e.set(t,n),RW(i,e,void 0,0,r.maxDepth)}return RW(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1,r.maxDepth)},YW=W(2,(e,t)=>XW(e,t.key)),XW=(e,t)=>{let n=HW(e,t);return n===VW?void 0:n},ZW=W(2,(e,t)=>{let n=HW(e,t.key);if(n===VW){if(GW(t))return eG(t);throw lIe(t)}return n}),QW=ZW,$W=`~effect/Context/defaultValue`,eG=e=>$W in e?e[$W]:e[$W]=e.defaultValue(),lIe=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(t.stack){let e=t.stack.split(`
584
+ `);e.splice(1,3),t.stack=e.join(`
585
+ `)}return t},uIe=W(2,(e,t)=>{let n=HW(e,t.key);return n===VW?GW(t)?CW(eG(t)):G():CW(n)}),tG=W(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:iIe(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),dIe=(...e)=>{let t=new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return UW(t)},nG=PW,rG=e=>e.length>0,iG=e=>e>0?Math.floor(e):0,aG=XFe,oG=YFe,fIe=e=>{if(pH(e))try{return aG(e())}catch(e){return oG(e)}try{return aG(e.try())}catch(t){return oG(e.catch(t))}},pIe=fW,sG=pW,cG=mW,mIe=W(2,(e,t)=>sG(e)?oG(t(e.failure)):e),hIe=W(2,(e,{onFailure:t,onSuccess:n})=>sG(e)?t(e.failure):n(e.success)),gIe=W(2,(e,t)=>{if(cG(e))return e.success;throw t(e.failure)})(YV),_Ie=W(2,(e,t)=>{let n=0;for(let r of e){let e=t(r,n);if(fH(e)){if(e)return CW(r)}else if(TW(e))return e;n++}return G()}),lG=globalThis.Array,uG=e=>lG.isArray(e)?e:lG.from(e),dG=W(2,(e,{onEmpty:t,onNonEmpty:n})=>pG(e)?n(e):t()),fG=W(2,(e,t)=>[...e,t]);lG.isArray;const vIe=rG,pG=rG,mG=W(2,(e,t)=>{let n=0;for(let r of e){if(t(r,n))return CW(n);n++}return G()}),yIe=_Ie,bIe=W(2,(e,t)=>{let n=uG(e);for(let e=n.length-1;e>=0;e--){let r=n[e],i=t(r,e);if(typeof i==`boolean`){if(i)return CW(r)}else if(TW(i))return i}return G()}),xIe=W(2,(e,t)=>{let n=lG.from(e);return n.sort(t),n}),hG=()=>[],gG=e=>[e],_G=W(2,(e,t)=>e.map(t)),vG=W(3,(e,t,n)=>uG(e).reduce((e,t,r)=>n(e,t,r),t)),yG=`~effect/Duration`,bG=BigInt(0),xG=BigInt(1),SG=BigInt(2),SIe=BigInt(10),CG=BigInt(24),wG=BigInt(60),TG=BigInt(1e3),EG=BigInt(1e6),DG=BigInt(1e9),CIe=BigInt(6e10),wIe=BigInt(36e11),TIe=BigInt(864e11),EIe=BigInt(6048e11),OG=e=>BigInt(Math.sign(e)*Math.round(Math.abs(e))),kG=e=>Number.isInteger(e)?BigInt(e)*EG:OG(e*1e6),AG=e=>BG(Number.isFinite(e)?OG(e):e),jG=(e,t)=>{let n=Number(e);if(Number.isFinite(n))return n/t;let r=BigInt(t);return Number(e/r)+Number(e%r)/t},MG=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=SIe**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t;return NG(r?-o:o,a)},NG=(e,t)=>{let n=e<bG?-e:e,r=n/t+(n%t*SG>=t?xG:bG);return e<bG?-r:r},PG=(e,t)=>{let n=Number(e)*t;if(!Number.isFinite(n))return BG(n);let r=MG(e,BigInt(t)*EG);return BG(Number.isInteger(n)&&BigInt(n)*EG===r?n:r)},DIe=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,FG=e=>{switch(typeof e){case`number`:return KG(e);case`bigint`:return GG(e);case`string`:{if(e===`Infinity`)return UG;if(e===`-Infinity`)return WG;let t=DIe.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return GG(MG(r,xG));if(i===`micro`||i===`micros`)return GG(MG(r,TG));switch(i){case`milli`:case`millis`:return PG(r,1);case`second`:case`seconds`:return PG(r,1e3);case`minute`:case`minutes`:return PG(r,6e4);case`hour`:case`hours`:return PG(r,36e5);case`day`:case`days`:return PG(r,864e5);case`week`:case`weeks`:return PG(r,6048e5)}break}case`object`:{if(e===null)break;if(yG in e)return e;if(Array.isArray(e)){if(e.length!==2||!e.every(dH))return RG(e);if(Number.isNaN(e[0])||Number.isNaN(e[1]))return HG;if(e[0]===-1/0||e[1]===-1/0)return WG;if(e[0]===1/0||e[1]===1/0)return UG;let t=e[0]*1e9+e[1];return Number.isFinite(t)&&Number.isInteger(e[0])&&Number.isInteger(e[1])?BG(BigInt(e[0])*DG+BigInt(e[1])):AG(t)}let t=e,n=0;if(t.weeks&&(n+=t.weeks*6048e5),t.days&&(n+=t.days*864e5),t.hours&&(n+=t.hours*36e5),t.minutes&&(n+=t.minutes*6e4),t.seconds&&(n+=t.seconds*1e3),t.milliseconds&&(n+=t.milliseconds),!t.microseconds&&!t.nanoseconds){if(!Number.isFinite(n))return BG(n);let e=LG(t);return e===void 0||BigInt(n)*EG===e?BG(n):BG(e)}let r=n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0),i=Number.isFinite(r)?LG(t):void 0;return i===void 0?AG(r):BG(i)}}return RG(e)},IG=e=>!e||Number.isInteger(e),LG=e=>{if(!IG(e.weeks)||!IG(e.days)||!IG(e.hours)||!IG(e.minutes)||!IG(e.seconds)||!IG(e.milliseconds)||!IG(e.microseconds)||!IG(e.nanoseconds))return;let t=bG;return e.weeks&&(t+=BigInt(e.weeks)*EIe),e.days&&(t+=BigInt(e.days)*TIe),e.hours&&(t+=BigInt(e.hours)*wIe),e.minutes&&(t+=BigInt(e.minutes)*CIe),e.seconds&&(t+=BigInt(e.seconds)*DG),e.milliseconds&&(t+=BigInt(e.milliseconds)*EG),e.microseconds&&(t+=BigInt(e.microseconds)*TG),e.nanoseconds&&(t+=BigInt(e.nanoseconds)),t},RG=e=>{throw Error(`Invalid Input: ${e}`)},OIe=tIe(FG),zG={_tag:`Millis`,millis:0},kIe={_tag:`Infinity`},AIe={_tag:`NegativeInfinity`},jIe={[yG]:yG,[xH](){switch(this.value._tag){case`Millis`:return SH(kG(this.value.millis));case`Nanos`:return SH(this.value.nanos);default:return AH(this.value)}},[LH](e){return MIe(e)&&UIe(this,e)},toString(){switch(this.value._tag){case`Infinity`:return`Infinity`;case`NegativeInfinity`:return`-Infinity`;case`Nanos`:return`${this.value.nanos} nanos`;case`Millis`:return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,nanos:String(this.value.nanos)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`};case`NegativeInfinity`:return{_id:`Duration`,_tag:`NegativeInfinity`}}},[nU](){return this.toJSON()},pipe(){return KV(this,arguments)}},BG=e=>{let t=Object.create(jIe);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?zG:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:kG(e)}:e>0?kIe:AIe:e===bG?zG:{_tag:`Nanos`,nanos:e},t},MIe=e=>yH(e,yG),VG=e=>e.value._tag!==`Infinity`&&e.value._tag!==`NegativeInfinity`,NIe=e=>{switch(e.value._tag){case`Millis`:return e.value.millis===0;case`Nanos`:return e.value.nanos===bG;case`Infinity`:case`NegativeInfinity`:return!1}},PIe=e=>{switch(e.value._tag){case`Millis`:return e.value.millis<0;case`Nanos`:return e.value.nanos<bG;case`NegativeInfinity`:return!0;case`Infinity`:return!1}},FIe=e=>{switch(e.value._tag){case`Infinity`:case`NegativeInfinity`:return UG;case`Millis`:return e.value.millis<0?BG(-e.value.millis):e;case`Nanos`:return e.value.nanos<bG?BG(-e.value.nanos):e}},HG=BG(0),UG=BG(1/0),WG=BG(-1/0),GG=e=>BG(e),KG=e=>BG(e),qG=e=>BG(e*1e3),JG=e=>BG(e*6e4),YG=e=>BG(e*36e5),IIe=e=>BG(e*864e5),XG=e=>QG(FG(e),{onMillis:YV,onNanos:e=>jG(e,1e6),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),LIe=e=>QG(FG(e),{onMillis:e=>e/1e3,onNanos:e=>jG(e,1e9),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),RIe=e=>QG(FG(e),{onMillis:e=>e/6e4,onNanos:e=>jG(e,6e10),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),zIe=e=>QG(FG(e),{onMillis:e=>e/36e5,onNanos:e=>jG(e,36e11),onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),ZG=e=>{let t=FG(e);switch(t.value._tag){case`Infinity`:case`NegativeInfinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return kG(t.value.millis)}},QG=W(2,(e,t)=>{switch(e.value._tag){case`Millis`:return t.onMillis(e.value.millis);case`Nanos`:return t.onNanos(e.value.nanos);case`Infinity`:return t.onInfinity();case`NegativeInfinity`:return(t.onNegativeInfinity??t.onInfinity)()}}),BIe=W(3,(e,t,n)=>e.value._tag===`Infinity`||e.value._tag===`NegativeInfinity`||t.value._tag===`Infinity`||t.value._tag===`NegativeInfinity`?n.onInfinity(e,t):e.value._tag===`Millis`?t.value._tag===`Millis`?n.onMillis(e.value.millis,t.value.millis):n.onNanos(ZG(e),t.value.nanos):n.onNanos(e.value.nanos,ZG(t))),VIe=(e,t)=>BIe(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),HIe=W(2,(e,t)=>QG(e,{onMillis:e=>BG(e*t),onNanos:e=>{if(Number.isInteger(t))return BG(e*BigInt(t));let n=Number(e),r=n*t;if(!Number.isFinite(t)||Number.isSafeInteger(n)&&Math.abs(r)<=2**53-1)return AG(r);let i=t,a=xG;for(;!Number.isInteger(i);)i*=2,a*=SG;return BG(NG(e*BigInt(i),a))},onInfinity:()=>t>0?UG:t<0?WG:HG,onNegativeInfinity:()=>t>0?WG:t<0?UG:HG})),UIe=W(2,(e,t)=>VIe(e,t)),WIe=e=>{if(e.value._tag===`Infinity`)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};if(e.value._tag===`NegativeInfinity`)return{days:-1/0,hours:-1/0,minutes:-1/0,seconds:-1/0,millis:-1/0,nanos:-1/0};let t=ZG(e),n=t<bG,r=n?-t:t,i=r/EG,a=i/TG,o=a/wG,s=o/wG,c=s/CG,l=n?-1:1;return{days:l*Number(c),hours:l*Number(s%CG),minutes:l*Number(o%wG),seconds:l*Number(a%wG),millis:l*Number(i%TG),nanos:l*Number(r%EG)}},$G=e=>{if(e.value._tag===`Infinity`)return`Infinity`;if(e.value._tag===`NegativeInfinity`)return`-Infinity`;if(NIe(e))return`0`;if(PIe(e))return`-`+$G(FIe(e));let t=WIe(e),n=[];return t.days!==0&&n.push(`${t.days}d`),t.hours!==0&&n.push(`${t.hours}h`),t.minutes!==0&&n.push(`${t.minutes}m`),t.seconds!==0&&n.push(`${t.seconds}s`),t.millis!==0&&n.push(`${t.millis}ms`),t.nanos!==0&&n.push(`${t.nanos}ns`),n.join(` `)},GIe=W(2,(e,t)=>n=>{let r=e(n);if(sG(r))return oG(n);let i=t(r.success);return sG(i)?oG(n):i}),eK=nG(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new rK}),tK=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},KIe=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},nK=e=>{try{return KIe(e)}catch{return tK(e)}};var qIe=class{buckets=[];scheduleTask(e,t){let n=this.buckets,r=n.length,i,a=0;for(;a<r&&!(n[a][0]>t);a++)i=n[a];i&&i[0]===t?i[1].push(e):a===r?n.push([t,[e]]):n.splice(a,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}},rK=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?tK:nK)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new JIe(this.setImmediate)}},JIe=class{tasks=new qIe;running=void 0;setImmediate;constructor(e=nK){this.setImmediate=e}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running===void 0&&(this.running=this.setImmediate(this.afterScheduled))}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let n=e[t][1];for(let e=0;e<n.length;e++)n[e]()}}flush(){for(;this.tasks.buckets.length>0;)this.running!==void 0&&(this.running(),this.running=void 0),this.runTasks()}};const YIe=nG(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),XIe=nG(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),ZIe=()=>new Proxy({},{get(e,t,n){return t===`$is`?bH:t===`$match`?QIe:e=>({...e,_tag:t})}});function QIe(){if(arguments.length===1){let e=arguments[0];return function(t){return e[t._tag](t)}}let e=arguments[0];return arguments[1][e._tag](e)}const $Ie=XU,iK=ZU,aK=`~effect/encoding/EncodingError`;var oK=class extends iK(`EncodingError`){[aK]=aK};const sK=e=>{switch(e){case 16:return tLe();case 32:return nLe();default:{let t=``;for(let n=e>>>3;n>0;n--)t+=eLe();return t}}},K=Uint8Array.from(`0123456789abcdef`,e=>e.charCodeAt(0)),cK=()=>Math.random()*4294967296>>>0,eLe=()=>{let e=cK();return String.fromCharCode(K[e>>>28],K[e>>>24&15],K[e>>>20&15],K[e>>>16&15],K[e>>>12&15],K[e>>>8&15],K[e>>>4&15],K[e&15])},tLe=()=>{let e=cK(),t=cK();return String.fromCharCode(K[e>>>28],K[e>>>24&15],K[e>>>20&15],K[e>>>16&15],K[e>>>12&15],K[e>>>8&15],K[e>>>4&15],K[e&15],K[t>>>28],K[t>>>24&15],K[t>>>20&15],K[t>>>16&15],K[t>>>12&15],K[t>>>8&15],K[t>>>4&15],K[t&15])},nLe=()=>{let e=cK(),t=cK(),n=cK(),r=cK();return String.fromCharCode(K[e>>>28],K[e>>>24&15],K[e>>>20&15],K[e>>>16&15],K[e>>>12&15],K[e>>>8&15],K[e>>>4&15],K[e&15],K[t>>>28],K[t>>>24&15],K[t>>>20&15],K[t>>>16&15],K[t>>>12&15],K[t>>>8&15],K[t>>>4&15],K[t&15],K[n>>>28],K[n>>>24&15],K[n>>>20&15],K[n>>>16&15],K[n>>>12&15],K[n>>>8&15],K[n>>>4&15],K[n&15],K[r>>>28],K[r>>>24&15],K[r>>>20&15],K[r>>>16&15],K[r>>>12&15],K[r>>>8&15],K[r>>>4&15],K[r&15])},lK=new Uint8Array(256).fill(255);for(let e=0;e<16;e++)lK[`0123456789abcdef`.charCodeAt(e)]=e,lK[`0123456789ABCDEF`.charCodeAt(e)]=e;const uK=`effect/Tracer/ParentSpan`;var rLe=class extends PW()(uK,{fiberCached:!0}){};const iLe=e=>e,dK=nG(`effect/Tracer/DisablePropagation`,{defaultValue:QV}),aLe=nG(`effect/Tracer/CurrentTraceLevel`,{defaultValue:()=>`Info`}),oLe=nG(`effect/Tracer/MinimumTraceLevel`,{defaultValue:()=>`All`}),sLe=iLe({span:e=>new cLe(e)});var cLe=class{_tag=`Span`;sampled;name;parent;annotations;links;startTime;kind;status;_traceId=void 0;_spanId=void 0;_attributes=void 0;_events=void 0;constructor(e){this.name=e.name,this.parent=e.parent,this.annotations=e.annotations,this.links=e.links,this.startTime=e.startTime,this.kind=e.kind,this.sampled=e.sampled,this.status={_tag:`Started`,startTime:e.startTime}}get traceId(){return this._traceId??=AW(this.parent)?.traceId??sK(32)}get spanId(){return this._spanId??=sK(16)}get attributes(){return this._attributes??=new Map}get events(){return this._events??=[]}end(e,t){this.status._tag!==`Ended`&&(this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime})}attribute(e,t){this.status._tag!==`Ended`&&this.attributes.set(e,t)}event(e,t,n){this.status._tag!==`Ended`&&this.events.push([e,t,n??{}])}addLinks(e){this.status._tag!==`Ended`&&this.links.push(...e)}};const fK=nG(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:$V}),lLe=nG(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:ZV}),pK=nG(`effect/References/TracerTimingEnabled`,{defaultValue:ZV}),uLe=nG(`effect/References/TracerSpanAnnotations`,{defaultValue:()=>({})}),dLe=nG(`effect/References/TracerSpanLinks`,{defaultValue:()=>[]}),mK=nG(`effect/References/CurrentLogAnnotations`,{defaultValue:()=>({})}),fLe=nG(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),hK=nG(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),pLe=nG(`effect/References/UnhandledLogLevel`,{defaultValue:()=>`Error`}),mLe=nG(`effect/References/CurrentLogSpans`,{defaultValue:()=>[]}),gK=e=>{if(e?.captureStackTrace===!1||e?.captureStackTrace!==void 0&&typeof e.captureStackTrace!=`boolean`)return e;let t=aU();if(t===0&&e?.captureStackTrace!==!0)return{...e,captureStackTrace:!1};oU(3);let n=Error();return oU(t),{...e,captureStackTrace:hLe(()=>n.stack)}},hLe=(e=>t=>{let n;return()=>{if(n!==void 0)return n;let r=t();if(!r)return;let i=r.split(`
586
+ `);if(i[e]!==void 0)return n=i[e].trim(),n}})(3);var gLe=class extends DU{constructor(e,t=OU){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[LH](e){return zU(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[xH](){return kH(`${this._tag}:${this.fiberId}`)}};const _K=e=>new TU([new gLe(e)]),_Le=e=>e.reasons.some(LU),vK=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return aG(n.error)}return oG(e)},yK=e=>e.reasons.some(RU),bK=e=>yK(e)&&_Le(e)?AU(e.reasons.map(e=>e._tag===`Fail`&&!$U(e.error)?new PU(e.error,e.annotations):e)):e,xK=e=>yK(e)?oG(bK(e)):vK(e),SK=e=>e.reasons.some(zU),vLe=e=>e.reasons.length>0&&e.reasons.every(zU),CK=W(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>LU(e)?(n=!0,new kU(t(e.error),e.annotations)):e);return n?AU(r):e}),yLe=e=>{let t;for(let n of e.reasons){if(n._tag===`Fail`)return n.error;n._tag===`Die`&&(t??=n)}return t===void 0?e.reasons.length>0?new globalThis.Error(`All fibers interrupted without error`):new globalThis.Error(`Empty cause`):t.defect},bLe=(e,t)=>{let n=[],r=[];if(e.reasons.length===0)return n;let i=aU();i!==0&&oU(1);try{for(let i of e.reasons){if(i._tag===`Interrupt`){r.push(i);continue}n.push(wK(i._tag===`Die`?i.defect:i.error,i.annotations,t))}if(n.length===0){let e=Error(`The fiber was interrupted by:`);e.name=`InterruptCause`,e.stack=wLe(e,r);let i=new globalThis.Error(`All fibers interrupted without error`,{cause:e});i.name=`InterruptError`,i.stack=`${i.name}: ${i.message}`,n.push(wK(i,r[0].annotations,t))}}finally{i!==0&&oU(i)}return n},wK=(e,t,n,r=new Set)=>{let i=typeof e,a;if(e&&i===`object`){r.add(e);let i=e.cause;if(a=new globalThis.Error(xLe(e),{cause:i!==void 0&&!r.has(i)?wK(i,void 0,void 0,r):void 0}),typeof e.name==`string`&&(a.name=e.name),typeof e.stack==`string`)a.stack=CLe(e.stack,a,t);else{let e=`${a.name}: ${a.message}`;a.stack=t?TK(e,t):e}n?.includeCauseInStack&&(a.stack=OK(a));for(let t of Object.keys(e))t in a||(a[t]=e[t])}else{a=new globalThis.Error(e?i===`string`?e:tU(e):`Unknown error: ${e}`);let n=`${a.name}: ${a.message}`;a.stack=t?TK(n,t):n}return a},xLe=e=>{if(typeof e.message==`string`)return e.message;if(typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString)try{return e.toString()}catch{}return tU(e)},SLe=/\((.*)\)/g,CLe=(e,t,n)=>{let r=`${t.name}: ${t.message}`,i=(e.startsWith(r)?e.slice(r.length):e).split(`
587
+ `),a=[r];for(let e=1;e<i.length&&!/Generator\.next|~effect\/(?:Effect|Utils)/.test(i[e]);e++)a.push(i[e]);return n?TK(a.join(`
588
+ `),n):a.join(`
589
+ `)},TK=(e,t)=>{let n=t?.get(WU.key);return n&&(e=`${e}\n${EK(n)}`),e},wLe=(e,t)=>{let n=[`${e.name}: ${e.message}`];for(let e of t){let t=e.fiberId===void 0?`unknown`:`#${e.fiberId}`,r=e.annotations.get(GU.key);n.push(` at fiber (${t})`),r&&n.push(EK(r))}return n.join(`
590
+ `)},EK=e=>{let t=[],n=e,r=0;for(;n&&r<10;){let e=n.stack();if(e){let r=e.matchAll(SLe),i=!1;for(let[,e]of r)i=!0,t.push(` at ${n.name} (${e})`);i||t.push(` at ${n.name} (${e.replace(/^at /,``)})`)}else t.push(` at ${n.name}`);n=n.parent,r++}return t.join(`
591
+ `)},DK=e=>bLe(e).map(OK).join(`
592
+ `),OK=e=>e.cause?`${e.stack} {\n${kK(e.cause,` `)}\n}`:e.stack,kK=(e,t)=>{let n=e.stack.split(`
593
+ `),r=`${t}[cause]: ${n[0]}`;for(let e=1,i=n.length;e<i;e++)r+=`\n${t}${n[e]}`;return e.cause&&(r+=` {\n${kK(e.cause,`${t} `)}\n${t}}`),r},AK=`~effect/Fiber`,TLe={_A:YV,_E:YV},ELe={id:0},jK=(()=>{try{return globalThis.process?.getBuiltinModule?.(`node:async_hooks`)?.AsyncResource}catch{return}})(),MK=()=>jK===void 0?void 0:new jK(`effect/Fiber`),NK=()=>globalThis[XH];var PK=class{constructor(e,t=!0){this.setContext(e),this.id=++ELe.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._autoYielded=!1,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[AK](){return TLe}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return QW(this.context,e)}addObserver(e){return this._exit?(e(this._exit),eH):(this._observers===void 0?this._observers=[e]:this._observers.push(e),()=>this.removeObserver(e))}removeObserver(e){if(this._exit||this._observers===void 0)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let n=_K(e);this.cache.stackFrame&&(n=IU(n,qW(WU,this.cache.stackFrame))),t&&(n=IU(n,t)),this._interruptedCause=this._interruptedCause?MU(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(UK(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._asyncContext!==void 0){let t=this._asyncContext;this._asyncContext=void 0;try{return t.runInAsyncScope(this.evaluate,this,e)}finally{t.emitDestroy()}}else if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===vU){this._asyncContext=MK();return}let n=FK.interruptChildren&&FK.interruptChildren(this);if(n!==void 0)return this.evaluate(gq(n,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&=(this._parent._children?.delete(this),void 0),this._observers!==void 0){let e=this._observers;this._observers=void 0;for(let n=0;n<e.length;n++)e[n](t)}this._stack.length=0,this._children=void 0,this.context=KW();let r=this.cache;(r.span!==void 0||r.stackFrame!==void 0)&&(this.cache={...r,span:void 0,stackFrame:void 0})}runLoop(e){let t=globalThis[XH];globalThis[XH]=this;let n=this._running;this._running=!0;let r=!1,i=this._autoYielded;this._autoYielded=!1;let a=e;this.currentOpCount=+!!i;try{for(;;)try{this._deferredInterrupt&&(this._deferredInterrupt=!1,a=UK(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!i&&!r&&!e.preventYield&&e.scheduler.shouldYield(this)?(r=!0,a=this.yieldNow(a,0,!0)):(i=!1,a=e.tracerContext?e.tracerContext(a,this):a[mU](this)),a===vU){let e=this._yielded;if(dU in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return vU}}catch(e){if(!yH(a,mU))return JU(`Fiber.runLoop: Not a valid effect: ${String(a)}`);a=JU(e)}}finally{this._running=n,globalThis[XH]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,OLe;for(;;){let t=this._stack.pop();if(!t)return;let n=t[_U];if(n!==void 0){let r=n.call(t,this);if(r)return r[e]=r,r}if(t[e])return t}}succeedWith(e){if(!(++this.currentOpCount&kLe-1))return UU(e);let t=this.getCont(hU);return t?t[hU](e,this):this.yieldWith(UU(e))}yieldWith(e){return this._yielded=e,vU}yieldNow(e,t=0,n=!1){let r=!1;return this.currentDispatcher.scheduleTask(()=>{r||(this._autoYielded=n,this.evaluate(e))},t),this.yieldWith(()=>{r=!0})}children(){return this._children??=new Set}pipe(){return KV(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&oIe(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=DLe(e);this.cache?.scheduler!==r.scheduler&&(this._dispatcher=void 0),this.cache=r}get currentSpanLocal(){let e=this.cache.span;return e?._tag===`Span`?e:void 0}};const DLe=e=>{let t=XW(e,`effect/Tracer`);return{scheduler:QW(e,eK),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:QW(e,lLe),span:XW(e,uK),logLevel:QW(e,fLe),minimumLogLevel:QW(e,hK),stackFrame:QW(e,fK),runtimeMetrics:XW(e,`effect/Metric/FiberRuntimeMetrics`),maxOpsBeforeYield:QW(e,YIe),preventYield:QW(e,XIe)}},OLe={[hU](e,t){return UK(t._interruptedCause)},[gU](e,t){return UK(t._interruptedCause)}},kLe=32,FK={interruptChildren:void 0},IK=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(GU.key,e.cache.stackFrame),UW(t)},ALe=e=>{if(e._children!==void 0&&e._children.size!==0)return VK(e._children)},LK=e=>{let t=e;return t._exit?HK(t._exit):ZK(n=>t._exit?n(HK(t._exit)):GK(e.addObserver(e=>n(HK(e)))))},RK=e=>ZK(t=>{let n=e[Symbol.iterator](),r=[],i;function a(){let e=n.next();for(;!e.done;){if(e.value._exit){r.push(e.value._exit),e=n.next();continue}i=e.value.addObserver(e=>{r.push(e),a()});return}t(HK(r))}return a(),GK(()=>i?.())}),zK=e=>{let t=e;return t._exit?t._exit:ZK(n=>t._exit?n(t._exit):GK(e.addObserver(n)))},BK=e=>YU(t=>jLe(e,t.id)),jLe=W(e=>yH(e[0],AK),(e,t,n)=>YU(r=>{let i=IK(r);return i=i&&n?tG(i,n):i??n,e.interruptUnsafe(t,i),mq(LK(e))})),VK=e=>YU(t=>{let n=IK(t),r=hG();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return mq(RK(r))}),HK=UU,UK=KU,WK=qU,GK=VU({op:`Sync`,[mU](e){let t=this[pU],n=t(),r=e.getCont(hU);return r?r[hU](n,e):e.yieldWith(UU(n))}}),KK=VU({op:`Suspend`,[mU](e){let t=this[pU];return t()}}),MLe=hIe({onFailure:WK,onSuccess:HK}),qK=VU({op:`Yield`,[mU](e){return e.yieldNow(xq,this[pU]??0)}})(0),NLe=HK(G()),PLe=e=>KK(()=>UK(e())),JK=e=>JU(e),FLe=e=>KK(()=>WK(e())),YK=HK(void 0),ILe=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new VJ(e,`An error occurred in Effect.try`):e.catch;return KK(()=>{try{return HK(t())}catch(e){return WK(n(e))}})},LLe=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new VJ(e,`An error occurred in Effect.tryPromise`):e.catch;return XK(function(e,r){let i=e=>KK(()=>{try{return WK(cU(()=>n(e)))}catch(e){return JK(e)}});try{t(r).then(t=>e(HK(t)),t=>e(i(t)))}catch(t){e(i(t))}},t.length!==0)},XK=function(){let e=BU({op:`Async`,[mU](e){let t=!1,n=!1,r=this.withSignal?new AbortController:void 0,i=this.register.call(e.cache.scheduler,r=>{t||(t=!0,n?e.evaluate(r):n=r)},r?.signal);return n===!1?(n=!0,e.yieldWith(()=>{t=!0}),r===void 0&&i===void 0||e._stack.push(RLe(()=>(t=!0,r?.abort(),i??xq))),vU):n}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),RLe=VU({op:`AsyncFinalizer`,[_U](e){e.interruptible&&(e.interruptible=!1,e._stack.push(dJ))},[gU](e,t){return SK(e)?gq(Jq(KU(e),this[pU]()),()=>UK(e)):UK(e)}}),ZK=e=>XK(e,e.length>=2),QK=ZK(eH),zLe=(...e)=>{if(e.length===1){let t=e[0];return KK(()=>rq(t()))}let[t,n]=e;return KK(()=>rq(n.call(t.self)))},$K=(e,t)=>typeof e==`function`?e:t.shift().bind(e.self),eq=(e,...t)=>{let n=$K(e,t),r=t.length===0?function(){return KK(()=>rq(n.apply(this,arguments)))}:function(){let e=KK(()=>rq(n.apply(this,arguments)));for(let n=0;n<t.length;n++)e=t[n](e,...arguments);return e};return tq(n.length,r)},tq=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),BLe=(e,...t)=>{let n=$K(e,t);return tq(n.length,t.length===0?function(){return nq(()=>n.apply(this,arguments))}:function(){let e=nq(()=>n.apply(this,arguments));for(let n of t)e=n(e,...arguments);return e})},nq=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return HK(r.value);let i=r.value;if(i&&i._tag===`Success`){n=i.value;continue}if(i&&i._tag===`Failure`)return r.value;{let n=!0;return KK(()=>n?(n=!1,gq(r.value,e=>rq(t,e))):KK(()=>rq(e())))}}}catch(e){return JK(e)}},rq=function(){let e=BU({op:`Iterator`,[hU](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return HK(r.value);if(!_q(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[mU](e){return this[hU](this.initial,e)}}),t=function(e,t){this.iterator=e,this.initial=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),iq=W(2,(e,t)=>new oq(e,sq,HK(t))),aq=function(e){return e._stack.push(this),this[pU]},VLe=BU({op:`OnSuccess`,[mU]:aq}),oq=function(e,t,n){this[pU]=e,this[hU]=t,this.payload=n};oq.prototype=VLe;const sq=function(){return this.payload},cq=function(e,t){return t.succeedWith(this.payload)},lq=(()=>{let e=aU();if(e===0)return!1;let t=`~effect/Effect/stackProbe`,n={[t]:function(){return Error()}};oU(1);let r=n[t]();return oU(e),r.stack?.includes(`[as `+t+`]`)===!0})(),HLe=function(e,t){let n=this.payload;return t.succeedWith(lq?n(e):cU(()=>n(e)))},uq=function(e){let t=this.payload;return t(e)},ULe=function(e){let t=this.payload;return new oq(t(e),cq,e)},WLe=function(e){return new oq(this.payload,cq,e)},dq=e=>vq(e,CW),fq=W(2,(e,t)=>new oq(e,bU(t)?sq:uq,t)),pq=W(2,(e,t)=>new oq(e,bU(t)?WLe:ULe,t)),mq=e=>new oq(e,sq,xq),GLe=(e,t)=>YU(n=>{let r=new Set;return sJ(n,()=>r.size===0?void 0:VK(r)),ZK(i=>{let a=!1,o=0;for(let s of e){if(a)break;let e=o++,c=bJ(n,s,!0,!0,!1);r.add(c),c.addObserver(o=>{r.delete(c);let s=!a;a=!0,i(o),s&&(KLe(r,n),t?.onWinner?.({fiber:c,index:e,parentFiber:n}))})}})}),KLe=(e,t)=>{let n=IK(t);for(let r of e)r.interruptUnsafe(t.id,n)},hq=W(e=>bU(e[1]),(e,t,n)=>GLe([e,t],n)),gq=W(2,(e,t)=>new oq(e,uq,t)),_q=e=>e[dU]!==void 0,qLe=W(2,(e,t)=>_q(e)?e._tag===`Success`?t(e.value):e:gq(e,t)),JLe=e=>gq(e,YV),vq=W(2,(e,t)=>new oq(e,HLe,t)),YLe=W(2,(e,t)=>_q(e)?tRe(e,t):vq(e,t)),XLe=W(2,(e,t)=>_q(e)?nRe(e,t):Nq(e,t)),ZLe=e=>KU(_K(e)),yq=e=>e._tag===`Success`,QLe=e=>e._tag===`Failure`,bq=e=>e._tag===`Failure`?aG(e.cause):oG(e),$Le=GIe(bq,vK),eRe=e=>e._tag===`Failure`&&SK(e.cause),xq=UU(void 0),tRe=W(2,(e,t)=>e._tag===`Success`?UU(t(e.value)):e),nRe=W(2,(e,t)=>e._tag===`Success`?e:KU(CK(e.cause,t))),rRe=W(2,(e,t)=>yq(e)?t:e),iRe=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?xq:KU(AU(t))},aRe=e=>{let t=$Le(e);return sG(t)?G():CW(t.success)},oRe=e=>YU(t=>HK(uIe(t.context,e))),Sq=W(2,(e,t)=>YU(n=>{let r=n.context,i=t(r);return r===i?e:(n.setContext(i),sJ(n,()=>{n.setContext(r)}),e)})),sRe=W(3,(e,t,n)=>Sq(e,e=>{let r=ZW(e,t),i=n(r);return r===i?e:JW(e,t,i)})),cRe=()=>lRe,lRe=YU(e=>HK(e.context)),Cq=e=>YU(t=>e(t.context)),wq=W(2,(e,t)=>_q(e)?e:Sq(e,tG(t))),Tq=function(){return arguments.length===1?W(2,(e,t)=>Eq(e,arguments[0],t)):W(3,(e,t,n)=>Eq(e,t,n)).apply(this,arguments)},Eq=(e,t,n)=>Sq(e,JW(t,n)),uRe=W(e=>bU(e[1]),(e,t,n,r)=>r?.concurrent?vq(pJ([e,t],{concurrency:2}),([e,t])=>n(e,t)):gq(e,e=>vq(t,t=>n(e,t)))),dRe=W(e=>bU(e[0]),(e,t)=>mJ({while:ZV,body:XV(t?.disableYield?e:gq(e,e=>qK)),step:eH})),Dq=W(2,(e,t)=>new Oq(e,t.length===1?t:e=>t(e))),fRe=BU({op:`OnFailure`,[mU]:aq}),Oq=function(e,t){this[pU]=e,this[gU]=t};Oq.prototype=fRe;const kq=W(3,(e,t,n)=>Dq(e,e=>{let r=t(e);return sG(r)?UK(r.failure):n(r.success,e)})),Aq=W(2,(e,t)=>kq(e,xK,e=>t(e))),pRe=W(3,(e,t,n)=>Dq(e,e=>{let r=t(e);return sG(r)?UK(e):fq(n(r.success,e),UK(e))})),mRe=W(2,(e,t)=>pRe(e,vK,e=>t(e))),jq=W(e=>bU(e[0]),(e,t,n,r)=>Dq(e,e=>{let i=xK(e);return sG(i)?UK(i.failure):t(i.success)?n(i.success):r?r(i.success):UK(e)})),Mq=W(e=>bU(e[0]),(e,t,n,r)=>Dq(e,e=>{let i=xK(e);if(sG(i))return UK(i.failure);let a=t(i.success);return sG(a)?r?r(a.failure):UK(e):n(a.success)})),hRe=W(e=>bU(e[0]),(e,t,n,r)=>{let i=Array.isArray(t)?e=>yH(e,`_tag`)&&t.includes(e._tag):bH(t);return jq(e,i,n,r)}),gRe=W(e=>bU(e[0]),(e,t,n)=>{let r;return Mq(e,e=>(r??=Object.keys(t),yH(e,`_tag`)&&uH(e._tag)&&r.includes(e._tag)?aG(e):oG(e)),e=>t[e._tag](e),n)}),_Re=W(e=>bU(e[0]),(e,t,n,r,i)=>jq(e,e=>bH(e,t)&&yH(e,`reason`)&&(i!==void 0||bH(e.reason,n)),e=>{let t=e.reason;return bH(t,n)?r(t,e):i?i(t,e):WK(e)})),Nq=W(2,(e,t)=>Dq(e,e=>UK(CK(e,t)))),vRe=e=>Aq(e,JK),Pq=e=>e===`Unhandled`?(...e)=>YU(t=>{let n=t.getRef(pLe);return n===void 0?YK:GJ(n)(...e)}):GJ(e===!0?void 0:e),yRe=W(e=>bU(e[0]),(e,t)=>{if(!t?.log)return Rq(e,{onFailure:e=>YK,onSuccess:e=>YK});let n=Pq(t.log);return Iq(e,{onFailure(e){let r=xK(e);return sG(r)?UK(r.failure):t.message===void 0?n(e):n(t.message,e)},onSuccess:e=>YK})}),bRe=W(e=>bU(e[0]),(e,t)=>{if(!t?.log)return Iq(e,{onFailure:e=>YK,onSuccess:e=>YK});let n=Pq(t.log);return Iq(e,{onFailure:e=>t.message===void 0?n(e):n(t.message,e),onSuccess:e=>YK})}),Fq=e=>wRe(e,{onFailure:oG,onSuccess:aG}),Iq=W(2,(e,t)=>new Lq(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),xRe=BU({op:`OnSuccessAndFailure`,[mU]:aq}),Lq=function(e,t,n){this[pU]=e,this[hU]=t,this[gU]=n};Lq.prototype=xRe;const SRe=function(e,t){let n=this.payload;return t.succeedWith(lq?n.onSuccess(e):cU(()=>n.onSuccess(e)))},CRe=((e,t)=>{let n=BU({op:e,[mU]:aq,[hU]:SRe,[gU]:t}),r=function(e,t){this[pU]=e,this.payload=t};return r.prototype=n,r})(`Match`,function(e,t){let n=xK(e);if(sG(n))return UK(n.failure);let r=this.payload;return t.succeedWith(lq?r.onFailure(n.success):cU(()=>r.onFailure(n.success)))}),Rq=W(2,(e,t)=>Iq(e,{onFailure:e=>{let n=xK(e);return sG(n)?UK(n.failure):t.onFailure(n.success)},onSuccess:t.onSuccess})),zq=W(2,(e,t)=>new CRe(e,t)),wRe=W(2,(e,t)=>{if(_q(e)){if(e._tag===`Success`)return UU(t.onSuccess(e.value));let n=xK(e.cause);return sG(n)?KU(n.failure):UU(t.onFailure(n.success))}return zq(e,t)}),Bq=e=>_q(e)?UU(e):TRe(e),TRe=VU({op:`Exit`,[mU](e){return e._stack.push(this),this[pU]},[hU](e,t,n){return t.succeedWith(n??UU(e))},[gU](e,t,n){return t.succeedWith(n??KU(e))}}),Vq=W(2,(e,t)=>gq(ORe(e,t.duration),e=>wW(e)?t.orElse():HK(e.value))),ERe=e=>new pze(`Operation timed out after '${$G(e)}'`),DRe=W(2,(e,t)=>{let n=FG(t);return Vq(e,{duration:n,orElse:()=>WK(ERe(n))})}),ORe=W(2,(e,t)=>hq(dq(e),iq(IJ(t),G()))),Hq=`~effect/Scope`,Uq=`~effect/Scope/Closeable`,Wq=PW(`effect/Scope`),Gq=(e,t)=>YU(n=>(GRe(n),Kq(e,t)??YK)),Kq=(e,t)=>{let n=e.state;if(n._tag===`Closed`||(e.state={_tag:`Closed`,exit:t},e.parent!==void 0&&$q(e.parent,e),n._tag===`Empty`))return;if(n.finalizer!==void 0)return qq(n.finalizer,t);let r=n.finalizers;return r.size===1?qq(r.values().next().value,t):kRe(e,r,t)},qq=(e,t)=>{try{return e(t)}catch(e){return JU(e)}},Jq=(e,t)=>yq(e)?t:Dq(t,t=>UK(bK(jU(e.cause,t)))),kRe=eq(function*(e,t,n){let r=[],i=[],a=Array.from(t),o=NK();for(let t=a.length-1;t>=0;t--){let[s,c]=a[t];e.strategy===`sequential`?r.push(yield*Bq(qq(c,n))):s!==o&&i.push(bJ(o,qq(c,n),!0,!0,`inherit`))}return i.length>0&&(r=yield*RK(i)),yield*iRe(r)}),ARe=(e,t)=>GK(()=>Yq(e,t)),Yq=(e,t)=>{let n=tJ(t,e);return e.state._tag===`Closed`?(n.state=e.state,n):(Qq(e,n,e=>Gq(n,e)),n)},Xq=(e,t)=>KK(()=>e.state._tag===`Closed`?t(e.state.exit):(Qq(e,{},t),YK)),Zq=(e,t)=>Xq(e,XV(t)),Qq=(e,t,n)=>{if(e.state._tag===`Empty`)e.state={_tag:`Open`,finalizerKey:t,finalizer:n,finalizers:void 0};else if(e.state._tag===`Open`){let r=e.state;r.finalizer===void 0?r.finalizers.set(t,n):(r.finalizers=new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0,r.finalizers.set(t,n))}},$q=(e,t)=>{if(e.state._tag!==`Open`)return;let n=e.state;n.finalizerKey===t?e.state=nJ:n.finalizers!==void 0&&(n.finalizers.delete(t),n.finalizers.size===0&&(e.state=nJ))},eJ=e=>tJ(e,void 0),tJ=(e=`sequential`,t)=>({[Uq]:Uq,[Hq]:Hq,strategy:e,parent:t,state:nJ}),nJ={_tag:`Empty`},rJ=Wq,jRe=Tq(Wq),MRe=e=>YU(t=>{let n=t.context,r=eJ();return t.setContext(JW(t.context,Wq,r)),sJ(t,e=>(t.setContext(n),Kq(r,e))),e}),iJ=e=>KK(()=>{let t=eJ();return cJ(e(t),e=>KK(()=>Kq(t,e)??YK))}),NRe=(e,t,n)=>Cq(r=>fJ(i=>gq(rJ,a=>pq(n?.interruptible?i(e):e,e=>Xq(a,n=>wq(t(e,n),r)))))),PRe=e=>gq(rJ,t=>Cq(n=>Xq(t,t=>wq(e(t),n)))),aJ=function(){let e=BU({op:`OnExit`,[mU](e){return e._stack.push(this),this.effect},[_U](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(dJ),e.interruptible=!1)},[hU](e,t,n){n??=UU(e);let r;try{r=this.onExit(n)}catch(e){r=JU(e)}return r?gq(r,e=>n):n},[gU](e,t,n){n??=KU(e);let r;try{r=this.onExit(n)}catch(e){r=JU(e)}return r?gq(Jq(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,t}(),oJ=(e,t,n)=>new aJ(e,t,n),sJ=(e,t)=>{e._stack.push(new aJ(void 0,t,void 0))},cJ=W(2,oJ),FRe=W(2,(e,t)=>cJ(e,e=>t)),IRe=W(3,(e,t,n)=>cJ(e,e=>{let r=t(e);return sG(r)?YK:n(r.success,e)})),LRe=W(2,(e,t)=>IRe(e,bq,t)),RRe=(e,t,n)=>fJ(r=>gq(e,e=>oJ(KK(()=>r(t(e))),t=>n(e,t),!0))),zRe=XV(1/0),BRe=(e,t)=>{let n=0,r,i,a=(e,t)=>(t.awaiters++,sJ(e,()=>{if(!(--t.awaiters>0||t.done))return i===t&&(i=void 0),BK(t.fiber)}),zK(t.fiber));return[YU(o=>{if(i!==void 0)return o===i.fiber?zK(i.fiber):a(o,i);if(r!==void 0&&(n===1/0||o.getRef(jJ).currentTimeMillisUnsafe()<n))return r;r=void 0;let s=o.getRef(jJ),c={fiber:new PK(o.context),awaiters:0,done:!1};i=c;let l=a(o,c);return c.fiber.evaluate(oJ(e,e=>{if(c.done=!0,i!==c||(i=void 0,eRe(e)))return;let a=t(e);n=a===1/0?1/0:s.currentTimeMillisUnsafe()+a,r=e})),c.fiber._exit??l}),GK(()=>{i=void 0,r=void 0})]},VRe=e=>GK(()=>BRe(e,zRe)[0]),HRe=YU(e=>UK(_K(e.id))),lJ=e=>YU(t=>t.interruptible?(t.interruptible=!1,t._stack.push(dJ),e):e),uJ=VU({op:`SetInterruptible`,[_U](e){if(e.interruptible=this[pU],e._interruptedCause&&e.interruptible)return()=>UK(e._interruptedCause)}}),dJ=uJ(!0),URe=uJ(!1),WRe=e=>{if(e.interruptible=!0,e._stack.push(URe),e._interruptedCause)return UK(e._interruptedCause)},GRe=e=>{let t=e;t.interruptible&&(t.interruptible=!1,t._stack.push(dJ))},KRe=e=>YU(t=>t.interruptible?e:WRe(t)??e),fJ=e=>YU(t=>t.interruptible?(t.interruptible=!1,t._stack.push(dJ),e(KRe)):e(YV)),pJ=(e,t)=>cFe(e)?t?.mode===`result`?hJ(e,Fq,t):hJ(e,YV,t):t?.discard?t.mode===`result`?hJ(Object.values(e),Fq,t):hJ(Object.values(e),YV,t):KK(()=>vq(hJ(Object.entries(e),([e,n])=>vq(t?.mode===`result`?Fq(n):n,t=>[e,t]),{concurrency:t?.concurrency}),Object.fromEntries)),mJ=VU({op:`While`,[hU](e,t){return this[pU].step(e),this[pU].while()?(t._stack.push(this),this[pU].body()):xq},[mU](e){return this[pU].while()?(e._stack.push(this),this[pU].body()):xq}}),hJ=W(e=>typeof e[1]==`function`,(e,t,n)=>KK(()=>{let r=gJ(n?.concurrency);if(r===1)return qRe(e,t,n);let i=uG(e),a=i.length;if(a===0)return n?.discard?YK:HK([]);let o=n?.discard?void 0:Array(a),s=JRe({f:t,out:o},i,{concurrency:r});return s?iq(s,o):HK(o)})),qRe=(e,t,n)=>KK(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return iq(mJ({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),gJ=e=>e===`unbounded`?1/0:Math.max(1,e??1),_J=()=>e=>{let t=e.onItem,n=e.step,r=(e,t,r,a,o)=>gq(Bq(o),o=>n(e,t[r],o,r)??i(e,t,r+1,a)??YK),i=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!_q(c))return r(e,i,a,o,c);let l=n(e,s,c,a);if(l)return l._tag===`Failure`?l:void 0}};return i},vJ=e=>{let t=e.onItem,n=e.step;return(e,r,i)=>{let a=0,o=i.end??r.length,s=i.concurrency,c=!1,l,u,d,f,p,m=e=>{let t=JU(e);return f=t,c=!0,u&&u.size>0?gq(lJ(VK(Array.from(u))),()=>f??t):t},h=()=>{let i=!1;for(;!f&&a<o;a++){let o=r[a],g=p??t(e,o,a);if(_q(g)){if(f=n(e,o,g,a),f)break}else if(l){p=void 0;let t=bJ(l,g,!0,!0,`inherit`);if(t._exit){if(f=n(e,o,t._exit,a),f)break;continue}u.add(t);let r=a;if(t.addObserver(a=>{u.delete(t);try{if(f){if(a._tag===`Failure`){let e=a.cause.reasons.filter(e=>e._tag!==`Interrupt`);if(e.length>0){let t=AU(e);f=KU(f._tag===`Failure`?bK(jU(f.cause,t)):t)}}}else{let t=n(e,o,a,r);t&&(f=t,h())}if(i){let e=h();e&&d(e)}else c&&u.size===0&&d(f??YK)}catch(e){d(m(e))}}),u.size<s)continue;i=!0,a++;return}else return ZK(e=>{l=NK(),u=new Set,p=g,d=e;let t;try{t=h()}catch(t){return e(m(t))}return t?e(t):KK(()=>(f??=xq,gq(u?VK(u):YK,()=>f?._tag===`Failure`?f:YK)))})}if(c=!0,f){if(u&&u.size>0){let e=IK(l);u.forEach(t=>t.interruptUnsafe(l.id,e));return}if(d||f._tag===`Failure`)return f}else if(d){if(u)u.size===0&&d(YK);else return xq}};return h()}},yJ=()=>e=>vJ(e),JRe=vJ({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag===`Failure`)return n;e.out&&(e.out[r]=n.value)}}),YRe=W(e=>bU(e[0]),(e,t)=>YU(n=>(wze(),HK(bJ(n,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),bJ=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new PK(a.context,o);return r||(a.children().add(s),s._parent=a),n?s.evaluate(t):(s._asyncContext=MK(),a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),s},xJ=e=>()=>YU(t=>t===e?YK:BK(e)),SJ=W(e=>bU(e[0]),(e,t,n)=>YU(r=>{let i=t.state._tag===`Closed`?new PK(r.context):bJ(r,e,n?.startImmediately,!0,n?.uninterruptible);return i._exit||(t.state._tag===`Closed`?i.interruptUnsafe(r.id,IK(r)):(Qq(t,i,xJ(i)),i.addObserver(()=>$q(t,i)))),HK(i)})),XRe=W(e=>bU(e[0]),(e,t)=>gq(rJ,n=>SJ(e,n,t))),CJ=e=>(t,n)=>{let r=new PK(n?.scheduler?JW(e,eK,n.scheduler):e,n?.uninterruptible!==!0);if(r.evaluate(t),r._exit)return r;if(n?.signal){if(n.signal.aborted)r.interruptUnsafe();else{let e=()=>r.interruptUnsafe();n.signal.addEventListener(`abort`,e,{once:!0}),r.addObserver(()=>n.signal.removeEventListener(`abort`,e))}}return n?.onFiberStart&&n.onFiberStart(r),r},ZRe=W(2,(e,t)=>e._exit?e:t.state._tag===`Closed`?(e.interruptUnsafe(e.id),e):($q(t,e),Qq(t,e,xJ(e)),e.addObserver(()=>$q(t,e)),e)),QRe=CJ(KW()),$Re=(e=>{let t=CJ(e);return(e,n)=>{let r=t(e,n);return new Promise(e=>{r.addObserver(t=>e(t))})}})(KW()),eze=(e=>{let t=CJ(e);return e=>{if(_q(e))return e;let n=new rK(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??JU(new hze(r))}})(KW()),wJ=HK(!0),TJ=HK(!1);var tze=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return wJ;if(this.scheduled===void 0)this.scheduled=this.waiters,e.currentDispatcher.scheduleTask(this.flushScheduled,0);else for(let e=0;e<this.waiters.length;e++)this.scheduled.push(this.waiters[e]);return this.waiters=[],wJ}flushScheduled=()=>{if(this.scheduled===void 0)return;let e=this.scheduled;this.scheduled=void 0;for(let t=0;t<e.length;t++)e[t](xq)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](xq)}open=YU(e=>this._isOpen?TJ:(this._isOpen=!0,this.scheduleUnsafe(e)));release=YU(e=>this._isOpen?TJ:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=ZK(e=>this._isOpen?e(YK):(this.waiters.push(e),GK(()=>{let t=this.waiters.indexOf(e);t===-1?this.scheduled!==void 0&&(t=this.scheduled.indexOf(e),t!==-1&&this.scheduled.splice(t,1)):this.waiters.splice(t,1)})));closeUnsafe(){return this._isOpen?(this._isOpen=!1,!0):!1}close=GK(()=>this.closeUnsafe());whenOpen=e=>gq(this.await,()=>e);isOpen(){return this._isOpen}};const nze=e=>new tze(e??!1),EJ=BigInt(0),rze={_tag:`Span`,spanId:`noop`,traceId:`noop`,sampled:!1,status:{_tag:`Ended`,startTime:EJ,endTime:EJ,exit:xq},attributes:new Map,links:[],kind:`internal`,attribute(){},event(){},end(){},addLinks(){}},ize=e=>Object.assign(Object.create(rze),e),DJ=e=>e?QW(e.annotations,dK)?e._tag===`Span`?DJ(AW(e.parent)):G():CW(e):G(),aze=(e,t,n)=>{let r=!e.cache.tracerEnabled||n?.annotations&&QW(n.annotations,dK),i=n?.parent===void 0?n?.root?G():DJ(e.cache.span):CW(n.parent),a;if(r)a=ize({name:t,parent:i,annotations:JW(n?.annotations??KW(),dK,!0)});else{let r=e.cache.tracer??sLe,o=e.getRef(jJ),s=e.getRef(pK),c=e.getRef(uLe),l=e.getRef(dLe),u=n?.level??e.getRef(aLe),d=n?.links===void 0?l.length===0?[]:l.slice():[...l,...n.links];a=r.span({name:t,parent:i,annotations:n?.annotations??KW(),links:d,startTime:s?o.currentTimeNanosUnsafe():EJ,kind:n?.kind??`internal`,root:n?.root??!1,sampled:n?.sampled??(TW(i)&&i.value.sampled===!1?!1:!UJ(e.getRef(oLe),u))});for(let e in c)a.attribute(e,c[e]);if(n?.attributes!==void 0)for(let e in n.attributes)a.attribute(e,n.attributes[e])}return a},oze=(e,t)=>(t=typeof t==`function`?t:$V,sRe(fK,n=>({name:e,stack:t,parent:n}))),sze=(e,t,n,r)=>GK(()=>{e.status._tag!==`Ended`&&e.end(r?n.currentTimeNanosUnsafe():EJ,t)}),OJ=(e,...t)=>{let n=t.length===1?void 0:t[0],r=t[t.length-1];return YU(t=>{let i=aze(t,e,n),a=t.getRef(jJ),o=t.getRef(pK);return sJ(t,e=>sze(i,e,a,o)),r(i)})},kJ=Tq(rLe),AJ=function(){let e=bU(arguments[0]),t=e?arguments[1]:arguments[0],n=e?arguments[2]:arguments[1],r=YV;return t._tag===`Span`&&(n=gK(n),r=oze(t.name,n?.captureStackTrace)),e?kJ(r(arguments[0]),t):e=>kJ(r(e),t)},cze=function(){let e=typeof arguments[0]!=`string`,t=e?arguments[1]:arguments[0],n=gK(arguments[2]);if(e){let e=arguments[0];return OJ(t,arguments[2],t=>AJ(e,t,n))}let r=typeof arguments[1]==`function`?arguments[1]:void 0,i=r?void 0:arguments[1];return(e,...a)=>OJ(t,r?r(...a):i,t=>AJ(e,t,n))},jJ=nG(`effect/Clock`,{defaultValue:()=>new lze}),MJ=2**31-1;var lze=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=GK(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return uze()}currentTimeNanos=GK(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return PJ()}monotonicTimeNanos=GK(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(XG(e))}sleepMillis(e){return e<=0?qK:Number.isFinite(e)?ZK(t=>{let n=e>MJ?this.sleepMillis(e-MJ):YK,r=setTimeout(()=>t(n),Math.min(e,MJ));return GK(()=>clearTimeout(r))}):QK}};const NJ=BigInt(1e6),PJ=function(){let e=globalThis.process?.hrtime;if(typeof e?.bigint==`function`)return()=>e.bigint();if(typeof performance<`u`&&typeof performance.now==`function`)return()=>BigInt(Math.round(performance.now()*1e6));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*NJ;return e>t&&(t=e),t}}(),uze=function(){let e=BigInt(1e9),t;return()=>{let n=PJ(),r=BigInt(Date.now())*NJ;if(t===void 0)t=r-n;else{let i=t+n;(r>i?r-i:i-r)>e&&(t=r-n)}return t+n}}(),FJ=e=>YU(t=>e(t.getRef(jJ))),IJ=e=>FJ(t=>t.sleep(FG(e))),dze=FJ(e=>e.currentTimeMillis),fze=FJ(e=>e.monotonicTimeNanos),LJ=`~effect/Cause/TimeoutError`;var pze=class extends ZU(`TimeoutError`){[LJ]=LJ;constructor(e){super({message:e})}};const RJ=`~effect/Cause/IllegalArgumentError`;var mze=class extends ZU(`IllegalArgumentError`){[RJ]=RJ;constructor(e){super({message:e})}};const zJ=`~effect/Cause/AsyncFiberError`;var hze=class extends ZU(`AsyncFiberError`){[zJ]=zJ;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}};const BJ=`~effect/Cause/UnknownError`;var VJ=class extends ZU(`UnknownError`){[BJ]=BJ;constructor(e,t){super({message:t,cause:e})}};const HJ=nG(`effect/Console`,{defaultValue:()=>globalThis.console}),UJ=SW(bW(yW,e=>{switch(e){case`All`:return-(2**53-1);case`Fatal`:return 5e4;case`Error`:return 4e4;case`Warn`:return 3e4;case`Info`:return 2e4;case`Debug`:return 1e4;case`Trace`:return 0;case`None`:return 2**53-1}})),gze=nG(`effect/Logger/CurrentLoggers`,{defaultValue:()=>new Set([Sze,Cze])}),_ze=nG(`effect/Logger/LogToStderr`,{defaultValue:QV}),vze={"~effect/Logger":{_Message:YV,_Output:YV},pipe(){return KV(this,arguments)}},WJ=e=>{let t=Object.create(vze);return t.log=e,t},yze=e=>e.replace(/[\s="]/g,`_`),bze=(e,t)=>`${yze(e[0])}=${t-e[1]}ms`,GJ=e=>(...t)=>{let n;for(let e=0,r=t.length;e<r;e++){let r=t[e];wU(r)&&(n?t.splice(e,1):t=t.slice(0,e).concat(t.slice(e+1)),n=n?AU(n.reasons.concat(r.reasons)):r,e--)}return n===void 0&&(n=PFe),YU(r=>{let i=e??r.cache.logLevel;if(UJ(r.cache.minimumLogLevel,i))return YK;let a=r.getRef(jJ),o=r.getRef(gze);if(o.size>0){let e=new Date(a.currentTimeMillisUnsafe());for(let a of o)a.log({cause:n,fiber:r,date:e,logLevel:i,message:t})}return YK})},KJ={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};KJ.gray,KJ.blue,KJ.green,KJ.yellow,KJ.red,KJ.bgBrightRed,KJ.black;const xze=e=>`${e.getHours().toString().padStart(2,`0`)}:${e.getMinutes().toString().padStart(2,`0`)}:${e.getSeconds().toString().padStart(2,`0`)}.${e.getMilliseconds().toString().padStart(3,`0`)}`,Sze=WJ(({cause:e,date:t,fiber:n,logLevel:r,message:i})=>{let a=Array.isArray(i)?i.slice():[i];e.reasons.length>0&&a.push(DK(e));let o=t.getTime(),s=n.getRef(mLe),c=``;for(let e of s)c+=` ${bze(e,o)}`;let l=n.getRef(mK);Object.keys(l).length>0&&a.push(l);let u=n.getRef(HJ);(n.getRef(_ze)?u.error:u.log)(`[${xze(t)}] ${r.toUpperCase()} (#${n.id})${c}:`,...a)}),Cze=WJ(({cause:e,fiber:t,logLevel:n,message:r})=>{let i=t.getRef(jJ),a=t.getRef(mK),o=t.cache.span;if(o===void 0||o._tag===`ExternalSpan`||o.status._tag===`Ended`)return;let s={};for(let[e,t]of Object.entries(a))lU(s,e,t);s[`effect.fiberId`]=t.id,s[`effect.logLevel`]=n.toUpperCase(),e.reasons.length>0&&(s[`effect.cause`]=DK(e)),o.event(OFe(Array.isArray(r)&&r.length===1?r[0]:r),i.currentTimeNanosUnsafe(),s)});function wze(){FK.interruptChildren??=ALe}const Tze={"~effect/Deferred":{_A:YV,_E:YV},pipe(){return KV(this,arguments)}},qJ=function(){this.resumes=void 0,this.effect=void 0};qJ.prototype=Tze;const JJ=()=>new qJ,YJ=()=>GK(()=>JJ()),XJ=e=>ZK(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),GK(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),ZJ=W(2,(e,t)=>GK(()=>nY(e,t))),QJ=W(2,(e,t)=>ZJ(e,qU(t))),$J=e=>GK(()=>eY(e)),eY=e=>e.effect!==void 0;function Eze(e){return GK(()=>kW(e.effect))}const tY=W(2,(e,t)=>ZJ(e,UU(t))),nY=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let n=e.resumes;e.resumes=void 0;for(let e=0;e<n.length;e++)n[e](t)}return!0},Dze=W(2,(e,t)=>fJ(n=>gq(Bq(n(e)),e=>ZJ(t,e)))),Oze=hK,rY=Wq,iY=eJ,aY=jRe,oY=Xq,sY=Zq,cY=ARe,lY=Yq,uY=Gq,dY=`~effect/Layer/MemoMap`,kze=(e,t)=>{let n={observers:0,deferred:JJ(),scope:iY(),finalizer:r=>KK(()=>--n.observers>0?YK:(e.map.delete(t),uY(n.scope,r)))};return n},fY=(e,t)=>t.state._tag!==`Closed`&&(e.observers++,Qq(t,{},e.finalizer),!0),Aze={"~effect/Layer":{_ROut:YV,_E:YV,_RIn:YV},pipe(){return KV(this,arguments)}},pY=e=>{let t=Object.create(Aze);return t.build=e,t},jze=e=>pY((t,n)=>{let r=lY(n);return cJ(e(t,r),e=>e._tag===`Failure`?uY(r,e):YK)}),mY=e=>{let t=jze((n,r)=>n.getOrElseMemoize(t,r,e));return t};var hY=class{get[dY](){return dY}parent;constructor(e){this.parent=e}map=new Map;get(e,t){let n=this.map.get(e);return n?(fY(n,t),n.deferred.effect??XJ(n.deferred)):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return KK(()=>{let r;return oJ(KK(()=>{let i=this.get(e,t);if(i)return i;let a=kze(this,e);return fY(a,t)?(r=a.deferred,this.map.set(e,a),n(this,a.scope)):n(this,t)}),e=>{r&&nY(r,e)})})}};const gY=()=>new hY,Mze=e=>new hY(e);var _Y=class e extends PW()(`effect/Layer/CurrentMemoMap`){static forkOrCreate(t){let n=YW(t,e);return n?Mze(n):gY()}};const vY=W(3,(e,t,n)=>Tq(vq(KK(()=>e.build(t,n)),JW(_Y,t)),_Y,t)),Nze=W(2,(e,t)=>YU(n=>vY(e,_Y.forkOrCreate(n.context),t))),yY=function(){return arguments.length===1?e=>bY(qW(arguments[0],e)):bY(qW(arguments[0],arguments[1]))},bY=e=>pY(XV(HK(e))),xY=function(){return arguments.length===1?e=>SY(arguments[0],e):SY(arguments[0],arguments[1])},SY=(e,t)=>Pze(vq(t,t=>qW(e,t))),Pze=e=>mY((t,n)=>aY(e,n)),CY=(e,t,n)=>{let r=lY(n,`parallel`);return hJ(e,e=>e.build(t,lY(r,`sequential`)),{concurrency:e.length}).pipe(vq(e=>dIe(...e)))},wY=(...e)=>mY((t,n)=>CY(e,t,n)),Fze=(e,t,n)=>mY((r,i)=>gq(Array.isArray(t)?CY(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(wq(t),vq(e=>n(e,t))))),TY=W(2,(e,t)=>Fze(e,t,(e,t)=>tG(t,e))),EY=UU,DY=KU,OY=qU,kY=xq,AY=yq,jY=QLe,Ize=aRe,Lze=wU,MY=LU,NY=AU,Rze=NU,zze=FU,PY=vLe,FY=CK,Bze=yLe,IY=vK,Vze=DK,LY=$U,RY=tW,zY=RFe,Hze=mze,Uze=VJ,BY=dze,VY=fze,HY=`~effect/DateTime`,UY=`~effect/DateTime/TimeZone`,WY={[HY]:HY,pipe(){return KV(this,arguments)},[nU](){return this.toString()},toJSON(){return $Y(this).toJSON()}},GY={...WY,_tag:`Utc`,[xH](){return OH(this.epochMilliseconds)},[LH](e){return XY(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${$Y(this).toJSON()})`}},Wze={...WY,_tag:`Zoned`,[xH](){return TH(OH(this.epochMilliseconds))(SH(this.zone))},[LH](e){return XY(e)&&e._tag===`Zoned`&&this.epochMilliseconds===e.epochMilliseconds&&RH(this.zone,e.zone)},toString(){return`DateTime.Zoned(${tBe(this)})`}},KY={[UY]:UY,[nU](){return this.toString()}};({...KY}),{...KY};const Gze={value:void 0,enumerable:!1,writable:!0},qY=new WeakMap,JY=(e,t)=>({get(){return Object.isExtensible(this)?void 0:qY.get(this)?.[e]},set(n){if(Object.isExtensible(this)){for(let e of t)Object.defineProperty(this,e,Gze);this[e]=n}else{let t=qY.get(this);t===void 0&&(t={},qY.set(this,t)),t[e]=n}}}),YY=[`partsUtc`,`adjustedEpochMilliseconds`,`partsAdjusted`];Object.defineProperty(GY,"partsUtc",JY(`partsUtc`,[`partsUtc`])),Object.defineProperties(Wze,{partsUtc:JY(`partsUtc`,YY),adjustedEpochMilliseconds:JY(`adjustedEpochMilliseconds`,YY),partsAdjusted:JY(`partsAdjusted`,YY)});const XY=e=>yH(e,HY),ZY=e=>{let t=Object.create(GY);return t.epochMilliseconds=e,t},QY=e=>{let t=e.getTime();if(Number.isNaN(t))throw new Hze(`Invalid date`);return ZY(t)},Kze=e=>{if(XY(e))return e;if(e instanceof Date)return QY(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return QY(new Date(e.epochMilliseconds));let t=new Date(0);return $ze(t,e),QY(t)}return typeof e==`string`&&!qze(e)?QY(new Date(e+`Z`)):QY(new Date(e))},qze=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e)||/z$|gmt$/i.test(e),Jze=vq(BY,ZY),$Y=e=>new Date(e.epochMilliseconds),eX=e=>{if(e._tag===`Utc`)return new Date(e.epochMilliseconds);if(e.zone._tag===`Offset`)return new Date(e.epochMilliseconds+e.zone.offset);if(e.adjustedEpochMilliseconds!==void 0)return new Date(e.adjustedEpochMilliseconds);let t=!1,n=e.zone.format.formatToParts(e.epochMilliseconds).filter(e=>e.type===`era`?(t=e.value===`BC`,!1):e.type!==`literal`),r=Number(n[2].value),i=new Date(0);return i.setUTCFullYear(t?1-r:r,Number(n[0].value)-1,Number(n[1].value)),i.setUTCHours(Number(n[3].value),Number(n[4].value),Number(n[5].value),n[6]?.type===`fractionalSecond`?Number(n[6].value):(e.epochMilliseconds%1e3+1e3)%1e3),e.adjustedEpochMilliseconds=i.getTime(),i},Yze=e=>eX(e).getTime()-Qze(e),Xze=e=>{let t=Math.abs(e),n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r===60&&(n+=1,r=0),`${e<0?`-`:`+`}${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`},Zze=e=>Xze(Yze(e)),Qze=e=>e.epochMilliseconds,$ze=(e,t)=>{if((t.year!==void 0||t.month!==void 0||t.day!==void 0)&&e.setUTCFullYear(t.year??e.getUTCFullYear(),t.month===void 0?e.getUTCMonth():t.month-1,t.day??e.getUTCDate()),t.weekDay!==void 0){let n=t.weekDay-e.getUTCDay();e.setUTCDate(e.getUTCDate()+n)}t.hour!==void 0&&e.setUTCHours(t.hour),t.minute!==void 0&&e.setUTCMinutes(t.minute),t.second!==void 0&&e.setUTCSeconds(t.second),t.millisecond!==void 0&&e.setUTCMilliseconds(t.millisecond)},eBe=e=>$Y(e).toISOString(),tX=e=>{let t=eX(e);return e._tag===`Utc`?t.toISOString():`${t.toISOString().slice(0,-1)}${Zze(e)}`},tBe=e=>e.zone._tag===`Offset`?tX(e):`${tX(e)}[${e.zone.id}]`;globalThis.Number;const nBe=W(2,(e,t)=>{let n=10**t;return Math.round(e*n)/n}),nX=W(2,(e,t)=>kq(e,rBe,e=>t(e))),rX=e=>e.reasons.some(iX),iX=e=>e._tag===`Fail`&&LY(e.error),aX=e=>{let t,n=!1;for(let r of e.reasons)iX(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?oG(e):n?oG(NY(e.reasons.filter(e=>!iX(e)))):aG(t)},rBe=e=>{let t=aX(e);return sG(t)?t:aG(t.success.value)},oX=e=>{let t=aX(e);return sG(t)?DY(t.failure):EY(t.success.value)},sX=W(2,(e,t)=>Iq(e,{onSuccess:t.onSuccess,onFailure:e=>{let n=aX(e);return sG(n)?t.onFailure(n.failure):t.onDone(n.success.value)}})),cX=`~effect/Schedule`,lX=nG(`effect/Schedule/CurrentMetadata`,{defaultValue:XV({input:void 0,output:void 0,duration:HG,attempt:0,start:0,now:0,elapsed:0,elapsedSincePrevious:0})}),iBe={[cX]:{_Out:YV,_In:YV,_Env:YV},pipe(){return KV(this,arguments)}},aBe=e=>yH(e,cX),uX=e=>{let t=Object.create(iBe);return t.step=e,t},dX=()=>{let e=0,t,n;return(r,i)=>{n===void 0&&(n=r);let a=r-n,o=t===void 0?0:r-t;return t=r,{input:i,attempt:++e,start:n,now:r,elapsed:a,elapsedSincePrevious:o}}},oBe=e=>uX(vq(e,e=>{let t=dX();return(n,r)=>e(t(n,r))})),fX=e=>Dq(e.step,e=>HK(()=>UK(e))),sBe=e=>FJ(t=>vq(fX(e),e=>{let n=dX();return r=>KK(()=>{let i=t.currentTimeMillisUnsafe();return gq(e(i,r),([e,t])=>{let a=n(i,r);return a.output=e,a.duration=t,iq(IJ(t),a)})})})),pX=e=>uX(vq(fX(e),e=>(t,n)=>sX(e(t,n),{onSuccess:e=>HK([n,e[1]]),onFailure:UK,onDone:()=>zY(n)}))),mX=e=>{let t=FG(e);return oBe(HK(e=>HK([e.attempt-1,t])))},hX=W(2,(e,t)=>uX(vq(fX(e),e=>{let n=dX();return(r,i)=>gq(e(r,i),e=>{let[a,o]=e,s=t({...n(r,i),output:a,duration:o});return gq(bU(s)?s:HK(s),t=>t?HK(e):zY(a))})}))),cBe=mX(HG),lBe=(e,t,n)=>iJ(r=>gq(n?.local?vY(t,gY(),r):Nze(t,r),t=>wq(e,t))),uBe=W(e=>bU(e[0]),(e,t,n)=>WW(t)?wq(e,t):lBe(e,Array.isArray(t)?wY(...t):t,n)),dBe=W(3,(e,t,n)=>gq(sBe(t),t=>{let r=lX.defaultValue(),i=n=>sX(t(n),{onSuccess(t){return r=t,gq(Tq(e,lX,r),i)},onFailure:UK,onDone:HK});return kq(gq(Tq(e,lX,r),i),xK,e=>n(e,r.attempt===0?G():CW(r)))})),fBe=W(2,(e,t)=>{let n=typeof t==`function`?t(YV):aBe(t)?t:mBe(t);return dBe(e,n,WK)}),pBe=pX(cBe),mBe=e=>{let t=e.schedule?pX(e.schedule):pBe;return e.while&&(t=hX(t,({input:t})=>{let n=e.while(t);return bU(n)?n:HK(n)})),e.until&&(t=hX(t,({input:t})=>{let n=e.until(t);return bU(n)?vq(n,e=>!e):HK(!n)})),e.times!==void 0&&(t=hX(t,({attempt:t})=>HK(t<=e.times))),t},gX=bU,_X=pJ,vX=hJ,hBe=mJ,yX=LLe,q=HK,bX=KK,xX=GK,SX=YK,CX=ZK,wX=QK,TX=zLe,J=WK,gBe=FLe,EX=UK,DX=PLe,OX=JK,kX=ILe,AX=YU,_Be=MLe,Y=gq,vBe=JLe,jX=fq,MX=pq,NX=Bq,PX=vq,FX=iq,IX=mq,yBe=uRe,LX=Aq,RX=hRe,bBe=gRe,xBe=_Re,zX=Dq,BX=jq,VX=Mq,HX=Nq,UX=vRe,WX=mRe,GX=yRe,SBe=bRe,CBe=DRe,wBe=Vq,KX=IJ,qX=hq,JX=zq,YX=Iq,TBe=Rq,XX=cRe,EBe=Cq,DBe=uBe,ZX=wq,QX=oRe,$X=Tq,eZ=rJ,tZ=MRe,OBe=iJ,nZ=NRe,kBe=RRe,rZ=PRe,iZ=FRe,aZ=LRe,ABe=oJ,oZ=cJ,jBe=VRe,sZ=HRe,MBe=lJ,cZ=fJ,lZ=dRe,NBe=fBe,uZ=cze,PBe=YRe,dZ=SJ,fZ=XRe,FBe=QRe,pZ=CJ,IBe=$Re,mZ=eze,X=eq,hZ=(e,t,n)=>(...r)=>CX(i=>{let a=!0,o;try{e(...r,(e,n)=>{let s=e?t?bX(()=>J(t(e,r))):J(e):q(n);a?o??=s:i(s)})}catch(e){o=n?J(n(e,r)):OX(e)}a=!1,o&&i(o)}),LBe=YLe,RBe=XLe,gZ=qLe,zBe=BLe,_Z=globalThis.BigInt,BBe=e=>e>_Z(2**53-1)||e<_Z(-(2**53-1))?G():CW(Number(e)),vZ=BigInt(0),VBe=BigInt(1),yZ=BigInt(1e3),bZ=BigInt(1024),xZ=[{symbol:`B`,factor:VBe,names:[`B`,`byte`,`bytes`]},{symbol:`kB`,factor:yZ,names:[`kB`,`kilobyte`,`kilobytes`]},{symbol:`MB`,factor:yZ**BigInt(2),names:[`MB`,`megabyte`,`megabytes`]},{symbol:`GB`,factor:yZ**BigInt(3),names:[`GB`,`gigabyte`,`gigabytes`]},{symbol:`TB`,factor:yZ**BigInt(4),names:[`TB`,`terabyte`,`terabytes`]},{symbol:`PB`,factor:yZ**BigInt(5),names:[`PB`,`petabyte`,`petabytes`]},{symbol:`EB`,factor:yZ**BigInt(6),names:[`EB`,`exabyte`,`exabytes`]},{symbol:`ZB`,factor:yZ**BigInt(7),names:[`ZB`,`zettabyte`,`zettabytes`]},{symbol:`YB`,factor:yZ**BigInt(8),names:[`YB`,`yottabyte`,`yottabytes`]},{symbol:`RB`,factor:yZ**BigInt(9),names:[`RB`,`ronnabyte`,`ronnabytes`]},{symbol:`QB`,factor:yZ**BigInt(10),names:[`QB`,`quettabyte`,`quettabytes`]}],HBe=[xZ[0],{symbol:`KiB`,factor:bZ,names:[`KiB`,`kibibyte`,`kibibytes`]},{symbol:`MiB`,factor:bZ**BigInt(2),names:[`MiB`,`mebibyte`,`mebibytes`]},{symbol:`GiB`,factor:bZ**BigInt(3),names:[`GiB`,`gibibyte`,`gibibytes`]},{symbol:`TiB`,factor:bZ**BigInt(4),names:[`TiB`,`tebibyte`,`tebibytes`]},{symbol:`PiB`,factor:bZ**BigInt(5),names:[`PiB`,`pebibyte`,`pebibytes`]},{symbol:`EiB`,factor:bZ**BigInt(6),names:[`EiB`,`exbibyte`,`exbibytes`]},{symbol:`ZiB`,factor:bZ**BigInt(7),names:[`ZiB`,`zebibyte`,`zebibytes`]},{symbol:`YiB`,factor:bZ**BigInt(8),names:[`YiB`,`yobibyte`,`yobibytes`]}],UBe=[...xZ,...HBe.slice(1)],WBe=new Map(UBe.flatMap(e=>e.names.map(t=>[t,e]))),SZ=e=>e,CZ=e=>{throw Error(`Invalid ByteSize: ${e}`)},wZ=e=>!Number.isSafeInteger(e)||e<0?CZ(`expected a non-negative safe integer, received ${e}`):SZ(BigInt(e)),GBe=(e,t)=>{let n=/^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(e);if(n===null)return;let r=n[2]??``,i=BigInt(n[1]+r)*t,a=Number(n[3]??0)-r.length;if(a>=0)return i*BigInt(10)**BigInt(a);let o=BigInt(10)**BigInt(-a);return i%o===vZ?i/o:void 0},KBe=e=>{let t=/^\s*(\d+(?:\.\d+)?)\s*([A-Za-z]+)\s*$/.exec(e);if(t===null)return CZ(`unsupported syntax ${JSON.stringify(e)}`);let n=WBe.get(t[2]);if(n===void 0)return CZ(`unsupported unit ${JSON.stringify(t[2])}`);let r=GBe(t[1],n.factor);return r===void 0?CZ(`${JSON.stringify(e)} does not represent an integral number of bytes`):SZ(r)},TZ=e=>{switch(typeof e){case`bigint`:return e<vZ?CZ(`expected a non-negative bigint, received ${e}`):SZ(e);case`number`:return wZ(e);case`string`:return KBe(e)}return CZ(`unsupported input ${e}`)},EZ=e=>typeof e==`bigint`?TZ(e):wZ(e),DZ=LK,OZ=zK,kZ=BK,qBe=NK,AZ=ZRe,jZ=1e4,JBe=2**22,MZ=(e,t)=>{let n=[],r=new Set;for(let t of e)for(let e of oVe(t)){let t=n.length;ZBe(e,n)&&r.add(t)}let i=HZ(n,r);return{nodes:n,initial:i,dot:t,masks:n.length<=32?YBe(n,i):void 0}},YBe=(e,t)=>{let n=0;for(let e of t)n|=1<<e;let r=0,i=0,a=0;for(let t=0;t<e.length;t++){let n=e[t],o=1<<t;n._tag===`Globstar`?r|=o:n._tag===`End`&&(i|=o,n.directoryOnly||(a|=o))}return{initial:n,globstar:r,end:i,endFile:a}},XBe=e=>e.startsWith(`//`)&&e[2]!==void 0&&e[2]!==`/`,ZBe=(e,t)=>{if(e===``||XBe(e))return!1;let n=QBe(e),r=n.indexOf(`**`);if(r!==-1&&n.some((e,t)=>t>r&&(e===`.`||e===`..`)))return!1;let{directory:i,segments:a}=tVe(n);if(a.length===0)return!1;for(let e of a)e===`**`?t[t.length-1]!==NZ&&t.push(NZ):t.push(nVe(Array.from(e)));return t.push({_tag:`End`,directoryOnly:i}),!0},NZ={_tag:`Globstar`},QBe=e=>{let t=[],n=0;for(let r=0;r<e.length;r++)e[r]===`\\`?r++:e[r]===`/`&&(t.push(e.slice(n,r)),n=r+1);return t.push(e.slice(n)),t},PZ=/^[A-Za-z]:/,$Be=e=>e.length===2&&PZ.test(e),FZ=e=>e===``||e.length===3&&e[2]===`/`&&PZ.test(e),eVe=e=>e.startsWith(`/`)||e[2]===`/`&&PZ.test(e),tVe=e=>{let t=[],n=0;e.length>1&&(e[0]===``||$Be(e[0]))&&(t.push(e[0]===``?``:`${e[0]}/`),n=1);let r=!1;for(;n<e.length;n++){let i=e[n];i===``||i===`.`?r=n===e.length-1&&t.length>0:(t.push(i),r=!1)}return t.length===0&&e.includes(`.`)&&t.push(`.`),{segments:t,directory:r}},nVe=e=>{let t=[],n=``,r=!1,i=!0;for(let a=0;a<e.length;a++){let o=e[a];if(o===`\\`&&a+1<e.length)n+=e[++a],t.push({_tag:`Char`,code:e[a].codePointAt(0)});else if(o===`*`)r=!0,t[t.length-1]?._tag!==`Star`&&t.push({_tag:`Star`});else if(o===`?`)r=!0,t.push({_tag:`Any`});else if(o===`[`&&i){let s=LZ(e,a);s===void 0?(i=!1,n+=o,t.push({_tag:`Char`,code:o.codePointAt(0)})):(r=!0,t.push(s.token),a=s.end)}else n+=o,t.push({_tag:`Char`,code:o.codePointAt(0)})}if(!r)return{_tag:`Literal`,value:n};let a=t[0];return{_tag:`Wildcard`,tokens:t,leadingDot:a._tag===`Char`&&a.code===46,affixes:rVe(t)}},rVe=e=>{let t=``,n;for(let r of e)if(r._tag===`Star`&&n===void 0)n=``;else if(r._tag===`Char`&&(r.code<55296||r.code>57343)){let e=String.fromCodePoint(r.code);n===void 0?t+=e:n+=e}else return;return n===void 0?void 0:{prefix:t,suffix:n}},IZ=(e,t)=>[e.codePointAt(0),t.codePointAt(0)],iVe={alnum:[...IZ(`0`,`9`),...IZ(`A`,`Z`),...IZ(`a`,`z`)],alpha:[...IZ(`A`,`Z`),...IZ(`a`,`z`)],blank:[9,9,32,32],cntrl:[0,31,127,127],digit:IZ(`0`,`9`),graph:[33,126],lower:IZ(`a`,`z`),print:[32,126],punct:[33,47,58,64,91,96,123,126],space:[9,13,32,32],upper:IZ(`A`,`Z`),word:[...IZ(`0`,`9`),...IZ(`A`,`Z`),95,95,...IZ(`a`,`z`)],xdigit:[...IZ(`0`,`9`),...IZ(`A`,`F`),...IZ(`a`,`f`)]},aVe=(e,t)=>{for(let n=t+2;n<e.length&&n<=t+8;n++)if(e[n]===`:`&&e[n+1]===`]`){let r=iVe[e.slice(t+2,n).join(``)];return r===void 0?void 0:{ranges:r,end:n+1}}},LZ=(e,t)=>{let n=t+1,r=e[n]===`!`||e[n]===`^`;r&&n++;let i=[];for(let t=!0;n<e.length;n++,t=!1){let a=e[n];if(a===`/`)return;if(a===`]`&&!t)return{token:{_tag:`Class`,ranges:i,negated:r},end:n};if(a===`[`&&e[n+1]===`:`){let t=aVe(e,n);if(t!==void 0){i.push(...t.ranges),n=t.end;continue}}if(a===`\\`&&n+1<e.length&&(a=e[++n]),e[n+1]===`-`&&n+2<e.length&&e[n+2]!==`]`){let t=n+2;if(e[t]===`/`)return;e[t]===`\\`&&t+1<e.length&&t++,i.push(...IZ(a,e[t])),n=t;continue}i.push(...IZ(a,a))}},oVe=e=>{let t=Array.from(e),n=sVe(t);if(n.size===0)return[e];let r=RZ(t,0,t.length,n,0);if(r===void 0)return[e];let i=zZ(r);return i>jZ||i*e.length>JBe?[e]:BZ(r)},sVe=e=>{let t=new Map,n=[],r=!0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`\\`)i++;else if(a===`/`)r=!0;else if(a===`[`&&r){let t=LZ(e,i);t===void 0?r=!1:i=t.end}else if(a===`{`)n.push({open:i,commas:[]});else if(a===`,`)n[n.length-1]?.commas.push(i);else if(a===`}`){let e=n.pop();e!==void 0&&e.commas.length>0&&t.set(e.open,{commas:e.commas,close:i})}}return t},RZ=(e,t,n,r,i)=>{if(i>64)return;let a=[],o=``;for(let s=t;s<n;s++){let t=r.get(s);if(t===void 0){e[s]===`\\`&&s+1<n&&(o+=e[s++]),o+=e[s];continue}let c=[],l=s+1;for(let n of[...t.commas,t.close]){let t=RZ(e,l,n,r,i+1);if(t===void 0)return;c.push(t),l=n+1}o!==``&&(a.push(o),o=``),a.push(c),s=t.close}return o!==``&&a.push(o),a},zZ=e=>{let t=1;for(let n of e)if(typeof n!=`string`){let e=0;for(let t of n)e+=zZ(t);if(t*=e,t>jZ)return 1/0}return t},BZ=e=>{let t=[``];for(let n of e)if(typeof n==`string`)t=t.map(e=>e+n);else{let e=n.flatMap(BZ);t=t.flatMap(t=>e.map(e=>t+e))}return t},cVe=(e,t)=>{switch(e._tag){case`Char`:return e.code===t;case`Any`:return!0;case`Star`:return!1;case`Class`:{let n=!1;for(let r=0;r<e.ranges.length&&!n;r+=2)n=t>=e.ranges[r]&&t<=e.ranges[r+1];return n!==e.negated}}},VZ=e=>e>65535?2:1,lVe=(e,t,n)=>{if(t===`.`||t===`..`||t.startsWith(`.`)&&!n&&!e.leadingDot)return!1;if(e.affixes!==void 0){let{prefix:n,suffix:r}=e.affixes;return t.length>=n.length+r.length&&t.startsWith(n)&&t.endsWith(r)}let{tokens:r}=e,i=0,a=0,o=-1,s=0;for(;a<t.length;){if(r[i]?._tag===`Star`){o=i++,s=a;continue}let e=t.codePointAt(a);if(i<r.length&&cVe(r[i],e))i++,a+=VZ(e);else if(o!==-1)i=o+1,s+=VZ(t.codePointAt(s)),a=s;else return!1}for(;r[i]?._tag===`Star`;)i++;return i===r.length},HZ=(e,t)=>{for(let n of t)e[n]._tag===`Globstar`&&t.add(n+1);return t},UZ=(e,t,n)=>{let r=new Set,i=new Set,a=FZ(n);for(let o of t){let t=e.nodes[o];switch(t._tag){case`Globstar`:!a&&n!==`.`&&n!==`..`&&(e.dot||!n.startsWith(`.`))&&i.add(o);break;case`Literal`:t.value===n&&r.add(o+1);break;case`Wildcard`:!a&&lVe(t,n,e.dot)&&r.add(o+1)}}return{explicit:HZ(e.nodes,r),globstar:HZ(e.nodes,i)}},WZ=e=>{if(e.globstar.size===0)return e.explicit;let t=new Set(e.explicit);for(let n of e.globstar)t.add(n);return t},GZ=(e,t,n)=>{for(let r of t){let t=e.nodes[r];if(t._tag===`End`&&(n||!t.directoryOnly))return!0}return!1},KZ=(e,t)=>{for(let n of t)if(e.nodes[n]._tag!==`End`)return!0;return!1},uVe=(e,t)=>{for(let n of t){let t=e.nodes[n];if(t._tag===`End`&&t.directoryOnly)return!0}return!1},qZ=(e,t)=>e===``?t===``?`/`:t:e.endsWith(`/`)?e+t:`${e}/${t}`,JZ=e=>e.reason._tag===`NotFound`||e.reason._tag===`BadResource`,YZ=e=>JZ(e)||e.reason._tag===`PermissionDenied`,XZ=e=>YZ(e)||e.reason._tag===`Unknown`,dVe=bW(vW,e=>e.name),fVe=e=>(t,n)=>pVe(e,MZ([t],n?.dot??!1),n),pVe=X(function*(e,t,n){if(t.initial.size===0)return[];let r=n?.root??``,i=MZ(n?.exclude??[],!0),a=i.nodes.some(e=>e._tag===`End`&&e.directoryOnly),o=e=>eVe(e)?e:e===``?r===``?`.`:r:qZ(r,e),s=e=>e===`.`||e===`..`||FZ(e),c=(t,n,r)=>{let i=o(qZ(t,n));return e.stat(i).pipe(PX(e=>e.type),xBe(`PlatformError`,`NotFound`,()=>e.readLink(i).pipe(FX(`SymbolicLink`),BX(XZ,()=>q(void 0)))),BX(r?JZ:YZ,()=>q(void 0)),PX(e=>e===void 0?void 0:{name:n,type:e}))},l=(n,r,i)=>{let a=new Set,l=!i;for(let e of r){let n=t.nodes[e];n._tag===`Literal`?a.add(n.value):n._tag!==`End`&&(l=!0)}let u=l?[...a].filter(s):[...a];return yBe(l?BX(e.readDirectoryEntries(o(n)),i?JZ:YZ,()=>q([])):q([]),vX(u,e=>c(n,e,i),{concurrency:16}),(e,t)=>({entries:xIe([...e,...t.filter(hH)],dVe),named:i&&!l}))},u=({name:n,type:r},s,c,l)=>{let u=UZ(t,c,n),d=WZ(u);if(d.size===0)return;let f=qZ(s,n),p=WZ(UZ(i,l,n)),m=KZ(t,d),h=(e,n)=>{let r=GZ(t,d,e);if((r||e&&m)&&!GZ(i,p,e))return{relative:f,accepted:r,excluded:p,next:!e||!m?void 0:!n||u.globstar.size===0?d:KZ(t,u.explicit)?u.explicit:void 0}};if(!m&&!uVe(t,d)&&!a)return h(!1,!1);if(r!==`Unknown`&&r!==`SymbolicLink`)return h(r===`Directory`,!1);let g=o(f);return e.stat(g).pipe(PX(e=>e.type===`Directory`),BX(YZ,()=>q(!1)),Y(t=>{let n=h(t,r===`SymbolicLink`);return r===`SymbolicLink`||n?.next===void 0||u.globstar.size===0?q(n):e.readLink(g).pipe(FX(h(t,!0)),BX(XZ,()=>q(n)))}))},d=16,f=!1,p=JJ(),m=e=>e.pipe(aZ(e=>xX(()=>{f||nY(p,EX(e))})),iZ(xX(()=>{d++})),PBe),h=X(function*(e,t,n,r){let i=yield*l(e,t,r),a=[],o=[];for(let r of i.entries){let i=u(r,e,t,n);if(gX(i)){let e=a.push(void 0)-1;o.push(PX(i,t=>{a[e]=t}))}else a.push(i)}o.length>0&&(yield*_X(o,{concurrency:16,discard:!0}));let s=[];for(let e of a)if(e?.next!==void 0){let t=h(e.relative,e.next,e.excluded,i.named);d>0?(d--,s.push(OZ(yield*m(t)))):s.push(q(yield*t))}let c=[],f=0;for(let e of a)if(e!==void 0&&(e.accepted&&c.push(e.relative),e.next!==void 0))for(let e of yield*s[f++])c.push(e);return c});return yield*qX(iZ(h(``,t.initial,i.initial,!0),xX(()=>{f=!0})),XJ(p))}),ZZ=`~effect/PlatformError`;var QZ=class extends iK(`BadArgument`){get message(){return`${this.module}.${this.method}${this.description?`: ${this.description}`:``}`}},mVe=class extends $Ie{get message(){return`${this._tag}: ${this.module}.${this.method}${this.pathOrDescriptor===void 0?``:` (${this.pathOrDescriptor})`}${this.description?`: ${this.description}`:``}`}},$Z=class extends iK(`PlatformError`){constructor(e){`cause`in e?super({reason:e,cause:e.cause}):super({reason:e})}[ZZ]=ZZ;get message(){return this.reason.message}};const eQ=e=>new $Z(new mVe(e)),tQ=e=>new $Z(new QZ(e)),hVe=nze,nQ=`~effect/MutableRef`,gVe={[nQ]:nQ,...yU,toJSON(){return{_id:`MutableRef`,current:rU(this.current)}}},rQ=e=>{let t=Object.create(gVe);return t.current=e,t},_Ve=W(2,(e,t)=>(e.current=t,e)),vVe=Symbol.for(`effect/MutableList/Empty`),yVe=()=>({head:void 0,tail:void 0,length:0}),iQ=e=>{let t=e.head;t.offset>=1024&&t===e.tail&&t.mutable&&(t.array.length-t.offset)*8<=t.offset&&(e.head=e.tail={array:t.array.slice(t.offset),mutable:!0,offset:0,next:void 0})},aQ=()=>({array:[],mutable:!0,offset:0,next:void 0}),oQ=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=aQ(),e.tail=e.tail.next):e.head=e.tail=aQ(),e.tail.array.push(t),e.length++},sQ=e=>{e.head=e.tail=void 0,e.length=0},bVe=(e,t)=>{if(t=iG(t),t<=0||!e.head)return[];if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){let t=e.head.array;return sQ(e),t}let n=Array(t),r=0,i=e.head;for(;i;){for(;i.offset<i.array.length;)if(n[r++]=i.array[i.offset],i.mutable&&(i.array[i.offset]=void 0),i.offset++,r===t)return e.head=i.offset===i.array.length&&i.next?i.next:i,e.length-=t,e.length===0?sQ(e):iQ(e),n;i=i.next}return sQ(e),n},xVe=(e,t)=>{if(t=iG(t),t<=0||!e.head)return;if(t=Math.min(t,e.length),t===e.length&&e.head?.offset===0&&!e.head.next){sQ(e);return}let n=0,r=e.head;for(;r;){let i=r.array.length-r.offset;if(n+i>t){r.offset+=t-n,e.head=r,e.length-=t,iQ(e);return}n+=i,r=r.next}sQ(e)},cQ=e=>{if(!e.head)return vVe;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length?e.head.next?e.head=e.head.next:sQ(e):iQ(e),t},lQ={_A:YV,_E:YV},SVe={"~effect/Queue":lQ,"~effect/Queue/Enqueue":lQ,"~effect/Queue/Dequeue":lQ,...yU,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:DVe(this)}}},uQ=e=>YU(t=>{let n=Object.create(SVe);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=yVe(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},HK(n)}),dQ=e=>uQ({capacity:e}),CVe=e=>uQ({capacity:e,strategy:`sliding`}),fQ=W(2,(e,t)=>KK(()=>pQ(e,t)?SQ:e.state._tag===`Open`&&e.strategy===`suspend`?jVe(e,t):xQ)),pQ=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.capacity<=0&&e.state.takers.size>(e.strategy===`sliding`?0:e.messages.length)?(oQ(e.messages,t),e.strategy===`sliding`&&xVe(e.messages,e.messages.length-e.state.takers.size),CQ(e),!0):e.strategy===`sliding`&&(e.capacity>0&&(cQ(e.messages),oQ(e.messages,t)),!0):(oQ(e.messages,t),wQ(e),!0):!1,mQ=W(2,(e,t)=>GK(()=>hQ(e,t))),hQ=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=KU(t),r=rRe(n,OVe);return e.state.offers.size===0&&e.messages.length===0?(AQ(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},wQ(e),!0)},gQ=e=>hQ(e,NU(tW())),_Q=e=>GK(()=>wVe(e)),wVe=e=>{if(e.state._tag===`Done`)return!1;sQ(e.messages);let t=e.state.offers;AQ(e,e.state._tag===`Open`?kVe:e.state.exit);for(let e of t)OQ(e);return!0},TVe=e=>vQ(e,1,1/0),vQ=W(3,(e,t,n)=>(t=iG(t),n=iG(n),TQ(()=>AVe(e,t,n)??fq(DQ(e,()=>EQ(e,t)),vQ(e,t,n))))),yQ=e=>TQ(()=>bQ(e)??fq(DQ(e,()=>EQ(e,1)),yQ(e))),EVe=e=>TQ(()=>{let t=bQ(e);return t===void 0?HK(G()):t._tag===`Success`?HK(CW(t.value)):HK(G())}),bQ=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=cQ(e.messages);return kQ(e),UU(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=NVe(e.state.offers);return kQ(e),UU(t)}},DVe=e=>e.state._tag===`Done`?0:e.messages.length,xQ=UU(!1),SQ=UU(!0),OVe=qU(tW()),kVe=ZLe(),CQ=e=>{if(e.state._tag!==`Done`&&e.state.takers.size!==0){for(let t of e.state.takers)if(t.ready()&&(e.state.takers.delete(t),t.resume(xq),e.messages.length===0))break}},wQ=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,CQ(e)},0))},AVe=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return UU([]);if(!EQ(e,t))return;let r=e.messages.length>0?bVe(e.messages,n):[NVe(e.state.offers)];return kQ(e),UU(r)},TQ=VU({op:`QueueTake`,[mU](e){let t=this[pU]();return xU(t)?t[mU](e):t}}),EQ=(e,t)=>e.messages.length>=(e.state._tag===`Closing`?1:Math.min(t,e.capacity||1))||e.capacity<=0&&e.state._tag!==`Done`&&e.state.offers.size>0,DQ=(e,t)=>ZK(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(xq);let r={ready:t,resume:n};return e.state.takers.add(r),GK(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),jVe=(e,t)=>ZK(n=>pQ(e,t)?n(SQ):MVe(e,{_tag:`Single`,message:t,resume:n})),MVe=(e,t)=>{if(e.state._tag!==`Open`)return OQ(t);let n=e.state.offers;return n.add(t),GK(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&AQ(e,e.state.exit))})},OQ=e=>e._tag===`Single`?e.resume(xQ):e.resume(UU(e.remaining.slice(e.offset))),NVe=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(SQ),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(UU([]))),n},kQ=e=>{if(e.state._tag===`Done`)return rX(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(AQ(e,e.state.exit),rX(e.state.exit.cause));for(let t of e.state.offers){let n=e.capacity-e.messages.length;if(n<=0)break;if(t._tag===`Single`)oQ(e.messages,t.message),e.state.offers.delete(t),t.resume(SQ);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;oQ(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(UU([]))}let r=e.state;if(r._tag===`Done`)return rX(r.exit.cause)}return!1},AQ=(e,t)=>{if(e.state._tag===`Done`)return;let n=e.state;e.state={_tag:`Done`,exit:t};for(let e of n.takers)e.resume(t);n.takers.clear();for(let e of n.awaiters)e(t);n.awaiters.clear()},jQ=e=>new PVe(e),MQ=e=>{for(let t of e.waiters)if(t.permits<=e.free)return t},NQ=(e,t,n,r=YV)=>YU(i=>{if(e.free>=t&&MQ(e)===void 0)return e.taken+=t,n();let a={permits:t,resume:void 0},o=()=>{e.waiters.delete(a)&&e.releaseUnsafe(i,0)};e.waiters.add(a),sJ(i,o);let s=r(ZK(t=>{MQ(e)===a?t(YK):a.resume=t})),c=gq(s,()=>MQ(e)===a?(e.taken+=t,o(),n()):c);return c});var PVe=class{waiters=new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){return NQ(this,e,()=>HK(e))}takeScoped(e){return fJ(t=>gq(rJ,n=>NQ(this,e,()=>Zq(n,this.release(e)),t)))}takeIfAvailable(e){return KK(()=>this.free<e?HK(!1):(this.taken+=e,HK(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{let e=this.free;for(let t of Array.from(this.waiters)){if(!this.waiters.has(t)||t.permits>e)continue;e-=t.permits;let n=t.resume;t.resume=void 0,n?.(YK)}},0),this.free}resize(e){return YU(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),YK))}release(e){return YU(t=>HK(this.releaseUnsafe(t,e)))}get releaseAll(){return YU(e=>HK(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>fJ(n=>NQ(this,e,()=>oJ(n(t),()=>{this.releaseUnsafe(NK(),e)},!0),n))}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>fJ(n=>this.free<e?NLe:(this.taken+=e,oJ(n(dq(t)),()=>{this.releaseUnsafe(NK(),e)},!0)))}};const PQ=`~effect/Channel`,FQ=e=>yH(e,PQ),FVe={[PQ]:{_Env:YV,_InErr:YV,_InElem:YV,_OutErr:YV,_OutElem:YV},pipe(){return KV(this,arguments)}},IQ=e=>{let t=Object.create(FVe);return t.transform=(t,n)=>zX(e(t,n),e=>q(EX(e))),t},LQ=(e,t)=>IQ((n,r)=>Y(BQ(e)(n,r),e=>t(e,r))),RQ=e=>IQ((t,n)=>e),zQ=e=>IQ(X(function*(t,n){let r=lY(n),i=e=>uY(r,oX(e)),a=yield*aZ(e(t,n,r),i);return aZ(a,i)})),BQ=e=>e.transform,IVe=(e,t,n)=>uQ({capacity:n?.bufferSize,strategy:n?.strategy}).pipe(MX(t=>sY(e,_Q(t))),MX(n=>aY(t(n),e).pipe(zX(e=>mQ(n,e)),dZ(e,{startImmediately:!0})))),LVe=(e,t)=>IQ((n,r)=>PX(IVe(r,e,t),TVe)),RVe=e=>IQ((t,n)=>bX(()=>BQ(e())(t,n))),zVe=e=>UVe(q(e)),BVe=RQ(q(zY())),VVe=RQ(q(wX)),HVe=e=>RQ(q(J(e))),UVe=e=>RQ(xX(()=>{let t=!1;return bX(()=>t?zY():(t=!0,e))})),WVe=e=>RQ(Y(e,()=>zY())),GVe=W(2,(e,t)=>LQ(e,e=>xX(()=>{let n=0;return PX(e,e=>t(e,n++))}))),KVe=W(2,(e,t)=>qVe(e,e=>q(t(e)))),qVe=W(2,(e,t)=>LQ(e,e=>q(nX(e,e=>Y(t(e),zY))))),JVe=e=>e===void 0||e!==`unbounded`&&e<=1,YVe=W(e=>FQ(e[0]),(e,t,n)=>JVe(n?.concurrency)?XVe(e,t):ZVe(e,t,n)),XVe=(e,t)=>IQ((n,r)=>{let i=0;return PX(BQ(e)(n,r),Y(e=>t(e,i++)))}),ZVe=(e,t,n)=>zQ(X(function*(r,i,a){let o=0,s=yield*BQ(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:Math.min(n.concurrency,2**53-1),l=yield*dQ(0);yield*sY(a,_Q(l));let u=pZ(yield*XX()),d=AZ(a);if(n.unordered){let e=jQ(c),n=XV(e.release(1)),r=YX({onFailure:e=>Y(mQ(l,e),n),onSuccess:e=>Y(fQ(l,e),n)});yield*e.take(1).pipe(Y(()=>s),Y(e=>{let n=o++;return d(u(r(bX(()=>t(e,n))))),SX}),lZ({disableYield:!0}),zX(t=>e.withPermits(c-1)(mQ(l,t))),dZ(a))}else{let e=yield*dQ(c-2);yield*sY(a,_Q(e)),yield*yQ(e).pipe(vBe,Y(e=>fQ(l,e)),lZ({disableYield:!0}),zX(e=>mQ(l,e)),dZ(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,hQ(l,e.cause))};yield*s.pipe(Y(i=>{if(n)return EX(n);let a=o++,s=u(bX(()=>t(i,a)));return d(s),s.addObserver(r),fQ(e,OZ(s))}),lZ({disableYield:!0}),zX(t=>fQ(e,DY(t)).pipe(jX(mQ(e,t)))),dZ(a))}return yQ(l)})),QVe=e=>LQ(e,e=>{let t,n=0,r=bX(function r(){if(t===void 0)return Y(e,e=>{switch(e.length){case 0:return r();case 1:return q(e[0]);default:return t=e,q(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),q(i)});return q(r)}),$Ve=W(2,(e,t)=>IQ((n,r)=>{let i=lY(r);return PX(BQ(e)(n,i),e=>{let a=e.pipe(zX(e=>{if(rX(e))return EX(e);let o=i;return i=lY(r),uY(o,DY(e)).pipe(jX(BQ(t(e))(n,i)),Y(e=>(a=e,e)))}));return bX(()=>a)})})),eHe=W(2,(e,t)=>LQ(e,e=>q(WX(e,e=>LY(e)?SX:IX(t(e)))))),VQ=W(e=>FQ(e[0])&&FQ(e[1]),(e,t,n)=>zQ(X(function*(r,i,a){let o=n?.haltStrategy??`both`,s=yield*dQ(0);yield*sY(a,_Q(s));let c=0;function l(e,t){if(c++,!rX(t))return mQ(s,t);switch(o){case`both`:return c===2?mQ(s,t):SX;case`left`:case`right`:return e===o?mQ(s,t):SX;case`either`:return mQ(s,t)}}let u=(e,t,n)=>BQ(t)(r,n).pipe(Y(e=>e.pipe(Y(e=>fQ(s,e)),lZ)),aZ(t=>ABe(oX(t),e=>uY(n,e)).pipe(YX({onFailure:t=>l(e,t),onSuccess:()=>l(e,t)}))),dZ(a));return yield*u(`left`,e,lY(a)),yield*u(`right`,t,lY(a)),yQ(s)}))),tHe=W(2,(e,t)=>VQ(e,WVe(t),{haltStrategy:`left`})),nHe=()=>IQ((e,t)=>xX(()=>{let t=``,n=!1,r=G();function i(e){let r=[];function i(e){t.length===0?r.push(e):(r.push(t+e),t=``)}for(let r=0;r<e.length;r++){let a=e[r];if(a.length!==0){let e=0,r=a.indexOf(`\r`),o=a.indexOf(`
594
+ `);for(n&&=(o===0&&(e=1,o=a.indexOf(`
595
+ `,e)),!1);r!==-1||o!==-1;)r===-1||o!==-1&&o<r?(i(a.substring(e,o)),e=o+1,o=a.indexOf(`
596
+ `,e)):(i(a.substring(e,r)),a.length===r+1?(n=!0,e=a.length,r=-1):(e=r+(o===r+1?2:1),r=a.indexOf(`\r`,e),o=a.indexOf(`
597
+ `,e)));t+=a.substring(e)}}return pG(r)?r:null}let a=bX(()=>r._tag===`Some`?zY(r.value):sX(e,{onSuccess:o,onFailure:EX,onDone:e=>{if(r=CW(e),t.length>0){let e=t;return t=``,n=!1,q([e])}return zY(e)}}));function o(e){let t=i(e);return t===null?a:q(t)}return a})),rHe=(e,t)=>IQ((n,r)=>xX(()=>{let r=new TextDecoder(e,t),i={stream:!0},a=n.pipe(PX(_G(e=>r.decode(e,i))),nX(e=>{a=zY(e);let t=r.decode();return t.length>0?q(gG(t)):a}));return bX(()=>a)})),HQ=W(2,(e,t)=>IQ((n,r)=>Y(BQ(e)(n,r),e=>BQ(t)(e,r)))),UQ=e=>e._tag===`Die`&&LY(e.defect)&&Lze(e.defect.value),iHe=e=>e.reasons.some(UQ),aHe=e=>zX(e,e=>rX(e)?EX(e):OX(RY(e))),oHe=e=>iHe(e)?NY(e.reasons.flatMap(e=>UQ(e)?e.defect.value.reasons:[e])):e,sHe=e=>zX(e,e=>EX(oHe(e))),WQ=e=>IQ((t,n)=>{let r;return q(bX(()=>r||e.pipe(aY(n),Y(e=>BQ(e)(t,n)),Y(e=>r=e))))}),GQ=(e,t,n)=>bX(()=>{let r=iY(),i=BQ(e)(zY(),r);return nX(Y(i,t),n||q).pipe(oZ(e=>uY(r,e)))}),cHe=e=>GQ(e,e=>lZ(e,{disableYield:!0})),KQ=W(3,(e,t,n)=>bX(()=>{let r=t();return GQ(e,e=>hBe({while:ZV,body:()=>e,step:e=>{r=n(r,e)}}),()=>q(r))})),lHe=X(function*(e){let t=jQ(1),n=yield*XX(),r=QW(n,rY);return(yield*BQ(e)(zY(),r)).pipe(ZX(n),t.withPermits(1))},zX(e=>q(EX(e)))),qQ=(e,t)=>BQ(e)(zY(),t),uHe={_R:YV,_E:YV,_A:YV},JQ=function(e){this.channel=e};JQ.prototype={"~effect/Stream":uHe,pipe(){return KV(this,arguments)}};const dHe=e=>new JQ(e),YQ=`~effect/Sink`,XQ=q([void 0]),fHe={_A:YV,_In:YV,_L:YV,_E:YV,_R:YV},pHe={[YQ]:fHe,pipe(){return KV(this,arguments)}},ZQ=e=>yH(e,YQ),QQ=e=>$Q((t,n)=>BQ(e)(t,n).pipe(Y(lZ({disableYield:!0})),nX(q))),$Q=e=>{let t=Object.create(pHe);return t.transform=e,t},mHe=e=>IQ((t,n)=>q(Y(e.transform(t,n),zY))),e$=$Q(e=>nX(lZ(e,{disableYield:!0}),()=>XQ)),hHe=e=>gHe(vX(t=>e(t),{discard:!0})),gHe=e=>$Q(t=>t.pipe(Y(e),lZ({disableYield:!0}),nX(()=>XQ))),_He=e=>QQ(WQ(PX(e,mHe))),t$={_tag:`Empty`},vHe={_tag:`Closed`},yHe={_A:YV,_E:YV};var bHe=class{"~effect/RcRef"=yHe;pipe(){return KV(this,arguments)}state=t$;acquire;context;scope;idleTimeToLive;constructor(e,t,n,r){this.acquire=e,this.context=t,this.scope=n,this.idleTimeToLive=r}};const xHe=e=>AX(t=>{let n=t.context,r=QW(n,rY),i=new bHe(e.acquire,n,r,e.idleTimeToLive===void 0?void 0:FG(e.idleTimeToLive));return FX(oY(r,()=>{let e=i.state;return i.state=vHe,e._tag===`Acquired`?uY(e.scope,kY):e._tag===`Acquiring`?kZ(e.fiber):SX}),i)}),SHe=(e,t)=>{switch(e.state._tag){case`Closed`:return sZ;case`Acquired`:{let t=e.state;return t.refCount++,t.fiber?FX(kZ(t.fiber),t):q(t)}case`Acquiring`:{let n=e.state;return n.awaiters++,n$(e,n,t)}case`Empty`:{let n={_tag:`Acquiring`,fiber:void 0,awaiters:1,acquired:void 0};e.state=n;let r=iY(),i=ZX(e.acquire,JW(e.context,rY,r)).pipe(Y(t=>{if(e.state!==n)return sZ;let i={_tag:`Acquired`,value:t,scope:r,fiber:void 0,refCount:n.awaiters,invalidated:!1};return e.state=i,n.acquired=i,q(i)}),oZ(t=>AY(t)?SX:(e.state===n&&(e.state=t$),uY(r,t))));return n.fiber=pZ(qBe().context)(i),n$(e,n,t)}}},n$=(e,t,n)=>oZ(n(OZ(t.fiber)),n=>{let r=t.acquired;return r===void 0?--t.awaiters>0||e.state!==t?SX:(e.state=t$,kZ(t.fiber)):jY(n)?r$(e,r):SX}),CHe=e=>{let t=e;return cZ(e=>Y(eZ,n=>Y(SHe(t,e),e=>FX(oY(n,()=>r$(t,e)),e.value))))},r$=(e,t)=>{if(t.refCount--,t.refCount>0)return SX;let n=e.idleTimeToLive;return n===void 0||t.invalidated?(e.state===t&&(e.state=t$),uY(t.scope,kY)):(VG(n)&&(t.fiber=cZ(r=>Y(r(KX(n)),()=>e.state===t&&t.refCount===0?(e.state=t$,SBe(uY(t.scope,kY),{log:`Unhandled`,message:`Unhandled error in RcRef finalizer`})):SX)).pipe(iZ(xX(()=>{t.fiber=void 0})),pZ(e.context),AZ(e.scope))),SX)},i$=xHe,a$=CHe,o$=e=>yH(e,`~effect/Stream`),s$=dHe,c$=e=>s$(RQ(e)),wHe=(e,t)=>s$(IQ((n,r)=>Y(qQ(e.channel,r),e=>t(e,r)))),l$=e=>e.channel,THe=(e,t)=>s$(LVe(e,t)),u$=s$(BVe),d$=(...e)=>kHe(e),EHe=e=>{let t=s$(RVe(()=>e().channel));return DHe.set(t,e),t},DHe=new WeakMap,OHe=e=>s$(HVe(e)),kHe=e=>pG(e)?s$(zVe(e)):u$,AHe=s$(VVe),f$=e=>s$(WQ(PX(e,l$))),jHe=W(e=>o$(e[0]),(e,t,n)=>e.channel.pipe(QVe,YVe(t,n),GVe(gG),s$)),MHe=W(e=>o$(e[0]),(e,t,n)=>jHe(e,e=>FX(t(e),e),n)),NHe=W(2,(e,t)=>FHe(e,g$(t))),PHe=W(e=>o$(e[0])&&o$(e[1]),(e,t,n)=>s$(VQ(l$(e),l$(t),n))),FHe=W(2,(e,t)=>e.channel.pipe(tHe(t),s$)),IHe=W(2,(e,t)=>e.channel.pipe($Ve(e=>t(e).channel),s$)),LHe=W(2,(e,t)=>e.channel.pipe(eHe(t),s$)),p$=W(2,(e,t)=>wHe(e,(e,n)=>xX(()=>{let r,i,a=bX(()=>{if(i!==void 0){let e=i;return i=void 0,q(e)}return e}).pipe(LX(e=>(r=OY(e),zY()))),o=PX(bX(()=>t.transform(a,n)),([e,t])=>(i=t,gG(e)));return bX(()=>r||o)}))),m$=W(e=>o$(e[0]),(e,t)=>e.channel.pipe(HQ(rHe(t?.encoding)),s$)),RHe=e=>e.channel.pipe(HQ(nHe()),s$),h$=W(2,(e,t)=>OBe(n=>qQ(e.channel,n).pipe(Y(e=>zHe(t,e,n)),PX(([e])=>e)))),zHe=(e,t,n)=>sHe(e.transform(aHe(t),n)),BHe=e=>KQ(e.channel,()=>[],(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n]);return e}),g$=e=>cHe(e.channel),VHe=e=>lHe(e.channel),_$=e=>KQ(e.channel,()=>``,(e,t)=>e+t.join(``)),v$=`~effect/FileSystem`,y$=PW(`effect/FileSystem`),HHe=e=>y$.of({...e,[v$]:v$,glob:fVe(e),exists:t=>tH(e.access(t),FX(!0),RX(`PlatformError`,e=>e.reason._tag===`NotFound`?q(!1):J(e))),readFileString:(t,n)=>Y(e.readFile(t),e=>kX({try:()=>new TextDecoder(n).decode(e),catch:e=>tQ({module:`FileSystem`,method:`readFileString`,description:`invalid encoding`,cause:e})})),stream:X(function*(t,n){let r=yield*e.open(t,{flag:`r`}),i=n?.offset===void 0?void 0:TZ(n.offset);i&&(yield*r.seek(i,`start`));let a=n?.bytesToRead===void 0?void 0:TZ(n.bytesToRead),o=BigInt(0),s=Number(BigInt(n?.chunkSize??65536)),c=r.readAlloc(s);return c$(q(Y(bX(()=>a!==void 0&&a<=o?zY():a!==void 0&&a-o<s?r.readAlloc(Number(a-o)):c),EW({onNone:()=>zY(),onSome:e=>(o+=BigInt(e.length),q(gG(e)))}))))},f$),sink:(t,n)=>tH(e.open(t,{...n,flag:n?.flag??`w`}),PX(e=>hHe(t=>e.writeAll(t))),_He),writeFileString:(t,n,r)=>Y(kX({try:()=>new TextEncoder().encode(n),catch:e=>tQ({module:`FileSystem`,method:`writeFileString`,description:`could not encode string`,cause:e})}),n=>e.writeFile(t,n,r))}),b$=`~effect/FileSystem/File`;var x$=class extends PW()(`effect/FileSystem/WatchBackend`){};const S$=`~effect/Path`,C$=PW(`effect/Path`),UHe=e=>C$.of({...e,[S$]:S$,resolveWithin(t,n){if(e.parse(n).root!==``)return G();let r=e.resolve(t),i=e.resolve(r,n),a=e.relative(r,i);return a===`..`||a.startsWith(`..${e.sep}`)||e.isAbsolute(a)?G():CW(i)}});function WHe(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}const w$=`~sentinels`,T$=`~constructor`,E$=nH(e=>{let t=WHe(e)?.identifier;return typeof t==`string`?t:e.getExpected(E$)}),D$=Symbol.for(`effect/schema/parser/missing`),O$=EY,k$=O$(D$),A$=Object.assign(O$(D$),{[D$]:!0}),j$=e=>e[D$]===!0,M$=e=>e===D$?G():CW(e),N$=e=>e._tag===`None`?k$:O$(e.value),P$=`~effect/SchemaIssue/Issue`;function F$(e){return yH(e,P$)&&e[P$]===P$}function GHe(e){return Object.hasOwn(e,`input`)}var I$=class{[P$]=P$;constructor(e,t){t?.reportInput===!0&&e!==D$&&(this.input=e)}};const KHe=class extends I${_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},qHe=class extends I${_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},L$=class extends I${_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},R$=class extends I${_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},z$=class extends I${_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},B$=class extends I${_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},V$=class extends I${_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},H$=class extends I${_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},U$=class extends I${_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},JHe=class extends I${_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function W$(e,t,n){if(F$(e))return e;if(typeof e==`string`)return new H$({message:e},t,n);let r=typeof e.issue==`string`?new H$({message:e.issue},t,n):e.issue;return new L$(e.path,r)}function YHe(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new H$(void 0,t,n):W$(e,t,n)}function XHe(e,t,n,r){return Array.isArray(t)?pG(t)?t.length===1?W$(t[0],n,r):new B$(e,_G(t,e=>W$(e,n,r)),n,r):void 0:YHe(t,n,r)}const G$=e=>{let t=e1(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Y$(E$(e.ast),e);case`InvalidValue`:{let t=J$(e);if(t!==void 0)return Y$(t,e);let n=q$(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=q$(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=q$(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},K$=e=>e1(e)??e1(e.issue);function ZHe(e){return t=>({issues:Z$(t,[],e?.leafHook??G$,e?.checkHook??K$)})}function q$(e){return GHe(e)?QH(e.input):void 0}function J$(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Y$(e,t){let n=q$(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function X$(e,t){let n=t(e);if(n!==void 0||e.issue._tag!==`InvalidValue`)return n;let r=J$(e.issue);return r===void 0?Y$(Q$(e.filter),e):Y$(r,e.issue)}function Z$(e,t,n,r,i){switch(e._tag){case`Filter`:return Z$(e.issue,t,n,r,i??X$(e,r));case`Encoding`:return Z$(e.issue,t,n,r,i);case`Pointer`:return Z$(e.issue,[...t,...e.path],n,r,i);case`Composite`:case`AnyOf`:return e._tag===`Composite`||e.issues.length>0?e.issues.flatMap(e=>Z$(e,t,n,r,i)):[{path:t,message:i??e1(e)??Y$(E$(e.ast),e)}];default:return[{path:t,message:i??n(e)}]}}function Q$(e){let t=e.annotations?.expected;if(typeof t==`string`)return t;switch(e._tag){case`Filter`:return`<filter>`;case`FilterGroup`:return e.checks.map(e=>Q$(e)).join(` & `)}}function QHe(){return e=>$$(e,``)}const $He=QHe();function $$(e,t,n){let r;switch(e._tag){case`Filter`:return $$(e.issue,t,n??X$(e,K$));case`Encoding`:return $$(e.issue,t,n);case`Pointer`:return $$(e.issue,t+SFe(e.path),n);case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>$$(e,t,n)).join(`
598
+ `);r=n??e1(e)??Y$(E$(e.ast),e);break;default:r=n??G$(e)}return t?`${r}\n at ${t}`:r}function e1(e){if(e._tag===`Pointer`||e._tag===`Composite`)return;if(e._tag===`Encoding`)return e1(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function t1(e){let t;for(let n of e.reasons){if(!MY(n)||!F$(n.error))return;t??=n.error}return t}function n1(e,t){let n=t1(e);if(n===void 0)throw Error(t,{cause:e});return n}const eUe=Kze,tUe=Jze,r1=eBe,nUe=(e,t,n)=>{if(e.length<128)return;let r=Uint8Array;if(typeof r.fromBase64==`function`)try{let i=r.fromBase64(e,n);return i.length===t?i:null}catch{return null}},rUe=e=>e.indexOf(`
599
+ `)===-1&&e.indexOf(`\r`)===-1?e:e.replace(/[\n\r]/g,``),iUe=e=>oUe(typeof e==`string`?i1.encode(e):e),aUe=e=>{let t=rUe(e),n=t.length;if(n%4!=0)return oG(new oK({kind:`Decode`,module:`Base64`,input:t,message:`Length must be a multiple of 4, but is ${n}`}));let r=t.indexOf(`=`);if(r!==-1&&(r<n-2||r===n-2&&t[n-1]!==`=`))return oG(new oK({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));let i=t.endsWith(`==`)?2:+!!t.endsWith(`=`),a=n/4*3-i,o=nUe(t,a,void 0);if(o)return aG(o);if(o===null){let e=uUe.exec(t);if(e!==null)return oG(new oK({kind:`Decode`,module:`Base64`,input:t,message:`Invalid character ${e[0]}`}))}try{let e=new Uint8Array(a);for(let r=0,i=0;r<n;r+=4,i+=3){let n=l1(t.charCodeAt(r))<<18|l1(t.charCodeAt(r+1))<<12|l1(t.charCodeAt(r+2))<<6|l1(t.charCodeAt(r+3));e[i]=n>>16,e[i+1]=n>>8&255,e[i+2]=n&255}return aG(e)}catch(e){return oG(new oK({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},oUe=e=>{let t=e.length,n=Uint8Array.prototype.toBase64;return t>=32&&typeof n==`function`?n.call(e):t<128?sUe(e):cUe(e)},sUe=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=a1[e[r-2]>>2],n+=a1[(e[r-2]&3)<<4|e[r-1]>>4],n+=a1[(e[r-1]&15)<<2|e[r]>>6],n+=a1[e[r]&63];return r===t+1&&(n+=a1[e[r-2]>>2],n+=a1[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=a1[e[r-2]>>2],n+=a1[(e[r-2]&3)<<4|e[r-1]>>4],n+=a1[(e[r-1]&15)<<2],n+=`=`),n},cUe=e=>{let t=e.length,n=new Uint8Array(Math.ceil(t/3)*4),r,i=0;for(r=2;r<t;r+=3,i+=4)n[i]=o1[e[r-2]>>2],n[i+1]=o1[(e[r-2]&3)<<4|e[r-1]>>4],n[i+2]=o1[(e[r-1]&15)<<2|e[r]>>6],n[i+3]=o1[e[r]&63];return r===t+1&&(n[i]=o1[e[r-2]>>2],n[i+1]=o1[(e[r-2]&3)<<4],n[i+2]=s1,n[i+3]=s1),r===t&&(n[i]=o1[e[r-2]>>2],n[i+1]=o1[(e[r-2]&3)<<4|e[r-1]>>4],n[i+2]=o1[(e[r-1]&15)<<2],n[i+3]=s1),lUe.decode(n)},i1=new TextEncoder,lUe=new TextDecoder(`utf-8`,{ignoreBOM:!0}),a1=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,o1=i1.encode(a1),s1=61,uUe=/[^A-Za-z0-9+/=]/,c1=new Uint8Array(123).fill(255);for(let e=0;e<64;e++)c1[a1.charCodeAt(e)]=e;c1[61]=0;const l1=e=>{if(e>=c1.length||c1[e]===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return c1[e]},u1=e=>Object.assign(Object.create(qV),e),dUe=u1({_tag:`Passthrough`});function d1(){return dUe}function f1(e){return u1({_tag:`Transform`,transform:e})}function p1(e){return u1({_tag:`TransformEffect`,transform:e})}function m1(){return f1(globalThis.String)}function h1(){return f1(globalThis.Number)}function fUe(e){return p1((t,n)=>kX({try:()=>JSON.parse(t,e?.reviver),catch:()=>new H$({expected:`a valid JSON string`},t,n)}))}function pUe(e){return p1((t,n)=>kX({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new H$({expected:`a JSON-serializable value`},t,n)}))}function mUe(){return f1(iUe)}function hUe(){return p1((e,t)=>RBe(_Be(aUe(e)),()=>new H$({expected:`a valid Base64 string`},e,t)))}const g1=`~effect/BigDecimal`,gUe={[g1]:g1,[xH](){let e=y1(this);return TH(kH(String(e.value)),OH(e.scale))},[LH](e){return _Ue(e)&&wUe(this,e)===0},toString(){return`BigDecimal(${TUe(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[nU](){return this.toJSON()},pipe(){return KV(this,arguments)}},_Ue=e=>yH(e,g1),vUe=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(gUe);return n.value=e,n.scale=t,n},_1=(e,t)=>{let n=vUe(e,t);return n.normalized=n,n},v1=BigInt(0),yUe=BigInt(1),bUe=BigInt(10),xUe=_1(v1,0),y1=e=>{if(e.normalized===void 0){if(e.value===v1)e.normalized=xUe;else{let t=`${e.value}`,n=SUe(t);e.normalized=_1(BigInt(t.slice(0,t.length-n)),e.scale-n)}}return e.normalized},SUe=e=>{let t=e.length;for(;e[t-1]===`0`;)t--;return e.length-t},CUe=[yUe],b1=(e,t)=>e===t?0:e<t?-1:1,x1=(e,t)=>{let n=`${e.value<v1?-e.value:e.value}`,r=`${t.value<v1?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==v1)return i<v1?-1:1;let a=Math.max(n.length,r.length);return vW(n.padEnd(a,`0`),r.padEnd(a,`0`))},wUe=(e,t)=>{if(e.scale===t.scale)return b1(e.value,t.value);let n=S1(e),r=S1(t);if(n!==r)return n<r?-1:1;if(n===0)return 0;let i=e.scale-t.scale,a=Math.abs(i);if(a>100)return n===-1?x1(t,e):x1(e,t);let o=CUe[a]??=bUe**BigInt(a);return i>0?b1(e.value,t.value*o):b1(e.value*o,t.value)},S1=e=>e.value===v1?0:e.value<v1?-1:1,TUe=e=>{let t=y1(e);if(Math.abs(t.scale)>=16)return EUe(t);let n=t.value<v1,r=`${n?-t.value:t.value}`,i=t.scale>0?r.padStart(t.scale+1,`0`):r.padEnd(r.length-t.scale,`0`),a=i.length-t.scale,o=t.scale>0?`${i.slice(0,a)}.${i.slice(a)}`:i;return n?`-${o}`:o},EUe=e=>{if(DUe(e))return`0e+0`;let t=y1(e),n=`${t.value}`,r=t.value<v1?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},DUe=e=>e.value===v1,OUe=Symbol.for(`~effect/Schema/content`);function kUe(e,t){return Object.defineProperty(e,OUe,{value:t}),e}const AUe=class extends JV{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new AUe(this.encode,this.decode)}},C1=`~effect/SchemaTransformation/Transformation`,w1=class extends JV{[C1]=C1;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new w1(this.encode,this.decode)}};function jUe(e){return yH(e,C1)&&e[C1]===C1}const T1=e=>jUe(e)?e:new w1(e.decode,e.encode);function E1(e){return new w1(f1(e.decode),f1(e.encode))}const MUe=new w1(d1(),d1());function D1(){return MUe}const O1=new w1(h1(),m1()),NUe=e=>_H(e)&&typeof e.message==`string`,PUe=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:k1(e.cause)}):Error(e.message);return typeof e.name==`string`&&e.name!==`Error`&&(t.name=e.name),typeof e.stack==`string`&&(t.stack=e.stack),t},FUe=e=>{try{let t=tU(e);return t===void 0?QH(e):JSON.parse(t)}catch{return QH(e)}},IUe=(e,t,n)=>{let r={name:e.name,message:typeof e.message==`string`?e.message:``};return t?.includeStack&&typeof e.stack==`string`&&(r.stack=e.stack),!t?.excludeCause&&e.cause!==void 0&&(r.cause=n(e.cause)),r},LUe=e=>{let t=new WeakSet,n=r=>{if(sFe(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=IUe(r,e,n);return t.delete(r),i}return FUe(r)};return n},k1=e=>NUe(e)?PUe(e):e,RUe=e=>E1({decode:k1,encode:LUe(e)}),zUe=new w1(hUe(),mUe());function BUe(e){return new w1(fUe(e??{}),kUe(pUe(e),{mediaType:`application/json`,preserveSchema:e?.reviver===void 0&&e?.replacer===void 0}))}function A1(e){return t=>t._tag===e}const j1=A1(`Declaration`),VUe=A1(`Never`),HUe=A1(`String`),UUe=A1(`Boolean`),M1=A1(`Literal`),N1=A1(`UniqueSymbol`),WUe=A1(`Arrays`),GUe=A1(`Objects`),P1=A1(`Suspend`),F1=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},I1={},L1=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},R1=`~effect/Schema`;var z1=class{[R1]=R1;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}};const B1=class extends z1{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>{if(t===D$)return k$;e??=this.run(this.typeParameters);try{return e(t,this,n)}catch(e){return OX(e)}}}_rebuild(e,t,n,r,i){let a=W0(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new B1(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},V1=new class extends z1{_tag=`Null`;getParser(){return Q0(this,null)}getExpected(){return`null`}},KUe=class extends z1{_tag=`Undefined`;getParser(){return Q0(this,void 0)}toCodecJson(){return P0(this,[qUe])}getExpected(){return`undefined`}},qUe=new F1(V1,new w1(f1(()=>void 0),f1(()=>null))),H1=new KUe,U1=new class extends z1{_tag=`Unknown`;getParser(){return $0(this,oFe)}getExpected(){return`unknown`}},W1=class extends z1{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${QH(e)}`);this.literal=e}getParser(){return Q0(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?G1(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:G1(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function G1(e){let t=globalThis.String(e.literal);return P0(e,[new F1(new W1(t),new w1(f1(()=>e.literal),f1(()=>t)))])}const K1=new class extends z1{_tag=`String`;getParser(){return $0(this,uH)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&i2(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},JUe=class extends z1{_tag=`Number`;getParser(){return $0(this,dH)}matchKey(e,t){return this._match(vWe,e,t)}matchPart(e,t){return this._match(n2,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:i2(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(q1(this.checks,`effect/schema/isFinite`)||q1(this.checks,`effect/schema/isInt`))?this:P0(this,[oWe])}toCodecStringTree(){return this.toCodecJson()===this?P0(this,[bWe]):P0(this,[xWe])}getExpected(){return`number`}};function q1(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&q1(e.checks,t))}const J1=new JUe,YUe=new class extends z1{_tag=`Boolean`;getParser(){return $0(this,fH)}getExpected(){return`boolean`}},Y1=class extends z1{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(q0(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(q0(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}let c=e=>{let{input:t,len:r,options:i}=e;if(n.rest.length===0&&r>a)for(let o=a;o<r;o++){let r=new z$(n,t[o],i),a=new L$([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return J(new B$(n,[a],t,i))}return e.issues?J(new B$(n,e.issues,t,i)):O$(e.output)},l=(e,t)=>{let r=e.length,i={ast:n,getParser:s,input:e,len:r,tailThreshold:Math.max(a,r-o),output:[],issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:gJ(t.concurrency),f=d===1?ZUe(i,e,0,u):QUe(i,e,{concurrency:d,end:u});if(!f)return c(i);if(_q(f))return gZ(f,()=>c(i));let p=!0;return bX(()=>p?(p=!1,Y(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===D$)return k$;try{return Array.isArray(e)?(r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)}))),l(e,a)):J(new V$(n,e,a))}catch(e){return OX(e)}}}_rebuild(e,t,n){let r=W0(this.elements,e),i=W0(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new Y1(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function XUe(e,t,n,r){if(n._tag===`Failure`)return Z1(e,e.ast,r,n);let i=j$(n)?t:n[pU];if(i!==D$)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(q0(t.ast))return;let n=new L$([r],new R$(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return OY(new B$(e.ast,[n],e.input,e.options))}}const X1={onItem(e,t,n){let r=n<e.len?t:D$;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:XUe},ZUe=_J()(X1),QUe=yJ()(X1),Z1=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=t1(r.cause);if(i===void 0)return DY(FY(r.cause,r=>new B$(t,[new L$([n],r)],e.input,e.options)));let a=new L$([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return OY(new B$(t,[a],e.input,e.options))},Q1=`[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[Ee][+-]?\\d+)?`;function $1(e,t,n=I1){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(r=>Object.prototype.propertyIsEnumerable.call(e,r)&&t.matchKey(r,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(e2(X0(t)))}const e0=class{name;type;constructor(e,t){this.name=e,this.type=t}};function t0(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(t0);default:return!1}}function n0(e){let t=I0(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(n0);default:return!1}}function $Ue(e){return t0(e)&&n0(e)}const r0=class{parameter;type;constructor(e,t){if(!$Ue(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,q0(t)||t.encoding!==void 0&&q0(X0(t)))throw Error("Cannot use `Schema.optionalKey` or `Schema.optional` with index signatures. Index signatures already allow keys to be absent; use `Schema.UndefinedOr` to allow `undefined` values.")}},i0=class extends z1{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o}getParser(e,t=e){let n=this,r=n.propertySignatures.length,i=n.indexSignatures.length;if(!r&&!i)return $0(n,aFe);let a,o,s=()=>(a||(a=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type,ownOnly:v0(e.name)})),o=i?n.indexSignatures.map(n=>({is:n,parserKey:e(e2(n.parameter)),parserValue:t(n.type)})):void 0),a),c=()=>{let e=new Set(n.propertySignatures.map(e=>typeof e.name==`number`?globalThis.String(e.name):e.name)),t=(t,i,a,o,s)=>{if(s._tag===`Failure`)return Z1(t,n,i,s)??kY;let c=j$(s)?o:s[pU];if(a!==D$&&c!==D$){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return kY;lU(t.out,a,c)}return kY},c=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!_q(t))return Y(NX(t),t=>c(e,r,i,t));a=t}if(a._tag===`Failure`)return Z1(e,n,r,a)??kY;let o=j$(a)?r:a[pU],s=e.input[r],l=i.parserValue(s,e.options);return _q(l)?t(e,r,o,s,l):Y(NX(l),n=>t(e,r,o,s,n))},l=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return _q(a)?t(e,n,n,i,a):Y(NX(a),r=>t(e,n,n,i,r))},u=i?yJ()({onItem:(e,[t,n])=>n.is.parameter===K1?l(e,t,n):c(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return zBe(function*(t,d){if(t===D$)return D$;if(typeof t!=`object`||!t||Array.isArray(t))return yield*J(new V$(n,t,d));s();let f=t,p={},m={ast:n,input:f,out:p,issues:void 0,options:d},h=d.errors===`all`,g=d.onExcessProperty===`error`,_=d.concurrency===void 0?1:gJ(d.concurrency),v=i&&g?n.indexSignatures.map(e=>$1(f,e.parameter,d)):void 0;if(g){let r=v?new Set(e):e;if(v)for(let e of v)for(let t of e)r.add(t);let i=Reflect.ownKeys(f);for(let e=0;e<i.length;e++){let a=i[e];if(!r.has(a)&&Object.prototype.propertyIsEnumerable.call(f,a)){let e=new z$(n,f[a],d),r=new L$([a],e);if(h){m.issues?m.issues.push(r):m.issues=[r];continue}return yield*J(new B$(n,[r],t,d))}}}if(r){let e=_===1?s0(m,a):eWe(m,a,{concurrency:_});e&&(yield*e)}if(i&&_===1)for(let e=0;e<i;e++){let t=o[e],n=t.is.parameter===K1?l:c,r=v?.[e]??(t.is.parameter===K1?Object.keys(f):$1(f,t.is.parameter,d));for(let e=0;e<r.length;e++){let i=n(m,r[e],t);if(!_q(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(u){let e=hG();for(let t=0;t<i;t++){let n=o[t],r=v?.[t]??(n.is.parameter===K1?Object.keys(f):$1(f,n.is.parameter,d));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=u(m,e,{concurrency:_});t&&(yield*t)}return m.issues?yield*J(new B$(n,m.issues,t,d)):p})};if(i)return c();let l,u=(e,t,n)=>{let r=a[t];return Y(NX(n),n=>{let i={...e,out:{...e.out}},o=a0(i,r,n);if(o)return o;let s=()=>O$(i.out),c=s0(i,a.slice(t+1));return c?gZ(c,s):s()})};return(e,t)=>{if(e===D$)return k$;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&gJ(t.concurrency)!==1)return(l??=c())(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return J(new V$(n,e,t));let r=s(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=n.ownOnly?Object.hasOwn(i,s):s in i,l=c?i[s]:D$,d=n.parser(l,t);if(!_q(d))return u(o,e,d);if(j$(d)){c&&lU(a,s,l);continue}let f=a0(o,n,d);if(f)return f}}catch(e){return OX(e)}return O$(a)}}_rebuild(e,t,n,r){let i=W0(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new e0(t.name,n)}),a=W0(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new r0(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new i0(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function a0(e,t,n){if(n._tag===`Failure`)return Z1(e,e.ast,t.name,n);if(j$(n))return;let r=n[pU];if(r!==D$){lU(e.out,t.name,r);return}if(delete e.out[t.name],!q0(t.type)){let n=new L$([t.name],new R$(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return OY(new B$(e.ast,[n],e.input,e.options))}}const o0={onItem(e,t){if(!(t.ownOnly?Object.hasOwn(e.input,t.name):t.name in e.input))return t.parser(D$,e.options);let n=e.input[t.name];return lU(e.out,t.name,n),t.parser(n,e.options)},step:a0},s0=_J()(o0),eWe=yJ()(o0);function c0(e,t){return e?t?[...e,...t]:e:t}function l0(e,t,n){return new i0(Reflect.ownKeys(e).map(t=>new e0(t,e[t].ast)),[],n,t)}function u0(e){return e.ast}function d0(e,t,n){return new b0(e.map(u0),t,void 0,n)}const f0=rH(e=>{for(;;){if(P1(e))return U1;let t=e.encoding;if(!t)return e.recur?.(f0,YV)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==YV))return U1;e=t[t.length-1].to}});function p0(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(p0)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function m0(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[w$];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!q0(t)){if(M1(t))return[{key:e.name,literal:t.literal}];if(N1(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!q0(e)){if(M1(e))return[{key:t,literal:e.literal}];if(N1(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>m0(f0(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return m0(e.thunk())}}const h0=new WeakMap,g0=Object.freeze([]),_0=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,tWe=new Set(Reflect.ownKeys(Object.prototype)).add(`__proto__`),v0=e=>tWe.has(typeof e==`number`?globalThis.String(e):e),y0=(e,t)=>Object.hasOwn(e,t)||t in e&&!v0(t);function nWe(e){let t=h0.get(e);if(t)return t;let n,r=0,i,a,o=!0,s=[];for(let t=0;t<e.length;t++){let c=e[t],l=f0(c);if(VUe(l))continue;if(M1(l)||N1(l)){a??=new Map;let e=M1(l)?l.literal:l.symbol;s[t]=e;let n=a.get(e);n||a.set(e,n=[]),n.push(t)}else o=!1;let u=m0(l);if(u.length){n??=new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=p0(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??g0);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??g0;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=new Map;for(let[e,t]of i)a.set(e,Object.freeze(Array.from(t)));let o=Object.freeze(e.map((e,t)=>t));t=(e,t)=>{if(vH(e)){let n=y0(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??g0;if(t)return o}return g0}}else if(n){let e;for(let t of n)(!e||t[1][0].size>e[1][0].size)&&t[1][1].size===r&&(e=t);t=(t,r)=>{let a=_0(t);if(!vH(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=y0(t,n),u=c?t[n]:void 0;if(c&&(!r||u!==void 0)){let e=i.get(u);if(!e)return l(a);for(let t of e)o.add(t);s=n}}if(s===void 0)for(let[e,[i,a]]of n){let n=y0(t,e),s=n?t[e]:void 0;if(n&&(!r||s!==void 0)){let e=i.get(s);if(e)for(let t of e)o.add(t)}else if(r)for(let e of a)o.add(e)}for(let[e,[i,a]]of n){if(e===s)continue;let n=y0(t,e),c=n?t[e]:void 0;if(n&&(!r||c!==void 0)){let e=i.get(c);for(let t of o)a.has(t)&&!e?.has(t)&&o.delete(t)}}return Array.from(o).sort((e,t)=>e-t)}}else t=e=>{let t=l(_0(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return h0.set(e,t),t}const b0=class extends z1{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this,r=t!==void 0,i=[],a=t=>i[t]??=e(n.types[t]),o;return(e,t)=>{if(e===D$)return k$;let i=(o??=nWe(n.types))(e,r);if(i.length===0)return J(new U$(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:_q(r)?x0(n,r.cause,e,t):rWe(n,r,e,t)}return S0(n,a,i,e,t)}}_rebuild(e,t,n){let r=W0(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new b0(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=X0(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(M1);if(t.length>0)return`${T0(n.isMutable)}[ ${t.map(t=>e(t)+E0(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>M1(e.type));if(t.length>0)return`{ ${t.map(t=>`${T0(t.type.context?.isMutable)}${$H(t.name)}${E0(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function x0(e,t,n,r){let i=t1(t);return i?OY(new U$(e,[i],n,r)):DY(t)}function rWe(e,t,n,r){return zX(t,t=>x0(e,t,n,r))}function S0(e,t,n,r,i){let a={ast:e,parser:t,input:r,out:void 0,successes:e.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},o=iWe(a,n);if(!o)return a.out?a.out:J(new U$(e,a.issues??[],r,i));if(_q(o))return C0(o,a);let s=!0;return bX(()=>s?(s=!1,C0(o,a)):S0(e,t,n,r,i))}function C0(e,t){return gZ(e,e=>t.out?j$(t.out)?q(t.input):t.out:J(new U$(t.ast,t.issues??[],t.input,t.options)))}const iWe=_J()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=t1(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(e.ast.types[t]),OY(new JHe(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return kY}}}),w0=new b0([new W1(`Infinity`),new W1(`-Infinity`),new W1(`NaN`)]);function T0(e){return e?``:`readonly `}function E0(e){return e?`?`:``}const D0=class extends JV{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new D0(this.run,{...this.annotations,...e},this.aborted)}abort(){return new D0(this.run,this.annotations,!0)}and(e,t){return new O0([this,e],t)}},O0=class extends JV{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new O0(this.checks,{...this.annotations,...e})}and(e,t){return new O0([this,e],t)}};function k0(e,t,n=!1){return new D0((t,n,r)=>XHe(n,e(t,n,r),t,r),t,n)}function aWe(e){return k0(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}const oWe=new F1(new b0([z0(J1,[aWe()]),w0]),new w1(h1(),f1(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function A0(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return k0(e=>(n.lastIndex=0,n.test(e)),{expected:`a string matching the RegExp ${r.source}`,representation:{id:`effect/schema/isPattern`,payload:r},toJsonSchema:()=>[{},!0],arbitraryConstraint:{patterns:[r]},...t})}const j0=new WeakMap;function M0(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&j0.set(n,N0(e)),n}function N0(e){let t=j0.get(e);if(t!==void 0)return t;if(e.encoding===void 0)return e;let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,{encoding:void 0});return j0.set(e,n),n}function P0(e,t){return e.encoding===t?e:M0(e,{encoding:t})}function F0(e,t){if(e.context===t)return e;let n=N0(e);return n.context===t&&n.encoding===e.encoding?n:M0(e,{context:t})}function I0(e){return e.encoding?I0(e.encoding[e.encoding.length-1].to):e}function L0(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return R0(e,fG(e.checks.slice(0,-1),n.annotate(t)))}return M0(e,{annotations:{...e.annotations,...t}})}function R0(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:M0(e,{checks:t})}function z0(e,t){return R0(e,c0(e.checks,t))}function B0(e,t){let n=t(e.to);return n===e.to?e:new F1(n,e.transformation)}function V0(e,t){let n=e,r=n[n.length-1],i=B0(r,t);return i===r?e:fG(e.slice(0,e.length-1),i)}function H0(e){return t=>t.encoding?P0(t,V0(t.encoding,e)):t}function sWe(e,t){return H0(e=>F0(e,t))(e)}function U0(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:P0(r,V0(r.encoding,n))}return e(r)}return rH(n)}function cWe(e,t,n){let r=new F1(e,t);return P0(n,n.encoding?[...n.encoding,r]:[r])}function W0(e,t){let n;for(let r=0;r<e.length;r++){let i=e[r],a=t(i);if(n)n[r]=a;else if(a!==i){n=Array(e.length);for(let t=0;t<r;t++)n[t]=e[t];n[r]=a}}return n??e}function G0(e,t){return F0(e,e.context?new L1(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new L1(!1,!1,void 0,t))}const K0=rH(e=>{let t=e.context?e.context.isOptional===!1?new L1(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new L1(!0,!1);return lWe(F0(e,t))}),lWe=H0(K0),uWe=nH(e=>K0(new b0([e,H1])));function dWe(e,t){return F0(e,e.context?new L1(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new L1(!1,!1,t))}function fWe(e,t,n){return cWe(e,n,t)}function pWe(e){let t=[],n=[];function r(e){t.includes(e)||t.push(e)}function i(e){switch(e._tag){case`Literal`:rFe(e.literal)&&r(e.literal);return;case`UniqueSymbol`:r(e.symbol);return;case`Enum`:for(let[,t]of e.enums)r(t);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)i(e.types[t]);return;default:n.push(e)}}return i(e),{literals:t,parameters:n}}function mWe(e,t){let{literals:n,parameters:r}=pWe(e);return new i0(n.map(e=>new e0(e,t)),r.map(e=>new r0(e,t)))}function q0(e){return e.context?.isOptional??!1}function J0(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(J0)}function hWe(e){function t(e){return J0(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return vIe(n)?n:void 0}function gWe(e){let t=!0;function n(e){return t=t&&!e.encoding&&!P1(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}const Y0=rH(e=>{let t=N0(e);if(t!==e){let n=Y0(t);return n===t&&e.encoding===void 0?e:F0(n,e.context)}let n=`recur`in e?e.recur(Y0):e;return`encodingChecks`in n&&n.encodingChecks?M0(n,{encodingChecks:void 0,checks:c0(gWe(e)?n.encodingChecks:WUe(n)||GUe(n)||j1(n)&&n.typeParameters.length>0?hWe(n.encodingChecks):void 0,n.checks)}):n}),X0=rH(e=>Y0(Z0(e)));function _We(e,t){let n=t,r=n.length,i=n[r-1],a=[new F1(Z0(P0(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new F1(Z0(n[e-1].to),n[e].transformation.flip()));let o=Z0(i.to);return o.encoding?P0(o,[...o.encoding,...a]):P0(o,a)}const Z0=nH(e=>{if(e.encoding)return _We(e,e.encoding);let t=N0(e);if(t!==e){let n=Z0(t);return n===t?e:F0(n,e.context)}return`flip`in e?e.flip(Z0):`recur`in e?e.recur(Z0):e});function Q0(e,t){let n=t===0?A$:O$(t);return(r,i)=>r===D$?k$:r===t?n:J(new V$(e,r,i))}function $0(e,t){return(n,r)=>n===D$?k$:t(n)?A$:J(new V$(e,n,r))}const e2=U0(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(e2)}}),t2=U0(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(t2)}}),n2=new globalThis.RegExp(`^${Q1}$`),vWe=new globalThis.RegExp(`^(?:${Q1}|Infinity|-Infinity|NaN)$`);function yWe(e){return A0(n2,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:n2.source}),...e})}const r2=z0(K1,[yWe()]),bWe=new F1(r2,O1),xWe=new F1(new b0([r2,w0]),O1);function i2(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=i2(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new KHe(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function a2(e){if(!j1(e))return;let t=e.annotations?.[T$];return pH(t)?t(e.typeParameters):void 0}function SWe(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function CWe(e){return e===void 0||typeof e==`string`}function o2(e,t){let n=new WeakMap,r=[];outer:for(;;){if(typeof e!=`object`||!e){if(!t(e))return!1}else{let t=e,i=n.get(t);if(i===!1)return!1;if(i===void 0){let e=Array.isArray(t);if(!e){let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null)return!1}n.set(t,!1),r.push({value:t,keys:e?t.length:Object.keys(t),index:0})}}for(;r.length>0;){let t=r[r.length-1],i=t.keys;if(typeof i==`number`){if(t.index<i){e=t.value[t.index++];continue outer}}else if(t.index<i.length){e=t.value[i[t.index++]];continue outer}n.set(t.value,!0),r.pop()}return!0}}function wWe(e){return o2(e,SWe)}const TWe=new B1([],()=>(e,t,n)=>wWe(e)?A$:J(new V$(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>s2});function EWe(e){return o2(e,CWe)}const s2=new F1(new B1([],()=>(e,t,n)=>EWe(e)?A$:J(new V$(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),D1());function c2(){return Object.assign(e=>e,{option:e=>CW(e),result:e=>aG(e),is:e=>!0})}const DWe=c2(),OWe=c2(),l2=`~effect/process/ChildProcessSpawner/ChildProcessHandle`,kWe={[l2]:l2,...iU,toJSON(){return{_id:`ChildProcessHandle`,pid:this.pid}}},u2=e=>Object.setPrototypeOf({...e},kWe),AWe=e=>{let t=(t,n)=>e(t).pipe(PX(e=>m$(n?.includeStderr===!0?e.all:NHe(e.stdout,e.stderr))),f$),n=(e,n)=>RHe(t(e,n));return d2.of({spawn:e,exitCode:t=>tZ(Y(e(t),e=>qX(e.exitCode,jX(g$(e.all),wX)))),streamString:t,streamLines:n,lines:(e,t)=>BHe(n(e,t)),string:(e,n)=>_$(t(e,n))})};var d2=class extends PW()(`effect/process/ChildProcessSpawner`){};const f2=new WeakMap,jWe=e=>{if(f2.has(e))return f2.get(e);throw Error(`Unable to get redacted value`+(e.label?` with label: "${e.label}"`:``))},p2=`~effect/Redacted`,m2=e=>yH(e,p2),h2=(e,t)=>{let n=Object.create(MWe);return t?.label&&(n.label=t.label),f2.set(n,e),n},MWe={[p2]:{_A:e=>e},label:void 0,...yU,toJSON(){return this.toString()},toString(){return`<redacted${uH(this.label)?`:`+this.label:``}>`},[xH](){return SH(f2.get(this))},[LH](e){return m2(e)&&RH(f2.get(this),f2.get(e))}},g2=jWe;var _2=class extends iK(`CommandLineError`){};const NWe=(e,t)=>{if(e.length===0)return``;let n=t?.format??`posix`;return RWe(n,e.map((e,t)=>m2(e)?`<redacted>`:qWe(LWe(n,e,t===0))))},PWe=(e,...t)=>{let n=e.findIndex(e=>e===void 0);return n===-1?QWe(e,t):oG(new _2({reason:`InvalidEscape`,message:`Template part ${n} contains an invalid escape sequence`}))},FWe=e=>m2(e)?g2(e):String(e),v2=e=>m2(e)?e:String(e),IWe=new Set(`!.{.}.and.begin.case.coproc.do.done.elif.else.end.esac.fi.for.foreach.function.if.in.nocorrect.not.or.repeat.select.switch.then.time.until.while`.split(`.`)),LWe=(e,t,n)=>{switch(e){case`posix`:return n&&IWe.has(t)?`'${t}'`:BWe(t);case`powershell`:return VWe(t);case`windows`:return n&&!t.includes(`"`)?WWe(t):UWe(t)}},RWe=(e,t)=>e===`powershell`?`& ${t.join(` `)}`:t.join(` `),zWe=/^[A-Za-z0-9_@+:,./-]+$/,BWe=e=>zWe.test(e)?e:`'${e.replace(/['\\]/g,e=>`'\\${e}'`)}'`,VWe=e=>`'${e.replace(/['\u2018\u2019\u201A\u201B]/g,`$&$&`)}'`,HWe=/[ \t\n\v"]/,UWe=e=>{if(e.length>0&&!HWe.test(e))return e;let t=`"`,n=0;for(let r of e)r===`\\`?n++:r===`"`?(t+=`\\`.repeat(n*2+1)+`"`,n=0):(t+=`\\`.repeat(n)+r,n=0);return t+`\\`.repeat(n*2)+`"`},WWe=e=>e.length>0&&!/[ \t]/.test(e)?e:`"${e}"`,GWe=/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g,KWe={"\n":`\\n`,"\r":`\\r`," ":`\\t`},qWe=e=>e.replace(GWe,e=>KWe[e]??`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`),JWe=/[A-Za-z_0-9{(@*#?$!'"-]/,YWe=/[A-Za-z_0-9{(@*#?$!-]/,XWe=/^[A-Za-z_][A-Za-z0-9_]*\+?$/,y2=e=>e===` `||e===` `||e===`
600
+ `,ZWe=(e,t,n)=>{if(`|&;<>()`.includes(e))return`The operator "${e}" needs a shell`;if(e==="`")return`Command substitution needs a shell`;if(e===`$`&&t!==void 0&&JWe.test(t))return`The expansion "$${t}" needs a shell`;if(`*?[`.includes(e))return`The glob character "${e}" needs a shell`;if(n){if(e===`#`)return`A comment needs a shell`;if(e===`~`)return`Tilde expansion needs a shell`;if(e===`=`&&t!==void 0&&!y2(t))return`A leading "=" is expanded by zsh`}},QWe=(e,t)=>{let n=[],r=[],i=!0,a=0,o,s=0,c=0,l=(e,t,n=c)=>oG(new _2({reason:e,message:`${t} in template part ${n}`})),u=()=>{if(r.length===0)return;let e=r.map(FWe).join(``);n.push(r.length===1&&m2(r[0])?r[0]:r.some(m2)?h2(e):e),r=[],i=!0,a=0},d=e=>{for(let t=0;t<e.length;t++){let d=e[t],f=e[t+1];if(o===`'`)d===`'`?o=void 0:r.push(d);else if(o===`"`){if(d===`"`)o=void 0;else if(d===`\\`&&f!==void 0&&`$\`"\\
601
+ `.includes(f))f!==`
602
+ `&&r.push(f),t++;else if(d==="`")return l(`UnsupportedSyntax`,`Command substitution needs a shell`);else if(d===`$`&&f!==void 0&&YWe.test(f))return l(`UnsupportedSyntax`,`The expansion "$${f}" needs a shell`);else r.push(d)}else if(y2(d))u();else if(d===`\\`){if(f===void 0)return l(`InvalidEscape`,`A trailing backslash escapes nothing`);f!==`
603
+ `&&(r.push(f),i=!1),t++}else if(d===`'`||d===`"`)o=d,s=c,r.push(``),i=!1;else{let e=ZWe(d,f,r.length===0);if(e!==void 0)return l(`UnsupportedSyntax`,e);if(d===`{`)a++;else if(d===`}`)a>0&&a--;else if(a>0&&(d===`,`||d===`.`&&f===`.`))return l(`UnsupportedSyntax`,`Brace expansion needs a shell`);else if(d===`=`&&n.length===0&&i&&XWe.test(r.join(``)))return l(`UnsupportedSyntax`,`A variable assignment needs a shell`);r.push(d)}}};for(;c<e.length;c++){let a=d(e[c]);if(a!==void 0)return a;if(c===t.length)break;let o=t[c];if(Array.isArray(o)){let i=e[c+1][0];if(r.length>0||(i===void 0?c+1<t.length:!y2(i)))return l(`UnsupportedSyntax`,`An interpolated array must be a separate argument`);for(let e of o)n.push(v2(e))}else r.push(v2(o)),i=!1}return o===void 0?(u(),aG(n)):l(`UnterminatedQuote`,`The quote is not closed`,s)},b2=`~effect/process/ChildProcess`,$We={...nW({label:`Command`,evaluate(e){return ZW(e.context,d2).spawn(this)}}),[b2]:b2},x2=(e,t,n)=>Object.assign(Object.create($We),{_tag:`StandardCommand`,command:e,args:t,options:n}),S2=function(...e){if(C2(e[0])){let[t,...n]=e,[r,i]=T2(t,n);return x2(r,i,{})}if(typeof e[0]==`object`&&!Array.isArray(e[0])&&!C2(e[0])){let t=e[0];return function(e,...n){if(t.shell!==void 0&&t.shell!==!1)return x2(tGe(e,n),[],t);let[r,i]=T2(e,n);return x2(r,i,t)}}if(typeof e[0]==`string`&&!Array.isArray(e[1])){let[t,n={}]=e;return x2(t,[],n)}let[t,n=[],r={}]=e;return x2(t,n,r)},C2=e=>Array.isArray(e)&&`raw`in e&&Array.isArray(e.raw),w2=e=>{let t=/^fd(\d+)$/.exec(e);if(t===null)return;let n=parseInt(t[1],10);return n>=3?n:void 0},eGe=e=>`fd${e}`,T2=(e,t)=>{let[n=``,...r]=gIe(PWe(e,...t));if(typeof n!=`string`)throw new _2({reason:`InvalidArgument`,message:`The program name of a command cannot be Redacted`});return[n,r]},tGe=(e,t)=>{if(t.length>0)throw new _2({reason:`UnsupportedSyntax`,message:`A shell template cannot interpolate values; build the script with CommandLine.quote`});let n=e[0];if(n===void 0)throw new _2({reason:`InvalidEscape`,message:`Template part 0 contains an invalid escape sequence`});return n},nGe=(e,t,n)=>{let r=e.detached??n!==`win32`;return{...t,detached:r,shell:e.shell,windowsHide:e.windowsHide??!r}},E2=(e,t)=>(n,[r])=>{let i=`Unknown`;switch(n.code){case`ENOENT`:i=`NotFound`;break;case`EACCES`:case`EPERM`:i=`PermissionDenied`;break;case`EEXIST`:i=`AlreadyExists`;break;case`EISDIR`:i=`BadResource`;break;case`ENOTDIR`:i=`BadResource`;break;case`EBUSY`:i=`Busy`;break;case`ELOOP`:i=`BadResource`}return eQ({_tag:i,module:e,method:t,pathOrDescriptor:r,syscall:n.syscall,cause:n})},D2=(e,t,n)=>{if(!(`closed`in e)){t(),n?.();return}let r=()=>{clearImmediate(a),e.off(`error`,r),e.off(`close`,r),n?.()},i=()=>{e.closed?r():(a=setImmediate(i),n||a.unref())},a=setImmediate(i);n||a.unref(),e.once(`error`,r),e.once(`close`,r),t(),e.closed||e.destroy()},O2=e=>QQ(KVe(rGe(e),e=>[e])),rGe=e=>IQ(t=>{let n=e.evaluate(),r=aGe({...e,writable:n,pull:t});return q(e.endOnDone===!1?r:aZ(r,e=>rX(e)?SX:iGe(n)))}),iGe=e=>CX(t=>{let n=()=>t(SX);if(e.closed){let t=ae(e,{readable:!1},()=>{t(),n()})}else D2(e,eH,n)}),aGe=e=>AX(t=>{let n=t.currentDispatcher,r=JJ(),i=JJ(),a=t=>nY(i,gBe(()=>e.onError(t))),o=!1,s=e=>{o=!0,a(e)};e.writable.on(`error`,s);let c=ae(e.writable,{readable:!1},e=>{e?a(e):nY(r,SX)});return e.pull.pipe(Y(t=>{let r=0;return CX(i=>{let o=!1,s=()=>n.scheduleTask(c,0),c=()=>{for(e.writable.off(`drain`,c),e.writable.off(`finish`,s);r<t.length;){if(o)return;if(!e.writable.write(t[r++],e.encoding,t=>{t&&(e.writable.closed?a(t):n.scheduleTask(()=>a(t),0))})){o||(e.writable.once(`drain`,c),e.writable.once(`finish`,s));return}}o||i(SX)};return c(),xX(()=>{o=!0,e.writable.off(`drain`,c),e.writable.off(`finish`,s)})})}),lZ({disableYield:!0}),e.endOnDone===!1?YV:nX(t=>(e.writable.end(),jX(XJ(r),zY(t)))),qX(XJ(i)),iZ(xX(()=>{c();let t=()=>{e.writable.off(`error`,s),e.writable.off(`error`,t),e.writable.off(`close`,t)};e.writable.errored&&!e.writable.closed&&!o?(e.writable.once(`error`,t),e.writable.once(`close`,t)):t()})))}),k2=e=>s$(oGe(e)),oGe=e=>IQ((t,n)=>sGe({scope:n,readable:e.evaluate(),onError:e.onError??cGe,chunkSize:e.chunkSize,readSize:e.readSize,closeOnDone:e.closeOnDone})),sGe=e=>{let t=e.readable,n=e.chunkSize??4096,r=e.closeOnDone??!0,i=e.exit??rQ(void 0),a=e.latch??hVe(!1);function o(){a.openUnsafe()}t.on(`readable`,o);let s=ae(t,{readable:!0,writable:!1},t=>{i.current??=OY(t?e.onError(t):RY()),a.openUnsafe()}),c=bX(function r(){let o=e.readable.read(e.readSize);if(o===null)return i.current?i.current:t.readableEnded?J(RY()):(a.closeUnsafe(),Y(a.await,r));let s=gG(o);for(;s.length<n&&(o=e.readable.read(e.readSize),o!==null);)s.push(o);return q(s)});return FX(sY(e.scope,xX(()=>{t.off(`readable`,o),r?D2(t,s):s()})),c)},cGe=e=>new Uze(e),A2=e=>e instanceof globalThis.Error?e:new globalThis.Error(String(e)),j2=(e,t,n)=>{let{commands:r}=B2(n),i=globalThis.process.platform===`win32`?`windows`:`posix`,a=r.map(e=>NWe([e.command,...e.args],{format:i})).join(` | `);return E2(`ChildProcess`,e)(t,[a])},M2=e=>m2(e)?g2(e):e,lGe=e=>{if(e.command.includes(`\0`))return`The command contains a NUL character`;let t=e.args.findIndex(e=>M2(e).includes(`\0`));if(t!==-1)return`Argument ${t+1} contains a NUL character`;for(let[t,n]of Object.entries(e.options.env??{}))if(n!==void 0&&M2(n).includes(`\0`))return`The environment variable ${t} contains a NUL character`},N2=1e3,P2=e=>{let t=()=>{};e.on(`error`,t),e.once(`close`,()=>e.off(`error`,t))},F2=e=>e.exitCode!==null||e.signalCode!==null,I2=(e,t)=>e.options.detached!==!1||!F2(t),L2=e=>e?.code===`EPERM`,R2=(e,t)=>{if(!F2(t))return!0;if(globalThis.process.platform===`win32`||!I2(e,t))return!1;try{return globalThis.process.kill(-t.pid,0),!0}catch(e){return L2(e)}},z2=(e,t=()=>{})=>{if(F2(e)){t(null);return}ee.execFile(`taskkill`,[`/pid`,String(e.pid),`/T`,`/F`],{windowsHide:!0},t)},uGe=xY(d2,TX(function*(){let e=yield*y$,t=yield*C$,n=X(function*(n){if(!mH(n.cwd))return yield*e.access(n.cwd),t.resolve(n.cwd)}),r=e=>{if(e.env===void 0)return;let t=e.extendEnv===!0?{...globalThis.process.env}:{};for(let[n,r]of Object.entries(e.env))r===void 0?delete t[n]:t[n]=M2(r);return t},i=e=>o$(e)?`pipe`:e,a=e=>ZQ(e)?`pipe`:e,o=e=>{let t={stream:`pipe`,encoding:`utf-8`,endOnDone:!0};return mH(e.stdin)?t:typeof e.stdin==`string`||o$(e.stdin)?{...t,stream:e.stdin}:{stream:e.stdin.stream,encoding:e.stdin.encoding??t.encoding,endOnDone:e.stdin.endOnDone??t.endOnDone}},s=(e,t)=>{let n=e[t];return mH(n)?{stream:`pipe`}:typeof n==`string`||ZQ(n)?{stream:n}:{stream:n.stream}},c=e=>{if(mH(e.additionalFds))return[];let t=[];for(let[n,r]of Object.entries(e.additionalFds)){let e=w2(n);hH(e)&&t.push({fd:e,config:r})}return t.sort((e,t)=>e.fd-t.fd)},l=(e,t,n,r)=>{let o=[i(e.stream),a(t.stream),a(n.stream)];if(r.length===0)return o;let s=r.reduce((e,{fd:t})=>Math.max(e,t),2);for(let e=3;e<=s;e++)o[e]=`ignore`;for(let{fd:e}of r)o[e]=`pipe`;return o},u=(e,t,n)=>fZ(h$(LHe(e,e=>QJ(n,e)),t)),d=X(function*(e,t,n,r){if(n.length===0)return{getInputFd:()=>e$,getOutputFd:()=>u$};let i=new Map,a=new Map,o=(t,n,a)=>bX(()=>{let o=e$;return n&&`write`in n&&(P2(n),o=O2({evaluate:()=>n,onError:n=>j2(`fromWritable(fd${t})`,A2(n),e)})),a?PX(u(a,o,r),()=>{i.set(t,o)}):(i.set(t,o),SX)}),s=(t,n,r)=>{let i=u$;if(n&&`read`in n){let r=new ie,a;r.on(`error`,e=>{a??=e}),n.on(`error`,e=>r.destroy(e)),n.pipe(r);let o=n=>j2(`fromReadable(fd${t})`,A2(n),e);i=EHe(()=>a===void 0?k2({evaluate:()=>r,onError:o}):OHe(o(a)))}r&&(i=p$(i,r)),a.set(t,i)};for(let{config:e,fd:r}of n){let n=t.stdio[r];switch(e.type){case`input`:yield*o(r,n,e.stream);break;case`output`:s(r,n,e.sink);break;case`duplex`:n&&`allowHalfOpen`in n&&(n.allowHalfOpen=!0),s(r,n,e.sink),yield*o(r,n,e.stream)}}return{getInputFd:e=>i.get(e)??e$,getOutputFd:e=>a.get(e)??u$}}),f=(e,t,n,r)=>bX(()=>{let i=e$;return gH(t.stdin)&&(P2(t.stdin),i=O2({evaluate:()=>t.stdin,onError:t=>j2(`fromWritable(stdin)`,A2(t),e),endOnDone:n.endOnDone,encoding:n.encoding})),o$(n.stream)?FX(u(n.stream,i,r),i):q(i)}),p=(e,t,n,r)=>{let i=t.stdout?(()=>{let n=new ie;return t.stdout.on(`error`,e=>n.destroy(e)),t.stdout.pipe(n),k2({evaluate:()=>n,onError:t=>j2(`fromReadable(stdout)`,A2(t),e)})})():u$,a=t.stderr?(()=>{let n=new ie;return t.stderr.on(`error`,e=>n.destroy(e)),t.stderr.pipe(n),k2({evaluate:()=>n,onError:t=>j2(`fromReadable(stderr)`,A2(t),e)})})():u$;ZQ(n.stream)&&(i=p$(i,n.stream)),ZQ(r.stream)&&(a=p$(a,r.stream));let o=PHe(i,a);return{stdout:i,stderr:a,all:o}},m=(e,t)=>CX(n=>{let r=JJ(),i=ee.spawn(e.command,e.args.map(M2),t);return i.on(`error`,t=>{e.args.some(m2)&&Object.assign(t,{spawnargs:[e.command,...e.args.map(e=>m2(e)?`<redacted>`:e)]}),n(J(j2(`spawn`,t,e)))}),i.on(`exit`,(...e)=>{nY(r,EY(e))}),i.on(`spawn`,()=>{n(q([i,r]))}),xX(()=>{i.kill(`SIGTERM`)})}),h=(e,t,n)=>globalThis.process.platform===`win32`?CX(n=>{z2(t,t=>{n(t?J(j2(`kill`,A2(t),e)):SX)})}):kX({try:()=>{globalThis.process.kill(-t.pid,n)},catch:t=>j2(`kill`,A2(t),e)}),g=(e,t)=>{if(globalThis.process.platform===`win32`){z2(e);return}try{globalThis.process.kill(-e.pid,t)}catch{}},_=(e,t,n)=>bX(()=>{if(!t.kill(n)){let t=new globalThis.Error(`Failed to kill child process`);return J(j2(`kill`,t,e))}return SX}),v=(e,t,n)=>CX(r=>{let i=Date.now()+n,a,o=()=>{clearTimeout(a),t.removeListener(`exit`,s)},s=()=>{if(clearTimeout(a),Date.now()>=i||!R2(e,t)){o(),r(SX);return}a=setTimeout(s,10)};return t.on(`exit`,s),s(),xX(o)}),y=X(function*(e,t,n,r){let i=n=>I2(e,t)?h(e,t,n).pipe(LX(r=>F2(t)&&L2(r.cause)?SX:_(e,t,n))):_(e,t,n);yield*i(r?.killSignal??`SIGTERM`),mH(r?.forceKillAfter)?(yield*XJ(n),yield*v(e,t,N2)):(yield*v(e,t,XG(r.forceKillAfter)),R2(e,t)&&(yield*i(`SIGKILL`),yield*v(e,t,N2))),yield*XJ(n)}),b=(e,t)=>{let n=t??`stdout`;switch(n){case`stdout`:return e.stdout;case`stderr`:return e.stderr;case`all`:return e.all;default:{let t=w2(n);return hH(t)?e.getOutputFd(t):e.stdout}}},x=X(function*(e){switch(e._tag){case`StandardCommand`:{if(e.options.shell!==void 0&&e.options.shell!==!1&&e.args.length>0)return yield*J(tQ({module:`ChildProcess`,method:`spawn`,description:`The shell option cannot be combined with arguments; pass the whole script as the command`}));let t=lGe(e);if(t!==void 0)return yield*J(tQ({module:`ChildProcess`,method:`spawn`,description:t}));let i=o(e.options),a=s(e.options,`stdout`),u=s(e.options,`stderr`),h=c(e.options),_=!0,v=yield*n(e.options),b=r(e.options),ee=l(i,a,u,h),x=X(function*(t,n){if(yield*$J(n)){let[r]=yield*XJ(n);(r!==0&&gH(r)||_&&process.platform!==`win32`&&e.options.detached!==!1)&&(yield*GX(y(e,t,n,e.options)));return}_&&(yield*GX(y(e,t,n,e.options)))}),te=iY(),[ne,re]=yield*nZ(m(e,nGe(e.options,{cwd:v,env:b,stdio:ee},process.platform)),([e,t],n)=>_X([uY(te,n),x(e,t)],{concurrency:`unbounded`,discard:!0})),ie=OWe(ne.pid);e.options.detached!==!1&&ne.on(`exit`,t=>{t!==0&&gH(t)&&g(ne,e.options.killSignal??`SIGTERM`)});let ae=xX(()=>{_||=(ne.ref(),!0)}),S=xX(()=>(_&&=(ne.unref(),!1),ae)),oe=JJ(),C=yield*aY(te)(f(e,ne,i,oe)),{all:se,stderr:ce,stdout:le}=p(e,ne,a,u),{getInputFd:ue,getOutputFd:w}=yield*aY(te)(d(e,ne,h,oe)),de=PX($J(re),e=>!e),fe=Y(qX(XJ(re),XJ(oe)),([t,n])=>{if(eY(oe))return XJ(oe);if(gH(t))return q(DWe(t));let r=new globalThis.Error(`Process interrupted due to receipt of signal: '${n}'`);return J(j2(`exitCode`,r,e))});return u2({pid:ie,exitCode:fe,isRunning:de,kill:t=>y(e,ne,re,t),stdin:C,stdout:le,stderr:ce,all:se,getInputFd:ue,getOutputFd:w,unref:S})}case`PipedCommand`:{let{commands:t,pipeOptions:n}=B2(e),[r,...i]=t,a=[yield*x(r)];for(let e=0;e<i.length;e++){let t=i[e],r=n[e]??{},s=o(t.options),c=f$(q(b(a[a.length-1],r.from))),l=r.to??`stdin`;if(l===`stdin`)a.push(yield*x(S2(t.command,t.args,{...t.options,stdin:{...s,stream:c}})));else{let e=w2(l);if(hH(e)){let n=eGe(e),r=t.options.additionalFds??{},i=r[n],o=i?.type===`duplex`?{...i,stream:c}:{type:`input`,stream:c};a.push(yield*x(S2(t.command,t.args,{...t.options,additionalFds:{...r,[n]:o}})))}else a.push(yield*x(S2(t.command,t.args,{...t.options,stdin:{...s,stream:c}})))}}let s=a[a.length-1],c=e=>vX([...a].reverse(),t=>GX(t.kill(e)),{discard:!0}),l=TX(function*(){let e=[];for(let t of a)e.push(yield*t.unref);return vX([...e].reverse(),e=>e,{discard:!0})});return u2({pid:s.pid,exitCode:s.exitCode,isRunning:s.isRunning,kill:c,stdin:a[0].stdin,stdout:s.stdout,stderr:s.stderr,all:s.all,getInputFd:s.getInputFd,getOutputFd:s.getOutputFd,unref:l})}}});return AWe(x)})),B2=e=>{let t=[],n=[],r=e=>{switch(e._tag){case`StandardCommand`:t.push(e);break;case`PipedCommand`:r(e.left),n.push(e.options),r(e.right)}};if(r(e),t.length===0)throw Error(`flattenCommand produced empty commands array`);let[i,...a]=t;return{commands:[i,...a],pipeOptions:n}},V2=e=>t=>tQ({module:`FileSystem`,method:e,description:t.message??String(t)}),H2=(e,t)=>{let n=Number(e);if(!Number.isSafeInteger(n))throw RangeError(`${t} exceeds the safe integer range: ${e}`);return n},U2=e=>jW(OW(e),BBe),W2=e=>BigInt.asUintN(64,e),G2=e=>nIe(OW(e),W2),K2=(e,t)=>kX({try:()=>H2(e,`position`),catch:V2(t)}),dGe=(()=>{let e=hZ(S.access,E2(`FileSystem`,`access`),V2(`access`));return(t,n)=>{let r=S.constants.F_OK;return n?.readable&&(r|=S.constants.R_OK),n?.writable&&(r|=S.constants.W_OK),e(t,r)}})(),fGe=(()=>{let e=hZ(S.cp,E2(`FileSystem`,`copy`),V2(`copy`));return(t,n,r)=>e(t,n,{force:r?.overwrite??!1,preserveTimestamps:r?.preserveTimestamps??!1,recursive:!0})})(),pGe=(()=>{let e=hZ(S.copyFile,E2(`FileSystem`,`copyFile`),V2(`copyFile`));return(t,n)=>e(t,n)})(),mGe=(()=>{let e=hZ(S.chmod,E2(`FileSystem`,`chmod`),V2(`chmod`));return(t,n)=>e(t,n)})(),hGe=(()=>{let e=hZ(S.chown,E2(`FileSystem`,`chown`),V2(`chown`));return(t,n,r)=>e(t,n,r)})(),gGe=(()=>{let e=hZ(S.link,E2(`FileSystem`,`link`),V2(`link`));return(t,n)=>e(t,n)})(),_Ge=(()=>{let e=hZ(S.mkdir,E2(`FileSystem`,`makeDirectory`),V2(`makeDirectory`));return(t,n)=>e(t,{recursive:n?.recursive??!1,mode:n?.mode})})(),q2=e=>{let n=hZ(S.mkdtemp,E2(`FileSystem`,e),V2(e));return e=>bX(()=>{let r=e?.prefix??``,i=typeof e?.directory==`string`?a.join(e.directory,`.`):t.tmpdir();return n(r?a.join(i,r):i+`/`)})},vGe=q2(`makeTempDirectory`),J2=e=>{let t=hZ(S.rm,E2(`FileSystem`,e),V2(e));return(e,n)=>t(e,{recursive:n?.recursive??!1,force:n?.force??!1})},yGe=J2(`remove`),bGe=(()=>{let e=q2(`makeTempDirectoryScoped`),t=J2(`makeTempDirectoryScoped`);return n=>nZ(e(n),e=>UX(t(e,{recursive:!0,force:!0})))})(),xGe=e=>{let{O_APPEND:t,O_CREAT:n,O_EXCL:r,O_RDONLY:i,O_RDWR:a,O_TRUNC:o,O_WRONLY:s}=S.constants;switch(e){case`r`:return i;case`r+`:return a;case`w`:return o|n|s;case`wx`:return o|n|s|r;case`w+`:return o|n|a;case`wx+`:return o|n|a|r;case`a`:return t|n|s;case`ax`:return t|n|s|r;case`a+`:return t|n|a;case`ax+`:return t|n|a|r}},SGe=(e,t)=>bX(()=>{let{O_NOFOLLOW:n}=S.constants;return process.platform===`win32`||typeof n!=`number`||n===0?J(tQ({module:`FileSystem`,method:e,description:`noFollow is not supported on this platform`})):q(xGe(t)|n)}),CGe=(e=>{let t=hZ(S.open,E2(`FileSystem`,e),V2(e)),n=hZ(S.close,E2(`FileSystem`,e),V2(e));return(r,i)=>tH(nZ(i?.noFollow===!0?Y(SGe(e,i.flag??`r`),e=>t(r,e,i.mode)):t(r,i?.flag??`r`,i?.mode),e=>UX(n(e))),PX(e=>wGe(e,i?.flag?.startsWith(`a`)??!1)))})(`open`),Y2=e=>tQ({module:`FileSystem`,method:e,description:`Cannot read before the start of the file`}),wGe=(()=>{let e=e=>hZ(S.read,E2(`FileSystem`,e),V2(e)),t=e(`read`),n=e(`readAlloc`),r=hZ(S.fstat,E2(`FileSystem`,`stat`),V2(`stat`)),i=hZ(S.ftruncate,E2(`FileSystem`,`truncate`),V2(`truncate`)),a=hZ(S.fsync,E2(`FileSystem`,`sync`),V2(`sync`)),o=e=>{let t=hZ(S.write,E2(`FileSystem`,e),V2(e));return(e,n,r)=>t(e,n,0,n.length,r)},s=o(`write`),c=o(`writeAll`);class l{[b$];fd;append;position=BigInt(0);constructor(e,t){this[b$]=b$,this.fd=e,this.append=t}get stat(){return Y(r(this.fd,{bigint:!0}),Q2)}get sync(){return a(this.fd)}seek(e,t){return bX(()=>{let n=t===`start`?e:this.position+e;return n<BigInt(0)?J(tQ({module:`FileSystem`,method:`seek`,description:`Cannot seek before the start of the file`})):(this.position=n,q(n))})}read(e,n){return bX(()=>{let r=n?.position;if(r!==void 0)return r<BigInt(0)?J(Y2(`read`)):t(this.fd,{buffer:e,position:r});let i=this.position;return PX(t(this.fd,{buffer:e,position:i}),e=>(this.position=i+BigInt(e),e))})}readAlloc(e,t){return bX(()=>{try{if(!Number.isInteger(e)||e<0)throw RangeError(`size must be a non-negative integer`);let r=t?.position;if(r!==void 0&&r<BigInt(0))return J(Y2(`readAlloc`));let i=Buffer.allocUnsafeSlow(e),a=r??this.position;return PX(n(this.fd,{buffer:i,position:a}),t=>{if(t===0)return G();if(r===void 0&&(this.position=a+BigInt(t)),t===e)return CW(i);let n=Buffer.allocUnsafeSlow(t);return i.copy(n,0,0,t),CW(n)})}catch(e){return J(V2(`readAlloc`)(e))}})}truncate(e){return PX(i(this.fd,e||void 0),()=>{if(!this.append){let t=BigInt(e??0);this.position>t&&(this.position=t)}})}write(e){return bX(()=>{let t=this.position;return Y(this.append?q(void 0):K2(t,`write`),n=>PX(s(this.fd,e,n),e=>(this.append||(this.position=t+BigInt(e)),e)))})}writeAllChunk(e){return bX(()=>{let t=this.position;return Y(this.append?q(void 0):K2(t,`writeAll`),n=>Y(c(this.fd,e,n),n=>n===0?J(eQ({module:`FileSystem`,method:`writeAll`,_tag:`WriteZero`,pathOrDescriptor:this.fd,description:`write returned 0 bytes written`})):(this.append||(this.position=t+BigInt(n)),n<e.length?this.writeAllChunk(e.subarray(n)):SX)))})}writeAll(e){return e.length===0?SX:this.writeAllChunk(e)}}return(e,t)=>new l(e,t)})(),X2=e=>{let t=q2(e);return X(function*(e){let n=yield*t(e),r=_.randomBytes(6).toString(`hex`),i=a.join(n,e?.suffix?`${r}${e.suffix}`:r);return yield*t4(i,new Uint8Array),i})},TGe=X2(`makeTempFile`),EGe=(()=>{let e=X2(`makeTempFileScoped`),t=J2(`makeTempFileScoped`);return n=>nZ(e(n),e=>UX(t(a.dirname(e),{recursive:!0,force:!0})))})(),DGe=(e,t)=>yX({try:()=>S.promises.readdir(e,t),catch:t=>E2(`FileSystem`,`readDirectory`)(t,[e])}),OGe=e=>yX({try:()=>S.promises.readdir(e,{withFileTypes:!0}),catch:t=>E2(`FileSystem`,`readDirectoryEntries`)(t,[e])}).pipe(PX(e=>e.map(e=>({name:e.name,type:Z2(e)})))),kGe=e=>CX((t,n)=>{try{S.readFile(e,{signal:n},(n,r)=>{t(n?J(E2(`FileSystem`,`readFile`)(n,[e])):q(r))})}catch(e){t(J(V2(`readFile`)(e)))}}),AGe=(()=>{let e=hZ(S.readlink,E2(`FileSystem`,`readLink`),V2(`readLink`));return t=>e(t)})(),jGe=(()=>{let e=hZ(process.platform===`win32`?S.realpath.native:S.realpath,E2(`FileSystem`,`realPath`),V2(`realPath`));return t=>e(t)})(),MGe=(()=>{let e=hZ(S.rename,E2(`FileSystem`,`rename`),V2(`rename`));return(t,n)=>e(t,n)})(),Z2=e=>e.isFile()?`File`:e.isDirectory()?`Directory`:e.isSymbolicLink()?`SymbolicLink`:e.isBlockDevice()?`BlockDevice`:e.isCharacterDevice()?`CharacterDevice`:e.isFIFO()?`FIFO`:e.isSocket()?`Socket`:`Unknown`,Q2=(e,t=`stat`)=>kX({try:()=>({type:Z2(e),mtime:OW(e.mtime),atime:OW(e.atime),birthtime:OW(e.birthtime),dev:W2(e.dev),rdev:G2(e.rdev),ino:G2(e.ino),mode:H2(e.mode,`mode`),nlink:G2(e.nlink),uid:U2(e.uid),gid:U2(e.gid),size:EZ(e.size),blksize:e.blksize===void 0?G():CW(EZ(e.blksize)),blocks:OW(e.blocks)}),catch:V2(t)}),$2=(e,t)=>{let n=hZ(t,E2(`FileSystem`,e),V2(e));return t=>Y(n(t,{bigint:!0}),t=>Q2(t,e))},e4=$2(`stat`,S.stat),NGe=$2(`lstat`,S.lstat),PGe=(()=>{let e=hZ(S.symlink,E2(`FileSystem`,`symlink`),V2(`symlink`));return(t,n)=>e(t,n)})(),FGe=(()=>{let e=hZ(S.truncate,E2(`FileSystem`,`truncate`),V2(`truncate`));return(t,n)=>e(t,n)})(),IGe=(()=>{let e=hZ(S.utimes,E2(`FileSystem`,`utime`),V2(`utime`));return(t,n,r)=>e(t,n,r)})(),LGe=(e,t,n)=>THe(r=>nZ(xX(()=>{let i=t.type===`Directory`?e:a.dirname(e),o=S.watch(e,{recursive:n?.recursive??!1},(e,t)=>{if(t)switch(e){case`rename`:FBe(TBe(e4(a.resolve(i,t)),{onSuccess:e=>fQ(r,{_tag:`Create`,path:t}),onFailure:e=>fQ(r,{_tag:`Remove`,path:t})}));return;case`change`:pQ(r,{_tag:`Update`,path:t});return}});return o.on(`error`,t=>{hQ(r,Rze(eQ({module:`FileSystem`,_tag:`Unknown`,method:`watch`,pathOrDescriptor:e,cause:t})))}),o.on(`close`,()=>{gQ(r)}),o}),e=>xX(()=>e.close())).pipe(MX(()=>xX(()=>n?.onReady?.())))),RGe=(e,t,n)=>_X([e4(t),QX(x$)]).pipe(PX(([r,i])=>eIe(i,()=>e).pipe(jW(e=>e.register(t,r,n)),DW(()=>LGe(t,r,n)))),f$),t4=(e,t,n)=>CX((r,i)=>{try{S.writeFile(e,t,{signal:i,flag:n?.flag,mode:n?.mode},t=>{r(t?J(E2(`FileSystem`,`writeFile`)(t,[e])):SX)})}catch(e){r(J(V2(`writeFile`)(e)))}}),zGe=PX(QX(x$),e=>HHe({access:dGe,chmod:mGe,chown:hGe,copy:fGe,copyFile:pGe,link:gGe,lstat:NGe,makeDirectory:_Ge,makeTempDirectory:vGe,makeTempDirectoryScoped:bGe,makeTempFile:TGe,makeTempFileScoped:EGe,open:CGe,readDirectory:DGe,readDirectoryEntries:OGe,readFile:kGe,readLink:AGe,realPath:jGe,remove:yGe,rename:MGe,stat:e4,symlink:PGe,truncate:FGe,utimes:IGe,watch(t,n){return RGe(e,t,n)},writeFile:t4})),BGe=xY(y$)(zGe),n4=e=>({fromFileUrl:t=>kX({try:()=>m.fileURLToPath(t,{windows:e}),catch:e=>new QZ({module:`Path`,method:`fromFileUrl`,cause:e})}),toFileUrl:t=>kX({try:()=>m.pathToFileURL(t,{windows:e}),catch:e=>new QZ({module:`Path`,method:`toFileUrl`,cause:e})})});({...a.posix,...n4(!1)}),{...a.win32,...n4(!0)};const VGe=yY(C$)(UHe({...a,...n4(void 0)})),r4=`~effect/Stdio`,HGe=yY(PW(r4),(e=>({[r4]:r4,stdinIsTerminal:q(!1),stdoutIsTerminal:q(!1),stderrIsTerminal:q(!1),...e}))({args:xX(()=>process.argv.slice(2)),stdinIsTerminal:xX(()=>process.stdin.isTTY===!0),stdoutIsTerminal:xX(()=>process.stdout.isTTY===!0),stderrIsTerminal:xX(()=>process.stderr.isTTY===!0),stdout:e=>O2({evaluate:()=>process.stdout,onError:e=>eQ({module:`Stdio`,method:`stdout`,_tag:`Unknown`,cause:e}),endOnDone:e?.endOnDone??!1}),stderr:e=>O2({evaluate:()=>process.stderr,onError:e=>eQ({module:`Stdio`,method:`stderr`,_tag:`Unknown`,cause:e}),endOnDone:e?.endOnDone??!1}),stdin:k2({evaluate:()=>process.stdin,onError:e=>eQ({module:`Stdio`,method:`stdin`,_tag:`Unknown`,cause:e}),closeOnDone:!1})}));({...iU}),{...iU},iU.toString,iU[nU],{...yU};const i4=(e,t,n)=>j$(e)?n(t):gZ(e,n);function a4(e){let t=UGe(e);return(e,n,r)=>{try{return t(e,n,r)}catch(e){return OX(e)}}}function UGe(e){if(e._tag===`Middleware`)return(t,n,r)=>{let i=j$(t)?e.decode(O$(M$(n)),r):e.decode(LBe(t,M$),r);return o4(i)};let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>j$(e)?O$(t):e;case`Transform`:{let e=e=>e===D$?k$:O$(t.transform(e));return(t,n)=>i4(t,n,e)}case`TransformOptional`:{let e=e=>N$(t.transform(M$(e)));return(t,n)=>i4(t,n,e)}case`TransformEffect`:return(e,n,r)=>i4(e,n,e=>e===D$?k$:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>i4(e,n,e=>o4(t.transform(M$(e),r)))}}const o4=e=>gZ(e,N$),s4=(e,t,n,r)=>zX(r,r=>DX(()=>FY(r,r=>new qHe(e,r,t,n))));function WGe(e,t){let n=a4(e.link.transformation),r;return(i,a)=>{if(i===D$)return k$;if(e.isConstructed(i))return A$;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function GGe(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==D$&&r!==void 0)return t(r,i);let a=n;if(_q(a)&&a._tag===`Success`){let e=t(a[pU],i);return j$(e)?a:e}return gZ(s4(e,r,i,a),e=>{let n=t(e,i);return j$(n)?O$(e):n})}}function KGe(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:GGe(e,n)}function c4(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?a2(e):void 0,o=a?WGe(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>a4(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);try{if(u&&!n.disableChecks){if(_q(r)){if(r._tag===`Success`){let i=j$(r)?t:r[pU];if(t!==D$&&i!==D$){let i=i2(u,t,void 0,e,n);i&&(r=J(new B$(e,i,t,n)))}}}else r=Y(r,r=>{if(t!==D$&&r!==D$){let r=i2(u,t,void 0,e,n);if(r)return J(new B$(e,r,t,n))}return q(r)})}if(s&&!n.disableChecks){if(_q(r)){if(r._tag===`Success`){let i=j$(r)?t:r[pU];if(i===D$)return r;let a=i2(s,i,void 0,e,n);a&&(r=J(new B$(e,a,i,n)))}}else r=Y(r,t=>{if(t!==D$){let r=i2(s,t,void 0,e,n);if(r)return J(new B$(e,r,t,n))}return q(t)})}return r}catch(e){return OX(e)}},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[pU],o=t(a,r)):o=gZ(o,e=>{let n=t(e,r);return j$(n)?O$(e):n})}if(o._tag===`Success`){let e=o[pU],t=p(e,r);return j$(t)?o:t}return o=s4(e,n,r,o),gZ(o,e=>{let t=p(e,r);return j$(t)?O$(e):t})}:p}const qGe=Symbol(),l4=new WeakMap,JGe=e=>d4(e).parser,u4=e=>d4(e).makeEffect,YGe=e=>KGe(e,u4);var XGe=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=c4(this.ast,JGe)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=c4(this.ast,u4,YGe)}};function d4(e){let t=l4.get(e);if(t!==void 0)return t;let n=new XGe(e);return l4.set(e,n),n}function f4(e){let t=e.ast,n;return(e,r)=>(n??=_4(lKe,Y0(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function p4(e){let t=f4(e);return(e,n)=>{let r=mZ(t(e,n));return AY(r)?CW(r.value):(n1(r.cause,`Option adapter can only return none for schema issues`),G())}}function ZGe(e){return oKe(Y0(e.ast))}function QGe(e){return eKe(e.ast)}function $Ge(e){{let t=iKe(g4(e));return e=>{let n=t(e,I1);return AY(n)?!0:(n1(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function eKe(e){let t=Y0(e),n=e=>(n=$Ge(t),n(e));return e=>n(e)}function tKe(e,t){let n=g4(e.ast);return t===void 0?n:(e,r)=>n(e,m4(t,r))}function nKe(e,t){let n=g4(Z0(e.ast));return t===void 0?n:(e,r)=>n(e,m4(t,r))}const m4=(e,t)=>t?{...e,...t}:e,h4=e=>e===D$?J(new H$):q(e);function g4(e){return _4(cKe,e)}function rKe(e,t){return j$(e)?q(t):_q(e)?e[pU]===D$?h4(D$):e:gZ(e,h4)}function _4(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??I1);return j$(a)?q(r):_q(a)?a[pU]===D$?h4(D$):a:gZ(a,h4)}}function iKe(e){return(t,n)=>mZ(e(t,n))}function aKe(e,t){let n=mZ(e);if(AY(n))return n.value;let r=n1(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}const v4=`Constructor adapter can only throw schema issues`;function y4(e){throw Error(v4,{cause:zze(e)})}function oKe(e){let t;return(n,r)=>b4(t??=d4(e),n,r)}function b4(e,t,n){let r=n?.disableChecks?n.parseOptions?{...n.parseOptions,disableChecks:!0}:{disableChecks:!0}:n?.parseOptions??I1,i=e.make;if(i!==void 0&&t!==D$){let e;try{e=i(t,r)}catch(e){y4(e)}if(e!==qGe&&e!==D$)return e}return aKe(rKe(e.makeEffect(t,r),t),v4)}function sKe(e,t,n,r){let i=d4(e),a=a2(e);if(a===void 0||i.make!==void 0||i.compiledMakeEffect!==void 0)return b4(i,t,n);if(a.isConstructed(t))return t;let o=b4((i.resolve??d4)(a.link.to),t,n);try{return r(o)}catch(e){y4(e)}}const cKe=e=>d4(e).parser,lKe=e=>d4(e).makeEffect,x4=`~effect/Schema/Schema`,S4=Symbol(),uKe={[x4]:x4,get make(){let e=ZGe(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=f4(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=p4(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return KV(this,arguments)},annotate(e){return this.rebuild(L0(this.ast,e))},annotateKey(e){return this.rebuild(G0(this.ast,e))},check(...e){return this.rebuild(z0(this.ast,e))},rebuild(e){return C4(e,this[S4])}};function C4(e,t){function n(){}let r=Object.setPrototypeOf(n,uKe);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r[S4]=t,r.ast=e,r}function dKe(e,t){let n=nH(t=>{let n=F0(t,void 0),i=e(n,r);return i===n?null:i}),r=U0(e=>{let t=n(N0(e));if(t===null)return e;let r=F0(t,e.context);return e.context===void 0?r:sWe(r,fKe(e.context))},t);return r}function fKe(e){return e.constructorDefault===void 0?e:new L1(e.isOptional,e.isMutable,void 0,e.annotations)}function pKe(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function mKe(e){return t=>{let n=[...t].sort((t,n)=>e(X0(t))-e(X0(n)));return n.some((e,n)=>e!==t[n])?n:t}}function hKe(e){return C4(xKe(e.ast),{schema:e})}const gKe=mKe(e=>{switch(e._tag){case`Null`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function _Ke(e,t,n){switch(e._tag){case`Declaration`:{let r=e.typeParameters.map(e=>C4(t(X0(e)))),i=e.annotations?.toCodecStringTree;if(pH(i)){let n=i(r);return n===void 0?e:P0(e,[B0(n,t)])}let a=e.annotations?.toCodecJson,o=pH(a)?a(r):void 0,s=o===void 0?e.annotations?.toCodec:void 0,c=o??(pH(s)?s(r):void 0);return c===void 0?n(e):P0(e,[B0(c,t)])}case`Null`:return P0(e,[vKe]);case`Boolean`:return P0(e,[yKe]);case`Unknown`:case`ObjectKeyword`:return P0(e,[s2]);case`Enum`:case`Number`:case`Literal`:case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return pKe(e),e.recur(t,t2);case`Union`:{let n=gKe(e.types);return n===e.types?e.recur(t):new b0(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}const vKe=new F1(new W1(`null`),new w1(f1(()=>null),f1(()=>`null`))),yKe=new F1(new b0([new W1(`true`),new W1(`false`)]),new w1(f1(e=>e===`true`),m1())),bKe=new w1(f1(e=>typeof e==`string`?[e]:e),d1()),xKe=dKe((e,t)=>_Ke(e,t,e=>{throw new globalThis.Error(`Missing structural codec for StringTree`,{cause:e})}),{stopAt:e=>e.transformation===bKe}),w4=e=>e,T4=`~effect/Schema/SchemaError`;function SKe(e){return yH(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}({...iU}),{...iU},{...iU},{...iU},{...iU},{...iU},{...iU},{...iU};const E4=`~effect/SemVer`,D4=`~effect/SemVer/SemVerError`;var O4=class extends iK(`SemVerError`){[D4]=D4};const CKe=e=>yH(e,D4),k4=e=>{throw new O4({message:e})},wKe=e=>fIe({try:e,catch:e=>{if(!CKe(e))throw e;return e}}),TKe=(e,t,n)=>mIe(wKe(()=>n(t)),n=>new O4({message:`Invalid ${e} ${JSON.stringify(t)}: ${n.message}`,input:t})),EKe=/^(?:0|[1-9]\d*)$/,DKe=/^\d+$/,A4=/^[0-9A-Za-z-]+$/,j4=(e,t)=>!Number.isSafeInteger(e)||e<0?k4(`${t} must be a non-negative safe integer, received ${e}`):e,M4=(e,t)=>EKe.test(e)?j4(Number(e),t):k4(`${t} must be a non-negative integer without leading zeros, received ${JSON.stringify(e)}`),N4=e=>typeof e==`number`?j4(e,`numeric pre-release identifier`):A4.test(e)?DKe.test(e)?M4(e,`numeric pre-release identifier`):e:k4(`pre-release identifier must be non-empty [0-9A-Za-z-], received ${JSON.stringify(e)}`),P4=e=>A4.test(e)?e:k4(`build identifier must be non-empty [0-9A-Za-z-], received ${JSON.stringify(e)}`),OKe=(e,t)=>{if(e.length===0)return t.length===0?0:1;if(t.length===0)return-1;let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e[r],i=t[r];if(n!==i)return typeof n==`number`?typeof i==`number`?yW(n,i):-1:typeof i==`number`?1:vW(n,i)}return yW(e.length,t.length)},kKe=(e,t)=>yW(e.major,t.major)||yW(e.minor,t.minor)||yW(e.patch,t.patch)||OKe(e.prerelease,t.prerelease),AKe={[E4]:E4,[LH](e){return jKe(e)&&IKe(this,e)},[xH](){return kH(I4(this))},toString(){return`SemVer(${I4(this)})`},toJSON(){return{_id:`SemVer`,value:I4(this)}},[nU](){return this.toJSON()},pipe(){return KV(this,arguments)}},F4=(e,t,n,r,i)=>{let a=Object.create(AKe);return a.major=e,a.minor=t,a.patch=n,a.prerelease=r,a.build=i,a},jKe=e=>yH(e,E4),MKe=e=>F4(j4(e.major,`major`),j4(e.minor,`minor`),j4(e.patch,`patch`),e.prerelease?.map(N4)??[],e.build?.map(P4)??[]),NKe=e=>{let t=e,n=[],r=t.indexOf(`+`);r!==-1&&(n=t.slice(r+1).split(`.`).map(P4),t=t.slice(0,r));let i=[],a=t.indexOf(`-`);a!==-1&&(i=t.slice(a+1).split(`.`).map(N4),t=t.slice(0,a));let o=t.split(`.`);return o.length===3?F4(M4(o[0],`major`),M4(o[1],`minor`),M4(o[2],`patch`),i,n):k4(`expected MAJOR.MINOR.PATCH`)},PKe=e=>TKe(`SemVer`,e,NKe),I4=e=>{let t=`${e.major}.${e.minor}.${e.patch}`;return e.prerelease.length>0&&(t+=`-${e.prerelease.join(`.`)}`),e.build.length>0&&(t+=`+${e.build.join(`.`)}`),t},FKe=_W(kKe),L4=VFe(BFe()),IKe=rW((e,t)=>e.major===t.major&&e.minor===t.minor&&e.patch===t.patch&&L4(e.prerelease,t.prerelease)&&L4(e.build,t.build)),LKe=xW(FKe),R4=x4;function RKe(){return(e,t,n)=>W4(new B1(e.map(u0),e=>t(e.map(e=>W4(e))),n))}function zKe(e,t){return RKe()([],()=>(t,n,r)=>e(t)?q(t):J(new V$(n,t,r)),t)}var z4=class extends iK(`SchemaError`){[T4]=T4;constructor(e){let t=aU();oU(0);try{super({issue:e})}finally{oU(t)}}get message(){return $He(this.issue)}toJSON(){return{_tag:this._tag,message:this.message}}[nU](){return this.toJSON()}toString(){return`SchemaError(${this.message})`}};function BKe(e){return SKe(e)}function B4(e){return _q(e)?VKe(e):zX(e,e=>DX(()=>FY(e,e=>new z4(e))))}function VKe(e){return AY(e)?e:DY(FY(e.cause,e=>new z4(e)))}function HKe(e,t){let n;for(let r of e.reasons){if(!MY(r)||!BKe(r.error))throw new globalThis.Error(t,{cause:e});n??=r.error}if(n===void 0)throw new globalThis.Error(t,{cause:e});return n}function UKe(e){let t=mZ(e);if(AY(t))return t.value;throw HKe(t.cause,`Sync adapter can only throw schema errors`)}const V4=QGe;function H4(e,t){let n=tKe(e,t);return(e,t)=>B4(n(e,t))}function U4(e,t){let n=H4(e,t);return(e,t)=>UKe(n(e,t))}function WKe(e,t){let n=nKe(e,t);return(e,t)=>B4(n(e,t))}const W4=C4;function GKe(e){return yH(e,R4)&&e[R4]===R4}const G4=w4(e=>W4(K0(e.ast),{schema:e})),K4=w4(e=>{let t=XKe(e);return W4(uWe(e.ast),{schema:t})}),KKe=w4(e=>W4(Y0(e.ast),{schema:e}));function q4(e){let t=W4(new W1(e),{literal:e,transform(n){return t.pipe(i3(q4(n),{decode:f1(()=>n),encode:f1(()=>e)}))}});return t}const J4=W4(U1),qKe=W4(V1),JKe=W4(H1),Z=W4(K1),Y4=W4(J1),X4=W4(YUe);function Z4(e,t){return W4(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Z4(l0(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Q(e){return Z4(l0(e,void 0),e)}function YKe(e,t){return W4(mWe(e.ast,t.ast),{key:e,value:t})}const Q4=w4(e=>W4(new Y1(!1,[],[e.ast]),{value:e}));function $4(e,t){return W4(e,{members:t,mapMembers(e,t){let n=e(this.members);return $4(d0(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function e3(e,t){return $4(d0(e,t,void 0),e)}function t3(e){let t=e.map(q4);return W4(d0(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return e3(e(this.members))},pick(e){return t3(e)},transform(e){return e3(t.map((t,n)=>t.transform(e[n])))}})}const n3=w4(e=>e3([e,qKe])),XKe=w4(e=>e3([e,JKe]));function r3(e){return t=>W4(t.ast,{schema:t,identifier:e})}function i3(e,t){return n=>W4(fWe(n.ast,e.ast,t?T1(t):D1()),{from:n,to:e})}const a3=t3([`true`,`yes`,`on`,`1`,`y`]),o3=t3([`false`,`no`,`off`,`0`,`n`]),ZKe=t3([...a3.literals,...o3.literals]).pipe(i3(X4,E1({decode:e=>e===`true`||e===`yes`||e===`on`||e===`1`||e===`y`,encode:e=>e?`true`:`false`})));function QKe(e){return t=>W4(dWe(t.ast,e),{schema:t})}function s3(e){return q4(e).pipe(QKe(q(e)))}function c3(e,t){return Q({_tag:s3(e),...t})}function $Ke(e,t){return zKe(t=>t instanceof e,t)}function eqe(){return(e,t)=>new F1(e.ast,T1(t))}const l3=k0;function u3(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new globalThis.RegExp(${QH(n)})`:`new globalThis.RegExp(${QH(n)}, ${QH(r)})`;return A0(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}function tqe(e){let t=QFe(e.order),n=SW(e.order),r=ZFe(e.order),i=xW(e.order),a=e.formatter??QH;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return l3(e=>c(e,o.minimum)&&l(e,o.maximum),{expected:`a value between ${a(o.minimum)}${o.exclusiveMinimum?` (excluded)`:``} and ${a(o.maximum)}${o.exclusiveMaximum?` (excluded)`:``}`,arbitraryConstraint:{order:e.order,minimum:o.minimum,maximum:o.maximum,...o.exclusiveMinimum&&{exclusiveMinimum:!0},...o.exclusiveMaximum&&{exclusiveMaximum:!0}},...e.annotate?.(o),...s})}}function d3(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${QH(e)}`);return e}const nqe=tqe({order:yW,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:d3(e.minimum),maximum:d3(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${QH(e.minimum)}, maximum: ${QH(e.maximum)}, exclusiveMinimum: ${QH(t)}, exclusiveMaximum: ${QH(n)} })`})}}});function rqe(e){return l3(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>({type:`integer`,minimum:globalThis.Number.MIN_SAFE_INTEGER,maximum:globalThis.Number.MAX_SAFE_INTEGER}),toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}const f3=Y4.check(rqe());function iqe(e,t){return e=oqe(e),p3(e,Math.ceil(e/2),t)}function p3(e,t,n){return l3(t=>t.length>=e,{expected:`a value with a length of at least ${e}`,representation:{id:`effect/schema/isMinLength`,payload:{minLength:e}},toJsonSchema:({type:n})=>n===`string`?e<=1?{minLength:t}:[{minLength:t},!0]:n===`array`?{minItems:e}:n===void 0?[{minLength:t,minItems:e},!0]:[{},!0],toCode:()=>({runtime:`Schema.isMinLength(${e})`}),"~structural":!0,arbitraryConstraint:{minLength:e},...n})}function aqe(e){return p3(1,1,e)}function oqe(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${e}`);return Math.max(0,Math.floor(e))}const sqe=Z.check(aqe()),cqe=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),lqe=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},m3=[];function h3(e){let t=cqe(e),n=m3[t];if(n!==void 0)return n;let r=vqe.pipe(i3(J4,RUe(lqe(t))));return m3[t]=r,r}globalThis.RegExp,globalThis.URL;const uqe=Z.annotate({expected:`a string that will be decoded as JSON`});function dqe(e,t){return uqe.pipe(i3(e,BUe(t)))}globalThis.File,globalThis.URLSearchParams;const fqe=Z.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),pqe=$Ke(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>eqe()(fqe,zUe)}),mqe=globalThis.Symbol.for(`immer-draftable`),g3={};function _3(e,t,n,r,i){let a=gqe(n,t,r),o=y3(t),s=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===g3?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:g3,value:i}})}static[R4]=R4;get[o](){return o}static[mqe]=!0;static identifier=t;static fields=n.fields;static get ast(){return a(this).ast}static pipe(){return KV(this,arguments)}static rebuild(e){return a(this).rebuild(e)}static make(e,t){return sKe(Y0(a(this).ast),e??{},t,e=>v3(this,e))}static makeOption(e,t){return p4(a(this))(e??{},t)}static makeEffect(e,t){return a(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(L0(this.ast,e))}static annotateKey(e){return this.rebuild(G0(this.ast,e))}static check(...e){return this.rebuild(z0(this.ast,e))}static extend(e){return(t,r)=>{let a=b3(t)?t:Q(t),o={...n.fields,...a.fields},s=l0(o,n.ast.checks,{identifier:e});return _3(this,e,Z4(z0(s,a.ast.checks),o),r,i)}}static mapFields(e,t){return n.mapFields(e,t)}};return i!==void 0&&Object.assign(s.prototype,i(t)),s}function v3(e,t){return new e(t,{"~payload":{token:g3,value:t}})}function hqe(e){return new w1(f1(t=>v3(e,t)),d1())}function y3(e){return`~effect/Schema/Class/${e}`}function gqe(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=y3(t),o=e=>e instanceof i||yH(e,a),s=hqe(i);return r=i3(W4(new B1([e.ast],()=>(e,t,n)=>o(e)?q(e):J(new V$(t,e,n)),{identifier:t,[T$]:([e])=>({isConstructed:o,link:new F1(e,s)}),toCodec:([e])=>new F1(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[w$]:m0(e.ast),...n})),s)(e)}}function b3(e){return GKe(e)}const x3=e=>(t,n)=>{let r=b3(t)?t:Q(t);return _3(XU,e,r,n,e=>({name:e}))},S3=e=>(t,n,r)=>{let i=b3(n)?n.mapFields(e=>({_tag:s3(t),...e}),{unsafePreserveChecks:!0}):c3(t,n);return x3(e??t)(i,r)},_qe=hKe,vqe=W4(L0(TWe,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),C3=`~effect/Terminal`,w3=`~effect/Terminal/QuitError`;var T3=class extends x3(`QuitError`)({_tag:s3(`QuitError`)}){[w3]=w3};const yqe=e=>yH(e,w3),E3=PW(`effect/Terminal`),bqe=e=>E3.of({...e,[C3]:C3}),xqe=xY(E3,X(function*(e=D3){let t=yield*uQ(),n=!1,r=!1,i=()=>{n=!0,r||gQ(t)},a,o=()=>(a===void 0&&(a=process.stdin,a.readableEnded?i():a.once(`end`,i)),a);yield*rZ(()=>xX(()=>a?.off(`end`,i)));let s=yield*i$({acquire:nZ(xX(()=>{let e=o(),n=he.createInterface({input:e,escapeCodeTimeout:50}),i=e=>pQ(t,e),a=()=>{r=!1,gQ(t)};return r=!0,he.emitKeypressEvents(e,n),n.on(`line`,i),n.once(`close`,a),{rl:n,onClose:a,onLine:i}}),({rl:e,onClose:i,onLine:a})=>xX(()=>{r=!1,e.off(`line`,a),e.off(`close`,i),e.close(),n&&gQ(t)})),idleTimeToLive:`10 millis`}),c=e=>xX(()=>{let t=o();t.isTTY&&t.setRawMode(e)}),l=yield*i$({acquire:nZ(c(!0),()=>c(!1)),idleTimeToLive:`10 millis`}),u=xX(()=>process.stdout.columns??0),d=xX(()=>process.stdout.rows??0),f=TX(function*(){let e=process.stdout,t=yield*CVe(1),n=()=>pQ(t,{columns:e.columns??0,rows:e.rows??0});return yield*rZ(()=>xX(()=>{e.off(`resize`,n),gQ(t)})),e.on(`resize`,n),n(),t}),p=TX(function*(){let t=o(),r=yield*uQ(),i=(t,n)=>{let i={input:kW(t),key:{name:n.name??``,ctrl:!!n.ctrl,meta:!!n.meta,shift:!!n.shift}};pQ(r,i),e(i)&&gQ(r)},a=setInterval(()=>{},2147483647),c=()=>{clearInterval(a),gQ(r)};return yield*rZ(()=>xX(()=>{clearInterval(a),t.off(`keypress`,i),t.off(`end`,c)})),t.on(`keypress`,i),n?c():(yield*a$(s),yield*a$(l),t.once(`end`,c)),r}),m=bX(()=>EVe(t).pipe(Y(EW({onNone:()=>tZ(jX(a$(s),yQ(t))),onSome:q})),HX(()=>new T3({}))));return bqe({columns:u,rows:d,size:f,readInput:p,readLine:m,display:e=>MBe(CX(t=>{process.stdout.write(e,e=>iFe(e)?t(SX):t(J(tQ({module:`Terminal`,method:`display`,description:`Failed to write prompt to stdout`,cause:e}))))}))})})(D3));function D3(e){let t=e.key;return t.name===`escape`||t.ctrl&&(t.name===`c`||t.name===`d`)}const Sqe=TY(uGe,wY(BGe,VGe,HGe,xqe)),Cqe=HJ,O3=e=>YU(t=>e(t.getRef(Cqe))),k3=(...e)=>O3(t=>GK(()=>{t.error(...e)})),A3=(...e)=>O3(t=>GK(()=>{t.log(...e)})),wqe={"~effect/Match/Matcher":{_input:YV,_filters:YV,_remaining:YV,_result:YV,_return:YV,_args:YV},_tag:`TypeMatcher`,add(e){return j3(this.select,[...this.cases,e])},pipe(){return KV(this,arguments)}};function j3(e,t){let n=Object.create(wqe);return n.select=e,n.cases=t,n}const Tqe=(e,t)=>({_tag:`When`,guard:e,evaluate:t}),Eqe=W(2,(e,t)=>Oqe(t)(j3(YV,[]))(e)),Dqe=e=>t=>{let n=Tqe(n=>n!=null&&Object.hasOwn(t,n[e])&&t[n[e]]!==void 0,n=>t[n[e]](n));return e=>e.add(n)},Oqe=(e=>t=>{let n=Dqe(e)(t);return e=>Aqe(n(e))})(`_tag`),kqe=e=>{if(e._tag===`ValueMatcher`)return e.value;let t=e.cases.length;if(t===1){let t=e.cases[0];return(...n)=>{let r=e.select(...n);return t._tag===`When`&&t.guard(r)===!0||t._tag===`Not`&&t.guard(r)===!1?aG(t.evaluate(r,...n)):oG(r)}}return(...n)=>{let r=e.select(...n);for(let i=0;i<t;i++){let t=e.cases[i];if(t._tag===`When`&&t.guard(r)===!0||t._tag===`Not`&&t.guard(r)===!1)return aG(t.evaluate(r,...n))}return oG(r)}},M3=`effect/match/Match/exhaustive: absurd`,Aqe=e=>{let t=kqe(e);if(pIe(t)){if(cG(t))return t.success;throw Error(M3)}return(...e)=>{let n=t(...e);if(cG(n))return n.success;throw Error(M3)}},jqe=Eqe,Mqe={"~effect/Ref":{_A:YV},...yU,toJSON(){return{_id:`Ref`,ref:this.ref}}},Nqe=e=>{let t=Object.create(Mqe);return t.ref=rQ(e),t},N3=e=>xX(()=>Nqe(e)),P3=e=>xX(()=>e.ref.current),F3=W(2,(e,t)=>xX(()=>_Ve(e.ref,t))),I3=`~effect/Runtime/errorReported`,L3=`~effect/cli/CliError`,R3=e=>yH(e,L3),z3=`~effect/cli/CliError/userMessage`,Pqe=e=>`~effect/cli/CliError/userMessage`in e&&typeof e[`~effect/cli/CliError/userMessage`]==`string`?e[z3]:void 0;var B3=class extends S3(`${L3}/UnrecognizedOption`)(`UnrecognizedOption`,{option:Z,command:K4(Q4(Z)),suggestions:Q4(Z)}){[L3]=L3;get message(){let e=this.suggestions.length>0?`\n\n Did you mean this?\n ${this.suggestions.join(`
604
+ `)}`:``;return(this.command?`Unrecognized flag: ${this.option} in command ${this.command.join(` `)}`:`Unrecognized flag: ${this.option}`)+e}},V3=class extends S3(`${L3}/DuplicateOption`)(`DuplicateOption`,{option:Z,parentCommand:Z,childCommand:Z}){[L3]=L3;get message(){return`Duplicate flag name "${this.option}" in parent command "${this.parentCommand}" and subcommand "${this.childCommand}". Parent will always claim this flag (Mode A semantics). Consider renaming one of them to avoid confusion.`}},H3=class extends S3(`${L3}/MissingOption`)(`MissingOption`,{option:Z}){[L3]=L3;get message(){return`Missing required flag: --${this.option}`}},U3=class extends S3(`${L3}/MissingArgument`)(`MissingArgument`,{argument:Z}){[L3]=L3;get message(){return`Missing required argument: ${this.argument}`}},W3=class extends S3(`${L3}/UnexpectedArgument`)(`UnexpectedArgument`,{arguments:Q4(Z)}){[L3]=L3;get message(){return`Unexpected positional ${this.arguments.length===1?`argument`:`arguments`}: ${this.arguments.map(e=>JSON.stringify(e)).join(`, `)}`}},G3=class extends S3(`${L3}/InvalidValue`)(`InvalidValue`,{option:Z,value:Z,expected:Z,kind:e3([q4(`flag`),q4(`argument`)])}){[L3]=L3;get message(){let e=this.expected.startsWith(`Expected `)||this.expected.startsWith(`Expected:`)?this.expected:`Expected: ${this.expected}`;return this.kind===`argument`?`Invalid value for argument <${this.option}>: "${this.value}". ${e}`:this.value.length===0?`Missing value for flag --${this.option}. ${e}`:`Invalid value for flag --${this.option}: "${this.value}". ${e}`}},K3=class extends S3(`${L3}/UnknownSubcommand`)(`UnknownSubcommand`,{subcommand:Z,parent:K4(Q4(Z)),suggestions:Q4(Z)}){[L3]=L3;get message(){let e=this.suggestions.length>0?`\n\n Did you mean this?\n ${this.suggestions.join(`
605
+ `)}`:``;return this.parent?`Unknown subcommand "${this.subcommand}" for "${this.parent.join(` `)}"${e}`:`Unknown subcommand "${this.subcommand}"${e}`}},Fqe=class extends S3(`${L3}/ValidationError`)(`ValidationError`,{message:Z}){[L3]=L3},q3=class extends S3(`${L3}/UserError`)(`UserError`,{cause:h3(),userMessage:G4(Z)}){[L3]=L3;[I3]=!0;get message(){return this.userMessage?this.userMessage:typeof this.cause==`string`&&this.cause?this.cause:this.cause instanceof Error&&this.cause.message?this.cause.message:`An error occurred`}get[z3](){return this.message}};const Iqe=e3([B3,V3,H3,U3,W3,G3,K3,Fqe,q3]);var J3=class extends S3(`${L3}/ShowHelp`)(`ShowHelp`,{commandPath:Q4(Z),errors:Q4(Iqe)}){[L3]=L3;"~effect/Runtime/errorExitCode"=+!!this.errors.length;[I3]=!1;get message(){return`Help requested`}};const Lqe={"~effect/cli/Primitive":{_A:YV}},Rqe=V4(a3),zqe=V4(o3),Y3=e=>e._tag===`Boolean`,X3=(e,t)=>Object.assign(Object.create(Lqe),{_tag:e,parse:t}),Bqe=((e,t)=>{let n=H4(_qe(t));return X3(e,e=>HX(n(e),e=>e.message))})(`Boolean`,ZKe),Vqe=X3(`String`,e=>q(e)),Hqe=e=>{let t=new Map(e),n=e.map(([e])=>QH(e)).join(` | `),r=X3(`Choice`,e=>t.has(e)?q(t.get(e)):J(n));return Object.assign(r,{choiceKeys:e.map(([e])=>e)})},Z3=e=>{switch(e._tag){case`Boolean`:return`boolean`;case`String`:return`string`;case`Int`:return`integer`;case`Finite`:return`number`;case`Date`:return`date`;case`Path`:return`path`;case`Choice`:return`choice`;case`Redacted`:return`string`;case`FileText`:return`file`;case`FileParse`:return`file`;case`FileSchema`:return`file`;case`KeyValuePair`:return`key=value`;case`Never`:return`none`;default:return`value`}},Q3=e=>e._tag===`Choice`?e.choiceKeys:void 0,$3=e=>e._tag===`Path`?e.pathType:void 0,e6=`\x1B[1m`,t6=`\x1B[4m`,n6=`\x1B[?25l`,r6=`\x1B[31m`,i6=`\x1B[32m`,a6=`\x1B[37m`,o6=`\x1B[90m`,s6=`\x1B[96m`,c6=(e,t,...n)=>e?`${n.flat().join(``)}${t}`:t,l6=()=>{let e=globalThis.process;return typeof e==`object`&&!!e&&typeof e.stdout==`object`&&e.stdout!==null&&e.stdout.isTTY===!0&&!e.env?.NO_COLOR},u6=(...e)=>e,Uqe=(e,t)=>t===void 0?`[${Math.max(e+1,0)}G`:`[${t+1};${Math.max(e+1,0)}H`,Wqe=(e=1)=>`[${e}B`,Gqe=(e,t=0)=>{let n=``;return t<0&&(n+=`[${-t}A`),t>0&&(n+=`[${t}B`),e>0&&(n+=`[${e}C`),e<0&&(n+=`[${-e}D`),n},Kqe=e=>{let t=``;for(let n=0;n<e;n++)t+=`\x1B[2K`+(n<e-1?`\x1B[1A`:``);return e>0&&(t+=`\x1B[G`),t},d6={prefix:`?`,arrowUp:`↑`,arrowDown:`↓`,checkboxOn:`☒`,checkboxOff:`☐`,tick:`✔`,ellipsis:`…`,pointerSmall:`›`,pointer:`❯`,descriptionSeparator:`- `,passwordMask:`*`,toggleSeparator:`/`,primaryColor:s6,mutedColor:o6,successColor:i6,errorColor:r6,submittedColor:a6},qqe={...d6,checkboxOn:`[*]`,checkboxOff:`[ ]`,tick:`√`,ellipsis:`...`,pointerSmall:`»`,pointer:`>`},f6=nG(`effect/cli/Prompt/Theme`,{defaultValue:e=>({...process.platform===`win32`?qqe:d6,...e,colors:e?.colors??l6()})}),p6=e=>PX(f6,t=>({...t,...e.theme})),m6=(e,t)=>c6(e.colors,t,u6(`\x1B[3m`,e.errorColor)),h6=(e,t,...n)=>t.length===0?``:c6(e.colors,t,...n),g6=(e,t)=>e.length===0?t:e+` `+t,Jqe=(e,t,n)=>{let r=Math.max(e.arrowUp.length,e.arrowDown.length);return t?e.arrowUp.padEnd(r):n?e.arrowDown.padEnd(r):` `.repeat(r)},_6=e=>{let t={initial:!1,...e,label:{confirm:`yes`,deny:`no`,...e.label},placeholder:{defaultConfirm:`(Y/n)`,defaultDeny:`(y/N)`,...e.placeholder}},n={value:t.initial};return v6(n,{render:lJe(t),process:e=>fJe(e,t.initial),clear:oJe(t)})},v6=(e,...t)=>{let[n,r]=t.length===1?[void 0,t[0]]:[t[0],t[1]],i=Object.create(S6);return i._tag=`Loop`,i.initialState=e,i.render=r.render,i.process=r.process,i.clear=r.clear,i.events=n,i},Yqe=e=>{let t={initial:new globalThis.Date,dateMask:`YYYY-MM-DD HH:mm:ss`,validate:q,...e,locales:{...CJe,...e.locales}},n=DJe(t.dateMask,t.initial,t.locales),r={dateParts:n,typed:``,cursor:n.findIndex(e=>!e.isToken()),value:t.initial,error:G()};return v6(r,{render:wJe(t),process:TJe(t),clear:pJe(t)})},Xqe=W(2,(e,t)=>{let n=Object.create(S6);return n._tag=`OnSuccess`,n.prompt=e,n.onSuccess=t,n}),Zqe=e=>{let t={default:0,min:globalThis.Number.NEGATIVE_INFINITY,max:globalThis.Number.POSITIVE_INFINITY,incrementBy:1,decrementBy:1,precision:2,validate:e=>e<t.min?J(`${e} must be greater than or equal to ${t.min}`):e>t.max?J(`${e} must be less than or equal to ${t.max}`):q(e),...e},n=e.default===void 0?``:`${t.default}`,r={cursor:n.length,value:n,error:G()};return v6(r,{render:HJe(t),process:UJe(t),clear:M6(t)})},y6=e=>{let t={default:0,min:globalThis.Number.NEGATIVE_INFINITY,max:globalThis.Number.POSITIVE_INFINITY,incrementBy:1,decrementBy:1,validate:e=>e<t.min?J(`${e} must be greater than or equal to ${t.min}`):e>t.max?J(`${e} must be less than or equal to ${t.max}`):q(e),...e},n=e.default===void 0?``:`${t.default}`,r={cursor:n.length,value:n,error:G()};return v6(r,{render:BJe(t),process:VJe(t),clear:M6(t)})},Qqe=W(2,(e,t)=>Xqe(e,e=>tJe(t(e)))),$qe=e=>K6(e,`password`).pipe(Qqe(h2)),b6=X(function*(e){let t=yield*E3,n=yield*jBe(t.readInput);return yield*C6(e,t,n)},HX(()=>new T3({})),tZ),eJe=e=>{let t=0,n=-1;for(let t=0;t<e.length;t++)if(e[t].selected===!0){if(n!==-1)throw Error(`InvalidArgumentException: only a single choice can be selected by default for Prompt.Select`);n=t}return n!==-1&&(t=n),t},x6=e=>{let t={maxPerPage:10,...e},n=eJe(t.choices);return v6(n,{render:ZJe(t),process:$Je(t),clear:QJe(t)})},tJe=e=>{let t=Object.create(S6);return t._tag=`Succeed`,t.value=e,t},nJe=e=>K6(e,`text`),rJe=e=>{let t={initial:!1,active:`on`,inactive:`off`,...e};return v6(t.initial,{render:gYe(t),process:_Ye,clear:()=>pYe(t)})},S6={...nW({label:`Prompt`,evaluate(){return b6(this)}}),"~effect/cli/Prompt":{_Output:e=>e}},C6=(e,t,n)=>bX(()=>{let r=e;switch(r._tag){case`Loop`:return Y(n,e=>iJe(r,t,e));case`OnSuccess`:return Y(C6(r.prompt,t,n),e=>C6(r.onSuccess(e),t,n));case`Succeed`:return q(r.value)}}),iJe=X(function*(e,t,n){let r=gX(e.initialState)?yield*e.initialState:e.initialState,i=$.NextFrame({state:r}),a=``;for(;;){let o=yield*e.render(r,i);if(yield*UX(t.display(a+o)),a=``,e.events){let t=yQ(n).pipe(PX(e=>({_tag:`Input`,input:e}))),a=yield*qX(t,yQ(e.events).pipe(PX(e=>({_tag:`Event`,value:e}))));i=yield*e.process(a,r)}else{let t=yield*yQ(n);i=yield*e.process(t,r)}switch(i._tag){case`Beep`:continue;case`NextFrame`:a=yield*e.clear(r,i),r=i.state;continue;case`Submit`:{a=yield*e.clear(r,i);let n=yield*e.render(r,i);return yield*UX(t.display(a+n)),i.value}}}},(e,t,n)=>iZ(e,UX(n.display(`\x1B[?25h`)))),$=ZIe(),w6=(e,t)=>{if(t===0)return`\x1B[2K`+Uqe(0);let n=0,r=e.split(E6);for(let e of r)n+=1+Math.floor(Math.max(e.length-1,0)/t);return Kqe(n)},aJe=(e,t)=>{let n=e.split(E6);return t===0?n.length:tH(_G(n,e=>Math.ceil(e.length/t)),vG(0,(e,t)=>e+t))},T6=(e,t,n)=>n!==void 0&&n.length>0?Wqe(aJe(n,t))+w6(`\n${n}`,t)+w6(e,t):w6(e,t),E6=/\r?\n/,oJe=e=>X(function*(t,n){let r=yield*(yield*E3).columns,i=yield*p6(e),a=t.value?e.placeholder.defaultConfirm:e.placeholder.defaultDeny,o=j6(a,e.message,i.prefix,i.pointerSmall,i,{plain:!0});return w6(o,r)+`\x1B[2K\x1B[G`}),sJe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.prefix,n.primaryColor),i=h6(n,n.pointerSmall,n.mutedColor),a=e.value?t.placeholder.defaultConfirm:t.placeholder.defaultDeny,o=c6(n.colors,a,n.mutedColor),s=j6(o,t.message,r,i,n);return n6+s}),cJe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.tick,n.successColor),i=h6(n,n.ellipsis,n.mutedColor),a=e?t.label.confirm:t.label.deny;return j6(a,t.message,r,i,n)+`
606
+ `}),lJe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>sJe(t,e),Submit:({value:t})=>cJe(t,e)}),uJe=/^y|t$/,dJe=/^n|f$/,fJe=(e,t)=>{let n=DW(e.input,()=>``);return e.key.name===`enter`||e.key.name===`return`?q($.Submit({value:t})):uJe.test(n.toLowerCase())?q($.Submit({value:!0})):dJe.test(n.toLowerCase())?q($.Submit({value:!1})):q($.Beep())},pJe=e=>X(function*(t,n){let r=yield*(yield*E3).columns,i=yield*p6(e),a=vG(t.dateParts,``,(e,t)=>e+t.toString()),o=j6(a,e.message,i.prefix,i.pointerSmall,i,{plain:!0}),s=TW(t.error)?dG(t.error.value.split(E6),{onEmpty:()=>``,onNonEmpty:e=>g6(i.pointerSmall,e.join(`
607
+ `))}):``;return T6(o,r,s)+`\x1B[2K\x1B[G`}),mJe=(e,t,n)=>{if(TW(e.error)){let r=e.error.value.split(E6);if(pG(r)){let e=h6(n,t,n.errorColor),i=_G(r,e=>m6(n,e));return`\x1B[s
608
+ `+g6(e,i.join(`
609
+ `))+`\x1B[u`}}return``},D6=(e,t,n=!1)=>vG(e.dateParts,``,(r,i,a)=>{let o=i.toString();if(a===e.cursor&&!n){let e=u6(t6,t.primaryColor);return r+c6(t.colors,o,e)}return r+o}),hJe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.prefix,n.primaryColor),i=h6(n,n.pointerSmall,n.mutedColor),a=D6(e,n),o=j6(a,t.message,r,i,n),s=mJe(e,n.pointerSmall,n);return n6+o+s}),gJe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.tick,n.successColor),i=h6(n,n.ellipsis,n.mutedColor),a=D6(e,n,!0);return j6(a,t.message,r,i,n)+`
610
+ `}),_Je=e=>(e.dateParts[e.cursor].increment(),$.NextFrame({state:{...e,typed:``}})),vJe=e=>(e.dateParts[e.cursor].decrement(),$.NextFrame({state:{...e,typed:``}})),yJe=e=>{let t=e.dateParts[e.cursor].previousPart();return TW(t)?$.NextFrame({state:{...e,typed:``,cursor:e.dateParts.indexOf(t.value)}}):$.Beep()},bJe=e=>{let t=e.dateParts[e.cursor].nextPart();return TW(t)?$.NextFrame({state:{...e,typed:``,cursor:e.dateParts.indexOf(t.value)}}):$.Beep()},xJe=e=>{let t=e.dateParts[e.cursor].nextPart(),n=EW(t,{onNone:()=>e.dateParts.findIndex(e=>!e.isToken()),onSome:t=>e.dateParts.indexOf(t)});return $.NextFrame({state:{...e,typed:``,cursor:n}})},SJe=(e,t)=>{if(/\d/.test(e)){let n=t.typed+e;return t.dateParts[t.cursor].setValue(n),$.NextFrame({state:{...t,typed:n}})}return $.Beep()},CJe={months:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],monthsShort:[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],weekdays:[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],weekdaysShort:[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`]},wJe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>hJe(t,e),Submit:()=>gJe(t,e)}),TJe=e=>(t,n)=>{switch(t.key.name){case`left`:return q(yJe(n));case`right`:return q(bJe(n));case`k`:case`up`:return q(_Je(n));case`j`:case`down`:return q(vJe(n));case`tab`:return q(xJe(n));case`enter`:case`return`:return JX(e.validate(n.value),{onFailure:e=>$.NextFrame({state:{...n,error:CW(e)}}),onSuccess:e=>$.Submit({value:e})});default:return q(SJe(DW(t.input,()=>``),n))}},EJe=/\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g,O6={1:({token:e,...t})=>new A6({token:e.replace(/\\(.)/g,`$1`),...t}),2:e=>new MJe(e),3:e=>new NJe(e),4:e=>new PJe(e),5:e=>new FJe(e),6:e=>new jJe(e),7:e=>new AJe(e),8:e=>new kJe(e),9:e=>new OJe(e)},DJe=(e,t,n)=>{let r=[],i=null;for(;i=EJe.exec(e);){let e=i.shift(),a=i.findIndex(e=>e!==void 0);if(a in O6){let o=i[a]||e;r.push(O6[a]({token:o,date:t,parts:r,locales:n}))}else r.push(new A6({token:i[a]||e,date:t,parts:r,locales:n}))}let a=r.reduce((e,t)=>{let n=e[e.length-1];return t.isToken()&&n!==void 0&&n.isToken()?n.setValue(t.token):e.push(t),e},hG());return r.splice(0,r.length,...a),r};var k6=class{token;date;parts;locales;constructor(e){this.token=e.token,this.locales=e.locales,this.date=e.date||new globalThis.Date,this.parts=e.parts||[this]}isToken(){return!1}nextPart(){let e=DW(mG(this.parts,e=>e===this),()=>0);return yIe(this.parts.slice(e+1),e=>!e.isToken())}previousPart(){let e=mG(this.parts,e=>e===this);return TW(e)?bIe(this.parts.slice(0,e.value),e=>!e.isToken()):G()}toString(){return globalThis.String(this.date)}},A6=class extends k6{increment(){}decrement(){}setValue(e){this.token+=e}isToken(){return!0}toString(){return this.token}},OJe=class extends k6{increment(){this.date.setMilliseconds(this.date.getMilliseconds()+1)}decrement(){this.date.setMilliseconds(this.date.getMilliseconds()-1)}setValue(e){this.date.setMilliseconds(globalThis.Number.parseInt(e.slice(-this.token.length)))}toString(){return`${this.date.getMilliseconds()}`.padStart(4,`0`).substring(0,this.token.length)}},kJe=class extends k6{increment(){this.date.setSeconds(this.date.getSeconds()+1)}decrement(){this.date.setSeconds(this.date.getSeconds()-1)}setValue(e){this.date.setSeconds(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=`${this.date.getSeconds()}`;return this.token.length>1?e.padStart(2,`0`):e}},AJe=class extends k6{increment(){this.date.setMinutes(this.date.getMinutes()+1)}decrement(){this.date.setMinutes(this.date.getMinutes()-1)}setValue(e){this.date.setMinutes(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=`${this.date.getMinutes()}`;return this.token.length>1?e.padStart(2,`0`):e}},jJe=class extends k6{increment(){this.date.setHours(this.date.getHours()+1)}decrement(){this.date.setHours(this.date.getHours()-1)}setValue(e){this.date.setHours(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=/h/.test(this.token)?this.date.getHours()%12||12:this.date.getHours();return this.token.length>1?`${e}`.padStart(2,`0`):`${e}`}},MJe=class extends k6{increment(){this.date.setDate(this.date.getDate()+1)}decrement(){this.date.setDate(this.date.getDate()-1)}setValue(e){this.date.setDate(globalThis.Number.parseInt(e.slice(-2)))}toString(){let e=this.date.getDate(),t=this.date.getDay();switch(this.token){case`DD`:return`${e}`.padStart(2,`0`);case`Do`:return`${e}${this.ordinalIndicator(e)}`;case`d`:return`${t+1}`;case`ddd`:return this.locales.weekdaysShort[t];case`dddd`:return this.locales.weekdays[t];default:return`${e}`}}ordinalIndicator(e){if(e>=11&&e<=13)return`th`;switch(e%10){case 1:return`st`;case 2:return`nd`;case 3:return`rd`;default:return`th`}}},NJe=class extends k6{increment(){this.date.setMonth(this.date.getMonth()+1)}decrement(){this.date.setMonth(this.date.getMonth()-1)}setValue(e){let t=globalThis.Number.parseInt(e.slice(-2))-1;this.date.setMonth(t<0?0:t)}toString(){let e=this.date.getMonth();switch(this.token.length){case 2:return`${e+1}`.padStart(2,`0`);case 3:return this.locales.monthsShort[e];case 4:return this.locales.months[e];default:return`${e+1}`}}},PJe=class extends k6{increment(){this.date.setFullYear(this.date.getFullYear()+1)}decrement(){this.date.setFullYear(this.date.getFullYear()-1)}setValue(e){this.date.setFullYear(globalThis.Number.parseInt(e.slice(-4)))}toString(){let e=`${this.date.getFullYear()}`.padStart(4,`0`);return this.token.length===2?e.slice(-2):e}},FJe=class extends k6{increment(){this.date.setHours((this.date.getHours()+12)%24)}decrement(){this.increment()}setValue(e){}toString(){let e=this.date.getHours()>=12?`pm`:`am`;return/A/.test(this.token)?e.toUpperCase():e}};const j6=(e,t,n,r,i,a)=>{let o=n.length===0?``:n+` `,s=t=>{let n=o+t;return r.length>0&&(n+=` `+r),e.length>0?n+=` `+e:r.length>0&&(n+=` `),n};return dG(t.split(E6),{onEmpty:()=>s(``),onNonEmpty:e=>{let t=a?.plain===!0?e:_G(e,e=>c6(i.colors,e,e6));return s(t.join(`
611
+ `))}})},IJe=(e,t,n,r)=>{if(!e.disabled&&e.description&&t){let t=n.descriptionSeparator+e.description;return r?.plain===!0?t:c6(n.colors,t,n.mutedColor)}return``},M6=e=>X(function*(t,n){let r=yield*(yield*E3).columns,i=yield*p6(e),a=N6(t,i.pointerSmall,i,{plain:!0}),o=P6(t,i.prefix,i.pointerSmall,e,i,{plain:!0});return T6(o,r,a)+`\x1B[2K\x1B[G`}),LJe=(e,t,n,r)=>{let i=e.value===``?``:`${e.value}`;if(t||r?.plain===!0)return i;let a=TW(e.error)?n.errorColor:u6(t6,n.primaryColor);return c6(n.colors,i,a)},N6=(e,t,n,r)=>TW(e.error)?dG(e.error.value.split(E6),{onEmpty:()=>``,onNonEmpty:e=>{if(r?.plain===!0)return g6(t,e.join(`
612
+ `));let i=h6(n,t,n.errorColor),a=_G(e,e=>m6(n,e));return`\x1B[s
613
+ `+g6(i,a.join(`
614
+ `))+`\x1B[u`}}):``,P6=(e,t,n,r,i,a,o=!1)=>{let s=LJe(e,o,i,a);return j6(s,r.message,t,n,i,a)},F6=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.prefix,n.primaryColor),i=h6(n,n.pointerSmall,n.mutedColor),a=N6(e,n.pointerSmall,n);return P6(e,r,i,t,n)+a}),I6=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.tick,n.successColor),i=h6(n,n.ellipsis,n.mutedColor);return P6(e,r,i,t,n,void 0,!0)+`
615
+ `}),L6=e=>{if(e.value.length<=0)return q($.Beep());let t=e.value.slice(0,e.value.length-1);return q($.NextFrame({state:{...e,value:t,error:G()}}))},R6=e=>q($.NextFrame({state:{...e,cursor:0,value:``,error:G()}})),RJe=(e,t)=>{if(t.value.length===0&&e===`-`)return q($.NextFrame({state:{...t,value:`-`,error:G()}}));let n=globalThis.Number.parseInt(t.value+e);return globalThis.Number.isNaN(n)?q($.Beep()):q($.NextFrame({state:{...t,value:`${n}`,error:G()}}))},zJe=(e,t)=>{if(e===`.`&&t.value.includes(`.`))return q($.Beep());if(t.value.length===0&&e===`-`)return q($.NextFrame({state:{...t,value:`-`,error:G()}}));let n=globalThis.Number.parseFloat(t.value+e);return globalThis.Number.isNaN(n)?q($.Beep()):q($.NextFrame({state:{...t,value:e===`.`?`${n}.`:t.value.includes(`.`)&&/^\d$/.test(e)?t.value+e:`${n}`,error:G()}}))},BJe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>F6(t,e),Submit:()=>I6(t,e)}),VJe=e=>(t,n)=>{if(t.key.ctrl&&t.key.name===`u`)return R6(n);switch(t.key.name){case`backspace`:return L6(n);case`k`:case`up`:return q($.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`${e.incrementBy}`:`${globalThis.Number.parseInt(n.value)+e.incrementBy}`,error:G()}}));case`j`:case`down`:return q($.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`-${e.decrementBy}`:`${globalThis.Number.parseInt(n.value)-e.decrementBy}`,error:G()}}));case`enter`:case`return`:{let t=globalThis.Number.parseInt(n.value);return globalThis.Number.isNaN(t)?q($.NextFrame({state:{...n,error:CW(`Must provide an integer value`)}})):JX(e.validate(t),{onFailure:e=>$.NextFrame({state:{...n,error:CW(e)}}),onSuccess:e=>$.Submit({value:e})})}default:return RJe(DW(t.input,()=>``),n)}},HJe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>F6(t,e),Submit:()=>I6(t,e)}),UJe=e=>(t,n)=>{if(t.key.ctrl&&t.key.name===`u`)return R6(n);switch(t.key.name){case`backspace`:return L6(n);case`k`:case`up`:return q($.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`${e.incrementBy}`:`${globalThis.Number.parseFloat(n.value)+e.incrementBy}`,error:G()}}));case`j`:case`down`:return q($.NextFrame({state:{...n,value:n.value===``||n.value===`-`?`-${e.decrementBy}`:`${globalThis.Number.parseFloat(n.value)-e.decrementBy}`,error:G()}}));case`enter`:case`return`:{let t=globalThis.Number.parseFloat(n.value);return globalThis.Number.isNaN(t)?q($.NextFrame({state:{...n,error:CW(`Must provide a floating point value`)}})):Y(xX(()=>nBe(t,e.precision)),t=>JX(e.validate(t),{onFailure:e=>$.NextFrame({state:{...n,error:CW(e)}}),onSuccess:e=>$.Submit({value:e})}))}default:return zJe(DW(t.input,()=>``),n)}},z6=(e,t,n,r,i)=>n.message===void 0?void 0:j6(``,n.message,e,t,r,i),B6=(e,t)=>e===void 0?t:e+`
616
+ `+t,WJe=(e,t,n,r,i,a)=>{let o=Jqe(i,r===n.startIndex&&n.startIndex>0,r===n.endIndex-1&&n.endIndex<t.length);if(a?.plain===!0)return e===r?i.pointer+o:o+` `.repeat(i.pointer.length);if(t[r].disabled){let t=u6(e6,i.mutedColor);return e===r?h6(i,i.pointer,t)+o:o+` `.repeat(i.pointer.length)}return e===r?h6(i,i.pointer,i.primaryColor)+o:o+` `.repeat(i.pointer.length)},GJe=(e,t,n,r)=>{if(r?.plain===!0)return e.title;let i=e.title;return t?e.disabled?c6(n.colors,i,u6(t6,n.mutedColor)):c6(n.colors,i,u6(t6,n.primaryColor)):e.disabled?c6(n.colors,i,u6(`\x1B[9m`,n.mutedColor)):i},V6=(e,t,n,r)=>{let i=t.choices,a=vYe(e,i.length,t.maxPerPage),o=[];for(let t=a.startIndex;t<a.endIndex;t++){let s=i[t],c=e===t,l=WJe(e,i,a,t,n,r),u=GJe(s,c,n,r),d=IJe(s,c,n,r);o.push(l+u+` `+d)}return o.join(`
617
+ `)},KJe=X(function*(e,t){let n=yield*p6(t),r=V6(e,t,n),i=h6(n,n.prefix,n.primaryColor),a=h6(n,n.pointerSmall,n.mutedColor),o=z6(i,a,t,n);return n6+B6(o,r)}),qJe=X(function*(e,t){let n=yield*p6(t),r=t.choices[e].title,i=h6(n,n.tick,n.successColor),a=h6(n,n.ellipsis,n.mutedColor);return(z6(i,a,t,n)??i)+` `+c6(n.colors,r,n.submittedColor)+`
618
+ `}),JJe=(e,t)=>q(e===0?$.NextFrame({state:t.length-1}):$.NextFrame({state:e-1})),YJe=(e,t)=>e===t.length-1?q($.NextFrame({state:0})):q($.NextFrame({state:e+1})),XJe=(e,t)=>q($.NextFrame({state:(e+1)%t.length})),ZJe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>KJe(t,e),Submit:()=>qJe(t,e)}),QJe=e=>X(function*(t,n){let r=yield*(yield*E3).columns,i=yield*p6(e),a=z6(i.prefix,i.pointerSmall,e,i,{plain:!0}),o=V6(t,e,i,{plain:!0});return w6(B6(a,o),r)+`\x1B[2K\x1B[G`}),$Je=e=>(t,n)=>{switch(t.key.name){case`k`:case`up`:return JJe(n,e.choices);case`j`:case`down`:return YJe(n,e.choices);case`tab`:return XJe(n,e.choices);case`enter`:case`return`:{let t=e.choices[n];return t.disabled?q($.Beep()):q($.Submit({value:t.value}))}default:return q($.Beep())}},eYe=X(function*(e,t){let n=yield*(yield*E3).columns,r=yield*p6(t),i=H6(e,r.pointerSmall,r,{plain:!0});return T6(U6(e,r.prefix,r.pointerSmall,t,r,{plain:!0}),n,i)+`\x1B[2K\x1B[G`}),tYe=(e,t,n,r,i)=>{let a=e.value;if(i?.plain===!0)switch(t.type){case`hidden`:return``;case`password`:return n.passwordMask.repeat(a.length);case`text`:return a}if(a.length===0)return``;let o=TW(e.error)?n.errorColor:r?n.submittedColor:u6(t6,n.primaryColor);switch(t.type){case`hidden`:return``;case`password`:return h6(n,n.passwordMask.repeat(a.length),o);case`text`:return c6(n.colors,a,o)}},H6=(e,t,n,r)=>TW(e.error)?dG(e.error.value.split(E6),{onEmpty:()=>``,onNonEmpty:e=>{if(r?.plain===!0)return g6(t,e.join(`
619
+ `));let i=h6(n,t,n.errorColor),a=_G(e,e=>m6(n,e));return`\x1B[s
620
+ `+g6(i,a.join(`
621
+ `))+`\x1B[u`}}):``,U6=(e,t,n,r,i,a,o=!1)=>{let s=tYe(e,r,i,o,a);return j6(s,r.message,t,n,i,a)},nYe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.prefix,n.primaryColor),i=h6(n,n.pointerSmall,n.mutedColor),a=U6(e,r,i,t,n),o=H6(e,n.pointerSmall,n),s=t.type===`password`?n.passwordMask.length:1,c=(e.cursor-e.value.length)*s;return a+o+Gqe(c)}),rYe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.tick,n.successColor),i=h6(n,n.ellipsis,n.mutedColor);return U6(e,r,i,t,n,void 0,!0)+`
622
+ `}),iYe=e=>{if(e.cursor<=0)return q($.Beep());let t=e.value.slice(0,e.cursor-1),n=e.value.slice(e.cursor),r=e.cursor-1,i=`${t}${n}`;return q($.NextFrame({state:{...e,cursor:r,value:i,error:G()}}))},aYe=e=>q($.NextFrame({state:{...e,cursor:0,value:``,error:G()}})),oYe=e=>{if(e.cursor<=0)return q($.Beep());let t=e.cursor-1;return q($.NextFrame({state:{...e,cursor:t,error:G()}}))},sYe=e=>{if(e.cursor>=e.value.length)return q($.Beep());let t=Math.min(e.cursor+1,e.value.length);return q($.NextFrame({state:{...e,cursor:t,error:G()}}))},W6=e=>q($.NextFrame({state:{...e,cursor:0,error:G()}})),G6=e=>q($.NextFrame({state:{...e,cursor:e.value.length,error:G()}})),cYe=(e,t)=>{if(e.value===t.default)return q($.Beep());let n=e.value.length===0?t.default:e.value;return q($.NextFrame({state:{...e,value:n,cursor:n.length,error:G()}}))},lYe=(e,t)=>{let n=`${t.value.slice(0,t.cursor)}${e}${t.value.slice(t.cursor)}`,r=t.cursor+e.length;return q($.NextFrame({state:{...t,cursor:r,value:n,error:G()}}))},uYe=e=>(t,n)=>$.$match(n,{Beep:()=>q(`\x07`),NextFrame:({state:t})=>nYe(t,e),Submit:()=>rYe(t,e)}),dYe=e=>(t,n)=>{if(t.key.ctrl)switch(t.key.name){case`u`:return aYe(n);case`a`:return W6(n);case`e`:return G6(n);default:return q($.Beep())}switch(t.key.name){case`backspace`:return iYe(n);case`left`:return oYe(n);case`right`:return sYe(n);case`home`:return W6(n);case`end`:return G6(n);case`enter`:case`return`:{let t=n.value;return JX(e.validate(t),{onFailure:e=>$.NextFrame({state:{...n,value:t,error:CW(e)}}),onSuccess:e=>$.Submit({value:e})})}case`tab`:return cYe(n,e);default:return lYe(DW(t.input,()=>``),n)}},fYe=e=>(t,n)=>eYe(t,e),K6=(e,t)=>{let n={default:``,type:t,validate:q,...e},r={cursor:n.default.length,value:n.default,error:G()};return v6(r,{render:uYe(n),process:dYe(n),clear:fYe(n)})},pYe=X(function*(e){let t=yield*(yield*E3).columns,n=yield*p6(e),r=e.active+` `+g6(n.toggleSeparator,e.inactive),i=j6(r,e.message,n.prefix,n.pointerSmall,n,{plain:!0});return w6(i,t)+`\x1B[2K\x1B[G`}),q6=(e,t,n,r=!1)=>{let i=h6(n,n.toggleSeparator,n.mutedColor),a=u6(t6,r?n.submittedColor:n.primaryColor),o=e?t.inactive:c6(n.colors,t.inactive,a);return(e?c6(n.colors,t.active,a):t.active)+` `+g6(i,o)},mYe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.prefix,n.primaryColor),i=h6(n,n.pointerSmall,n.mutedColor),a=q6(e,t,n),o=j6(a,t.message,r,i,n);return n6+o}),hYe=X(function*(e,t){let n=yield*p6(t),r=h6(n,n.tick,n.successColor),i=h6(n,n.ellipsis,n.mutedColor),a=q6(e,t,n,!0);return j6(a,t.message,r,i,n)+`
623
+ `}),J6=q($.NextFrame({state:!0})),Y6=q($.NextFrame({state:!1})),gYe=e=>(t,n)=>{switch(n._tag){case`Beep`:return q(`\x07`);case`NextFrame`:return mYe(t,e);case`Submit`:return hYe(t,e)}},_Ye=(e,t)=>{switch(e.key.name){case`0`:case`j`:case`delete`:case`right`:case`down`:return Y6;case`1`:case`k`:case`left`:case`up`:return J6;case` `:case`tab`:return t?Y6:J6;case`enter`:case`return`:return q($.Submit({value:t}));default:return q($.Beep())}},vYe=(e,t,n)=>{let r=n===void 0?t:n,i=Math.min(t-r,e-Math.floor(r/2));i<0&&(i=0);let a=Math.min(i+r,t);return{startIndex:i,endIndex:a}},X6=nG(`effect/cli/TerminalCapabilities`,{defaultValue:()=>xYe()}),Z6=e=>e!==void 0&&e.length>0,yYe=e=>Z6(e)&&e!==`0`&&e.toLowerCase()!==`false`,bYe=e=>e.term===`dumb`?{canColor:!1,canAnimate:!1,canPrompt:!1}:{canColor:!Z6(e.noColor)&&(yYe(e.forceColor)||e.stdoutIsTerminal),canAnimate:e.stdoutIsTerminal,canPrompt:e.stdinIsTerminal&&e.stdoutIsTerminal},xYe=()=>{let e=globalThis.process;return bYe({noColor:e?.env?.NO_COLOR,forceColor:e?.env?.FORCE_COLOR,term:e?.env?.TERM,stdinIsTerminal:e?.stdin?.isTTY===!0,stdoutIsTerminal:e?.stdout?.isTTY===!0})},Q6=`~effect/cli/Param`,$6=`flag`,e8={[Q6]:{_A:YV},pipe(){return KV(this,arguments)}},SYe=e=>yH(e,Q6),t8=e=>e.kind===`flag`,n8=e=>{let t=t=>e.kind===`argument`?FYe(e.name,e.primitiveType,t):IYe(e.name,e.primitiveType,t);return Object.setPrototypeOf({_tag:`Single`,...e,description:e.description??G(),aliases:e.aliases??[],hidden:e.hidden??!1,annotations:e.annotations??KW(),parse:t},e8)},CYe=(e,t)=>n8({name:t,primitiveType:Vqe,kind:e}),wYe=(e,t)=>n8({name:t,primitiveType:Bqe,kind:e}),TYe=(e,t,n)=>n8({name:t,primitiveType:Hqe(n),kind:e}),EYe=/^-+/,DYe=W(2,(e,t)=>o8(e,e=>n8({...e,aliases:[...e.aliases,t.replace(EYe,``)]}))),OYe=W(2,(e,t)=>o8(e,e=>n8({...e,description:CW(t)}))),kYe=W(2,(e,t)=>Object.assign(Object.create(e8),{_tag:`Map`,kind:e.kind,param:e,f:t,parse:n=>PX(e.parse(n),([e,n])=>[e,t(n)])})),r8=(e,t,n=[],r)=>{let i=n.map(e=>()=>e().parse);return Object.assign(Object.create(e8),{_tag:`Transform`,kind:e.kind,param:e,alternatives:n,f:t,fallback:r,parse:t(e.parse,i)})},AYe=W(2,(e,t)=>r8(e,e=>n=>Y(e(n),([e,n])=>t(n).pipe(PX(t=>[e,t]))))),i8=e=>Object.assign(Object.create(e8),{_tag:`Optional`,kind:e.kind,param:e,parse:t=>e.parse(t).pipe(PX(([e,t])=>[e,CW(t)]),bBe({MissingOption:()=>q([t.arguments,G()]),MissingArgument:()=>q([t.arguments,G()])}))}),jYe=W(2,(e,t)=>gX(t)?r8(i8(e),e=>n=>Y(e(n),([e,n])=>EW(n,{onNone:()=>PX(t,t=>[e,t]),onSome:t=>q([e,t])})),[],{_tag:`DefaultEffect`}):r8(i8(e),e=>n=>PX(e(n),([e,n])=>[e,DW(n,()=>t)]),[],{_tag:`Default`,value:t})),MYe=(e,t)=>{let n=c8(e);return Object.assign(Object.create(e8),{_tag:`Variadic`,kind:e.kind,param:e,min:kW(t?.min),max:kW(t?.max),parse:r=>n.kind===`argument`?LYe(e,n,r,t):RYe(e,n,r,t)})},NYe=W(2,(e,t)=>o8(e,e=>n8({...e,typeName:t}))),PYe=W(2,(e,t)=>{let n=H4(t);return AYe(e,t=>HX(n(t),n=>{let r=c8(e);return new G3({option:r.name,value:globalThis.String(t),expected:`Schema validation failed: ${n.message}`,kind:r.kind})}))}),FYe=X(function*(e,t,n){if(n.arguments.length===0)return yield*new U3({argument:e});let r=n.arguments[0],i=yield*HX(t.parse(r),t=>new G3({option:e,value:r,expected:t,kind:`argument`}));return[n.arguments.slice(1),i]}),IYe=X(function*(e,t,n){let r=n.flags[e];if(r===void 0||r.length===0)return yield*new H3({option:e});if(r.length>1)return yield*new G3({option:e,value:`${r.length} occurrences`,expected:`at most 1 value`,kind:`flag`});let i=r[0],a=yield*HX(t.parse(i),t=>new G3({option:e,value:i,expected:t,kind:`flag`}));return[n.arguments,a]}),LYe=X(function*(e,t,n,r){let i=[],a=r?.min??0,o=r?.max??1/0,s=0,c=n.arguments;for(;c.length>0&&s<o;){let[t,r]=yield*e.parse({flags:n.flags,arguments:c});i.push(r),c=t,s++}return s<a?yield*s===0?new U3({argument:t.name}):new G3({option:t.name,value:`${s} values`,expected:`at least ${a} value${a===1?``:`s`}`,kind:t.kind}):[c,i]}),RYe=X(function*(e,t,n,r){let i=[],a=[t.name,...t.aliases].flatMap(e=>n.flags[e]??[]),o=a.length;if(hH(r?.min)&&o<r.min)return yield*o===0?new H3({option:t.name}):new G3({option:t.name,value:`${o} occurrences`,expected:`at least ${r.min} value${r.min===1?``:`s`}`,kind:t.kind});if(hH(r?.max)&&o>r.max)return yield*new G3({option:t.name,value:`${o} occurrences`,expected:`at most ${r.max} value${r.max===1?``:`s`}`,kind:t.kind});for(let n of a){let[,r]=yield*e.parse({flags:{[t.name]:[n]},arguments:[]});i.push(r)}return[n.arguments,i]}),a8=(e,t)=>{let n=e;switch(n._tag){case`Single`:return t.Single(n);case`Map`:return t.Map(n);case`Transform`:return t.Transform(n);case`Optional`:return t.Optional(n);case`Variadic`:return t.Variadic(n)}},o8=(e,t)=>a8(e,{Single:e=>t(e),Map:e=>kYe(o8(e.param,t),e.f),Transform:e=>r8(o8(e.param,t),e.f,e.alternatives.map(e=>()=>o8(e(),t)),e.fallback),Optional:e=>i8(o8(e.param,t)),Variadic:e=>MYe(o8(e.param,t),{min:AW(e.min),max:AW(e.max)})}),s8=e=>a8(e,{Single:e=>[e],Map:e=>s8(e.param),Transform:e=>[...s8(e.param),...e.alternatives.flatMap(e=>s8(e()))],Optional:e=>s8(e.param),Variadic:e=>s8(e.param)}),c8=e=>{let t=s8(e);if(t.length===0)throw Error(`No Single param found in param structure`);if(t.length>1)throw Error(`Multiple Single params found: ${t.map(e=>e.name).join(`, `)}`);return t[0]},l8=e=>{let t=u8(e);return{...t,isRequired:!t.isOptional&&(!t.isVariadic||MW(t.variadicMin,e=>e>0))}},u8=e=>a8(e,{Single:()=>({isOptional:!1,isVariadic:!1,variadicMin:G(),variadicMax:G()}),Map:e=>u8(e.param),Transform:e=>u8(e.param),Optional:e=>({...u8(e.param),isOptional:!0}),Variadic:e=>({...u8(e.param),isVariadic:!0,variadicMin:e.min,variadicMax:e.max})}),d8=nG(`effect/cli/CliOutput`,{defaultValue:()=>m8()}),zYe={present:X(function*(e){let t=yield*XX(),n=YW(t,d8)??m8({colors:QW(t,X6).canColor});switch(e._tag){case`Help`:return yield*A3(n.formatHelpDoc(e.helpDoc));case`InvalidInvocation`:return yield*A3(n.formatHelpDoc(e.helpDoc)),yield*k3(n.formatErrors(e.errors));case`Version`:return yield*A3(n.formatVersion(e.name,e.version))}})},f8=nG(`effect/cli/CliOutput/Presenter`,{defaultValue:()=>zYe}),p8=e=>e.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g,e=>`\\x${e.charCodeAt(0).toString(16).padStart(2,`0`)}`),m8=e=>{let t=e?.colors??l6(),n={inheritedFlags:e?.inheritedFlags??`full`,globalFlags:e?.globalFlags??`full`},r=t?{bold:e=>`\x1b[1m${e}\x1b[0m`,dim:e=>`\x1b[2m${e}\x1b[0m`,cyan:e=>`\x1b[36m${e}\x1b[0m`,green:e=>`\x1b[32m${e}\x1b[0m`,blue:e=>`\x1b[34m${e}\x1b[0m`,yellow:e=>`\x1b[33m${e}\x1b[0m`,magenta:e=>`\x1b[35m${e}\x1b[0m`}:{bold:e=>e,dim:e=>e,cyan:e=>e,green:e=>e,blue:e=>e,yellow:e=>e,magenta:e=>e},i=t?`\x1B[0m`:``,a=t?`\x1B[31m`:``,o=t?`\x1B[1m`:``;return{formatHelpDoc:e=>qYe(e,r,n),formatCliError:e=>p8(e.message),formatError:e=>`\n${o}${a}ERROR${i}\n ${p8(e.message)}${i}`,formatErrors:e=>{if(e.length===0)return``;if(e.length===1)return`\n${o}${a}ERROR${i}\n ${p8(e[0].message)}${i}`;let t=new Map;for(let n of e){let e=n._tag??`Error`,r=t.get(e)??[];r.push(n),t.set(e,r)}let n=[];n.push(`\n${o}${a}ERRORS${i}`);for(let[,e]of t)for(let t of e)n.push(` ${p8(t.message)}${i}`);return n.join(`
624
+ `)},formatVersion:(e,t)=>`${r.bold(e)} ${r.dim(`v`)}${r.bold(t)}`}},BYe=e=>e.replace(/\u001B\[[0-9;]*m/g,``),VYe=new Intl.Segmenter(void 0,{granularity:`grapheme`}),HYe=/[\p{Mark}\p{Control}\p{Default_Ignorable_Code_Point}]/gu,UYe=/\p{Emoji_Presentation}/u,WYe=e=>e<4352?!1:e<=4447||e===9001||e===9002||e>=11904&&e<=12350||e>=12352&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=110592&&e<=111359||e>=127488&&e<=127569||e>=131072&&e<=262141,GYe=e=>{let t=e.replace(HYe,``);return t.length===0?0:UYe.test(e)||e.includes(`️`)||WYe(t.codePointAt(0))?2:1},h8=e=>{let t=0;for(let{segment:n}of VYe.segment(BYe(e)))t+=GYe(n);return t},KYe=(e,t)=>{let n=h8(e),r=Math.max(0,t-n);return e+` `.repeat(r)},g8=(e,t)=>{let n=Math.max(...e.map(e=>h8(e.left)))+4,r=t===void 0?n:Math.min(n,t);return e.map(({left:e,right:t})=>` ${KYe(e,Math.max(r,h8(e)+1))}${t}`).join(`
625
+ `)},_8=(e,t)=>t?`${e}, ${t}`:e,qYe=(e,t,n)=>{let r=[];if(e.description&&(r.push(t.bold(`DESCRIPTION`)),r.push(` ${e.description}`),r.push(``)),r.push(t.bold(`USAGE`)),r.push(` ${t.cyan(e.usage)}`),r.push(``),e.args&&e.args.length>0){r.push(t.bold(`ARGUMENTS`));let n=e.args.map(e=>{let n=e.name;e.variadic&&(n+=`...`);let r=`${t.green(n)} ${t.dim(e.type)}`,i=e.required?``:t.dim(` (optional)`);return{left:r,right:DW(e.description,()=>``)+i}});r.push(g8(n,25)),r.push(``)}let i=(e,n)=>{r.push(t.bold(e)),r.push(g8(n.map(e=>({left:[`--${e.name}`,...e.aliases].map(t.green).join(`, `)+(e.type===`boolean`?``:` ${t.dim(e.type)}`),right:DW(e.description,()=>``)})))),r.push(``)},a=[],o=(e,t,n,r)=>{t&&t.length!==0&&n!==`none`&&(n===`summary`&&r&&r.length>0?a.push(`Run '${r.join(` `)} --help' for ${e.toLowerCase()}`):i(e,t))};e.flags.length>0&&i(`FLAGS`,e.flags);let s=e.commandPath;o(`INHERITED FLAGS`,e.inheritedFlags,n.inheritedFlags,s?.slice(0,-1));let c=e.globalFlagsScope??s?.slice(0,1),l=s===void 0||c?.length===s.length;if(o(`GLOBAL FLAGS`,e.globalFlags,l?`full`:n.globalFlags,c),a.length>0&&r.push(...a,``),e.subcommands&&e.subcommands.length>0){let n=e.subcommands.find(e=>e.group===void 0);n&&(r.push(t.bold(`SUBCOMMANDS`)),r.push(g8(n.commands.map(e=>({left:t.cyan(_8(e.name,e.alias)),right:e.shortDescription??e.description})),20)),e.subcommands.length>1&&r.push(``));for(let n of e.subcommands)n.group!==void 0&&(r.push(t.bold(`${n.group}:`)),r.push(g8(n.commands.map(e=>({left:t.cyan(_8(e.name,e.alias)),right:e.shortDescription??e.description})),20)),r.push(``))}if(e.examples&&e.examples.length>0){r.push(t.bold(`EXAMPLES`));let n=!0,i=!1;for(let a of e.examples)a.description?(n||r.push(``),r.push(` ${t.dim(`# ${a.description}`)}`)):i&&r.push(``),r.push(` ${t.cyan(a.command)}`),n=!1,i=!!a.description;r.push(``)}return r[r.length-1]===``&&r.pop(),r.join(`
626
+ `)},v8=`~effect/cli/Command/Config/Internal`,y8=e=>{let t=[],n=[],r=[];function i(e){let t=Object.create(null);for(let n of Object.keys(e))t[n]=a(e[n]);return t}function a(e){if(Array.isArray(e))return{_tag:`Array`,children:e.map(e=>a(e))};if(SYe(e)){let i=t.length;return t.push(e),e.kind===`argument`?r.push(e):n.push(e),{_tag:`Param`,index:i}}return{_tag:`Nested`,tree:i(e)}}return{[v8]:v8,flags:n,arguments:r,orderedParams:t,tree:i(e)}},JYe=y8({}),b8=(e,t)=>{let n={};for(let t of Object.keys(e))lU(n,t,r(e[t]));return n;function r(e){switch(e._tag){case`Param`:return t[e.index];case`Array`:return e.children.map(e=>r(e));case`Nested`:return b8(e.tree,t)}}},x8=`~effect/cli/Command`,S8=e=>e,YYe={...nW({label:`Command`,evaluate(){return S8(this).service}})},C8=e=>{let t=e.config,n=e.contextConfig??JYe,r=e.service??PW(`~effect/cli/Command/${e.name}`),i=e.annotations??KW(),a=e.globalFlags??[],o=e.subcommands??[],s=e.resolveExamples??XYe,c=(t,n)=>hH(e.handle)?e.handle(t,n):J(new J3({commandPath:n,errors:[]})),l=e.parse??T8(t),u=e.parseContext??T8(n,{allowLeftovers:!0}),d=n=>{let r=[],a=[];for(let e of t.arguments){let t=s8(e),n=l8(e);for(let e of t)r.push({name:e.name,type:e.typeName??Z3(e.primitiveType),description:e.description,required:n.isRequired,variadic:n.isVariadic})}let c=n.length>0?n.join(` `):e.name;o.some(e=>e.commands.some(e=>!e.unlisted))&&(c+=` <subcommand>`),c+=` [flags]`;for(let e of r){let t=e.variadic?`<${e.name}...>`:`<${e.name}>`;c+=` ${e.required?t:`[${t}]`}`}for(let e of t.flags){let t=s8(e),n=l8(e);for(let e of t)e.hidden||a.push(w8(e,n))}let l=[];for(let e of o){let t=e.commands.filter(e=>!e.unlisted);t.length!==0&&l.push({group:e.group,commands:_G(t,e=>({name:e.name,alias:e.alias,shortDescription:e.shortDescription,description:e.description??``}))})}let u=s(n);return{description:e.description??``,usage:c,flags:a,annotations:i,...r.length>0&&{args:r},...l.length>0&&{subcommands:l},...u.length>0&&{examples:u}}};return Object.assign(Object.create(YYe),{[x8]:x8,name:e.name,examples:s([e.name]),resolveExamples:s,annotations:i,globalFlags:a,subcommands:o,unlisted:e.unlisted??!1,config:t,contextConfig:n,service:r,parse:l,parseContext:u,handle:c,buildHelpDoc:d,...hH(e.description)?{description:e.description}:{},...hH(e.shortDescription)?{shortDescription:e.shortDescription}:{},...hH(e.alias)?{alias:e.alias}:{}})},XYe=()=>[],w8=(e,t)=>{let n=e.aliases.map(e=>e.length===1?`-${e}`:`--${e}`),r=e.typeName??Z3(e.primitiveType);return{name:e.name,aliases:n,type:e.optionalValue===void 0?r:`[=${r}]`,description:ZYe(e.description,Q3(e.primitiveType)),required:e.primitiveType._tag!==`Boolean`&&!t.isOptional}},ZYe=(e,t)=>{if(t===void 0||t.length===0)return e;let n=`(choices: ${t.join(`, `)})`;return EW(e,{onNone:()=>CW(n),onSome:e=>CW(`${e} ${n}`)})},T8=(e,t)=>X(function*(n){let r={flags:n.flags,arguments:n.arguments},[i,a]=yield*QYe(r,e.orderedParams);return t?.allowLeftovers!==!0&&i.length>0?yield*new W3({arguments:i}):b8(e.tree,a)}),QYe=X(function*(e,t){let n=[],r=e.arguments;for(let i of t){let[t,a]=yield*i.parse({flags:e.flags,arguments:r});n.push(a),r=t}return[r,n]}),$Ye=(e,t,n)=>{let r=S8(e),i=new Set;(e=>{for(let t of e){let e=s8(t);for(let t of e)i.add(t.name)}})((n?.contextConfig??r.contextConfig).flags);for(let n of t){let t=S8(n);for(let r of t.config.flags){let t=s8(r);for(let r of t)if(i.has(r.name))throw new V3({option:r.name,parentCommand:e.name,childCommand:n.name})}}},eXe=e=>{switch(e.primitiveType._tag){case`Boolean`:return{_tag:`Boolean`};case`Int`:return{_tag:`Int`};case`Finite`:return{_tag:`Finite`};case`Date`:return{_tag:`Date`};case`Choice`:return{_tag:`Choice`,values:Q3(e.primitiveType)??[]};case`Path`:return{_tag:`Path`,pathType:$3(e.primitiveType)??`either`};case`FileText`:case`FileParse`:case`FileSchema`:return{_tag:`Path`,pathType:`file`};default:return{_tag:`String`}}},tXe=e=>{switch(e.primitiveType._tag){case`Int`:return{_tag:`Int`};case`Finite`:return{_tag:`Finite`};case`Date`:return{_tag:`Date`};case`Choice`:return{_tag:`Choice`,values:Q3(e.primitiveType)??[]};case`Path`:return{_tag:`Path`,pathType:$3(e.primitiveType)??`either`};case`FileText`:case`FileParse`:case`FileSchema`:return{_tag:`Path`,pathType:`file`};default:return{_tag:`String`}}},E8=(e,t)=>{let n=e;switch(n._tag){case`Single`:return[[n,t===!0]];case`Map`:case`Optional`:return E8(n.param,t);case`Transform`:return[...E8(n.param,t),...n.alternatives.flatMap(e=>E8(e(),t))];case`Variadic`:return E8(n.param,t??!MW(n.max,e=>e<=1))}},D8=(e,t=[])=>{let n=S8(e),r=n.config,i=[],a=new Set;for(let[e,n]of[...r.flags,...t].entries())for(let[t,o]of E8(n))t.hidden||e>=r.flags.length&&a.has(t.name)||(a.add(t.name),i.push({name:t.name,aliases:t.aliases,description:AW(t.description),type:eXe(t),optionalValue:t.optionalValue!==void 0,repeatable:o,negation:t.negation}));let o=[];for(let e of r.arguments){let t=s8(e),n=l8(e);for(let e of t)e.kind===`argument`&&o.push({name:e.name,description:AW(e.description),required:!n.isOptional&&(!n.isVariadic||MW(n.variadicMin,e=>e>0)),variadic:n.isVariadic,type:tXe(e)})}let s=[],c=[...t,...n.contextConfig.flags];for(let t of e.subcommands)for(let e of t.commands){if(e.unlisted)continue;let t=D8(e,c);s.push(t),e.alias&&e.alias!==e.name&&s.push({...t,name:e.alias})}return{name:e.name,description:e.shortDescription??e.description,flags:i,arguments:o,subcommands:s}},O8=e=>e.type._tag!==`Boolean`&&e.optionalValue!==!0,k8=e=>e.type._tag!==`Boolean`||e.negation===!1?void 0:e.negation??`no-${e.name}`,A8=e=>e.replace(/'/g,`'\\''`),j8=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),M8=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let n=k8(e);return n!==void 0&&t.push(`--${n}`),t},nXe=(e,t)=>{if(e.length===0)return;let n=e.map(M8);t.push(` local ${n.map((e,t)=>`_used_${t}=""`).join(` `)}`),t.push(` for ((i = 1; i < cword; i++)); do`),t.push(' case "${words[i]%%=*}" in'),n.forEach((e,n)=>{t.push(` ${e.join(`|`)}) _used_${n}=1 ;;`)}),t.push(` esac`),t.push(` done`),t.push(` local _filtered_flags=""`),n.forEach((n,r)=>{let i=e[r].repeatable===!0?``:`[[ -n "$_used_${r}" ]] || `;t.push(` ${i}_filtered_flags+=" ${n.join(` `)}"`)}),t.push(``)},N8=e=>[`\\\\`,`\\"`,`\\'`].map(t=>`${e}=\${${e}//${t}/}`).join(`; `),rXe=(e,t)=>{t.push(`${e}()`),t.push(`{`),t.push(` local _cur="$1" _word="$2"; shift 2`),t.push(``),t.push(' local _head="${_cur%"$_word"}"'),t.push(` local _open=""`),t.push(` case "$_head" in`),t.push(` *\\') _open="'" ;;`),t.push(` *\\") _open='"' ;;`),t.push(` esac`),t.push(``),t.push(` local _prefix="$_cur" _committed="$_head"`),t.push(` ${N8(`_prefix`)}`),t.push(` ${N8(`_committed`)}`),t.push(``),t.push(` COMPREPLY=()`),t.push(` local _choice _rest _match`),t.push(` for _choice in "$@"; do`),t.push(` [[ "$_choice" == "$_prefix"* ]] || continue`),t.push(' _rest="${_choice#"$_committed"}"'),t.push(` case "$_open" in`),t.push(` "'")`),t.push(` if [[ "$_head" == "'" ]]; then`),t.push(" _match=${_rest//\\'/\\'\\\\\\'\\'}"),t.push(` else`),t.push(` [[ "$_rest" == *\\'* ]] && continue`),t.push(` _match="$_rest"`),t.push(` fi`),t.push(` ;;`),t.push(` '"')`),t.push(' _match="${_rest//\\\\/\\\\\\\\}"'),t.push(' _match="${_match//\\$/\\\\$}"'),t.push(' _match="${_match//\\`/\\\\\\`}"'),t.push(' _match="${_match//\\"/\\\\\\"}"'),t.push(` ;;`),t.push(` *)`),t.push(` printf -v _match '%q' "$_rest"`),t.push(` [[ -z "$_head" && "$_match" == '~'* ]] && _match="\\\\$_match"`),t.push(` ;;`),t.push(` esac`),t.push(` [[ -n "$_open" && "$_match" == *"$_open" ]] && _match+="$_open"`),t.push(` COMPREPLY+=("$_match")`),t.push(` done`),t.push(`}`),t.push(``)},iXe=(e,t)=>{t.push(`${e.paths}()`),t.push(`{`),t.push(` local _kind="$1" _cur="$2" _word="$3"`),t.push(``),t.push(' local _prefix="$_cur" _committed="${_cur%"$_word"}"'),t.push(` ${N8(`_prefix`)}`),t.push(` ${N8(`_committed`)}`),t.push(``),t.push(` local _typed="" _dir="$_committed" _open="" _i`),t.push(` if [[ "$_word" == */* ]]; then`),t.push(' _typed="${_word%/*}/"'),t.push(' _dir="${_prefix%/*}/"'),t.push(` if [[ "$_cur" == "$_word" ]]; then`),t.push(" for ((_i = 0; _i < ${#_typed}; _i++)); do"),t.push(' case "$_open${_typed:_i:1}" in'),t.push(` \\\\|\\"\\\\) ((_i += 1)) ;;`),t.push(` \\"|\\') _open="\${_typed:_i:1}" ;;`),t.push(` \\"\\"|\\'\\') _open="" ;;`),t.push(` esac`),t.push(` done`),t.push(` fi`),t.push(` fi`),t.push(``),t.push(' local _path _names=() _rest="${_word#"$_typed"}"'),t.push(` while IFS= read -r _path; do`),t.push(` if [[ "$_path" == "$_dir"* ]]; then`),t.push(' _names+=("$_committed${_path#"$_dir"}")'),t.push(` elif [[ -z "$_committed" ]]; then`),t.push(` _names+=("$_path")`),t.push(` _typed="" _rest="" _open=""`),t.push(` fi`),t.push(` done < <(compgen "$_kind" -- "$_prefix")`),t.push(` if [[ -n "$_open" ]]; then`),t.push(` _typed+="$_open"`),t.push(' _rest="${_prefix##*/}"'),t.push(` fi`),t.push(``),t.push(` ${e.choices} "\${_cur%"$_word"}$_rest" "$_rest" "\${_names[@]}"`),t.push(" for ((_i = 0; _i < ${#COMPREPLY[@]}; _i++)); do"),t.push(' COMPREPLY[_i]="$_typed${COMPREPLY[_i]}"'),t.push(` done`),t.push(`}`),t.push(``)},P8=(e,t)=>`${t.choices} "$cur" "$_comp_word" ${e.map(e=>`'${A8(e)}'`).join(` `)}`,F8=(e,t)=>{switch(e._tag){case`Choice`:return P8(e.values,t);case`Path`:return`${t.paths} ${e.pathType===`directory`?`-d`:`-f`} "$cur" "$_comp_word"`;default:return}},I8=(e,t,n,r)=>{let i=[...t,e.name],a=`_${i.map(j8).join(`_`)}`;n.push(`${a}()`),n.push(`{`),n.push(` local cur prev words cword i`),n.push(t.length===0?` local _command_index=0`:` local _command_index="$1"`),n.push(` _init_completion -n "$COMP_WORDBREAKS" || return`),t.length===0&&n.push(` local _comp_word="$2"`),n.push(``);let o=e.flags.filter(O8);if(o.length>0){n.push(` # Flag value completions`),n.push(` case "$prev" in`);for(let e of o){let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let i=F8(e.type,r);i&&(n.push(` ${t.join(`|`)})`),n.push(` ${i}`),n.push(` return`),n.push(` ;;`))}n.push(` esac`),n.push(``)}if(e.subcommands.length>0){n.push(` # Subcommand dispatch`),n.push(` local cmd _skip_next=0`),n.push(` for ((i = _command_index + 1; i < cword; i++)); do`),n.push(` if (( _skip_next )); then`),n.push(` _skip_next=0`),n.push(` continue`),n.push(` fi`),n.push(' case "${words[i]}" in');for(let t of e.flags){if(!O8(t))continue;let e=M8(t);n.push(` ${e.join(`|`)}) _skip_next=1 ;;`),n.push(` ${e.map(e=>`${e}=*`).join(`|`)}) ;;`)}for(let t of e.subcommands){let e=`_${[...i,t.name].map(j8).join(`_`)}`;n.push(` ${t.name})`),n.push(` ${e} "$i"`),n.push(` return`),n.push(` ;;`)}n.push(` esac`),n.push(` done`),n.push(``)}nXe(e.flags,n),(e.flags.length>0||e.subcommands.length>0)&&(n.push(` # Complete flags (filtered) and subcommands`),n.push(` if [[ "$cur" == -* ]]; then`),e.flags.length>0&&n.push(` COMPREPLY=( $(compgen -W "$_filtered_flags" -- "$cur") )`),n.push(` return`),n.push(` fi`),n.push(``));let s=e.arguments.flatMap((e,t)=>{let n=F8(e.type,r);return n===void 0?[]:[{argument:e,completion:n,index:t}]});if(s.length>0){n.push(` # Positional argument completions`),n.push(` local _position=0 _skip_next=0 _end_of_options=0`),n.push(` for ((i = _command_index + 1; i < cword; i++)); do`),n.push(` if (( _skip_next )); then`),n.push(` _skip_next=0`),n.push(` continue`),n.push(` fi`),n.push(` if (( _end_of_options )); then`),n.push(` ((_position += 1))`),n.push(` continue`),n.push(` fi`),n.push(' case "${words[i]}" in'),n.push(` --) _end_of_options=1 ;;`);for(let t of e.flags){let e=M8(t);O8(t)?(n.push(` ${e.join(`|`)}) _skip_next=1 ;;`),n.push(` ${e.map(e=>`${e}=*`).join(`|`)}) ;;`)):n.push(` ${e.join(`|`)}) ;;`)}n.push(` -*) ;;`),n.push(` *) ((_position += 1)) ;;`),n.push(` esac`),n.push(` done`),n.push(` case "$_position" in`);for(let{argument:e,completion:t,index:r}of s)e.variadic||(n.push(` ${r})`),n.push(` ${t}`),n.push(` return`),n.push(` ;;`));n.push(` esac`);let t=s.find(({argument:e})=>e.variadic);t!==void 0&&(n.push(` if (( _position >= ${t.index} )); then`),n.push(` ${t.completion}`),n.push(` return`),n.push(` fi`))}else e.subcommands.length>0&&n.push(` ${P8(e.subcommands.map(e=>e.name),r)}`);n.push(`}`),n.push(``);for(let t of e.subcommands)I8(t,i,n,r)},aXe=(e,t)=>{let n=[],r=j8(e),i={choices:`_${r}--choices`,paths:`_${r}--paths`};return n.push(`###-begin-${A8(e)}-completions-###`),n.push(`#`),n.push(`# Static completion script for Bash`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${A8(e)} --completions bash >> ~/.bashrc`),n.push(`#`),n.push(``),n.push(`if ! type _init_completion &>/dev/null; then`),n.push(` _init_completion()`),n.push(` {`),n.push(` COMPREPLY=()`),n.push(` local _i _j=0 _piece _line="$COMP_LINE"`),n.push(' words=("${COMP_WORDS[0]}")'),n.push(` cword=0`),n.push(' _line="${_line#*"${COMP_WORDS[0]}"}"'),n.push(" for ((_i = 1; _i < ${#COMP_WORDS[@]}; _i++)); do"),n.push(' _piece="${COMP_WORDS[_i]}"'),n.push(` if [[ "$_line" == [[:blank:]]* ]]; then`),n.push(` ((_j++))`),n.push(` words[_j]="$_piece"`),n.push(` else`),n.push(' words[_j]="${words[_j]}$_piece"'),n.push(` fi`),n.push(` ((_i == COMP_CWORD)) && cword=$_j`),n.push(' _line="${_line#*"$_piece"}"'),n.push(` done`),n.push(' cur="${words[cword]}"'),n.push(` prev=""`),n.push(' ((cword > 0)) && prev="${words[cword-1]}"'),n.push(` return 0`),n.push(` }`),n.push(`fi`),n.push(``),rXe(i.choices,n),iXe(i,n),I8(t,[],n,i),n.push(`complete -F _${r} ${A8(e)}`),n.push(`###-end-${A8(e)}-completions-###`),n.join(`
627
+ `)},L8=e=>e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`),R8=e=>L8(e.replace(/[^A-Za-z0-9_.,/@%+-]/gu,`\\$&`)),oXe=(e,t)=>{if(e.length===0)return t.length>0?`__fish_use_subcommand`:``;let n=e.map(e=>`__fish_seen_subcommand_from ${e}`).join(`; and `);return t.length>0?`${n}; and not __fish_seen_subcommand_from ${t.join(` `)}`:n},z8=e=>{let t=[];for(let n of e.aliases)n.length===1&&t.push(`-s ${n}`);t.push(e.name);for(let n of e.aliases)n.length>1&&t.push(n);let n=k8(e);return n!==void 0&&t.push(n),`not __fish_contains_opt ${t.join(` `)}`},sXe=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);return`begin; ${z8(e)}; or contains -- (commandline -poc)[-1] ${t.join(` `)}; end`},cXe=e=>{let t=[`-l ${e.name}`];for(let n of e.aliases)n.length===1?t.push(`-s ${n}`):t.push(`-l ${n}`);e.description&&t.push(`-d '${L8(e.description)}'`);let n=O8(e)?lXe(e.type):void 0;return n&&t.push(n),t},lXe=e=>{switch(e._tag){case`Boolean`:return;case`Choice`:return`-r -f -a '${e.values.map(R8).join(` `)}'`;case`Path`:return e.pathType,`-r -F`;default:return`-r -f`}},uXe=e=>{switch(e._tag){case`Choice`:return`-r -f -a '${e.values.map(R8).join(` `)}'`;case`Path`:return`-r -F`;default:return}},B8=(e,t,n,r)=>{let i=t.subcommands.map(e=>e.name),a=oXe(n,i),o=a?`-n '${a}'`:``;if(!t.arguments.some(e=>e.type._tag===`Path`)){let t=[`complete -c ${e}`];o&&t.push(o),t.push(`-f`),r.push(t.join(` `))}for(let n of t.subcommands){let t=[`complete -c ${e}`];o&&t.push(o),t.push(`-f -a '${L8(n.name)}'`),n.description&&t.push(`-d '${L8(n.description)}'`),r.push(t.join(` `))}for(let n of t.flags){let t=[a,n.repeatable===!0?``:O8(n)?sXe(n):z8(n)].filter(e=>e!==``).join(`; and `),i=t?`-n '${t}'`:``,o=[`complete -c ${e}`];i&&o.push(i),o.push(...cXe(n)),r.push(o.join(` `));let s=k8(n);if(s!==void 0){let t=[`complete -c ${e}`];i&&t.push(i),t.push(`-l ${s}`),n.description&&t.push(`-d '${L8(`Disable ${n.name}`)}'`),r.push(t.join(` `))}}if(t.flags.length>0){let n=`not string match -q -- "-*" (commandline -ct)`,i=a?`${a}; and ${n}`:n;for(let n of t.flags){let t=n.repeatable===!0?i:`${i}; and ${z8(n)}`,a=k8(n),o=[`complete -c ${e}`];if(o.push(`-n '${t}'`),o.push(`-f -a '--${n.name}'`),n.description&&o.push(`-d '${L8(n.description)}'`),r.push(o.join(` `)),a!==void 0){let i=[`complete -c ${e}`];i.push(`-n '${t}'`),i.push(`-f -a '--${a}'`),n.description&&i.push(`-d '${L8(`Disable ${n.name}`)}'`),r.push(i.join(` `))}}}for(let n of t.arguments){let t=uXe(n.type);if(t){let i=[`complete -c ${e}`];o&&i.push(o),i.push(t),n.description&&i.push(`-d '${L8(n.description)}'`),r.push(i.join(` `))}}for(let i of t.subcommands)B8(e,i,[...n,i.name],r)},dXe=(e,t)=>{let n=[];return n.push(`###-begin-${e}-completions-###`),n.push(`#`),n.push(`# Static completion script for Fish`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${e} --completions fish > ~/.config/fish/completions/${e}.fish`),n.push(`#`),n.push(``),B8(e,t,[],n),n.push(``),n.push(`###-end-${e}-completions-###`),n.join(`
628
+ `)},V8=e=>{let t=[],n=``;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i>=32&&i<128){n+=e[r]===`'`?`''`:e[r];continue}(n!==``||t.length===0)&&t.push(`'${n}'`),n=``,t.push(`[char]0x${i.toString(16).toUpperCase().padStart(4,`0`)}`)}return(n!==``||t.length===0)&&t.push(`'${n}'`),t.length===1?t[0]:`(${t.join(` + `)})`},H8=e=>`@(${e.map(V8).join(`, `)})`,U8=e=>e?V8(e):`$null`,fXe=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),pXe=e=>[`--${e.name}`,...e.aliases.map(e=>e.length===1?`-${e}`:`--${e}`)],W8=e=>`values = ${H8(e._tag===`Choice`?e.values:[])}; pathType = ${e._tag===`Path`?V8(e.pathType):`$null`}`,mXe=e=>{let t=k8(e);return`@{ name = ${V8(e.name)}; forms = ${H8(pXe(e))}; takesValue = $${e.type._tag!==`Boolean`}; `+(t===void 0?``:`negation = ${V8(`--${t}`)}; `)+(e.optionalValue===!0?`optionalValue = $true; `:``)+(e.repeatable===!0?`repeatable = $true; `:``)+`${W8(e.type)}; description = ${U8(e.description)} }`},hXe=e=>`@{ name = ${V8(e.name)}; variadic = $${e.variadic}; ${W8(e.type)}; description = ${U8(e.description)} }`,G8=(e,t,n)=>{if(n.length===0){e.push(` ${t} = @()`);return}e.push(` ${t} = @(`);for(let t of n)e.push(` ${t}`);e.push(` )`)},K8=(e,t,n,r,i)=>{let a=n.join(` `);if(!i.has(a)){i.add(a),r.push(`${e}[${V8(a)}] = @{`),G8(r,`subcommands`,t.subcommands.map(e=>`@{ name = ${V8(e.name)}; description = ${U8(e.description)} }`)),G8(r,`flags`,t.flags.map(mXe)),G8(r,`arguments`,t.arguments.map(hXe)),r.push(`}`);for(let a of t.subcommands)K8(e,a,[...n,a.name],r,i)}},gXe=e=>String.raw` param($wordToComplete, $commandAst, $cursorPosition)
629
+
630
+ $spec = ${e}
631
+ $results = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()
632
+ $booleanLiterals = @('true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n')
633
+
634
+ $index = {
635
+ param($context)
636
+ $lookup = [hashtable]::new([System.StringComparer]::Ordinal)
637
+ foreach ($flag in $context.flags) {
638
+ foreach ($form in $flag.forms) { $lookup[$form] = $flag }
639
+ }
640
+ $lookup
641
+ }
642
+
643
+ $add = {
644
+ param([string]$value, [string]$type, $tooltip, [string]$typed, [string]$textPrefix)
645
+ if (-not $value.StartsWith($typed, [System.StringComparison]::OrdinalIgnoreCase)) { return }
646
+ $text = $value
647
+ if ($value -notmatch '^[\w./:%+=\\-]+$') { $text = "'" + ($value -replace "['\u2018-\u201b]", '$0$0') + "'" }
648
+ $text = $textPrefix + $text
649
+ $label = $value
650
+ if (-not $label) { $label = $text }
651
+ if (-not $tooltip) { $tooltip = $label }
652
+ $results.Add([System.Management.Automation.CompletionResult]::new($text, $label, $type, $tooltip))
653
+ }
654
+
655
+ $addValues = {
656
+ param($entry, [string]$typed, [string]$textPrefix)
657
+ foreach ($value in $entry.values) {
658
+ if ($textPrefix -eq '' -and (& $optionLike $value)) { continue }
659
+ & $add $value 'ParameterValue' $entry.description $typed $textPrefix
660
+ }
661
+ if ($entry.pathType) {
662
+ foreach ($file in [System.Management.Automation.CompletionCompleters]::CompleteFilename($typed)) {
663
+ if ($entry.pathType -eq 'directory' -and $file.ResultType -ne 'ProviderContainer') { continue }
664
+ $results.Add([System.Management.Automation.CompletionResult]::new($textPrefix + $file.CompletionText, $file.ListItemText, $file.ResultType, $file.ToolTip))
665
+ }
666
+ }
667
+ }
668
+
669
+ $addFlags = {
670
+ param([string]$typed)
671
+ foreach ($flag in $context.flags) {
672
+ if (-not $flag.repeatable -and $used.ContainsKey($flag.name)) { continue }
673
+ foreach ($form in $flag.forms) {
674
+ & $add $form 'ParameterName' $flag.description $typed ''
675
+ }
676
+ if ($flag.negation) {
677
+ $tooltip = $null
678
+ if ($flag.description) { $tooltip = 'Disable ' + $flag.name }
679
+ & $add $flag.negation 'ParameterName' $tooltip $typed ''
680
+ }
681
+ }
682
+ }
683
+
684
+ # As in the CLI lexer, nothing after '--' is an option, and negative numbers
685
+ # and a lone '-' are values.
686
+ $optionLike = {
687
+ param([string]$word)
688
+ -not $endOfOptions -and $word -match '^-.' -and $word -notmatch '^-(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$'
689
+ }
690
+
691
+ # A typed value that has no candidates completes to itself, so the engine
692
+ # does not fall back to listing files.
693
+ $keepTyped = {
694
+ if ($results.Count -eq 0 -and $current) {
695
+ $results.Add([System.Management.Automation.CompletionResult]::new($current, $current, 'ParameterValue', $current))
696
+ }
697
+ }
698
+
699
+ $path = ''
700
+ $context = $spec[$path]
701
+ $lookup = & $index $context
702
+ $used = [hashtable]::new([System.StringComparer]::Ordinal)
703
+ $pending = $null
704
+ $endOfOptions = $false
705
+ $position = 0
706
+
707
+ # The engine strips the quotes from a quoted word.
708
+ $typed = [string]$wordToComplete
709
+ if ($typed -match '^([''"])(.*?)\1?$') { $typed = $Matches[2] }
710
+ $current = $null
711
+
712
+ $elements = $commandAst.CommandElements
713
+ for ($i = 1; $i -lt $elements.Count; $i++) {
714
+ $element = $elements[$i]
715
+ $word = $element.Extent.Text
716
+ if ($element -is [System.Management.Automation.Language.StringConstantExpressionAst]) { $word = $element.Value }
717
+ if ($element.Extent.EndOffset -ge $cursorPosition) {
718
+ if ($element -is [System.Management.Automation.Language.ConstantExpressionAst] -and $element.Extent.StartOffset -le $cursorPosition) {
719
+ $current = $element.Extent.Text
720
+ if ($element.Extent.EndOffset -eq $cursorPosition) { $typed = $word }
721
+ }
722
+ break
723
+ }
724
+
725
+ # A flag takes the next word as its value unless it is an option or '--';
726
+ # a boolean flag only takes a boolean literal.
727
+ $isOption = & $optionLike $word
728
+ if ($null -ne $pending) {
729
+ $flag = $pending
730
+ $pending = $null
731
+ if ($flag.takesValue) {
732
+ if (-not $isOption) { continue }
733
+ } elseif ($booleanLiterals -ccontains $word) { continue }
734
+ }
735
+ if ($endOfOptions) { $position++; continue }
736
+ if ($word -ceq '--') { $endOfOptions = $true; continue }
737
+
738
+ if ($isOption) {
739
+ $hasValue = $word.Contains('=')
740
+ if ($hasValue) {
741
+ $forms = @($word.Substring(0, $word.IndexOf('=')))
742
+ } elseif ($word.StartsWith('--')) {
743
+ $forms = @($word)
744
+ } else {
745
+ $forms = @(foreach ($char in $word.Substring(1).ToCharArray()) { '-' + $char })
746
+ }
747
+ foreach ($form in $forms) {
748
+ $pending = $null
749
+ $flag = $lookup[$form]
750
+ # As in the CLI parser, a negation wins over an alias but not over a
751
+ # canonical name.
752
+ if ($null -eq $flag -or $form -cne ('--' + $flag.name)) {
753
+ $negated = $null
754
+ foreach ($candidate in $context.flags) {
755
+ if ($candidate.negation -ceq $form) { $negated = $candidate }
756
+ }
757
+ if ($null -ne $negated) {
758
+ $used[$negated.name] = $true
759
+ continue
760
+ }
761
+ }
762
+ if ($null -eq $flag) { continue }
763
+ $used[$flag.name] = $true
764
+ # A flag with an optional value only takes a value attached with '='.
765
+ if (-not $hasValue -and -not $flag.optionalValue) { $pending = $flag }
766
+ }
767
+ continue
768
+ }
769
+
770
+ if ($position -eq 0 -and $context.subcommands.name -ccontains $word) {
771
+ if ($path) { $path = $path + ' ' + $word } else { $path = $word }
772
+ $context = $spec[$path]
773
+ $lookup = & $index $context
774
+ $used = [hashtable]::new([System.StringComparer]::Ordinal)
775
+ continue
776
+ }
777
+ $position++
778
+ }
779
+
780
+ $typedIsOption = & $optionLike $typed
781
+ if ($null -ne $pending -and $pending.takesValue -and -not $typedIsOption) {
782
+ & $addValues $pending $typed ''
783
+ & $keepTyped
784
+ return $results
785
+ }
786
+
787
+ if ($typedIsOption) {
788
+ if ($typed -match '^(-[^=]+)=(.*)$') {
789
+ $form = $Matches[1]
790
+ $flag = $lookup[$form]
791
+ if ($null -ne $flag -and $flag.takesValue) {
792
+ & $addValues $flag $Matches[2] ($form + '=')
793
+ & $keepTyped
794
+ }
795
+ } else {
796
+ & $addFlags $typed
797
+ }
798
+ return $results
799
+ }
800
+
801
+ if (-not $endOfOptions -and $position -eq 0) {
802
+ foreach ($sub in $context.subcommands) {
803
+ & $add $sub.name 'Command' $sub.description $typed ''
804
+ }
805
+ }
806
+
807
+ $arguments = $context.arguments
808
+ if ($position -lt $arguments.Count) {
809
+ & $addValues $arguments[$position] $typed ''
810
+ } elseif ($arguments.Count -gt 0 -and $arguments[-1].variadic) {
811
+ & $addValues $arguments[-1] $typed ''
812
+ }
813
+
814
+ if (-not $endOfOptions) {
815
+ & $addFlags $typed
816
+ }
817
+ return $results`,_Xe=(e,t)=>{let n=`$global:_${fXe(e)}_Completions`,r=[];return r.push(`###-begin-${e}-completions-###`),r.push(`#`),r.push(`# Static completion script for PowerShell`),r.push(`#`),r.push(`# Installation:`),r.push(`# ${e} --completions powershell > ${e}-completion.ps1`),r.push(`# then add this line to your $PROFILE (use the full path to the file):`),r.push(`# . <PATH>\\${e}-completion.ps1`),r.push(`#`),r.push(``),r.push(`${n} = [hashtable]::new([System.StringComparer]::Ordinal)`),K8(n,t,[],r,new Set),r.push(``),r.push(`Register-ArgumentCompleter -Native -CommandName ${V8(e)} -ScriptBlock {`),r.push(gXe(n)),r.push(`}`),r.push(``),r.push(`###-end-${e}-completions-###`),r.join(`
818
+ `)},q8=e=>e.replace(/\\/g,`\\\\`).replace(/'/g,`'\\''`).replace(/:/g,`\\:`),J8=e=>q8(e).replace(/]/g,`\\]`),Y8=e=>e.replace(/[^A-Za-z0-9_.,/@%+-]/gu,`\\$&`).replace(/'/g,`'\\''`),X8=e=>e.replace(/[^a-zA-Z0-9_]/g,`_`),vXe=e=>{let t=[`--${e.name}`];for(let n of e.aliases)t.push(n.length===1?`-${n}`:`--${n}`);let n=k8(e);return n!==void 0&&t.push(`--${n}`),t},Z8=e=>{switch(e._tag){case`Boolean`:return``;case`Choice`:return`:value:(${e.values.map(Y8).join(` `)})`;case`Path`:return e.pathType===`directory`?`:directory:_directories`:`:file:_files`;case`Int`:return`:integer:`;case`Finite`:return`:float:`;case`Date`:return`:date:`;default:return`:value:`}},yXe=e=>{switch(e._tag){case`Choice`:return`(${e.values.map(Y8).join(` `)})`;case`Path`:return e.pathType===`directory`?`_directories`:`_files`;default:return``}},Q8=e=>{let t=[],n=e.description?`[${J8(e.description)}]`:``,r=e.optionalValue===!0&&e.type._tag!==`Boolean`,i=r?`=-`:``,a=r?`:${Z8(e.type)}`:Z8(e.type),o=e.repeatable===!0?`*`:`(${vXe(e).join(` `)})`;t.push(`'${o}--${e.name}${i}${n}${a}'`);for(let r of e.aliases){let e=r.length===1?`-`:`--`;t.push(`'${o}${e}${r}${i}${n}${a}'`)}let s=k8(e);if(s!==void 0){let n=e.description?`[${J8(`Disable ${e.name}`)}]`:``;t.push(`'${o}--${s}${n}'`)}return t},$8=e=>{let t=e.description?q8(e.description):e.name,n=yXe(e.type);return`'${e.variadic?`*`:``}:${t}:${n}'`},e5=(e,t,n)=>{let r=[...t,e.name],i=`_${r.map(X8).join(`_`)}`;if(n.push(`${i}() {`),e.subcommands.length>0){n.push(` local context state state_descr line`),n.push(` typeset -A opt_args`),n.push(``),n.push(` local -a commands`),n.push(` commands=(`);for(let t of e.subcommands){let e=t.description?q8(t.description):``;n.push(` '${q8(t.name)}:${e}'`)}n.push(` )`),n.push(``),n.push(` local -a specs`),n.push(` specs=(`);for(let t of e.flags)for(let e of Q8(t))n.push(` ${e}`);if(e.arguments.length>0){n.push(` -`),n.push(` parent-arguments`);for(let t of e.arguments)n.push(` ${$8(t)}`);n.push(` -`),n.push(` subcommands`)}n.push(` '1:command:->command'`),n.push(` '*::arg:->args'`),n.push(` )`),n.push(``),n.push(' _arguments -C "${specs[@]}"'),n.push(``),n.push(` case "$state" in`),n.push(` command)`),n.push(` _describe -t commands 'commands' commands`),n.push(` ;;`),n.push(` args)`),n.push(` case "$words[1]" in`);for(let t of e.subcommands){let e=`_${[...r,t.name].map(X8).join(`_`)}`;n.push(` ${t.name})`),n.push(` ${e}`),n.push(` ;;`)}n.push(` esac`),n.push(` ;;`),n.push(` esac`)}else{let t=[];for(let n of e.flags)t.push(...Q8(n));for(let n of e.arguments)t.push($8(n));if(t.length>0){n.push(` local -a specs`),n.push(` specs=(`);for(let e of t)n.push(` ${e}`);n.push(` )`),n.push(' _arguments "${specs[@]}"')}}n.push(`}`),n.push(``);for(let t of e.subcommands)e5(t,r,n)},bXe=(e,t)=>{let n=[],r=X8(e);return n.push(`#compdef ${e}`),n.push(`###-begin-${e}-completions-###`),n.push(`#`),n.push(`# Static completion script for Zsh`),n.push(`#`),n.push(`# Installation:`),n.push(`# ${e} --completions zsh > ~/.zsh/completions/_${e}`),n.push(`# then add ~/.zsh/completions to your fpath`),n.push(`#`),n.push(``),e5(t,[],n),n.push(`# Handle both direct invocation and autoload`),n.push('if [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]; then'),n.push(` _${r} "$@"`),n.push(`else`),n.push(` compdef _${r} ${e}`),n.push(`fi`),n.push(`###-end-${e}-completions-###`),n.join(`
819
+ `)},xXe=e=>D8(e),SXe=(e,t,n)=>{switch(t){case`bash`:return aXe(e,n);case`zsh`:return bXe(e,n);case`fish`:return dXe(e,n);case`powershell`:return _Xe(e,n)}},CXe=e=>CYe($6,e),t5=e=>wYe($6,e),n5=(e,t)=>TYe($6,e,t),r5=W(2,(e,t)=>DYe(e,t)),i5=W(2,(e,t)=>OYe(e,t)),a5=W(2,(e,t)=>NYe(e,t)),o5=e=>i8(e),s5=jYe,c5=W(2,(e,t)=>PYe(e,t)),l5=e=>{let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n},u5=(e,t)=>{let n=[e],r=e;for(let e=1;e<t.length;e++){let i=t[e],a;for(let e of r.subcommands)if(a=e.commands.find(e=>e.name===i),a)break;if(!a)break;n.push(a),r=a}return n},d5=(e,t,n)=>{let r=u5(e,t).flatMap(e=>S8(e).globalFlags);return l5([...n,...r])},wXe=e=>{let t=[],n=e=>{let r=S8(e);for(let e of r.globalFlags)t.push(e);for(let t of e.subcommands)for(let e of t.commands)n(e)};return n(e),l5(t)},TXe=(e,t)=>{if(e.length<=1)return[];let n=new Set(t.map(e=>e.name)),r=[];for(let t of e.slice(0,-1)){let e=S8(t);for(let t of e.contextConfig.flags){let e=s8(t),i=l8(t);for(let t of e)n.has(t.name)||t.hidden||(n.add(t.name),r.push(w8(t,i)))}}return r},EXe=(e,t)=>l5([...t,...wXe(e)]),f5=(e,t,n)=>TX(function*(){let r=u5(e,t),i=r.length>0?r[r.length-1]:e,a=S8(i).buildHelpDoc(t),o=TXe(r,a.flags),s=d5(e,t,n),c=[];for(let e of s){let t=s8(e.flag),n=l8(e.flag);for(let e of t)e.hidden||c.push({...w8(e,n),required:!1})}let l=1;for(let e=r.length-1;e>0;e--)if(S8(r[e]).globalFlags.length>0){l=e+1;break}return{...a,inheritedFlags:o,globalFlags:c,globalFlagsScope:t.slice(0,l),commandPath:t}}),p5=e=>({_tag:`Action`,flag:e.flag,run:e.run}),DXe=e=>t=>{m5+=1;let n=PW(`effect/cli/GlobalFlag/${e}/${m5}`);return Object.assign(n,{_tag:`Setting`,id:e,flag:t.flag})};let m5=0;const OXe=p5({flag:t5(`help`).pipe(r5(`h`),i5(`Show help information`),s5(!1)),run:X(function*(e,{builtIns:t,command:n,commandPath:r}){let i=yield*f8,a=yield*f5(n,r,t);yield*i.present({_tag:`Help`,reason:`Requested`,commandPath:r,helpDoc:a})})}),kXe=p5({flag:t5(`version`).pipe(r5(`v`),i5(`Show version information`),s5(!1)),run:X(function*(e,{command:t,version:n}){yield*(yield*f8).present({_tag:`Version`,name:t.name,version:n})})}),h5=p5({flag:t5(`wizard`).pipe(i5(`Start wizard mode for a command`),s5(!1)),run:()=>SX}),AXe=p5({flag:n5(`completions`,[[`bash`,`bash`],[`zsh`,`zsh`],[`fish`,`fish`],[`powershell`,`powershell`],[`sh`,`bash`],[`pwsh`,`powershell`]]).pipe(o5,a5(`<bash|zsh|fish|powershell|sh|pwsh>`),i5(`Print shell completion script`)),run:X(function*(e,{command:t}){if(wW(e))return;let n=xXe(t);yield*A3(SXe(t.name,e.value,n))})}),g5=DXe(`log-level`)({flag:n5(`log-level`,[[`all`,`All`],[`trace`,`Trace`],[`debug`,`Debug`],[`info`,`Info`],[`warn`,`Warn`],[`warning`,`Warn`],[`error`,`Error`],[`fatal`,`Fatal`],[`none`,`None`]]).pipe(o5,i5(`Sets the minimum log level`),a5(`<all|trace|debug|info|warn|warning|error|fatal|none>`))}),jXe=[OXe,kXe,h5,AXe,g5];var _5=class extends nG(`effect/cli/CliConfig`,{defaultValue:()=>MXe}){};const MXe={builtIns:jXe},NXe=EBe(e=>q(YW(e,d8)??m8({colors:QW(e,X6).canColor})));function PXe(e){let t=e.indexOf(`--`);return t===-1?{tokens:y5(e),trailingOperands:[]}:{tokens:y5(e.slice(0,t)),trailingOperands:e.slice(t+1)}}const FXe=e=>{if(e._tag===`Value`)return e.value;if(e._tag===`LongOption`)return e.raw;let t=v5.test(e.raw)?`--${e.flag}`:e.raw;return e.value===void 0?t:`${t}=${e.value}`},v5=/^-(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/,y5=e=>{let t=[];for(let n of e)if(!n.startsWith(`-`)||v5.test(n))t.push({_tag:`Value`,value:n});else if(n.startsWith(`--`)){let e=n.indexOf(`=`);if(e!==-1){let r=n.slice(2,e);if(r===``)t.push({_tag:`Value`,value:n});else{let i=n.slice(e+1);t.push({_tag:`LongOption`,name:r,raw:n,value:i})}}else t.push({_tag:`LongOption`,name:n.slice(2),raw:n})}else if(n.length>1){let e=n.slice(1),r=e.indexOf(`=`);if(r!==-1){let n=Array.from(e.slice(0,r)),i=n.pop()??``;for(let e of n)t.push({_tag:`ShortOption`,flag:e,raw:`-${e}`});t.push({_tag:`ShortOption`,flag:i,raw:`-${i}`,value:e.slice(r+1)})}else for(let n of e)t.push({_tag:`ShortOption`,flag:n,raw:`-${n}`})}else t.push({_tag:`Value`,value:n});return t},IXe=(e,t)=>{let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let e=0;e<=n;e++)i[e][0]=e;for(let e=0;e<=r;e++)i[0][e]=e;for(let a=1;a<=n;a++)for(let n=1;n<=r;n++){let r=e[a-1]===t[n-1]?0:1;i[a][n]=Math.min(i[a-1][n]+1,i[a][n-1]+1,i[a-1][n-1]+r)}return i[n][r]},b5=(e,t)=>{let n=t.map(t=>[IXe(e,t),t]).filter(([e])=>e<=2).sort(([e],[t])=>e-t);if(n.length===0)return[];let r=n[0][0];return n.filter(([e])=>e===r).map(([,e])=>e)},x5=e=>EW(e.subcommand,{onNone:()=>[],onSome:e=>[e.name,...x5(e.parsedInput)]}),S5=(e,t,n=[])=>TX(function*(){let{tokens:r,trailingOperands:i}=e,a=[...n,t.name],o=V5(r,B5(t,a));if(o._tag===`Leaf`)return{flags:o.flags,arguments:[...o.arguments,...i],subcommand:G(),...o.errors.length>0&&{errors:o.errors}};let s={tokens:o.childTokens,trailingOperands:i},c=yield*S5(s,o.sub,a),l=[...o.errors,...c.errors??[]];return{flags:o.flags,arguments:[],subcommand:CW({name:o.sub.name,parsedInput:c}),...l.length>0&&{errors:l}}}),C5=(e,t)=>{let n=V5(e,B5(t,[]));return n._tag===`Leaf`?e:C5(n.childTokens,n.sub)},w5=e=>{let t=0;return{peek:()=>e[t],take:()=>e[t++],rest:()=>e.slice(t)}},T5=e=>!Y3(e.primitiveType)||e.negation===!1?void 0:e.negation??`no-${e.name}`,E5=e=>{let t=new Map,n=new Map;for(let r of e){if(t.has(r.name))throw Error(`Duplicate flag name "${r.name}" in command definition`);t.set(r.name,r);for(let e of r.aliases){if(t.has(e))throw Error(`Duplicate flag/alias "${e}" in command definition (conflicts with "${t.get(e).name}")`);t.set(e,r)}let e=T5(r);if(e!==void 0){if(n.has(e))throw Error(`Duplicate negation "${e}" in command definition (conflicts with "${n.get(e).name}")`);n.set(e,r)}}return{params:e,index:t,negations:n}},D5=e=>{let t=new Map,n=(e,n)=>{let r=t.get(e);if(r&&r!==n)throw Error(`Duplicate subcommand name/alias "${e}" in command definition (conflicts with "${r.name}")`);t.set(e,n)};for(let t of e)for(let e of t.commands)n(e.name,e),e.alias&&e.alias!==e.name&&n(e.alias,e);return t},O5=e=>Object.fromEntries(e.map(e=>[e.name,[]])),LXe=e=>{let t=O5(e);return{add:(e,n)=>{n!==void 0&&t[e].push(n)},merge:e=>{for(let n in e){let r=e[n];if(r?.length)for(let e=0;e<r.length;e++)t[n].push(r[e])}},snapshot:()=>t}},k5=e=>e._tag===`LongOption`||e._tag===`ShortOption`,A5=e=>e._tag===`LongOption`?e.name:e.flag,j5=(e,t)=>{let n=A5(e),r=t.index.get(n);if(r&&r.name===n)return{param:r,negated:!1};let i=e._tag===`LongOption`?t.negations.get(e.name):void 0;if(i)return{param:i,negated:!0};if(r)return{param:r,negated:!1}},M5=(e,t,n)=>new G3({option:t.name,value:n,expected:`omit the value and use ${e.raw} by itself to set --${t.name} to false`,kind:`flag`}),RXe=e=>{let t=Q3(e.primitiveType);return new G3({option:e.name,value:``,expected:t===void 0?e.typeName??Z3(e.primitiveType):t.join(` | `),kind:`flag`})},N5=e=>e?._tag===`Value`&&(Rqe(e.value)||zqe(e.value))?e.value:void 0,P5=(e,t,n,r=!1)=>{let i=F5(e,t,n,r);switch(i._tag){case`Value`:return{_tag:`Value`,value:i.value};case`Error`:return{_tag:`Error`,error:i.error}}},F5=(e,t,n,r=!1)=>{if(r){if(t.value!==void 0)return{_tag:`Error`,error:M5(t,n,t.value),tokens:[]};let r=n.optionalValue===void 0?N5(e.peek()):void 0;if(r!==void 0){let i=e.take();return{_tag:`Error`,error:M5(t,n,r),tokens:i===void 0?[]:[i]}}return{_tag:`Value`,value:`false`,tokens:[]}}if(t.value!==void 0)return{_tag:`Value`,value:t.value,tokens:[]};if(n.optionalValue!==void 0)return{_tag:`Value`,value:n.optionalValue,tokens:[]};if(Y3(n.primitiveType)){let t=N5(e.peek()),n=t===void 0?void 0:e.take();return{_tag:`Value`,value:t??`true`,tokens:n===void 0?[]:[n]}}let i=e.peek();if(i?._tag===`Value`){let t=e.take();return{_tag:`Value`,value:i.value,tokens:t===void 0?[]:[t]}}return{_tag:`Error`,error:RXe(n),tokens:[]}},zXe=(e,t)=>{let n=O5(t.params),r=[],i=[],a=w5(e);for(let e=a.take();e;e=a.take()){if(!k5(e)){r.push(e);continue}let o=j5(e,t);if(!o){r.push(e);continue}let s=P5(a,e,o.param,o.negated);if(s._tag===`Error`){i.push(s.error);continue}s.value!==void 0&&n[o.param.name].push(s.value)}return{flagMap:n,remainder:r,errors:i}},I5=e=>S8(e).config.flags.flatMap(s8).filter(t8),L5=e=>S8(e).contextConfig.flags.flatMap(s8).filter(t8),R5=(e,t)=>{for(let n of t){let t=j5(e,n);if(t!==void 0)return t}},z5=(e,t,n,r)=>{e.push(n);let i=F5(t,n,r.param,r.negated);e.push(...i.tokens)},BXe=(e,t,n,r,i)=>{let a=w5(t);F5(a,e,n.param,n.negated);for(let e=a.take();e;e=a.take()){if(k5(e)){let t=R5(e,i);t!==void 0&&F5(a,e,t.param,t.negated);continue}if(e._tag===`Value`)return r.has(e.value)}return!1},VXe=(e,t,n)=>{let r=O5(n.params),i=[],a=(e,t,o)=>{let s=E5(I5(t)),c=E5(L5(t)),l=D5(t.subcommands),u=w5(e),d=[],f=!0;for(let e=u.take();e;e=u.take()){if(k5(e)){let t=R5(e,o);if(t!==void 0){z5(d,u,e,t);continue}let a=j5(e,c);if(a!==void 0){z5(d,u,e,a);continue}let p=j5(e,s),m=j5(e,n);if(p!==void 0&&(m===void 0||!f||!BXe(e,u.rest(),p,l,[s,c,n]))){z5(d,u,e,p);continue}if(m!==void 0){let t=F5(u,e,m.param,m.negated);if(t._tag===`Error`){i.push(t.error);continue}t.value!==void 0&&r[m.param.name].push(t.value);continue}d.push(e);continue}if(e._tag===`Value`&&f){let t=l.get(e.value);if(t!==void 0)return d.push(e),d.push(...a(u.rest(),t,[...o,c])),d;f=!1}d.push(e)}return d};return{flagMap:r,remainder:a(e,t,[]),errors:i}},HXe=(e,t,n)=>{let r=e._tag===`LongOption`?`--${e.name}`:`-${e.flag}`,i=[];for(let e of t){if(e.hidden)continue;i.push(e.name);let t=T5(e);t!==void 0&&i.push(t);for(let t of e.aliases)i.push(t)}return new B3({option:r,suggestions:b5(A5(e),i).map(e=>e.length===1?`-${e}`:`--${e}`),command:n})},UXe=e=>({flags:LXe(e.params),arguments:[],errors:[],mode:{_tag:`AwaitingFirstValue`}}),WXe=e=>({_tag:`Leaf`,flags:e.flags.snapshot(),arguments:e.arguments,errors:e.errors}),GXe=(e,t,n,r)=>{let{command:i,commandPath:a,inheritedFlagRegistry:o,localFlagNames:s}=n,c=D5(i.subcommands),l=c.get(e);if(l){let e=[...a,l.name],n=r.flags.snapshot();for(let t of s){let i=n[t];i!==void 0&&i.length>0&&r.errors.push(new B3({option:`--${t}`,suggestions:[],command:e}))}let i=zXe(t.rest(),o);return r.flags.merge(i.flagMap),r.errors.push(...i.errors),{_tag:`Subcommand`,result:{_tag:`Sub`,flags:r.flags.snapshot(),sub:l,childTokens:i.remainder,errors:r.errors}}}if(!(S8(i).config.arguments.length>0)&&c.size>0){let t=[];for(let[e,n]of c)n.unlisted||t.push(e);let n=b5(e,t);r.errors.push(new K3({subcommand:e,parent:a,suggestions:n}))}return{_tag:`Argument`}},KXe=(e,t,n,r)=>{let{commandPath:i,flagRegistry:a}=n,o=j5(e,a);if(!o){r.errors.push(HXe(e,a.params,i));return}let s=P5(t,e,o.param,o.negated);if(s._tag===`Error`){r.errors.push(s.error);return}r.flags.add(o.param.name,s.value)},qXe=(e,t,n,r)=>{if(r.mode._tag===`AwaitingFirstValue`){let i=GXe(e,t,n,r);if(i._tag===`Subcommand`)return i.result;r.mode={_tag:`CollectingArguments`}}r.arguments.push(e)},B5=(e,t)=>{let n=I5(e),r=L5(e),i=new Set(r.map(e=>e.name));return{command:e,commandPath:t,flagRegistry:E5(n),inheritedFlagRegistry:E5(r),localFlagNames:n.filter(e=>!i.has(e.name)).map(e=>e.name)}},V5=(e,t)=>{let n=w5(e),r=UXe(t.flagRegistry);for(let e=n.take();e;e=n.take()){if(k5(e)){KXe(e,n,t,r);continue}if(e._tag===`Value`){let i=qXe(e.value,n,t,r);if(i)return i}}return WXe(r)},JXe=X(function*(e,t){let n=t?.commandPath??[e.name],r=YXe(e,n),i=(t?.prefix??n).map(e=>W5(e)),{colors:a}=yield*f6;return yield*K5(i,a),yield*H5(r,i,r===e?`ROOT`:r.name,a),{args:i.map(e=>e.value),displayArgs:i.map(e=>e.displayValue)}}),YXe=(e,t)=>{let n=e;for(let e of t.slice(1)){let t=n.subcommands.flatMap(e=>e.commands).find(t=>t.name===e||t.alias===e);if(t===void 0)break;n=t}return n},H5=X(function*(e,t,n,r){let i=S8(e),a=e.subcommands.flatMap(e=>e.commands.filter(e=>!e.unlisted)),o=a.length===0?i.config:i.contextConfig;if(o.flags.length>0){yield*A3(q5(n,`FLAGS`,r));for(let e of o.flags)t.push(...yield*U5(e));(o.arguments.length>0||a.length>0)&&(yield*K5(t,r))}if(o.arguments.length>0){yield*A3(q5(n,`ARGUMENTS`,r)),a.length===0&&t.push(W5(`--`));for(let e of o.arguments)t.push(...yield*U5(e));a.length>0&&(yield*K5(t,r))}if(a.length===0)return;let s=yield*b6(x6({message:`Command`,choices:a.map(e=>({title:e.name,value:e,...e.shortDescription===void 0?e.description===void 0?{}:{description:e.description}:{description:e.shortDescription}}))}));yield*A3(),t.push(W5(s.name)),XXe(s)&&(yield*K5(t,r)),yield*H5(s,t,s.name,r)}),XXe=e=>e.subcommands.some(e=>e.commands.some(e=>!e.unlisted))||S8(e).config.orderedParams.length>0,U5=X(function*(e){let t=c8(e),n=l8(e);if(n.isOptional&&!(yield*b6(_6({message:`Set ${G5(t)}?`,initial:!1}))))return yield*A3(),[];let r=n.isVariadic?yield*b6(y6({message:`${G5(t)} count`,default:DW(n.variadicMin,()=>0),min:DW(n.variadicMin,()=>0),...TW(n.variadicMax)?{max:n.variadicMax.value}:{}})):1,i=[];for(let e=0;e<r;e++)i.push(yield*ZXe(t));let a=t.kind===`flag`?{flags:{[t.name]:i.map(e=>e.value)},arguments:[]}:{flags:{},arguments:i.map(e=>e.value)};return yield*e.parse(a),yield*A3(),t.kind===`argument`?i:i.flatMap(e=>t.optionalValue!==void 0||e.value.startsWith(`-`)&&e.value.length>1?[W5(`--${t.name}=${e.value}`,`--${t.name}=${e.displayValue}`)]:[W5(`--${t.name}`),e])}),ZXe=e=>{let t=$Xe(e);switch(e.primitiveType._tag){case`Boolean`:return PX(b6(_6({message:t,label:{confirm:`true`,deny:`false`},placeholder:{defaultConfirm:`(T/f)`,defaultDeny:`(t/F)`}})),e=>W5(String(e)));case`Choice`:{let n=Q3(e.primitiveType)??[];return PX(b6(x6({message:t,choices:n.map(e=>({title:e,value:e}))})),W5)}case`Date`:return PX(b6(Yqe({message:t})),e=>W5(e.toISOString()));case`Finite`:return PX(b6(Zqe({message:t})),e=>W5(String(e)));case`Int`:return PX(b6(y6({message:t})),e=>W5(String(e)));case`Redacted`:return PX(b6($qe({message:t})),e=>W5(g2(e),`<redacted>`));default:return PX(b6(nJe({message:t})),W5)}},W5=(e,t=e)=>({value:e,displayValue:t}),QXe=e=>e.kind===`flag`?`--${e.name}`:e.name,$Xe=e=>G5(e),G5=e=>{let t=AW(e.description)?.trim(),n=e.kind===`flag`&&t!==void 0&&t.length<=32?t:eZe(e.name);return e.kind===`flag`?`${n} (${QXe(e)})`:n},eZe=e=>{let t=e.split(/[-_]+/).filter(e=>e.length>0);return t.length===0?e:[t[0][0].toUpperCase()+t[0].slice(1),...t.slice(1)].join(` `)},K5=(e,t)=>A3(J5(`Current command`,e.map(e=>e.displayValue),t,`\x1B[35m`)),q5=(e,t,n)=>`${c6(n,e.toUpperCase(),e6,s6)} ${c6(n,`·`,o6)} ${c6(n,t,e6,a6)}`,tZe=(e,t,n,r)=>[`${c6(r,e,e6,s6)} ${c6(r,`v${t}`,a6)} ${c6(r,`· Command wizard`,e6,a6)}`,...n===void 0||n.length===0?[]:[n],c6(r,`Build a command interactively. Press Ctrl+C to cancel.`,o6),``].join(`
820
+ `),nZe=(e,t)=>J5(`Command ready`,e,t,s6,i6),rZe=e=>`\n${c6(e,`Wizard cancelled.`,r6)}`,J5=(e,t,n,r,i=a6)=>{let a=iZe(t);return[c6(n,e,e6,i),...a.map(e=>c6(n,e,r)),``].join(`
821
+ `)},iZe=e=>{let t=` $ `,n=` `,r=e.map(aZe),i=[],a=t;for(let e of r){let r=a===t||a===n?``:` `;a.length+r.length+e.length>88&&a!==t?(i.push(`${a} \\`),a=`${n}${e}`):a+=`${r}${e}`}return a!==t&&i.push(a),i},aZe=e=>/^[A-Za-z0-9_./:@%+=,-]+$/.test(e)?e:`'${e.replaceAll(`'`,`'"'"'`)}'`,oZe=e=>yH(e,x8),Y5=(e,t,n)=>{let r=y8(t??{});return C8({name:e,config:r,...hH(n)?{handle:n}:{}})},sZe=e=>{let t=[],n=new Map,r=(e,r)=>{t.push(r);let i=n.get(e);i?i.push(r):n.set(e,[r])};for(let t of e){if(oZe(t)){r(void 0,t);continue}for(let e of t.commands)r(t.group,e)}let i=[],a=n.get(void 0);a&&a.length>0&&i.push({group:void 0,commands:a});for(let[e,t]of n)e!==void 0&&i.push({group:e,commands:t});return{flat:t,groups:i}},cZe=W(2,(e,t)=>{let n=sZe(t);$Ye(e,n.flat);let r=S8(e),i=new Map(n.flat.map(e=>[e.name,S8(e)])),a=Symbol(`effect/cli/SubcommandState`),o=X(function*(e){if(wW(e.subcommand))return yield*r.parse(e);let t=i.get(e.subcommand.value.name);if(!t)return yield*r.parse(e);let n=yield*r.parseContext(e),o=yield*t.parse(e.subcommand.value.parsedInput);return{...n,[a]:{name:t.name,result:o}}}),s=X(function*(e,t){let n=e[a];if(n){let a=i.get(n.name);return a?yield*a.handle(n.result,[...t,a.name]).pipe($X(r.service,e)):yield*new J3({commandPath:t,errors:[]})}return yield*r.handle(e,t)});return C8({name:r.name,config:r.config,contextConfig:r.contextConfig,description:r.description,shortDescription:r.shortDescription,alias:r.alias,unlisted:r.unlisted,annotations:r.annotations,globalFlags:r.globalFlags,resolveExamples:r.resolveExamples,service:r.service,subcommands:n.groups,parse:o,parseContext:r.parseContext,handle:s})}),X5=W(2,(e,t)=>C8({...S8(e),description:t})),lZe=(e,t,n,r)=>{let i=new Set(t),a=[],o=new Set;for(let t of e){if(i.has(t))continue;let e=s8(t.flag);for(let t of e){let e=n[t.name];if(!e||e.length===0)continue;let i=`--${t.name}`;o.has(i)||(o.add(i),a.push(new B3({option:i,suggestions:[],command:r})))}}return a},uZe=(e,t,n)=>TX(function*(){let{builtIns:r}=yield*_5,i=yield*f8,{commandPath:a,errors:o}=t,s=yield*f5(e,a,r);yield*i.present(n&&o.length>0?{_tag:`InvalidInvocation`,commandPath:a,helpDoc:s,errors:o}:{_tag:`Help`,reason:`Implicit`,commandPath:a,helpDoc:s})}),dZe=(e,t)=>TX(function*(){let n=yield*NXe,r=e instanceof q3?e:new q3({cause:e,userMessage:t});yield*k3(n.formatError(r)),Object.assign(e,{[I3]:!1})}),Z5=(e,t)=>{let n=S8(e);return X(function*(r){let{builtIns:i}=yield*_5,{tokens:a,trailingOperands:o}=PXe(r),s=EXe(e,i),c=s.flatMap(e=>s8(e.flag)),l=E5(c.filter(t8)),{flagMap:u,remainder:d,errors:f}=VXe(a,e,l),p={flags:u,arguments:[]},m=yield*S5({tokens:d,trailingOperands:o},e),h=[e.name,...x5(m)],g=e=>e._tag===`ShowHelp`?e:new J3({commandPath:h,errors:[e]}),_=HX(g),v={builtIns:i,command:e,commandPath:h,version:t.version},y=d5(e,h,i),b=lZe(s,y,u,h);if(b.length>0||f.length>0){let e=m.errors??[];return yield*new J3({commandPath:h,errors:[...f,...b,...e]})}for(let n of y){if(n._tag!==`Action`||!s8(n.flag).some(e=>{let t=u[e.name];return t!==void 0&&t.length>0}))continue;let[,r]=yield*n.flag.parse(p).pipe(_);if(n===h5){let{colors:n}=yield*f6;return yield*TX(function*(){yield*A3(tZe(e.name,t.version,e.description,n));let r=new Set(C5(d,e)),i=[e.name,...a.filter(e=>!r.has(e)&&(e._tag!==`LongOption`||e.name!==`wizard`)).map(FXe)],o=yield*JXe(e,{commandPath:h,prefix:i});yield*A3(nZe(o.displayArgs,n)),(yield*b6(rJe({message:`Run this command?`,initial:!0,active:`yes`,inactive:`no`})))&&(yield*A3(),yield*Z5(e,{...t,renderErrors:!1})(o.args.slice(1)))}).pipe(RX(`QuitError`,()=>A3(rZe(n))))}yield*n.run(r,v);return}if(m.errors&&m.errors.length>0)return yield*new J3({commandPath:h,errors:m.errors});let ee=yield*n.parse(m).pipe(HX(e=>R3(e)?g(e):e)),x=n.handle(ee,[e.name]),te=y.includes(g5)?(yield*g5.flag.parse(p).pipe(_))[1]:G();x=$X(x,g5,te);for(let e of y){if(e._tag!==`Setting`||e===g5)continue;let[,t]=yield*e.flag.parse(p).pipe(_);x=$X(x,e,t)}let ne=EW(te,{onNone:()=>KW(),onSome:e=>qW(Oze,e)});yield*ZX(x,ne)},VX(e=>R3(e)&&e._tag===`ShowHelp`?aG(e):oG(e),n=>jX(uZe(e,n,t.renderErrors!==!1),J(n))),VX(e=>{if(t.renderErrors===!1||!vH(e))return oG(e);let n=Pqe(e);return n===void 0?oG(e):aG({error:e,userMessage:n})},({error:e,userMessage:t})=>jX(dZe(e,t),J(e))),VX(e=>yqe(e)?aG(e):oG(e),e=>sZ))},Q5=e=>yH(e,`code`)&&uH(e.code)?e.code:void 0,$5=e=>{try{process.kill(e,0);return}catch(e){return e}},e7=e=>bX(()=>{let t=$5(-e);if(t===void 0)return q({_tag:`Succeeded`});let n=Q5(t);return n===void 0?OX(t):q({_tag:`Failed`,code:n})}),t7=e=>e._tag===`Failed`&&e.code===`ESRCH`,fZe=(e,t)=>t7(e)||t._tag===`Read`&&t.processes.length>0&&t.processes.every(({state:e})=>e.startsWith(`Z`))?`observed`:e._tag===`Succeeded`?`not-observed`:`unknown`,n7=/^\d+$/,pZe=e=>{let[t,n,r,...i]=e.trim().split(/\s+/);return t!==void 0&&n!==void 0&&r!==void 0&&i.length===0&&n7.test(t)&&n7.test(n)?{pid:Number(t),pgid:Number(n),state:r}:void 0},mZe=(e,t)=>{let n=[];for(let r of e.split(`
822
+ `)){if(r.trim()===``)continue;let e=pZe(r);if(e===void 0)return{_tag:`Unreadable`,why:`ps listed ${JSON.stringify(r)}, which is not a pid, a process group and a state`};e.pgid===t&&n.push({pid:e.pid,state:e.state})}return{_tag:`Read`,processes:n}},hZe=KG(10),gZe=(e,t,n)=>TX(function*(){let r=yield*NBe(e7(e),{schedule:mX(hZe),while:e=>!t7(e)&&PX(VY,e=>e<t)});if(t7(r))return{groupGone:`observed`,evidence:{lastProbe:r,members:{_tag:`NotRead`}}};let i=yield*n,a=yield*e7(e);return{groupGone:fZe(a,i),evidence:{lastProbe:a,members:i}}}),_Ze=e=>{if(e===void 0)return`present`;let t=Q5(e);return t===`ESRCH`?`absent`:t===`EPERM`?`present`:`unknown`},vZe=e=>xX(()=>_Ze($5(e))),yZe=/^Process interrupted due to receipt of signal: '([A-Z0-9]+)'$/,bZe=e=>{if(e instanceof Error)return yZe.exec(e.message)?.[1]},r7=(e,t)=>({_tag:`Capture`,limitBytes:e,onExceed:t}),xZe={_tag:`Ignore`},i7=e3([c3(`Captured`,{bytes:pqe,totalBytes:f3,truncated:X4,omitted:G4(Q({at:f3,bytes:f3})),closed:X4}),c3(`Forwarded`,{forwardedBytes:f3,totalBytes:f3,truncated:X4,closed:X4}),c3(`Ignored`,{})]),SZe=e3([c3(`Exited`,{code:f3}),c3(`Signaled`,{signal:Z})]),CZe=e3([c3(`None`,{}),c3(`Fed`,{bytesWritten:f3,ended:t3([`source-done`,`child-closed`,`stopped`])})]),wZe=e3([c3(`Succeeded`,{}),c3(`Failed`,{code:Z})]),TZe=e3([c3(`NotRead`,{}),c3(`Read`,{processes:Q4(Q({pid:f3,state:Z}))}),c3(`Unreadable`,{why:Z})]),a7=Q({pid:f3,executable:Z,exit:SZe,stdin:CZe,stdout:i7,stderr:i7,termination:Q({by:n3(t3([`deadline`,`stop`,`output-limit`])),reason:n3(Z),requestedAt:n3(Z),groupGone:t3([`observed`,`not-observed`,`unknown`,`not-applicable`]),confirmedAt:n3(Z),group:n3(Q({lastProbe:wZe,members:TZe}))}),durationMs:f3}).annotate({identifier:`@inkeep/impulse-owned-process/ProcessRecord`}),o7=Q({pid:f3.check(nqe({minimum:1,maximum:2**31-1})),startedAt:Z.check(iqe(1))}),EZe=Q({identity:o7,releasedAt:Z,deadlineAt:Z}).annotate({identifier:`@inkeep/impulse-owned-process/HandOff`}),DZe=e3([c3(`SpawnFailed`,{code:Z}),c3(`DeadlineExceeded`,{record:a7}),c3(`OutputLimit`,{stream:t3([`stdout`,`stderr`]),limitBytes:f3,record:a7}),c3(`ExitFailed`,{record:a7}),c3(`ReleaseRefused`,{why:t3([`exited`,`identity-unavailable`]),record:n3(a7)})]),OZe=e=>e.exit._tag===`Exited`?`exited ${e.exit.code}`:`ended by ${e.exit.signal}`,kZe=e=>{if(e._tag===`SpawnFailed`)return`SpawnFailed: ${e.code}`;if(e._tag===`ReleaseRefused`)return`ReleaseRefused: ${e.why}`;if(e._tag===`OutputLimit`)return`OutputLimit: ${e.record.executable} passed its ${e.limitBytes}-byte ${e.stream} capture`;let t=e._tag===`DeadlineExceeded`?` after its deadline`:``;return`${e._tag}: ${e.record.executable} ${OZe(e.record)}${t}`};var s7=class extends S3()(`ProcessError`,{reason:DZe}){get message(){return kZe(this.reason)}};const AZe=(e,t)=>{let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n},c7=(e,t,n)=>e.pipe(Y(e=>(t.steps+=1,vX(e,n,{discard:!0}))),lZ({disableYield:!0}),nX(()=>xX(()=>{t.closed=!0})),zX(()=>SX)),jZe=(e,t,n)=>{let r={steps:0,busy:!1,closed:!1},i=[],a=0,o=[],s=0,c=0,l=!1,u=e=>{let r=t.limitBytes-s;if(r>0){let t=e.byteLength>r?e.subarray(0,r):e;o.push(t),s+=t.byteLength}return e.byteLength<=r||l?SX:(l=!0,n)},d=t.onExceed===`keep-ends`?Math.floor(t.limitBytes/2):0,f=t.limitBytes-d,p=t.onExceed===`terminate`?u:e=>xX(()=>{let t=e.subarray(0,d-a);t.byteLength>0&&(i.push(t),a+=t.byteLength);let n=e.subarray(t.byteLength);if(n.byteLength!==0)for(o.push(n),s+=n.byteLength;s>f;){let e=o[0];if(e===void 0)return;let t=s-f;e.byteLength<=t?(o.shift(),s-=e.byteLength):(o[0]=e.subarray(t),s-=t)}});return{progress:r,run:c7(e,r,e=>(c+=e.byteLength,p(e))),record:()=>{let e=c-a-s;return{_tag:`Captured`,bytes:AZe([...i,...o],a+s),totalBytes:c,truncated:e>0,...t.onExceed===`keep-ends`&&e>0?{omitted:{at:a,bytes:e}}:{},closed:r.closed}}}},MZe=(e,t,n)=>{let r={steps:0,busy:!1,closed:!1},i=0,a=0,o=!1,s=t.limitBytes??1/0,c=e=>xX(()=>{o=!0,r.closed=e}),l=bX(()=>(r.busy=!1,s<=0?zY():sX(e,{onSuccess:e=>{r.steps+=1;let t=[];for(let n of e){if(a+=n.byteLength,s<=0)continue;let e=n.byteLength>s?n.subarray(0,s):n;t.push(e),s-=e.byteLength,i+=e.byteLength}let[n,...o]=t;return n===void 0?zY():(r.busy=!0,q([n,...o]))},onFailure:()=>jX(c(!1),zY()),onDone:()=>jX(c(!0),zY())}))),u=bX(()=>o?SX:c7(e,r,e=>xX(()=>{a+=e.byteLength})));return{progress:r,run:h$(c$(q(l)),t.sink).pipe(iZ(xX(()=>{r.busy=!1})),zX(n),jX(u)),record:()=>({_tag:`Forwarded`,forwardedBytes:i,totalBytes:a,truncated:a>i,closed:r.closed})}},NZe=(e,t,n)=>Y(VY,r=>{let i=ZG(n.ceiling),a=jX(kZ(e),xX(()=>{t.closed=!1})),o=(s,c)=>Y(DZ(e).pipe(FX(!0),qX(FX(KX(n.tick),!1))),e=>e?SX:Y(VY,e=>{let l=t.steps!==s||t.busy?0:c+1;return l>=n.idleTicks||e-r>=i?a:o(t.steps,l)}));return o(t.steps,0)}),PZe={PATH:`/usr/bin:/bin:/usr/sbin:/sbin`},FZe=(e,t)=>S2(`/bin/sh`,[`-c`,`group=-$1 polls=$2
823
+ gone() { ! kill -s 0 -- "$group" 2>/dev/null; }
824
+ settle() { n=0; while [ "$n" -lt "$polls" ]; do gone && return 0; sleep 0.1; n=$((n + 1)); done; gone; }
825
+ read -r line && exit 0
826
+ kill -s TERM -- "$group" 2>/dev/null
827
+ settle && exit 0
828
+ kill -s KILL -- "$group" 2>/dev/null
829
+ settle`,`owned-process-tether`,String(e),String(Math.max(1,Math.ceil(XG(t)/100)))],{env:{...PZe},extendEnv:!1,stdin:`pipe`,stdout:`ignore`,stderr:`ignore`,detached:!0,killSignal:`SIGTERM`,forceKillAfter:t}),IZe=new TextEncoder().encode(`disarm
830
+ `),LZe=(e,t)=>jX(GX(h$(d$(IZe),e.stdin)),GX(CBe(e.exitCode,t)));Q({executable:Z,args:Q4(Z),env:YKe(Z,Z)});const RZe=Q({code:Z}),zZe=nG(`@inkeep/impulse-owned-process/internal/NodeVersion`,{defaultValue:()=>process.versions.node}),l7=(e,t)=>{let n=OIe(t);if(wW(n)||!VG(n.value))throw RangeError(`owned-process: ${e} must be a finite duration`);return n.value},u7=(e,t)=>{if(!Number.isSafeInteger(t)||t<=0)throw RangeError(`owned-process: ${e} must be a positive integer, got ${t}`)},d7=(e,t)=>{switch(t._tag){case`Capture`:u7(`${e}.limitBytes`,t.limitBytes);return;case`Forward`:t.limitBytes!==void 0&&u7(`${e}.limitBytes`,t.limitBytes);return;case`Ignore`:return}},BZe=e=>{if(e.executable.length===0)throw RangeError(`owned-process: executable must be non-empty`);if(e.cwd!==void 0&&!u(e.cwd))throw RangeError(`owned-process: cwd must be absolute, got ${e.cwd}`);for(let[t,n]of Object.entries(e.env))if(typeof n!=`string`)throw TypeError(`owned-process: env.${t} must be a string`);let t=l7(`deadline`,e.deadline);if(XG(t)<=0)throw RangeError(`owned-process: deadline must be greater than zero`);return d7(`stdout`,e.stdout),d7(`stderr`,e.stderr),{request:e,deadline:t,terminationGrace:l7(`terminationGrace`,e.terminationGrace),inheritGroup:e.processGroup===`inherit`}},VZe=e=>e.stdin===void 0&&e.stdout._tag===`Ignore`&&e.stderr._tag===`Ignore`,f7={tick:KG(250),idleTicks:8,ceiling:qG(30)},p7=XG(qG(1)),m7=1000000n,HZe=BigInt(p7)*m7,h7=(e,t)=>Number((e-t)/m7),g7=(e,t)=>{let n=XG(t),r=n>p7;return{forceKillAfterMillis:n-(r?p7:0),settleByNanos:e+ZG(t)+(r?0n:HZe)}},UZe={Deadline:`deadline`,Stop:`stop`,OutputLimit:`output-limit`,CallerFailed:null},_7=e=>{let t=yH(e.reason,`cause`)?e.reason.cause:void 0;return new s7({reason:{_tag:`SpawnFailed`,code:yH(t,`code`)&&uH(t.code)?t.code:e.reason._tag}})},v7=e=>e._tag===`Ignore`?`ignore`:`pipe`,WZe=e=>e.exitCode.pipe(PX(e=>({_tag:`Exited`,code:Number(e)})),RX(`PlatformError`,e=>{let t=yH(e.reason,`cause`)?e.reason.cause:void 0,n=bZe(t);return n===void 0?OX(e):q({_tag:`Signaled`,signal:n})})),y7=PX(tUe,r1),GZe=(e,t,n)=>{let r=0,i=`stopped`,a=(o$(e)?e:d$(e)).pipe(MHe(e=>xX(()=>{r+=e.byteLength})),IHe(e=>f$(FX(PY(e)?SX:n(e),AHe))));return{run:h$(a,t).pipe(YX({onSuccess:()=>xX(()=>{i=`source-done`}),onFailure:e=>{let t=IY(e);return sG(t)?PY(t.failure)?SX:n(t.failure):xX(()=>{i=`child-closed`})}})),record:()=>({_tag:`Fed`,bytesWritten:r,ended:i})}},b7={_tag:`Ignored`},KZe=g(new URL(import.meta.url.endsWith(`.ts`)?`./internal/launch.ts`:`./internal/launch.js`,import.meta.url)),x7=(e,t)=>TX(function*(){let{request:n,inheritGroup:r}=e,i=e=>t.spawned===void 0?SX:QJ(t.spawned,e);if(!r){let e=PKe(yield*zZe);if(sG(e)||LKe(e.success,MKe({major:26,minor:10,patch:0}))||process.execve===void 0){let e=new s7({reason:{_tag:`SpawnFailed`,code:`ENOSYS`}});return yield*i(e),yield*e}}let a=yield*d2,o=yield*N3({groupGone:`unknown`,confirmedAt:null,group:null}),s=yield*tZ(TX(function*(){let s=yield*N3({_tag:`Unspawned`}),c=yield*cY(yield*eZ);yield*rZ(()=>TX(function*(){let t=yield*P3(s);if(r||t._tag===`Unspawned`||t._tag===`Released`)return;let n=t._tag===`Exited`?t.settleByNanos:t.settleByNanos??g7(yield*VY,e.terminationGrace).settleByNanos,{groupGone:i,evidence:a}=yield*gZe(t.pid,n,YZe(t.pid,n));yield*F3(o,{groupGone:i,confirmedAt:i===`observed`?yield*y7:null,group:a})}));let l=yield*cY(yield*eZ),u=yield*a.spawn(S2(r?n.executable:process.execPath,r?[...n.args]:[`--no-warnings`,KZe],{cwd:n.cwd,env:r?{...n.env}:{},extendEnv:!1,stdin:n.stdin===void 0?`ignore`:`pipe`,stdout:v7(n.stdout),stderr:v7(n.stderr),detached:!r,killSignal:`SIGTERM`,forceKillAfter:KG(g7(0n,e.terminationGrace).forceKillAfterMillis),additionalFds:r?void 0:{fd3:{type:`input`},fd4:{type:`output`}}})).pipe(HX(_7),WX(i)),d=yield*BY,f=yield*VY,p=f+ZG(e.deadline),m=Number(u.pid);if(yield*F3(s,{_tag:`Running`,pid:m,settleByNanos:g7(f,e.terminationGrace).settleByNanos}),!r){let t=yield*a.spawn(FZe(m,e.terminationGrace)).pipe(aY(c),HX(_7),WX(i));yield*sY(c,LZe(t,e.terminationGrace));let r=h$(d$(new TextEncoder().encode(JSON.stringify({executable:n.executable,args:n.args,env:n.env}))),u.getInputFd(3)).pipe(jX(_$(m$(u.getOutputFd(4))))),o=h7(p,yield*VY),s=()=>J(new s7({reason:{_tag:`SpawnFailed`,code:`ETIMEDOUT`}})),l=yield*(o<=0?s():r.pipe(HX(_7),wBe({duration:KG(o),orElse:s}))).pipe(WX(i));if(l!==``){let{code:e}=yield*H4(dqe(RZe))(l).pipe(UX),t=new s7({reason:{_tag:`SpawnFailed`,code:e}});return yield*i(t),yield*t}}let h=yield*YJ(),g=yield*YJ(),_=yield*YJ();yield*fZ(Dze(WZe(u),_)),t.spawned!==void 0&&(yield*tY(t.spawned,{pid:m,spawnedAtMillis:d,exited:$J(_)}));let v=e=>Y(tY(h,e),t=>t||e._tag!==`OutputLimit`&&e._tag!==`CallerFailed`?SX:IX(tY(g,e))),y=e=>Y(Eze(e),EW({onNone:()=>q(void 0),onSome:e=>PX(e,e=>e)})),b=e=>v({_tag:`CallerFailed`,cause:e}),ee=h7(p,yield*VY),x=[yield*fZ(jX(ee<=0?SX:KX(KG(ee)),v({_tag:`Deadline`})))];t.stop!==void 0&&x.push(yield*fZ(YX(t.stop,{onSuccess:e=>v({_tag:`Stop`,reason:e}),onFailure:e=>PY(e)?SX:b(e)}))),t.release!==void 0&&x.push(yield*fZ(jX(t.release,v({_tag:`Release`}))));let te=(e,t,n)=>TX(function*(){if(t._tag===`Ignore`)return;let r=yield*VHe(n);return t._tag===`Capture`?jZe(r,t,v({_tag:`OutputLimit`,stream:e,limitBytes:t.limitBytes})):MZe(r,t,b)}),ne=yield*te(`stdout`,n.stdout,u.stdout),re=yield*te(`stderr`,n.stderr,u.stderr),ie=[];for(let e of[ne,re].filter(hH))ie.push({drain:e,fiber:yield*fZ(e.run)});let ae=n.stdin===void 0?void 0:GZe(n.stdin,u.stdin,b),S=ae===void 0?void 0:yield*dZ(ae.run,l),oe=g7(yield*VY,e.terminationGrace);yield*F3(s,{_tag:`Running`,pid:m,settleByNanos:oe.settleByNanos});let C=yield*qX(FX(XJ(_),void 0),XJ(h));if(C?._tag===`Release`&&!(yield*$J(_)))return yield*GX(u.unref),yield*F3(s,{_tag:`Released`}),{_tag:`Released`};let se=C!==void 0&&C._tag!==`Release`?C:void 0,ce=se===void 0?null:yield*y7;se===void 0&&(yield*vX(x,kZ,{discard:!0}));let le=g7(yield*VY,e.terminationGrace);yield*F3(s,{_tag:`Running`,pid:m,settleByNanos:le.settleByNanos});let ue=yield*NX(u.kill({killSignal:`SIGTERM`,forceKillAfter:KG(le.forceKillAfterMillis)}));if(AY(ue))yield*GX(u.unref);else{let e=yield*NX(u.isRunning);AY(e)&&!e.value&&(yield*GX(u.unref))}let w=yield*XJ(_);yield*F3(s,{_tag:`Exited`,pid:m,settleByNanos:le.settleByNanos}),yield*vX(ie,({drain:e,fiber:t})=>NZe(t,e.progress,f7),{concurrency:`unbounded`,discard:!0}),S!==void 0&&(yield*qX(IX(DZ(S)),jX(KX(HIe(f7.tick,f7.idleTicks)),kZ(S))));let de=se===void 0?yield*y(h):void 0,fe=de?._tag===`OutputLimit`||de?._tag===`CallerFailed`?de:yield*y(g);return{_tag:`Exited`,pid:m,spawnedAtMillis:d,spawnedAtNanos:f,exited:w,stopping:se,late:se===void 0?fe:void 0,requestedAt:ce,stdin:ae===void 0?{_tag:`None`}:ae.record(),stdout:ne===void 0?b7:ne.record(),stderr:re===void 0?b7:re.record()}}));if(s._tag===`Released`)return s;let c=r?{groupGone:`not-applicable`,confirmedAt:null,group:null}:yield*P3(o),l=yield*VY,{stopping:u}=s,d=s.late?._tag===`OutputLimit`||s.late?._tag===`CallerFailed`?s.late:void 0,f=a7.make({pid:s.pid,executable:n.executable,exit:s.exited,stdin:s.stdin,stdout:s.stdout,stderr:s.stderr,termination:{by:u===void 0?null:UZe[u._tag],reason:u?._tag===`Stop`?u.reason:null,requestedAt:s.requestedAt,...c},durationMs:Math.max(0,Math.round(Number(l-s.spawnedAtNanos)/Number(m7)))}),p=u??d;return p===void 0||p._tag===`Stop`?{_tag:`Completed`,record:f}:p._tag===`CallerFailed`?yield*EX(p.cause):yield*new s7({reason:p._tag===`Deadline`?{_tag:`DeadlineExceeded`,record:f}:{_tag:`OutputLimit`,stream:p.stream,limitBytes:p.limitBytes,record:f}})}),S7=e=>xX(()=>BZe(e)),C7=e=>e._tag===`Completed`?q(e.record):OX(Error(`owned-process: a run cannot be released`)),w7=(e,t)=>Y(S7(e),e=>Y(x7(e,{stop:t?.stop}),C7)),qZe=(e,t)=>Y(w7(e,t),e=>e.exit._tag===`Exited`&&e.exit.code===0?q(e):J(new s7({reason:{_tag:`ExitFailed`,record:e}}))),JZe={PATH:`/usr/bin:/bin:/usr/sbin:/sbin`,LC_ALL:`C`},YZe=(e,t)=>TX(function*(){let n=h7(t,yield*VY);return n<=p7?{_tag:`Unreadable`,why:`termination grace exhausted before group-member read`}:yield*qZe({executable:`/bin/ps`,args:[`-A`,`-o`,`pid=,pgid=,stat=`],env:JZe,deadline:KG(n-p7),terminationGrace:`0 millis`,processGroup:`inherit`,stdout:r7(1<<20,`terminate`),stderr:xZe}).pipe(PX(t=>mZe(t.stdout._tag===`Captured`?new TextDecoder().decode(t.stdout.bytes):``,e)),RX(`ProcessError`,e=>q({_tag:`Unreadable`,why:e.message})))}),XZe={PATH:`/usr/bin:/bin:/usr/sbin:/sbin`,LC_ALL:`C`,TZ:`UTC`},ZZe=U4(o7.fields.pid);U4(o7);const QZe=e=>TX(function*(){let t=yield*xX(()=>ZZe(e)),n=yield*w7({executable:`/bin/ps`,args:[`-o`,`lstart=`,`-p`,String(t)],env:XZe,deadline:`10 seconds`,terminationGrace:`1 second`,stdout:r7(4096,`terminate`),stderr:r7(4096,`keep-tail`)}),r=n.stdout._tag===`Captured`?new TextDecoder().decode(n.stdout.bytes).trim():``;return n.exit._tag===`Exited`&&n.exit.code===0&&r.length>0?CW(r):(yield*vZe(t))===`absent`?G():yield*new s7({reason:{_tag:`ExitFailed`,record:n}})}),T7=OX(Error(`owned-process: the child was released, and the package no longer holds it`)),$Ze=OX(Error(`owned-process: release takes only an unpiped child: no stdin, and Ignore on both outputs`)),E7=e=>{if(AY(e))return e.value._tag===`Completed`?e.value.record:null;let t=IY(e.cause);if(sG(t)||!(t.success instanceof s7))return null;let n=t.success.reason;return yH(n,`record`)?n.record:null},D7=(e,t)=>new s7({reason:{_tag:`ReleaseRefused`,why:e,record:t}}),eQe=e=>TX(function*(){let t=yield*S7(e),n=yield*d2,r=yield*YJ(),i=yield*YJ(),a=yield*YJ(),o=VZe(e),s=yield*fZ(x7(t,{stop:XJ(r),release:o?XJ(i):void 0,spawned:a})),c=Y(DZ(s),e=>Y($J(a),t=>t?XJ(a):OX(jY(e)?Bze(e.cause):Error(`owned-process: supervision ended before the child spawned`)))),l=yield*qX(XJ(a),c),u=!1,d=bX(()=>u?T7:Y(OZ(s),C7)),f=bX(()=>u?T7:o?TX(function*(){let e=yield*QZe(l.pid).pipe($X(d2,n),HX(()=>D7(`identity-unavailable`,null)));if(wW(e)||(yield*l.exited))return yield*D7(`exited`,E7(yield*DZ(s)));yield*tY(i,void 0);let r=yield*DZ(s);return AY(r)&&r.value._tag===`Released`?(u=!0,EZe.make({identity:{pid:l.pid,startedAt:e.value},releasedAt:yield*y7,deadlineAt:r1(eUe(l.spawnedAtMillis+XG(t.deadline)))})):yield*D7(`exited`,E7(r))}):$Ze);return{pid:l.pid,await:d,stop:e=>bX(()=>u?T7:jX(tY(r,e),d)),release:f}});var O7=class extends S3()(`ProcessError`,{command:Z,reason:t3([`SpawnFailed`,`DeadlineExceeded`,`Signaled`,`OutputLimit`]),stderr:Z,cause:K4(h3())}){get message(){return`${this.command}: ${this.reason} ${this.stderr.trim().slice(-600)}`}},tQe=class extends S3()(`ExitFailed`,{command:Z,exitCode:f3,stderr:Z}){get message(){return`${this.command}: exit ${this.exitCode} ${this.stderr.trim().slice(-600)}`}};qG(3);const k7=262144,nQe=(e,t)=>{let n=new TextDecoder().decode(e);return t===0?n:`${n}${n===``||n.endsWith(`
831
+ `)?``:`
832
+ `}[offload: ${t} earlier bytes of stderr dropped]\n`},A7=(e,t)=>[e,...t].map(e=>/^[\w@%+=:,./-]+$/.test(e)?e:JSON.stringify(e)).join(` `),j7=new Uint8Array,M7=(e,t)=>{if(t.exit._tag===`Signaled`)return J(new O7({command:e,reason:`Signaled`,stderr:``,cause:new s7({reason:{_tag:`ExitFailed`,record:t}})}));let n=t.stderr._tag===`Captured`?t.stderr:void 0,r=n===void 0?0:n.totalBytes-n.bytes.byteLength;return q({exitCode:t.exit.code,stdout:t.stdout._tag===`Captured`?t.stdout.bytes:j7,stderr:nQe(n?.bytes??j7,r),stderrDroppedBytes:r})},N7=(e,t)=>jqe(t.reason,{SpawnFailed:()=>J(new O7({command:e,reason:`SpawnFailed`,stderr:``,cause:t})),DeadlineExceeded:()=>J(new O7({command:e,reason:`DeadlineExceeded`,stderr:``})),OutputLimit:({stream:t,limitBytes:n})=>J(new O7({command:e,reason:`OutputLimit`,stderr:`${t} passed its ${n}-byte capture; the process was stopped`})),ExitFailed:()=>OX(t),ReleaseRefused:()=>OX(t)});var P7=class e extends PW()(`@openteammate/offload/Processes`){static layer=xY(e,TX(function*(){let t=yield*d2,n=e=>e instanceof s7,r=e=>{let r=A7(e.executable,e.args);return w7({...e,stdout:e.stdout??r7(8388608,`terminate`),stderr:r7(k7,`keep-tail`)}).pipe(BX(n,e=>N7(r,e)),Y(e=>M7(r,e)),$X(d2,t),uZ(`Processes.run`))};return e.of({run:r,checked:e=>r(e).pipe(Y(t=>t.exitCode===0?q(t):J(new tQe({command:A7(e.executable,e.args),exitCode:t.exitCode,stderr:t.stderr}))),uZ(`Processes.checked`)),hold:e=>{let r=A7(e.executable,e.args);return eQe({...e,stdout:e.stdout??r7(8388608,`terminate`),stderr:r7(k7,`keep-tail`)}).pipe(BX(n,e=>N7(r,e)),PX(e=>({pid:e.pid,ended:e.await.pipe(BX(n,e=>N7(r,e)),Y(e=>M7(r,e)))})),$X(d2,t),uZ(`Processes.hold`))}})}))};const F7=e=>new TextDecoder().decode(e);var I7=class extends S3()(`InvalidInput`,{field:Z,message:Z}){};const L7=`teammates`,R7=`us-west-2`,z7=`mac-host`,B7=`c-team`,V7=YG(24),rQe=YG(24),H7=JG(10),U7={pool:`ot-pool`,kind:`ot-kind`,owner:`ot-owner`,run:`ot-run`,retireAt:`ot-retire-at`,macos:`ot-macos`,ready:`ot-ready`,admission:`ot-admission`},W7=Q({Key:Z,Value:Z}),G7=Q({Hosts:Q4(Q({HostId:Z,State:Z,AvailabilityZone:G4(Z),AllocationTime:G4(Z),HostProperties:G4(Q({InstanceType:G4(Z)})),Instances:G4(Q4(Q({InstanceId:Z}))),Tags:G4(Q4(W7))}))}),iQe=Q({Reservations:Q4(Q({Instances:Q4(Q({InstanceId:Z,State:Q({Name:Z}),ImageId:G4(Z),Placement:G4(Q({HostId:G4(Z)})),Tags:G4(Q4(W7))}))}))}),aQe=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/,K7=e=>e.toISOString().replace(/\.\d{3}Z$/,`Z`),q7=e=>{let t=aQe.exec(e??``);if(e===void 0||t===null||t[1]===`0000`)return;let n=new Date(e);return Number.isNaN(n.getTime())||K7(n)!==e?void 0:n},oQe=e=>new Date(Math.ceil(e.getTime()/1e3)*1e3),J7=(e,t)=>K7(new Date(e.getTime()+Math.max(XG(rQe),XG(t))+6e4)),Y7=e=>e?.find(e=>e.Key===U7.retireAt)?.Value,sQe=(e,t)=>{if(e===void 0)return{write:!1,reason:`current value is missing or malformed`};let n=oQe(t);return e.getTime()>=n.getTime()?{write:!1,reason:`current value is already later`}:{write:!0,value:K7(n)}},X7=e=>Object.fromEntries((e??[]).map(e=>[e.Key,e.Value])),Z7=Q({run:Z,deadlineEpochSeconds:f3}),cQe=(e,t)=>{let n=new Map(t.Reservations.flatMap(e=>e.Instances).map(e=>{let t=X7(e.Tags),n={id:e.InstanceId,state:e.State.Name,imageId:e.ImageId,tags:t,retireAt:q7(t[U7.retireAt])};return[e.InstanceId,n]}));return e.Hosts.map(e=>{let t=X7(e.Tags);return{id:e.HostId,state:e.State,zone:e.AvailabilityZone,instanceType:e.HostProperties?.InstanceType,allocatedAt:e.AllocationTime,tags:t,retireAt:q7(t[U7.retireAt]),instances:(e.Instances??[]).flatMap(e=>{let t=n.get(e.InstanceId);return t===void 0?[]:[t]})}})},lQe=new Set([`released`,`released-permanent-failure`]),Q7=e=>e.retireAt===void 0?void 0:e.instances.reduce((e,t)=>t.retireAt!==void 0&&t.retireAt.getTime()>e.getTime()?t.retireAt:e,e.retireAt),$7=(e,t)=>e.filter(e=>{let n=Q7(e);return!lQe.has(e.state)&&n!==void 0&&n.getTime()<t.getTime()}),uQe=e=>{let t=/^(\d+)(?:\.\d+){0,2}$/.exec(e??``);return t===null?void 0:Number(t[1])},e9=(e,t)=>{let n=[];(e.tags[U7.pool]!==`teammates`||e.tags[U7.kind]!==`mac-host`)&&n.push(`not tagged as a team pool Mac`),e.state!==`available`&&n.push(`host state is ${e.state}`),e.tags[U7.ready]!==`true`&&n.push(`ot-ready is not true`);let r=uQe(e.tags[U7.macos]);r===void 0?n.push(`ot-macos is missing or malformed`):r<t.guestMacosMajor&&n.push(`macOS ${e.tags[U7.macos]} cannot run a macOS ${t.guestMacosMajor} guest`);let i=Q7(e);i===void 0?n.push(`ot-retire-at is missing or malformed`):i.getTime()-t.now.getTime()<XG(H7)&&n.push(`ot-retire-at ${K7(i)} leaves less than the ${RIe(H7)}-minute reuse margin`);let[a,...o]=e.instances;return a===void 0?n.push(`no instance on the host`):(o.length>0&&n.push(`${e.instances.length} instances on the host`),a.state!==`running`&&n.push(`instance ${a.id} is ${a.state}`),a.tags[U7.admission]!==`session-manager`&&n.push(`instance is not admitted to Session Manager`),(a.tags[U7.pool]!==`teammates`||a.tags[U7.kind]!==`mac-host`)&&n.push(`instance is not tagged as a team pool Mac`),a.retireAt===void 0&&n.push(`instance ot-retire-at is missing or malformed`)),n.length===0&&a!==void 0?{usable:!0,host:e,instance:a}:{usable:!1,host:e,reasons:n}},dQe=(e,t)=>e.map(e=>e9(e,t)).filter(e=>e.usable).toSorted((e,t)=>(Q7(t.host)?.getTime()??0)-(Q7(e.host)?.getTime()??0)),fQe=e3([Q({outcome:q4(`booted`),vm:Z,ip:Z,mac:Z,guestMacos:Z,guestHostKey:Z,bootSeconds:Y4,boundSeconds:Y4}),Q({outcome:q4(`runner-exited`),vm:Z,runnerExit:e3([Y4,Z]),frameworkDomain:Z,frameworkCode:e3([Y4,q4(``)]),frameworkStarted:X4,probe:t3([`present`,`absent`]),presentBeforeDelete:X4,absent:X4,log:Z}),Q({outcome:q4(`not-established`),vm:Z,reason:K4(Z),boundSeconds:Y4,presentBeforeDelete:X4,absent:X4,log:Z}),Q({outcome:q4(`clone-failed`),vm:Z,base:Z,reason:Z,absent:X4}),Q({outcome:q4(`cancelled`),vm:Z,absent:X4,reason:Z}),Q({outcome:t3([`name-taken`,`refused-input`]),reason:Z}),Q({outcome:q4(`host-held`),reason:Z})]),pQe=e=>U4(fQe)(e),t9=e=>{switch(e.outcome){case`host-held`:return{kind:`held`,reason:e.reason};case`booted`:return{kind:`booted`,vm:e.vm,ip:e.ip,mac:e.mac,guestMacos:e.guestMacos,guestHostKey:e.guestHostKey,bootSeconds:e.bootSeconds};case`runner-exited`:return e.frameworkDomain===`VZErrorDomain`&&e.frameworkCode===6&&!e.frameworkStarted?{kind:`limit`,cloneAbsent:e.absent}:{kind:`failed`,reason:e.probe===`absent`?`the VM's runner exited ${e.runnerExit}; no probe on the host to read the framework's error`:e.frameworkStarted?`the VM's runner exited ${e.runnerExit}, and the framework then started the same VM`:`the VM's runner exited ${e.runnerExit}; the framework reported ${e.frameworkDomain||`no domain`} code ${e.frameworkCode===``?`none`:e.frameworkCode}`,cloneAbsent:e.absent};case`not-established`:return{kind:`failed`,reason:e.reason??`the guest did not answer over SSH within ${e.boundSeconds} s`,cloneAbsent:e.absent};case`clone-failed`:return{kind:`failed`,reason:`cloning ${e.base} failed: ${e.reason}`,cloneAbsent:e.absent};case`cancelled`:return{kind:`cancelled`,reason:e.reason,cloneAbsent:e.absent};case`name-taken`:case`refused-input`:return{kind:`refused`,reason:e.reason};default:return e}},n9=e=>Object.entries(e).map(([e,t])=>({Key:e,Value:t})),r9=e=>({[U7.pool]:L7,[U7.kind]:z7,[U7.owner]:e.owner,[U7.run]:e.run,[U7.retireAt]:e.retireAt,[U7.macos]:e.hostMacos,Name:`ot-${e.run}`}),mQe=(e,t)=>({InstanceType:`${e.family}.metal`,Quantity:1,AutoPlacement:`off`,HostRecovery:`off`,AvailabilityZone:e.zone,ClientToken:t,TagSpecifications:[{ResourceType:`dedicated-host`,Tags:n9(r9(e))}]}),hQe=(e,t)=>({ImageId:t.imageId,InstanceType:`${e.family}.metal`,MinCount:1,MaxCount:1,Placement:{HostId:t.hostId,Tenancy:`host`},IamInstanceProfile:{Name:`openteammate-host-ssm`},MetadataOptions:{HttpTokens:`required`,HttpPutResponseHopLimit:1,HttpEndpoint:`enabled`},SecurityGroupIds:[t.securityGroupId],SubnetId:t.subnetId,BlockDeviceMappings:[{DeviceName:t.rootDevice,Ebs:{VolumeSize:500,VolumeType:`gp3`,Iops:5e3,Throughput:500,DeleteOnTermination:!0}}],ClientToken:`${e.run}-instance`,TagSpecifications:[{ResourceType:`instance`,Tags:n9({...r9(e),[U7.admission]:`session-manager`})},{ResourceType:`volume`,Tags:n9(r9(e))}]}),gQe=IIe(3),_Qe=(e,t)=>e.filter(e=>Date.parse(e.CreationDate)<=t.getTime()-XG(gQe)).toSorted((e,t)=>Date.parse(t.CreationDate)-Date.parse(e.CreationDate)).at(0),i9=e=>`"${e.replaceAll(`"`,`\\"`)}"`,a9=e=>{let t=`${e.directory}/id_ed25519`,n=`${e.directory}/known_hosts`,r=[`Host mac`,` HostName ${e.instanceId}`,` User ${B7}`,` IdentityFile ${i9(t)}`,` IdentitiesOnly yes`,` UserKnownHostsFile ${i9(n)}`,` StrictHostKeyChecking yes`,` HostKeyAlias ${e.instanceId}`,` ProxyCommand ${i9(e.otFleet)} proxy-instance ${e.instanceId} ${B7} ${i9(`${t}.pub`)}`,` ServerAliveInterval 15`,` ServerAliveCountMax 3`,` ControlMaster auto`,` ControlPath /tmp/ot-%C`,` ControlPersist 60`];return e.vm!==void 0&&r.push(`Host vm`,` HostName ${e.vm.ip}`,` User lume`,` ProxyJump mac`,` IdentityFile ${i9(t)}`,` IdentitiesOnly yes`,` UserKnownHostsFile ${i9(n)}`,` StrictHostKeyChecking yes`,` HostKeyAlias ${e.vm.name}`,` ServerAliveInterval 15`),r.join(`
833
+ `)+`
834
+ `},o9=/^\s*(ssh-ed25519) ([A-Za-z0-9+/=]+)(?:\s|$)/,s9=Z.check(u3(o9)),c9=(e,t)=>{let n=o9.exec(t.trim());if(n===null)throw Error(`not an ssh-ed25519 public key: ${t.slice(0,40)}`);return`${e} ${n[1]} ${n[2]}\n`},l9={repository:`trycua/macos-tahoe-vanilla`,tag:`latest`,digest:`sha256:10a8c1c95c5c2367c633d99be2aa91abf1e7db9cf80c7829061b57c997674b67`,macosMajor:26,baseVm:`ot-base-tahoe`},u9=e=>({hostId:e.id,state:e.state,zone:e.zone??null,instanceType:e.instanceType??null,allocatedAt:e.allocatedAt??null,owner:e.tags[U7.owner]??null,run:e.tags[U7.run]??null,retireAt:e.tags[U7.retireAt]??null,macos:e.tags[U7.macos]??null,ready:e.tags[U7.ready]??null,instances:e.instances.map(e=>({instanceId:e.id,state:e.state,admission:e.tags[U7.admission]??null,retireAt:e.tags[U7.retireAt]??null}))}),vQe=(e,t)=>{if(e.createdAtEpochSeconds===null||!Number.isFinite(e.createdAtEpochSeconds))return{name:e.name,state:e.state,isBaseImage:e.name===l9.baseVm,createdAt:null,ageSeconds:null};let n=new Date(e.createdAtEpochSeconds*1e3);return{name:e.name,state:e.state,isBaseImage:e.name===l9.baseVm,createdAt:K7(n),ageSeconds:Math.max(0,Math.floor((t.getTime()-n.getTime())/1e3))}},yQe=Q({instanceId:Z,state:Z,admission:n3(Z),retireAt:n3(Z)}),d9={hostId:Z,state:Z,zone:n3(Z),instanceType:n3(Z),allocatedAt:n3(Z),owner:n3(Z),run:n3(Z),retireAt:n3(Z),macos:n3(Z),ready:n3(Z),instances:Q4(yQe)},bQe=Q({name:Z,state:Z,isBaseImage:X4,createdAt:n3(Z),ageSeconds:n3(f3)}),xQe=Q({schema:q4(`openteammate.team-mac/inventory@3`),observedAt:Z,region:Z,hosts:Q4(Q({...d9,usable:X4,reasons:Q4(Z),vms:n3(Q4(bQe)),vmInventoryError:n3(Z),hold:n3(Q({...Z7.fields,expired:X4})),holdInventoryError:n3(Z)})),expiredStillAllocated:Q4(Q(d9))}),SQe=(e,t,n={})=>{let r={now:t,guestMacosMajor:l9.macosMajor};return{schema:`openteammate.team-mac/inventory@3`,observedAt:K7(t),region:R7,hosts:e.map(e=>{let i=e9(e,r),a=n[e.id],o=a?.hold;return{...u9(e),usable:i.usable,reasons:i.usable?[]:i.reasons,vms:a?.vms?.map(e=>vQe(e,t))??null,vmInventoryError:a?.error??(a===void 0?`not queried`:null),hold:o==null?null:{...o,expired:o.deadlineEpochSeconds<=Math.floor(t.getTime()/1e3)},holdInventoryError:a?.holdError??(a===void 0?`not queried`:null)}}),expiredStillAllocated:$7(e,t).map(u9)}};var f9=class extends S3()(`TeamMacError`,{step:Z,message:Z}){},p9=class extends S3()(`AwsFailure`,{step:Z,code:Z,message:Z}){},m9=class extends S3()(`TeamMacBlocked`,{reason:Z,report:J4}){};const h9=e=>g(new URL(`../team-mac/${e}`,import.meta.url)),CQe=[`PATH`,`HOME`,`AWS_CONFIG_FILE`,`AWS_SHARED_CREDENTIALS_FILE`,`AWS_RETRY_MODE`,`AWS_MAX_ATTEMPTS`,`OT_FLEET_AWS_ACCESS_KEY_ID`,`OT_FLEET_AWS_SECRET_ACCESS_KEY`,`OT_FLEET_AWS_SESSION_TOKEN`,`OT_FLEET_AWS_REGION`,`OT_FLEET_AWS_PROFILE`],g9=e=>Object.fromEntries(CQe.flatMap(t=>{let n=e[t];return n===void 0?[]:[[t,n]]})),wQe=e=>{let t={AWS_PROFILE:e.profile,AWS_REGION:e.region,AWS_PAGER:``,AWS_CLI_AUTO_PROMPT:`off`,AWS_RETRY_MODE:`standard`,AWS_MAX_ATTEMPTS:`5`,LC_ALL:`C`};for(let n of[`PATH`,`HOME`,`AWS_CONFIG_FILE`,`AWS_SHARED_CREDENTIALS_FILE`]){let r=e.env[n];r!==void 0&&(t[n]=r)}return t},TQe=e=>/An error occurred \(([A-Za-z0-9.]+)\)/.exec(e)?.[1]??`unknown`,EQe=[100,200],_9=e=>({_tag:`success`,value:e}),DQe=e=>({_tag:`failure`,failure:e}),v9=BY.pipe(PX(e=>new Date(e))),y9=(e,t,n=384)=>{w(l(e),{recursive:!0,mode:448});let r=`${e}.tmp-${process.pid}`;E(r,t,{mode:n}),se(r,n),pe(r,e)},b9=e=>d(e.directory,`known_hosts`),OQe=e=>ue(b9(e))?T(b9(e),`utf8`).split(`
835
+ `).filter(e=>e!==``):[],kQe=(e,t)=>OQe(e).some(e=>e.startsWith(`${t} `)),x9=(e,t,n)=>y9(b9(e),[...OQe(e).filter(e=>!e.startsWith(`${t} `)),n.trimEnd()].join(`
836
+ `)+`
837
+ `),AQe=(e,t,n)=>y9(d(e.directory,`steps`,`${t}.json`),JSON.stringify(n,null,2)+`
838
+ `),S9=X(function*(e,t,n,r){let i=yield*P7,a=r===void 0?JG(5):KG(Math.max(1,r.getTime()-(yield*v9).getTime())),o=yield*i.run({executable:e.tools.aws,args:[...n,`--output`,`json`],env:wQe(e),deadline:a,terminationGrace:qG(3)}).pipe(HX(e=>new f9({step:t,message:e.message})));if(o.exitCode!==0)return yield*new p9({step:t,code:TQe(o.stderr),message:o.stderr.trim().slice(-800)});let s=F7(o.stdout).trim();return yield*kX({try:()=>s===``?{}:JSON.parse(s),catch:()=>new f9({step:t,message:`aws printed no JSON: ${s.slice(0,200)}`})})}),C9=(e,t,n)=>H4(e)(n).pipe(HX(e=>new f9({step:t,message:`unexpected aws output: ${String(e)}`}))),w9=X(function*(e){let t=yield*S9(e,`describe-hosts`,[`ec2`,`describe-hosts`,`--filter`,`Name=tag:${U7.pool},Values=${L7}`,`Name=tag:${U7.kind},Values=${z7}`]).pipe(Y(e=>C9(G7,`describe-hosts`,e))),n=yield*S9(e,`describe-instances`,[`ec2`,`describe-instances`,`--filters`,`Name=tag:${U7.pool},Values=${L7}`,`Name=tag:${U7.kind},Values=${z7}`]).pipe(Y(e=>C9(iQe,`describe-instances`,e)));return cQe(t,n)}),jQe=Q({Tags:Q4(Q({ResourceId:Z,Key:Z,Value:Z}))}),MQe=X(function*(e,t){return(yield*S9(e,`describe-tags`,[`ec2`,`describe-tags`,`--filters`,`Name=resource-id,Values=${t}`,`Name=key,Values=${U7.retireAt}`]).pipe(Y(e=>C9(jQe,`describe-tags`,e)))).Tags.find(e=>e.ResourceId===t)?.Value}),T9=X(function*(e,t,n){let r=[];for(let i of t){let t=yield*MQe(e,i),a=sQe(q7(t),n);if(!a.write){r.push({resource:i,before:t??null,after:t??null,wrote:!1,reason:a.reason});continue}let o,s=!0;for(let t=1;;t+=1){s&&(yield*S9(e,`create-tags`,[`ec2`,`create-tags`,`--resources`,i,`--tags`,`Key=${U7.retireAt},Value=${a.value}`])),o=yield*MQe(e,i);let r=q7(o);if(r!==void 0&&r.getTime()>=n.getTime()-1e3)break;if(t>=5)return yield*new f9({step:`keep-warm`,message:`${i}: wrote ot-retire-at ${a.value}, but after ${t} reads it still read ${o??`nothing`}`});s=r!==void 0,yield*KX(e.poll)}r.push({resource:i,before:t??null,after:o??null,wrote:!0,reason:`moved later`})}return r}),NQe=Q({Status:Z,ResponseCode:G4(Y4),StandardOutputContent:G4(Z),StandardErrorContent:G4(Z)}),PQe=e=>{let t=e.trim().split(`
839
+ `).at(-1)??``;try{return JSON.parse(t)}catch{return}},FQe=new Set([`Success`,`Failed`,`Cancelled`,`TimedOut`,`DeliveryTimedOut`,`ExecutionTimedOut`,`Undeliverable`,`Terminated`,`InvalidPlatform`,`AccessDenied`,`Cancelling`]),E9=X(function*(e,t,n,r,i,a){if((yield*v9).getTime()>=a.getTime())return yield*new m9({reason:`the run's deadline passed before Run Command ${t} could start`,report:{step:t,instanceId:n}});let o=d(e.directory,`steps`,`${t}.ssm-parameters.json`);y9(o,JSON.stringify({commands:r,executionTimeout:[String(i)]},null,2)+`
840
+ `);let s=(yield*S9(e,t,[`ssm`,`send-command`,`--instance-ids`,n,`--document-name`,`AWS-RunShellScript`,`--comment`,`team-mac ${t}`,`--timeout-seconds`,`600`,`--parameters`,`file://${o}`]).pipe(Y(e=>C9(Q({Command:Q({CommandId:Z})}),t,e)))).Command.CommandId,c=(yield*v9).getTime()+(i+720)*1e3,l=Math.min(c,a.getTime());for(let r=(yield*v9).getTime();r<l;r=(yield*v9).getTime()){yield*KX(KG(Math.min(XG(e.poll),l-r)));let i;for(let r=0;;r+=1){let o=a.getTime()-(yield*v9).getTime();if(o<=0)return yield*new m9({reason:`Run Command ${t} reached its deadline while polling AWS`,report:{step:t,instanceId:n,commandId:s}});let c=yield*S9(e,t,[`ssm`,`get-command-invocation`,`--command-id`,s,`--instance-id`,n],a).pipe(PX(_9),RX(`TeamMacError`,e=>TX(function*(){return(yield*v9).getTime()>=a.getTime()?yield*new m9({reason:`Run Command ${t} reached its deadline while polling AWS`,report:{step:t,instanceId:n,commandId:s}}):yield*e})),RX(`AwsFailure`,e=>TX(function*(){return(yield*v9).getTime()>=a.getTime()?yield*new m9({reason:`Run Command ${t} reached its deadline while polling AWS`,report:{step:t,instanceId:n,commandId:s}}):e.code===`InvocationDoesNotExist`?_9(void 0):DQe(e)})));if(c._tag===`success`){i=c.value;break}let l=EQe[r];if(c.failure.code!==`ThrottlingException`||l===void 0)return yield*c.failure;if(o<=l)return yield*new m9({reason:`Run Command ${t} reached its deadline before the next AWS retry`,report:{step:t,instanceId:n,commandId:s}});yield*KX(KG(l))}if(i===void 0)continue;let o=yield*C9(NQe,t,i);if(!FQe.has(o.Status))continue;let c={commandId:s,status:o.Status,responseCode:o.ResponseCode??null,record:PQe(o.StandardOutputContent??``),stderrTail:(o.StandardErrorContent??``).trim().split(`
841
+ `).slice(-12).join(`
842
+ `)};return AQe(e,t,c),c}return a.getTime()<=c?yield*new m9({reason:`Run Command ${t} (${s}) had not finished at the run's deadline`,report:{step:t,instanceId:n,commandId:s}}):yield*new f9({step:t,message:`Run Command ${s} did not finish in time`})}),IQe=(e,t,n)=>{if(t.split(`
843
+ `).includes(n))throw Error(`${e} contains ${n}`);return[`cat > ${e} <<'${n}'`,...t.replace(/\n$/,``).split(`
844
+ `),n]},D9=e=>[`set -e`,`mkdir -p /var/tmp/ot-team-mac`,...IQe(`/var/tmp/ot-team-mac/vz-start-probe.swift`,T(h9(`vz-start-probe.swift`),`utf8`),`OT_TEAM_MAC_PROBE_EOF`),...IQe(`/var/tmp/ot-team-mac/host-prepare.sh`,T(h9(`host-prepare.sh`),`utf8`),`OT_TEAM_MAC_PREPARE_EOF`),`/bin/bash /var/tmp/ot-team-mac/host-prepare.sh ${e}`],O9=Q({phase:Z,outcome:t3([`ok`,`failed`]),bootTime:G4(Z),rebootScheduled:G4(X4),failedStep:G4(Z),aqua:G4(Z),hostKey:G4(Z),lume:G4(Z),base:G4(Z),probe:G4(Z),steps:G4(Q4(Q({name:Z,status:Z,detail:Z})))}),LQe=Q({hostId:Z,instanceId:Z,prepared:Q({setup:O9,check:O9})}),k9=(e,t)=>t.status!==`Success`&&t.status!==`Failed`?J(new f9({step:e,message:`Run Command ended ${t.status}`})):t.record===void 0||t.record===null||typeof t.record!=`object`||Array.isArray(t.record)?J(new f9({step:e,message:`Run Command ended ${t.status} without a JSON record${t.stderrTail===``?``:`: ${t.stderrTail}`}`})):C9(O9,e,t.record).pipe(RX(`TeamMacError`,()=>t.status===`Failed`?J(new f9({step:e,message:`Run Command ended ${t.status}${t.stderrTail===``?``:`: ${t.stderrTail}`}`})):J(new f9({step:e,message:`Run Command returned an invalid record`})))),RQe=X(function*(e,t,n){let r=yield*E9(e,`host-key`,t,D9(`check`),300,n),i=yield*k9(`host-key`,r);if(i.hostKey===void 0||i.hostKey===``)return yield*new f9({step:`host-key`,message:`the host printed no ed25519 host key`});let a=yield*C9(s9,`host-key`,i.hostKey);return{record:i,line:c9(t,a)}}),zQe=X(function*(e,t,n){let r=yield*E9(e,`prepare-setup`,t.instanceId,D9(`setup`),3600,n),i=yield*k9(`prepare-setup`,r);if(i.outcome!==`ok`)return yield*new f9({step:`prepare-setup`,message:`host preparation failed at ${i.failedStep??`an unknown step`}`});let a=E9(e,`prepare-check`,t.instanceId,D9(`check`),300,n).pipe(Y(e=>k9(`prepare-check`,e)),PX(e=>e),RX(`TeamMacError`,e=>q(e.message))),o=e=>typeof e!=`string`&&e.aqua===`ready`&&(i.rebootScheduled!==!0||e.bootTime!==i.bootTime);i.rebootScheduled===!0&&(yield*KX(e.poll));let s=yield*a;for(;!o(s);){if((yield*v9).getTime()>=n.getTime())return yield*new m9({reason:`the Mac's Aqua session for c-team was not ready before the run's deadline`,report:{setup:i,lastCheck:s}});yield*KX(e.poll),s=yield*a}if(s.hostKey===void 0||s.base!==`present`||s.lume===void 0)return yield*new f9({step:`prepare-check`,message:`the prepared host is incomplete: base=${s.base??`?`} lume=${s.lume??`?`}`});let c=yield*C9(s9,`prepare-check-host-key`,s.hostKey);return x9(e,t.instanceId,c9(t.instanceId,c)),yield*S9(e,`tag-ready`,[`ec2`,`create-tags`,`--resources`,t.hostId,t.instanceId,`--tags`,`Key=${U7.ready},Value=true`]),{setup:i,check:s}}),A9=e=>`'${e.replaceAll(`'`,`'\\''`)}'`,BQe=e=>({...g9(e.env),LC_ALL:`C`}),j9=X(function*(e,t,n,r,i){let a=yield*(yield*P7).run({executable:e.tools.ssh,args:[`-F`,d(e.directory,`ssh_config`),`-o`,`ControlMaster=no`,`-o`,`ControlPath=none`,`-o`,`BatchMode=yes`,`mac`,`/bin/bash`,`-s`,`--`,...r.map(A9)],env:BQe(e),stdin:new TextEncoder().encode((n===`vm-start.sh`||n===`host-hold.sh`?T(h9(`host-claim.sh`),`utf8`)+`
845
+ `:``)+T(h9(n),`utf8`)),deadline:i,terminationGrace:qG(5)}).pipe(HX(e=>new f9({step:t,message:e.message}))),o=PQe(F7(a.stdout));return AQe(e,t,{exitCode:a.exitCode,record:o,stderrTail:a.stderr.slice(-2e3)}),o===void 0?yield*new f9({step:t,message:`ssh to the Mac ended ${a.exitCode} with no result: ${a.stderr.trim().slice(-400)}`}):o}),VQe=Q4(Q({name:Z,status:Z,createdAtEpochSeconds:n3(Y4)})),HQe=X(function*(e,t){let n=yield*v9,r=new Date(n.getTime()+XG(JG(5))),i=t.instances[0];if(i===void 0)return yield*new f9({step:`inventory-vms`,message:`${t.id} has no instance to inspect`});yield*I9(e,`inventory-${t.id}`);let a=yield*E9(e,`inventory-host-key-${t.id}`,i.id,[`perl -MJSON::PP -e 'open my $f, q(<), q(/etc/ssh/ssh_host_ed25519_key.pub) or die q(cannot read host key); my $key = <$f>; print encode_json({hostKey => $key}), qq(\\n);'`],60,r);if(a.status!==`Success`)return yield*new f9({step:`inventory-host-key`,message:`Run Command ended ${a.status}`});let o=yield*C9(Q({hostKey:s9}),`inventory-host-key`,a.record);x9(e,i.id,c9(i.id,o.hostKey)),y9(d(e.directory,`ssh_config`),a9({instanceId:i.id,directory:e.directory,otFleet:e.tools.otFleet}));let s=yield*j9(e,`inventory-hold-${t.id}`,`host-hold-read.sh`,[],JG(2)).pipe(Y(e=>C9(n3(Z7),`inventory-hold`,e)),PX(e=>({hold:e,holdError:null})),LX(e=>q({hold:null,holdError:G9(e)}))),c=yield*j9(e,`inventory-vms-${t.id}`,`vm-list.sh`,[],JG(2)).pipe(Y(e=>C9(VQe,`inventory-vms`,e)),PX(e=>({vms:e.map(e=>({name:e.name,state:e.status,createdAtEpochSeconds:e.createdAtEpochSeconds})),error:null})),LX(e=>q({vms:null,error:G9(e)})));return{...s,...c}}),UQe=Q({resource:Z,before:n3(Z),after:n3(Z),wrote:X4,reason:Z}),WQe=Q({kind:q4(`booted`),vm:Z,ip:Z,mac:Z,guestMacos:Z,guestHostKey:Z,bootSeconds:Y4,owner:G4(Z)}),GQe=Q({hostId:Z,instanceId:Z,zone:n3(Z)}),KQe=Q({owner:Z,attempt:Z,deadlineEpochSeconds:f3,released:X4}),qQe=Q({outcome:t3([`held`,`released`,`not-owned`,`blocked`]),reason:G4(Z)}),JQe=Q({vm:Z,host:GQe,owner:Z,startProtocol:G4(q4(`claim-v1`))}),M9=Q({schema:q4(`openteammate.team-mac/run@1`),run:Z,owner:Z,region:Z,admittedAt:G4(Z),vmDeadlineEpochSeconds:G4(f3),host:n3(GQe),hold:G4(KQe),vm:n3(WQe),pending:G4(n3(JQe)),attempts:Q4(J4),allocated:J4,prepared:J4,retireAt:Q4(UQe),stopped:J4}),N9=e=>d(e.directory,`record.json`),P9=(e,t)=>y9(N9(e),JSON.stringify(t,null,2)+`
846
+ `),F9=e=>kX({try:()=>JSON.parse(T(N9(e),`utf8`)),catch:e=>new f9({step:`record`,message:`cannot read record.json: ${String(e)}`})}).pipe(Y(e=>C9(M9,`record`,e))),I9=X(function*(e,t){let n=d(e.directory,`id_ed25519`);return ue(n)&&ue(`${n}.pub`)?T(`${n}.pub`,`utf8`).trim():(w(e.directory,{recursive:!0,mode:448}),yield*(yield*P7).checked({executable:e.tools.sshKeygen,args:[`-q`,`-t`,`ed25519`,`-N`,``,`-C`,`team-mac-${t}`,`-f`,n],env:{PATH:`/usr/bin:/bin`,LC_ALL:`C`},deadline:qG(30),terminationGrace:qG(2)}).pipe(HX(e=>new f9({step:`run-key`,message:e.message}))),T(`${n}.pub`,`utf8`).trim())}),YQe=JG(2),XQe=qG(30),ZQe=X(function*(e,t,n,r){let i=`hold-check-${t.hostId}`,a=yield*E9(e,i,t.instanceId,[`/bin/bash -s -- ${A9(n)} ${A9(B7)} <<'OT_TEAM_MAC_HOLD_CHECK_EOF'`,T(h9(`host-claim.sh`),`utf8`),T(h9(`host-hold-check.sh`),`utf8`),`OT_TEAM_MAC_HOLD_CHECK_EOF`],300,r);return a.status===`Success`?yield*C9(n3(Z),i,a.record):yield*new f9({step:i,message:`host hold read ended ${a.status}: ${a.stderrTail}`})}),QQe=X(function*(e,t,n,r,i,a,o){let s=yield*ZQe(e,{hostId:n.host.id,instanceId:n.instanceId},r,i);if(s!==null)return{verdict:t9({outcome:`host-held`,reason:s}),record:{outcome:`host-held`,reason:s},retire:[],boundSeconds:0};let c=yield*T9(e,[n.host.id,n.instanceId],new Date(i.getTime()+XG(t.need)));if(!kQe(e,n.instanceId)){let t=yield*RQe(e,n.instanceId,i);x9(e,n.instanceId,t.line)}y9(d(e.directory,`ssh_config`),a9({instanceId:n.instanceId,directory:e.directory,otFleet:e.tools.otFleet}));let l=i.getTime()-(yield*v9).getTime()-XG(YQe);if(l<XG(XQe))return yield*new m9({reason:`the run's deadline left too little time to start a VM on ${n.host.id}`,report:{hostId:n.host.id,retireAt:c}});let u=Math.floor(l/1e3),f=`${r} ${b()}`;o({vm:t.vm,host:{hostId:n.host.id,instanceId:n.instanceId,zone:n.host.zone??null},owner:f,startProtocol:`claim-v1`});let p=yield*j9(e,`vm-start-${n.host.id}`,`vm-start.sh`,[t.vm,l9.baseVm,String(u),f,String(a)],qG(u+180)),m=yield*kX({try:()=>pQe(p),catch:e=>new f9({step:`vm-start`,message:`unexpected start record: ${String(e)}`})});return{verdict:t9(m),record:m,retire:c,boundSeconds:u}}),$Qe=Q({InstanceTypeOfferings:Q4(Q({Location:Z}))}),e$e=Q({Images:Q4(Q({ImageId:Z,Name:Z,CreationDate:Z,RootDeviceName:Z}))}),t$e=Q({Quotas:Q4(Q({QuotaName:Z,QuotaCode:Z,Value:Y4}))}),n$e=Q({RequestedQuotas:Q4(Q({Id:Z,Status:Z,DesiredValue:G4(Y4)}))}),r$e=Q({SecurityGroups:Q4(Q({GroupId:Z,VpcId:Z}))}),i$e=Q({Subnets:Q4(Q({SubnetId:Z}))}),a$e=Q({HostIds:Q4(Z)}),o$e=Q({Instances:Q4(Q({InstanceId:Z}))}),s$e=Q({InstanceInformationList:Q4(Q({InstanceId:Z,PingStatus:Z}))}),c$e=X(function*(e,t){let n=`Running Dedicated ${t} Hosts`,r=(yield*S9(e,`quota`,[`service-quotas`,`list-service-quotas`,`--service-code`,`ec2`,`--query`,`{Quotas: Quotas[?QuotaName=='${n}']}`]).pipe(Y(e=>C9(t$e,`quota`,e)))).Quotas[0];if(r===void 0)return yield*new f9({step:`quota`,message:`no quota named ${n}`});let i=(yield*S9(e,`quota-usage`,[`ec2`,`describe-hosts`,`--filter`,`Name=instance-type,Values=${t}.metal`]).pipe(Y(e=>C9(G7,`quota-usage`,e)))).Hosts.filter(e=>e.State!==`released`&&e.State!==`released-permanent-failure`).length,a=yield*S9(e,`quota-requests`,[`service-quotas`,`list-requested-service-quota-change-history-by-quota`,`--service-code`,`ec2`,`--quota-code`,r.QuotaCode]).pipe(Y(e=>C9(n$e,`quota-requests`,e)));return{name:n,code:r.QuotaCode,applied:r.Value,inUse:i,openRequests:a.RequestedQuotas.filter(e=>e.Status===`PENDING`||e.Status===`CASE_OPENED`)}}),l$e=Q({Placement:Q({HostId:Z})}),u$e=e=>ue(e)?kX({try:()=>JSON.parse(T(e,`utf8`)),catch:e=>new f9({step:`run-instances`,message:`cannot read this run's earlier launch request: ${String(e)}`})}).pipe(Y(e=>C9(l$e,`run-instances`,e)),PX(e=>e.Placement.HostId)):q(void 0),d$e=X(function*(e,t){return(yield*S9(e,`find-run-host`,[`ec2`,`describe-hosts`,`--filter`,`Name=tag:${U7.run},Values=${t}`,`Name=tag:${U7.pool},Values=${L7}`]).pipe(Y(e=>C9(G7,`find-run-host`,e)))).Hosts.find(e=>e.State!==`released`&&e.State!==`released-permanent-failure`)}),f$e=X(function*(e,t,n,r,i){let a=``;for(;a!==`Online`;)(yield*v9).getTime()>=i.getTime()&&(yield*new m9({reason:`instance ${n} did not reach Session Manager before the run's deadline`,report:{hostId:t,instanceId:n,retireAt:r}})),yield*KX(e.poll),a=(yield*S9(e,`ssm-ping`,[`ssm`,`describe-instance-information`,`--filters`,`Key=InstanceIds,Values=${n}`]).pipe(Y(e=>C9(s$e,`ssm-ping`,e)))).InstanceInformationList[0]?.PingStatus??`absent`}),p$e=X(function*(e,t,n,r){let i=yield*v9,a=yield*d$e(e,t.run),o=a?.Instances?.[0];if(a!==void 0&&o!==void 0){yield*f$e(e,a.HostId,o.InstanceId,Y7(a.Tags),r);let n=yield*ZQe(e,{hostId:a.HostId,instanceId:o.InstanceId},yield*I9(e,t.run),r);if(n!==null)return yield*new m9({reason:n,report:{hostId:a.HostId}})}let s=yield*c$e(e,t.family),c=$7(n,i).map(u9);if(a===void 0&&s.inUse>=s.applied)return yield*new m9({reason:`the ${s.name} quota (${s.code}) is ${s.applied} and ${s.inUse} hosts hold it`,report:{quota:s,expiredStillAllocated:c}});let l=(yield*S9(e,`security-group`,[`ec2`,`describe-security-groups`,`--filters`,`Name=group-name,Values=ot-no-ingress`]).pipe(Y(e=>C9(r$e,`security-group`,e)))).SecurityGroups[0];if(l===void 0)return yield*new f9({step:`security-group`,message:`no ot-no-ingress security group: the account's one-time pool setup has not been deployed`});let u=yield*S9(e,`image`,[`ec2`,`describe-images`,`--owners`,`amazon`,`--filters`,`Name=name,Values=amzn-ec2-macos-${t.hostMacos}*`,`Name=architecture,Values=arm64_mac`,`Name=state,Values=available`]).pipe(Y(e=>C9(e$e,`image`,e))),f=_Qe(u.Images,i);if(f===void 0)return yield*new m9({reason:`AWS publishes no arm64 macOS ${t.hostMacos} image at least three days old`,report:{images:u.Images.map(e=>e.Name)}});let p=(yield*S9(e,`offerings`,[`ec2`,`describe-instance-type-offerings`,`--location-type`,`availability-zone`,`--filters`,`Name=instance-type,Values=${t.family}.metal`]).pipe(Y(e=>C9($Qe,`offerings`,e)))).InstanceTypeOfferings.map(e=>e.Location).toSorted();if(p.length===0)return yield*new m9({reason:`AWS offers ${t.family}.metal in no zone of ${e.region}`,report:{family:t.family,expiredStillAllocated:c}});let m=[],h=a?.HostId,g=Y7(a?.Tags),_;for(let n=1;h===void 0;n+=1){for(let r of p){let i={...m$e(t),zone:r,retireAt:J7(yield*v9,t.need)},a=d(e.directory,`steps`,`allocate-hosts-${r}-r${n}.json`);y9(a,JSON.stringify(mQe(i,`${t.run}-host-${r}-r${n}`),null,2)+`
847
+ `);let o=yield*S9(e,`allocate-hosts`,[`ec2`,`allocate-hosts`,`--cli-input-json`,`file://${a}`]).pipe(Y(e=>C9(a$e,`allocate-hosts`,e)),PX(e=>e.HostIds[0]),RX(`AwsFailure`,e=>e.code===`InsufficientHostCapacity`?xX(()=>{m.push({zone:r,round:n,code:e.code})}):J(e)));if(o!==void 0){h=o,_=r,g=i.retireAt;break}}if(h!==void 0)break;if((yield*v9).getTime()+XG(e.poll)>=r.getTime())return yield*new m9({reason:`no zone had mac host capacity before the run's deadline`,report:{refusals:m,expiredStillAllocated:c}});yield*KX(e.poll);let i=yield*d$e(e,t.run);h=i?.HostId,g=Y7(i?.Tags)}let v=g??J7(yield*v9,t.need),y=``;for(;y!==`available`;){let t=yield*S9(e,`host-state`,[`ec2`,`describe-hosts`,`--host-ids`,h]).pipe(Y(e=>C9(G7,`host-state`,e)));if(y=t.Hosts[0]?.State??`missing`,_=t.Hosts[0]?.AvailabilityZone??_,y===`available`)break;if((yield*v9).getTime()>=r.getTime())return yield*new m9({reason:`host ${h} stayed ${y} until the run's deadline; it keeps its ot-retire-at ${v} and the administrator's sweep releases it`,report:{hostId:h,state:y,retireAt:v}});yield*KX(e.poll)}let b=(yield*S9(e,`subnet`,[`ec2`,`describe-subnets`,`--filters`,`Name=vpc-id,Values=${l.VpcId}`,`Name=availability-zone,Values=${_??``}`,`Name=default-for-az,Values=true`]).pipe(Y(e=>C9(i$e,`subnet`,e)))).Subnets[0];if(b===void 0)return yield*new f9({step:`subnet`,message:`no default subnet in ${_??`the host's zone`}`});let ee=d(e.directory,`steps`,`run-instances.json`);(yield*u$e(ee))!==h&&y9(ee,JSON.stringify(hQe({...m$e(t),zone:_??``,retireAt:v},{hostId:h,imageId:f.ImageId,rootDevice:f.RootDeviceName,securityGroupId:l.GroupId,subnetId:b.SubnetId}),null,2)+`
848
+ `);let x=(yield*S9(e,`run-instances`,[`ec2`,`run-instances`,`--cli-input-json`,`file://${ee}`]).pipe(Y(e=>C9(o$e,`run-instances`,e)))).Instances[0]?.InstanceId;return x===void 0?yield*new f9({step:`run-instances`,message:`no instance ID`}):(yield*f$e(e,h,x,v,r),{hostId:h,instanceId:x,zone:_??null,image:{id:f.ImageId,name:f.Name},retireAt:v,refusals:m,quota:s})}),m$e=e=>({run:e.run,owner:e.owner,family:e.family,hostMacos:e.hostMacos}),h$e=X(function*(e,t){let n;if(ue(N9(e))){let r=yield*F9(e);if((r.vm!==null||r.pending!==null&&r.pending!==void 0)&&!V4(Q({absent:q4(!0)}))(r.stopped))return yield*new f9({step:`vm-start`,message:`the run record already names a VM; run stop with this --dir before starting again`});if(r.hold!==void 0&&!r.hold.released){if(r.run!==t.run||t.host!==void 0&&t.host!==r.host?.hostId)return yield*new f9({step:`vm-start`,message:`this directory holds a different run or host; stop it before starting another run`});n=r}}let r=yield*I9(e,t.run),i=yield*v9,a=new Date(i.getTime()+XG(t.within)),o=Math.floor((a.getTime()+XG(t.need))/1e3),s=yield*w9(e),c={now:i,guestMacosMajor:l9.macosMajor},l=[],u={schema:`openteammate.team-mac/run@1`,run:t.run,owner:t.owner,region:e.region,vmDeadlineEpochSeconds:o,host:n?.host??null,...n?.hold===void 0?{}:{hold:n.hold},vm:null,pending:null,attempts:l,allocated:null,prepared:null,retireAt:[],stopped:null},d=n?.host?.hostId??t.host,f=d===void 0?dQe(s,c):s.filter(e=>e.id===d).map(e=>e9(e,c)).flatMap(e=>e.usable?[e]:(l.push({hostId:e.host.id,skipped:e.reasons}),[]));d!==void 0&&s.every(e=>e.id!==d)&&l.push({hostId:d,skipped:[`not a team pool Mac`]});let p=X(function*(n){let i=yield*QQe(e,t,n,r,a,o,t=>{u={...u,pending:t},P9(e,u)}),s=i.verdict.kind===`refused`||i.verdict.kind===`held`||(i.verdict.kind===`limit`||i.verdict.kind===`failed`||i.verdict.kind===`cancelled`)&&i.verdict.cloneAbsent;return l.push({hostId:n.host.id,instanceId:n.instanceId,verdict:i.verdict,boundSeconds:i.boundSeconds}),u={...u,pending:s?null:u.pending??null,retireAt:[...u.retireAt,...i.retire]},P9(e,u),i.verdict});for(let t of f){let n=yield*p({host:t.host,instanceId:t.instance.id});if(n.kind===`booted`)return yield*g$e(e,u,t.host,t.instance.id,n);if(n.kind===`limit`&&!n.cloneAbsent)return yield*new f9({step:`vm-start`,message:`${t.host.id}: the clone is not confirmed absent; run stop with this --dir`});if(n.kind!==`limit`&&n.kind!==`held`)return yield*new f9({step:`vm-start`,message:`${t.host.id}: ${n.reason}`})}if(d!==void 0||!t.allocate)return yield*new m9({reason:d===void 0?`no team pool Mac took the VM, and this run does not allocate`:`pool Mac ${d} did not take the VM`,report:{attempts:l,expiredStillAllocated:$7(s,i).map(u9)}});let m=yield*p$e(e,t,s,a);u={...u,allocated:m},P9(e,u);let h=yield*zQe(e,{hostId:m.hostId,instanceId:m.instanceId},a);u={...u,prepared:h},P9(e,u);let g=(yield*w9(e)).find(e=>e.id===m.hostId);if(g===void 0)return yield*new f9({step:`allocate`,message:`${m.hostId} is missing from the pool read`});let _=yield*p({host:g,instanceId:m.instanceId});return _.kind===`booted`?yield*g$e(e,u,g,m.instanceId,_):yield*new f9({step:`vm-start`,message:`the VM did not start on the Mac this run allocated: ${`reason`in _?_.reason:_.kind}`})}),g$e=X(function*(e,t,n,r,i){let a=yield*v9,o={...t,host:{hostId:n.id,instanceId:r,zone:n.zone??null},vm:{...i,...t.pending!==null&&t.pending!==void 0?{owner:t.pending.owner}:{}},pending:null,admittedAt:K7(a)};P9(e,o);let s=yield*kX({try:()=>c9(i.vm,i.guestHostKey),catch:()=>new f9({step:`vm-start`,message:`${i.vm} booted, but its guest gave no ed25519 host key; it is recorded, so run stop with this --dir to delete it`})});return x9(e,i.vm,s),y9(d(e.directory,`ssh_config`),a9({instanceId:r,directory:e.directory,otFleet:e.tools.otFleet,vm:{name:i.vm,ip:i.ip}})),o}),L9=Q({outcome:Z,reason:G4(Z),vm:G4(Z),absent:G4(X4),at:G4(Z)}),_$e=X(function*(e,t=qG(120)){let n=yield*F9(e),r=n.host??n.pending?.host,i=n.vm?.vm??n.pending?.vm;if(r===void 0||i===void 0&&n.hold===void 0)return yield*new f9({step:`stop`,message:`the run record names no VM or host hold`});let a;if(V4(L9)(n.stopped)&&n.stopped.absent===!0)a=n.stopped;else if(i===void 0)a={outcome:`hold-only`,absent:!0};else{if(n.vm===null&&n.pending?.startProtocol!==`claim-v1`)return yield*new f9({step:`vm-stop`,message:`this pending start predates startup claims; remote completion cannot be confirmed; the record and key are retained`});let r=n.vm?.owner??n.pending?.owner;if(n.vm===null&&(r===void 0||r===``))return yield*new f9({step:`vm-stop`,message:`the run record has no VM attempt identity; ownership cannot be confirmed; the record and key are retained`});a=yield*j9(e,`vm-stop`,`vm-stop.sh`,[i,String(LIe(t)),r??``,n.vm?.mac??``],JG(5)).pipe(Y(e=>C9(L9,`vm-stop`,e)))}if(a.outcome===`refused-owner`)return yield*new f9({step:`vm-stop`,message:`${i}: ${a.reason??`the VM has no matching run ownership marker`}; the run record and key are retained`});if(a.outcome===`start-in-progress`)return yield*new m9({reason:`${i}: ${a.reason??`another start or stop of this VM is active; retry stop after it exits`}`,report:{vm:i,hostId:r.hostId,instanceId:r.instanceId}});let o=yield*v9,s={...a,at:a.at??K7(o)},c={...n,host:r,stopped:s};if(P9(e,c),a.absent!==!0)return yield*new f9({step:`vm-stop`,message:`the VM was not confirmed absent: ${a.outcome}`});if(n.hold!==void 0&&!n.hold.released){let t=yield*j9(e,`host-hold-release-${n.hold.attempt}`,`host-hold.sh`,[`release`,n.run,n.hold.owner,`0`,n.hold.attempt],JG(2)).pipe(Y(e=>C9(qQe,`host-hold-release`,e)));if(t.outcome!==`released`&&t.outcome!==`not-owned`)return yield*new f9({step:`host-hold-release`,message:t.reason??`the host hold was not released`});c={...c,hold:{...n.hold,released:!0}},P9(e,c)}let l=yield*T9(e,[r.hostId,r.instanceId],new Date(o.getTime()+XG(V7))),u={...c,pending:null,retireAt:[...n.retireAt,...l]};return P9(e,u),yield*kX({try:()=>{let t=d(e.directory,`id_ed25519`);me(t,{force:!0}),me(`${t}.pub`,{force:!0})},catch:e=>new f9({step:`run-key-cleanup`,message:`cannot remove the run key after confirming the VM absent: ${String(e)}`})}),{...u,stopped:s}}),R9=Z.check(u3(/^[a-z0-9][a-z0-9-]{0,47}$/)).pipe(r3(`TeamMacRunName`)),z9=Z.check(u3(/^h-[0-9a-f]{8,17}$/)).pipe(r3(`TeamMacHostId`)),B9=Z.check(u3(/^[1-9][0-9]*(s|m|h)$/)).pipe(r3(`DurationText`)),V9=e=>{let t=Number(e.slice(0,-1)),n=e.slice(-1);return n===`h`?YG(t):n===`m`?JG(t):qG(t)},H9=sqe,U9={profile:H9,region:H9,otFleet:G4(H9)},v$e=Q(U9),y$e=Q({...U9,directory:H9}),b$e=Q({...U9,directory:H9,run:R9,owner:H9,vm:G4(R9),need:B9,within:B9,host:G4(z9),noAllocate:X4,family:H9,hostMacos:H9}),x$e=Q({...U9,directory:H9,host:z9,run:R9,adopt:X4,within:B9}),S$e=Q({...U9,directory:H9,host:z9,run:R9,owner:H9,need:B9,within:B9}),W9=(e,t)=>{for(let n of(t??``).split(c)){if(n===``)continue;let t=d(n,e);try{return C(t,le.X_OK),t}catch{continue}}},G9=e=>e instanceof m9?e.reason:e instanceof f9||e instanceof p9?`${e.step}: ${e.message}`:String(e),K9=X(function*(e,t,n){let r=t.otFleet??n.otFleet;if(r===void 0)return yield*new I7({field:`otFleet`,message:`no ot-fleet helper was given, and this entry has no default: pass the use-cloud-vms skill's scripts/ot-fleet`});let i={aws:W9(`aws`,e.PATH),ssh:W9(`ssh`,e.PATH),sshKeygen:W9(`ssh-keygen`,e.PATH)};for(let[e,t]of Object.entries(i))if(t===void 0)return yield*new f9({step:`tools`,message:`no ${e} on PATH`});return{profile:t.profile,region:t.region,tools:{aws:i.aws??``,ssh:i.ssh??``,sshKeygen:i.sshKeygen??``,otFleet:r},env:g9(e),directory:p(t.directory),poll:KG(Number(e.TEAM_MAC_POLL_MILLIS??`20000`))}}),C$e=(e,t,n)=>kBe(xX(()=>de(d(i(),`team-mac-inventory-`))),r=>TX(function*(){let i=yield*K9(e,{...t,directory:r},n),a=yield*w9(i),o=yield*v9,s={};for(let e of a){let t=e.instances[0];if(t===void 0){s[e.id]={vms:null,error:`host has no instance to inspect`,hold:null,holdError:`host has no instance to inspect`};continue}if(t.state!==`running`){s[e.id]={vms:null,error:`not inspected: instance is ${t.state}`,hold:null,holdError:`not inspected: instance is ${t.state}`};continue}s[e.id]=yield*HQe(i,e).pipe(LX(e=>q({vms:null,error:G9(e),hold:null,holdError:G9(e)})))}return SQe(a,o,s)}),e=>xX(()=>me(e,{recursive:!0,force:!0}))),w$e=X(function*(e,t,n){let r=yield*K9(e,t,n);return yield*h$e(r,{run:t.run,owner:t.owner,vm:t.vm??t.run,need:V9(t.need),within:V9(t.within),host:t.host,allocate:!t.noAllocate,family:t.family,hostMacos:t.hostMacos})}),T$e=X(function*(e,t,n){let r=yield*K9(e,t,n),i=ue(N9(r))?yield*F9(r):void 0,a=i!==void 0&&V4(Q({absent:q4(!0)}))(i.stopped)&&(i.hold===void 0||i.hold.released)&&!ue(d(r.directory,`id_ed25519`))&&!ue(d(r.directory,`id_ed25519.pub`))?void 0:i;if(a!==void 0&&(a.hold!==void 0||a.run!==t.run||a.host?.hostId!==t.host||a.pending!==null&&a.pending!==void 0))return yield*new f9({step:`host-hold`,message:`finish stop for the run already recorded in this directory before requesting another hold`});let o=yield*v9,s=new Date(o.getTime()+XG(V9(t.within))),c=new Date(s.getTime()+XG(V9(t.need))),l=(yield*w9(r)).find(e=>e.id===t.host);if(l===void 0)return yield*new m9({reason:`not a team pool Mac`,report:{hostId:t.host}});let u=e9(l,{now:o,guestMacosMajor:l9.macosMajor});if(!u.usable)return yield*new m9({reason:u.reasons.join(`; `),report:{hostId:t.host}});let f=yield*I9(r,t.run),p=yield*RQe(r,u.instance.id,s);x9(r,u.instance.id,p.line),y9(d(r.directory,`ssh_config`),a9({instanceId:u.instance.id,directory:r.directory,otFleet:r.tools.otFleet,...a?.vm===void 0||a.vm===null?{}:{vm:{name:a.vm.vm,ip:a.vm.ip}}}));let m=yield*T9(r,[l.id,u.instance.id],c),h=b(),g={schema:`openteammate.team-mac/run@1`,run:t.run,owner:t.owner,region:r.region,host:{hostId:l.id,instanceId:u.instance.id,zone:l.zone??null},vm:a?.vm??null,...a?.vmDeadlineEpochSeconds===void 0?{}:{vmDeadlineEpochSeconds:a.vmDeadlineEpochSeconds},pending:null,attempts:a?.attempts??[],allocated:a?.allocated??null,prepared:a?.prepared??null,retireAt:[...a?.retireAt??[],...m],stopped:null,hold:{owner:f,attempt:h,deadlineEpochSeconds:Math.floor(c.getTime()/1e3),released:!1}};P9(r,g);let _=yield*j9(r,`host-hold-${h}`,`host-hold.sh`,[`hold`,t.run,f,String(Math.floor(c.getTime()/1e3)),h],V9(t.within)).pipe(Y(e=>C9(qQe,`host-hold`,e)));if(_.outcome!==`held`)return yield*new m9({reason:_.reason??`the host hold was refused`,report:{hostId:l.id}});let v=yield*F9(r);return v.hold?.attempt!==h||v.hold.released||v.stopped!==null?yield*new m9({reason:`this host hold was stopped or replaced while acquisition was in progress`,report:{hostId:l.id}}):v}),E$e=X(function*(e,t,n){let r=yield*K9(e,t,n),i=(yield*w9(r)).find(e=>e.id===t.host),a=i?.instances[0];if(i===void 0||a===void 0)return yield*new f9({step:`prepare`,message:`${t.host} is not a team pool Mac with an instance`});if(!t.adopt&&i.tags[U7.run]!==t.run)return yield*new f9({step:`prepare`,message:`${i.id} belongs to run ${i.tags[U7.run]??`(no ot-run tag)`}, not ${t.run}: prepare only a Mac your run allocated`});if(!t.adopt&&i.tags[U7.ready]===`true`)return yield*new f9({step:`prepare`,message:`${i.id} is already prepared (ot-ready=true) and runs may be using it: start reuses it as it is`});let o=new Date((yield*BY)+XG(V9(t.within))),s=yield*zQe(r,{hostId:i.id,instanceId:a.id},o);return{hostId:i.id,instanceId:a.id,prepared:s}}),D$e=X(function*(e,t,n){let r=yield*K9(e,t,n);return yield*_$e(r)});var O$e=class e extends PW()(`@openteammate/offload/Compute`){static local=(t,n)=>xY(e,TX(function*(){let r=yield*P7;return e.of({"team-mac.hold":e=>T$e(t,e,n).pipe($X(P7,r)),"team-mac.inventory":e=>C$e(t,e,n).pipe($X(P7,r)),"team-mac.start":e=>w$e(t,e,n).pipe($X(P7,r)),"team-mac.prepare":e=>E$e(t,e,n).pipe($X(P7,r)),"team-mac.stop":e=>D$e(t,e,n).pipe($X(P7,r))})}))};const k$e=(e,t)=>TX(function*(){return yield*(yield*O$e)[e](t)}),q9=(e,t)=>({name:e,...t,error:e3([I7,...t.errors])}),J9={profile:{flag:`profile`,description:`The AWS profile for the team's agent role (role_arn plus source_profile openteammate-team, session name <teammate>@<lane>)`},region:{flag:`region`,description:`The pool's region`,default:R7},otFleet:{flag:`ot-fleet`,description:`The use-cloud-vms skill's ot-fleet helper`,optional:!0}},Y9={flag:`dir`,description:`This run's private directory outside the repository: run key, known_hosts, ssh_config, record.json and step records`},A$e={"team-mac.inventory":q9(`team-mac.inventory`,{description:`List the team's pool Macs, say which can take a run's VM and why not, and name expired Macs that are still allocated. Read-only`,kind:`query`,payload:v$e,success:xQe,errors:[f9,p9],cli:{command:[`team-mac`,`inventory`],flags:J9}}),"team-mac.start":q9(`team-mac.start`,{description:`Start this run's macOS VM on a team pool Mac: a compatible ready Mac with room, else a Mac this run allocates and prepares. Admits the VM only when its guest answers over SSH; reaches the Mac as ${B7} with the team credential`,kind:`mutation`,payload:b$e,success:M9,errors:[m9,f9,p9],cli:{command:[`team-mac`,`start`],flags:{...J9,directory:Y9,run:{flag:`run`,description:`This run's unique name: lowercase letters, digits and hyphens; the ot-run tag of any Mac it allocates`},owner:{flag:`owner`,description:`Your handle, for the ot-owner tag`},vm:{flag:`vm`,description:`The VM's name on the Mac (default: the run name)`,optional:!0},need:{flag:`need`,description:`How long the run will use the VM, such as 90m or 3h; before the VM starts, the Mac's ot-retire-at is moved to no earlier than the --within deadline plus this`},within:{flag:`within`,description:`The controller's acquisition budget for allocating, preparing and booting, such as 30m or 2h; remote work can outlive it`},host:{flag:`host`,description:`Use this pool Mac only; no other Mac, no allocation`,optional:!0},noAllocate:{flag:`no-allocate`,description:`Reuse a pool Mac only; report instead of allocating one`,default:!1},family:{flag:`family`,description:`Mac host family to allocate`,default:`mac-m4`},hostMacos:{flag:`host-macos`,description:`macOS major version for a Mac this run allocates`,default:`27`}}}}),"team-mac.hold":q9(`team-mac.hold`,{description:`Hold a ready pool Mac for this run alone until --within plus --need expires. Refuses VMs owned by other runs. Stop releases the hold; start from the same --dir may use it`,kind:`mutation`,payload:S$e,success:M9,errors:[m9,f9,p9],cli:{command:[`team-mac`,`hold`],flags:{...J9,directory:Y9,host:{flag:`host`,description:`The ready pool Mac to hold`},run:{flag:`run`,description:`This run's unique name: lowercase letters, digits and hyphens`},owner:{flag:`owner`,description:`Your handle`},need:{flag:`need`,description:`How long the run needs the host alone, such as 3h`},within:{flag:`within`,description:`Acquisition budget, such as 10m; the hold expires at this deadline plus --need`}}}}),"team-mac.prepare":q9(`team-mac.prepare`,{description:`Prepare a pool Mac this run allocated whose preparation did not finish, over Run Command: the c-team login user with auto-login, SSH host keys, Lume, the base image and the start probe; then publish ot-ready. Refuses another run's Mac and a Mac already ready, unless an administrator passes --adopt`,kind:`mutation`,payload:x$e,success:LQe,errors:[m9,f9,p9],cli:{command:[`team-mac`,`prepare`],flags:{...J9,directory:Y9,host:{flag:`host`,description:`The pool Mac this run allocated`},run:{flag:`run`,description:`This run's name: the Mac's ot-run tag must be it`},adopt:{flag:`adopt`,description:`For the account's administrator only: prepare a Mac made outside team-mac, or prepare a ready Mac again (scripts/cloud-qa/pool/README.md)`,default:!1},within:{flag:`within`,description:`Bound for preparing, such as 30m`}}}}),"team-mac.stop":q9(`team-mac.stop`,{description:`Stop and delete this run's VM, confirm it absent, and move the Mac's ot-retire-at to no earlier than now plus the keep-warm window`,kind:`mutation`,payload:y$e,success:M9,errors:[m9,f9,p9],cli:{command:[`team-mac`,`stop`],flags:{...J9,directory:Y9}}})},j$e=e=>HUe(X0(e.ast)),M$e=e=>UUe(X0(e.ast)),N$e=(e,t,n,r)=>{if(M$e(n))return t5(r.flag).pipe(i5(r.description),c5(n));if(j$e(n))return CXe(r.flag).pipe(i5(r.description),c5(n));throw Error(`${e}: payload field ${t} is neither text nor a switch, so it has no flag`)},P$e=(e,t,n,r)=>{let i=N$e(e,t,n,r);return r.optional===!0?o5(i):r.default===void 0?i:i.pipe(s5(r.default))},F$e=e=>Object.fromEntries(Object.entries(e).flatMap(([e,t])=>$Fe(t)?EW(t,{onNone:()=>[],onSome:t=>[[e,t]]}):[[e,t]])),X9=(e,t)=>{if(Array.isArray(t))return t.map((t,n)=>X9(Array.isArray(e)?e[n]:void 0,t));if(!_H(t))return t;let n=_H(e)?e:{},r=[...Object.keys(n).filter(e=>Object.hasOwn(t,e)),...Object.keys(t).filter(e=>!Object.hasOwn(n,e))];return Object.fromEntries(r.map(e=>[e,X9(n[e],t[e])]))},I$e=e=>{let[t]=ZHe()(e.issue).issues,n=t?.path?.[0];return new I7({field:typeof n==`string`?n:`payload`,message:t?.message??e.message})},L$e=(e,t,n,r)=>{let i=A$e[e],a=i.cli.flags,o=r,s=Object.fromEntries(Object.entries(i.payload.fields).map(([t,n])=>{let r=a[t];if(r===void 0)throw Error(`${e}: payload field ${t} has no flag hint`);let i=o[t],s=i===void 0?r:{...r,description:`${r.description} (${i})`};return[t,P$e(e,t,n,s)]})),c=e=>{let t=a[e];return t===void 0?e:`--${t.flag}`};return Y5(i.cli.command[1],s,r=>TX(function*(){let a=yield*H4(KKe(i.payload))(F$e(r),{onExcessProperty:`error`}).pipe(HX(I$e)),o=yield*k$e(e,a),s=yield*WKe(i.success)(o).pipe(UX);t.out(JSON.stringify(X9(o,s),null,2)+`
849
+ `);let c=n[e];c!==void 0&&t.err(c(o,a))}).pipe(RX(`InvalidInput`,e=>J(new I7({field:c(e.field),message:e.message}))))).pipe(X5(i.description))},R$e=(e,t,n,r)=>Object.values(A$e).filter(t=>t.cli.command[0]===e).map(e=>L$e(e.name,t,n,r)),z$e={out:e=>process.stdout.write(e),err:e=>process.stderr.write(e)},B$e=()=>({version:`0.1.0`,defaults:{otFleet:g(new URL(`../../../.agents/skills/use-cloud-vms/scripts/ot-fleet`,import.meta.url))},notes:{otFleet:`default: this checkout's copy`}}),V$e={"team-mac.inventory":e=>[...e.hosts.map(e=>{let t=`VMs unknown: ${e.vmInventoryError}`;if(e.vms!==null){let n=e.vms.filter(e=>e.state===`running`).length,r=e.vms.filter(e=>e.state===`stopped`).length,i=e.vms.length-n-r,a=e.vms.find(e=>e.isBaseImage);t=`${n} running, ${r} stopped${i===0?``:`, ${i} other state`}${a===void 0?``:`; base image: ${a.name} (${a.state})`}`}let n=e.holdInventoryError===null?e.hold===null?`no hold`:`hold for ${e.hold.run} until epoch ${e.hold.deadlineEpochSeconds}${e.hold.expired?` (expired)`:``}`:`hold unknown: ${e.holdInventoryError}`;return`${e.hostId} ${e.state} retire-at ${e.retireAt??`?`} ${e.usable?`usable`:`not usable: ${e.reasons.join(`; `)}`} ${t}; ${n}\n`}),...e.expiredStillAllocated.map(e=>`expired but still allocated: ${e.hostId} (retire-at ${e.retireAt??`?`}, ${e.state}); the administrator's sweep releases it once AWS allows, and it counts against the account's Mac host quota until then\n`)].join(``),"team-mac.start":(e,t)=>`VM ${e.vm?.vm??`?`} booted on ${e.host?.hostId??`?`} at ${e.vm?.ip??`?`}: ssh -F ${d(p(t.directory),`ssh_config`)} vm\n`,"team-mac.hold":e=>`Mac ${e.host?.hostId??`?`} held for ${e.run} until epoch ${e.hold?.deadlineEpochSeconds??`?`}; stop with the same --dir to release it\n`,"team-mac.stop":e=>{let t=U4(L9)(e.stopped),n=e.retireAt.at(-1)?.after??`unknown`;if(t.outcome===`hold-only`)return`Host hold for ${e.host?.hostId??`?`} released\n`;let r=t.outcome===`absent-already`?`already absent`:`deleted and confirmed absent`;return`VM ${t.vm??e.vm?.vm??`?`} ${r}; the Mac's ot-retire-at is ${n} (moved to no earlier than now plus ${zIe(V7)} hours), and the administrator's sweep retires the Mac once it passes\n`}},H$e=async(e,t=process.env,n=z$e,r=B$e())=>{let i=Y5(`team-mac`).pipe(X5(`Team cloud Macs for a run: inventory, hold, start, prepare and stop`),cZe(R$e(`team-mac`,n,V$e,r.notes))),a=await IBe(Z5(i,{version:r.version})(e).pipe(DBe(O$e.local(t,r.defaults).pipe(TY(P7.layer.pipe(TY(Sqe)))))));if(AY(a))return GV.done;let o=AW(Ize(a));return o instanceof m9?(n.out(JSON.stringify({blocked:!0,reason:o.reason,report:o.report},null,2)+`
850
+ `),n.err(`team-mac: blocked: ${o.reason}\n`),GV.blocked):o instanceof f9||o instanceof p9?(n.err(`team-mac: ${o.step}: ${o.message}\n`),GV.failure):o instanceof I7?(n.err(`team-mac: ${o.field}: ${o.message}\n`),GV.usage):o===void 0?(n.err(`team-mac: ${Vze(a.cause)}\n`),GV.failure):(n.err(`team-mac: ${String(o)}\n`),GV.usage)},Z9=`Usage: impulse-compute <group> [arguments]
851
+
852
+ Groups:
853
+ team-mac Team cloud Macs for a run: inventory, hold, start, prepare and stop
854
+ linux-desktop A Linux desktop in an E2B guest or on this machine: sessions, apps,
855
+ captures and exact-crop checks
856
+ ec2 Create, reach, inspect, extend and retire a Windows EC2 instance
857
+
858
+ Options:
859
+ --version, -v Print this package's version
860
+ --help, -h Print this help
861
+
862
+ Run "impulse-compute <group> --help" for a group's commands.
863
+ `,[Q9,...$9]=process.argv.slice(2),U$e=Q9===`team-mac`?Lx(Q9):void 0;U$e===void 0?Q9===`team-mac`?process.exitCode=await H$e($9,process.env,z$e,{version:ke,defaults:{},notes:{}}):Q9===`linux-desktop`?$Pe($9):Q9===`ec2`?X_e($9,process.env).pipe(Vve):Q9===`--version`||Q9===`-v`?process.stdout.write(`${ke}\n`):Q9===`--help`||Q9===`-h`?process.stdout.write(Z9):(process.stderr.write(Q9===void 0?Z9:`impulse-compute: unknown group ${Q9}\n\n${Z9}`),process.exitCode=GV.usage):(process.stderr.write(`${U$e}\n`),process.exitCode=GV.failure);export{};
864
+ /*!
865
+ @effect/platform-node-shared@4.1.4 (MIT, LICENSE)
866
+ MIT License
867
+
868
+ Copyright (c) 2023 Effectful Technologies Inc
869
+
870
+ Permission is hereby granted, free of charge, to any person obtaining a copy
871
+ of this software and associated documentation files (the "Software"), to deal
872
+ in the Software without restriction, including without limitation the rights
873
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
874
+ copies of the Software, and to permit persons to whom the Software is
875
+ furnished to do so, subject to the following conditions:
876
+
877
+ The above copyright notice and this permission notice shall be included in all
878
+ copies or substantial portions of the Software.
879
+
880
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
881
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
882
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
883
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
884
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
885
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
886
+ SOFTWARE.
887
+
888
+
889
+ @effect/platform-node@4.1.4 (MIT, LICENSE)
890
+ MIT License
891
+
892
+ Copyright (c) 2023 Effectful Technologies Inc
893
+
894
+ Permission is hereby granted, free of charge, to any person obtaining a copy
895
+ of this software and associated documentation files (the "Software"), to deal
896
+ in the Software without restriction, including without limitation the rights
897
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
898
+ copies of the Software, and to permit persons to whom the Software is
899
+ furnished to do so, subject to the following conditions:
900
+
901
+ The above copyright notice and this permission notice shall be included in all
902
+ copies or substantial portions of the Software.
903
+
904
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
905
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
906
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
907
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
908
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
909
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
910
+ SOFTWARE.
911
+
912
+
913
+ @inkeep/impulse-owned-process@0.3.0 (UNLICENSED, package.json)
914
+
915
+ effect@4.1.4 (MIT, LICENSE)
916
+ MIT License
917
+
918
+ Copyright (c) 2023 Effectful Technologies Inc
919
+
920
+ Permission is hereby granted, free of charge, to any person obtaining a copy
921
+ of this software and associated documentation files (the "Software"), to deal
922
+ in the Software without restriction, including without limitation the rights
923
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
924
+ copies of the Software, and to permit persons to whom the Software is
925
+ furnished to do so, subject to the following conditions:
926
+
927
+ The above copyright notice and this permission notice shall be included in all
928
+ copies or substantial portions of the Software.
929
+
930
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
931
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
932
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
933
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
934
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
935
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
936
+ SOFTWARE.
937
+
938
+
939
+ @bufbuild/protobuf@2.17.0 ((Apache-2.0 AND BSD-3-Clause), package.json)
940
+
941
+ @connectrpc/connect-web@2.3.0 (Apache-2.0, package.json)
942
+
943
+ @connectrpc/connect@2.3.0 (Apache-2.0, package.json)
944
+
945
+ @e2b/dockerfile-utils@0.1.1 (Apache-2.0, LICENSE)
946
+ Apache License
947
+ Version 2.0, January 2004
948
+ http://www.apache.org/licenses/
949
+
950
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
951
+
952
+ 1. Definitions.
953
+
954
+ "License" shall mean the terms and conditions for use, reproduction,
955
+ and distribution as defined by Sections 1 through 9 of this document.
956
+
957
+ "Licensor" shall mean the copyright owner or entity authorized by
958
+ the copyright owner that is granting the License.
959
+
960
+ "Legal Entity" shall mean the union of the acting entity and all
961
+ other entities that control, are controlled by, or are under common
962
+ control with that entity. For the purposes of this definition,
963
+ "control" means (i) the power, direct or indirect, to cause the
964
+ direction or management of such entity, whether by contract or
965
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
966
+ outstanding shares, or (iii) beneficial ownership of such entity.
967
+
968
+ "You" (or "Your") shall mean an individual or Legal Entity
969
+ exercising permissions granted by this License.
970
+
971
+ "Source" form shall mean the preferred form for making modifications,
972
+ including but not limited to software source code, documentation
973
+ source, and configuration files.
974
+
975
+ "Object" form shall mean any form resulting from mechanical
976
+ transformation or translation of a Source form, including but
977
+ not limited to compiled object code, generated documentation,
978
+ and conversions to other media types.
979
+
980
+ "Work" shall mean the work of authorship, whether in Source or
981
+ Object form, made available under the License, as indicated by a
982
+ copyright notice that is included in or attached to the work
983
+ (an example is provided in the Appendix below).
984
+
985
+ "Derivative Works" shall mean any work, whether in Source or Object
986
+ form, that is based on (or derived from) the Work and for which the
987
+ editorial revisions, annotations, elaborations, or other modifications
988
+ represent, as a whole, an original work of authorship. For the purposes
989
+ of this License, Derivative Works shall not include works that remain
990
+ separable from, or merely link (or bind by name) to the interfaces of,
991
+ the Work and Derivative Works thereof.
992
+
993
+ "Contribution" shall mean any work of authorship, including
994
+ the original version of the Work and any modifications or additions
995
+ to that Work or Derivative Works thereof, that is intentionally
996
+ submitted to Licensor for inclusion in the Work by the copyright owner
997
+ or by an individual or Legal Entity authorized to submit on behalf of
998
+ the copyright owner. For the purposes of this definition, "submitted"
999
+ means any form of electronic, verbal, or written communication sent
1000
+ to the Licensor or its representatives, including but not limited to
1001
+ communication on electronic mailing lists, source code control systems,
1002
+ and issue tracking systems that are managed by, or on behalf of, the
1003
+ Licensor for the purpose of discussing and improving the Work, but
1004
+ excluding communication that is conspicuously marked or otherwise
1005
+ designated in writing by the copyright owner as "Not a Contribution."
1006
+
1007
+ "Contributor" shall mean Licensor and any individual or Legal Entity
1008
+ on behalf of whom a Contribution has been received by Licensor and
1009
+ subsequently incorporated within the Work.
1010
+
1011
+ 2. Grant of Copyright License. Subject to the terms and conditions of
1012
+ this License, each Contributor hereby grants to You a perpetual,
1013
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1014
+ copyright license to reproduce, prepare Derivative Works of,
1015
+ publicly display, publicly perform, sublicense, and distribute the
1016
+ Work and such Derivative Works in Source or Object form.
1017
+
1018
+ 3. Grant of Patent License. Subject to the terms and conditions of
1019
+ this License, each Contributor hereby grants to You a perpetual,
1020
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1021
+ (except as stated in this section) patent license to make, have made,
1022
+ use, offer to sell, sell, import, and otherwise transfer the Work,
1023
+ where such license applies only to those patent claims licensable
1024
+ by such Contributor that are necessarily infringed by their
1025
+ Contribution(s) alone or by combination of their Contribution(s)
1026
+ with the Work to which such Contribution(s) was submitted. If You
1027
+ institute patent litigation against any entity (including a
1028
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
1029
+ or a Contribution incorporated within the Work constitutes direct
1030
+ or contributory patent infringement, then any patent licenses
1031
+ granted to You under this License for that Work shall terminate
1032
+ as of the date such litigation is filed.
1033
+
1034
+ 4. Redistribution. You may reproduce and distribute copies of the
1035
+ Work or Derivative Works thereof in any medium, with or without
1036
+ modifications, and in Source or Object form, provided that You
1037
+ meet the following conditions:
1038
+
1039
+ (a) You must give any other recipients of the Work or
1040
+ Derivative Works a copy of this License; and
1041
+
1042
+ (b) You must cause any modified files to carry prominent notices
1043
+ stating that You changed the files; and
1044
+
1045
+ (c) You must retain, in the Source form of any Derivative Works
1046
+ that You distribute, all copyright, patent, trademark, and
1047
+ attribution notices from the Source form of the Work,
1048
+ excluding those notices that do not pertain to any part of
1049
+ the Derivative Works; and
1050
+
1051
+ (d) If the Work includes a "NOTICE" text file as part of its
1052
+ distribution, then any Derivative Works that You distribute must
1053
+ include a readable copy of the attribution notices contained
1054
+ within such NOTICE file, excluding those notices that do not
1055
+ pertain to any part of the Derivative Works, in at least one
1056
+ of the following places: within a NOTICE text file distributed
1057
+ as part of the Derivative Works; within the Source form or
1058
+ documentation, if provided along with the Derivative Works; or,
1059
+ within a display generated by the Derivative Works, if and
1060
+ wherever such third-party notices normally appear. The contents
1061
+ of the NOTICE file are for informational purposes only and
1062
+ do not modify the License. You may add Your own attribution
1063
+ notices within Derivative Works that You distribute, alongside
1064
+ or as an addendum to the NOTICE text from the Work, provided
1065
+ that such additional attribution notices cannot be construed
1066
+ as modifying the License.
1067
+
1068
+ You may add Your own copyright statement to Your modifications and
1069
+ may provide additional or different license terms and conditions
1070
+ for use, reproduction, or distribution of Your modifications, or
1071
+ for any such Derivative Works as a whole, provided Your use,
1072
+ reproduction, and distribution of the Work otherwise complies with
1073
+ the conditions stated in this License.
1074
+
1075
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
1076
+ any Contribution intentionally submitted for inclusion in the Work
1077
+ by You to the Licensor shall be under the terms and conditions of
1078
+ this License, without any additional terms or conditions.
1079
+ Notwithstanding the above, nothing herein shall supersede or modify
1080
+ the terms of any separate license agreement you may have executed
1081
+ with Licensor regarding such Contributions.
1082
+
1083
+ 6. Trademarks. This License does not grant permission to use the trade
1084
+ names, trademarks, service marks, or product names of the Licensor,
1085
+ except as required for reasonable and customary use in describing the
1086
+ origin of the Work and reproducing the content of the NOTICE file.
1087
+
1088
+ 7. Disclaimer of Warranty. Unless required by applicable law or
1089
+ agreed to in writing, Licensor provides the Work (and each
1090
+ Contributor provides its Contributions) on an "AS IS" BASIS,
1091
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1092
+ implied, including, without limitation, any warranties or conditions
1093
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
1094
+ PARTICULAR PURPOSE. You are solely responsible for determining the
1095
+ appropriateness of using or redistributing the Work and assume any
1096
+ risks associated with Your exercise of permissions under this License.
1097
+
1098
+ 8. Limitation of Liability. In no event and under no legal theory,
1099
+ whether in tort (including negligence), contract, or otherwise,
1100
+ unless required by applicable law (such as deliberate and grossly
1101
+ negligent acts) or agreed to in writing, shall any Contributor be
1102
+ liable to You for damages, including any direct, indirect, special,
1103
+ incidental, or consequential damages of any character arising as a
1104
+ result of this License or out of the use or inability to use the
1105
+ Work (including but not limited to damages for loss of goodwill,
1106
+ work stoppage, computer failure or malfunction, or any and all
1107
+ other commercial damages or losses), even if such Contributor
1108
+ has been advised of the possibility of such damages.
1109
+
1110
+ 9. Accepting Warranty or Additional Liability. While redistributing
1111
+ the Work or Derivative Works thereof, You may choose to offer,
1112
+ and charge a fee for, acceptance of support, warranty, indemnity,
1113
+ or other liability obligations and/or rights consistent with this
1114
+ License. However, in accepting such obligations, You may act only
1115
+ on Your own behalf and on Your sole responsibility, not on behalf
1116
+ of any other Contributor, and only if You agree to indemnify,
1117
+ defend, and hold each Contributor harmless for any liability
1118
+ incurred by, or claims asserted against, such Contributor by reason
1119
+ of your accepting any such warranty or additional liability.
1120
+
1121
+ END OF TERMS AND CONDITIONS
1122
+
1123
+ APPENDIX: How to apply the Apache License to your work.
1124
+
1125
+ To apply the Apache License to your work, attach the following
1126
+ boilerplate notice, with the fields enclosed by brackets "[]"
1127
+ replaced with your own identifying information. (Don't include
1128
+ the brackets!) The text should be enclosed in the appropriate
1129
+ comment syntax for the file format. We also recommend that a
1130
+ file or class name and description of purpose be included on the
1131
+ same "printed page" as the copyright notice for easier
1132
+ identification within third-party archives.
1133
+
1134
+ Copyright 2023 FoundryLabs, Inc.
1135
+
1136
+ Licensed under the Apache License, Version 2.0 (the "License");
1137
+ you may not use this file except in compliance with the License.
1138
+ You may obtain a copy of the License at
1139
+
1140
+ http://www.apache.org/licenses/LICENSE-2.0
1141
+
1142
+ Unless required by applicable law or agreed to in writing, software
1143
+ distributed under the License is distributed on an "AS IS" BASIS,
1144
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1145
+ See the License for the specific language governing permissions and
1146
+ limitations under the License.
1147
+
1148
+
1149
+ @e2b/dockerfile-utils@0.1.1 (Apache-2.0, NOTICE)
1150
+ E2B Dockerfile utils
1151
+ Copyright 2025 FoundryLabs, Inc.
1152
+
1153
+ This product includes software derived from moby/buildkit
1154
+ (https://github.com/moby/buildkit), licensed under the Apache License 2.0:
1155
+ the Dockerfile parser and shell lexer are ported from frontend/dockerfile.
1156
+
1157
+ This product includes software derived from moby/patternmatcher
1158
+ (https://github.com/moby/patternmatcher), licensed under the Apache License 2.0.
1159
+ Copyright 2012-2017 Docker, Inc.
1160
+ This product includes software developed at Docker, Inc. (https://www.docker.com).
1161
+
1162
+
1163
+ @effect/platform-node-shared@4.1.4 (MIT, LICENSE)
1164
+ MIT License
1165
+
1166
+ Copyright (c) 2023 Effectful Technologies Inc
1167
+
1168
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1169
+ of this software and associated documentation files (the "Software"), to deal
1170
+ in the Software without restriction, including without limitation the rights
1171
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1172
+ copies of the Software, and to permit persons to whom the Software is
1173
+ furnished to do so, subject to the following conditions:
1174
+
1175
+ The above copyright notice and this permission notice shall be included in all
1176
+ copies or substantial portions of the Software.
1177
+
1178
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1179
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1180
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1181
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1182
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1183
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1184
+ SOFTWARE.
1185
+
1186
+
1187
+ @effect/platform-node@4.1.4 (MIT, LICENSE)
1188
+ MIT License
1189
+
1190
+ Copyright (c) 2023 Effectful Technologies Inc
1191
+
1192
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1193
+ of this software and associated documentation files (the "Software"), to deal
1194
+ in the Software without restriction, including without limitation the rights
1195
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1196
+ copies of the Software, and to permit persons to whom the Software is
1197
+ furnished to do so, subject to the following conditions:
1198
+
1199
+ The above copyright notice and this permission notice shall be included in all
1200
+ copies or substantial portions of the Software.
1201
+
1202
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1203
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1204
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1205
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1206
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1207
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1208
+ SOFTWARE.
1209
+
1210
+
1211
+ chalk@5.6.2 (MIT, license)
1212
+ MIT License
1213
+
1214
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
1215
+
1216
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1217
+
1218
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1219
+
1220
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1221
+
1222
+
1223
+ compare-versions@6.1.1 (MIT, LICENSE)
1224
+ The MIT License (MIT)
1225
+
1226
+ Copyright (c) 2015-2021 Ole Michelsen
1227
+
1228
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1229
+ of this software and associated documentation files (the "Software"), to deal
1230
+ in the Software without restriction, including without limitation the rights
1231
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1232
+ copies of the Software, and to permit persons to whom the Software is
1233
+ furnished to do so, subject to the following conditions:
1234
+
1235
+ The above copyright notice and this permission notice shall be included in all
1236
+ copies or substantial portions of the Software.
1237
+
1238
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1239
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1240
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1241
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1242
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1243
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1244
+ SOFTWARE.
1245
+
1246
+
1247
+ e2b@2.63.0 (MIT, LICENSE)
1248
+ MIT License
1249
+
1250
+ Copyright (c) 2025 FOUNDRYLABS, INC.
1251
+
1252
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1253
+
1254
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1255
+
1256
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1257
+
1258
+ effect@4.1.4 (MIT, LICENSE)
1259
+ MIT License
1260
+
1261
+ Copyright (c) 2023 Effectful Technologies Inc
1262
+
1263
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1264
+ of this software and associated documentation files (the "Software"), to deal
1265
+ in the Software without restriction, including without limitation the rights
1266
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1267
+ copies of the Software, and to permit persons to whom the Software is
1268
+ furnished to do so, subject to the following conditions:
1269
+
1270
+ The above copyright notice and this permission notice shall be included in all
1271
+ copies or substantial portions of the Software.
1272
+
1273
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1274
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1275
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1276
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1277
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1278
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1279
+ SOFTWARE.
1280
+
1281
+
1282
+ openapi-fetch@0.17.0 (MIT, LICENSE)
1283
+ MIT License
1284
+
1285
+ Copyright (c) 2023 Drew Powers
1286
+
1287
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1288
+ of this software and associated documentation files (the "Software"), to deal
1289
+ in the Software without restriction, including without limitation the rights
1290
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1291
+ copies of the Software, and to permit persons to whom the Software is
1292
+ furnished to do so, subject to the following conditions:
1293
+
1294
+ The above copyright notice and this permission notice shall be included in all
1295
+ copies or substantial portions of the Software.
1296
+
1297
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1298
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1299
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1300
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1301
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1302
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1303
+ SOFTWARE.
1304
+
1305
+
1306
+ platform@1.3.6 (MIT, LICENSE)
1307
+ Copyright 2014-2020 Benjamin Tan
1308
+ Copyright 2011-2013 John-David Dalton
1309
+
1310
+ Permission is hereby granted, free of charge, to any person obtaining
1311
+ a copy of this software and associated documentation files (the
1312
+ "Software"), to deal in the Software without restriction, including
1313
+ without limitation the rights to use, copy, modify, merge, publish,
1314
+ distribute, sublicense, and/or sell copies of the Software, and to
1315
+ permit persons to whom the Software is furnished to do so, subject to
1316
+ the following conditions:
1317
+
1318
+ The above copyright notice and this permission notice shall be
1319
+ included in all copies or substantial portions of the Software.
1320
+
1321
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1322
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1323
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1324
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1325
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1326
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1327
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1328
+
1329
+
1330
+ pngjs@7.0.0 (MIT, LICENSE)
1331
+ pngjs original work Copyright (c) 2015 Luke Page & Original Contributors
1332
+ pngjs derived work Copyright (c) 2012 Kuba Niegowski
1333
+
1334
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1335
+ of this software and associated documentation files (the "Software"), to deal
1336
+ in the Software without restriction, including without limitation the rights
1337
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1338
+ copies of the Software, and to permit persons to whom the Software is
1339
+ furnished to do so, subject to the following conditions:
1340
+
1341
+ The above copyright notice and this permission notice shall be included in
1342
+ all copies or substantial portions of the Software.
1343
+
1344
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1345
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1346
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1347
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1348
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1349
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1350
+ THE SOFTWARE.
1351
+
1352
+
1353
+ @effect/platform-node-shared@4.1.4 (MIT, LICENSE)
1354
+ MIT License
1355
+
1356
+ Copyright (c) 2023 Effectful Technologies Inc
1357
+
1358
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1359
+ of this software and associated documentation files (the "Software"), to deal
1360
+ in the Software without restriction, including without limitation the rights
1361
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1362
+ copies of the Software, and to permit persons to whom the Software is
1363
+ furnished to do so, subject to the following conditions:
1364
+
1365
+ The above copyright notice and this permission notice shall be included in all
1366
+ copies or substantial portions of the Software.
1367
+
1368
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1369
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1370
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1371
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1372
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1373
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1374
+ SOFTWARE.
1375
+
1376
+
1377
+ @effect/platform-node@4.1.4 (MIT, LICENSE)
1378
+ MIT License
1379
+
1380
+ Copyright (c) 2023 Effectful Technologies Inc
1381
+
1382
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1383
+ of this software and associated documentation files (the "Software"), to deal
1384
+ in the Software without restriction, including without limitation the rights
1385
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1386
+ copies of the Software, and to permit persons to whom the Software is
1387
+ furnished to do so, subject to the following conditions:
1388
+
1389
+ The above copyright notice and this permission notice shall be included in all
1390
+ copies or substantial portions of the Software.
1391
+
1392
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1393
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1394
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1395
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1396
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1397
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1398
+ SOFTWARE.
1399
+
1400
+
1401
+ @inkeep/impulse-owned-process@0.3.0 (UNLICENSED, package.json)
1402
+
1403
+ effect@4.1.4 (MIT, LICENSE)
1404
+ MIT License
1405
+
1406
+ Copyright (c) 2023 Effectful Technologies Inc
1407
+
1408
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1409
+ of this software and associated documentation files (the "Software"), to deal
1410
+ in the Software without restriction, including without limitation the rights
1411
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1412
+ copies of the Software, and to permit persons to whom the Software is
1413
+ furnished to do so, subject to the following conditions:
1414
+
1415
+ The above copyright notice and this permission notice shall be included in all
1416
+ copies or substantial portions of the Software.
1417
+
1418
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1419
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1420
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1421
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1422
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1423
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1424
+ SOFTWARE.
1425
+
1426
+ */