@yuriai/web 0.2.33 → 0.2.34-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AssistantContactStatus-BecTSK5f.js → AssistantContactStatus-D3ScljGl.js} +3 -3
- package/dist/assets/{AssistantUnreadBadge-DXBINpQi.js → AssistantUnreadBadge-NkBCB4n9.js} +1 -1
- package/dist/assets/{AssistantView-CsTe7SbK.js → AssistantView-CI2lhkIT.js} +1 -1
- package/dist/assets/{DiagramView-xR1d8Ci2.js → DiagramView-DNQmqZTz.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DWRx9_eT.js → GuiPluginSurface-Da61Xn7x.js} +1 -1
- package/dist/assets/MarkdownRenderer-D-7r0LeT.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-CVuPLz_2.js → MarkdownRendererImpl-yQaid-kp.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-ChHTqL5i.js → MarkstreamRendererImpl-B1S_vvdw.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-CR8A8U_9.js → MobileDetailNavigation-Hd18mJ2l.js} +1 -1
- package/dist/assets/{MobileShareBridge-HTePwQfS.js → MobileShareBridge-CgAoZoO9.js} +1 -1
- package/dist/assets/{MobileTabPageHeader-DefPdEd9.js → MobileTabPageHeader-B9kurLFw.js} +1 -1
- package/dist/assets/{MultiRunWindow-BcZ0T4aM.js → MultiRunWindow-CdUZs6BA.js} +1 -1
- package/dist/assets/{SettingsView-23-CPGGR.js → SettingsView-C0P981Yx.js} +1 -1
- package/dist/assets/{SettingsWindow-BP17xUN4.js → SettingsWindow-Bep47gp_.js} +1 -1
- package/dist/assets/{SetupTourDialog-DpBf7CQD.js → SetupTourDialog-CngeU4Gl.js} +1 -1
- package/dist/assets/{TerminalView-D63MDq0o.js → TerminalView-BRuYIzl6.js} +1 -1
- package/dist/assets/{ToolOutputDialog-GHLioHaB.js → ToolOutputDialog-DvBKkPyY.js} +1 -1
- package/dist/assets/{VoiceSettings-CE3EP3rH.js → VoiceSettings-Bwq3L5vz.js} +1 -1
- package/dist/assets/{appThemeRegistry-CH4WssKX.js → appThemeRegistry-DSbTAzmO.js} +1 -1
- package/dist/assets/{capgoAdapter-Dy6n1WSE.js → capgoAdapter-D9oY9_ut.js} +1 -1
- package/dist/assets/{gitApi-C9-qJDQ6.js → gitApi-DSzxh9dp.js} +1 -1
- package/dist/assets/{insertionBoundaries-DBgOjaGM.js → insertionBoundaries-B_epKOnH.js} +1 -1
- package/dist/assets/{main-C9v4tzOp.js → main-C8bkHEMX.js} +2 -2
- package/dist/assets/{main-DqXuTHzy.js → main-DROYKEfx.js} +5 -5
- package/dist/assets/{mcpQueries-BtTn7vvF.js → mcpQueries-Daeejbnx.js} +1 -1
- package/dist/assets/{miniChat-bbNf-k6A.js → miniChat-CoUl0Vav.js} +2 -2
- package/dist/assets/{mobile-C90aX0Ai.js → mobile-LaGrgSUM.js} +2 -2
- package/dist/assets/{mobileBackNavigation-BdgpYYzc.js → mobileBackNavigation-goIeVVNl.js} +1 -1
- package/dist/assets/{multirun-CXgyUUR_.js → multirun-D_JGy3RU.js} +1 -1
- package/dist/assets/{native-config-Npmx-FHi.js → native-config-BFOCyZg2.js} +1 -1
- package/dist/assets/{projectMeta-Byov-Bf8.js → projectMeta-wNuM5rHW.js} +1 -1
- package/dist/assets/{pwa-BPywK9hc.js → pwa-xGAzXaZv.js} +1 -1
- package/dist/assets/{queue-abort-optimistic-Cd9goCtP.js → queue-abort-optimistic-BGuIwEZM.js} +1 -1
- package/dist/assets/{readiness-Ba0wqXJe.js → readiness-BPbnvr2e.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-Dgj_tRzV.js → renderElectronMiniChatApp-C3T22u2H.js} +2 -2
- package/dist/assets/{renderMobileApp-muVQ8WGb.js → renderMobileApp-DAQsqK1D.js} +7 -7
- package/dist/assets/{runtimeConfig-YOnCHT8o.js → runtimeConfig-DtKtvKA2.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-BkJyMZon.js → runtimeEndpointReset-BwfxkwS0.js} +3 -3
- package/dist/assets/{sessionLookup-BjxeNni8.js → sessionLookup-pYkh3EU2.js} +1 -1
- package/dist/assets/{speechSettingsQueries-CvDICLsw.js → speechSettingsQueries-6Ea0FfKL.js} +1 -1
- package/dist/assets/src-BgE3FRXg.css +2 -0
- package/dist/assets/types-CNECQLeq.js +2 -0
- package/dist/assets/{useAppFontEffects-DoOyrAD1.js → useAppFontEffects-BW8yQWSG.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-Dnn-eOUA.js → useDesktopWindowControlsLayout-BC2wTKdJ.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DouDG4ZI.js → useEffectiveDirectory-OJzoI-nH.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-C2mIlnz9.js → useMobileNavigationStore-C8nCzxDH.js} +4 -4
- package/dist/assets/{usePluginsStore-CePF_bcX.js → usePluginsStore-B3584ktF.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-D0Nf66Jj.js → useWorkerHighlightedLines-CZlfrVSP.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +6 -6
- package/package.json +1 -1
- package/server/lib/llm/DOCUMENTATION.md +17 -2
- package/server/lib/llm/bridge-plugin.bundle.js +10 -10
- package/server/lib/llm/bridge-plugin.js +30 -3
- package/server/lib/llm/bridge-plugin.test.js +49 -0
- package/dist/assets/MarkdownRenderer-WSxkmNai.js +0 -2
- package/dist/assets/src-GtPQ8f4o.css +0 -2
- package/dist/assets/types-BkSficP0.js +0 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import{createHash as e}from"node:crypto";var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};const r=(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}}},i={pipe(){return r(this,arguments)}},a=/*#__PURE__*/ function(){function e(){}return e.prototype=i,e}(),o=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)}}}},s=e=>e,c=e=>()=>e,l=/*#__PURE__*/ c(!0),u=/*#__PURE__*/ c(!1),d=/*#__PURE__*/ c(void 0),f=d;function ee(e){let t=/* @__PURE__ */ 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 te(e){let t=/* @__PURE__ */ 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 ne=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete(`stack`);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},re=/*#__PURE__*/ new WeakSet,ie=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);let ae=0;const oe=()=>{ae++};function se(e){return typeof e==`string`}function ce(e){return typeof e==`number`}function le(e){return typeof e==`boolean`}function ue(e){return typeof e==`bigint`}function de(e){return typeof e==`symbol`}function fe(e){return se(e)||ce(e)||de(e)}function pe(e){return typeof e==`function`}function me(e){return e!=null}function he(e){return!0}function ge(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _e(e){return typeof e==`object`&&!!e||pe(e)}const p=/*#__PURE__*/ o(2,(e,t)=>_e(e)&&t in e);function ve(e){return e instanceof Error}function ye(e){return p(e,Symbol.iterator)||se(e)}const be=`~effect/Hash`,
|
|
2
|
-
`+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=
|
|
3
|
-
`)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}const
|
|
1
|
+
import{createHash as e}from"node:crypto";var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};const r=(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}}},i={pipe(){return r(this,arguments)}},a=/*#__PURE__*/ function(){function e(){}return e.prototype=i,e}(),o=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)}}}},s=e=>e,c=e=>()=>e,l=/*#__PURE__*/ c(!0),u=/*#__PURE__*/ c(!1),d=/*#__PURE__*/ c(void 0),f=d;function ee(e){let t=/* @__PURE__ */ 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 te(e){let t=/* @__PURE__ */ 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 ne=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete(`stack`);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},re=/*#__PURE__*/ new WeakSet,ie=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);let ae=0;const oe=()=>{ae++};function se(e){return typeof e==`string`}function ce(e){return typeof e==`number`}function le(e){return typeof e==`boolean`}function ue(e){return typeof e==`bigint`}function de(e){return typeof e==`symbol`}function fe(e){return se(e)||ce(e)||de(e)}function pe(e){return typeof e==`function`}function me(e){return e!=null}function he(e){return!0}function ge(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _e(e){return typeof e==`object`&&!!e||pe(e)}const p=/*#__PURE__*/ o(2,(e,t)=>_e(e)&&t in e);function ve(e){return e instanceof Error}function ye(e){return p(e,Symbol.iterator)||se(e)}const be=`~effect/Hash`,m=e=>{switch(typeof e){case`number`:return Ee(e);case`bigint`:return De(e.toString(10));case`string`:return De(e);case`function`:case`object`:if(e===null)break;if(e instanceof Date)return Number.isNaN(e.getTime())?De(`Invalid Date`):De(e.toISOString());if(e instanceof RegExp)return De(e.toString());{if(re.has(e))return xe(e);let t=Ie.get(e);if(t!==void 0)return t;if(Le.has(e))return oe(),De(`[Circular]`);Le.add(e);let n=ae,r;try{r=`~effect/Hash`in e?e[be]():typeof e==`function`?xe(e):e instanceof DataView?je(ie(e)):Array.isArray(e)||ArrayBuffer.isView(e)?je(e):e instanceof Map?Me(e):e instanceof Set?Pe(e):ke(e)}finally{Le.delete(e)}return n===ae&&Ie.set(e,r),r}}return we(Se(De(String(e))))},xe=e=>(Fe.has(e)||Fe.set(e,we(Math.random()*4294967296|0)),Fe.get(e)),Se=e=>(e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^e>>>16),Ce=/*#__PURE__*/ o(2,(e,t)=>Se(Math.imul(e,2654435761)+Math.imul(t,2246822507))),we=e=>e&3221225471|e>>>1&1073741824,Te=/*#__PURE__*/ new DataView(/*#__PURE__*/ new ArrayBuffer(8)),Ee=e=>{let t=e|0;return t===e?we(t):(Te.setFloat64(0,e===e?e:NaN),we(Ce(Te.getInt32(0),Te.getInt32(4))))},De=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return we(t)},Oe=(e,t)=>{let n=12289;for(let r of t)n^=Ce(m(r),m(e[r]));return we(n)},ke=e=>Oe(e,ne(e)),Ae=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return we(r)},je=e=>{let t=6151;for(let n of e)t=Ce(t,m(n));return we(t)},Me=/*#__PURE__*/ Ae(/*#__PURE__*/ De(`Map`),([e,t])=>Ce(m(e),m(t))),Ne=/*#__PURE__*/ De(`Set`),Pe=/*#__PURE__*/ Ae(Ne,e=>Ce(Ne,m(e))),Fe=/*#__PURE__*/ new WeakMap,Ie=/*#__PURE__*/ new WeakMap,Le=/*#__PURE__*/ new WeakSet,Re=`~effect/Equal`;function ze(){return arguments.length===1?e=>Be(e,arguments[0]):Be(arguments[0],arguments[1])}function Be(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`||re.has(e)||re.has(t)?!1:Ve(e,t):!1}function Ve(e,t){let n=Ue.length;for(let r=n;r-->0;)if(Ue[r]===e&&We[r]===t)return!0;if(n)return He(e,t);let r=Ge.get(e);r||Ge.set(e,r=/* @__PURE__ */ new WeakMap);let i=r.get(t);return i===void 0&&r.set(t,i=He(e,t)),i}function He(e,t){Ue.push(e),We.push(t);try{return Ke(e,t)}finally{Ue.pop(),We.pop()}}const Ue=[],We=[],Ge=/*#__PURE__*/ new WeakMap;function Ke(e,t){if(m(e)!==m(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=nt(e);if(n!==nt(t)||typeof e==`function`&&!n)return!1;if(n)return e[Re](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:qe(e,t);if(ArrayBuffer.isView(e)){let n=e instanceof DataView;return!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||n!==t instanceof DataView?!1:n?Je(ie(e),ie(t)):Je(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:Xe(e,t,Ze,Qe):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:Xe(e,t,m,Be):Ye(e,t)}function qe(e,t){for(let n=0;n<e.length;n++)if(!Be(e[n],t[n]))return!1;return!0}function Je(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 Ye(e,t){let n=ne(e),r=ne(t);if(n.size!==r.size)return!1;for(let i of n)if(!r.has(i)||!Be(e[i],t[i]))return!1;return!0}function Xe(e,t,n,r){let i=/* @__PURE__ */ new Map;for(let e of t){let t=n(e),r=i.get(t);r?r.push(e):i.set(t,[e])}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();continue outer}}return!1}return!0}const Ze=e=>m(e[0]),Qe=(e,t)=>Be(e[0],t[0])&&Be(e[1],t[1]),$e=()=>0;function et(e,t){return tt((n,r)=>e(n[0],r[0])&&t(n[1],r[1]))}function tt(e){return function(t,n){return Xe(t,n,$e,e)}}const nt=e=>p(e,Re),rt=/*#__PURE__*/ Symbol.for(`~effect/Redactable`),it=e=>p(e,rt);function at(e){return it(e)?ot(e):e}function ot(e){return e[rt](globalThis[`~effect/Fiber/currentFiber`]?.context??lt)}const st=`~effect/Fiber/currentFiber`,ct=/*#__PURE__*/ new Map,lt={"~effect/Context":{},base:ct,depth:0,mapUnsafe:ct,pipe(){return r(this,arguments)}};function h(e,t){let n=t?.space??0,r=/* @__PURE__ */ 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 ut;r.add(e);let l;if(rt in e)l=c(ot(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(`,
|
|
2
|
+
`+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=pt(e);else if(!t?.ignoreToString&&p(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=mt(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=>`${dt(t)}:${c(ht(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${dt(t)}: ${c(ht(e,t),n+1)}`).join(`,
|
|
3
|
+
`)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}const ut=`[Circular]`;function dt(e){return typeof e==`string`?JSON.stringify(e):String(e)}function ft(e){return e.map(e=>`[${dt(e)}]`).join(``)}function pt(e){try{return e.toISOString()}catch{return`Invalid Date`}}function mt(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function ht(e,t){try{return e[t]}catch{return`[property access threw]`}}function gt(e,t){let n=[];return JSON.stringify(e,function(e,t){let r=Object.getOwnPropertyDescriptor(this,e)?.value,i=p(r,rt)?at(r):at(t);if(typeof i==`bigint`)return h(i);if(typeof i!=`object`||!i)return i;let a=i instanceof Error&&!p(i,`toJSON`)?{...i,name:i.name,message:i.message}:i;for(;n.length>0&&n[n.length-1]!==this;)n.pop();if(!n.includes(i))return n.push(i),a!==i&&n.push(a),a},t?.space)??`null`}const _t=/*#__PURE__*/ Symbol.for(`nodejs.util.inspect.custom`),vt=e=>{try{return e=at(e),p(e,`toJSON`)&&pe(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(vt):e}catch{return`[toJSON threw]`}},yt={toJSON(){return vt(this)},[_t](){return this.toJSON()},toString(){return h(this.toJSON())}};var bt=class{[_t](){return this.toJSON()}toString(){return h(this.toJSON())}};const xt=/*#__PURE__*/ (()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),St=()=>Error.stackTraceLimit,Ct=e=>{xt&&(Error.stackTraceLimit=e)};var wt=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 Tt=/*#__PURE__*/ (()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}};return St()!==0&&t[e](()=>(/* @__PURE__ */ Error()).stack)?.includes(e)===!0?t[e]:n[e]})();function Et(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function Dt(e,t){for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&Et(e,n,t[n])}const Ot=`~effect/Effect`,kt=`~effect/Exit`,At={_A:s,_E:s,_R:s},jt=`${Ot}/identifier`,g=`${Ot}/args`,Mt=`${Ot}/evaluate`,Nt=`${Ot}/successCont`,Pt=`${Ot}/failureCont`,Ft=`${Ot}/ensureCont`,It=/*#__PURE__*/ Symbol.for(`effect/Effect/Yield`),Lt={pipe(){return r(this,arguments)},toJSON(){return{...this}},toString(){return h(this.toJSON(),{ignoreToString:!0,space:2})},[_t](){return this.toJSON()}},Rt={[Ot]:At,...Lt,[Symbol.iterator](){return new wt(this)},toJSON(){return{_id:`Effect`,op:this[jt],...`~effect/Effect/args`in this?{args:this[g]}:void 0}}},zt=e=>p(e,Ot),Bt=e=>p(e,kt),Vt=`~effect/Cause`,Ht=`~effect/Cause/Reason`,Ut=e=>p(e,Vt);var Wt=class{constructor(e){this[Vt]=Vt,this.reasons=e}pipe(){return r(this,arguments)}toJSON(){return{_id:`Cause`,failures:this.reasons.map(e=>e.toJSON())}}toString(){return`Cause(${h(this.reasons)})`}[_t](){return this.toJSON()}[Re](e){return Ut(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>ze(t,e.reasons[n]))}[be](){return je(this.reasons)}};const Gt=/*#__PURE__*/ new WeakMap;var Kt=class{[Ht];annotations;_tag;constructor(e,t,n){if(this[Ht]=Ht,this._tag=e,t!==qt&&typeof n==`object`&&n&&t.size>0){let e=Gt.get(n);e&&(t=new Map([...e,...t])),Gt.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);e.mapUnsafe.forEach((e,r)=>{t?.overwrite!==!0&&n.has(r)||n.set(r,e)});let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return r(this,arguments)}toString(){return h(this)}[_t](){return this.toString()}};const qt=/*#__PURE__*/ new Map;var Jt=class extends Kt{constructor(e,t=qt){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${h(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[Re](e){return nn(e)&&ze(this.error,e.error)&&ze(this.annotations,e.annotations)}[be](){return Ce(De(this._tag))(Ce(m(this.error))(m(this.annotations)))}};const Yt=e=>new Wt(e),Xt=(e,t)=>{let n=/* @__PURE__ */ new Map,r=[];for(let i of e.concat(t)){let e=m(i),t=n.get(e);if(t===void 0)n.set(e,[i]);else if(t.some(e=>ze(e,i)))continue;else t.push(i);r.push(i)}return r},Zt=/*#__PURE__*/ o(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new Wt(Xt(e.reasons,t.reasons));return ze(e,n)?e:n}),Qt=e=>new Wt([new Jt(e)]);var $t=class extends Kt{constructor(e,t=qt){super(`Die`,t,e),this.defect=e}toString(){return`Die(${h(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[Re](e){return rn(e)&&ze(this.defect,e.defect)&&ze(this.annotations,e.annotations)}[be](){return Ce(De(this._tag))(Ce(m(this.defect))(m(this.annotations)))}};const en=e=>new Wt([new $t(e)]),tn=/*#__PURE__*/ o(e=>Ut(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new Wt(e.reasons.map(e=>e.annotate(t,n)))),nn=e=>e._tag===`Fail`,rn=e=>e._tag===`Die`,an=e=>e._tag===`Interrupt`;function on(e){return hn(`Effect.evaluate: Not implemented`)}const sn=e=>({...Rt,[jt]:e.op,[Mt]:e[`~effect/Effect/evaluate`]??on,[Nt]:e[Nt],[Pt]:e[Pt],[Ft]:e[Ft]}),cn=e=>{let t=sn(e),n=function(e){this[g]=e};return n.prototype=t,function(e){return new n(e)}},ln=e=>{let t={[kt]:kt,_tag:e.op,get[e.prop](){return this[g]},...sn(e),toString(){return`${e.op}(${h(this[g])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[g]}},[Re](e){return Bt(e)&&e._tag===this._tag&&ze(this[`~effect/Effect/args`],e[`~effect/Effect/args`])},[be](){return Ce(De(e.op),m(this[g]))}},n=function(e){this[g]=e};return n.prototype=t,function(e){return new n(e)}},un=/*#__PURE__*/ ln({op:`Success`,prop:`value`,[Mt](e){let t=e.getCont(Nt);return t?t[Nt](this[g],e,this):e.yieldWith(this)}}),dn={key:`effect/Cause/StackTrace`},fn={key:`effect/Cause/InterruptorStackTrace`},pn=/*#__PURE__*/ ln({op:`Failure`,prop:`cause`,[Mt](e){let t=this[g],n=!1;e.cache.stackFrame&&(t=tn(t,{mapUnsafe:/* @__PURE__ */ new Map([[dn.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(Pt),i=e._interruptedCause;if(i&&e.interruptible){let a=!1;for(;r&&e.interruptible;)a||=jt in r,r=e.getCont(Pt);a&&(t=Yt(t.reasons.filter(e=>e._tag!==`Fail`))),t=Zt(t,i),n=!0}return r?r[Pt](t,e,n?void 0:this):e.yieldWith(n?pn(t):this)}}),mn=e=>pn(Qt(e)),hn=e=>pn(en(e)),_=/*#__PURE__*/ cn({op:`WithFiber`,[Mt](e){return this[g](e)}}),gn=/*#__PURE__*/ function(){class e extends globalThis.Error{}let t=/*#__PURE__*/ sn({op:`YieldableError`,[Mt](){return mn(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),_n=/*#__PURE__*/ function(){let e=/*#__PURE__*/ Symbol.for(`effect/Data/Error/plainArgs`);return class extends gn{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Dt(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),vn=e=>{class t extends _n{_tag=e}return t.prototype.name=e,t},yn=`~effect/Cause/Done`,bn=e=>p(e,yn),xn={[yn]:yn,_tag:`Done`,value:void 0},Sn=e=>e===void 0?xn:{[yn]:yn,_tag:`Done`,value:e},Cn=/*#__PURE__*/ mn(xn),wn=e=>e===void 0?Cn:mn(Sn(e)),Tn=e=>sn({op:e.label,[Mt]:e.evaluate}),En=e=>(t,n)=>t===n||e(t,n),Dn=(e,t)=>e===t,On=()=>Dn;function kn(e){return En((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e[r](t[r],n[r]))return!1;return!0})}function An(e){return En((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 jn=`~effect/Option`,Mn={[jn]:{_A:e=>e},...Lt,[Symbol.iterator](){return new wt(this)}},Nn=/*#__PURE__*/ Object.defineProperty(/*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Mn),{_tag:`Some`,_op:`Some`,[Re](e){return In(e)&&Rn(e)&&ze(this.value,e.value)},[be](){return Ce(m(this._tag))(m(this.value))},toString(){return`some(${h(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:vt(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),Pn=/*#__PURE__*/ m(`None`),Fn=/*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Mn),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[Re](e){return In(e)&&Ln(e)},[be](){return Pn},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),In=e=>p(e,jn),Ln=e=>e._tag===`None`,Rn=e=>e._tag===`Some`,zn=/*#__PURE__*/ Object.create(Fn),Bn=function(e){this.value=e};Bn.prototype=Nn;const Vn=e=>new Bn(e),Hn=`~effect/Result`,Un={[Hn]:{
|
|
4
4
|
/* v8 ignore next 2 */
|
|
5
|
-
_A:e=>e,_E:e=>e},...
|
|
5
|
+
_A:e=>e,_E:e=>e},...Lt,[Symbol.iterator](){return new wt(this)}},Wn=/*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Un),{_tag:`Success`,_op:`Success`,[Re](e){return Kn(e)&&Jn(e)&&ze(this.success,e.success)},[be](){return Ce(m(this._tag))(m(this.success))},toString(){return`success(${h(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:vt(this.success)}}}),Gn=/*#__PURE__*/ Object.assign(/*#__PURE__*/ Object.create(Un),{_tag:`Failure`,_op:`Failure`,[Re](e){return Kn(e)&&qn(e)&&ze(this.failure,e.failure)},[be](){return Ce(m(this._tag))(m(this.failure))},toString(){return`failure(${h(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:vt(this.failure)}}}),Kn=e=>p(e,Hn),qn=e=>e._tag===`Failure`,Jn=e=>e._tag===`Success`,Yn=function(e){this.failure=e};Yn.prototype=Gn;const Xn=e=>new Yn(e),Zn=function(e){this.success=e};Zn.prototype=Wn;const Qn=e=>new Zn(e);function $n(e){return(t,n)=>t===n?0:e(t,n)}const er=/*#__PURE__*/ $n((e,t)=>e<t?-1:1),tr=/*#__PURE__*/ $n((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),nr=/*#__PURE__*/ o(2,(e,t)=>$n((n,r)=>e(t(n),t(r)))),rr=e=>o(2,(t,n)=>e(t,n)===-1),ir=e=>o(2,(t,n)=>e(t,n)===1),ar=e=>o(2,(t,n)=>e(t,n)!==1),or=e=>o(2,(t,n)=>e(t,n)!==-1),sr=e=>o(2,(t,n)=>t===n||e(t,n)<1?t:n),cr=e=>o(2,(t,n)=>t===n||e(t,n)>-1?t:n),lr=()=>zn,ur=Vn,dr=Ln,fr=Rn,pr=/*#__PURE__*/ o(2,(e,{onNone:t,onSome:n})=>dr(e)?t():n(e.value)),mr=/*#__PURE__*/ o(2,(e,t)=>dr(e)?t():e.value),hr=e=>e==null?lr():ur(e),gr=/*#__PURE__*/ mr(d),_r=e=>(...t)=>{try{return ur(e(...t))}catch{return lr()}},vr=/*#__PURE__*/ o(2,(e,t)=>dr(e)?lr():t(e.value)?ur(e.value):lr()),yr=`~effect/Context/Service`,br=function(){function e(){}let t=e;Object.setPrototypeOf(t,xr);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[Cr]=Cr,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&Sr.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},xr={[yr]:yr,.../*#__PURE__*/ Tn({label:`Service`,evaluate(e){return un(Wr(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return Rr(this,e)},use(e){return _(t=>e(Wr(t.context,this)))},useSync(e){return _(t=>un(e(Wr(t.context,this))))}},Sr=/*#__PURE__*/ new Set,Cr=`~effect/Context/Reference`,wr=`~effect/Context`,Tr=(e,t,n,r)=>{let i=Object.create(Mr);return i.cacheRoot=e??i,i.base=t,i.overlay=n,i.depth=r,i._flat=void 0,i.baseHits=0,i},Er=(e,t)=>{t&&(Er(e,t.parent),e.set(t.key,t.value))},Dr=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return Er(t,e.overlay),e._flat=t},Or=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),jr(n)},kr=/*#__PURE__*/ Symbol(),Ar=(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)?kr:(n.overlay&&++n.baseHits>=n.base.size&&n.baseHits>=8&&(n.base=Dr(n),n.overlay=void 0,n.depth=0),r)},jr=e=>Tr(void 0,e,void 0,0),Mr={get mapUnsafe(){return Dr(this)},...Lt,[wr]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[Re](e){if(!Pr(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)||!ze(r,n.get(e)))return!1;return!0},[be](){return Ee(this.mapUnsafe.size)}},Nr=(e,t)=>e.cacheRoot===t.cacheRoot,Pr=e=>p(e,wr),Fr=e=>!!e[Cr],Ir=()=>Lr,Lr=/*#__PURE__*/ jr(/*#__PURE__*/ new Map),Rr=(e,t)=>jr(/* @__PURE__ */ new Map([[e.key,t]])),zr=/*#__PURE__*/ o(3,(e,t,n)=>Br(e,t.key,n)),Br=(e,t,n)=>{let r=e,i=Sr.has(t)?void 0:r.cacheRoot;if(r.depth>=8){let e=new Map(r.mapUnsafe);return e.set(t,n),Tr(i,e,void 0,0)}return Tr(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1)},Vr=/*#__PURE__*/ o(2,(e,t)=>Hr(e,t.key)),Hr=(e,t)=>{let n=Ar(e,t);return n===kr?void 0:n},Ur=/*#__PURE__*/ o(2,(e,t)=>{let n=Ar(e,t.key);if(n===kr){if(Fr(t))return Kr(t);throw qr(t)}return n}),Wr=Ur,Gr=`~effect/Context/defaultValue`,Kr=e=>Gr in e?e[Gr]:e[Gr]=e.defaultValue(),qr=e=>{let t=/* @__PURE__ */ Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(t.stack){let e=t.stack.split(`
|
|
6
6
|
`);e.splice(1,3),t.stack=e.join(`
|
|
7
|
-
`)}return t},Yr=/*#__PURE__*/ o(2,(e,t)=>{let n=jr(e,t.key);return n===Ar?Ir(t)?dr(qr(t)):ur():dr(n)}),Xr=/*#__PURE__*/ o(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:kr(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),Zr=(...e)=>{let t=/* @__PURE__ */ new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return Mr(t)},Qr=xr,$r=e=>e.length>0,ei=e=>e>0?Math.floor(e):0,ti=e=>Math.max(1,ei(e)),ni=$n,ri=Zn,ii=e=>{if(pe(e))try{return ni(e())}catch(e){return ri(e)}try{return ni(e.try())}catch(t){return ri(e.catch(t))}},ai=Jn,oi=Yn,si=/*#__PURE__*/ o(2,(e,t)=>oi(e)?ni(t(e.success)):e),ci=/*#__PURE__*/ o(2,(e,{onFailure:t,onSuccess:n})=>ai(e)?t(e.failure):n(e.success)),li=An,ui=e=>{let t=e[Symbol.iterator]().next();if(t.done)throw Error(`headUnsafe: empty iterable`);return t.value},di=/*#__PURE__*/ o(2,(e,t)=>Object.hasOwn(e,t)),fi=/*#__PURE__*/ o(2,(e,t)=>{let n={...e};for(let r of pi(e))Dt(n,r,t(e[r],r));return n}),pi=e=>Object.keys(e),mi=e=>o(2,(t,n)=>{for(let r of pi(t))if(!di(n,r)||!e(t[r],n[r]))return!1;return!0}),hi=e=>{let t=mi(e);return(e,n)=>t(e,n)&&t(n,e)},gi=globalThis.Array,_i=e=>gi.isArray(e)?e:gi.from(e),vi=/*#__PURE__*/ o(2,(e,t)=>[...e,t]);gi.isArray;const yi=$r,bi=$r,xi=()=>[],Si=e=>[e],Ci=/*#__PURE__*/ o(2,(e,t)=>e.map(t)),wi=jn,Ti=`~effect/Duration`,Ei=/*#__PURE__*/ BigInt(0),Di=/*#__PURE__*/ BigInt(1),Oi=/*#__PURE__*/ BigInt(2),ki=/*#__PURE__*/ BigInt(10),Ai=/*#__PURE__*/ BigInt(24),ji=/*#__PURE__*/ BigInt(60),Mi=/*#__PURE__*/ BigInt(1e3),Ni=/*#__PURE__*/ BigInt(1e6),Pi=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),Fi=e=>Pi(e*1e6),Ii=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=ki**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t,s=o/a+(o%a*Oi>=a?Di:Ei);return r?-s:s},Li=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,Ri=e=>{switch(typeof e){case`number`:return ea(e);case`bigint`:return $i(e);case`string`:{if(e===`Infinity`)return Zi;if(e===`-Infinity`)return Qi;let t=Li.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return $i(Ii(r,Di));if(i===`micro`||i===`micros`)return $i(Ii(r,Mi));let a=Number(r);switch(i){case`milli`:case`millis`:return ea(a);case`second`:case`seconds`:return ta(a);case`minute`:case`minutes`:return na(a);case`hour`:case`hours`:return ra(a);case`day`:case`days`:return ia(a);case`week`:case`weeks`:return aa(a)}break}case`object`:{if(e===null)break;if(Ti in e)return e;if(Array.isArray(e))return e.length!==2||!e.every(ce)?zi(e):Number.isNaN(e[0])||Number.isNaN(e[1])?Xi:e[0]===-1/0||e[1]===-1/0?Qi:e[0]===1/0||e[1]===1/0?Zi:Gi(Pi(e[0]*1e9+e[1]));let t=e,n=0;return 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?Gi(n):Gi(Pi(n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0)))}}return zi(e)},zi=e=>{throw Error(`Invalid Input: ${e}`)},Bi=/*#__PURE__*/ vr(Ri),Vi={_tag:`Millis`,millis:0},Hi={_tag:`Infinity`},Ui={_tag:`NegativeInfinity`},Wi={[Ti]:Ti,[be](){switch(this.value._tag){case`Millis`:{let e=this.value.millis*1e6;return Number.isFinite(e)?xe(Pi(e)):De(this.value.millis)}case`Nanos`:return xe(this.value.nanos);default:return Ae(this.value)}},[ze](e){return Ki(e)&&ma(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`}}},[vt](){return this.toJSON()},pipe(){return r(this,arguments)}},Gi=e=>{let t=Object.create(Wi);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?Vi:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:Fi(e)}:e>0?Hi:Ui:e===Ei?Vi:{_tag:`Nanos`,nanos:e},t},Ki=e=>p(e,Ti),qi=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}},Ji=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}},Yi=e=>{switch(e.value._tag){case`Infinity`:case`NegativeInfinity`:return Zi;case`Millis`:return e.value.millis<0?Gi(-e.value.millis):e;case`Nanos`:return e.value.nanos<Ei?Gi(-e.value.nanos):e}},Xi=/*#__PURE__*/ Gi(0),Zi=/*#__PURE__*/ Gi(1/0),Qi=/*#__PURE__*/ Gi(-1/0),$i=e=>Gi(e),ea=e=>Gi(e),ta=e=>Gi(e*1e3),na=e=>Gi(e*6e4),ra=e=>Gi(e*36e5),ia=e=>Gi(e*864e5),aa=e=>Gi(e*6048e5),oa=e=>ca(Ri(e),{onMillis:s,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),sa=e=>{let t=Ri(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 Fi(t.value.millis)}},ca=/*#__PURE__*/ o(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)()}}),la=/*#__PURE__*/ o(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(sa(e),t.value.nanos):n.onNanos(e.value.nanos,sa(t))),ua=/*#__PURE__*/ er((e,t)=>la(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})),da=(e,t)=>la(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),fa=/*#__PURE__*/ cr(ua),pa=/*#__PURE__*/ lr(ua),ma=/*#__PURE__*/ o(2,(e,t)=>da(e,t)),ha=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=sa(e),n=t<Ei,r=n?-t:t,i=r/Ni,a=i/Mi,o=a/ji,s=o/ji,c=s/Ai,l=n?-1:1;return{days:l*Number(c),hours:l*Number(s%Ai),minutes:l*Number(o%ji),seconds:l*Number(a%ji),millis:l*Number(i%Mi),nanos:l*Number(r%Ni)}},ga=e=>{if(e.value._tag===`Infinity`)return`Infinity`;if(e.value._tag===`NegativeInfinity`)return`-Infinity`;if(qi(e))return`0`;if(Ji(e))return`-`+ga(Yi(e));let t=ha(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(` `)},_a=/*#__PURE__*/ Qr(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new Sa}),va=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},ya=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},ba=e=>{try{return ya(e)}catch{return va(e)}};var xa=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}},Sa=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?va:ba)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new Ca(this.setImmediate)}},Ca=class{tasks=/*#__PURE__*/ new xa;running=void 0;setImmediate;constructor(e=ba){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 wa=/*#__PURE__*/ Qr(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),Ta=/*#__PURE__*/ Qr(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),Ea=class extends a{constructor(e){super(),e&&Ot(this,e)}},Da=yn,Oa=`~effect/encoding/EncodingError`;var ka=class extends (/*#__PURE__*/ Da(`EncodingError`)){[Oa]=Oa};const Aa=e=>{switch(e){case 16:return Na();case 32:return Pa();default:{let t=``;for(let n=e>>>3;n>0;n--)t+=Ma();return t}}},_=/*#__PURE__*/ Uint8Array.from(`0123456789abcdef`,e=>e.charCodeAt(0)),ja=()=>Math.random()*4294967296>>>0,Ma=()=>{let e=ja();return String.fromCharCode(_[e>>>28],_[e>>>24&15],_[e>>>20&15],_[e>>>16&15],_[e>>>12&15],_[e>>>8&15],_[e>>>4&15],_[e&15])},Na=()=>{let e=ja(),t=ja();return String.fromCharCode(_[e>>>28],_[e>>>24&15],_[e>>>20&15],_[e>>>16&15],_[e>>>12&15],_[e>>>8&15],_[e>>>4&15],_[e&15],_[t>>>28],_[t>>>24&15],_[t>>>20&15],_[t>>>16&15],_[t>>>12&15],_[t>>>8&15],_[t>>>4&15],_[t&15])},Pa=()=>{let e=ja(),t=ja(),n=ja(),r=ja();return String.fromCharCode(_[e>>>28],_[e>>>24&15],_[e>>>20&15],_[e>>>16&15],_[e>>>12&15],_[e>>>8&15],_[e>>>4&15],_[e&15],_[t>>>28],_[t>>>24&15],_[t>>>20&15],_[t>>>16&15],_[t>>>12&15],_[t>>>8&15],_[t>>>4&15],_[t&15],_[n>>>28],_[n>>>24&15],_[n>>>20&15],_[n>>>16&15],_[n>>>12&15],_[n>>>8&15],_[n>>>4&15],_[n&15],_[r>>>28],_[r>>>24&15],_[r>>>20&15],_[r>>>16&15],_[r>>>12&15],_[r>>>8&15],_[r>>>4&15],_[r&15])},Fa=`effect/Tracer/ParentSpan`;var Ia=class extends (/*#__PURE__*/ xr()(Fa,{fiberCached:!0})){};const La=e=>e,Ra=/*#__PURE__*/ Qr(`effect/Tracer/DisablePropagation`,{defaultValue:u}),za=/*#__PURE__*/ Qr(`effect/Tracer/CurrentTraceLevel`,{defaultValue:()=>`Info`}),Ba=/*#__PURE__*/ Qr(`effect/Tracer/MinimumTraceLevel`,{defaultValue:()=>`All`}),Va=/*#__PURE__*/ La({span:e=>new Ha(e)});var Ha=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??=_r(this.parent)?.traceId??Aa(32)}get spanId(){return this._spanId??=Aa(16)}get attributes(){return this._attributes??=/* @__PURE__ */ new Map}get events(){return this._events??=[]}end(e,t){this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime}}attribute(e,t){this.attributes.set(e,t)}event(e,t,n){this.events.push([e,t,n??{}])}addLinks(e){this.links.push(...e)}};const Ua=/*#__PURE__*/ Qr(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:d}),Wa=/*#__PURE__*/ Qr(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:l}),Ga=/*#__PURE__*/ Qr(`effect/References/TracerTimingEnabled`,{defaultValue:l}),Ka=/*#__PURE__*/ Qr(`effect/References/TracerSpanAnnotations`,{defaultValue:()=>({})}),qa=/*#__PURE__*/ Qr(`effect/References/TracerSpanLinks`,{defaultValue:()=>[]}),Ja=/*#__PURE__*/ Qr(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Ya=/*#__PURE__*/ Qr(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Xa=e=>{if(e?.captureStackTrace===!1||e?.captureStackTrace!==void 0&&typeof e.captureStackTrace!=`boolean`)return e;let t=Ct();if(t===0&&e?.captureStackTrace!==!0)return{...e,captureStackTrace:!1};wt(3);let n=/* @__PURE__ */ Error();return wt(t),{...e,captureStackTrace:Qa(()=>n.stack)}},Za=e=>t=>{let n;return()=>{if(n!==void 0)return n;let r=t();if(!r)return;let i=r.split(`
|
|
8
|
-
`);if(i[e]!==void 0)return n=i[e].trim(),n}},Qa=/*#__PURE__*/ Za(3);var $a=class extends qt{constructor(e,t=Jt){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[ze](e){return on(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[be](){return we(Oe(`${this._tag}:${this.fiberId}`))(Se(this.annotations))}};const eo=e=>new Gt([new $a(e)]),to=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return ni(n.error)}return ri(e)},no=e=>e.reasons.some(on),ro=e=>{let t;for(let n=0;n<e.reasons.length;n++){let r=e.reasons[n];r._tag===`Interrupt`&&(t??=/* @__PURE__ */ new Set,r.fiberId!==void 0&&t.add(r.fiberId))}return t?ni(t):ri(e)},io=/*#__PURE__*/ o(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>rn(e)?(n=!0,new Yt(t(e.error),e.annotations)):e);return n?Xt(r):e}),ao=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},oo=`~effect/Fiber`,so={_A:s,_E:s},co={id:0},lo=/*#__PURE__*/ (()=>{try{return globalThis.process?.getBuiltinModule?.(`node:async_hooks`)?.AsyncResource}catch{return}})(),uo=()=>lo===void 0?void 0:new lo(`effect/Fiber`),fo=()=>globalThis[ct];var po=class{constructor(e,t=!0){this.setContext(e),this.id=++co.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._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[oo](){return so}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return Gr(this.context,e)}addObserver(e){return this._exit?(e(this._exit),f):(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=eo(e);this.cache.stackFrame&&(n=nn(n,zr(fn,this.cache.stackFrame))),t&&(n=nn(n,t)),this._interruptedCause=this._interruptedCause?Qt(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(Eo(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._asyncContext!==void 0){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===Lt){this._asyncContext=uo();return}let n=_o.interruptChildren&&_o.interruptChildren(this);if(n!==void 0)return this.evaluate(b(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=Lr()}runLoop(e){let t=globalThis[ct];globalThis[ct]=this;let n=this._running;this._running=!0;let r=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=Eo(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!r&&!e.preventYield&&e.scheduler.shouldYield(this)){r=!0;let e=i;i=b(Ao,()=>e)}if(i=e.tracerContext?e.tracerContext(i,this):i[Nt](this),i===Lt){let e=this._yielded;if(`~effect/Exit`in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return Lt}}}catch(e){return p(i,`~effect/Effect/evaluate`)?this.runLoop(gn(e)):gn(`Fiber.runLoop: Not a valid effect: ${String(i)}`)}finally{this._running=n,globalThis[ct]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,ho;for(;;){let t=this._stack.pop();if(!t)return;let n=t[It];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&go-1))return dn(e);let t=this.getCont(Pt);return t?t[Pt](e,this):this.yieldWith(dn(e))}yieldWith(e){return this._yielded=e,Lt}children(){return this._children??=/* @__PURE__ */ new Set}pipe(){return r(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Pr(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=mo(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 mo=e=>{let t=Ur(e,`effect/Tracer`);return{scheduler:Gr(e,_a),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:Gr(e,Wa),span:Ur(e,Fa),logLevel:Gr(e,Ja),minimumLogLevel:Gr(e,Ya),stackFrame:Gr(e,Ua),runtimeMetrics:Ur(e,`effect/Metric/FiberRuntimeMetrics`),maxOpsBeforeYield:Gr(e,wa),preventYield:Gr(e,Ta)}},ho={[Pt](e,t){return Eo(t._interruptedCause)},[Ft](e,t){return Eo(t._interruptedCause)}},go=32,_o={interruptChildren:void 0},vo=e=>{if(!e.cache.stackFrame)return;let t=/* @__PURE__ */ new Map;return t.set(pn.key,e.cache.stackFrame),Mr(t)},yo=e=>{if(e._children!==void 0&&e._children.size!==0)return To(e._children)},bo=e=>{let t=e;return t._exit?v(t._exit):Ho(n=>t._exit?n(v(t._exit)):Oo(e.addObserver(e=>n(v(e)))))},xo=e=>Ho(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();else{i=e.value.addObserver(e=>{r.push(e),a()});return}t(v(r))}return a(),Oo(()=>i?.())}),So=e=>{let t=e;return t._exit?t._exit:Ho(n=>t._exit?n(t._exit):Oo(e.addObserver(n)))},Co=e=>g(t=>wo(e,t.id)),wo=/*#__PURE__*/ o(e=>p(e[0],oo),(e,t,n)=>g(r=>{let i=vo(r);return i=i&&n?Xr(i,n):i??n,e.interruptUnsafe(t,i),ps(bo(e))})),To=e=>g(t=>{let n=vo(t),r=xi();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return ps(xo(r))}),v=dn,Eo=mn,Do=hn,Oo=/*#__PURE__*/ ln({op:`Sync`,[Nt](e){let t=this[h](),n=e.getCont(Pt);return n?n[Pt](t,e):e.yieldWith(dn(t))}}),y=/*#__PURE__*/ ln({op:`Suspend`,[Nt](e){return this[h]()}}),ko=/*#__PURE__*/ ci({onFailure:Do,onSuccess:v}),Ao=/*#__PURE__*/ (/* @__PURE__ */ ln({op:`Yield`,[Nt](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(Os)},this[`~effect/Effect/args`]??0),e.yieldWith(()=>{t=!0})}}))(0),jo=/*#__PURE__*/ v(/*#__PURE__*/ ur()),Mo=e=>y(()=>Eo(e())),No=e=>gn(e),Po=e=>y(()=>Do(e())),Fo=/*#__PURE__*/ v(void 0),Io=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new Wl(e,`An error occurred in Effect.try`):e.catch;return y(()=>{try{return v(t())}catch(e){return Do(n(e))}})},Lo=e=>Bo(function(t,n){e(n).then(e=>t(v(e)),e=>t(No(e)))},e.length!==0),Ro=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new Wl(e,`An error occurred in Effect.tryPromise`):e.catch;return Bo(function(e,r){let i=e=>y(()=>{try{return Do(Et(()=>n(e)))}catch(e){return No(e)}});try{t(r).then(t=>e(v(t)),t=>e(i(t)))}catch(t){e(i(t))}},t.length!==0)},zo=e=>g(t=>e(t.id)),Bo=/*#__PURE__*/ function(){let e=/*#__PURE__*/ cn({op:`Async`,[Nt](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._yielded=()=>{t=!0},r===void 0&&i===void 0||e._stack.push(Vo(()=>(t=!0,r?.abort(),i??Os))),Lt):n}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),Vo=/*#__PURE__*/ ln({op:`AsyncFinalizer`,[It](e){e.interruptible&&(e.interruptible=!1,e._stack.push(Hc))},[Ft](e,t){return no(e)?b(hc(mn(e),this[h]()),()=>Eo(e)):Eo(e)}}),Ho=e=>Bo(e,e.length>=2),Uo=/*#__PURE__*/ Ho(f),Wo=(...e)=>{if(e.length===1){let t=e[0];return y(()=>Qo(t()))}let[t,n]=e;return y(()=>Qo(n.call(t.self)))},Go=(e,...t)=>{let n=t.length===0?function(){return y(()=>Qo(e.apply(this,arguments)))}:function(){let n=y(()=>Qo(e.apply(this,arguments)));for(let e=0;e<t.length;e++)n=t[e](n,...arguments);return n};return Ko(e.length,n)},Ko=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),qo=/*#__PURE__*/ Za(2),Jo=function(){let e=typeof arguments[0]==`string`,t=e?arguments[0]:`Effect.fn`,n=e?arguments[1]:void 0,r=Ct(),i;return r!==0&&(wt(2),i=new globalThis.Error,wt(r)),e?(r,...a)=>Yo(t,r,i,a,e,n):Yo(t,arguments[0],i,Array.prototype.slice.call(arguments,1),e,n)},Yo=(e,t,n,r,i,a)=>{let o=typeof t==`function`?t:r.shift().bind(t.self),s=`${e} (definition)`,c=n?qo(()=>n.stack):d;return Ko(o.length,function(...t){let n=y(()=>{let e=o.apply(this,arguments);return Bt(e)?e:Qo(e)});for(let e=0;e<r.length;e++)n=r[e](n,...t);if(!Bt(n))return n;let l=Ct(),u;return l!==0&&(wt(2),u=new globalThis.Error,wt(l)),Fs(i?El(e,a,e=>Dl(n,e)):n,Ua,t=>({name:e,stack:u?qo(()=>u.stack):d,parent:{name:s,stack:c,parent:t}}))})},Xo=(e,...t)=>Ko(e.length,t.length===0?function(){return Zo(()=>e.apply(this,arguments))}:function(){let n=Zo(()=>e.apply(this,arguments));for(let e of t)n=e(n,...arguments);return n}),Zo=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return v(r.value);let i=r.value;if(i&&i._tag===`Success`)n=i.value;else{if(i&&i._tag===`Failure`)return r.value;{let n=!0;return y(()=>n?(n=!1,b(r.value,e=>Qo(t,e))):y(()=>Qo(e())))}}}}catch(e){return No(e)}},Qo=/*#__PURE__*/ function(){let e=/*#__PURE__*/ cn({op:`Iterator`,[Pt](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return v(r.value);if(!gs(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[Nt](e){return this[Pt](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)}}(),$o=/*#__PURE__*/ o(2,(e,t)=>new ns(e,rs,v(t))),es=function(e){return e._stack.push(this),this[h]},ts=/*#__PURE__*/ cn({op:`OnSuccess`,[Nt]:es}),ns=function(e,t,n){this[h]=e,this[Pt]=t,this.payload=n};ns.prototype=ts;const rs=function(){return this.payload},is=function(e,t){return t.succeedWith(this.payload)},as=/*#__PURE__*/ (()=>{let e=`~effect/Effect/stackProbe`;return{[e]:function(){return(/* @__PURE__ */ Error()).stack}}[e]()?.includes(`[as `+e+`]`)===!0})(),os=function(e,t){let n=this.payload;return t.succeedWith(as?n(e):Et(()=>n(e)))},ss=function(e){let t=this.payload;return t(e)},cs=function(e){let t=this.payload;return new ns(t(e),is,e)},ls=function(e){return new ns(this.payload,is,e)},us=e=>ys(e,dr),ds=/*#__PURE__*/ o(2,(e,t)=>new ns(e,Bt(t)?rs:ss,t)),fs=/*#__PURE__*/ o(2,(e,t)=>new ns(e,Bt(t)?ls:cs,t)),ps=e=>new ns(e,rs,Os),ms=(e,t)=>g(n=>{let r=/* @__PURE__ */ new Set;return jc(n,()=>r.size===0?void 0:To(r)),Ho(i=>{let a=!1,o=0;for(let s of e){if(a)break;let e=o++,c=il(n,s,!0,!0,!1);r.add(c),c.addObserver(o=>{r.delete(c);let s=!a;a=!0,i(o),s&&t?.onWinner&&t.onWinner({fiber:c,index:e,parentFiber:n})})}})}),hs=/*#__PURE__*/ o(e=>Bt(e[1]),(e,t,n)=>ms([e,t],n)),b=/*#__PURE__*/ o(2,(e,t)=>new ns(e,ss,t)),gs=e=>e[At]!==void 0,_s=/*#__PURE__*/ o(2,(e,t)=>gs(e)?e._tag===`Success`?t(e.value):e:b(e,t)),vs=e=>b(e,s),ys=/*#__PURE__*/ o(2,(e,t)=>new ns(e,os,t)),bs=/*#__PURE__*/ o(2,(e,t)=>gs(e)?ks(e,t):ys(e,t)),xs=/*#__PURE__*/ o(2,(e,t)=>gs(e)?As(e,t):Js(e,t)),Ss=/*#__PURE__*/ o(2,(e,t)=>gs(e)?js(e,t):Ys(e,t)),Cs=/*#__PURE__*/ o(2,(e,t)=>{if(gs(e)){if(e._tag===`Success`)return e;let n=to(e.cause);return ai(n)?e:t(n.success)}return qs(e,t)}),ws=e=>mn(eo(e)),Ts=e=>e._tag===`Success`,Es=e=>e._tag===`Failure`?ni(e.cause):ri(e),Ds=e=>e._tag===`Failure`&&no(e.cause),Os=/*#__PURE__*/ dn(void 0),ks=/*#__PURE__*/ o(2,(e,t)=>e._tag===`Success`?dn(t(e.value)):e),As=/*#__PURE__*/ o(2,(e,t)=>{if(e._tag===`Success`)return e;let n=to(e.cause);return ai(n)?e:hn(t(n.success))}),js=/*#__PURE__*/ o(2,(e,t)=>{if(e._tag===`Success`)return dn(t.onSuccess(e.value));let n=to(e.cause);return ai(n)?e:hn(t.onFailure(n.success))}),Ms=/*#__PURE__*/ o(2,(e,t)=>Ts(e)?t:e),Ns=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?Os:mn(Xt(t))},Ps=/*#__PURE__*/ o(2,(e,t)=>g(n=>{let r=n.context,i=t(r);return r===i||(n.setContext(i),jc(n,()=>{n.setContext(r)})),e})),Fs=/*#__PURE__*/ o(3,(e,t,n)=>Ps(e,e=>{let r=Wr(e,t),i=n(r);return r===i?e:Br(e,t,i)})),Is=()=>Ls,Ls=/*#__PURE__*/ g(e=>v(e.context)),Rs=e=>g(t=>e(t.context)),zs=/*#__PURE__*/ o(2,(e,t)=>gs(e)?e:Ps(e,Xr(t))),Bs=function(){return arguments.length===1?o(2,(e,t)=>Vs(e,arguments[0],t)):o(3,(e,t,n)=>Vs(e,t,n)).apply(this,arguments)},Vs=(e,t,n)=>Ps(e,Br(t,n)),Hs=/*#__PURE__*/ o(e=>Bt(e[0]),(e,t)=>Yc({while:l,body:c(t?.disableYield?e:b(e,e=>Ao)),step:f})),Us=/*#__PURE__*/ o(2,(e,t)=>new Gs(e,t.length===1?t:e=>t(e))),Ws=/*#__PURE__*/ cn({op:`OnFailure`,[Nt]:es}),Gs=function(e,t){this[h]=e,this[Ft]=t};Gs.prototype=Ws;const Ks=/*#__PURE__*/ o(3,(e,t,n)=>Us(e,e=>{let r=t(e);return ai(r)?Eo(r.failure):n(r.success,e)})),qs=/*#__PURE__*/ o(2,(e,t)=>Ks(e,to,e=>t(e))),Js=/*#__PURE__*/ o(2,(e,t)=>qs(e,e=>Po(()=>t(e)))),Ys=/*#__PURE__*/ o(2,(e,t)=>nc(e,{onFailure:e=>Po(()=>t.onFailure(e)),onSuccess:e=>Oo(()=>t.onSuccess(e))})),Xs=e=>ic(e,{onFailure:ri,onSuccess:ni}),Zs=/*#__PURE__*/ o(2,(e,t)=>new $s(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Qs=/*#__PURE__*/ cn({op:`OnSuccessAndFailure`,[Nt]:es}),$s=function(e,t,n){this[h]=e,this[Pt]=t,this[Ft]=n};$s.prototype=Qs;const ec=function(e,t){let n=this.payload;return t.succeedWith(as?n.onSuccess(e):Et(()=>n.onSuccess(e)))},tc=/*#__PURE__*/ ((e,t)=>{let n=cn({op:e,[Nt]:es,[Pt]:ec,[Ft]:t}),r=function(e,t){this[h]=e,this.payload=t};return r.prototype=n,r})(`Match`,function(e,t){let n=e.reasons.find(rn);if(n===void 0)return Eo(e);let r=this.payload;return t.succeedWith(as?r.onFailure(n.error):Et(()=>r.onFailure(n.error)))}),nc=/*#__PURE__*/ o(2,(e,t)=>Zs(e,{onFailure:e=>{let n=e.reasons.find(rn);return n?t.onFailure(n.error):Eo(e)},onSuccess:t.onSuccess})),rc=/*#__PURE__*/ o(2,(e,t)=>new tc(e,t)),ic=/*#__PURE__*/ o(2,(e,t)=>{if(gs(e)){if(e._tag===`Success`)return dn(t.onSuccess(e.value));let n=to(e.cause);return ai(n)?e:dn(t.onFailure(n.success))}return rc(e,t)}),ac=e=>gs(e)?dn(e):oc(e),oc=/*#__PURE__*/ ln({op:`Exit`,[Nt](e){return e._stack.push(this),this[h]},[Pt](e,t,n){return t.succeedWith(n??dn(e))},[Ft](e,t,n){return t.succeedWith(n??mn(e))}}),sc=/*#__PURE__*/ o(2,(e,t)=>b(cc(e,t.duration),e=>fr(e)?t.orElse():v(e.value))),cc=/*#__PURE__*/ o(2,(e,t)=>hs(us(e),$o(Il(t),ur()))),lc=`~effect/Scope`,uc=`~effect/Scope/Closeable`,dc=/*#__PURE__*/ xr(`effect/Scope`),fc=(e,t)=>g(n=>{let r=pc(e,t);return r===void 0?Fo:(Gc(n),r)}),pc=(e,t)=>{let n=e.state;if(n._tag===`Closed`||(e.state={_tag:`Closed`,exit:t},e.parent!==void 0&&xc(e.parent,e),n._tag===`Empty`))return;if(n.finalizer!==void 0)return mc(n.finalizer,t);let r=n.finalizers;return r.size===1?mc(r.values().next().value,t):gc(e,r,t)},mc=(e,t)=>{try{return e(t)}catch(e){return gn(e)}},hc=(e,t)=>Ts(e)?t:Us(t,t=>Eo(Qt(e.cause,t))),gc=/*#__PURE__*/ Go(function*(e,t,n){let r=[],i=[],a=Array.from(t.values()),o=fo();for(let t=a.length-1;t>=0;t--){let s=a[t];e.strategy===`sequential`?r.push(yield*ac(mc(s,n))):i.push(il(o,mc(s,n),!0,!0,`inherit`))}return i.length>0&&(r=yield*xo(i)),yield*Ns(r)}),_c=(e,t)=>{let n=Cc(t,e);return e.state._tag===`Closed`?(n.state=e.state,n):(bc(e,n,e=>fc(n,e)),n)},vc=(e,t)=>y(()=>e.state._tag===`Closed`?t(e.state.exit):(bc(e,{},t),Fo)),yc=(e,t)=>vc(e,c(t)),bc=(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=/* @__PURE__ */ new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0),r.finalizers.set(t,n)}},xc=(e,t)=>{if(e.state._tag!==`Open`)return;let n=e.state;n.finalizerKey===t?e.state=wc:n.finalizers!==void 0&&(n.finalizers.delete(t),n.finalizers.size===0&&(e.state=wc))},Sc=e=>Cc(e,void 0),Cc=(e=`sequential`,t)=>({[uc]:uc,[lc]:lc,strategy:e,parent:t,state:wc}),wc={_tag:`Empty`},Tc=dc,Ec=/*#__PURE__*/ Bs(dc),Dc=e=>y(()=>{let t=Sc();return Mc(e(t),e=>y(()=>pc(t,e)??Fo))}),Oc=(e,t,n)=>Rs(r=>qc(i=>b(Tc,a=>fs(n?.interruptible?i(e):e,e=>vc(a,n=>zs(t(e,n),r)))))),kc=/*#__PURE__*/ function(){let e=/*#__PURE__*/ cn({op:`OnExit`,[Nt](e){return e._stack.push(this),this.effect},[It](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(Hc),e.interruptible=!1)},[Pt](e,t,n){n??=dn(e);let r;try{r=this.onExit(n)}catch(e){r=gn(e)}return r?b(r,e=>n):n},[Ft](e,t,n){n??=mn(e);let r;try{r=this.onExit(n)}catch(e){r=gn(e)}return r?b(hc(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,t}(),Ac=(e,t,n)=>new kc(e,t,n),jc=(e,t)=>{e._stack.push(new kc(void 0,t,void 0))},Mc=/*#__PURE__*/ o(2,Ac),Nc=/*#__PURE__*/ o(3,(e,t,n)=>Mc(e,e=>{let r=t(e);return ai(r)?Fo:n(r.success,e)})),Pc=/*#__PURE__*/ o(2,(e,t)=>Nc(e,Es,t)),Fc=/*#__PURE__*/ o(3,(e,t,n)=>Mc(e,e=>{if(e._tag!==`Failure`)return Fo;let r=t(e.cause);return ai(r)?Fo:n(r.success,e.cause)})),Ic=/*#__PURE__*/ o(2,(e,t)=>Fc(ro,t)(e)),Lc=/*#__PURE__*/ c(1/0),Rc=(e,t)=>{let n=0,r,i,a=(e,t)=>(t.awaiters++,jc(e,()=>{if(!(--t.awaiters>0||i!==t))return i=void 0,Co(t.fiber)}),So(t.fiber));return[g(o=>{if(i!==void 0)return a(o,i);if(r!==void 0&&(n===1/0||o.getRef(kl).currentTimeMillisUnsafe()<n))return r;r=void 0;let s=o.getRef(kl),c={fiber:void 0,awaiters:0};return i=c,c.fiber=il(o,Ac(e,e=>{if(i!==c||(i=void 0,Ds(e)))return;let a=t(e);n=a===1/0?1/0:s.currentTimeMillisUnsafe()+a,r=e}),!0,!0),c.fiber._exit??a(o,c)}),Oo(()=>{r=void 0})]},zc=e=>Oo(()=>Rc(e,Lc)[0]),Bc=e=>g(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(Hc)),e)),Vc=/*#__PURE__*/ ln({op:`SetInterruptible`,[It](e){if(e.interruptible=this[h],e._interruptedCause&&e.interruptible)return()=>Eo(e._interruptedCause)}}),Hc=/*#__PURE__*/ Vc(!0),Uc=/*#__PURE__*/ Vc(!1),Wc=e=>{if(e.interruptible=!0,e._stack.push(Uc),e._interruptedCause)return Eo(e._interruptedCause)},Gc=e=>{let t=e;t.interruptible&&(t.interruptible=!1,t._stack.push(Hc))},Kc=e=>g(t=>t.interruptible?e:Wc(t)??e),qc=e=>g(t=>t.interruptible?(t.interruptible=!1,t._stack.push(Hc),e(Kc)):e(s)),Jc=(e,t)=>ye(e)?t?.mode===`result`?Xc(e,Xs,t):Xc(e,s,t):t?.discard?t.mode===`result`?Xc(Object.values(e),Xs,t):Xc(Object.values(e),s,t):y(()=>{let n={};return $o(Xc(Object.entries(e),([e,r])=>ys(t?.mode===`result`?Xs(r):r,t=>{Dt(n,e,t)}),{discard:!0,concurrency:t?.concurrency}),n)}),Yc=/*#__PURE__*/ ln({op:`While`,[Pt](e,t){return this[h].step(e),this[`~effect/Effect/args`].while()?(t._stack.push(this),this[h].body()):Os},[Nt](e){return this[`~effect/Effect/args`].while()?(e._stack.push(this),this[h].body()):Os}}),Xc=/*#__PURE__*/ o(e=>typeof e[1]==`function`,(e,t,n)=>y(()=>{let r=Qc(n?.concurrency);if(r===1)return Zc(e,t,n);let i=_i(e),a=i.length;if(a===0)return n?.discard?Fo:v([]);let o=n?.discard?void 0:Array(a),s=nl({f:t,out:o},i,{concurrency:r});return s?$o(s,o):v(o)})),Zc=(e,t,n)=>y(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return $o(Yc({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),Qc=e=>e===`unbounded`?1/0:Math.max(1,e??1),$c=()=>e=>{let t=e.onItem,n=e.step,r=(e,t,r,a,o)=>b(ac(o),o=>n(e,t[r],o,r)??i(e,t,r+1,a)??Fo),i=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!gs(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},el=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,ee,te=e=>{let t=gn(e);return f=t,c=!0,u&&u.size>0?b(Bc(To(Array.from(u))),()=>f??t):t},ne=()=>{let i=!1;for(;!f&&a<o;a++){let o=r[a],re=ee??t(e,o,a);if(gs(re)){if(f=n(e,o,re,a),f)break}else if(l){ee=void 0;let t=il(l,re,!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=Xt(e);f=mn(f._tag===`Failure`?Qt(f.cause,t):t)}}}else{let t=n(e,o,a,r);t&&(f=t,ne())}if(i){let e=ne();e&&d(e)}else c&&u.size===0&&d(f??Fo)}catch(e){d(te(e))}}),u.size<s)continue;i=!0,a++;return}else return Ho(e=>{l=fo(),u=/* @__PURE__ */ new Set,ee=re,d=e;let t;try{t=ne()}catch(t){return e(te(t))}return t?e(t):y(()=>(f??=Os,b(u?To(u):Fo,()=>f?._tag===`Failure`?f:Fo)))})}if(c=!0,f){if(u&&u.size>0){let e=vo(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(Fo);else return Os}};return ne()}},tl=()=>e=>el(e),nl=/*#__PURE__*/ el({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)}}),rl=/*#__PURE__*/ o(e=>Bt(e[0]),(e,t)=>g(n=>(ql(),v(il(n,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),il=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new po(a.context,o);return n?s.evaluate(t):(s._asyncContext=uo(),a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),!r&&!s._exit&&(a.children().add(s),s._parent=a),s},al=/*#__PURE__*/ o(e=>Bt(e[0]),(e,t,n)=>g(r=>{let i=il(r,e,n?.startImmediately,!0,n?.uninterruptible);if(!i._exit){if(t.state._tag!==`Closed`){let e={};bc(t,e,()=>zo(e=>e===i.id?Fo:Co(i))),i.addObserver(()=>xc(t,e))}else i.interruptUnsafe(r.id,vo(r))}return v(i)})),ol=e=>(t,n)=>{let r=new po(n?.scheduler?Br(e,_a,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},sl=/*#__PURE__*/ o(2,(e,t)=>{if(e._exit)return e;if(t.state._tag===`Closed`)return e.interruptUnsafe(e.id),e;let n={};return bc(t,n,()=>Co(e)),e.addObserver(()=>xc(t,n)),e}),cl=/*#__PURE__*/ ol(/*#__PURE__*/ Lr()),ll=e=>{let t=ol(e);return(e,n)=>{let r=t(e,n);return new Promise(e=>{r.addObserver(t=>e(t))})}},ul=/*#__PURE__*/ (e=>{let t=ll(e);return(e,n)=>t(e,n).then(e=>{if(e._tag===`Failure`)throw ao(e.cause);return e.value})})(/*#__PURE__*/ Lr()),dl=e=>{let t=ol(e);return e=>{if(gs(e))return e;let n=new Sa(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??gn(new Hl(r))}},fl=/*#__PURE__*/ dl(/*#__PURE__*/ Lr()),pl=/*#__PURE__*/ (e=>{let t=dl(e);return e=>{let n=t(e);if(n._tag===`Failure`)throw ao(n.cause);return n.value}})(/*#__PURE__*/ Lr()),ml=/*#__PURE__*/ v(!0),hl=/*#__PURE__*/ v(!1);var gl=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return ml;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=[],ml}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](Os)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](Os)}open=/*#__PURE__*/ g(e=>this._isOpen?hl:(this._isOpen=!0,this.scheduleUnsafe(e)));release=/*#__PURE__*/ g(e=>this._isOpen?hl:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=/*#__PURE__*/ Ho(e=>this._isOpen?e(Fo):(this.waiters.push(e),Oo(()=>{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=/*#__PURE__*/ Oo(()=>this.closeUnsafe());whenOpen=e=>b(this.await,()=>e);isOpen(){return this._isOpen}};const _l=e=>new gl(e??!1),vl=e=>Oo(()=>_l(e)),yl=/*#__PURE__*/ BigInt(0),bl={_tag:`Span`,spanId:`noop`,traceId:`noop`,sampled:!1,status:{_tag:`Ended`,startTime:yl,endTime:yl,exit:Os},attributes:/*#__PURE__*/ new Map,links:[],kind:`internal`,attribute(){},event(){},end(){},addLinks(){}},xl=e=>Object.assign(Object.create(bl),e),Sl=e=>e?Gr(e.annotations,Ra)?e._tag===`Span`?Sl(_r(e.parent)):ur():dr(e):ur(),Cl=(e,t,n)=>{let r=!e.cache.tracerEnabled||n?.annotations&&Gr(n.annotations,Ra),i=n?.parent===void 0?n?.root?ur():Sl(e.cache.span):dr(n.parent),a;if(r)a=xl({name:t,parent:i,annotations:Br(n?.annotations??Lr(),Ra,!0)});else{let r=e.cache.tracer??Va,o=e.getRef(kl),s=e.getRef(Ga),c=e.getRef(Ka),l=e.getRef(qa),u=n?.level??e.getRef(za),d=n?.links===void 0?l.length===0?[]:l.slice():[...l,...n.links];a=r.span({name:t,parent:i,annotations:n?.annotations??Lr(),links:d,startTime:s?o.currentTimeNanosUnsafe():yl,kind:n?.kind??`internal`,root:n?.root??fr(i),sampled:n?.sampled??(pr(i)&&i.value.sampled===!1?!1:!Gl(e.getRef(Ba),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},wl=(e,t)=>(t=typeof t==`function`?t:d,Fs(Ua,n=>({name:e,stack:t,parent:n}))),Tl=(e,t,n,r)=>Oo(()=>{e.status._tag!==`Ended`&&e.end(r?n.currentTimeNanosUnsafe():yl,t)}),El=(e,...t)=>{let n=t.length===1?void 0:t[0],r=t[t.length-1];return g(t=>{let i=Cl(t,e,n),a=t.getRef(kl),o=t.getRef(Ga);return jc(t,e=>Tl(i,e,a,o)),r(i)})},Dl=/*#__PURE__*/ Bs(Ia),Ol=function(){let e=Bt(arguments[0]),t=e?arguments[1]:arguments[0],n=e?arguments[2]:arguments[1],r=s;return t._tag===`Span`&&(n=Xa(n),r=wl(t.name,n?.captureStackTrace)),e?Dl(r(arguments[0]),t):e=>Dl(r(e),t)},kl=/*#__PURE__*/ Qr(`effect/Clock`,{defaultValue:()=>new jl}),Al=2**31-1;var jl=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=/*#__PURE__*/ Oo(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return Pl()}currentTimeNanos=/*#__PURE__*/ Oo(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return Nl()}monotonicTimeNanos=/*#__PURE__*/ Oo(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(oa(e))}sleepMillis(e){return e<=0?Ao:Number.isFinite(e)?Ho(t=>{let n=e>Al?this.sleepMillis(e-Al):Fo,r=setTimeout(()=>t(n),Math.min(e,Al));return Oo(()=>clearTimeout(r))}):Uo}};const Ml=/*#__PURE__*/ BigInt(1e6),Nl=/*#__PURE__*/ 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=/*#__PURE__*/ BigInt(0);return()=>{let e=BigInt(Date.now())*Ml;return e>t&&(t=e),t}}(),Pl=/*#__PURE__*/ function(){let e=/*#__PURE__*/ BigInt(1e9),t;return()=>{let n=Nl(),r=BigInt(Date.now())*Ml;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}}(),Fl=e=>g(t=>e(t.getRef(kl))),Il=e=>Fl(t=>t.sleep(Ri(e))),Ll=/*#__PURE__*/ Fl(e=>e.currentTimeMillis),Rl=e=>p(e,`~effect/Cause/TimeoutError`),zl=`~effect/Cause/IllegalArgumentError`;var Bl=class extends (/*#__PURE__*/ yn(`IllegalArgumentError`)){[zl]=zl;constructor(e){super({message:e})}};const Vl=`~effect/Cause/AsyncFiberError`;var Hl=class extends (/*#__PURE__*/ yn(`AsyncFiberError`)){[Vl]=Vl;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}};const Ul=`~effect/Cause/UnknownError`;var Wl=class extends (/*#__PURE__*/ yn(`UnknownError`)){[Ul]=Ul;constructor(e,t){super({message:t,cause:e})}};const Gl=/*#__PURE__*/ ar(/* @__PURE__ */ rr(nr,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}})),Kl={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};Kl.gray,Kl.blue,Kl.green,Kl.yellow,Kl.red,Kl.bgBrightRed,Kl.black;function ql(){_o.interruptChildren??=yo}const Jl=/*#__PURE__*/ v(void 0),Yl=rn,Xl=Xt,Zl=$t,Ql=tn,$l=io,eu=ao,tu=to,nu=no,ru=xn,iu=Tn,au=Rl,ou=Bl,su=dn,cu=mn,lu=hn,uu=Os,du=Ts,fu={"~effect/Deferred":{_A:s,_E:s},pipe(){return r(this,arguments)}},pu=function(){this.resumes=void 0,this.effect=void 0};pu.prototype=fu;const mu=()=>new pu,hu=e=>Ho(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),Oo(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),gu=(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},_u=Sc,vu=Ec,yu=vc,bu=yc,xu=_c,Su=fc,Cu=`~effect/Layer/MemoMap`,wu=(e,t)=>{let n={observers:0,deferred:mu(),scope:_u(),finalizer:r=>y(()=>--n.observers>0?Fo:(e.map.delete(t),Su(n.scope,r)))};return n},Tu=(e,t)=>t.state._tag!==`Closed`&&(e.observers++,bc(t,{},e.finalizer),!0),Eu={"~effect/Layer":{_ROut:s,_E:s,_RIn:s},pipe(){return r(this,arguments)}},Du=e=>{let t=Object.create(Eu);return t.build=e,t},Ou=e=>Du((t,n)=>{let r=xu(n);return Mc(e(t,r),e=>e._tag===`Failure`?Su(r,e):Fo)}),ku=e=>{let t=Ou((n,r)=>n.getOrElseMemoize(t,r,e));return t};var Au=class{get[Cu](){return Cu}parent;constructor(e){this.parent=e}map=/*#__PURE__*/ new Map;get(e,t){let n=this.map.get(e);return n?(Tu(n,t),n.deferred.effect??hu(n.deferred)):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return y(()=>{let r;return Ac(y(()=>{let i=this.get(e,t);if(i)return i;let a=wu(this,e);return Tu(a,t)?(r=a.deferred,this.map.set(e,a),n(this,a.scope)):n(this,t)}),e=>{r&&gu(r,e)})})}};const ju=()=>new Au,Mu=e=>new Au(e);var Nu=class e extends (/*#__PURE__*/ xr()(`effect/Layer/CurrentMemoMap`)){static forkOrCreate(t){let n=Hr(t,e);return n?Mu(n):ju()}};const Pu=/*#__PURE__*/ o(3,(e,t,n)=>Bs(ys(e.build(t,n),Br(Nu,t)),Nu,t)),Fu=/*#__PURE__*/ o(2,(e,t)=>g(n=>Pu(e,Nu.forkOrCreate(n.context),t))),Iu=function(){return arguments.length===1?e=>Lu(arguments[0],e):Lu(arguments[0],arguments[1])},Lu=(e,t)=>Ru(ys(t,t=>zr(e,t))),Ru=e=>ku((t,n)=>vu(e,n)),zu=(e,t,n)=>{let r=xu(n,`parallel`);return Xc(e,e=>e.build(t,xu(r,`sequential`)),{concurrency:e.length}).pipe(ys(e=>Zr(...e)))},Bu=(...e)=>Ou((t,n)=>zu(e,t,n)),Vu=(e,t,n)=>Ou((r,i)=>b(Array.isArray(t)?zu(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(zs(t),ys(e=>n(e,t))))),Hu=/*#__PURE__*/ o(2,(e,t)=>Vu(e,t,s)),Uu=/*#__PURE__*/ o(2,(e,t)=>Vu(e,t,(e,t)=>Xr(t,e))),Wu=Ll,Gu=`~effect/DateTime`,Ku=`~effect/DateTime/TimeZone`,qu={[Gu]:Gu,pipe(){return r(this,arguments)},[vt](){return this.toString()},toJSON(){return id(this).toJSON()}},Ju={...qu,_tag:`Utc`,[be](){return De(this.epochMilliseconds)},[ze](e){return Xu(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${id(this).toJSON()})`}};({...qu});const Yu={[Ku]:Ku,[vt](){return this.toString()}};({...Yu}),{...Yu};const Xu=e=>p(e,Gu),Zu=e=>e._tag===`Utc`,Qu=e=>{let t=Object.create(Ju);return t.epochMilliseconds=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},$u=e=>{let t=e.getTime();if(Number.isNaN(t))throw new ou(`Invalid date`);return Qu(t)},ed=e=>{if(Xu(e))return e;if(e instanceof Date)return $u(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return $u(new Date(e.epochMilliseconds));let t=/* @__PURE__ */ new Date(0);return od(t,e),$u(t)}return typeof e==`string`&&!td(e)?$u(/* @__PURE__ */ new Date(e+`Z`)):$u(new Date(e))},td=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e),nd=/*#__PURE__*/ vr(ed),rd=e=>Qu(e.epochMilliseconds),id=e=>new Date(e.epochMilliseconds),ad=e=>e.epochMilliseconds,od=(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)},sd=e=>id(e).toISOString();globalThis.String;const cd=e=>e.trim(),ld=/*#__PURE__*/ Qr(`effect/Random`,{defaultValue:()=>({nextIntUnsafe(){return Math.floor(Math.random()*(2**53-1- -(2**53-1)+1))+-(2**53-1)},nextDoubleUnsafe(){return Math.random()}})}),ud=/*#__PURE__*/ o(2,(e,t)=>Ks(e,md,e=>t(e))),dd=e=>e.reasons.some(fd),fd=e=>e._tag===`Fail`&&ru(e.error),pd=e=>{let t,n=!1;for(let r of e.reasons)fd(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?ri(e):n?ri(Xl(e.reasons.filter(e=>!fd(e)))):ni(t)},md=e=>{let t=pd(e);return ai(t)?t:ni(t.success.value)},hd=e=>{let t=pd(e);return ai(t)?cu(t.failure):su(t.success.value)},gd=/*#__PURE__*/ o(2,(e,t)=>Zs(e,{onSuccess:t.onSuccess,onFailure:e=>{let n=pd(e);return ai(n)?t.onFailure(n.failure):t.onDone(n.success.value)}})),_d=`~effect/Schedule`,vd=/*#__PURE__*/ ld.useSync(e=>e.nextDoubleUnsafe()),yd=/*#__PURE__*/ Qr(`effect/Schedule/CurrentMetadata`,{defaultValue:/*#__PURE__*/ c({input:void 0,output:void 0,duration:Xi,attempt:0,start:0,now:0,elapsed:0,elapsedSincePrevious:0})}),bd={[_d]:{_Out:s,_In:s,_Env:s},pipe(){return r(this,arguments)}},xd=e=>p(e,_d),Sd=e=>{let t=Object.create(bd);return t.step=e,t},Cd=()=>{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}}},wd=e=>Sd(ys(e,e=>{let t=Cd();return(n,r)=>e(t(n,r))})),Td=e=>Us(e.step,e=>v(()=>Eo(e))),Ed=e=>Fl(t=>ys(Td(e),e=>{let n=Cd();return r=>y(()=>{let i=t.currentTimeMillisUnsafe();return b(e(i,r),([e,t])=>{let a=n(i,r);return a.output=e,a.duration=t,$o(Il(t),a)})})})),Dd=e=>Sd(ys(Jc(e.map(Td)),e=>(t,n)=>b(Xc(e,e=>gd(e(t,n),{onSuccess:e=>v(e[1]),onDone:()=>Jl,onFailure:Eo})),e=>{let t=Od(e);return t===void 0?iu(Xi):v([t,t])}))),Od=e=>{let t=e[0];for(let n=1;n<e.length&&(t=e[n]&&t&&pa(t,e[n]),t!==void 0);n++);return t},kd=e=>Sd(ys(Jc(e.map(Td)),e=>(t,n)=>b(Xc(e,e=>gd(e(t,n),{onSuccess:e=>v(e[1]),onDone:()=>Jl,onFailure:Eo})),e=>{let t=Ad(e);return t===void 0?iu(Xi):v([t,t])}))),Ad=e=>{let t;for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&(t=t===void 0?r:fa(t,r))}return t},jd=(e,t=2)=>{let n=oa(Ri(e));return wd(v(e=>{let r=ea(n*t**(e.attempt-1));return v([r,r])}))},Md=/*#__PURE__*/ o(2,(e,t)=>Sd(ys(Td(e),e=>{let n=Cd();return(r,i)=>b(e(r,i),([e,a])=>ys(t({...n(r,i),output:e,duration:a}),t=>[e,Ri(t)]))}))),Nd=e=>Md(e,({duration:e})=>ys(vd,t=>{let n=oa(e);return ea(n*.8*(1-t)+n*1.2*t)})),Pd=e=>Sd(ys(Td(e),e=>(t,n)=>gd(e(t,n),{onSuccess:e=>v([n,e[1]]),onFailure:Eo,onDone:()=>iu(n)}))),Fd=e=>Ld(Rd,({attempt:t})=>v(t<=e)),Id=e=>{let t=Ri(e);return wd(v(e=>v([e.attempt-1,t])))},Ld=/*#__PURE__*/ o(2,(e,t)=>Sd(ys(Td(e),e=>{let n=Cd();return(r,i)=>b(e(r,i),e=>{let[a,o]=e,s=t({...n(r,i),output:a,duration:o});return b(Bt(s)?s:v(s),t=>t?v(e):iu(a))})}))),Rd=/*#__PURE__*/ Id(Xi),zd=()=>e=>e,Bd=(e,t,n)=>Dc(r=>b(n?.local?Pu(t,ju(),r):Fu(t,r),t=>zs(e,t))),Vd=/*#__PURE__*/ o(e=>Bt(e[0]),(e,t,n)=>Fr(t)?zs(e,t):Bd(e,Array.isArray(t)?Bu(...t):t,n)),Hd=/*#__PURE__*/ o(3,(e,t,n)=>b(Ed(t),t=>{let r=yd.defaultValue();return qs(Hs(fs(b(y(()=>Bs(e,yd,r)),t),e=>Oo(()=>{r=e})),{disableYield:!0}),e=>xn(e)?v(e.value):n(e,r.attempt===0?ur():dr(r)))})),Ud=/*#__PURE__*/ o(3,(e,t,n)=>b(Ed(t),t=>{let r=yd.defaultValue(),i,a=qs(y(()=>Bs(e,yd,r)),e=>(i=e,b(t(e),e=>(r=e,a))));return ud(a,e=>Et(()=>n(i,e)))})),Wd=/*#__PURE__*/ o(2,(e,t)=>{let n=typeof t==`function`?t(s):xd(t)?t:qd(t);return Hd(e,n,Do)}),Gd=/*#__PURE__*/ o(2,(e,t)=>{let n=typeof t==`function`?t(s):xd(t)?t:qd(t);return Ud(e,n,Do)}),Kd=/*#__PURE__*/ Pd(Rd),qd=e=>{let t=e.schedule?Pd(e.schedule):Kd;return e.while&&(t=Ld(t,({input:t})=>{let n=e.while(t);return Bt(n)?n:v(n)})),e.until&&(t=Ld(t,({input:t})=>{let n=e.until(t);return Bt(n)?ys(n,e=>!e):v(!n)})),e.times!==void 0&&(t=Ld(t,({attempt:t})=>v(t<=e.times))),t},Jd=Yc,Yd=Lo,Xd=Ro,x=v,Zd=jo,Qd=y,$d=Oo,ef=Fo,tf=Ho,nf=Uo,rf=Wo,S=Do,af=Eo,of=Mo,sf=No,cf=Io,lf=Ao,uf=g,df=ko,C=b,ff=vs,pf=ds,mf=fs,hf=Xs,gf=ac,_f=ys,vf=$o,yf=ps,bf=Us,xf=Js,Sf=Gd,Cf=sc,wf=hs,Tf=Zs,Ef=Is,Df=Rs,Of=Vd,kf=zs,Af=Ps,jf=Bs,Mf=Oc,Nf=Pc,Pf=Mc,Ff=zc,If=Ic,Lf=qc,Rf=Hs,zf=Wd,Bf=El,Vf=Ol,Hf=rl,Uf=al,Wf=cl,Gf=ol,Kf=ul,qf=pl,Jf=fl,Yf=Go,Xf=Jo,Zf=bs,Qf=xs,$f=Ss,ep=_s,tp=Cs,np=Xo,rp=`~effect/BigDecimal`,ip={[rp]:rp,[be](){let e=fp(this);return we(Oe(String(e.value)),De(e.scale))},[ze](e){return ap(e)&&gp(this,e)===0},toString(){return`BigDecimal(${vp(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[vt](){return this.toJSON()},pipe(){return r(this,arguments)}},ap=e=>p(e,rp),op=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(ip);return n.value=e,n.scale=t,n},sp=(e,t)=>{let n=op(e,t);return n.normalized=n,n},cp=/*#__PURE__*/ BigInt(0),lp=/*#__PURE__*/ BigInt(1),up=/*#__PURE__*/ BigInt(10),dp=/*#__PURE__*/ sp(cp,0),fp=e=>{if(e.normalized===void 0){if(e.value===cp)e.normalized=dp;else{let t=`${e.value}`,n=t.length;for(;t[n-1]===`0`;)n--;e.normalized=sp(BigInt(t.slice(0,n)),e.scale-(t.length-n))}}return e.normalized},pp=[lp],mp=(e,t)=>e===t?0:e<t?-1:1,hp=(e,t)=>{let n=`${e.value<cp?-e.value:e.value}`,r=`${t.value<cp?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==cp)return i<cp?-1:1;let a=Math.max(n.length,r.length);return tr(n.padEnd(a,`0`),r.padEnd(a,`0`))},gp=(e,t)=>{if(e.scale===t.scale)return mp(e.value,t.value);let n=_p(e),r=_p(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?hp(t,e):hp(e,t);let o=pp[a]??=up**BigInt(a);return i>0?mp(e.value,t.value*o):mp(e.value*o,t.value)},_p=e=>e.value===cp?0:e.value<cp?-1:1,vp=e=>{let t=fp(e);if(Math.abs(t.scale)>=16)return yp(t);let n=t.value<cp,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},yp=e=>{if(bp(e))return`0e+0`;let t=fp(e),n=`${t.value}`,r=t.value<cp?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},bp=e=>e.value===cp,xp=Xu,Sp=Zu,Cp=ed,wp=nd,Tp=rd,Ep=ad,Dp=sd,Op=e=>Ap(typeof e==`string`?jp.encode(e):e),kp=e=>{let t=Mp(e),n=t.length;if(n%4!=0)return ri(new ka({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 ri(new ka({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));try{let e=t.endsWith(`==`)?2:+!!t.endsWith(`=`),r=new Uint8Array(n/4*3-e);for(let e=0,i=0;e<n;e+=4,i+=3){let n=Fp(t.charCodeAt(e))<<18|Fp(t.charCodeAt(e+1))<<12|Fp(t.charCodeAt(e+2))<<6|Fp(t.charCodeAt(e+3));r[i]=n>>16,r[i+1]=n>>8&255,r[i+2]=n&255}return ni(r)}catch(e){return ri(new ka({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},Ap=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=Np[e[r-2]>>2],n+=Np[(e[r-2]&3)<<4|e[r-1]>>4],n+=Np[(e[r-1]&15)<<2|e[r]>>6],n+=Np[e[r]&63];return r===t+1&&(n+=Np[e[r-2]>>2],n+=Np[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=Np[e[r-2]>>2],n+=Np[(e[r-2]&3)<<4|e[r-1]>>4],n+=Np[(e[r-1]&15)<<2],n+=`=`),n},jp=/*#__PURE__*/ new TextEncoder,Mp=e=>e.replace(/[\n\r]/g,``),Np=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Pp=/*#__PURE__*/ (/* @__PURE__ */ new Uint8Array(123)).fill(255);for(let e=0;e<64;e++)Pp[/*#__PURE__*/ Np.charCodeAt(e)]=e;Pp[61]=0;const Fp=e=>{if(e>=Pp.length||Pp[e]===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return Pp[e]},Ip=`~effect/http/Cookies`,Lp=`~effect/http/Cookies/Cookie`,Rp={[Ip]:Ip,...bt,toJSON(){return{_id:`effect/Cookies`,cookies:fi(this.cookies,e=>e.toJSON())}},pipe(){return r(this,arguments)}},zp=e=>{let t=Object.create(Rp);return t.cookies=e,t},Bp=e=>{let t={};for(let n of e)Dt(t,n.name,n);return zp(t)},Vp=e=>{let t=typeof e==`string`?[e]:e,n=[];for(let e of t){let t=Hp(e.trim());t&&n.push(t)}return Bp(n)};function Hp(e){let t=e.split(`;`).map(e=>e.trim()).filter(e=>e!==``);if(t.length===0)return;let n=t[0].indexOf(`=`);if(n===-1)return;let r=t[0].slice(0,n);if(!Up.test(r))return;let i=t[0].slice(n+1),a=Gp(i);if(t.length===1)return Object.assign(Object.create(Wp),{name:r,value:a,valueEncoded:i});let o={};for(let e=1;e<t.length;e++){let n=t[e],r=n.indexOf(`=`),i=r===-1?n:n.slice(0,r).trim(),a=r===-1?void 0:n.slice(r+1).trim();switch(i.toLowerCase()){case`domain`:{if(a===void 0)break;let e=a.trim().replace(/^\./,``);e&&(o.domain=e);break}case`expires`:{if(a===void 0)break;let e=new Date(a);isNaN(e.getTime())||(o.expires=e);break}case`max-age`:{if(a===void 0)break;let e=parseInt(a,10);isNaN(e)||(o.maxAge=ta(e));break}case`path`:if(a===void 0)break;a[0]===`/`&&(o.path=a);break;case`priority`:if(a===void 0)break;switch(a.toLowerCase()){case`low`:o.priority=`low`;break;case`medium`:o.priority=`medium`;break;case`high`:o.priority=`high`}break;case`httponly`:o.httpOnly=!0;break;case`secure`:o.secure=!0;break;case`partitioned`:o.partitioned=!0;break;case`samesite`:if(a===void 0)break;switch(a.toLowerCase()){case`lax`:o.sameSite=`lax`;break;case`strict`:o.sameSite=`strict`;break;case`none`:o.sameSite=`none`}}}return Object.assign(Object.create(Wp),{name:r,value:a,valueEncoded:i,options:Object.keys(o).length>0?o:void 0})}const Up=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,Wp={[Lp]:Lp,...bt,toJSON(){return{_id:`effect/Cookies/Cookie`,name:this.name,value:this.value,options:this.options}}},Gp=e=>{try{return decodeURIComponent(e)}catch{return e}},Kp=/*#__PURE__*/ new WeakMap,qp=`~effect/Redacted`,Jp=e=>p(e,qp),Yp=(e,t)=>{let n=Object.create(Xp);return t?.label&&(n.label=t.label),Kp.set(n,e),n},Xp={[qp]:{_A:e=>e},label:void 0,...Rt,toJSON(){return this.toString()},toString(){return`<redacted${se(this.label)?`:`+this.label:``}>`},[be](){return xe(Kp.get(this))},[ze](e){return Jp(e)&&Be(Kp.get(this),Kp.get(e))}},Zp=/*#__PURE__*/ Symbol.for(`~effect/http/Headers`),Qp=/*#__PURE__*/ Object.defineProperties(/*#__PURE__*/ Object.create(null),{[Zp]:{value:Zp},[it]:{value(e){return cm(this,Gr(e,um))}},toJSON:{value(){return ot(this)}},[ze]:{value(e){return em(this,e)}},[be]:{value(){return Ae(this)}},toString:{value:bt.toString},[vt]:{value:bt[vt]}}),$p=e=>Object.assign(Object.create(Qp),e),em=/*#__PURE__*/ hi(/*#__PURE__*/ kn()),tm=/*#__PURE__*/ Object.create(Qp),nm=e=>{if(e===void 0)return tm;if(Symbol.iterator in e){let t=Object.create(Qp);for(let[n,r]of e)t[n.toLowerCase()]=r;return t}let t=Object.create(Qp);for(let[n,r]of Object.entries(e))Array.isArray(r)?t[n.toLowerCase()]=r.join(`, `):r!==void 0&&(t[n.toLowerCase()]=r);return t},rm=e=>Object.setPrototypeOf(e,Qp),im=/*#__PURE__*/ o(3,(e,t,n)=>{let r=$p(e);return r[t.toLowerCase()]=n,r}),am=/*#__PURE__*/ o(2,(e,t)=>$p({...e,...nm(t)})),om=/*#__PURE__*/ o(2,(e,t)=>{let n=$p(e);return Object.assign(n,t),n}),sm=/*#__PURE__*/ o(2,(e,t)=>{let n=$p(e);return delete n[t.toLowerCase()],n}),cm=/*#__PURE__*/ o(2,(e,t)=>{let n={...e},r=t=>{if(typeof t==`string`){let r=t.toLowerCase();r in e&&(n[r]=Yp(e[r]))}else for(let r in e)r.search(t)!==-1&&(n[r]=Yp(e[r]))};if(Array.isArray(t))for(let e=0;e<t.length;e++)r(t[e]);else r(t);return n}),lm=(e,t)=>{for(let n=0;n<t.length;n++){let r=t[n];if(typeof r==`string`){if(r.toLowerCase()===e.toLowerCase())return!0}else if(e.search(r)!==-1)return!0}return!1},um=/*#__PURE__*/ Qr(`effect/Headers/CurrentRedactedNames`,{defaultValue:()=>[`authorization`,`cookie`,`set-cookie`,`x-api-key`]}),dm=`~effect/http/UrlParams`,fm=e=>p(e,dm),pm={...Rt,[dm]:dm,[Symbol.iterator](){return this.params[Symbol.iterator]()},toJSON(){return{_id:`UrlParams`,params:Object.fromEntries(this.params)}},[ze](e){return _m(this,e)},[be](){return Me(this.params.flat())}},mm=e=>{let t=Object.create(pm);return t.params=e,t},hm=e=>{if(fm(e))return e;let t=gm(e),n=[];for(let e=0;e<t.length;e++)if(Array.isArray(t[e][0])){let[r,i]=t[e];n.push([`${r[0]}[${r.slice(1).join(`][`)}]`,i])}else n.push(t[e]);return mm(n)},gm=e=>{let t=typeof e[Symbol.iterator]==`function`?_i(e):Object.entries(e),n=[];for(let[e,r]of t)if(Array.isArray(r))for(let t=0;t<r.length;t++)r[t]!==void 0&&n.push([e,String(r[t])]);else if(typeof r==`object`&&r){let t=gm(r);for(let[r,i]of t)n.push([[e,...typeof r==`string`?[r]:r],i])}else r!==void 0&&n.push([e,String(r)]);return n},_m=/*#__PURE__*/ Dn((e,t)=>vm(e.params,t.params)),vm=/*#__PURE__*/ wi(/*#__PURE__*/ li([/*#__PURE__*/ kn(),/*#__PURE__*/ kn()])),ym=/*#__PURE__*/ mm([]),bm=/*#__PURE__*/ o(2,(e,t)=>{let n=hm(t).params.slice(),r=/* @__PURE__ */ new Set;for(let e=0;e<n.length;e++)r.add(n[e][0]);for(let t=0;t<e.params.length;t++)r.has(e.params[t][0])||n.push(e.params[t]);return mm(n)});function xm(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}const Sm=`~sentinels`,Cm=`~constructor`,wm=/*#__PURE__*/ ee(e=>{let t=xm(e)?.identifier;return typeof t==`string`?t:e.getExpected(wm)}),w=/*#__PURE__*/ Symbol(),Tm=su,Em=/*#__PURE__*/ Tm(w),Dm=/*#__PURE__*/ Tm(w),Om=e=>e===w?ur():dr(e),km=e=>e._tag===`None`?Em:Tm(e.value),Am=`~effect/SchemaIssue/Issue`;function jm(e){return p(e,Am)&&e[Am]===Am}function Mm(e){return Object.hasOwn(e,`input`)}var Nm=class{[Am]=Am;constructor(e,t){t?.reportInput===!0&&e!==w&&(this.input=e)}};const Pm=class extends Nm{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},Fm=class extends Nm{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},Im=class extends Nm{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},Lm=class extends Nm{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},Rm=class extends Nm{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},zm=class extends Nm{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},Bm=class extends Nm{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Vm=class extends Nm{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Hm=class extends Nm{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Um=class extends Nm{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},Wm=class extends Nm{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Gm(e,t,n){if(jm(e))return e;if(typeof e==`string`)return new Vm({message:e},t,n);let r=typeof e.issue==`string`?new Vm({message:e.issue},t,n):e.issue;return new Im(e.path,r)}function Km(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Vm(void 0,t,n):Gm(e,t,n)}function qm(e,t,n,r){return Array.isArray(t)?bi(t)?t.length===1?Gm(t[0],n,r):new zm(e,Ci(t,e=>Gm(e,n,r)),n,r):void 0:Km(t,n,r)}const Jm=e=>{let t=rh(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Qm(wm(e.ast),e);case`InvalidValue`:{let t=Zm(e);if(t!==void 0)return Qm(t,e);let n=Xm(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Xm(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Xm(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},Ym=e=>rh(e.issue)??rh(e);function Xm(e){return Mm(e)?m(e.input):void 0}function Zm(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Qm(e,t){let n=Xm(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function $m(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=>$m(e)).join(` & `)}}function eh(){return e=>nh(e,``)}const th=/*#__PURE__*/ eh();function nh(e,t){let n;switch(e._tag){case`Filter`:{let r=Ym(e);if(r!==void 0)n=r;else{if(e.issue._tag!==`InvalidValue`)return nh(e.issue,t);let r=Zm(e.issue);n=r===void 0?Qm($m(e.filter),e):Qm(r,e.issue)}break}case`Encoding`:return nh(e.issue,t);case`Pointer`:return nh(e.issue,t+pt(e.path));case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>nh(e,t)).join(`
|
|
9
|
-
`);n=rh(e)??Qm(wm(e.ast),e);break;default:n=Jm(e)}return t?`${n}\n at ${t}`:n}function rh(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return rh(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 ih(e){let t;for(let n of e.reasons){if(!Yl(n)||!jm(n.error))return;t??=n.error}return t}function ah(e,t){let n=ih(e);if(n===void 0)throw Error(t,{cause:e});return n}const oh=e=>Op(e).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`),sh=e=>{let t=e.replace(/[\n\r]/g,``),n=t.length;if(n%4==1)return ri(new ka({module:`Base64Url`,kind:`Decode`,input:t,message:`Length should be a multiple of 4, but is ${n}`}));if(!/^[-_A-Z0-9]*?={0,2}$/i.test(t))return ri(new ka({module:`Base64Url`,kind:`Decode`,input:t,message:`Invalid input`}));let r=n%4==2?`${t}==`:n%4==3?`${t}=`:t;return r=r.replace(/-/g,`+`).replace(/_/g,`/`),kp(r)},ch=e=>si(sh(e),e=>lh.decode(e)),lh=/*#__PURE__*/ new TextDecoder,uh=e=>Object.assign(Object.create(i),e);function dh(e){return vh((t,n)=>S(e(t,n)))}function fh(e){return dh((t,n)=>{let r={message:e(t)};return pr(t)?new Hm(r,t.value,n):new Hm(r)})}const ph=/*#__PURE__*/ fh(()=>`Encoding is not supported`),mh=/*#__PURE__*/ uh({_tag:`Passthrough`});function hh(){return mh}function T(e){return uh({_tag:`Transform`,transform:e})}function gh(e){return uh({_tag:`TransformEffect`,transform:e})}function _h(e){return uh({_tag:`TransformOptional`,transform:e})}function vh(e){return uh({_tag:`TransformOptionalEffect`,transform:e})}function yh(){return T(globalThis.String)}function bh(){return T(globalThis.Number)}function xh(){return T(globalThis.BigInt)}function Sh(){return T(cd)}function Ch(e){return gh((t,n)=>cf({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Vm({expected:`a valid JSON string`},t,n)}))}function wh(e){return gh((t,n)=>cf({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 Vm({expected:`a JSON-serializable value`},t,n)}))}function Th(){return T(Op)}function Eh(){return gh((e,t)=>Qf(df(kp(e)),()=>new Vm({expected:`a valid Base64 string`},e,t)))}const Dh=class extends a{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Dh(this.encode,this.decode)}},Oh=`~effect/SchemaTransformation/Transformation`,kh=class extends a{[Oh]=Oh;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new kh(this.encode,this.decode)}};function Ah(e){return p(e,Oh)&&e[Oh]===Oh}const jh=e=>Ah(e)?e:new kh(e.decode,e.encode);function Mh(e){return new kh(gh(e.decode),gh(e.encode))}function Nh(e){return new kh(T(e.decode),T(e.encode))}function Ph(){return new kh(Sh(),hh())}const Fh=/*#__PURE__*/ new kh(/*#__PURE__*/ hh(),/*#__PURE__*/ hh());function Ih(){return Fh}const Lh=/*#__PURE__*/ new kh(/*#__PURE__*/ bh(),/*#__PURE__*/ yh()),Rh=/*#__PURE__*/ new kh(/*#__PURE__*/ xh(),/*#__PURE__*/ yh()),zh=e=>ge(e)&&typeof e.message==`string`,Bh=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:Wh(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},Vh=e=>{try{let t=_t(e);return t===void 0?m(e):JSON.parse(t)}catch{return m(e)}},Hh=(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},Uh=e=>{let t=/* @__PURE__ */ new WeakSet,n=r=>{if(ve(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=Hh(r,e,n);return t.delete(r),i}return Vh(r)};return n},Wh=e=>zh(e)?Bh(e):e,Gh=e=>Nh({decode:Wh,encode:Uh(e)}),Kh=/*#__PURE__*/ new kh(/*#__PURE__*/ Eh(),/*#__PURE__*/ Th());function qh(e){return new kh(Ch(e??{}),wh(e))}function Jh(e){return t=>t._tag===e}const Yh=/*#__PURE__*/ Jh(`Declaration`),Xh=/*#__PURE__*/ Jh(`Never`),Zh=/*#__PURE__*/ Jh(`Literal`),Qh=/*#__PURE__*/ Jh(`UniqueSymbol`),$h=/*#__PURE__*/ Jh(`Arrays`),eg=/*#__PURE__*/ Jh(`Objects`),tg=/*#__PURE__*/ Jh(`Union`),ng=/*#__PURE__*/ Jh(`Suspend`),rg=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},ig={},ag=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}},og=`~effect/Schema`;var sg=class{[og]=og;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 cg=class extends sg{_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)=>t===w?Em:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=L_(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new cg(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>`}},lg=/*#__PURE__*/ new class extends sg{_tag=`Null`;getParser(){return tv(this,null)}getExpected(){return`null`}},ug=class extends sg{_tag=`Undefined`;getParser(){return tv(this,void 0)}toCodecJson(){return T_(this,[dg])}getExpected(){return`undefined`}},dg=/*#__PURE__*/ new rg(lg,/*#__PURE__*/ new kh(/*#__PURE__*/ T(()=>void 0),/*#__PURE__*/ T(()=>null))),fg=/*#__PURE__*/ new ug,pg=/*#__PURE__*/ new class extends sg{_tag=`Any`;getParser(){return nv(this,he)}getExpected(){return`any`}},mg=/*#__PURE__*/ new class extends sg{_tag=`Unknown`;getParser(){return nv(this,he)}getExpected(){return`unknown`}};function hg(e){return typeof e==`number`?`parts[${e}]`:e}function gg(e,t,n){if(n.has(e))return!0;if(e.encoding)throw Error(`TemplateLiteral parts cannot have an encoding at ${hg(t)}`);let r;switch(e._tag){case`String`:case`Number`:case`BigInt`:r=!0;break;case`Literal`:r=!e.checks;break;case`TemplateLiteral`:{let i=hg(t);r=!e.checks&&e.parts.every((e,t)=>gg(e,`${i}.parts[${t}]`,n));break}case`Union`:{let i=hg(t);r=!e.checks&&e.types.every((e,t)=>gg(e,`${i}.types[${t}]`,n));break}default:return!1}return r&&n.add(e),r}const _g=class extends sg{_tag=`TemplateLiteral`;parts;encodedParts;literals;suffixLengths;constructor(e,t,n,r,i){super(t,n,r,i);let a=[],o=[],s=/* @__PURE__ */ new Set;for(let t=0;t<e.length;t++){let n=e[t];if(!gg(n,t,s))throw Error(`Invalid TemplateLiteral part ${n._tag}`);a.push(n),o.push(n._tag===`Literal`?globalThis.String(n.literal):void 0)}let c=Array(a.length+1);c[a.length]=0;for(let e=a.length-1;e>=0;e--)c[e]=c[e+1]+(o[e]?.length??0);this.parts=e,this.encodedParts=a,this.literals=o,this.suffixLengths=c}getParser(e){let t=new Dg(!1,this.parts.map(av),[]),n=e(U_(xg,t,vg(this)));return(e,t)=>{if(e===w)return Em;let r=n(e,t);return r._tag===`Success`?Dm:$f(r,{onSuccess:()=>e,onFailure:n=>new zm(this,[n],e,t)})}}getExpected(){return`string`}matchPart(e,t){return rv(this,e,t)===void 0?void 0:e}};function vg(e){return new kh(gh((t,n)=>{let r=rv(e,t,n);return r?x(r):S(new Vm({expected:`a string matching template literal parts`},t,n))}),T(e=>e.join(``)))}const yg=class extends sg{_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 ${m(e)}`);this.literal=e}getParser(){return tv(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?bg(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:bg(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function bg(e){let t=globalThis.String(e.literal);return T_(e,[new rg(new yg(t),new kh(T(()=>e.literal),T(()=>t)))])}const xg=/*#__PURE__*/ new class extends sg{_tag=`String`;getParser(){return nv(this,se)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&hv(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},Sg=class extends sg{_tag=`Number`;getParser(){return nv(this,ce)}matchKey(e,t){return this._match(sv,e,t)}matchPart(e,t){return this._match(ov,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:hv(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(Cg(this.checks,`effect/schema/isFinite`)||Cg(this.checks,`effect/schema/isInt`))?this:T_(this,[b_])}toCodecStringTree(){return this.toCodecJson()===this?T_(this,[uv]):T_(this,[dv])}getExpected(){return`number`}};function Cg(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&Cg(e.checks,t))}const wg=/*#__PURE__*/ new Sg,Tg=/*#__PURE__*/ new class extends sg{_tag=`Boolean`;getParser(){return nv(this,le)}getExpected(){return`boolean`}},Eg=/*#__PURE__*/ new class extends sg{_tag=`BigInt`;getParser(){return nv(this,ue)}matchPart(e,t){if(!fv.test(e))return;let n=globalThis.BigInt(e);return t.disableChecks||!this.checks?n:hv(this.checks,n,void 0,this,t)?void 0:n}toCodecStringTree(){return T_(this,[mv])}getExpected(){return`bigint`}},Dg=class extends sg{_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(K_(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(K_(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 Rm(n,t[o],i),a=new Im([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return S(new zm(n,[a],t,i))}return e.issues?S(new zm(n,e.issues,t,i)):Tm(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:new globalThis.Array(r),issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:Qc(t.concurrency),f=d===1?Ag(i,e,0,u):jg(i,e,{concurrency:d,end:u});if(!f)return c(i);if(gs(f))return ep(f,()=>c(i));let ee=!0;return Qd(()=>ee?(ee=!1,C(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===w)return Em;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)):S(new Bm(n,e,a))}catch(e){return sf(e)}}}_rebuild(e,t,n){let r=L_(this.elements,e),i=L_(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new Dg(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 Og(e,t,n,r){if(n._tag===`Failure`)return Mg(e,e.ast,r,n);let i=n===Dm?t:n[h];if(i!==w)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(K_(t.ast))return;let n=new Im([r],new Lm(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return lu(new zm(e.ast,[n],e.input,e.options))}}const kg={onItem(e,t,n){let r=n<e.len?t:w;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:Og},Ag=/*#__PURE__*/ $c()(kg),jg=/*#__PURE__*/ tl()(kg),Mg=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=ih(r.cause);if(i===void 0)return cu($l(r.cause,r=>new zm(t,[new Im([n],r)],e.input,e.options)));let a=new Im([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return lu(new zm(t,[a],e.input,e.options))},Ng=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function Pg(e,t,n=ig){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(iv(Z_(t)))}const Fg=class{name;type;constructor(e,t){this.name=e,this.type=t}};function Ig(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(Ig);default:return!1}}function Lg(e){let t=D_(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(Lg);default:return!1}}function Rg(e){return Ig(e)&&Lg(e)}const zg=class{parameter;type;constructor(e,t){if(!Rg(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,K_(t)&&!ev(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},Bg=class extends sg{_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 nv(n,me);let a,o,s=()=>(a||(a=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type})),o=i?n.indexSignatures.map(n=>({is:n,parserKey:e(iv(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 Mg(t,n,i,s)??uu;let c=s===Dm?o:s[h];if(a!==w&&c!==w){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return uu;Dt(t.out,a,c)}return uu},c=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!gs(t))return C(gf(t),t=>c(e,r,i,t));a=t}if(a._tag===`Failure`)return Mg(e,n,r,a)??uu;let o=a===Dm?r:a[h],s=e.input[r],l=i.parserValue(s,e.options);return gs(l)?t(e,r,o,s,l):C(gf(l),n=>t(e,r,o,s,n))},l=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return gs(a)?t(e,n,n,i,a):C(gf(a),r=>t(e,n,n,i,r))},u=i?tl()({onItem:(e,[t,n])=>n.is.parameter===xg?l(e,t,n):c(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return np(function*(t,d){if(t===w)return w;if(typeof t!=`object`||!t||Array.isArray(t))return yield*S(new Bm(n,t,d));s();let f=t,ee={},te={ast:n,input:f,out:ee,issues:void 0,options:d},ne=d.errors===`all`,re=d.onExcessProperty===`error`,ie=d.concurrency===void 0?1:Qc(d.concurrency),ae=i&&re?n.indexSignatures.map(e=>Pg(f,e.parameter,d)):void 0;if(re){let r=ae?new Set(e):e;if(ae)for(let e of ae)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 Rm(n,f[a],d),r=new Im([a],e);if(ne){te.issues?te.issues.push(r):te.issues=[r];continue}return yield*S(new zm(n,[r],t,d))}}}if(r){let e=ie===1?Ug(te,a):Wg(te,a,{concurrency:ie});e&&(yield*e)}if(i&&ie===1)for(let e=0;e<i;e++){let t=o[e],n=t.is.parameter===xg?l:c,r=ae?.[e]??(t.is.parameter===xg?Object.keys(f):Pg(f,t.is.parameter,d));for(let e=0;e<r.length;e++){let i=n(te,r[e],t);if(!gs(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(u){let e=xi();for(let t=0;t<i;t++){let n=o[t],r=ae?.[t]??(n.is.parameter===xg?Object.keys(f):Pg(f,n.is.parameter,d));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=u(te,e,{concurrency:ie});t&&(yield*t)}return te.issues?yield*S(new zm(n,te.issues,t,d)):ee})};if(i)return c();let l,u=(e,t,n)=>{let r=a[t];return C(gf(n),n=>{let i=Vg(e,r,n);if(i)return i;let o=()=>Tm(e.out),s=Ug(e,a.slice(t+1));return s?ep(s,o):o()})};return(e,t)=>{if(e===w)return Em;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&Qc(t.concurrency)!==1)return(l??=c())(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return S(new Bm(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_(i,s),l=c?i[s]:w,d=n.parser(l,t);if(!gs(d))return u(o,e,d);if(d===Dm){c&&Dt(a,s,l);continue}let f=Vg(o,n,d);if(f)return f}}catch(e){return sf(e)}return Tm(a)}}_rebuild(e,t,n,r){let i=L_(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new Fg(t.name,n)}),a=L_(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new zg(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new Bg(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 Vg(e,t,n){if(n._tag===`Failure`)return Mg(e,e.ast,t.name,n);if(n===Dm)return;let r=n[h];if(r!==w)Dt(e.out,t.name,r);else if(delete e.out[t.name],!K_(t.type)){let n=new Im([t.name],new Lm(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return lu(new zm(e.ast,[n],e.input,e.options))}}const Hg={onItem(e,t){if(!n_(e.input,t.name))return t.parser(w,e.options);let n=e.input[t.name];return Dt(e.out,t.name,n),t.parser(n,e.options)},step:Vg},Ug=/*#__PURE__*/ $c()(Hg),Wg=/*#__PURE__*/ tl()(Hg);function Gg(e,t){return e?t?[...e,...t]:e:t}function Kg(e,t,n){return new Bg(Reflect.ownKeys(e).map(t=>new Fg(t,e[t].ast)),[],n,t)}function qg(e){return e.ast}function Jg(e,t,n){return new i_(e.map(qg),t,void 0,n)}function Yg(e,t){if(e.encoding||t.some(e=>e.encoding))throw Error(`StructWithRest does not support encodings`);let n=e.propertySignatures,r=e.indexSignatures,i=e.checks;for(let e of t){for(let t of e.propertySignatures)if(n.some(e=>e.name===t.name))throw Error(`Duplicate identifier: ${JSON.stringify(t.name)}. ts(2300)`);n=n.concat(e.propertySignatures),r=r.concat(e.indexSignatures),i=Gg(i,e.checks)}return new Bg(n,r,void 0,i)}const Xg=/*#__PURE__*/ te(e=>{for(;;){if(ng(e))return mg;let t=e.encoding;if(!t)return e.recur?.(Xg,s)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==s))return mg;e=t[t.length-1].to}});function Zg(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(Zg)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function Qg(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[Sm];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!K_(t)){if(Zh(t))return[{key:e.name,literal:t.literal}];if(Qh(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!K_(e)){if(Zh(e))return[{key:t,literal:e.literal}];if(Qh(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>Qg(Xg(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return Qg(e.thunk())}}const $g=/*#__PURE__*/ new WeakMap,e_=/*#__PURE__*/ Object.freeze([]),t_=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,n_=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function r_(e){let t=$g.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=Xg(c);if(Xh(l))continue;if(Zh(l)||Qh(l)){a??=/* @__PURE__ */ new Map;let e=Zh(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=Qg(l);if(u.length){n??=/* @__PURE__ */ new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[/* @__PURE__ */ new Map,/* @__PURE__ */ new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=/* @__PURE__ */ new Set),a.add(t)}}else{i??={};let e=Zg(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??e_);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??e_;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=/* @__PURE__ */ 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=n_(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??e_;if(t)return o}return e_}}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=t_(t);if(!_e(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=n_(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=n_(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=n_(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(t_(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return $g.set(e,t),t}const i_=class extends sg{_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===w)return Em;let i=(o??=r_(n.types))(e,r);if(i.length===0)return S(new Um(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:gs(r)?a_(n,r.cause,e,t):o_(n,r,e,t)}return s_(n,a,i,e,t)}}_rebuild(e,t,n){let r=L_(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new i_(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=Z_(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Zh);if(t.length>0)return`${d_(n.isMutable)}[ ${t.map(t=>e(t)+f_(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Zh(e.type));if(t.length>0)return`{ ${t.map(t=>`${d_(t.type.context?.isMutable)}${ft(t.name)}${f_(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function a_(e,t,n,r){let i=ih(t);return i?lu(new Um(e,[i],n,r)):cu(t)}function o_(e,t,n,r){return bf(t,t=>a_(e,t,n,r))}function s_(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=l_(a,n);return o?c_(o,a):a.out?a.out:S(new Um(e,a.issues??[],r,i))}function c_(e,t){return ep(e,e=>t.out===Dm?x(t.input):t.out?t.out:S(new Um(t.ast,t.issues??[],t.input,t.options)))}const l_=/*#__PURE__*/ $c()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=ih(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]),lu(new Wm(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return uu}}}),u_=/*#__PURE__*/ new i_([/*#__PURE__*/ new yg(`Infinity`),/*#__PURE__*/ new yg(`-Infinity`),/*#__PURE__*/ new yg(`NaN`)]);function d_(e){return e?``:`readonly `}function f_(e){return e?`?`:``}const p_=class extends sg{_tag=`Suspend`;thunk;constructor(e,t,n,r,i){if(n)throw Error(`Cannot add checks to Suspend`);super(t,void 0,r,i);let a;this.thunk=()=>a??=e()}getParser(e){let t;return(n,r)=>(t??=e(this.thunk()))(n,r)}recur(e){return new p_(()=>e(this.thunk()),this.annotations,void 0,void 0,this.context)}getExpected(e){return e(this.thunk())}},m_=class extends a{_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 m_(this.run,{...this.annotations,...e},this.aborted)}abort(){return new m_(this.run,this.annotations,!0)}and(e,t){return new h_([this,e],t)}},h_=class extends a{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new h_(this.checks,{...this.annotations,...e})}and(e,t){return new h_([this,e],t)}};function g_(e,t,n=!1){return new m_((t,n,r)=>qm(n,e(t,n,r),t,r),t,n)}function __(e,t){return new m_((t,n,r)=>e(t)?void 0:new Vm(void 0,t,r),t,!0)}function v_(e){return g_(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 y_=/*#__PURE__*/ A_(wg,[/*#__PURE__*/ v_()]),b_=/*#__PURE__*/ new rg(/*#__PURE__*/ new i_([y_,u_]),/*#__PURE__*/ new kh(/*#__PURE__*/ bh(),/*#__PURE__*/ T(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function x_(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return g_(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 S_=/*#__PURE__*/ new WeakMap;function C_(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&S_.set(n,w_(e)),n}function w_(e){let t=S_.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 S_.set(e,n),n}function T_(e,t){return e.encoding===t?e:C_(e,{encoding:t})}function E_(e,t){if(e.context===t)return e;let n=w_(e);return n.context===t&&n.encoding===e.encoding?n:C_(e,{context:t})}function D_(e){return e.encoding?D_(e.encoding[e.encoding.length-1].to):e}function O_(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return k_(e,vi(e.checks.slice(0,-1),n.annotate(t)))}return C_(e,{annotations:{...e.annotations,...t}})}function k_(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:C_(e,{checks:t})}function A_(e,t){return k_(e,Gg(e.checks,t))}function j_(e,t){let n=t(e.to);return n===e.to?e:new rg(n,e.transformation)}function M_(e,t){let n=e,r=n[n.length-1],i=j_(r,t);return i===r?e:vi(e.slice(0,e.length-1),i)}function N_(e){return t=>t.encoding?T_(t,M_(t.encoding,e)):t}function P_(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:T_(r,M_(r.encoding,n))}return e(r)}return te(n)}function F_(e,t){return I_(e,t,X_(e))}function I_(e,t,n){let r=new rg(e,t);return T_(n,n.encoding?[...n.encoding,r]:[r])}function L_(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 R_(e,t){return E_(e,e.context?new ag(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new ag(!1,!1,void 0,t))}const z_=/*#__PURE__*/ te(e=>{let t=e.context?e.context.isOptional===!1?new ag(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new ag(!0,!1);return B_(E_(e,t))}),B_=/*#__PURE__*/ N_(z_),V_=/*#__PURE__*/ ee(e=>z_(new i_([e,fg])));function H_(e,t){return E_(e,e.context?new ag(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new ag(!1,!1,t))}function U_(e,t,n){return I_(e,n,t)}function W_(e){let t=[],n=[];function r(e){switch(e._tag){case`Literal`:fe(e.literal)&&!t.includes(e.literal)&&t.push(e.literal);return;case`UniqueSymbol`:t.includes(e.symbol)||t.push(e.symbol);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)r(e.types[t]);return;default:n.push(e)}}return r(e),{literals:t,parameters:n}}function G_(e,t){let{literals:n,parameters:r}=W_(e);return new Bg(n.map(e=>new Fg(e,t)),r.map(e=>new zg(e,t)))}function K_(e){return e.context?.isOptional??!1}function q_(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(q_)}function J_(e){function t(e){return q_(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return yi(n)?n:void 0}function Y_(e){let t=!0;function n(e){return t=t&&!e.encoding&&!ng(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}const X_=/*#__PURE__*/ te(e=>{let t=w_(e);if(t!==e){let n=X_(t);return n===t&&e.encoding===void 0?e:E_(n,e.context)}let n=`recur`in e?e.recur(X_):e;if(`encodingChecks`in n&&n.encodingChecks){let t=Y_(e)?n.encodingChecks:$h(n)||eg(n)||Yh(n)&&n.typeParameters.length>0?J_(n.encodingChecks):void 0;return C_(n,{encodingChecks:void 0,checks:Gg(n.checks,t)})}return n}),Z_=/*#__PURE__*/ te(e=>X_($_(e)));function Q_(e,t){let n=t,r=n.length,i=n[r-1],a=[new rg($_(T_(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new rg($_(n[e-1].to),n[e].transformation.flip()));let o=$_(i.to);return o.encoding?T_(o,[...o.encoding,...a]):T_(o,a)}const $_=/*#__PURE__*/ ee(e=>{if(e.encoding)return Q_(e,e.encoding);let t=w_(e);if(t!==e){let n=$_(t);return n===t?e:E_(n,e.context)}return`flip`in e?e.flip($_):`recur`in e?e.recur($_):e});function ev(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some(ev);default:return!1}}function tv(e,t){let n=t===0?Dm:Tm(t);return(r,i)=>r===w?Em:r===t?n:S(new Bm(e,r,i))}function nv(e,t){return(n,r)=>n===w?Em:t(n)?Dm:S(new Bm(e,n,r))}function rv(e,t,n){let r=e.encodedParts,i=e.literals,a=t.length;for(let e=0;e<i.length;e++){let n=i[e];if(n&&!t.includes(n))return}if(e.suffixLengths[0]>a)return;let o=Array(r.length),s;function c(l,u){if(l===r.length)return u===a;if(s?.has(l*(a+1)+u))return!1;let d=r[l];if(l===r.length-1){let e=t.slice(u);if(d.matchPart(e,n)!==void 0)return o[l]=e,!0}else if(d._tag===`Literal`){let e=i[l];if(t.startsWith(e,u)&&c(l+1,u+e.length))return o[l]=e,!0}else{let r=a-e.suffixLengths[l+1],s=i[l+1],f=s===void 0?r:t.lastIndexOf(s,r);for(;f>=u;){let e=t.slice(u,f);if(d.matchPart(e,n)!==void 0&&c(l+1,f))return o[l]=e,!0;if(f===0)break;f=s===void 0?f-1:t.lastIndexOf(s,f-1)}}return s??=/* @__PURE__ */ new Set,s.add(l*(a+1)+u),!1}return c(0,0)?o:void 0}const iv=/*#__PURE__*/ P_(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(iv)}}),av=/*#__PURE__*/ P_(e=>{switch(e._tag){default:return e;case`Number`:case`Literal`:case`BigInt`:return e.toCodecStringTree();case`Union`:return e.recur(av)}}),ov=/*#__PURE__*/ new globalThis.RegExp(`^${Ng}$`),sv=/*#__PURE__*/ new globalThis.RegExp(`^(?:${Ng}|Infinity|-Infinity|NaN)$`);function cv(e){return x_(ov,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:ov.source}),...e})}const lv=/*#__PURE__*/ A_(xg,[/*#__PURE__*/ cv()]),uv=/*#__PURE__*/ new rg(lv,Lh),dv=/*#__PURE__*/ new rg(/*#__PURE__*/ new i_([lv,u_]),Lh),fv=/*#__PURE__*/ new globalThis.RegExp(`^-?\\d+$`);function pv(e){return x_(fv,{expected:`a string representing a bigint`,representation:{id:`effect/schema/isStringBigInt`,payload:null},toJsonSchema:()=>({pattern:fv.source}),...e})}const mv=/*#__PURE__*/ new rg(/* @__PURE__ */ A_(xg,[/*#__PURE__*/ pv({expected:`a string representing a bigint`})]),Rh);function hv(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=hv(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 Pm(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function gv(e){if(!Yh(e))return;let t=e.annotations?.[Cm];return pe(t)?t(e.typeParameters):void 0}function _v(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function vv(e){return e===void 0||typeof e==`string`}function yv(e,t){let n=/* @__PURE__ */ 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 bv(e){return yv(e,_v)}const xv=/*#__PURE__*/ new cg([],()=>(e,t,n)=>bv(e)?Dm:S(new Bm(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>Cv});function Sv(e){return yv(e,vv)}const Cv=/*#__PURE__*/ new rg(/* @__PURE__ */ new cg([],()=>(e,t,n)=>Sv(e)?Dm:S(new Bm(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),/*#__PURE__*/ Ih()),wv=(e,t,n)=>e===Dm?n(t):ep(e,n);function Tv(e){if(e._tag===`Middleware`)return(t,n,r)=>{let i=t===Dm?e.decode(Tm(Om(n)),r):e.decode(Zf(t,Om),r);return Ev(i)};let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===Dm?Tm(t):e;case`Transform`:{let e=e=>e===w?Em:Tm(t.transform(e));return(t,n)=>wv(t,n,e)}case`TransformOptional`:{let e=e=>km(t.transform(Om(e)));return(t,n)=>wv(t,n,e)}case`TransformEffect`:return(e,n,r)=>wv(e,n,e=>e===w?Em:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>wv(e,n,e=>Ev(t.transform(Om(e),r)))}}const Ev=e=>ep(e,km),Dv=(e,t,n,r)=>bf(r,r=>of(()=>$l(r,r=>new Fm(e,r,t,n))));function Ov(e,t){let n=Tv(e.link.transformation),r;return(i,a)=>{if(i===w)return Em;if(e.isConstructed(i))return Dm;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function kv(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==w&&r!==void 0)return t(r,i);let a=n;if(gs(a)&&a._tag===`Success`){let e=t(a[h],i);return e===Dm?a:e}return ep(Dv(e,r,i,a),e=>{let n=t(e,i);return n===Dm?Tm(e):n})}}function Av(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:kv(e,n)}function jv(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?gv(e):void 0,o=a?Ov(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Tv(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);if(u&&!n.disableChecks){if(gs(r)){if(r._tag===`Success`){let i=r===Dm?t:r[h];if(t!==w&&i!==w){let i=hv(u,t,void 0,e,n);i&&(r=S(new zm(e,i,t,n)))}}}else r=C(r,r=>{if(t!==w&&r!==w){let r=hv(u,t,void 0,e,n);if(r)return S(new zm(e,r,t,n))}return x(r)})}if(s&&!n.disableChecks){if(gs(r)){if(r._tag===`Success`){let i=r===Dm?t:r[h];if(i===w)return r;let a=hv(s,i,void 0,e,n);a&&(r=S(new zm(e,a,i,n)))}}else r=C(r,t=>{if(t!==w){let r=hv(s,t,void 0,e,n);if(r)return S(new zm(e,r,t,n))}return x(t)})}return r},ee=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[h],o=t(a,r)):o=ep(o,e=>{let n=t(e,r);return n===Dm?Tm(e):n})}if(o._tag===`Success`){let e=o[h],t=ee(e,r);return t===Dm?o:t}return o=Dv(e,n,r,o),ep(o,e=>{let t=ee(e,r);return t===Dm?Tm(e):t})}:ee}const Mv=/*#__PURE__*/ Symbol(),Nv=/*#__PURE__*/ new WeakMap,Pv=e=>Rv(e).parser,Fv=e=>Rv(e).makeEffect,Iv=e=>Av(e,Fv);var Lv=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=jv(this.ast,Pv)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=jv(this.ast,Fv,Iv)}};function Rv(e){let t=Nv.get(e);if(t!==void 0)return t;let n=new Lv(e);return Nv.set(e,n),n}function zv(e){let t=e.ast,n;return(e,r)=>(n??=$v(ay,X_(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Bv(e){let t=zv(e);return(e,n)=>{let r=Jf(t(e,n));return du(r)?dr(r.value):(ah(r.cause,`Option adapter can only return none for schema issues`),ur())}}function Vv(e){return ry(X_(e.ast))}function Hv(e){return Wv(e.ast)}function Uv(e){{let t=ey(Zv(e));return e=>{let n=t(e,ig);return du(n)?!0:(ah(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Wv(e){let t=X_(e),n=e=>(n=Uv(t),n(e));return e=>n(e)}function Gv(e,t){let n=Zv(e.ast);return t===void 0?n:(e,r)=>n(e,Yv(t,r))}function Kv(e,t){return ty(Gv(e,t))}function qv(e,t){let n=Zv($_(e.ast));return t===void 0?n:(e,r)=>n(e,Yv(t,r))}function Jv(e,t){return ty(qv(e,t))}const Yv=(e,t)=>t?{...e,...t}:e,Xv=e=>e===w?S(new Vm):x(e);function Zv(e){return $v(iy,e)}function Qv(e,t){return e===Dm?x(t):gs(e)?e[`~effect/Effect/args`]===w?Xv(w):e:ep(e,Xv)}function $v(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??ig);return a===Dm?x(r):gs(a)?a[`~effect/Effect/args`]===w?Xv(w):a:ep(a,Xv)}}function ey(e){return(t,n)=>Jf(e(t,n))}function ty(e){let t=ey(e);return(e,n)=>{let r=t(e,n);return du(r)?dr(r.value):(ah(r.cause,`Option adapter can only return none for schema issues`),ur())}}function ny(e,t){let n=Jf(e);if(du(n))return n.value;let r=ah(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function ry(e){let t,n;return(r,i)=>{t??=Rv(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??ig,o=t.make;if(o!==void 0&&r!==w){let e;try{e=o(r,a)}catch(e){throw ah(Ql(e),`Constructor adapter can only throw schema issues`),e}if(e!==Mv&&e!==w)return e}return ny(Qv((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}const iy=e=>Rv(e).parser,ay=e=>Rv(e).makeEffect,oy=`~effect/Schema/Schema`,sy=/*#__PURE__*/ Symbol(),cy={[oy]:oy,get make(){let e=Vv(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=zv(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=Bv(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return r(this,arguments)},annotate(e){return this.rebuild(O_(this.ast,e))},annotateKey(e){return this.rebuild(R_(this.ast,e))},check(...e){return this.rebuild(A_(this.ast,e))},rebuild(e){return ly(e,this[sy])}};function ly(e,t){function n(){}let r=Object.setPrototypeOf(n,cy);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[sy]=t,r.ast=e,r}globalThis.RegExp;const uy=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`),dy=/*#__PURE__*/ ee(e=>fy(e));function fy(e){let t=xm(e)?.toEquivalence;if(t)return t(Yh(e)?e.typeParameters.map(fy):[]);switch(e._tag){case`Never`:return kn();case`Declaration`:return py(e);case`Null`:case`Undefined`:case`Void`:case`Unknown`:case`Any`:case`String`:case`Number`:case`Boolean`:case`BigInt`:case`Symbol`:case`Literal`:case`UniqueSymbol`:case`ObjectKeyword`:case`Enum`:case`TemplateLiteral`:return Be;case`Arrays`:{let t=e.elements.map(fy),n=e.rest.map(fy),[r,...i]=n,a=i.length;return Dn((o,s)=>{if(!Array.isArray(o)||!Array.isArray(s))return!1;let c=o.length;if(c!==s.length)return!1;let l=0;for(;l<Math.min(c,e.elements.length);l++)if(!t[l](o[l],s[l]))return!1;if(n.length>0){for(;l<c-a;l++)if(!r(o[l],s[l]))return!1;for(let e=0;e<a;e++)if(!i[e](o[l+e],s[l+e]))return!1}return!0})}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return Be;let t=e.propertySignatures.map(e=>fy(e.type)),n=e.indexSignatures.map(e=>fy(e.type));return Dn((r,i)=>{if(!ge(r)||!ge(i))return!1;for(let n=0;n<t.length;n++){let a=e.propertySignatures[n],o=a.name,s=Object.hasOwn(r,o),c=Object.hasOwn(i,o);if(K_(a.type)&&s!==c||s&&c&&!t[n](r[o],i[o]))return!1}for(let t=0;t<n.length;t++){let a=e.indexSignatures[t],o=Pg(r,a.parameter),s=Pg(i,a.parameter);if(o.length!==s.length)return!1;for(let e=0;e<o.length;e++){let a=o[e];if(!Object.hasOwn(i,a)||!n[t](r[a],i[a]))return!1}}return!0})}case`Union`:{let t=X_(e).types,n=r_(t),r=t.map((t,n)=>[Wv(t),fy(e.types[n])]);return Dn((e,t)=>{let i=n(e,!1);for(let n=0;n<i.length;n++){let[a,o]=r[i[n]];if(a(e)&&a(t))return o(e,t)}return!1})}case`Suspend`:{let t;return Dn((n,r)=>(t??=dy(e.thunk()))(n,r))}}}function py(e){let t=e.annotations?.representation;if(t===void 0)return Be;switch(t.id){case`effect/schema/Option`:{let[t]=my(e);return(e,n)=>e._tag===n._tag&&(e._tag===`None`||t(e.value,n.value))}case`effect/schema/Result`:{let[t,n]=my(e);return(e,r)=>e._tag===r._tag&&(e._tag===`Success`?t(e.success,r.success):n(e.failure,r.failure))}case`effect/schema/CauseReason`:{let[t,n]=my(e);return hy(t,n)}case`effect/schema/Cause`:{let[t,n]=my(e);return gy(t,n)}case`effect/schema/Exit`:{let[t,n,r]=my(e),i=gy(n,r);return(e,n)=>e._tag===n._tag&&(e._tag===`Success`?t(e.value,n.value):i(e.cause,n.cause))}case`effect/schema/ReadonlyMap`:{let[t,n]=my(e);return tt(t,n)}case`effect/schema/ReadonlySet`:return nt(my(e)[0]);case`effect/schema/RegExp`:return(e,t)=>e.source===t.source&&e.flags===t.flags;case`effect/schema/URL`:return(e,t)=>e.toString()===t.toString();default:return Be}}function my(e){return e.typeParameters.map(fy)}function hy(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case`Fail`:return e(n.error,r.error);case`Die`:return t(n.defect,r.defect);case`Interrupt`:return n.fiberId===r.fiberId}}}function gy(e,t){let n=jn(hy(e,t));return(e,t)=>n(e.reasons,t.reasons)}const _y=/*#__PURE__*/ o(2,(e,t)=>xy(e,(e,n)=>by(t,e)?[e,n]:void 0)),vy=/*#__PURE__*/ o(2,(e,t)=>xy(e,(e,n)=>by(t,e)?void 0:[e,n])),yy=e=>e;function by(e,t){return e.some(e=>e===t||typeof e==`number`&&String(e)===t)}function xy(e,t){let n={};for(let r of Reflect.ownKeys(e)){if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;let i=t(r,e[r]);if(i){let[e,t]=i;Dt(n,e,t)}}return n}const Sy=`~effect/Schema/SchemaError`;function Cy(e){return p(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}const wy=oy;function Ty(){return(e,t,n)=>D(new cg(e.map(qg),e=>t(e.map(e=>D(e))),n))}function Ey(e,t){return Ty()([],()=>(t,n,r)=>e(t)?x(t):S(new Bm(n,t,r)),t)}function E(e){return t=>t.annotate(e)}var Dy=class extends (/*#__PURE__*/ Da(`SchemaError`)){[Sy]=Sy;constructor(e){let t=Ct();wt(0);try{super({issue:e})}finally{wt(t)}}get message(){return th(this.issue)}toString(){return`SchemaError(${this.message})`}};function Oy(e){return Cy(e)}function ky(e){return gs(e)?Ay(e):bf(e,e=>of(()=>$l(e,e=>new Dy(e))))}function Ay(e){return du(e)?e:cu($l(e.cause,e=>new Dy(e)))}function jy(e,t){let n;for(let r of e.reasons){if(!Yl(r)||!Oy(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 My(e){let t=Jf(e);if(du(t))return t.value;throw jy(t.cause,`Sync adapter can only throw schema errors`)}const Ny=Hv;function Py(e,t){let n=Gv(e,t);return(e,t)=>ky(n(e,t))}const Fy=Kv;function Iy(e,t){let n=Py(e,t);return(e,t)=>My(n(e,t))}function Ly(e,t){let n=qv(e,t);return(e,t)=>ky(n(e,t))}const Ry=Jv;function zy(e,t){let n=Ly(e,t);return(e,t)=>My(n(e,t))}const By=zy,D=ly;function Vy(e){return p(e,wy)&&e[wy]===wy}const Hy=/*#__PURE__*/ yy(e=>D(z_(e.ast),{schema:e})),O=/*#__PURE__*/ yy(e=>{let t=nb(e);return D(V_(e.ast),{schema:t})}),Uy=/*#__PURE__*/ yy(e=>D(X_(e.ast),{schema:e})),Wy=/*#__PURE__*/ yy(e=>D(Z_(e.ast),{schema:e}));function k(e){let t=D(new yg(e),{literal:e,transform(n){return t.pipe(lb(k(n),{decode:T(()=>n),encode:T(()=>e)}))}});return t}function Gy(e){return e.map(e=>Vy(e)?e.ast:new yg(e))}function Ky(e){return D(new _g(Gy(e)),{parts:e})}const qy=/*#__PURE__*/ D(pg),A=/*#__PURE__*/ D(mg),Jy=/*#__PURE__*/ D(lg),Yy=/*#__PURE__*/ D(fg),j=/*#__PURE__*/ D(xg),M=/*#__PURE__*/ D(wg),N=/*#__PURE__*/ D(Tg),Xy=/*#__PURE__*/ D(Eg);function Zy(e,t){return D(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Zy(Kg(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function P(e){return Zy(Kg(e,void 0),e)}function F(e,t){return D(G_(e.ast,t.ast),{key:e,value:t})}function Qy(e,t){return D(Yg(e.ast,t.map(qg)),{schema:e,records:t})}const I=/*#__PURE__*/ yy(e=>D(new Dg(!1,[],[e.ast]),{value:e})),$y=/*#__PURE__*/ yy(e=>D(new Dg(!1,[e.ast],[e.ast]),{value:e}));function eb(e,t){return D(e,{members:t,mapMembers(e,t){let n=e(this.members);return eb(Jg(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function L(e,t){return eb(Jg(e,t,void 0),e)}function R(e){let t=e.map(k);return D(Jg(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return L(e(this.members))},pick(e){return R(e)},transform(e){return L(t.map((t,n)=>t.transform(e[n])))}})}const tb=/*#__PURE__*/ yy(e=>L([e,Jy])),nb=/*#__PURE__*/ yy(e=>L([e,Yy]));function rb(e){return D(new p_(()=>e().ast))}function ib(...e){return t=>t.check(...e)}function ab(e,t){return n=>D(A_(n.ast,[__(e,t)]),{schema:n})}function z(e){return t=>D(t.ast,{schema:t,identifier:e})}function ob(e){return t=>D(F_(t.ast,new Dh(e,s)),{schema:t})}function sb(e){return cb(e)}function cb(e){return t=>ob(tp(e))(t)}function lb(e,t){return n=>D(U_(n.ast,e.ast,t?jh(t):Ih()),{from:n,to:e})}function ub(){return(e,t)=>hb()(e,{decode:t,encode:ph})}function db(e,t){return n=>t?lb(n,t)(e):lb(n)(e)}function fb(e){return t=>D(H_(t.ast,e),{schema:t})}function B(e){return k(e).pipe(fb(x(e)))}function pb(e,t){return P({_tag:B(e),...t})}function V(e){return t=>{let n={},r=[],i=/* @__PURE__ */ new Set,a={};return o(t),Object.assign(t,{cases:n,discriminants:r,isAnyOf:t=>n=>t.includes(n[e]),guards:a,match:s,matchOrElse:c});function o(t){let s=t.ast;if(tg(s)&&`members`in t&&globalThis.Array.isArray(t.members)&&t.members.every(Vy))return t.members.forEach(o);let c=Qg(s);if(c.length>0){let o=c.find(t=>t.key===e)?.literal;if(fe(o)){let e=typeof o==`number`?globalThis.String(o):o;if(i.has(e))throw new globalThis.Error(`Duplicate discriminant: ${globalThis.String(o)}`);i.add(e),r.push(o),Dt(n,o,t),Dt(a,o,Hv(Uy(t)));return}}throw new globalThis.Error(`No literal or unique symbol found`)}function s(){if(arguments.length===1){let t=arguments[0];return function(n){let r=n[e];return(Object.hasOwn(t,r)?t[r]:void 0)(n)}}let t=arguments[0],n=arguments[1],r=t[e];return(Object.hasOwn(n,r)?n[r]:void 0)(t)}function c(){if(arguments.length===2){let t=arguments[0],n=arguments[1];return function(r){let i=r[e];return(Object.hasOwn(t,i)?t[i]??n:n)(r)}}let t=arguments[0],n=arguments[1],r=arguments[2],i=t[e];return(Object.hasOwn(n,i)?n[i]??r:r)(t)}}}function mb(e,t){return Ey(t=>t instanceof e,t)}function hb(){return(e,t)=>new rg(e.ast,jh(t))}const gb=g_,_b=`^\\S[\\s\\S]*\\S$|^\\S$|^$`;function vb(e){let t=new globalThis.RegExp(_b);return gb(e=>e.trim()===e,{expected:`a string with no leading or trailing whitespace`,representation:{id:`effect/schema/isTrimmed`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isTrimmed()`}),arbitraryConstraint:{patterns:[{source:_b,flags:``}]},...e})}function yb(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new RegExp(${m(n)})`:`new RegExp(${m(n)}, ${m(r)})`;return x_(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}function bb(e,t,n){if(e.length===0)return t.length===0?{}:[{},!0];let r={pattern:new globalThis.RegExp(n).source};return e===t?r:[r,!0]}function xb(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`^${uy(e)}`),i=e.replace(/[\uD800-\uDBFF]$/,``);return gb(t=>t.startsWith(e),{expected:`a string starting with ${n}`,representation:{id:`effect/schema/isStartingWith`,payload:{startsWith:e}},toJsonSchema:()=>bb(i,e,`^${uy(i)}`),toCode:()=>({runtime:`Schema.isStartingWith(${m(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}const H=/*#__PURE__*/ D(y_);function Sb(e){let t=ar(e.order),n=e.formatter??m;return(r,i)=>gb(e=>t(e,r),{expected:`a value greater than ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r,exclusiveMinimum:!0},...e.annotate?.(r),...i})}function Cb(e){let t=sr(e.order),n=e.formatter??m;return(r,i)=>gb(e=>t(e,r),{expected:`a value greater than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r},...e.annotate?.(r),...i})}function wb(e){let t=or(e.order),n=e.formatter??m;return(r,i)=>gb(e=>t(e,r),{expected:`a value less than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r},...e.annotate?.(r),...i})}function Tb(e){let t=sr(e.order),n=ar(e.order),r=or(e.order),i=ir(e.order),a=e.formatter??m;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return gb(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 Eb(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${m(e)}`);return e}const Db=/*#__PURE__*/ Sb({order:nr,annotate:e=>({representation:{id:`effect/schema/isGreaterThan`,payload:{exclusiveMinimum:Eb(e)}},toJsonSchema:()=>({exclusiveMinimum:e}),toCode:()=>({runtime:`Schema.isGreaterThan(${m(e)})`})})}),Ob=/*#__PURE__*/ Cb({order:nr,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualTo`,payload:{minimum:Eb(e)}},toJsonSchema:()=>({minimum:e}),toCode:()=>({runtime:`Schema.isGreaterThanOrEqualTo(${m(e)})`})})}),kb=/*#__PURE__*/ wb({order:nr,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualTo`,payload:{maximum:Eb(e)}},toJsonSchema:()=>({maximum:e}),toCode:()=>({runtime:`Schema.isLessThanOrEqualTo(${m(e)})`})})}),Ab=/*#__PURE__*/ Tb({order:nr,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:Eb(e.minimum),maximum:Eb(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${m(e.minimum)}, maximum: ${m(e.maximum)}, exclusiveMinimum: ${m(t)}, exclusiveMaximum: ${m(n)} })`})}}});function jb(e){return gb(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>[{type:`integer`},!0],toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}const U=/*#__PURE__*/ M.check(/*#__PURE__*/ jb()),Mb=/*#__PURE__*/ U.check(/*#__PURE__*/ Ob(0));function Nb(e,t,n){return gb(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 Pb(e){return Nb(1,1,e)}const Fb=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),Ib=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},Lb=[];function Rb(e){let t=Fb(e),n=Lb[t];if(n!==void 0)return n;let r=cx.pipe(lb(A,Gh(Ib(t))));return Lb[t]=r,r}globalThis.RegExp,globalThis.URL;const zb=/*#__PURE__*/ j.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function Bb(e,t){return zb.pipe(lb(e,qh(t)))}globalThis.File,globalThis.FormData,globalThis.URLSearchParams;const Vb=/*#__PURE__*/ j.check(/*#__PURE__*/ vb()),Hb=/*#__PURE__*/ j.annotate({expected:`a string that will be decoded as a trimmed string`}).pipe(/*#__PURE__*/ lb(Vb,/*#__PURE__*/ Ph())),Ub=/*#__PURE__*/ j.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),Wb=/*#__PURE__*/ mb(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>hb()(Ub,Kh)}),Gb=/*#__PURE__*/ Mh({decode:(e,t)=>mr(wp(e),{onNone:()=>S(new Vm({expected:`a valid UTC DateTime string`},e,t)),onSome:e=>x(Tp(e))}),encode:e=>x(Dp(e))});function Kb(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 qb(e,t){return U.check(Ab({minimum:e,maximum:t}))}const Jb=/*#__PURE__*/ Ey(e=>xp(e)&&Sp(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]=Kb(e,-864e13,864e13);return ub()(qb(t,n),T(Cp))},toCodecJson:()=>hb()(j,Gb),toFormatter:()=>e=>e.toString()}),Yb=/*#__PURE__*/ Mh({decode:(e,t)=>mr(Bi(e),{onNone:()=>S(new Vm({expected:`a valid Duration string`},e,t)),onSome:x}),encode:e=>x(globalThis.String(e))}),Xb=/*#__PURE__*/ Ey(Ki,{representation:{id:`effect/schema/Duration`,payload:null},toCode:()=>({runtime:`Schema.Duration`,Type:`Duration.Duration`,importDeclarations:[`import * as Duration from "effect/Duration"`]}),expected:`Duration`,toCodecJson:()=>hb()(L([P({_tag:k(`Infinity`)}),P({_tag:k(`NegativeInfinity`)}),P({_tag:k(`Nanos`),value:Xy}),P({_tag:k(`Millis`),value:U})]),Nh({decode:e=>{switch(e._tag){case`Infinity`:return Zi;case`NegativeInfinity`:return Qi;case`Nanos`:return $i(e.value);case`Millis`:return ea(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}}}}))}),Zb=/*#__PURE__*/ (/* @__PURE__ */ j.annotate({expected:`a string that will be decoded as a Duration`})).pipe(/*#__PURE__*/ lb(Xb,Yb)),Qb=/*#__PURE__*/ globalThis.Symbol.for(`immer-draftable`),$b={};function ex(e,t,n,i,a){let o=rx(n,t,i),s=nx(t),c=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===$b?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:$b,value:i}})}static[wy]=wy;get[s](){return s}static[Qb]=!0;static identifier=t;static fields=n.fields;static get ast(){return o(this).ast}static pipe(){return r(this,arguments)}static rebuild(e){return o(this).rebuild(e)}static make(e,t){return Vv(o(this))(e??{},t)}static makeOption(e,t){return Bv(o(this))(e??{},t)}static makeEffect(e,t){return o(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(O_(this.ast,e))}static annotateKey(e){return this.rebuild(R_(this.ast,e))}static check(...e){return this.rebuild(A_(this.ast,e))}static extend(e){return(t,r)=>{let i=ix(t)?t:P(t),o={...n.fields,...i.fields},s=Kg(o,n.ast.checks,{identifier:e});return ex(this,e,Zy(A_(s,i.ast.checks),o),r,a)}}static mapFields(e,t){return n.mapFields(e,t)}};return a!==void 0&&Object.assign(c.prototype,a(t)),c}function tx(e){return new kh(T(t=>new e(t,{"~payload":{token:$b,value:t}})),hh())}function nx(e){return`~effect/Schema/Class/${e}`}function rx(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=nx(t),o=e=>e instanceof i||p(e,a),s=tx(i);return r=lb(D(new cg([e.ast],()=>(e,t,n)=>o(e)?x(e):S(new Bm(t,e,n)),{identifier:t,[Cm]:([e])=>({isConstructed:o,link:new rg(e,s)}),toCodec:([e])=>new rg(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[Sm]:Qg(e.ast),...n})),s)(e)}}function ix(e){return Vy(e)}const W=e=>(t,n)=>{let r=ix(t)?t:P(t);return ex(Ea,e,r,n,e=>({toString(){return`${e}(${m({...this})})`}}))},ax=e=>(t,n)=>{let r=ix(t)?t:P(t);return ex(vn,e,r,n,e=>({name:e}))},ox=e=>(t,n,r)=>{let i=ix(n)?n.mapFields(e=>({_tag:B(t),...e}),{unsafePreserveChecks:!0}):pb(t,n);return ax(e??t)(i,r)};function sx(e){return dy(e.ast)}const cx=/*#__PURE__*/ D(/*#__PURE__*/ O_(xv,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),lx=So,ux=Co,dx=sl,fx=_l,px=vl,mx=`~effect/MutableRef`,hx={[mx]:mx,...Rt,toJSON(){return{_id:`MutableRef`,current:yt(this.current)}}},gx=e=>{let t=Object.create(hx);return t.current=e,t},_x=/*#__PURE__*/ Symbol.for(`effect/MutableList/Empty`),vx=()=>({head:void 0,tail:void 0,length:0}),yx=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})},bx=()=>({array:[],mutable:!0,offset:0,next:void 0}),xx=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=bx(),e.tail=e.tail.next):e.head=e.tail=bx(),e.tail.array.push(t),e.length++},Sx=e=>{e.head=e.tail=void 0,e.length=0},Cx=(e,t)=>{if(t=ei(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 Sx(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?Sx(e):yx(e),n;i=i.next}return Sx(e),n},wx=e=>{if(!e.head)return _x;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:Sx(e):yx(e),t},Tx={_A:s,_E:s},Ex={"~effect/Queue":Tx,"~effect/Queue/Enqueue":Tx,"~effect/Queue/Dequeue":Tx,...Rt,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:Bx(this)}}},Dx=e=>g(t=>{let n=Object.create(Ex);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=vx(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:/* @__PURE__ */ new Set,offers:/* @__PURE__ */ new Set,awaiters:/* @__PURE__ */ new Set},v(n)}),Ox=e=>Dx({capacity:e}),kx=()=>Dx(),Ax=/*#__PURE__*/ o(2,(e,t)=>y(()=>jx(e,t)?Hx:e.state._tag===`Open`&&e.strategy===`suspend`?Xx(e,t):Vx)),jx=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.strategy===`sliding`?(wx(e.messages),xx(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(xx(e.messages,t),Gx(e),!0):(xx(e.messages,t),Kx(e),!0):!1,Mx=/*#__PURE__*/ o(2,(e,t)=>Oo(()=>Nx(e,t))),Nx=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=mn(t),r=Ms(n,Ux);return e.state.offers.size===0&&e.messages.length===0?(tS(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},Kx(e),!0)},Px=e=>Oo(()=>Fx(e)),Fx=e=>{if(e.state._tag===`Done`)return!1;Sx(e.messages);let t=e.state.offers;tS(e,e.state._tag===`Open`?Wx:e.state.exit);for(let e of t)Qx(e);return!0},Ix=e=>Lx(e,1,1/0),Lx=/*#__PURE__*/ o(3,(e,t,n)=>(t=ei(t),n=ei(n),y(()=>qx(e,t,n)??ds(Yx(e,()=>Jx(e,t)),Lx(e,t,n))))),Rx=e=>y(()=>zx(e)??ds(Yx(e,()=>Jx(e,1)),Rx(e))),zx=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=wx(e.messages);return eS(e),dn(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=$x(e.state.offers);return eS(e),dn(t)}},Bx=e=>e.state._tag===`Done`?0:e.messages.length,Vx=/*#__PURE__*/ dn(!1),Hx=/*#__PURE__*/ dn(!0),Ux=/*#__PURE__*/ hn(/*#__PURE__*/ Cn()),Wx=/*#__PURE__*/ ws(),Gx=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(Os),e.messages.length===0))break}},Kx=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,Gx(e)},0))},qx=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return dn([]);if(!Jx(e,t))return;let r=e.messages.length>0?Cx(e.messages,n):[$x(e.state.offers)];return eS(e),dn(r)},Jx=(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,Yx=(e,t)=>Ho(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(Os);let r={ready:t,resume:n};return e.state.takers.add(r),Oo(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),Xx=(e,t)=>Ho(n=>jx(e,t)?n(Hx):Zx(e,{_tag:`Single`,message:t,resume:n})),Zx=(e,t)=>{if(e.state._tag!==`Open`)return Qx(t);let n=e.state.offers;return n.add(t),Oo(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&tS(e,e.state.exit))})},Qx=e=>e._tag===`Single`?e.resume(Vx):e.resume(dn(e.remaining.slice(e.offset))),$x=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(Hx),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(dn([]))),n},eS=e=>{if(e.state._tag===`Done`)return dd(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(tS(e,e.state.exit),dd(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`)xx(e.messages,t.message),e.state.offers.delete(t),t.resume(Hx);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;xx(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(dn([]))}}return!1},tS=(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()},nS=e=>new iS(e),rS=(e,t,n)=>Ho(r=>{if(e.free>=t)return r(n);let i=()=>{e.free<t||(e.waiters.delete(i),r(n))};return e.waiters.add(i),Oo(()=>{e.waiters.delete(i)})});var iS=class{waiters=/*#__PURE__*/ new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){let t=y(()=>this.free<e?rS(this,e,t):(this.taken+=e,v(e)));return t}takeIfAvailable(e){return y(()=>this.free<e?v(!1):(this.taken+=e,v(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{for(let e of this.waiters){if(this.free<=0)break;e()}},0),this.free}resize(e){return g(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),Fo))}release(e){return g(t=>v(this.releaseUnsafe(t,e)))}get releaseAll(){return g(e=>v(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>qc(n=>{let r=y(()=>{if(this.free<e){let t=rS(this,e,Fo);return b(n(t),()=>r)}return this.taken+=e,Ac(n(t),()=>{this.releaseUnsafe(fo(),e)},!0)});return r})}withPermit=/*#__PURE__*/ this.withPermits(1);withPermitsIfAvailable(e){return t=>qc(n=>this.free<e?jo:(this.taken+=e,Ac(n(us(t)),()=>{this.releaseUnsafe(fo(),e)},!0)))}};const aS=`~effect/Channel`,oS=e=>p(e,aS),sS={[aS]:{_Env:s,_InErr:s,_InElem:s,_OutErr:s,_OutElem:s},pipe(){return r(this,arguments)}},cS=e=>{let t=Object.create(sS);return t.transform=(t,n)=>bf(e(t,n),e=>x(af(e))),t},lS=(e,t)=>cS((n,r)=>C(fS(e)(n,r),e=>t(e,r))),uS=e=>cS((t,n)=>e),dS=e=>cS(Yf(function*(t,n){let r=xu(n),i=e=>Su(r,hd(e)),a=yield*Nf(e(t,n,r),i);return Nf(a,i)})),fS=e=>e.transform,pS=4096,mS=e=>cS((t,n)=>Qd(()=>fS(e())(t,n))),hS=e=>uS($d(()=>{let t=e();return Qd(()=>{let e=t.next();return e.done?iu(e.value):x(e.value)})})),gS=(e,t=pS)=>{let n=ti(t);return uS($d(()=>{let t=e(),r=ur();return Qd(()=>{if(r._tag===`Some`)return iu(r.value);let e=[];for(;e.length<n;){let n=t.next();if(n.done){if(e.length===0)return iu(n.value);r=dr(n.value);break}e.push(n.value)}return x(e)})}))},_S=(e,t=pS)=>gS(()=>e[Symbol.iterator](),t),vS=e=>SS(x(e)),yS=/*#__PURE__*/ uS(/*#__PURE__*/ x(/*#__PURE__*/ iu())),bS=e=>uS(x(S(e))),xS=e=>uS(af(e)),SS=e=>uS($d(()=>{let t=!1;return Qd(()=>t?iu():(t=!0,e))})),CS=e=>uS(x(Ix(e))),wS=e=>cS((t,n)=>TS({scope:n,readable:e.evaluate(),onError:e.onError,releaseLockOnEnd:e.releaseLockOnEnd})),TS=e=>{let t=e.readable.getReader(),n=e.exit??gx(void 0),r=Qd(()=>n.current?n.current:Tf(Xd({try:()=>t.read(),catch:e.onError}),{onFailure:e=>n.current??af(e),onSuccess:({done:e,value:t})=>n.current?n.current:e?iu():x(Si(t))}));return vf(bu(e.scope,e.releaseLockOnEnd?$d(()=>t.releaseLock()):Yd(()=>t.cancel().catch(f))),r)},ES=/*#__PURE__*/ o(2,(e,t)=>lS(e,e=>$d(()=>{let n=0;return _f(e,e=>t(e,n++))}))),DS=e=>e===void 0||e!==`unbounded`&&e<=1,OS=/*#__PURE__*/ o(e=>oS(e[0]),(e,t,n)=>DS(n?.concurrency)?kS(e,t):AS(e,t,n)),kS=(e,t)=>cS((n,r)=>{let i=0;return _f(fS(e)(n,r),C(e=>t(e,i++)))}),AS=(e,t,n)=>dS(Yf(function*(r,i,a){let o=0,s=yield*fS(e)(r,i),l=n.concurrency===`unbounded`?2**53-1:n.concurrency,u=yield*Ox(0);yield*bu(a,Px(u));let d=Gf(yield*Ef()),f=dx(a);if(n.unordered){let e=nS(l),n=c(e.release(1)),r=Tf({onFailure:e=>C(Mx(u,e),n),onSuccess:e=>C(Ax(u,e),n)});yield*e.take(1).pipe(C(()=>s),C(e=>{let n=o++;return f(d(r(Qd(()=>t(e,n))))),ef}),Rf({disableYield:!0}),bf(t=>e.withPermits(l-1)(Mx(u,t))),Uf(a))}else{let e=yield*Ox(l-2);yield*bu(a,Px(e)),yield*Rx(e).pipe(ff,C(e=>Ax(u,e)),Rf({disableYield:!0}),bf(e=>Mx(u,e)),Uf(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,Nx(u,e.cause))};yield*s.pipe(C(i=>{if(n)return af(n);let a=o++,s=d(Qd(()=>t(i,a)));return f(s),s.addObserver(r),Ax(e,lx(s))}),Rf({disableYield:!0}),bf(t=>Ax(e,cu(t)).pipe(pf(Mx(e,t)))),Uf(a))}return Rx(u)})),jS=/*#__PURE__*/ o(e=>oS(e[0]),(e,t,n)=>DS(n?.concurrency)?MS(e,t):NS(e,t,n)),MS=(e,t)=>cS((n,r)=>_f(fS(e)(n,r),e=>{let i,a,o=C(e,e=>(a??=xu(r),ep(fS(t(e))(n,a),e=>(i=s(e),i)))),s=ud(e=>{if(i=void 0,a.state._tag===`Empty`)return o;let t=Su(a,uu);return a=void 0,C(t,()=>o)});return Qd(()=>i??o)})),NS=(e,t,n)=>e.pipe(ES(t),VS(n)),PS=e=>jS(e,s),FS=e=>lS(e,e=>{let t,n=0,r=Qd(function r(){if(t===void 0)return C(e,e=>{switch(e.length){case 0:return r();case 1:return x(e[0]);default:return t=e,x(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),x(i)});return x(r)}),IS=/*#__PURE__*/ o(2,(e,t)=>lS(e,e=>x(C(e,function n(r){let i=[];for(let e=0;e<r.length;e++)t(r[e])&&i.push(r[e]);return bi(i)?x(i):C(e,n)})))),LS=/*#__PURE__*/ o(2,(e,t)=>cS((n,r)=>{let i=xu(r);return _f(fS(e)(n,i),e=>{let a=e.pipe(bf(e=>{if(dd(e))return af(e);let o=i;return i=xu(r),Su(o,cu(e)).pipe(pf(fS(t(e))(n,i)),C(e=>(a=e,e)))}));return Qd(()=>a)})})),RS=/*#__PURE__*/ o(3,(e,t,n)=>LS(e,e=>{let r=t(e);return ai(r)?xS(r.failure):n(r.success,e)})),zS=/*#__PURE__*/ o(2,(e,t)=>RS(e,tu,e=>t(e))),BS=/*#__PURE__*/ o(2,(e,t)=>zS(e,e=>bS(t(e)))),VS=/*#__PURE__*/ o(2,(e,{bufferSize:t=16,concurrency:n,switch:r=!1})=>dS(Yf(function*(i,a,o){let s=n===`unbounded`?2**53-1:Math.max(1,n),c=r?void 0:nS(s),l=yield*px(!0),u=/* @__PURE__ */ new Set,d=yield*Ox(t);yield*bu(o,Px(d));let f=yield*fS(e)(i,a);return yield*rf(function*(){for(;;){let e;c&&(u.size<s?yield*c.take(1):(e=yield*Hf(f),yield*wf(c.take(1),pf(lx(e),nf))));let t=e===void 0?yield*f:yield*lx(e),n=xu(o),r=yield*fS(t)(i,n);for(;u.size>=s;){let e=ui(u);u.delete(e),u.size===0&&(yield*l.open),yield*ux(e)}let a=yield*r.pipe(mf(()=>lf),C(e=>Ax(d,e)),Rf({disableYield:!0}),Nf(Yf(function*(e){let t=pd(e);if(yield*gf(Su(n,ai(t)?cu(t.failure):su(t.success.value))),u.has(a)&&(u.delete(a),c&&(yield*c.release(1)),u.size===0&&(yield*l.open),!oi(t)))return yield*Mx(d,e)})),Hf);l.closeUnsafe(),u.add(a)}}).pipe(bf(e=>{let t=pd(e);return oi(t)?l.whenOpen(Mx(d,e)):Mx(d,e)}),Uf(o)),Rx(d)}))),HS=e=>cS((t,n)=>{let r;return x(Qd(()=>r||e.pipe(vu(n),C(e=>fS(e)(t,n)),C(e=>r=e))))}),US=/*#__PURE__*/ o(2,(e,t)=>dS((n,r,i)=>yu(i,t).pipe(pf(fS(e)(n,r))))),WS=/*#__PURE__*/ o(2,(e,t)=>US(e,e=>t)),GS=(e,t,n)=>Qd(()=>{let r=_u(),i=fS(e)(iu(),r);return ud(C(i,t),n||x).pipe(Pf(e=>Su(r,e)))}),KS=/*#__PURE__*/ o(2,(e,t)=>GS(e,e=>Rf(C(e,t),{disableYield:!0}))),qS=/*#__PURE__*/ o(3,(e,t,n)=>Qd(()=>{let r=t();return GS(e,e=>Jd({while:l,body:()=>e,step:e=>{r=n(r,e)}}),()=>x(r))})),JS=(e,t)=>fS(e)(iu(),t),YS={_R:s,_E:s,_A:s},XS=function(e){this.channel=e};XS.prototype={"~effect/Stream":YS,pipe(){return r(this,arguments)}};const ZS=e=>new XS(e),QS=e=>p(e,`~effect/Stream`),$S=ZS,eC=(e,t)=>tC(rf(function*(){let n=yield*Ed(t),r=yield*jf(e,yd,yd.defaultValue()),i=!0,a=Qd(()=>n(r)).pipe(C(t=>jf(e,yd,t)),_f(e=>(r=e,Si(e))));return Qd(()=>i?(i=!1,x(Si(r))):a)})),tC=e=>$S(uS(e)),nC=(e,t)=>$S(cS((n,r)=>C(JS(e.channel,r),e=>t(e,r)))),rC=e=>e.channel,iC=/*#__PURE__*/ $S(yS),aC=(...e)=>uC(e),oC=e=>$S(mS(()=>e().channel)),sC=e=>$S(bS(e)),cC=(e,t)=>Array.isArray(e)&&t?.chunkSize===void 0?uC(e):$S(_S(e,t?.chunkSize)),lC=e=>pC(_f(e,cC)),uC=e=>bi(e)?$S(vS(e)):iC,dC=e=>$S(CS(e)),fC=e=>$S(wS(e)),pC=e=>$S(HS(_f(e,rC))),mC=/*#__PURE__*/ o(2,(e,t)=>oC(()=>{let n=0;return $S(ES(e.channel,Ci(e=>t(e,n++))))})),hC=/*#__PURE__*/ o(e=>QS(e[0]),(e,t,n)=>e.channel.pipe(FS,OS(t,n),ES(Si),$S)),gC=/*#__PURE__*/ o(e=>QS(e[0]),(e,t,n)=>e.channel.pipe(FS,jS(e=>t(e).channel,n),$S)),_C=e=>gC(e,cC),vC=/*#__PURE__*/ o(2,(e,t)=>{let n=$S(PS(hS(()=>bC(e,t))));return yC.set(n,[e,t]),n}),yC=/*#__PURE__*/ new WeakMap;function*bC(e,t){let n=[t,e];for(;n.length>0;){let e=n.pop(),t=yC.get(e);t===void 0?yield e.channel:n.push(t[1],t[0])}}const xC=/*#__PURE__*/ o(2,(e,t)=>$S(IS(rC(e),t))),SC=/*#__PURE__*/ o(2,(e,t)=>$S(BS(e.channel,t))),CC=/*#__PURE__*/ o(e=>QS(e[0]),(e,t,n)=>nC(e,(e,r)=>$d(()=>{let r=0,i=!1;return C(Qd(()=>i?iu():e),e=>{let a=e.findIndex(e=>t(e,r++));if(a>=0){i=!0;let t=e.slice(0,n?.excludeLast?a:a+1);return bi(t)?x(t):iu()}return x(e)})}))),wC=/*#__PURE__*/ o(2,(e,t)=>$S(WS(e.channel,t))),TC=e=>qS(e.channel,()=>[],(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n]);return e}),EC=/*#__PURE__*/ o(3,(e,t,n)=>qS(e.channel,t,(e,t)=>{for(let r=0;r<t.length;r++)e=n(e,t[r]);return e})),DC=/*#__PURE__*/ o(2,(e,t)=>KS(e.channel,t)),OC=/*#__PURE__*/ o(e=>QS(e[0]),(e,t,n)=>{let r,i,a=fx(!1);return new ReadableStream({start(n){i=Wf(kf(DC(e,e=>a.whenOpen($d(()=>{a.closeUnsafe();for(let t=0;t<e.length;t++)n.enqueue(e[t]);r(),r=void 0}))),t)),i.addObserver(e=>{e._tag===`Failure`?n.error(eu(e.cause)):n.close()})},pull(){return new Promise(e=>{r=e,a.openUnsafe()})},cancel(){if(i)return Kf(yf(ux(i)))}},n?.strategy)}),kC=/*#__PURE__*/ o(e=>QS(e[0]),(e,t)=>_f(Ef(),n=>OC(e,n,t))),AC=`~effect/http/HttpBody`;var jC=class{[AC];constructor(){this[AC]=AC}[vt](){return this.toJSON()}toString(){return m(this,{ignoreToString:!0})}};const MC=/*#__PURE__*/ new class extends jC{_tag=`Empty`;toJSON(){return{_id:`effect/HttpBody`,_tag:`Empty`}}};var NC=class extends jC{_tag=`Raw`;body;contentType;contentLength;constructor(e,t,n){super(),this.body=e,this.contentType=t,this.contentLength=n}toJSON(){return{_id:`effect/HttpBody`,_tag:`Raw`,body:this.body,contentType:this.contentType,contentLength:this.contentLength}}};const PC=(e,t)=>new NC(e,t?.contentType,t?.contentLength);var FC=class extends jC{_tag=`Uint8Array`;contentType;contentLength;text;_body;constructor(e,t,n,r){super(),this._body=e,this.text=r,this.contentType=t,this.contentLength=n}get body(){return this._body??=zC(this.text)}toJSON(){return{_id:`effect/HttpBody`,_tag:`Uint8Array`,body:this.contentType.startsWith(`text/`)||this.contentType.endsWith(`json`)?new TextDecoder().decode(this.body):`Uint8Array(${this.body.length})`,contentType:this.contentType,contentLength:this.contentLength}}};const IC=(e,t)=>new FC(e,t??`application/octet-stream`,e.length),LC=/*#__PURE__*/ new TextEncoder,RC=globalThis.Buffer,zC=RC===void 0?e=>LC.encode(e):e=>RC.from(e,`utf8`),BC=(e,t)=>{if(typeof e!=`string`&&(e=e===void 0?``:String(e)),RC!==void 0)return new FC(void 0,t??`text/plain`,RC.byteLength(e,`utf8`),e);let n=LC.encode(e);return new FC(n,t??`text/plain`,n.length,e)};var VC=class extends jC{_tag=`FormData`;contentType=void 0;contentLength=void 0;formData;constructor(e){super(),this.formData=e}toJSON(){return{_id:`effect/HttpBody`,_tag:`FormData`,formData:this.formData}}};const HC=e=>new VC(e),UC=`~effect/http/HttpClientError`,WC=e=>p(e,UC);var GC=class extends (/*#__PURE__*/ Da(`HttpClientError`)){constructor(e){`cause`in e.reason?super({...e,cause:e.reason.cause}):super(e)}[UC]=UC;get request(){return this.reason.request}get response(){return`response`in this.reason?this.reason.response:void 0}get message(){return this.reason.message}};const KC=e=>e.endsWith(`Error`)?e.slice(0,-5):e,qC=(e,t,n)=>t?`${e}: ${t} (${n})`:`${e} error (${n})`;var JC=class extends (/*#__PURE__*/ Da(`TransportError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return qC(KC(this._tag),this.description,this.methodAndUrl)}},YC=class extends (/*#__PURE__*/ Da(`InvalidUrlError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return qC(KC(this._tag),this.description,this.methodAndUrl)}},XC=class extends (/*#__PURE__*/ Da(`DecodeError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return qC(KC(this._tag),this.description,e)}},ZC=class extends (/*#__PURE__*/ Da(`EmptyBodyError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return qC(KC(this._tag),this.description,e)}};const QC=e=>e!==`GET`&&e!==`HEAD`&&e!==`OPTIONS`&&e!==`TRACE`,$C=[[`GET`,`get`],[`POST`,`post`],[`PUT`,`put`],[`DELETE`,`del`],[`PATCH`,`patch`],[`HEAD`,`head`],[`OPTIONS`,`options`],[`TRACE`,`trace`],[`QUERY`,`query`]],ew=(e,t)=>t._tag===`Empty`||t._tag===`FormData`?sm(sm(e,`content-type`),`content-length`):(e=t.contentType===void 0?sm(e,`content-type`):im(e,`content-type`,t.contentType),t.contentLength===void 0?sm(e,`content-length`):im(e,`content-length`,t.contentLength.toString())),tw=e=>{if(e==null||!/^\d+$/.test(e))return;let t=Number(e);return Number.isSafeInteger(t)?t:void 0};var nw=class extends (/*#__PURE__*/ Da(`UrlError`)){};const rw=(e,t,n)=>ii({try:()=>{let r=new URL(e,iw());for(let e=0;e<t.params.length;e++){let[n,i]=t.params[e];i!==void 0&&r.searchParams.append(n,i)}return n!==void 0&&(r.hash=n),r},catch:e=>new nw({cause:e})}),iw=()=>{if(`location`in globalThis&&globalThis.location!==void 0&&globalThis.location.origin!==void 0&&globalThis.location.pathname!==void 0)return location.origin+location.pathname},aw=`~effect/http/HttpClientRequest`,ow=e=>p(e,aw),sw={[aw]:aw,...bt,toJSON(){return{_id:`HttpClientRequest`,method:this.method,url:this.url,urlParams:this.urlParams,hash:this.hash,headers:ot(this.headers),body:this.body.toJSON()}},pipe(){return r(this,arguments)}};function cw(e,t,n,r,i,a){let o=Object.create(sw);return o.method=e,o.url=t,o.urlParams=n,o.hash=r,o.headers=i,o.body=a,o}const lw=/*#__PURE__*/ cw(`GET`,``,ym,/*#__PURE__*/ ur(),tm,MC),uw=e=>(t,n)=>fw(lw,{method:e,url:t,...n??void 0}),dw=/*#__PURE__*/ uw(`GET`),fw=/*#__PURE__*/ o(2,(e,t)=>{let n=e;return t.method&&(n=pw(n,t.method)),t.url&&(n=vw(n,t.url)),t.headers&&(n=hw(n,t.headers)),t.urlParams&&(n=yw(n,t.urlParams)),t.hash&&(n=bw(n,t.hash)),t.body&&(n=xw(n,t.body)),t.accept&&(n=gw(n,t.accept)),t.acceptJson&&(n=_w(n)),n}),pw=/*#__PURE__*/ o(2,(e,t)=>cw(t,e.url,e.urlParams,e.hash,e.headers,e.body)),mw=/*#__PURE__*/ o(3,(e,t,n)=>cw(e.method,e.url,e.urlParams,e.hash,im(e.headers,t,n),e.body)),hw=/*#__PURE__*/ o(2,(e,t)=>cw(e.method,e.url,e.urlParams,e.hash,am(e.headers,t),e.body)),gw=/*#__PURE__*/ o(2,(e,t)=>mw(e,`Accept`,t)),_w=/*#__PURE__*/ gw(`application/json`),vw=/*#__PURE__*/ o(2,(e,t)=>{if(typeof t==`string`)return cw(e.method,t,e.urlParams,e.hash,e.headers,e.body);let n=new URL(t.toString()),r=hm(n.searchParams),i=gr(n.hash===``?void 0:n.hash.slice(1));return n.search=``,n.hash=``,cw(e.method,n.toString(),r,i,e.headers,e.body)}),yw=/*#__PURE__*/ o(2,(e,t)=>cw(e.method,e.url,bm(e.urlParams,t),e.hash,e.headers,e.body)),bw=/*#__PURE__*/ o(2,(e,t)=>cw(e.method,e.url,e.urlParams,dr(t),e.headers,e.body)),xw=/*#__PURE__*/ o(2,(e,t)=>cw(e.method,e.url,e.urlParams,e.hash,ew(e.headers,t),t)),Sw=/*#__PURE__*/ o(e=>ow(e[0]),(e,t,n)=>xw(e,IC(t,n))),Cw=/*#__PURE__*/ o(e=>ow(e[0]),(e,t,n)=>xw(e,BC(t,n))),ww=/*#__PURE__*/ o(2,(e,t)=>xw(e,HC(t)));function Tw(e){let t=rw(e.url,e.urlParams,_r(e.hash));return oi(t)?dr(t.success):ur()}const Ew=e=>{let t=e.method.toUpperCase();return fw(lw,{method:t,url:new URL(e.url),headers:e.headers,body:Dw(e,t)})},Dw=(e,t)=>!QC(t)||e.body===null?MC:PC(e.body,{contentType:e.headers.get(`content-type`)??void 0,contentLength:tw(e.headers.get(`content-length`))}),Ow=(e,t)=>{let n=rw(e.url,e.urlParams,_r(e.hash));if(ai(n))return ri(n.failure);let r={method:e.method,headers:e.headers};if(t?.signal&&(r.signal=t.signal),QC(e.method))switch(e.body._tag){case`Empty`:break;case`Raw`:r.body=e.body.body,kw(e.body.body)&&(r.duplex=`half`);break;case`Uint8Array`:r.body=e.body.body;break;case`FormData`:r.body=e.body.formData;break;case`Stream`:r.body=OC(e.body.stream,t?.context??Lr()),r.duplex=`half`}return ii({try:()=>new Request(n.success,r),catch:e=>new nw({cause:e})})},kw=e=>typeof ReadableStream<`u`&&e instanceof ReadableStream,Aw=(e,t)=>Df(n=>df(Ow(e,{context:n,signal:t?.signal}))),jw=`~effect/http/HttpIncomingMessage`,Mw=(e,t)=>{let n=e.headers[`content-type`]??``,r;if(n.includes(`application/json`))try{r=qf(e.json)}catch{}else if(n.includes(`text/`)||n.includes(`urlencoded`))try{r=qf(e.text)}catch{}let i={...t,headers:ot(e.headers),remoteAddress:e.remoteAddress};return r!==void 0&&(i.body=r),i},Nw=`~effect/http/HttpClientResponse`,Pw=(e,t)=>new Fw(e,t);var Fw=class extends xt{[jw];[Nw];request;source;constructor(e,t){super(),this.request=e,this.source=t,this[jw]=jw,this[Nw]=Nw}toJSON(){return Mw(this,{_id:`HttpClientResponse`,request:this.request.toJSON(),status:this.status})}get status(){return this.source.status}get url(){if(this.source.url)return this.source.url.split(`#`)[0];let e=Tw(this.request);return fr(e)?``:(e.value.hash=``,e.value.href)}get headers(){return nm(this.source.headers)}cachedCookies;get cookies(){return this.cachedCookies?this.cachedCookies:this.cachedCookies=Vp(this.source.headers.getSetCookie())}get remoteAddress(){return ur()}get stream(){return this.source.body?fC({evaluate:()=>this.source.body,onError:e=>new GC({reason:new XC({request:this.request,response:this,cause:e})})}):sC(new GC({reason:new ZC({request:this.request,response:this,description:`can not create stream from empty body`})}))}get json(){return C(this.text,e=>cf({try:()=>e===``?null:JSON.parse(e),catch:e=>new GC({reason:new XC({request:this.request,response:this,cause:e})})}))}textBody;get text(){return this.textBody??=_f(this.arrayBuffer,e=>new TextDecoder().decode(e))}get urlParamsBody(){return C(this.text,e=>cf({try:()=>hm(new URLSearchParams(e)),catch:e=>new GC({reason:new XC({request:this.request,response:this,cause:e})})}))}formDataBody;get formData(){return this.formDataBody??=Xd({try:()=>this.source.formData(),catch:e=>new GC({reason:new XC({request:this.request,response:this,cause:e})})}).pipe(Ff,qf)}arrayBufferBody;get arrayBuffer(){return this.arrayBufferBody||=Xd({try:()=>this.source.arrayBuffer(),catch:e=>new GC({reason:new XC({request:this.request,response:this,cause:e})})}).pipe(Ff,qf),this.arrayBufferBody}pipe(){return r(this,arguments)}};const Iw=e=>rm({b3:`${e.traceId}-${e.spanId}-${e.sampled?`1`:`0`}${mr(e.parent,{onNone:()=>``,onSome:e=>`-${e.spanId}`})}`,traceparent:`00-${e.traceId}-${e.spanId}-${e.sampled?`01`:`00`}`}),Lw=`~effect/http/HttpClient`,Rw=/*#__PURE__*/ xr(`effect/HttpClient`),zw=/*#__PURE__*/ o(2,(e,t)=>Bw(n=>t(e.postprocess(n)),e.preprocess)),Bw=(e,t)=>{let n=Object.create(Vw);return n.preprocess=t,n.postprocess=e,n.execute=function(n){return e(t(n))},n},Vw={[Lw]:Lw,pipe(){return r(this,arguments)},...bt,toJSON(){return{_id:`effect/HttpClient`}},.../*#__PURE__*/ Object.fromEntries(/*#__PURE__*/ $C.map(([e,t])=>[t,function(t,n){return this.execute(uw(e)(t,n))}]))},Hw=e=>Bw(t=>C(t,t=>uf(n=>{let r=Yw.get(t),i=r??new AbortController,a=rw(t.url,t.urlParams,_r(t.hash));if(ai(a))return S(new GC({reason:new YC({request:t,cause:a.failure})}));let o=a.success;if(n.getRef(Ra)||n.getRef(Uw)(t)){let a=e(t,o,i.signal,n);return r?a:Lf(e=>Tf(e(a),{onSuccess(e){return Jw.register(e,i),x(new Xw(e,i))},onFailure(e){return nu(e)&&i.abort(),af(e)}}))}return Bf(n.getRef(Kw)(t),{kind:`client`},a=>{a.attribute(`http.request.method`,t.method),a.attribute(`server.address`,o.origin),o.port!==``&&a.attribute(`server.port`,+o.port),a.attribute(`url.full`,o.toString()),a.attribute(`url.path`,o.pathname),a.attribute(`url.scheme`,o.protocol.slice(0,-1));let s=o.search.slice(1);s!==``&&a.attribute(`url.query`,s);let c=n.getRef(um),l=n.getRef(Ww);for(let e in t.headers)l(e,`request`)&&a.attribute(`http.request.header.${e}`,lm(e,c)?`<redacted>`:t.headers[e]);return t=n.getRef(Gw)?hw(t,Iw(a)):t,Lf(s=>s(e(t,o,i.signal,n)).pipe(Vf(a,{captureStackTrace:!1}),Tf({onSuccess:e=>{a.attribute(`http.response.status_code`,e.status);for(let t in e.headers)l(t,`response`)&&a.attribute(`http.response.header.${t}`,lm(t,c)?`<redacted>`:e.headers[t]);return r?x(e):(Jw.register(e,i),x(new Xw(e,i)))},onFailure(e){return!r&&nu(e)&&i.abort(),af(e)}})))})})),x),Uw=/*#__PURE__*/ Qr(`effect/http/HttpClient/TracerDisabledWhen`,{defaultValue:()=>u}),Ww=/*#__PURE__*/ Qr(`effect/http/HttpClient/TracerHeaderFilter`,{defaultValue:()=>l}),Gw=/*#__PURE__*/ Qr(`effect/http/HttpClient/TracerPropagationEnabled`,{defaultValue:l}),Kw=/*#__PURE__*/ Qr(`effect/http/HttpClient/SpanNameGenerator`,{defaultValue:()=>e=>`http.client ${e.method}`}),qw=e=>Iu(Rw)(Df(t=>_f(e,e=>zw(e,Af(e=>Xr(t,e)))))),Jw=/*#__PURE__*/ (()=>{if(`FinalizationRegistry`in globalThis&&globalThis.FinalizationRegistry){let e=/*#__PURE__*/ new FinalizationRegistry(e=>{e.abort()});return{register(t,n){e.register(t,n,t)},unregister(t){e.unregister(t)}}}let e=/*#__PURE__*/ new Map;return{register(t,n){e.set(t,setTimeout(()=>n.abort(),5e3))},unregister(t){let n=e.get(t);n!==void 0&&(clearTimeout(n),e.delete(t))}}})(),Yw=/*#__PURE__*/ new WeakMap;var Xw=class{original;controller;constructor(e,t){this.original=e,this.controller=t}[Nw]=Nw;[jw]=jw;applyInterrupt(e){return Qd(()=>(Jw.unregister(this.original),If(e,()=>$d(()=>{this.controller.abort()}))))}get request(){return this.original.request}get url(){return this.original.url}get status(){return this.original.status}get headers(){return this.original.headers}get cookies(){return this.original.cookies}get remoteAddress(){return this.original.remoteAddress}get formData(){return this.applyInterrupt(this.original.formData)}get text(){return this.applyInterrupt(this.original.text)}get json(){return this.applyInterrupt(this.original.json)}get urlParamsBody(){return this.applyInterrupt(this.original.urlParamsBody)}get arrayBuffer(){return this.applyInterrupt(this.original.arrayBuffer)}get stream(){return oC(()=>(Jw.unregister(this.original),wC(this.original.stream,$d(()=>{this.controller.abort()}))))}toJSON(){return this.original.toJSON()}[vt](){return this.original[vt]()}pipe(){return r(this,arguments)}};const Zw=/*#__PURE__*/ Qr(`effect/http/FetchHttpClient/Fetch`,{defaultValue:()=>globalThis.fetch});var Qw=class extends (/*#__PURE__*/ xr()(`effect/http/FetchHttpClient/RequestInit`)){};const $w=/*#__PURE__*/ qw(/*#__PURE__*/ x(/* @__PURE__ */ Hw((e,t,n,r)=>{let i=r.getRef(Zw),a=Hr(r.context,Qw)??{},o=a.headers?om(nm(a.headers),e.headers):e.headers;o[`content-length`]&&(o=sm(o,`content-length`));let s=r=>_f(Xd({try:()=>i(t,{...a,method:e.method,headers:o,body:r,duplex:typeof ReadableStream<`u`&&r instanceof ReadableStream?`half`:void 0,signal:n}),catch:t=>new GC({reason:new JC({request:e,cause:t})})}),t=>Pw(e,t));switch(e.body._tag){case`Raw`:case`Uint8Array`:return s(e.body.body);case`FormData`:return s(e.body.formData);case`Stream`:return C(kC(e.body.stream),s)}return s(void 0)})));var eT=class extends (/*#__PURE__*/ xr()(`@effect/platform/Socket/WebSocketConstructor`)){};const tT=j,nT=j.pipe(z(`AI.ModelID`)),rT=j.pipe(z(`AI.ProviderID`)),iT=j,aT=j,G=e=>typeof e==`object`&&!!e&&!Array.isArray(e),oT=F(j,A),sT=(...e)=>{let t=e.filter(e=>e!==void 0);if(t.length===0)return;if(t.length===1&&Object.values(t[0]).every(e=>e!==void 0))return t[0];let n={};for(let e of t)for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=G(n[t])&&G(r)?sT(n[t],r):r);return Object.keys(n).length===0?void 0:n},cT=(...e)=>{let t=e.filter(e=>e!==void 0);if(t.length===0)return;if(t.length===1)return t[0];let n=Object.fromEntries(t.flatMap(e=>Object.entries(e).filter(e=>e[1]!==void 0)));return Object.keys(n).length===0?void 0:n},lT=F(j,A),K=F(j,F(j,A)).annotate({identifier:`LLM.ProviderMetadata`}),uT=(...e)=>sT(...e),dT=L([M.check(Db(0)),k(!1)]),fT=R([`zstd`,`gzip`,`none`]);var pT=class extends W(`AI.HttpOptions`)({body:O(oT),headers:O(F(j,j)),query:O(F(j,j)),timeout:O(dT),headerTimeout:O(dT),chunkTimeout:O(dT),encoding:O(fT)}){};(function(e){function t(t){return t===void 0||t instanceof e?t:new e(t)}e.make=t})(pT||={});const mT=(...e)=>{let t=sT(...e.map(e=>e?.body)),n=cT(...e.map(e=>e?.headers)),r=cT(...e.map(e=>e?.query)),i=e.findLast(e=>e?.timeout!==void 0)?.timeout,a=e.findLast(e=>e?.headerTimeout!==void 0)?.headerTimeout,o=e.findLast(e=>e?.chunkTimeout!==void 0)?.chunkTimeout,s=e.findLast(e=>e?.encoding!==void 0)?.encoding;if(t||n||r||i!==void 0||a!==void 0||o!==void 0||s!==void 0)return new pT({body:t,headers:n,query:r,timeout:i,headerTimeout:a,chunkTimeout:o,encoding:s})};var hT=class extends W(`LLM.GenerationOptions`)({maxTokens:O(M),temperature:O(M),topP:O(M),topK:O(M),frequencyPenalty:O(M),presencePenalty:O(M),seed:O(M),stop:O(I(j))}){};(function(e){e.make=(t={})=>t instanceof e?t:new e(t)})(hT||={});const gT=(e,t)=>e.findLast(e=>e?.[t]!==void 0)?.[t],_T=(...e)=>{let t=new hT({maxTokens:gT(e,`maxTokens`),temperature:gT(e,`temperature`),topP:gT(e,`topP`),topK:gT(e,`topK`),frequencyPenalty:gT(e,`frequencyPenalty`),presencePenalty:gT(e,`presencePenalty`),seed:gT(e,`seed`),stop:gT(e,`stop`)});return Object.values(t).some(e=>e!==void 0)?t:void 0};var vT=class extends W(`LLM.LanguageModelDefaults`)({generation:O(hT),providerOptions:O(lT),http:O(pT)}){};(function(e){e.make=t=>t instanceof e?t:new e({generation:t.generation===void 0?void 0:hT.make(t.generation),providerOptions:t.providerOptions,http:pT.make(t.http)})})(vT||={});const yT=Ey(e=>typeof e==`string`,{title:`ReasoningEffort`}),bT=R([`gemini`,`moonshot`,`none`]),xT=R([`max_completion_tokens`,`max_tokens`]),ST=R([`anthropic`,`alibaba`]);var CT=class extends W(`LLM.LanguageModelCompatibility`)({sanitizer:O(bT),reasoningField:O(j),requireReasoning:O(N),maxTokensField:O(xT),requireFinishReason:O(N),requireAssistantAfterTool:O(N),supportsStore:O(N),streamUsage:O(N),supportsStrictMode:O(N),supportsPromptCacheKey:O(N),cacheFormat:O(ST),zaiToolStream:O(N),requireSignature:O(N),supportsThinkingBlockBinding:O(N),supportsEffortUpdates:O(N)}){};(function(e){e.make=t=>t instanceof e?t:new e(t)})(CT||={});var wT=class e{id;provider;route;defaults;compatibility;constructor(e){this.id=e.id,this.provider=e.provider,this.route=e.route,this.defaults=e.defaults,this.compatibility=e.compatibility}static make(t){return new e({id:nT.make(t.id),provider:rT.make(t.provider),route:t.route,defaults:t.defaults===void 0?void 0:vT.make(t.defaults),compatibility:t.compatibility===void 0?void 0:CT.make(t.compatibility)})}static input(e){return{id:e.id,provider:e.provider,route:e.route,defaults:e.defaults,compatibility:e.compatibility}}static update(t,n){return Object.keys(n).length===0?t:e.make({...e.input(t),...n,route:n.route??t.route})}};const TT=Ey(e=>e instanceof wT,{expected:`LLM.LanguageModel`}),ET=Ky([M,R([`ms`,`s`,`m`,`h`,`d`])]).check(yb(/^\d+(ms|s|m|h|d)$/));var DT=class extends W(`LLM.CacheHint`)({type:R([`ephemeral`,`persistent`]),ttl:O(ET)}){};const OT=P({tools:O(N),system:O(N),messages:O(L([k(`latest-user-message`),k(`latest-assistant`),P({tail:Mb})])),ttl:O(ET)}),kT=L([k(`auto`),k(`none`),OT]),q=U.check(Db(0)),J=U.check(Ob(0)),AT=j.pipe(z(`RelativePath`),E({identifier:`RelativePath`})),jT=j.pipe(z(`AbsolutePath`),E({identifier:`AbsolutePath`})),Y=e=>Hy(e).pipe(lb(O(Uy(e)),{decode:hh({strict:!1}),encode:_h(yr(e=>e!==void 0))})),MT=(e,t)=>Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)),NT=e=>t=>MT(t,e(t)),PT=H.pipe(lb(Jb,{decode:T(e=>Cp(e)),encode:T(e=>Ep(e))}));j.pipe(z(`Tool.CallID`)),ox()(`Tool.Error`,{message:j,error:O(Rb()),metadata:O(F(j,A))});const FT=L([P({type:k(`text`),text:j}).annotate({identifier:`Tool.TextContent`}),P({type:k(`file`),uri:j,mime:j,name:O(j)}).annotate({identifier:`Tool.FileContent`})]).pipe(V(`type`)).annotate({identifier:`Tool.Content`});let IT=0,LT=0;function RT(){return BT(!1)}function zT(){return BT(!0)}function BT(e,t=Date.now()){t!==IT&&(IT=t,LT=0),LT++;let n=BigInt(t)*4096n+BigInt(LT),r=e?~n:n,i=Array.from({length:6},(e,t)=>Number(r>>BigInt(40-8*t)&255n).toString(16).padStart(2,`0`)).join(``),a=crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(14));return i+Array.from(a,e=>`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`[e%62]).join(``)}const VT=j.pipe(z(`Project.ID`),E({identifier:`Project.ID`}),NT(e=>({global:e.make(`global`)}))),HT=j.check(xb(`wrk`)).pipe(z(`Workspace.ID`),E({identifier:`Workspace.ID`}),NT(e=>{let t=()=>e.make(`wrk_`+RT());return{ascending:n=>n?e.make(n):t(),create:t}})),UT=P({directory:jT,workspaceID:Y(HT)}).annotate({identifier:`Location.Ref`});P(vy(UT.fields,[`workspaceID`])).annotate({identifier:`Location.PublicRef`}),P(vy(class extends W(`Location.Info`)({directory:jT,workspaceID:Y(HT),project:P({id:VT,directory:jT,canonical:jT})}){}.fields,[`workspaceID`])).annotate({identifier:`Location.PublicInfo`});const WT=j.check(xb(`evt_`)).pipe(z(`Event.ID`),E({identifier:`Event.ID`}),NT(e=>({create:()=>e.make(`evt_`+RT())}))),GT=U.check(Ob(0)).pipe(z(`Event.Seq`),E({identifier:`Event.Seq`})),KT=U.check(Ob(1)).pipe(z(`Event.Version`),E({identifier:`Event.Version`})),qT=P({aggregateID:j,seq:GT,version:KT});function X(e){let t=P(e.schema),n=P({aggregateID:qT.fields.aggregateID,seq:qT.fields.seq,version:k(e.durable.version).pipe(lb(Uy(KT),Nh({decode:()=>KT.make(e.durable.version),encode:()=>e.durable.version})))});return P({id:WT,created:H,metadata:Y(F(j,A)),type:k(e.type),durable:n,location:Y(UT),data:t}).annotate({identifier:e.identifier??e.type}).pipe(NT(()=>({type:e.type,durability:`durable`,durable:e.durable,data:t})))}function Z(e){let t=P(e.schema);return P({id:WT,created:H,metadata:Y(F(j,A)),type:k(e.type),location:Y(UT),data:t}).annotate({identifier:e.identifier??e.type}).pipe(NT(()=>({type:e.type,durability:`ephemeral`,durable:void 0,data:t})))}function JT(...e){return Object.freeze(e)}const YT=j.pipe(z(`Integration.ID`),E({identifier:`Integration.ID`})),XT=j.pipe(z(`Integration.MethodID`),E({identifier:`Integration.MethodID`})),ZT=j.pipe(z(`Credential.ID`),E({identifier:`Credential.ID`}),NT(e=>({create:()=>e.make(`cred_`+RT())})));JT(Z({type:`credential.updated`,schema:{}}),Z({type:`credential.switched`,schema:{integrationID:YT,credentialID:tb(ZT)}}));const QT=L([P({type:k(`oauth`),methodID:XT,refresh:j,access:j,expires:J,metadata:Y(F(j,A))}).annotate({identifier:`Credential.OAuth`}),P({type:k(`key`),key:j,metadata:Y(F(j,A))}).annotate({identifier:`Credential.Key`}),P({type:k(`external`),methodID:XT,metadata:Y(F(j,A))}).annotate({identifier:`Credential.External`})]).pipe(V(`type`)).annotate({identifier:`Credential.Value`});P({id:ZT,integrationID:YT,label:j,active:N,value:QT}).annotate({identifier:`Credential.Entry`}),P({id:Y(ZT),integrationID:YT,label:Y(j),value:QT,activate:Y(N)}).annotate({identifier:`Credential.CreateInput`});const $T=P({status:R([`needs_auth`]),message:j,url:Y(j)}).annotate({identifier:`Connection.Status`}),eE=L([P({type:k(`credential`),id:ZT,label:j,method:R([`key`,`oauth`,`external`]),status:Y($T)}).annotate({identifier:`Connection.CredentialInfo`}),P({type:k(`env`),name:j,status:Y($T)}).annotate({identifier:`Connection.EnvInfo`})]).pipe(V(`type`)).annotate({identifier:`Connection.Info`}),tE=j.check(xb(`frm_`)).pipe(z(`Form.ID`),E({identifier:`Form.ID`})).pipe(NT(e=>({create:t=>e.make(t??`frm_`+RT())}))),nE=F(j,A).annotate({identifier:`Form.Metadata`}),rE=P({value:j,label:j,description:j.pipe(Y)}).annotate({identifier:`Form.Option`}),iE=P({key:j,op:R([`eq`,`neq`]),value:L([j,M,N])}).annotate({identifier:`Form.When`}),aE={key:j,title:j.pipe(Y),description:j.pipe(Y),required:N.pipe(Y),hidden:N.pipe(Y).annotate({description:`Skip the interactive authentication prompt and use the default unless an answer is supplied`}),when:I(iE).pipe(Y)},oE=$y(L([P({...aE,type:k(`string`),format:R([`email`,`uri`,`date`,`date-time`]).pipe(Y),minLength:J.pipe(Y),maxLength:J.pipe(Y),pattern:j.pipe(Y),placeholder:j.pipe(Y),default:j.pipe(Y),options:I(rE).pipe(Y),custom:N.pipe(Y)}).annotate({identifier:`Form.StringField`}),P({...aE,type:k(`number`),minimum:M.pipe(Y),maximum:M.pipe(Y),default:M.pipe(Y)}).annotate({identifier:`Form.NumberField`}),P({...aE,type:k(`integer`),minimum:M.pipe(Y),maximum:M.pipe(Y),default:M.pipe(Y)}).annotate({identifier:`Form.IntegerField`}),P({...aE,type:k(`boolean`),default:N.pipe(Y)}).annotate({identifier:`Form.BooleanField`}),P({...aE,type:k(`multiselect`),options:I(rE),minItems:J.pipe(Y),maxItems:J.pipe(Y),custom:N.pipe(Y),default:I(j).pipe(Y)}).annotate({identifier:`Form.MultiselectField`}),P({key:j,type:k(`external`),url:j,title:j.pipe(Y),description:j.pipe(Y)}).annotate({identifier:`Form.ExternalField`})]).pipe(V(`type`),E({identifier:`Form.Field`}))).annotate({identifier:`Form.Fields`}),sE=P({id:tE,sessionID:j,title:j,metadata:nE.pipe(Y),fields:oE}).annotate({identifier:`Form.Info`}),cE=F(j,L([j,M,N,I(j)]).annotate({identifier:`Form.Value`})).annotate({identifier:`Form.Answer`}),lE=L([P({status:k(`pending`)}),P({status:k(`answered`),answer:cE}),P({status:k(`cancelled`),message:j.pipe(Y)})]).pipe(V(`status`)).annotate({identifier:`Form.State`});P({...sE.fields,state:lE}).annotate({identifier:`Form.Detail`}),P({answer:cE}).annotate({identifier:`Form.Reply`}),JT(Z({type:`form.created`,schema:{form:sE}}),Z({type:`form.replied`,schema:{id:tE,sessionID:j,answer:cE}}),Z({type:`form.cancelled`,schema:{id:tE,sessionID:j}}));const uE=YT,dE=XT,fE=L([P({id:dE,type:k(`oauth`),label:j,form:Y(oE)}).annotate({identifier:`Integration.OAuthMethod`}),P({id:dE,type:k(`command`),label:j,command:I(j)}).annotate({identifier:`Integration.CommandMethod`}),P({type:k(`key`),label:Y(j),form:Y(oE)}).annotate({identifier:`Integration.KeyMethod`}),P({id:dE,type:k(`external`),label:j,form:Y(oE)}).annotate({identifier:`Integration.ExternalMethod`}),P({type:k(`env`),names:I(j)}).annotate({identifier:`Integration.EnvMethod`})]).pipe(V(`type`)).annotate({identifier:`Integration.Method`});JT(Z({type:`integration.updated`,schema:{}})),P({id:uE,name:j,metadata:Y(F(j,qy))}).annotate({identifier:`Integration.Ref`}),P({id:uE,name:j,metadata:Y(F(j,qy)),methods:I(fE),connections:I(eE)}).annotate({identifier:`Integration.Info`});const pE=j.pipe(z(`Integration.AttemptID`),E({identifier:`Integration.AttemptID`}),NT(e=>({create:()=>e.make(`con_`+RT())}))),mE=P({created:M,expires:M});W(`Integration.Attempt`)({attemptID:pE,url:j,instructions:j,mode:R([`auto`,`code`]),time:mE}),L([P({status:k(`pending`),time:mE}),P({status:k(`complete`),time:mE}),P({status:k(`failed`),message:j,time:mE}),P({status:k(`expired`),time:mE})]).pipe(V(`status`)).annotate({identifier:`Integration.AttemptStatus`}),P({attemptID:pE,time:mE}).annotate({identifier:`Integration.CommandAttempt`}),L([P({status:k(`pending`),message:Y(j),time:mE}),P({status:k(`complete`),time:mE}),P({status:k(`failed`),message:j,time:mE}),P({status:k(`expired`),time:mE})]).pipe(V(`status`)).annotate({identifier:`Integration.CommandAttemptStatus`});const hE=L([R([`reasoning`,`reasoning_content`,`reasoning_text`]),j]).annotate({identifier:`Model.ReasoningField`}),gE=R([`max_completion_tokens`,`max_tokens`]).annotate({identifier:`Model.MaxTokensField`}),_E=R([`assets`,`state`,`root`]).annotate({identifier:`Model.MediaInput`}),vE=R([`anthropic`,`alibaba`]).annotate({identifier:`Model.CacheFormat`}),yE=P({reasoningField:hE.pipe(Y),requireReasoning:N.pipe(Y),maxTokensField:gE.pipe(Y),requireFinishReason:N.pipe(Y),requireAssistantAfterTool:N.pipe(Y),supportsPromptCacheKey:N.pipe(Y),streamUsage:N.pipe(Y),cacheFormat:vE.pipe(Y),supportsThinkingBlockBinding:N.pipe(Y),supportsEffortUpdates:N.pipe(Y),mediaInput:_E.pipe(Y)}).annotate({identifier:`Model.Compatibility`}),bE=P(vy(yE.fields,[`supportsThinkingBlockBinding`,`supportsEffortUpdates`])).annotate({identifier:`Provider.Compatibility`}),xE=j.pipe(z(`Provider.ID`),E({identifier:`Provider.ID`}),NT(e=>({opencode:e.make(`opencode`),anthropic:e.make(`anthropic`),openai:e.make(`openai`),google:e.make(`google`),googleVertex:e.make(`google-vertex`),githubCopilot:e.make(`github-copilot`),amazonBedrock:e.make(`amazon-bedrock`),azure:e.make(`azure`),openrouter:e.make(`openrouter`),mistral:e.make(`mistral`),gitlab:e.make(`gitlab`)})));JT(Z({type:`provider.updated`,schema:{}}));const SE=j,CE=R([`auto`,`enabled`,`disabled`]),wE=L([P({type:k(`summary`)}),P({type:k(`native`)})]).pipe(V(`type`)).annotate({identifier:`Provider.Compaction`}),TE=R([`http`,`websocket`]).annotate({identifier:`Provider.Transport`}),EE=P({ttl:Ky([M,R([`ms`,`s`,`m`,`h`,`d`])]).check(yb(/^\d+(ms|s|m|h|d)$/)).annotate({identifier:`Provider.CacheTTL`}).pipe(Y)}).annotate({identifier:`Provider.Cache`}),DE=R([`zstd`,`gzip`,`none`]).annotate({identifier:`Provider.Encoding`}),OE=L([H,k(!1)]).pipe(Y),kE=Qy(P({timeout:OE,headerTimeout:OE,chunkTimeout:OE,compaction:wE.pipe(Y),cache:EE.pipe(Y),transport:TE.pipe(Y),encoding:DE.pipe(Y)}),[F(j,qy)]).annotate({identifier:`Provider.Settings`}),AE={settings:kE.pipe(Y),headers:F(j,j).pipe(Y),body:F(j,qy).pipe(Y)},jE=P({settings:kE.pipe(fb(x({}))),headers:F(j,j),body:F(j,qy)}).annotate({identifier:`Provider.Request`});P({id:xE,canonical:xE.pipe(Y),integrationID:uE.pipe(Y),name:j,activation:CE,package:SE,compatibility:bE.pipe(Y),...AE}).annotate({identifier:`Provider.Info`}).pipe(NT(()=>({empty:e=>({id:e,name:e,activation:`auto`,package:``})})));const ME=H.pipe(z(`Money.USD`),E({identifier:`Money.USD`}),NT(e=>({zero:e.make(0)}))),NE=H.pipe(z(`Money.USDPerMillionTokens`),E({identifier:`Money.USDPerMillionTokens`}),NT(e=>({zero:e.make(0)}))),PE=j.pipe(z(`Model.ID`));JT(Z({type:`model.updated`,schema:{}}));const FE=j.pipe(z(`Model.VariantID`)),IE=P({id:PE,providerID:xE,variant:FE.pipe(Y)}).annotate({identifier:`Model.Ref`}).pipe(NT(e=>({parse:t=>{let n=t.indexOf(`/`);if(n<=0)throw Error(`Invalid model reference: ${t}`);let r=t.slice(0,n),i=t.indexOf(`#`,n+1),a=t.slice(n+1,i===-1?void 0:i),o=i===-1?void 0:t.slice(i+1);if(!a||r.includes(`#`)||o!==void 0&&(!o||o.includes(`#`)))throw Error(`Invalid model reference: ${t}`);return e.make({providerID:xE.make(r),id:PE.make(a),...o?{variant:FE.make(o)}:{}})}}))),LE=j.pipe(z(`Model.Family`)),RE=L([R([`chat`,`decision`,`image`]),j]).annotate({identifier:`Model.Type`}),zE=Qy(P(_y(kE.schema.fields,[`compaction`,`cache`,`encoding`])),[F(j,qy)]).annotate({identifier:`Model.Settings`}),BE=Qy(P(vy(zE.schema.fields,[`cache`])),zE.records).annotate({identifier:`Model.VariantSettings`}),VE={settings:zE.pipe(Y),headers:F(j,j).pipe(Y),body:F(j,qy).pipe(Y)},HE=P({tools:N,input:I(j),output:I(j),temperature:N.pipe(Y)}).annotate({identifier:`Model.Capabilities`}).pipe(NT(()=>({default:()=>({tools:!0,input:[`text`,`image`],output:[`text`]})}))),UE=P({tier:P({type:B(`context`),size:U}).pipe(Y),input:NE,output:NE,cache:P({read:NE,write:NE})}).annotate({identifier:`Model.Cost`}),WE=P({id:FE,...VE,settings:BE.pipe(Y)}).annotate({identifier:`Model.Variant`});P({id:PE,modelID:PE,providerID:xE,canonical:xE.pipe(Y),type:RE.pipe(Y),family:LE.pipe(Y),name:j,compatibility:yE.pipe(Y),package:SE.pipe(Y),...VE,capabilities:HE,variants:I(WE),time:P({released:H}),cost:I(UE),status:R([`alpha`,`beta`,`deprecated`,`active`]),enabled:N,limit:P({context:U,input:U.pipe(Y),output:U})}).annotate({identifier:`Model.Info`}).pipe(NT(()=>({default:(e,t)=>({id:t,modelID:t,providerID:e,name:t,capabilities:HE.default(),variants:[],time:{released:0},cost:[],status:`active`,enabled:!0,limit:{context:2e5,output:32e3}})})));const GE=j.check(xb(`ses`)).pipe(z(`SessionID`),E({identifier:`Session.ID`}),NT(e=>({create:()=>e.make(`ses_`+zT())}))),KE=j.check(xb(`per`)).pipe(z(`Permission.ID`),E({identifier:`Permission.ID`}),NT(e=>({create:t=>e.make(t??`per_`+RT())}))),qE=L([P({type:k(`tool`),messageID:j,id:j})]).annotate({identifier:`Permission.Source`}),JE=P({id:KE,sessionID:GE,action:j,resources:I(j),save:I(j).pipe(Y),metadata:F(j,A).pipe(Y),source:qE.pipe(Y),message:j.pipe(Y)}).annotate({identifier:`Permission.Request`}),YE=R([`once`,`always`,`reject`]).annotate({identifier:`Permission.Reply`});JT(Z({type:`permission.asked`,schema:JE.fields}),Z({type:`permission.replied`,schema:{sessionID:GE,requestID:KE,reply:YE}}));const XE=I(P({action:j,resource:j,effect:R([`allow`,`deny`,`ask`]).annotate({identifier:`Permission.Effect`})}).annotate({identifier:`Permission.Rule`})).annotate({identifier:`Permission.Ruleset`}),ZE=Z({type:`agent.updated`,schema:{}}),QE=j.pipe(z(`Agent.ID`),E({identifier:`Agent.ID`})),$E=j.pipe(z(`Agent.Name`)),eD=j.annotate({identifier:`Agent.Color`});P({id:QE,name:$E,model:IE.pipe(Y),request:jE,system:j.pipe(Y),description:j.pipe(Y),mode:R([`subagent`,`primary`,`all`]),hidden:N,color:eD.pipe(Y),steps:q.pipe(Y),permissions:XE}).annotate({identifier:`Agent.Info`}).pipe(NT(()=>({default:e=>({id:e,name:$E.make(e),request:{settings:{},headers:{},body:{}},mode:`primary`,hidden:!1,permissions:[{action:`*`,resource:`*`,effect:`allow`},{action:`read`,resource:`*.env`,effect:`ask`},{action:`read`,resource:`*.env.*`,effect:`ask`},{action:`read`,resource:`*.env.example`,effect:`allow`}]})}))),JT(ZE);const tD=Z({type:`command.updated`,schema:{}});P({name:j,description:j.pipe(Y)}).annotate({identifier:`Command.Info`}),JT(tD);const nD=P({providerID:xE.check(yb(/^[^/#]+$/u)),model:PE.check(yb(/^[^#]+$/u)),variant:FE.check(yb(/^[^#]+$/u)).pipe(Y)}),rD=L([j.check(yb(/^[^/#]+\/[^#]+(?:#[^#]+)?$/u)),nD]).pipe(lb(nD,{decode:T(e=>typeof e==`string`?iD(e):e),encode:hh({strict:!1})})).annotate({identifier:`Config.ModelSelection`});function iD(e){let t=IE.parse(e);return{providerID:t.providerID,model:t.id,...t.variant?{variant:t.variant}:{}}}const aD=Qy(P(kE.schema.fields),[F(j,nb(cx))]).annotate({identifier:`Config.Provider.Settings`}),oD=Qy(P(zE.schema.fields),[F(j,nb(cx))]).annotate({identifier:`Config.Model.Settings`}),sD=F(j,cx),cD={settings:aD.pipe(Y),headers:F(j,j).pipe(Y),body:sD.pipe(Y)},lD={settings:oD.pipe(Y),headers:F(j,j).pipe(Y),body:sD.pipe(Y)};var uD=class extends W(`Config.Provider.Request`)({headers:cD.headers,body:cD.body}){},dD=class extends W(`Config.Model.Cost.Cache`)({read:NE.pipe(Y),write:NE.pipe(Y)}){},fD=class extends W(`Config.Model.Cost`)({tier:P({type:k(`context`),size:U}).pipe(Y),input:NE,output:NE,cache:dD.pipe(Y)}){},pD=class extends W(`Config.Model.Limit`)({context:U.pipe(Y),input:U.pipe(Y),output:U.pipe(Y)}){};const mD=L([P({supported:k(!1)}),P({supported:k(!0),toggle:N.pipe(Y),effort:j.pipe(I,Y),budget:P({min:U.pipe(Y),max:U.pipe(Y)}).pipe(Y)})]).annotate({identifier:`Config.Model.Reasoning`});var hD=class extends W(`Config.Model`)({modelID:PE.pipe(Y),type:RE.pipe(Y),family:LE.pipe(Y),name:j.pipe(Y),releaseDate:j.check(yb(/^\d{4}-\d{2}(-\d{2})?$/u)).annotate({description:`Release date as YYYY-MM-DD or YYYY-MM`}).pipe(Y),compatibility:yE.pipe(Y),package:j.pipe(Y),...lD,capabilities:HE.mapFields(e=>({tools:Y(e.tools),input:Y(e.input),output:Y(e.output),temperature:e.temperature,reasoning:mD.pipe(Y)})).annotate({identifier:`Config.Model.Capabilities`}).pipe(Y),variants:P({id:FE,...lD,settings:Qy(P(vy(oD.schema.fields,[`cache`])),oD.records).annotate({identifier:`Config.Model.VariantSettings`}).pipe(Y)}).pipe(I,Y),cost:L([fD,fD.pipe(I)]).pipe(Y),disabled:N.pipe(Y),limit:pD.pipe(Y)}){},gD=class extends W(`Config.Provider`)({canonical:xE.pipe(Y),name:j.pipe(Y),env:j.pipe(I,Y),package:j.pipe(Y),compatibility:bE.pipe(Y),...cD,models:F(j,hD).pipe(Y)}){};const _D=j.check(yb(/^#[0-9a-fA-F]{6}$/u));var vD=class extends W(`Config.Agent`)({model:rD.pipe(Y),request:uD.pipe(Y),system:j.pipe(Y),description:j.pipe(Y),mode:R([`subagent`,`primary`,`all`]).pipe(Y),hidden:N.pipe(Y),color:_D.pipe(sb(()=>Zd),Y),steps:q.pipe(Y),disabled:N.pipe(Y),permissions:XE.pipe(Y)}){},yD=class extends W(`Config.Media.Image`)({auto_resize:N.pipe(Y),max_width:q.pipe(Y),max_height:q.pipe(Y),max_base64_bytes:q.pipe(Y)}){},bD=class extends W(`Config.Media`)({image:yD.pipe(Y)}){},xD=class extends W(`Config.Compaction.Keep`)({tokens:J.pipe(Y)}){},SD=class extends W(`Config.Compaction`)({auto:N.pipe(Y),keep:xD.pipe(Y),buffer:J.pipe(Y)}){},CD=class extends W(`Config.Command`)({template:j,description:j.pipe(Y),agent:j.pipe(Y),model:rD.pipe(Y),subagent:N.pipe(Y),subtask:N.annotate({description:`Deprecated alias for subagent.`}).pipe(Y)}){};const wD=R([`allow`,`deny`]),TD=P({action:R([`provider.use`,`tool.use`,`integration.use`]),resource:j,effect:wD});var ED=class extends W(`ConfigExperimental.Info`)({portable_shell_scanner:N.pipe(Y).annotate({description:`Enable the experimental portable shell permission scanner. Defaults to false.`}),todo:N.pipe(Y).annotate({description:`Enable the experimental todowrite tool. Defaults to false.`}),background_compaction:N.pipe(Y).annotate({description:`Enable experimental background compaction: summarize the conversation in the background as it nears the compaction threshold, so automatic compaction does not wait for the summary. Background summaries that are never used still cost tokens. Defaults to false.`}),media_blob:N.pipe(Y).annotate({description:`Store new session media once in a deduplicated blob table instead of inline in every message row. Defaults to false.`}),image_generate:L([N,P({model:rD.pipe(Y).annotate({description:`Default model for the image_generate tool when the agent doesn't choose one, as providerID/modelID. Falls back to automatic selection when it isn't available.`})})]).pipe(Y).annotate({description:`Enable the experimental image_generate tool, offered while a connected provider has an image model. Set to true, or to an object with an optional default model. Defaults to false.`}),schedules:N.pipe(Y).annotate({description:`Enable experimental scheduled tasks that wake a session with a prompt. Defaults to false.`}),subagent_depth:J.pipe(Y).annotate({description:`Maximum subagent nesting depth. Defaults to 1.`}),location_idle_timeout:L([Zb,k(!1)]).pipe(Y).annotate({description:`How long a location can go without session activity before its services are unloaded. Running sessions and background jobs keep a location loaded. Set to false to never unload (default: "60 minutes")`}),policies:TD.pipe(I,Y).annotate({description:`Deprecated: use top-level policies. Ordered policies controlling access to configured resources`})}){};const DD=L([N,F(j,class extends W(`Config.Formatter.Entry`)({disabled:N.pipe(Y),command:j.pipe(I,Y),environment:F(j,j).pipe(Y),extensions:j.pipe(I,Y)}){})]),OD=L([N,F(j,L([P({disabled:k(!0)}),class extends W(`Config.LSP.Server`)({command:j.pipe(I),extensions:j.pipe(I,Y),disabled:N.pipe(Y),env:F(j,j).pipe(Y),initialization:F(j,A).pipe(Y)}){}]))]);var kD=class extends W(`Mcp.TimeoutConfig`)({startup:q.pipe(Y).annotate({description:`Maximum time in milliseconds to establish and initialize the MCP server.`}),catalog:q.pipe(Y).annotate({description:`Maximum time in milliseconds to wait for MCP discovery requests such as tools/list and prompts/list.`}),execution:q.pipe(Y).annotate({description:`Maximum time in milliseconds to wait for MCP tool and prompt execution.`})}){};const AD=R([`legacy`,`auto`,`2026-07-28`]).annotate({identifier:`Mcp.Protocol`,description:`MCP protocol negotiation. "legacy" (default) opens with the initialize handshake and speaks protocol revisions up to 2025-11-25. "auto" probes for the 2026-07-28 revision and falls back to legacy when the server does not support it. "2026-07-28" requires that revision and fails otherwise.`});var jD=class extends W(`Mcp.LocalConfig`)({type:k(`local`),command:j.pipe(I),cwd:j.pipe(Y).annotate({description:`Working directory for the MCP server process. Relative paths resolve from the workspace directory.`}),environment:F(j,j).pipe(Y),disabled:N.pipe(Y),codemode:N.pipe(Y).annotate({description:`Expose this server's tools through Code Mode. Defaults to true.`}),timeout:kD.pipe(Y),protocol:AD.pipe(Y)}){},MD=class extends W(`Mcp.OAuthConfig`)({client_id:j.pipe(Y),client_secret:j.pipe(Y),scope:j.pipe(Y),callback_port:U.check(Ab({minimum:1,maximum:65535})).pipe(Y),redirect_uri:j.pipe(Y),auth_server_metadata_url:j.pipe(Y).annotate({description:`URL of the OAuth or OpenID Connect authorization server metadata document. Set when the MCP server does not publish protected resource metadata that names its authorization server.`})}){};const ND=L([jD,class extends W(`Mcp.RemoteConfig`)({type:k(`remote`),url:j,headers:F(j,j).pipe(Y),oauth:L([MD,k(!1)]).pipe(Y),disabled:N.pipe(Y),codemode:N.pipe(Y).annotate({description:`Expose this server's tools through Code Mode. Defaults to true.`}),timeout:kD.pipe(Y),protocol:AD.pipe(Y)}){}]).pipe(V(`type`));P({name:j,status:L([P({status:k(`connected`)}).annotate({identifier:`Mcp.Status.Connected`}),P({status:k(`pending`)}).annotate({identifier:`Mcp.Status.Pending`}),P({status:k(`disabled`)}).annotate({identifier:`Mcp.Status.Disabled`}),P({status:k(`failed`),error:j}).annotate({identifier:`Mcp.Status.Failed`}),P({status:k(`needs_auth`),error:j}).annotate({identifier:`Mcp.Status.NeedsAuth`})]).pipe(V(`status`)),title:Y(j),integrationID:Y(YT)}).annotate({identifier:`Mcp.Server`});const PD=P({server:j,name:j,uri:j,description:Y(j),mimeType:Y(j)}).annotate({identifier:`Mcp.Resource`}),FD=P({server:j,name:j,uriTemplate:j,description:Y(j),mimeType:Y(j)}).annotate({identifier:`Mcp.ResourceTemplate`});P({resources:I(PD),templates:I(FD)}).annotate({identifier:`Mcp.ResourceCatalog`}),P({server:j,uri:j,contents:I(L([P({type:k(`text`),uri:j,text:j,mimeType:Y(j)}),P({type:k(`blob`),uri:j,blob:j,mimeType:Y(j)})]).pipe(V(`type`),E({identifier:`Mcp.ResourceContentPart`})))}).annotate({identifier:`Mcp.ResourceContent`});const ID=kD,LD=ND;var RD=class extends W(`Config.MCP`)({timeout:ID.pipe(Y),servers:F(j,LD).pipe(Y)}){};const zD=L([j,class extends W(`Config.Plugin.Entry`)({package:j,options:F(j,A).pipe(Y)}){}]).pipe(I),BD=F(j,L([j,class extends W(`Config.Reference.Git`)({repository:j,branch:j.pipe(Y),description:j.pipe(Y),hidden:N.pipe(Y)}){},class extends W(`Config.Reference.Local`)({path:j,description:j.pipe(Y),hidden:N.pipe(Y)}){}])),VD=j.pipe(z(`WebSearch.ID`),E({identifier:`WebSearch.ID`}));P({id:VD,name:j}).annotate({identifier:`WebSearch.Provider`}),P({query:j,providerID:VD.pipe(Y)}).annotate({identifier:`WebSearch.Input`});const HD=P({url:j,title:j.pipe(Y),content:j.pipe(Y),time:P({published:H.pipe(Y).annotate({description:`Publication time in milliseconds since the Unix epoch`})})}).annotate({identifier:`WebSearch.Result`});W(`WebSearch.Response`)({providerID:VD,results:I(HD)}),JT(Z({type:`websearch.updated`,schema:{}}));var UD=class extends W(`ConfigWebSearch.Info`)({provider:L([k(`random`).annotate({description:`Reuse a randomly selected provider until it is rate limited, then switch to another available provider.`}),VD])}){};const WD=L([k(!1),UD]);var GD=class extends W(`Config.ToolOutput`)({max_lines:q.pipe(Y),max_bytes:q.pipe(Y)}){},KD=class extends W(`Config.Watcher`)({ignore:j.pipe(I,Y)}){};const qD=L([N,class extends W(`Config.Warming`)({prompt:j.pipe(Y).annotate({description:`Prompt sent for keep-alive requests`}),interval:Zb.pipe(Y).annotate({description:`Idle time between keep-alive requests (default: "4 minutes")`}),duration:Zb.pipe(Y).annotate({description:`Time after the last active request to keep a session warm (default: "30 minutes")`})}){}]),JD=P({directory:Hb.pipe(ib(Pb())).annotate({description:`Parent directory for new worktrees, relative to the project's primary checkout when not absolute`})}).annotate({identifier:`Config.Worktree`});var YD=class extends W(`Config.Info`)({$schema:Y(j).annotate({description:`JSON schema reference for configuration validation`}),shell:j.pipe(Y).annotate({description:`Default shell to use for terminal and shell tool execution`}),model:rD.pipe(Y).annotate({description:`Default model to use when no session or agent model is selected`}),default_agent:j.pipe(Y).annotate({description:`Default primary agent to use when no session agent is selected`}),update:R([`disable`,`notify`,`auto`]).pipe(Y).annotate({description:`Disable updates, notify when one is available, or install updates automatically`}),share:R([`manual`,`auto`,`disabled`]).pipe(Y).annotate({description:`Control whether sessions may be shared manually, automatically, or not at all`}),enterprise:P({url:j.pipe(Y)}).pipe(Y).annotate({description:`Enterprise sharing service configuration`}),username:j.pipe(Y).annotate({description:`Username displayed in conversations and used for telemetry identity`}),timezone:j.pipe(Y).annotate({description:`IANA time zone for schedules, e.g. America/Los_Angeles. Defaults to the server's local zone`}),permissions:XE.pipe(Y).annotate({description:`Ordered tool permission rules applied to agent tool use`}),policies:TD.pipe(I,Y).annotate({description:`Ordered policies controlling access to providers, tools, and integrations`}),agents:F(j,vD).pipe(Y).annotate({description:`Named built-in agent overrides and custom agent definitions`}),snapshots:N.pipe(Y).annotate({description:`Enable snapshots used for undo and revert behavior`}),watcher:KD.pipe(Y).annotate({description:`Filesystem watcher configuration`}),formatter:DD.pipe(Y).annotate({description:`Enable built-in formatters or configure formatter overrides`}),lsp:OD.pipe(Y).annotate({description:`Enable built-in language servers or configure server overrides`}),media:bD.pipe(Y).annotate({description:`Media processing configuration`}),tool_output:GD.pipe(Y).annotate({description:`Tool output truncation thresholds`}),mcp:RD.pipe(Y).annotate({description:`MCP server configuration`}),compaction:SD.pipe(Y).annotate({description:`Conversation compaction behavior`}),skills:j.pipe(I,Y).annotate({description:`Additional paths or URLs to discover skills from`}),commands:F(j,CD).pipe(Y).annotate({description:`Named slash command definitions`}),instructions:j.pipe(I,Y).annotate({description:`Additional paths or URLs supplying ambient instructions`}),references:BD.pipe(Y).annotate({description:`Named local directories or Git repositories available as external context`}),websearch:WD.pipe(Y).annotate({description:`Web search provider selection`}),plugins:zD.pipe(Y).annotate({description:`Ordered plugin enablement directives and external package declarations`}),worktree:JD.pipe(Y).annotate({description:`Directory defaults for local worktree creation`}),warming:qD.pipe(Y).annotate({description:`Keep recently active sessions warm with transient model requests (default: false)`}),providers:F(j,gD).pipe(Y),experimental:ED.pipe(Y)}){};P({shell:tb(j)}).annotate({identifier:`Config.Patch`}),L([class extends W(`Config.Document`)({type:k(`document`),path:jT.pipe(Y),info:YD}){},class extends W(`Config.Directory`)({type:k(`directory`),path:jT}){}]).annotate({identifier:`Config.Entry`}),JT(Z({type:`config.updated`,schema:{}})),JT(Z({type:`filesystem.changed`,schema:{file:j,event:R([`add`,`change`,`unlink`])}})),P({entry:P({path:AT,type:R([`file`,`directory`])}).annotate({identifier:`FileSystem.Entry`}),line:q,offset:J,text:j,submatches:I(P({text:j,start:J,end:J}).annotate({identifier:`FileSystem.Submatch`}))}).annotate({identifier:`FileSystem.Match`}),W(`FileSystem.FindInput`)({query:j,type:R([`file`,`directory`]).pipe(Y),limit:q.pipe(Y)}),P({path:jT}).annotate({identifier:`FileSystem.Write`});const XD=R([`stop`,`length`,`tool-calls`,`content-filter`,`error`,`unknown`]);P({id:j.pipe(z(`PermissionSaved.ID`),E({identifier:`PermissionSaved.ID`}),NT(e=>({create:()=>e.make(`psv_`+RT())}))),projectID:VT,action:j,resource:j,time:P({created:PT,updated:PT})}).annotate({identifier:`PermissionSaved.Info`});const ZD=VT,QD=j.check(yb(/^[a-z][a-z0-9._-]*$/u)).annotate({identifier:`Project.Vcs`});P({id:ZD,directory:jT,canonical:jT}).annotate({identifier:`Project.Current`});const $D=P({url:Y(j),override:Y(j),color:Y(j)}).annotate({identifier:`Project.Icon`}),eO=P({start:Y(j.annotate({description:`Startup script to run when creating a new workspace (worktree)`}))}).annotate({identifier:`Project.Commands`}),tO=P({created:J,updated:J,active:J,archived:Y(J)}).annotate({identifier:`Project.Time`}),nO=P({id:ZD,canonical:jT,vcs:Y(QD),name:Y(j),icon:Y($D),commands:Y(eO),time:tO,sandboxes:I(j)}).annotate({identifier:`Project`});P({projectID:ZD,canonical:Y(jT),name:Y(j),icon:Y($D),commands:Y(eO)}).annotate({identifier:`Project.UpdateInput`}),JT(Z({type:`project.updated`,schema:nO.fields})),Hb.pipe(ib(Pb()),z(`Worktree.StrategyID`)),P({projectID:ZD,from:Y(jT),branch:Y(Hb.pipe(ib(Pb()))),directory:Y(jT).annotate({description:`Parent directory for the new worktree. Uses the project's canonical configuration, then defaults to the server's data directory under worktree/<first six project ID characters>.`}),name:Y(j)}).annotate({identifier:`Worktree.CreateInput`}),P({projectID:ZD,directory:jT,force:N}).annotate({identifier:`Worktree.RemoveInput`}),P({directory:jT}).annotate({identifier:`Worktree.Info`});const rO=P({directory:jT,strategy:Y(j)}).annotate({identifier:`Worktree.Directory`});P({directory:jT,type:R([`root`,`worktree`])}).annotate({identifier:`Worktree.ListEntry`}),ox()(`Worktree.OperationError`,{message:j,forceRequired:Y(N)}),I(rO).annotate({identifier:`Worktree.List`}),JT(Z({type:`worktree.updated`,schema:{projectID:ZD}}),X({type:`worktree.resolved`,durable:{aggregate:`projectID`,version:1},schema:{projectID:ZD,directory:jT,previous:ZD,adopted:Y(I(ZD))}})),JT(Z({type:`reference.updated`,schema:{}}));const iO=L([P({type:k(`local`),path:jT,description:j.pipe(Y),hidden:N.pipe(Y)}).annotate({identifier:`Reference.LocalSource`}),P({type:k(`git`),repository:j,branch:j.pipe(Y),description:j.pipe(Y),hidden:N.pipe(Y)}).annotate({identifier:`Reference.GitSource`})]).pipe(V(`type`)).annotate({identifier:`Reference.Source`});P({name:j,path:jT,description:j.pipe(Y),hidden:N.pipe(Y),source:iO}).annotate({identifier:`Reference.Info`});function aO(e){let t=Object.values(e.methods).flatMap(e=>Object.keys(e.errors??{})).find(e=>e.startsWith(`rpc.`));if(t)throw Error(`RPC error names starting with "rpc." are reserved: ${t}`);return e}const oO=F(j,cx).annotate({identifier:`Session.Metadata`}),sO=j.pipe(z(`Skill.ID`),E({identifier:`Skill.ID`})),cO=j.pipe(z(`Skill.Name`),E({identifier:`Skill.Name`})),lO=P({type:B(`directory`),path:jT}).annotate({identifier:`Skill.DirectorySource`}),uO=P({type:B(`url`),url:j}).annotate({identifier:`Skill.UrlSource`}),dO=P({id:sO,name:cO,description:j.pipe(Y),autoinvoke:N.pipe(Y),path:jT,content:j}).annotate({identifier:`Skill.Info`});JT(Z({type:`skill.updated`,schema:{}}));const fO=P({type:B(`embedded`),skill:rb(()=>dO)}).annotate({identifier:`Skill.EmbeddedSource`});Object.assign(L([lO,uO,fO]).pipe(V(`type`),E({identifier:`Skill.Source`})),{equals:(e,t)=>e.type===t.type?e.type===`directory`&&t.type===`directory`?e.path===t.path:e.type===`url`&&t.type===`url`?e.url===t.url:e.type===`embedded`&&t.type===`embedded`&&e.skill.id===t.skill.id:!1,key:e=>e.type===`directory`?`directory:${e.path}`:e.type===`url`?`url:${e.url}`:`embedded:${e.skill.id}`});const pO=P({start:H,end:H,text:j}).annotate({identifier:`Prompt.Mention`}),mO=L([P({type:k(`inline`)}),P({type:k(`uri`),uri:j})]).pipe(V(`type`)).annotate({identifier:`Prompt.FileSource`}),hO=P({data:j.check(gb(e=>e.length%4==0&&/^[A-Za-z0-9+/]*={0,2}$/u.test(e),yb(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u).annotations)).annotate({identifier:`Prompt.Base64`}),mime:j,source:mO,name:j.pipe(Y),description:j.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`Prompt.FileAttachment`}).pipe(NT(e=>({create:t=>e.make({data:t.data,mime:t.mime,source:t.source,name:t.name,description:t.description,mention:t.mention})}))),gO=j.check(yb(/^media:[0-9a-f]{64}$/)).annotate({identifier:`Prompt.MediaRef`}),{data:_O,...vO}=hO.fields,yO=L([hO,P({...vO,uri:gO,bytes:U.pipe(Y),width:U.pipe(Y),height:U.pipe(Y)}).annotate({identifier:`Prompt.MediaFileAttachment`})]).annotate({identifier:`Prompt.Attachment`}),bO=P({name:j,mention:pO.pipe(Y)}).annotate({identifier:`Prompt.AgentAttachment`}),xO=P({id:sO,name:cO,text:j.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`Prompt.SkillAttachment`}),SO=P({text:j,files:I(hO).pipe(Y),agents:I(bO).pipe(Y),skills:I(xO).pipe(Y)}).annotate({identifier:`Prompt`}).pipe(NT(e=>({equivalence:sx(e),fromUserMessage:t=>e.make({text:t.text,...t.files===void 0?{}:{files:t.files},...t.agents===void 0?{}:{agents:t.agents},...t.skills===void 0?{}:{skills:t.skills}})}))),CO=j.check(xb(`sh_`)).pipe(z(`Shell.ID`),E({identifier:`Shell.ID`})).pipe(NT(e=>{let t=()=>e.make(`sh_`+RT());return{create:t,ascending:n=>n===void 0?t():e.make(n)}})),wO=R([`running`,`exited`,`timeout`,`killed`]),TO=P({started:H.annotate({description:`Start time in milliseconds since the Unix epoch`}),completed:Y(H).annotate({description:`Completion time in milliseconds since the Unix epoch`})}),EO=F(j,A),DO=P({id:CO,status:wO,command:j,cwd:j,shell:j,file:j,pid:Y(J),exit:Y(H),signal:Y(j),metadata:EO,time:TO}).annotate({identifier:`Shell.Info`});JT(Z({type:`shell.created`,schema:{info:DO}}),Z({type:`shell.exited`,schema:{id:CO,exit:Y(H),status:wO}}),Z({type:`shell.deleted`,schema:{id:CO}})),P({command:j,cwd:Y(j),timeout:Y(J),metadata:Y(EO)}),P({cursor:Y(J),limit:Y(J)});const OO=P({output:j,cursor:J,size:J,truncated:N}),kO=P({type:j,message:j,status:U.check(Ab({minimum:100,maximum:599})).pipe(Y),response:P({body:j}).pipe(Y),retryAfterMs:J.pipe(Y)}).annotate({identifier:`Session.StructuredError`}),AO=j.pipe(z(`Snapshot.ID`),E({identifier:`Snapshot.ID`})),jO=P({input:H,output:H,reasoning:H,cache:P({read:H,write:H})}).annotate({identifier:`TokenUsage.Info`}),MO=j.check(xb(`msg_`)).pipe(z(`Session.Message.ID`),E({identifier:`Session.Message.ID`}),NT(e=>({create:()=>e.make(`msg_`+RT()),fromEvent:t=>e.make(t.replace(/^evt_/,`msg_`))}))),NO={id:MO,metadata:F(j,A).pipe(Y),time:P({created:PT})},PO=F(j,A).annotate({identifier:`Session.Message.Native`}),FO=P({...NO,type:B(`agent-switched`),agent:QE,previous:QE.pipe(Y)}).annotate({identifier:`Session.Message.AgentSelected`}),IO=P({...NO,type:B(`model-switched`),model:IE,previous:IE.pipe(Y)}).annotate({identifier:`Session.Message.ModelSelected`}),LO=P({...NO,type:B(`location-switched`),location:UT,projectID:ZD.pipe(Y),subpath:AT.pipe(Y),previous:P({location:UT,projectID:ZD.pipe(Y),subpath:AT.pipe(Y)}).pipe(Y)}).annotate({identifier:`Session.Message.LocationSwitched`}),RO=P({...NO,text:SO.fields.text,files:SO.fields.files,agents:SO.fields.agents,skills:SO.fields.skills,type:B(`user`)}).annotate({identifier:`Session.Message.User`}),zO=P({...RO.fields,files:I(yO).pipe(Y)}).annotate({identifier:`Session.Message.MediaUser`}),BO=P({...NO,text:j,description:j.pipe(Y),type:B(`synthetic`)}).annotate({identifier:`Session.Message.Synthetic`}),VO=P({...NO,type:B(`system`),text:j,description:j.pipe(Y)}).annotate({identifier:`Session.Message.System`}),HO=P({...NO,type:B(`skill`),skill:sO,name:cO,text:j}).annotate({identifier:`Session.Message.Skill`}),UO=P({...NO,type:B(`shell`),shellID:CO,command:j,status:wO,exit:M.pipe(Y),output:OO.pipe(Y),time:P({created:PT,completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Shell`}),WO=L([P({status:B(`streaming`),input:j}).annotate({identifier:`Session.Message.ToolState.Streaming`}),P({status:B(`running`),input:F(j,A),metadata:F(j,cx)}).annotate({identifier:`Session.Message.ToolState.Running`}),P({status:B(`completed`),input:F(j,A),content:$y(FT),metadata:F(j,cx).pipe(Y)}).annotate({identifier:`Session.Message.ToolState.Completed`}),P({status:B(`error`),input:F(j,A),error:kO,content:$y(FT).pipe(Y),metadata:F(j,cx).pipe(Y)}).annotate({identifier:`Session.Message.ToolState.Error`})]).pipe(V(`status`)),GO=P({type:B(`tool`),id:j,name:j,executed:N.pipe(Y),native:PO.pipe(Y),state:WO,time:P({created:PT,ran:PT.pipe(Y),completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Assistant.Tool`}),KO=L([P({type:B(`text`),text:j,native:PO.pipe(Y)}).annotate({identifier:`Session.Message.Assistant.Text`}),P({type:B(`reasoning`),text:j,native:PO.pipe(Y),time:P({created:PT,completed:PT.pipe(Y)}).pipe(Y)}).annotate({identifier:`Session.Message.Assistant.Reasoning`}),GO]).pipe(V(`type`)),qO=Wy(KO).annotate({identifier:`Session.Message.AssistantContent.Encoded`}),JO=P({attempt:q,at:PT,error:kO}).annotate({identifier:`Session.Message.Assistant.Retry`}),YO=P({...NO,type:B(`assistant`),agent:QE,model:IE,content:KO.pipe(I),snapshot:P({start:AO.pipe(Y),end:AO.pipe(Y),files:I(AT).pipe(Y)}).pipe(Y),finish:XD.pipe(Y),rawFinish:j.pipe(Y),native:PO.pipe(Y),cost:ME.pipe(Y),tokens:jO.pipe(Y),error:kO.pipe(Y),retry:JO.pipe(Y),time:P({created:PT,streamed:PT.pipe(Y),completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Assistant`}),XO={type:B(`compaction`),...NO},ZO={cost:ME.pipe(Y),tokens:jO.pipe(Y)},QO=P({...XO,status:B(`running`),reason:R([`auto`,`manual`]),summary:j}).annotate({identifier:`Session.Message.Compaction.Running`}),$O=P({...XO,status:B(`completed`),reason:R([`auto`,`manual`]),model:IE.pipe(Y),native:PO.pipe(Y),summary:j,...ZO}).annotate({identifier:`Session.Message.Compaction.Completed`}),ek=P({...XO,status:B(`failed`),reason:R([`auto`,`manual`]),error:kO,...ZO}).annotate({identifier:`Session.Message.Compaction.Failed`}),tk=L([QO,$O,ek]).pipe(V(`status`),E({identifier:`Session.Message.Compaction`})),nk=P({...NO,type:B(`idle`),outcome:R([`succeeded`,`failed`,`interrupted`]),error:kO.pipe(Y)}).annotate({identifier:`Session.Message.Idle`}),rk=L([FO,IO,LO,RO,BO,VO,HO,UO,YO,tk,nk]).annotate({identifier:`Session.Message.Info`});L([FO,IO,LO,zO,BO,VO,HO,UO,YO,tk,nk]).annotate({identifier:`Session.Message.MediaInfo`});const ik=P({file:j,patch:j,additions:J,deletions:J,status:R([`added`,`deleted`,`modified`]),more:k(!0).pipe(Y)}).annotate({identifier:`FileDiff.Info`});P({file:j.pipe(Y),patch:j.pipe(Y),additions:H,deletions:H,status:R([`added`,`deleted`,`modified`]).pipe(Y)}).annotate({identifier:`FileDiff.LegacyInfo`});const ak=P({messageID:MO,partID:j.pipe(Y),snapshot:AO.pipe(Y),files:I(ik).pipe(Y)}).annotate({identifier:`Session.Revert`}),ok=P({path:j,status:R([`added`,`modified`,`deleted`]),additions:H,deletions:H,patch:j}),sk=P({messageID:MO,partID:j.pipe(Y),snapshot:j.pipe(Y),diff:j.pipe(Y),files:I(ok).pipe(Y)}).annotate({identifier:`Session.RevertV1`});L([ak.pipe(lb(P({source:B(`current`),revert:Uy(ak)}),Nh({decode:e=>({source:`current`,revert:e}),encode:e=>e.revert}))),sk.pipe(lb(P({source:B(`legacy`),revert:Uy(sk)}),Nh({decode:e=>({source:`legacy`,revert:e}),encode:e=>e.revert})))]).pipe(V(`source`),lb(Uy(ak),Nh({decode:e=>e.source===`current`?e.revert:ak.make({messageID:e.revert.messageID,partID:e.revert.partID,snapshot:e.revert.snapshot?AO.make(e.revert.snapshot):void 0,files:e.revert.files?.map(e=>({file:e.path,status:e.status,additions:e.additions,deletions:e.deletions,patch:e.patch}))}),encode:e=>({source:`current`,revert:e})})),E({identifier:`Session.Revert.Persisted`}));const ck=j.check(yb(/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._/-]*$/u)).pipe(z(`Instruction.Key`),E({identifier:`Instruction.Key`})),lk=j.check(yb(/^[a-f0-9]{64}$/u)).pipe(z(`Instruction.Hash`),E({identifier:`Instruction.Hash`})),uk=F(ck,lk),dk=k(`removed`);dk.make(`removed`);const fk=F(j,L([lk,dk])),pk=I(P({...P({key:j.check(yb(/^[a-z0-9][a-z0-9._-]*$/u)).annotate({identifier:`InstructionEntry.Key`,description:`Instruction entry key (lowercase alphanumerics plus . _ -)`}),value:cx.annotate({description:`JSON value attached to the session's instructions`})}).annotate({identifier:`InstructionEntry.Info`}).fields,removed:N})).annotate({identifier:`InstructionEntry.Snapshot`});ox()(`InstructionEntryValueTooLargeError`,{actualBytes:U,maxBytes:U,message:j},{httpApiStatus:413});const mk=R([`steer`,`queue`]).annotate({identifier:`Session.Inbox.Delivery`}),hk=P({...SO.fields,metadata:F(j,A).pipe(Y)}).annotate({identifier:`Session.Inbox.UserPayload`}),gk=P({...hk.fields,files:I(yO).pipe(Y)}).annotate({identifier:`Session.Inbox.MediaUserPayload`}),_k=P({text:j,description:j.pipe(Y),metadata:F(j,A).pipe(Y)}).annotate({identifier:`Session.Inbox.SyntheticPayload`}),vk=P({}).annotate({identifier:`Session.Inbox.CompactionPayload`}),yk=P({location:UT,projectID:ZD,subpath:AT.pipe(Y)}).annotate({identifier:`Session.Inbox.MovePayload`}),bk=P({type:B(`user`),payload:hk,delivery:mk}),xk=P({type:B(`synthetic`),payload:_k,delivery:mk}),Sk=P({type:B(`compaction`),payload:vk,delivery:mk}),Ck=P({type:B(`move`),payload:yk,delivery:mk}),wk=L([bk,xk,Sk,Ck]).pipe(V(`type`),E({identifier:`Session.Inbox.Item`})),Tk={id:MO,sessionID:GE,time:P({created:PT})},Ek=P({...Tk,...bk.fields}).annotate({identifier:`Session.Inbox.User`}),Dk=P({...Ek.fields,payload:gk}).annotate({identifier:`Session.Inbox.MediaUser`}),Ok=P({...Tk,...xk.fields}).annotate({identifier:`Session.Inbox.Synthetic`}),kk=P({...Tk,...Sk.fields}).annotate({identifier:`Session.Inbox.Compaction`}),Ak=P({...Tk,...Ck.fields}).annotate({identifier:`Session.Inbox.Move`});L([Ek,Ok,kk,Ak]).pipe(V(`type`),E({identifier:`Session.Inbox.Info`})),L([Dk,Ok,kk,Ak]).pipe(V(`type`),E({identifier:`Session.Inbox.MediaInfo`}));const jk=L([P({type:k(`before`),messageID:MO}),P({type:k(`through`),messageID:MO})]).annotate({identifier:`Session.ForkBoundary`}),Q={sessionID:GE},$={durable:{aggregate:`sessionID`,version:1}},Mk=X({type:`session.created`,...$,schema:{...Q,projectID:ZD,location:UT,subpath:AT.pipe(Y),parentID:GE.pipe(Y),slug:j,title:j.pipe(Y),agent:QE.pipe(Y),model:IE.pipe(Y),metadata:oO.pipe(Y),permissions:XE.pipe(Y),version:j}}),Nk=X({type:`session.agent.selected`,...$,schema:{...Q,agent:QE,previous:QE.pipe(Y)}}),Pk=X({type:`session.model.selected`,...$,schema:{...Q,model:IE,previous:IE.pipe(Y)}}),Fk=X({type:`session.moved`,...$,schema:{...Q,...yk.fields}}),Ik=X({type:`session.renamed`,...$,schema:{...Q,title:j}}),Lk=X({type:`session.metadata.updated`,...$,schema:{...Q,metadata:oO}}),Rk=X({type:`session.permissions`,...$,schema:{...Q,permissions:XE}}),zk=X({type:`session.viewed`,...$,schema:{...Q,idle:H}}),Bk=X({type:`session.archived`,...$,schema:Q}),Vk=X({type:`session.unarchived`,...$,schema:Q}),Hk=X({type:`session.message.content.updated`,...$,schema:{...Q,messageID:MO,content:I(qO)}}),Uk=X({type:`session.usage.recorded`,...$,schema:{...Q,source:R([`title`,`compaction`]),cost:ME,tokens:jO}}),Wk=Z({type:`session.usage.updated`,schema:{...Q,cost:ME,tokens:jO}}),Gk=X({type:`session.deleted`,durable:{aggregate:`sessionID`,version:2},schema:Q}),Kk=X({type:`session.forked`,durable:{aggregate:`sessionID`,version:2},schema:{...Q,parentID:GE,boundary:jk,instructions:uk.pipe(Y),instructionEntries:pk.pipe(Y)}}),qk={...Q,inboxID:MO},Jk=X({type:`session.inbox.delivered`,...$,schema:qk}),Yk=X({type:`session.inbox.enqueued`,...$,schema:{...qk,item:wk}}),Xk=X({type:`session.inbox.cancelled`,...$,schema:qk}),Zk=X({type:`session.inbox.delivery.changed`,...$,schema:{...qk,delivery:mk}});var Qk;(function(e){e.Started=X({type:`session.execution.started`,...$,schema:Q}),e.Succeeded=X({type:`session.execution.succeeded`,...$,schema:Q}),e.Failed=X({type:`session.execution.failed`,...$,schema:{...Q,error:kO}}),e.Interrupted=X({type:`session.execution.interrupted`,...$,schema:{...Q,reason:R([`user`,`shutdown`,`superseded`,`inactivity`])}})})(Qk||={});const $k=X({type:`session.instructions.updated`,durable:{aggregate:`sessionID`,version:2},schema:{...Q,delta:fk,text:j.pipe(Y)}}),eA=X({type:`session.synthetic`,...$,schema:{...Q,text:j,description:j.pipe(Y),metadata:F(j,A).pipe(Y)}});var tA;(function(e){e.Activated=X({type:`session.skill.activated`,...$,schema:{...Q,id:sO,name:cO,text:j}})})(tA||={});var nA;(function(e){e.Started=X({type:`session.shell.started`,...$,schema:{...Q,shell:DO}}),e.Ended=X({type:`session.shell.ended`,...$,schema:{...Q,shell:DO,output:OO}})})(nA||={});var rA;(function(e){e.Started=X({type:`session.step.started`,...$,schema:{...Q,assistantMessageID:MO,agent:QE,model:IE,snapshot:AO.pipe(Y),started:J}}),e.Streamed=X({type:`session.step.streamed`,...$,schema:{...Q,assistantMessageID:MO}}),e.Ended=X({type:`session.step.ended`,...$,schema:{...Q,assistantMessageID:MO,finish:XD,rawFinish:j.pipe(Y),native:PO.pipe(Y),cost:ME,tokens:jO,snapshot:AO.pipe(Y),files:I(AT).pipe(Y)}}),e.Failed=X({type:`session.step.failed`,...$,schema:{...Q,assistantMessageID:MO,error:kO,finish:R([`content-filter`]).pipe(Y),rawFinish:j.pipe(Y),native:PO.pipe(Y),cost:ME.pipe(Y),tokens:jO.pipe(Y),snapshot:AO.pipe(Y),files:I(AT).pipe(Y)}})})(rA||={});var iA;(function(e){e.Started=X({type:`session.text.started`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J}}),e.Delta=Z({type:`session.text.delta`,schema:{...Q,assistantMessageID:MO,ordinal:J,delta:j}}),e.Ended=X({type:`session.text.ended`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,text:j,native:PO.pipe(Y)}})})(iA||={});var aA;(function(e){e.Started=X({type:`session.reasoning.started`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,native:PO.pipe(Y)}}),e.Delta=Z({type:`session.reasoning.delta`,schema:{...Q,assistantMessageID:MO,ordinal:J,delta:j}}),e.Ended=X({type:`session.reasoning.ended`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,text:j,native:PO.pipe(Y)}})})(aA||={});var oA;(function(e){let t={...Q,assistantMessageID:MO,id:j};(function(e){e.Started=X({type:`session.tool.input.started`,...$,schema:{...t,name:j}}),e.Delta=Z({type:`session.tool.input.delta`,schema:{...t,delta:j}}),e.Ended=X({type:`session.tool.input.ended`,...$,schema:{...t,text:j}})})(e.Input||={}),e.Called=X({type:`session.tool.called`,...$,schema:{...t,input:F(j,A),executed:N,native:PO.pipe(Y)}}),e.Progress=Z({type:`session.tool.progress`,schema:{...t,metadata:F(j,cx)}}),e.Success=X({type:`session.tool.success`,durable:{aggregate:`sessionID`,version:2},schema:{...t,content:$y(FT),metadata:F(j,cx).pipe(Y),executed:N,native:PO.pipe(Y)}}),e.Failed=X({type:`session.tool.failed`,durable:{aggregate:`sessionID`,version:2},schema:{...t,error:kO,content:$y(FT).pipe(Y),metadata:F(j,cx).pipe(Y),executed:N,native:PO.pipe(Y)}})})(oA||={});const sA=X({type:`session.retry.scheduled`,...$,schema:{...Q,assistantMessageID:MO,attempt:q,at:J,error:kO}});var cA;(function(e){e.Started=X({type:`session.compaction.started`,...$,schema:{...Q,reason:R([`auto`,`manual`]),inputID:MO.pipe(Y)}}),e.Delta=Z({type:`session.compaction.delta`,schema:{...Q,text:j}}),e.Ended=X({type:`session.compaction.ended`,...$,schema:{...Q,reason:e.Started.data.fields.reason,model:$O.fields.model,native:$O.fields.native,text:j,cost:$O.fields.cost,tokens:$O.fields.tokens}}),e.Failed=X({type:`session.compaction.failed`,...$,schema:{...Q,reason:e.Started.data.fields.reason,error:kO,inputID:MO.pipe(Y),cost:ek.fields.cost,tokens:ek.fields.tokens}})})(cA||={});var lA;(function(e){e.Staged=X({type:`session.revert.staged`,...$,schema:{...Q,revert:ak}}),e.Cleared=X({type:`session.revert.cleared`,...$,schema:Q}),e.Committed=X({type:`session.revert.committed`,...$,schema:{...Q,to:MO}})})(lA||={});const uA=JT(Mk,Nk,Pk,Fk,Ik,Lk,Rk,zk,Bk,Vk,Wk,Gk,Kk,Jk,Yk,Xk,Zk,Qk.Started,Qk.Succeeded,Qk.Failed,Qk.Interrupted,$k,eA,tA.Activated,nA.Started,nA.Ended,rA.Started,rA.Streamed,rA.Ended,rA.Failed,iA.Started,iA.Delta,iA.Ended,aA.Started,aA.Delta,aA.Ended,oA.Input.Started,oA.Input.Delta,oA.Input.Ended,oA.Called,oA.Progress,oA.Success,oA.Failed,sA,cA.Started,cA.Delta,cA.Ended,cA.Failed,lA.Staged,lA.Cleared,lA.Committed),dA=JT(...uA.filter(e=>e.durability===`durable`),Uk,Hk),fA=JT(...uA.filter(e=>e.durability===`ephemeral`));L([L(dA,{mode:`oneOf`}).annotate({identifier:`Session.Event.Durable`}).pipe(V(`type`)),...fA],{mode:`oneOf`}).pipe(V(`type`));const pA=GE,mA=oO,hA=jk,gA=P({id:pA,parentID:pA.pipe(Y),fork:P({sessionID:pA,boundary:hA}).pipe(Y),projectID:ZD,agent:QE.pipe(Y),model:IE.pipe(Y),cost:ME,tokens:jO,outcome:R([`succeeded`,`failed`,`interrupted`]).pipe(Y),time:P({created:PT,updated:PT,idle:PT.pipe(Y),viewed:PT.pipe(Y),archived:PT.pipe(Y)}),title:j.pipe(Y),location:UT,subpath:AT.pipe(Y),metadata:mA.pipe(Y),permissions:XE.pipe(Y),revert:ak.pipe(Y)}).annotate({identifier:`Session.Info`}),_A=P({id:pA,time:H,direction:R([`previous`,`next`])}).annotate({identifier:`Session.ListAnchor`}),vA={order:R([`asc`,`desc`]).pipe(O).annotate({description:`Session order for the first page. Use desc for newest first or asc for oldest first.`}),search:j.pipe(O),parentID:L([pA,Jy.pipe(db(k(`null`),{decode:T(()=>null),encode:T(()=>`null`)}))]).annotate({description:`Filter by parent session. Use null to return only root sessions.`}).pipe(O),archived:R([`true`,`false`]).pipe(lb(N,{decode:T(e=>e===`true`),encode:T(e=>e?`true`:`false`)})).annotate({description:`Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.`}).pipe(O)};P({...vA,directory:jT.pipe(O),project:ZD.pipe(O),subpath:AT.pipe(O)}).annotate({identifier:`Session.ListFilter`});const yA=Bb(L([P({...vA,directory:jT,anchor:_A}),P({...vA,project:ZD,subpath:AT.pipe(O),anchor:_A}),P({...vA,anchor:_A})])),bA=By(yA),xA=Py(yA);j.pipe(z(`SessionsCursor`),E({identifier:`SessionsCursor`,description:`Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response.`}),NT(e=>{let t=Vv(e);return{make:e=>t(oh(bA(e))),parse:e=>Qd(()=>{let t=ch(e);return ai(t)?S(`Invalid cursor`):xA(t.success).pipe(xf(()=>`Invalid cursor`))})}}));const SA=P({current:Y(j),default:Y(j)}).annotate({identifier:`Vcs.Branch`});P({provider:Y(j),branch:SA}).annotate({identifier:`Vcs.Info`}),I(j).annotate({identifier:`Vcs.BranchList`}),P({name:j,ref:j,source:R([`reflog`,`default`])}).annotate({identifier:`Vcs.Base`}),R([`working`,`branch`,`committed`]).annotate({identifier:`Vcs.Mode`}),R([`files`,`folders`]).annotate({identifier:`Vcs.Untracked`}),P({file:j,additions:J,deletions:J,status:R([`added`,`deleted`,`modified`])}).annotate({identifier:`Vcs.FileStatus`});const CA=P({date:j,steps:J}).annotate({identifier:`SessionStats.Activity`}),wA=P({model:IE,steps:J,tokens:jO,cost:ME}).annotate({identifier:`SessionStats.ModelUsage`}),TA=P({name:j,calls:J,succeeded:J,failed:J,unfinished:J,durationP50:H.pipe(Y)}).annotate({identifier:`SessionStats.ToolUsage`});R([`none`,`summary`,`detail`]);const EA=P({calls:J,succeeded:J,failed:J,unfinished:J}).annotate({identifier:`SessionStats.ToolTotals`}),DA=L([P({mode:k(`none`)}),P({mode:k(`summary`),totals:EA}),P({mode:k(`detail`),totals:EA,usage:I(TA)})]).annotate({identifier:`SessionStats.Tools`});P({range:P({from:PT,to:PT}),sessions:J,subagents:J,prompts:J,steps:J,tokens:jO,cost:ME,tools:DA,activeDays:J,streak:J,activity:I(CA),models:I(wA)}).annotate({identifier:`SessionStats.Info`}),P({info:gA,messages:I(rk)}).annotate({identifier:`SessionTransfer.Data`});const OA=j.check(xb(`pty`)).pipe(z(`PtyID`),E({identifier:`Pty.ID`})).pipe(NT(e=>{let t=()=>e.make(`pty_`+RT());return{create:t,ascending:n=>n===void 0?t():e.make(n)}})),kA=P({id:OA,title:j,command:j,args:I(j),cwd:j,status:R([`running`,`exited`]),pid:J,exitCode:Y(J)}).annotate({identifier:`Pty`});JT(Z({type:`pty.created`,schema:{info:kA}}),Z({type:`pty.updated`,schema:{info:kA}}),Z({type:`pty.exited`,schema:{id:OA,exitCode:J}}),Z({type:`pty.deleted`,schema:{id:OA}})),P({command:Y(j),args:Y(I(j)),cwd:Y(j),title:Y(j),env:Y(F(j,j))}),P({title:Y(j),size:Y(P({rows:q,cols:q}))});const AA=P({...kA.fields,sessionID:pA,foregroundProcess:tb(j),size:P({cols:q,rows:q}),output:P({head:J,tail:J})}).annotate({identifier:`PersistentPty.Info`});P({directory:j,instanceID:j,ticket:j,expiresAt:M}).annotate({identifier:`PersistentPty.Handoff`}),P({command:Y(j),args:I(j),cwd:Y(j),title:j,env:F(j,j),size:Y(P({cols:q,rows:q}))}).annotate({identifier:`PersistentPty.CreateInput`}),P({attachmentID:Y(j),size:P({cols:q,rows:q})}).annotate({identifier:`PersistentPty.UpdateInput`});const jA=P({info:AA,text:j,checkpoint:Wb,cursor:P({x:J,y:J})}).annotate({identifier:`PersistentPty.Snapshot`});q.check(kb(65535)).annotate({identifier:`PersistentPty.ReadLines`}),P({ptyID:OA,title:j,cwd:j,foregroundProcess:tb(j),screen:P({text:j,cols:q,rows:q,cursor:jA.fields.cursor})}).annotate({identifier:`PersistentPty.ReadResult`}),JT(Z({type:`persistent-pty.added`,schema:{sessionID:pA,terminal:AA}}),Z({type:`persistent-pty.removed`,schema:{sessionID:pA,ptyID:OA}})),P({ticket:j,expires_in:q}).annotate({identifier:`PtyTicket.ConnectToken`});const MA=P({label:j.annotate({description:`Display text (1-5 words, concise)`}),description:j.annotate({description:`Explanation of choice`})});P({question:j.annotate({description:`Complete question`}),header:j.annotate({description:`Very short label (max 30 chars)`}),options:I(MA).annotate({description:`Available choices`}),multiple:N.pipe(Y).annotate({description:`Allow selecting multiple choices`})}).annotate({identifier:`Question.Prompt`}),I(j).annotate({identifier:`Question.Answer`});const NA=P({workspaceID:HT,status:R([`connected`,`connecting`,`disconnected`,`error`])}).annotate({identifier:`WorkspaceEvent.ConnectionStatus`});JT(Z({type:`workspace.ready`,schema:{name:j}}),Z({type:`workspace.failed`,schema:{message:j}}),Z({type:`workspace.status`,schema:NA.fields})),P({destroyed:N.annotate({description:`True when this request transitioned the workspace from existing to destroyed.`})}).annotate({identifier:`WorkspaceDestroyResult`,description:`Reports whether this request destroyed an existing workspace.`});const PA=P({uri:j,name:j.pipe(Y),description:j.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`PromptInput.FileAttachment`}),FA=P({id:sO,mention:pO.pipe(Y)}).annotate({identifier:`PromptInput.SkillAttachment`});P({text:j,files:I(PA).pipe(Y),agents:I(bO).pipe(Y),skills:I(FA).pipe(Y)}).annotate({identifier:`PromptInput`});const IA=R([`context-overflow`,`payload-too-large`]);var LA=class extends W(`AI.HttpContext`)({url:j,status:U.check(Ab({minimum:100,maximum:599})),headers:F(j,j)}){},RA=class extends W(`AI.HttpRateLimitDetails`)({retryAfterMs:O(J),limit:O(F(j,j)),remaining:O(F(j,j)),reset:O(F(j,j))}){};const zA={message:j,body:O(j),http:O(LA),cause:O(Rb({includeStack:!0}))};var BA=class extends ox(`AI.Error.InvalidRequest`)(`InvalidRequest`,{...zA,parameter:O(j),classification:O(IA)}){},VA=class extends ox(`AI.Error.UnsupportedOperation`)(`UnsupportedOperation`,{...zA,operation:j,provider:O(rT),route:O(tT)}){};ox(`AI.Error.ProviderConfiguration`)(`ProviderConfiguration`,{provider:rT,message:j});var HA=class extends ox(`AI.Error.NoRoute`)(`NoRoute`,{...zA,route:tT,provider:rT,model:nT}){},UA=class extends ox(`AI.Error.Authentication`)(`Authentication`,zA){},WA=class extends ox(`AI.Error.RateLimit`)(`RateLimit`,{...zA,retryAfterMs:O(J),rateLimit:O(RA)}){},GA=class extends ox(`AI.Error.QuotaExceeded`)(`QuotaExceeded`,{...zA,retryAfterMs:O(J)}){},KA=class extends ox(`AI.Error.ContentPolicy`)(`ContentPolicy`,zA){},qA=class extends ox(`AI.Error.ProviderInternal`)(`ProviderInternal`,{...zA,retryAfterMs:O(J)}){};const JA=R([`http`,`websocket`]),YA=R([`request`,`read`,`write`]);var XA=class extends ox(`AI.Error.Transport`)(`Transport`,{...zA,transport:JA,operation:YA,code:O(j),url:O(j),phase:O(R([`prepare`,`queue`,`connect`,`send`,`receive`,`decode`,`complete`,`fallback`,`close`])),delivery:O(R([`not-sent`,`rejected`,`ambiguous`,`accepted`])),recovery:O(R([`retry-connect`,`retry-full`,`rotate-and-retry-full`,`fallback-http`,`fail`]))}){},ZA=class extends ox(`AI.Error.InvalidProviderOutput`)(`InvalidProviderOutput`,{...zA,classification:O(R([`incomplete-stream`])),route:O(j)}){},QA=class extends ox(`AI.Error.UnknownProvider`)(`UnknownProvider`,zA){},$A=class extends ox(`AI.Error.Timeout`)(`Timeout`,{...zA,timeoutMs:O(J)}){};const ej=L([BA,VA,HA,UA,WA,GA,KA,qA,XA,ZA,QA,$A]).pipe(V(`_tag`));var tj=class extends ox()(`AI.Error`,{reason:ej}){cause=this.reason;get message(){return this.reason.message}};const nj=class extends xr()(`@opencode/AI/RequestExecutor`){},rj=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t])),ij=e=>new LA({url:e.request.url,status:e.status,headers:rj(e.headers)}),aj=(e,t,n)=>String.fromCharCode(...e.subarray(t,n)),oj=(e,t)=>e.length>=t.length&&t.every((t,n)=>e[n]===t),sj=e=>{if(oj(e,[137,80,78,71,13,10,26,10]))return`image/png`;if(oj(e,[255,216,255]))return`image/jpeg`;if(oj(e,[71,73,70,56]))return`image/gif`;if(e.length>=12&&aj(e,0,4)===`RIFF`){let t=aj(e,8,12);if(t===`WEBP`)return`image/webp`;if(t===`WAVE`)return`audio/wav`}if(oj(e,[37,80,68,70]))return`application/pdf`;if(e.length>=12&&aj(e,4,8)===`ftyp`){let t=aj(e,8,12),n=Math.min(new DataView(e.buffer,e.byteOffset).getUint32(0),e.length),r=Array.from({length:Math.floor((n-16)/4)},(t,n)=>aj(e,16+n*4,20+n*4)),i=t===`mif1`||t===`msf1`;return t===`avif`||t===`avis`||i&&(r.includes(`avif`)||r.includes(`avis`))?`image/avif`:i||[`heic`,`heix`,`hevc`,`hevx`].includes(t)?`image/heic`:t===`qt `?`video/quicktime`:t===`M4A `?`audio/mp4`:`video/mp4`}if(oj(e,[26,69,223,163]))return`video/webm`;if(oj(e,[73,68,51]))return`audio/mpeg`;if(e.length>=2&&e[0]===255&&(e[1]&224)==224)return e[1]&6?`audio/mpeg`:`audio/aac`;if(oj(e,[79,103,103,83]))return`audio/ogg`;if(oj(e,[102,76,97,67]))return`audio/flac`},cj=`application/octet-stream`,lj=L([P({type:k(`bytes`),data:Wb,mediaType:j}),P({type:k(`base64`),data:j,mediaType:j}),P({type:k(`url`),url:j,mediaType:O(j),expiresAt:O(M)}),P({type:k(`ref`),provider:rT,id:j,mediaType:O(j)})]).pipe(V(`type`)).annotate({identifier:`Media.Source`}),uj=Ey(e=>typeof e==`string`&&/^\d+(?:\.\d+)?:\d+(?:\.\d+)?$/.test(e),{title:`Media.AspectRatio`});R([`image`,`video`,`audio`,`document`,`other`]);const dj=e=>{let t=e.toLowerCase();return t.startsWith(`image/`)?`image`:t.startsWith(`video/`)?`video`:t.startsWith(`audio/`)?`audio`:t===`application/pdf`||t.startsWith(`text/`)?`document`:`other`},fj=P({width:O(M),height:O(M),durationSeconds:O(M),sampleRate:O(M),channels:O(M),encoding:O(j),format:O(j)}).annotate({identifier:`Media.Info`}),pj=(e,t)=>new tj({reason:new BA({message:e,cause:t})});var mj=class{source;mediaType;kind;info;expiresAt;providerMetadata;headers;#e;#t;constructor(e){this.source=e.source,this.mediaType=e.source.mediaType??(e.source.type===`bytes`?sj(e.source.data):void 0)??cj,this.kind=dj(this.mediaType),this.info=e.info,this.expiresAt=e.source.type===`url`?e.source.expiresAt:void 0,this.providerMetadata=e.providerMetadata,this.headers=e.source.type===`url`?e.headers:void 0}inline(){let e=this.source;if(e.type!==`bytes`&&e.type!==`base64`)return;let t=e.type===`base64`?e.data:this.#t??=Op(e.data),n=this.mediaType.toLowerCase();return{mime:n,base64:t,dataUrl:`data:${n};base64,${t}`}}bytes(){return Qd(()=>{let e=this.source;return e.type===`bytes`?x(e.data):this.#e===void 0?e.type===`ref`?S(pj(`Cannot materialize provider ref ${e.provider}:${e.id}`)):(e.type===`base64`?df(kp(e.data)).pipe(xf(e=>pj(`Media asset contains invalid base64 data`,e))):yj(e,this.headers)).pipe(mf(e=>$d(()=>this.#e=e))):x(this.#e)})}base64(){return Qd(()=>{let e=this.source;return e.type===`base64`?x(e.data):this.#t===void 0?this.bytes().pipe(_f(e=>this.#t=Op(e))):x(this.#t)})}dataUrl(){return this.base64().pipe(_f(e=>`data:${this.mediaType};base64,${e}`))}toJSON(){let e=this.source;return{source:e.type===`bytes`?{...e,data:Op(e.data)}:e,info:this.info,providerMetadata:this.providerMetadata}}materialize(){return this.source.type===`bytes`||this.source.type===`base64`?x(this):this.bytes().pipe(_f(e=>xj(e,this.source.mediaType,{info:this.info,providerMetadata:this.providerMetadata})))}};const hj=P({source:lj,info:O(fj),providerMetadata:O(K)}).annotate({identifier:`Media.AssetEncoded`}),gj=e=>({source:e.source,info:e.info,providerMetadata:e.providerMetadata}),_j=Ey(e=>e instanceof mj,{expected:`Media.Asset`}),vj=hj.pipe(lb(_j,{decode:T(e=>new mj(e)),encode:T(gj)})),yj=Xf(`Media.download`)(function*(e,t){let n=yield*(yield*nj).execute(dw(e.url).pipe(hw(t??{}))),r=yield*n.arrayBuffer.pipe(xf(t=>new tj({reason:new ZA({message:`Failed to read media from ${e.url}`,http:ij(n),cause:t})})));return new Uint8Array(r)}),bj=(e,t)=>new mj({...t,source:e}),xj=(e,t,n)=>bj({type:`bytes`,data:e,mediaType:t??sj(e)??cj},n),Sj=(e,t,n)=>bj({type:`base64`,data:e,mediaType:t},n),Cj=Bb(A);Iy(Cj);const wj=By(Cj),Tj=R([`system`,`user`,`assistant`,`tool`]),Ej=P({type:k(`text`),text:j,cache:O(DT),metadata:O(F(j,A))}).annotate({identifier:`LLM.SystemPart`}),Dj=e=>({type:`text`,text:e}),Oj=MT(Ej,{make:Dj,content:e=>e===void 0?[]:typeof e==`string`?[Dj(e)]:Array.isArray(e)?[...e]:[e]}),kj=P({type:k(`text`),text:j,cache:O(DT),metadata:O(F(j,A)),providerMetadata:O(K)}).annotate({identifier:`LLM.Content.Text`}),Aj=P({type:k(`media`),media:vj,filename:O(j),cache:O(DT),metadata:O(F(j,A)),providerMetadata:O(K)}).annotate({identifier:`LLM.Content.Media`}),jj=L([P({type:k(`json`),value:A}),P({type:k(`text`),value:A}),P({type:k(`error`),value:A}),P({type:k(`content`),value:I(FT)})]).annotate({identifier:`LLM.ToolResult`}),Mj=Ny(jj),Nj=MT(jj,{is:Mj,make:(e,t=`json`)=>Mj(e)?e:t===`content`?{type:t,value:Array.isArray(e)?e:[]}:{type:t,value:e}}),Pj=MT(P({structured:A,content:I(FT)}).annotate({identifier:`LLM.ToolOutput`}),{make:(e,t=[])=>({structured:e,content:t}),fromResultValue:e=>{switch(e.type){case`json`:return{structured:e.value,content:[]};case`text`:return{structured:{},content:[{type:`text`,text:Ij(e.value)}]};case`content`:return{structured:{},content:e.value};case`error`:return}},toResultValue:e=>e.content.length===0?{type:`json`,value:e.structured}:e.content.length===1&&e.content[0]?.type===`text`?{type:`text`,value:e.content[0].text}:{type:`content`,value:e.content}}),Fj=Ry(Cj),Ij=e=>typeof e==`string`?e:hr(Fj(e),()=>String(e)),Lj=MT(P({type:k(`tool-call`),id:j,name:j,namespace:O(j),input:A,providerExecuted:O(N),cache:O(DT),metadata:O(F(j,A)),providerMetadata:O(K)}).annotate({identifier:`LLM.Content.ToolCall`}),{make:e=>({type:`tool-call`,...e})}),Rj=MT(P({type:k(`tool-result`),id:j,name:j,namespace:O(j),result:Nj,providerExecuted:O(N),cache:O(DT),metadata:O(F(j,A)),providerMetadata:O(K)}).annotate({identifier:`LLM.Content.ToolResult`}),{make:e=>({type:`tool-result`,id:e.id,name:e.name,namespace:e.namespace,result:Nj.make(e.result,e.resultType),providerExecuted:e.providerExecuted,cache:e.cache,metadata:e.metadata,providerMetadata:e.providerMetadata})}),zj=P({type:k(`reasoning`),text:j,encrypted:O(j),cache:O(DT),metadata:O(F(j,A)),providerMetadata:O(K)}).annotate({identifier:`LLM.Content.Reasoning`}),Bj=P({type:k(`compaction`),provider:rT,id:O(j),encrypted:O(j),text:O(tb(j))}).pipe(ab(e=>e.encrypted!==void 0!=(e.text!==void 0),{message:`Compaction requires either encrypted content or a summary`})).annotate({identifier:`LLM.Content.Compaction`}),Vj=MT(Bj,{make:e=>Iy(Bj)({type:`compaction`,...e})}),Hj=L([kj,Aj,Lj,Rj,zj,Vj,P({type:k(`effort`),effort:O(yT),previous:O(yT)}).annotate({identifier:`LLM.Content.Effort`})]).pipe(V(`type`));var Uj=class extends W(`LLM.Message`)({id:O(j),role:Tj,content:I(Hj),metadata:O(F(j,A)),providerMetadata:O(K),native:O(F(j,A))}){};(function(e){e.text=e=>({type:`text`,text:e}),e.media=(e,t)=>({type:`media`,media:e,...t}),e.content=t=>typeof t==`string`?[e.text(t)]:Array.isArray(t)?[...t]:[t],e.make=t=>t instanceof e?t:new e({...t,content:e.content(t.content)}),e.user=t=>e.make({role:`user`,content:t}),e.assistant=t=>e.make({role:`assistant`,content:t}),e.system=t=>e.make({role:`system`,content:t}),e.effort=t=>e.make({role:`system`,content:[{type:`effort`,effort:t.effort,previous:t.previous}]}),e.tool=t=>e.make({role:`tool`,content:[`type`in t?t:Rj.make(t)]})})(Uj||={});const Wj=L([P({type:k(`text`)}),P({type:k(`regex`),pattern:j}),P({type:k(`lark`),grammar:j})]).annotate({identifier:`LLM.Freeform`}),Gj={name:j,description:j,inputSchema:oT,outputSchema:O(oT),freeform:O(Wj),cache:O(DT),metadata:O(F(j,A)),native:O(F(j,A))};var Kj=class extends W(`LLM.ToolDefinition`)({type:k(`tool`),...Gj}){constructor(e){super({...e,type:`tool`})}};(function(e){e.make=t=>t instanceof e?t:new e(t),e.freeformField=e=>{let t=Object.entries(Ny(oT)(e.properties)?e.properties:{});if(t.length!==1)return;let[n,r]=t[0];if(Ny(oT)(r)&&r.type===`string`)return Array.isArray(e.required)&&e.required.includes(n)?n:void 0}})(Kj||={});const qj=MT(P({type:k(`namespace`),name:j,description:O(nb(j)),tools:I(rb(()=>Jj))}).annotate({identifier:`LLM.ToolNamespace`}),{make:e=>({...e,type:`namespace`,tools:e.tools.map(Jj.make)})}),Jj=MT(L([Kj,qj]).pipe(V(`type`),E({identifier:`LLM.ToolEntry`})),{make:e=>`type`in e&&e.type===`namespace`?qj.make(e):Kj.make(e)});var Yj=class extends W(`LLM.ToolChoice`)({type:R([`auto`,`none`,`required`,`tool`]),name:O(j),disableParallelToolUse:O(N)}){};(function(e){let t=e=>e===`auto`||e===`none`||e===`required`;e.named=t=>new e({type:`tool`,name:t}),e.make=n=>n instanceof e?n:n instanceof Kj?e.named(n.name):typeof n==`string`?t(n)?new e({type:n}):e.named(n):new e(n)})(Yj||={});const Xj=P({id:O(j),model:TT,system:I(Oj),messages:I(Uj),tools:I(Jj),toolChoice:O(Yj),generation:O(hT),providerOptions:O(lT),http:O(pT),cache:O(kT),promptCacheKey:O(j),metadata:O(F(j,A)),includeRaw:O(N)});var Zj=class extends W(`LLM.Request`)(Xj.fields){constructor(e){super(e)}};(function(e){e.input=e=>({id:e.id,model:e.model,system:e.system,messages:e.messages,tools:e.tools,toolChoice:e.toolChoice,generation:e.generation,providerOptions:e.providerOptions,http:e.http,cache:e.cache,promptCacheKey:e.promptCacheKey,metadata:e.metadata,includeRaw:e.includeRaw});function t(t,n){return Object.keys(n).length===0?t:new e({...e.input(t),...n,model:n.model??t.model})}e.update=t})(Zj||={});const Qj=XD;var $j=class e extends W(`AI.Usage`)({contextTokens:O(M),inputTokens:O(M),outputTokens:O(M),nonCachedInputTokens:O(M),cacheReadInputTokens:O(M),cacheWriteInputTokens:O(M),reasoningTokens:O(M),totalTokens:O(M),cost:O(M),providerMetadata:O(K)}){get visibleOutputTokens(){return Math.max(0,(this.outputTokens??0)-(this.reasoningTokens??0))}static from(t){return t instanceof e?t:new e(t)}};const eM=L([P({type:k(`tokens`),input:O(M),output:O(M),total:O(M),details:O(F(j,A))}),P({type:k(`seconds`),seconds:M}),P({type:k(`characters`),characters:M}),P({type:k(`credits`),credits:M}),P({type:k(`compute`),seconds:M})]).pipe(V(`type`)).annotate({identifier:`AI.MediaUsage`});W(`LLM.CompactionResponse`)({replacement:I(Uj),usage:O($j)}),W(`LLM.CompactionCheckpointResponse`)({checkpoint:Vj.pipe(ab(e=>e.encrypted!==void 0&&e.encrypted.length>0,{message:`A checkpoint response requires encrypted compaction content`})),responseID:j.check(yb(/\S/)),usage:O($j)});const tM=P({type:B(`step-start`),index:M}).annotate({identifier:`LLM.Event.StepStart`}),nM=P({type:B(`text-start`),id:iT,providerMetadata:O(K)}).annotate({identifier:`LLM.Event.TextStart`}),rM=P({type:B(`text-delta`),id:iT,text:j,providerMetadata:O(K)}).annotate({identifier:`LLM.Event.TextDelta`}),iM=P({type:B(`text-end`),id:iT,text:O(j),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.TextEnd`}),aM=P({type:B(`reasoning-start`),id:iT,providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ReasoningStart`}),oM=P({type:B(`reasoning-delta`),id:iT,text:j,providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ReasoningDelta`}),sM=P({type:B(`reasoning-end`),id:iT,text:O(j),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ReasoningEnd`}),cM=P({type:B(`tool-input-start`),id:aT,name:j,namespace:O(j),providerExecuted:O(N),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ToolInputStart`}),lM=P({type:B(`tool-input-delta`),id:aT,name:j,namespace:O(j),text:j,input:O(A)}).annotate({identifier:`LLM.Event.ToolInputDelta`}),uM=P({type:B(`tool-input-end`),id:aT,name:j,namespace:O(j),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ToolInputEnd`}),dM=P({type:B(`tool-input-error`),id:aT,name:j,namespace:O(j),raw:j}).annotate({identifier:`LLM.Event.ToolInputError`}),fM=P({type:B(`tool-call`),id:aT,name:j,namespace:O(j),input:A,providerExecuted:O(N),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ToolCall`}),pM=P({type:B(`tool-result`),id:aT,name:j,namespace:O(j),result:Nj,output:O(Pj),providerExecuted:O(N),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ToolResult`}),mM=P({type:B(`tool-error`),id:aT,name:j,namespace:O(j),message:j,error:O(Rb()),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ToolError`}),hM=P({normalized:Qj,raw:O(j),category:O(j),explanation:O(j)}).annotate({identifier:`LLM.FinishReasonDetails`}),gM=P({type:B(`step-finish`),index:M,reason:hM,usage:O($j),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.StepFinish`}),_M=P({type:B(`finish`),reason:hM,usage:O($j),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.Finish`}),vM=P({type:B(`media`),media:vj,providerMetadata:O(K)}).annotate({identifier:`LLM.Event.Media`}),yM=P({type:B(`provider-error`),message:j,classification:O(IA),providerMetadata:O(K)}).annotate({identifier:`LLM.Event.ProviderError`}),bM=P({type:B(`raw`),data:A}).annotate({identifier:`LLM.Event.Raw`}),xM=L([Vj,tM,nM,rM,iM,aM,oM,sM,cM,lM,uM,dM,fM,pM,mM,vM,gM,_M,yM,bM]).pipe(V(`type`)),SM=e=>iT.make(e),CM=e=>aT.make(e),wM=Object.assign(xM,{compaction:Vj.make,stepStart:tM.make,textStart:e=>nM.make({...e,id:SM(e.id)}),textDelta:e=>rM.make({...e,id:SM(e.id)}),textEnd:e=>iM.make({...e,id:SM(e.id)}),reasoningStart:e=>aM.make({...e,id:SM(e.id)}),reasoningDelta:e=>oM.make({...e,id:SM(e.id)}),reasoningEnd:e=>sM.make({...e,id:SM(e.id)}),toolInputStart:e=>cM.make({...e,id:CM(e.id)}),toolInputDelta:e=>lM.make({...e,id:CM(e.id)}),toolInputEnd:e=>uM.make({...e,id:CM(e.id)}),toolInputError:e=>dM.make({...e,id:CM(e.id)}),toolCall:e=>fM.make({...e,id:CM(e.id)}),toolResult:e=>pM.make({...e,id:CM(e.id),output:e.output===void 0?void 0:Pj.make(e.output.structured,e.output.content)}),toolError:e=>mM.make({...e,id:CM(e.id)}),media:vM.make,stepFinish:e=>gM.make({...e,usage:e.usage===void 0?void 0:$j.from(e.usage)}),finish:e=>_M.make({...e,usage:e.usage===void 0?void 0:$j.from(e.usage)}),providerError:yM.make,raw:bM.make,is:{compaction:xM.guards.compaction,stepStart:xM.guards[`step-start`],textStart:xM.guards[`text-start`],textDelta:xM.guards[`text-delta`],textEnd:xM.guards[`text-end`],reasoningStart:xM.guards[`reasoning-start`],reasoningDelta:xM.guards[`reasoning-delta`],reasoningEnd:xM.guards[`reasoning-end`],toolInputStart:xM.guards[`tool-input-start`],toolInputDelta:xM.guards[`tool-input-delta`],toolInputEnd:xM.guards[`tool-input-end`],toolInputError:xM.guards[`tool-input-error`],toolCall:xM.guards[`tool-call`],toolResult:xM.guards[`tool-result`],toolError:xM.guards[`tool-error`],media:xM.guards.media,stepFinish:xM.guards[`step-finish`],finish:xM.guards.finish,providerError:xM.guards[`provider-error`],raw:xM.guards.raw}}),TM=(e,t,n)=>{let r=[],i=/* @__PURE__ */ new Map;for(let a of e)t(a)&&(i.has(a.id)||r.push(a.id),i.set(a.id,(i.get(a.id)??``)+a.text)),n(a)&&a.text!==void 0&&(i.has(a.id)||r.push(a.id),i.set(a.id,a.text));return r.map(e=>i.get(e)).join(``)},EM=e=>TM(e,wM.is.textDelta,wM.is.textEnd),DM=e=>TM(e,wM.is.reasoningDelta,wM.is.reasoningEnd),OM=e=>e.reduce((e,t)=>`usage`in t&&t.usage!==void 0?t.usage:e,void 0),kM=()=>({events:[],message:Uj.assistant([]),textParts:{},reasoningParts:{},toolInputs:{}}),AM=(e,t)=>{let n=[...e.events,t];return wM.is.finish(t)?{...e,events:n,usage:t.usage??e.usage,finishReason:t.reason}:wM.is.providerError(t)?{...e,events:n,finishReason:e.finishReason??{normalized:`error`}}:{...e,events:n,usage:`usage`in t&&t.usage!==void 0?t.usage:e.usage}},jM=(e,t)=>t===void 0?{type:`text`,text:e}:{type:`text`,text:e,providerMetadata:t},MM=(e,t)=>t===void 0?{type:`reasoning`,text:e}:{type:`reasoning`,text:e,providerMetadata:t},NM=(e,t)=>({...e,message:Uj.assistant(t)}),PM=(e,t)=>NM(e,[...e.message.content,t]),FM=(e,t,n)=>NM(e,e.message.content.map((e,r)=>r===t?n:e)),IM=(e,t,n)=>e.textParts[t]?e:{...PM(e,jM(``,n)),textParts:{...e.textParts,[t]:{contentIndex:e.message.content.length,text:``,providerMetadata:n}}},LM=(e,t)=>{let n=IM(e,t.id,t.providerMetadata),r=n.textParts[t.id];if(!r)return n;let i=r.text+t.text,a=t.providerMetadata??r.providerMetadata;return{...FM(n,r.contentIndex,jM(i,a)),textParts:{...n.textParts,[t.id]:{...r,text:i,providerMetadata:a}}}},RM=(e,t)=>{let n=e.textParts[t.id];if(!n)return e;let r=t.text??n.text,i=t.providerMetadata??n.providerMetadata;return{...FM(e,n.contentIndex,jM(r,i)),textParts:{...e.textParts,[t.id]:{...n,text:r,providerMetadata:i}}}},zM=(e,t,n)=>e.reasoningParts[t]?e:{...PM(e,MM(``,n)),reasoningParts:{...e.reasoningParts,[t]:{contentIndex:e.message.content.length,text:``,providerMetadata:n}}},BM=(e,t)=>{let n=zM(e,t.id,t.providerMetadata),r=n.reasoningParts[t.id];if(!r)return n;let i=r.text+t.text,a=t.providerMetadata??r.providerMetadata;return{...FM(n,r.contentIndex,MM(i,a)),reasoningParts:{...n.reasoningParts,[t.id]:{...r,text:i,providerMetadata:a}}}},VM=(e,t)=>{let n=e.reasoningParts[t.id];if(!n)return e;let r=t.text??n.text,i=t.providerMetadata??n.providerMetadata;return{...FM(e,n.contentIndex,MM(r,i)),reasoningParts:{...e.reasoningParts,[t.id]:{...n,text:r,providerMetadata:i}}}},HM=(e,t)=>({...e,toolInputs:{...e.toolInputs,[t.id]:{name:t.name,namespace:t.namespace,text:``,providerMetadata:t.providerMetadata}}}),UM=(e,t)=>{let n=e.toolInputs[t.id]??{name:t.name,namespace:t.namespace,text:``};return{...e,toolInputs:{...e.toolInputs,[t.id]:{...n,text:n.text+t.text}}}},WM=(e,t)=>{let n=e.toolInputs[t.id]??{name:t.name,namespace:t.namespace,text:``};return{...e,toolInputs:{...e.toolInputs,[t.id]:{...n,name:t.name,namespace:t.namespace,providerMetadata:t.providerMetadata??n.providerMetadata}}}},GM=e=>Lj.make({id:e.id,name:e.name,namespace:e.namespace,input:e.input,...e.providerExecuted===void 0?{}:{providerExecuted:e.providerExecuted},...e.providerMetadata===void 0?{}:{providerMetadata:e.providerMetadata}}),KM=e=>Rj.make({id:e.id,name:e.name,namespace:e.namespace,result:e.result,...e.providerExecuted===void 0?{}:{providerExecuted:e.providerExecuted},...e.providerMetadata===void 0?{}:{providerMetadata:e.providerMetadata}}),qM=(e,t)=>{let{[t.id]:n,...r}=e.toolInputs;return{...PM(e,GM(t)),toolInputs:r}},JM=(e,t)=>{if(t.type===`raw`)return e;let n=AM(e,t);switch(t.type){case`compaction`:return PM(n,t);case`text-start`:return IM(n,t.id,t.providerMetadata);case`text-delta`:return LM(n,t);case`text-end`:return RM(n,t);case`reasoning-start`:return zM(n,t.id,t.providerMetadata);case`reasoning-delta`:return BM(n,t);case`reasoning-end`:return VM(n,t);case`tool-input-start`:return HM(n,t);case`tool-input-delta`:return UM(n,t);case`tool-input-end`:return WM(n,t);case`tool-input-error`:{let{[t.id]:e,...r}=n.toolInputs;return{...n,toolInputs:r}}case`tool-call`:return qM(n,t);case`tool-result`:return PM(n,KM(t));case`media`:return PM(n,t.providerMetadata===void 0?{type:`media`,media:t.media}:{type:`media`,media:t.media,providerMetadata:t.providerMetadata});default:return n}};var YM=class extends W(`LLM.Response`)({message:Uj,events:I(wM),usage:O($j),finishReason:hM}){get text(){return EM(this.events)}get reasoning(){return DM(this.events)}get toolCalls(){return this.events.filter(wM.is.toolCall)}};(function(e){e.empty=kM,e.reduce=JM,e.complete=t=>t.finishReason===void 0?void 0:new e({message:t.message,events:[...t.events],usage:t.usage,finishReason:t.finishReason}),e.fromEvents=t=>e.complete(t.reduce(e.reduce,e.empty())),e.text=e=>EM(e.events),e.usage=e=>e.usage??OM(e.events),e.toolCalls=e=>e.events.filter(wM.is.toolCall),e.reasoning=e=>DM(e.events)})(YM||={});const XM=[/prompt is too long/i,/input is too long for (?:the )?(?:requested|selected) model/i,/too large for the model'?s configured input limit/i,/exceeded this model context window limit/i,/exceeds the context window/i,/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,/input token count.*exceeds the maximum/i,/number of input tokens exceeds maximum length/i,/tokens in request more than max tokens allowed/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/requested input length \d+ exceeds maximum input length/i,/maximum context length is \d+ tokens/i,/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,/input(?: \(\d+ tokens\))? is longer than the model'?s context length/i,/exceeds the limit of \d+/i,/exceeds the available context size/i,/greater than the context length/i,/`inputs` tokens \+ `max_new_tokens` must be <= \d+/i,/context window exceeds limit/i,/exceeded model token limit/i,/context[_ ]length[_ ]exceeded/i,/context length is only \d+ tokens/i,/input length.*exceeds.*context length/i,/prompt (?:too long|exceeds max length|超长)/i,/too large for model with \d+ maximum context length/i,/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,/model_context_window_exceeded/i,/range of input length should be/i,/too many tokens/i,/token limit exceeded/i,/request_too_large/i],ZM=[/request entity too large/i,/payload too large/i,/request too large/i],QM=[/^(throttling error|service unavailable):/i,/rate limit/i,/too many requests/i,/max[_ ]tokens must be less than/i,/too many tokens(?: per day)?, please wait/i],$M=e=>!QM.some(t=>t.test(e))&&(XM.some(t=>t.test(e))||/^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(e)),eN=e=>ZM.some(t=>t.test(e)),tN=e=>{let t=e.reason.http?.headers[`x-should-retry`];if(t===`true`)return!0;if(t===`false`)return!1;switch(e.reason._tag){case`RateLimit`:case`ProviderInternal`:return!0;case`Transport`:return e.reason.delivery!==`rejected`&&(e.reason.delivery!==`accepted`||e.reason.operation===`read`);case`InvalidProviderOutput`:return e.reason.classification===`incomplete-stream`;case`UnknownProvider`:return!0;case`Authentication`:case`QuotaExceeded`:case`ContentPolicy`:case`InvalidRequest`:case`UnsupportedOperation`:case`NoRoute`:case`Timeout`:return!1;default:return e.reason}},nN=Fy(Cj),rN=/* @__PURE__ */ new Set([`insufficient_quota`,`usage_not_included`,`billing_error`,`gousagelimiterror`,`budgetlimiterror`,`freeusagelimiterror`,`creditlimitexceeded`]),iN=/* @__PURE__ */ new Set([`authentication_error`,`permission_error`,`permission_denied`,`api_key_invalid`]),aN=/* @__PURE__ */ new Set([`api_error`,`internal_error`,`internalserverexception`,`modelstreamerrorexception`,`overloaded_error`,`server_error`,`server_is_overloaded`,`slow_down`,`serviceunavailableexception`]),oN=/* @__PURE__ */ new Set([`model_not_found`,`invalid_prompt`,`invalid_request`,`invalid_request_error`,`validationexception`]),sN=/* @__PURE__ */ new Set([`content_filter`,`content_moderation`,`responsibleaipolicyviolation`,`content_policy_violation`,`image_content_policy_violation`,`refusal`,`datainspectionfailed`,`moderation_blocked`]),cN=/^[^:\n]+: \[([A-Za-z0-9_.-]+)\]/,lN=/incorrect api key provided/i,uN=/rate increased too quickly|rate[-_\s]?limit|too[_\s]?many[_\s]?requests/i,dN=/insufficient[-_\s]?(?:quota|balance)|(?<!token_)quota[-_\s]?exceeded|budget exceeded|usage limit|limit exhausted|package has expired|plan does not yet include/i,fN=/violating our usage policy|blocked by content filtering policy|content[-_\s]?policy|rejected (?:as a result of our|by the) safety system|detected potentially unsafe or sensitive content/i,pN=/\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i,mN=j.check(yb(/\S/)),hN=(e,t)=>P(e).pipe(lb(j,{decode:T(t),encode:fh(()=>`Provider error messages are decode-only`)})),gN=Fy(Bb(L([hN({error:P({message:mN})},e=>e.error.message),hN({error:mN},e=>e.error),hN({message:mN},e=>e.message),hN({Message:mN},e=>e.Message),hN({detail:mN},e=>e.detail),hN({errors:$y(P({message:mN}))},e=>e.errors[0].message)]))),_N=e=>_r(gN(e));function vN(e){let t={message:e.message,body:e.rawBody,http:e.http,cause:e.cause},n=e.rawBody??``,r=[...yN(e.data),...yN(n),...yN(e.message),...cN.exec(e.message)?.slice(1)??[],...bN(e.http?.headers[`x-amzn-errortype`])].map(e=>e.toLowerCase()),i=[e.message,n].filter(e=>e.length>0).join(`
|
|
10
|
-
`),a=e.status===void 0||e.status>=400&&e.status<500;return a&&(r.includes(`context_length_exceeded`)||r.includes(`model_context_window_exceeded`)||r.includes(`request_too_large`)||e.status!==429&&!r.includes(`throttlingexception`)&&$M(i))?new BA({...t,classification:`context-overflow`}):e.status===413||eN(i)?new BA({...t,classification:`payload-too-large`}):r.some(e=>sN.has(e))||a&&fN.test(e.message)?new KA(t):e.status===402||r.some(e=>rN.has(e))||e.status===429&&dN.test(i)?new GA({...t,retryAfterMs:e.retryAfterMs}):e.status===401||e.status===403||r.some(e=>iN.has(e))||e.status===400&&lN.test(i)?new UA(t):e.status===429||r.some(e=>e.includes(`rate_limit`)||e===`too_many_requests`||e===`throttlingexception`)||uN.test(i)?new WA({...t,retryAfterMs:e.retryAfterMs,rateLimit:e.rateLimit}):e.status===408||e.status===409||e.status!==void 0&&e.status>=500||(e.status===void 0||e.status<400)&&(!r.some(e=>oN.has(e))&&pN.test(i)||r.some(e=>aN.has(e)||e.includes(`exhausted`)||e.includes(`unavailable`)))?new qA({...t,retryAfterMs:e.retryAfterMs}):r.some(e=>oN.has(e))||e.status!==void 0&&e.status>=400&&e.status<500?new BA(t):new QA(t)}function yN(e){let t=typeof e==`string`?_r(nN(e)):e;if(!G(t))return[];let n=G(t.error)?t.error:void 0,r=n&&G(n.innererror)?n.innererror:void 0,i=n&&G(n.metadata)?n.metadata:void 0,a=G(t.response)?t.response:void 0,o=a&&G(a.error)?a.error:void 0,s=G(t.exception)?t.exception:void 0;return[t.code,...bN(t.__type),...bN(t.code),t.error_type,n?.code,n?.type,n?.status,n?.error_type,...Array.isArray(n?.details)?n.details.map(e=>G(e)?e.reason:void 0):[],r?.code,i?.error_type,o?.code,a?.error_type,s?.type].filter(e=>typeof e==`string`)}function bN(e){return typeof e==`string`?[e.replace(/:.*/s,``).replace(/^[^#]*#/,``)]:[]}const xN=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t])),SN=e=>Math.min(2**53-1,Math.max(0,Math.ceil(e))),CN=e=>{let t=Number(e[`retry-after-ms`]);if(Number.isFinite(t))return SN(t);let n=e[`retry-after`];if(!n)return;let r=Number(n);if(Number.isFinite(r))return SN(r*1e3);let i=Date.parse(n);if(!Number.isNaN(i))return SN(i-Date.now())},wN=(e,t,n)=>{t.length>0&&(e[t]=n)},TN=(e,t)=>{let n={},r={},i={};if(Object.entries(e).forEach(([e,t])=>{let a=/^x-ratelimit-limit-(.+)$/.exec(e)?.[1];if(a)return wN(n,a,t);let o=/^x-ratelimit-remaining-(.+)$/.exec(e)?.[1];if(o)return wN(r,o,t);let s=/^x-ratelimit-reset-(.+)$/.exec(e)?.[1];if(s)return wN(i,s,t);let c=/^anthropic-ratelimit-(.+)-(limit|remaining|reset)$/.exec(e);if(c)return c[2]===`limit`?wN(n,c[1],t):c[2]===`remaining`?wN(r,c[1],t):wN(i,c[1],t)}),t!==void 0||Object.keys(n).length!==0||Object.keys(r).length!==0||Object.keys(i).length!==0)return new RA({retryAfterMs:t,limit:Object.keys(n).length===0?void 0:n,remaining:Object.keys(r).length===0?void 0:r,reset:Object.keys(i).length===0?void 0:i})},EN=2e3,DN=(e,t)=>{let n=`Provider request failed with HTTP ${e}`,r=t?.trim()??``;return _N(r)||(!r||/^<(?:!doctype|html)/i.test(r)?n:`${n}: ${r.length>EN?`${r.slice(0,EN)}…`:r}`)},ON=e=>rf(function*(){if(e.status<400)return e;let t=yield*e.text.pipe(hf);return yield*kN({message:DN(e.status,t._tag===`Success`?t.success:void 0),url:e.request.url,status:e.status,responseHeaders:rj(e.headers),responseBody:t._tag===`Success`?t.success:void 0,cause:t._tag===`Failure`?t.failure.cause??t.failure:void 0})}),kN=e=>{let t=xN(nm(e.responseHeaders)),n=CN(t),r=TN(t,n);return new tj({reason:vN({message:e.message,status:e.status,data:e.data,rawBody:e.responseBody,retryAfterMs:n,rateLimit:r,cause:e.cause,http:e.status===void 0||e.url===void 0?void 0:new LA({url:e.url,status:e.status,headers:t})})})},AN=Fy(P({message:j,code:Hy(j),cause:Hy(A)})),jN=e=>{let t=_r(AN(e));if(!t)return;if(t.code!==void 0)return t;let n=_r(AN(t.cause));return n?.code===void 0?t:n},MN=e=>WC(e)&&`cause`in e.reason&&e.reason.cause!==void 0?MN(e.reason.cause):e,NN=`Connection lost while reading the response`,PN=e=>{let t=WC(e.error)?e.error.request:e.request,n=n=>new tj({reason:new XA({message:n.message,cause:r,http:e.http,transport:`http`,operation:e.operation,code:n.code,url:t.url})}),r=MN(e.error),i=jN(r),a=i?.code,o=a&&i?.message&&!i.message.includes(a)?`${a}: ${i.message}`:i?.message,s=o??(e.error instanceof Error?e.error.message:void 0);return au(e.error)||au(r)?n({message:s??`HTTP transport timed out`,code:a??`Timeout`}):WC(e.error)?e.operation===`read`&&e.error.reason._tag===`DecodeError`?n({message:o?`${NN}: ${o}`:NN,code:a}):e.error.reason._tag===`TransportError`?n({message:s??e.error.reason.description??`HTTP transport failed`,code:a??e.error.reason._tag}):n({message:s??`HTTP transport failed: ${e.error.reason._tag}`,code:a??e.error.reason._tag}):n({message:s??`HTTP transport failed`,code:a})},FN=e=>e.stream.pipe(SC(t=>PN({error:t,request:e.request,operation:`read`,http:ij(e)}))),IN=Iu(nj,rf(function*(){let e=yield*Rw;return nj.of({execute:(t,n)=>rf(function*(){if(!n)return yield*e.execute(t).pipe(xf(e=>PN({error:e,request:t,operation:`request`})),C(ON));let r=yield*n(t,t=>e.execute(t).pipe(xf(e=>e instanceof Error?e:Error(String(e))))).pipe(xf(e=>PN({error:e,request:t,operation:`request`})));return yield*ON(r)})})})).pipe(Hu($w));var LN=class extends xr()(`@opencode/AI/DecisionClient`){};const RN=e=>C(LN,t=>t.generate(e)),zN=Iu(LN,rf(function*(){let e=yield*nj;return LN.of({generate:Yf(function*(t){let n=t.model.route,r=yield*n.generate(t,e.execute);return VN(t.questions,r.answers)?r:yield*new tj({reason:new ZA({route:n.id,message:`Decision answers do not match the requested questions`,cause:r.answers})})})})})),BN=zN.pipe(Uu(IN)),VN=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];if(r.name!==e.name)return!1;if(r.type===`error`)return!0;if(e.type===`predicate`)return r.type===`predicate`;if(e.type===`choice`){if(r.type!==`choice`)return!1;let t=e.choices.map(e=>e.value);return t.includes(r.choice)&&HN(t,r.probabilities.map(e=>e.value))}return r.type!==`score`||r.score<0||r.score>e.levels.length-1?!1:HN(e.levels.map((e,t)=>t),r.probabilities.map(e=>e.value))}),HN=(e,t)=>e.length===t.length&&new Set(t).size===t.length&&t.every(t=>e.includes(t)),UN={Service:LN,layer:zN,fetchLayer:BN,generate:RN};R([`queued`,`running`,`completed`,`failed`,`cancelled`,`expired`]);const WN=ta(5),GN=na(10),KN=P({type:B(`generation-queued`),id:j,position:O(M)}).annotate({identifier:`Generation.Event.Queued`}),qN=P({type:B(`generation-progress`),id:j,progress:O(M)}).annotate({identifier:`Generation.Event.Progress`}),JN=/* @__PURE__ */ new Set([`completed`,`failed`,`cancelled`,`expired`]),YN=e=>JN.has(e);var XN=class e{route;token;id;status;progress;position;constructor(e,t,n){this.route=e,this.token=t,this.id=n.id,this.status=n.status,this.progress=n.progress,this.position=n.position}get snapshot(){return{id:this.id,status:this.status,progress:this.progress,position:this.position}}get terminal(){return YN(this.status)}refresh(){return this.route.status.pipe(_f(t=>new e(this.route,this.token,t)))}result(){return this.route.result}await(e){let t=Ri(e?.poll?.timeout??GN);return(this.terminal?x(this):this.poll(e?.poll)).pipe(C(e=>e.result()),Cf({duration:t,orElse:()=>$N(this.id,t)}))}cancel(){return this.route.cancel??ef}events(e){if(this.terminal)return aC(this.event());let t=Ri(e?.poll?.timeout??GN);return pC(Wu.pipe(_f(n=>{let r=n+oa(t),i=QN(this.refresh(),this.id,t,r),a=this.schedule(e?.poll).pipe(Md(e=>x(fa(e.duration,ea(Math.max(0,r-e.now))))));return eC(i,a).pipe(CC(e=>e.terminal),mC(e=>e.event()))})))}event(){return this.terminal?{type:`generation-finished`,id:this.id,status:this.status}:this.status===`queued`?{type:`generation-queued`,id:this.id,position:this.position}:{type:`generation-progress`,id:this.id,progress:this.progress}}poll(e){return this.refresh().pipe(zf({schedule:this.schedule(e),until:e=>e.terminal}))}schedule(e){return Id(e?.interval??WN)}};const ZN=(e,t,n)=>{let r=Ri(n?.poll?.timeout??GN);return pC(Wu.pipe(_f(i=>e.events(n).pipe(xC(e=>e.type!==`generation-finished`),vC(lC(QN(e.result(),e.id,r,i+oa(r)).pipe(_f(t))))))))},QN=(e,t,n,r)=>Wu.pipe(C(i=>i>=r?S($N(t,n)):e.pipe(Cf({duration:ea(r-i),orElse:()=>S($N(t,n))})))),$N=(e,t)=>new tj({reason:new $A({message:`Generation ${e} did not finish within ${ga(t)}`,timeoutMs:Math.min(2**53-1,Math.max(0,Math.ceil(oa(t))))})}),eP=(e,t)=>({responseEvents:t.responseEvents,layer:Iu(e,rf(function*(){let n=yield*nj,r=(e,n)=>new tj({reason:new VA({operation:`${t.modality}.${n}`,provider:e.provider,route:e.id,message:`${e.provider}/${e.id} is not a queued route; use generate or stream`})}),i=e=>{let t=e.model.route;return t.kind===`queued`?t.start(e,n.execute):S(r(t,`start`))};return e.of({start:i,resume:(e,t)=>e.route.kind===`queued`?e.route.resume(e,t,n.execute):S(r(e.route,`resume`)),generate:(e,t)=>{let r=e.model.route;return r.kind===`queued`?i(e).pipe(C(e=>e.await(t))):r.generate(e,n.execute)},stream:(e,r)=>{let a=e.model.route;return a.kind===`stream`?a.stream(e,n.execute):a.kind===`queued`?pC(i(e).pipe(_f(e=>ZN(e,t.responseEvents,r)))):lC(_f(a.generate(e,n.execute),t.responseEvents))}})})),generate:(t,n)=>e.use(e=>e.generate(t,n)),stream:(t,n)=>pC(e.useSync(e=>e.stream(t,n))),start:t=>e.use(e=>e.start(t)),resume:(t,n)=>e.use(e=>e.resume(t,n))}),tP=(e,t={})=>({...t,path:e}),nP=e=>e.replace(/\/+$/,``),rP=(e,t)=>typeof e==`function`?e(t):e,iP=(e,t)=>{let n=new URL(`${nP(e.baseURL??``)}${rP(e.path,t)}`);for(let[t,r]of Object.entries(e.query??{}))n.searchParams.set(t,r);return n};var aP=class extends Error{source;_tag=`MissingCredentialError`;constructor(e,t=`Missing auth credential: ${e}`){super(t),this.source=e}};const oP=e=>e instanceof tj?e:new tj({reason:new UA({message:e instanceof aP?e.message:`Failed to resolve auth config: ${e.message}`,cause:e})}),sP=e=>t=>e.apply(t).pipe(xf(oP)),cP=e=>{if(typeof e==`string`)return e.isWellFormed()?e:e.toWellFormed();if(Array.isArray(e)){let t=e.map(cP);return Object.getPrototypeOf(e)===Array.prototype&&t.every((t,n)=>t===e[n])?e:t}if(e instanceof Uint8Array||e instanceof Error||e instanceof mj||!G(e))return e;let t=Object.entries(e),n=t.map(([e,t])=>[cP(e),cP(t)]);return n.every(([e,n],r)=>e===t[r][0]&&n===t[r][1])&&(Object.getPrototypeOf(e)===Object.prototype||Vy(e.constructor))?e:Object.fromEntries(n)},lP=e=>{let t=mP(e);return{kind:`inline`,id:e.protocol.id,provider:e.protocol.provider,protocol:e.protocol.id,generate:Xf(`MediaRoute.generate`)(function*(n,r){let i=yield*t.submit(n,{unsupported:e.protocol.unsupported,from:e.protocol.body.from},r);return yield*e.protocol.response.decode(i.response,i.context)})}},uP=ta(30),dP=Dd([kd([jd(`1 second`),Id(uP)]),Fd(8)]).pipe(Nd,zd(),Md(({input:e,duration:t})=>x(fa(e.reason._tag===`RateLimit`||e.reason._tag===`ProviderInternal`?pa(t,ea(e.reason.retryAfterMs??0)):t,uP)))),fP=e=>{let t=mP(e),n=e.protocol,r=Py(n.token),i=By(n.token),a=(e,r,i)=>{let a=n=>t.call(`GET`,n.path(e),r,i).pipe(Sf({schedule:dP,while:tN}),C(t=>n.decode(t.response,{token:e,auth:t.auth}))),o=a(n.status),s=n.cancel,c=s===void 0?void 0:t.call(s.method,s.path(e),r,i).pipe(yf);return{status:o,result:a(n.result),cancel:c!==void 0&&s?.activeOnly?o.pipe(C(e=>YN(e.status)?ef:c)):c}},o=Xf(`MediaRoute.start`)(function*(e,r){let o=yield*t.submit(e,{unsupported:n.unsupported,prepare:n.start.prepare,from:n.start.body.from},r),s=yield*n.start.decode(o.response,o.context);return new XN(a(s.token,o.context.request.http,r),i(s.token),s.snapshot)}),s=Xf(`MediaRoute.resume`)(function*(e,o,s){let c=yield*r(o).pipe(xf(e=>new tj({reason:new BA({message:`${n.id} cannot resume a generation from this token`,cause:e})}))),l=a(c,t.http(e),s);return new XN(l,i(c),yield*l.status)});return{kind:`queued`,id:n.id,provider:n.provider,protocol:n.id,start:o,resume:s}},pP=e=>{let t=mP(e),n=e.protocol,r=(e,r,i)=>pC(rf(function*(){let a=yield*t.submit({...e,mode:i},{unsupported:n.unsupported,from:n.body.from},r),o=ij(a.response);return oC(()=>{let e=n.initial();return n.frames(FN(a.response),a.context).pipe(hC(t=>n.step(e,t).pipe(_f(([t,n])=>(e=t,n)))),_C,vC(oC(()=>lC(n.finish(e,{...a.context,http:o})))),SC(e=>e.reason.http===void 0?new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:o})}):e))})}));return{kind:`stream`,id:n.id,provider:n.provider,protocol:n.id,stream:(e,t)=>r(e,t,`stream`),generate:(t,n)=>r(t,n,`generate`).pipe(TC,C(e.collect))}},mP=e=>{let t=e.headers===void 0?void 0:new pT({headers:e.headers}),n=sP(e.auth),r=t=>new URL(`${nP(e.endpoint.baseURL??``)}${t}`),i=Xf(`MediaRoute.send`)(function*(e,t){let r=gP(e.body,e.headers),i=e.url.toString(),a=yield*n({request:e.request,method:e.method,url:i,body:r.text,headers:r.headers});return{response:yield*t(r.apply(uw(e.method)(i).pipe(hw(a)))),auth:Object.fromEntries(Object.entries(a).filter(([e,t])=>r.headers[e]!==t))}});return{http:e=>mT(t,e.http),submit:Xf(`MediaRoute.submit`)(function*(n,a,o){yield*_P(e.protocol.id,e.protocol.provider,n,a.unsupported);let s=mT(t,n.model.http,n.http),c=uT(n.model.providerOptions,n.providerOptions),l=nm(s?.headers),u=a.prepare===void 0?n:yield*a.prepare(n,(e,t)=>i({method:`POST`,url:r(e),headers:l,request:n,body:t},o).pipe(_f(e=>e.response))),d={...cP({...u,http:s,providerOptions:c}),model:n.model},f=yield*a.from(d),ee=hP(hP(iP(e.endpoint,{request:d,body:f}),f.type===`multipart`?void 0:f.query),s?.query);return{response:(yield*i({method:`POST`,url:ee,headers:l,request:d,body:f},o)).response,context:{request:d,body:f}}}),call:(t,n,a,o)=>{let s=hP(/^https?:\/\//.test(n)?new URL(n):r(n),a?.query);for(let[t,n]of Object.entries(e.endpoint.query??{}))s.searchParams.set(t,n);return i({method:t,url:s,headers:nm(a?.headers),request:{http:a}},o)}}},hP=(e,t)=>{for(let[n,r]of Object.entries(t??{})){e.searchParams.delete(n);for(let t of typeof r==`string`?[r]:r)e.searchParams.append(n,t)}return e},gP=(e,t)=>{if(e===void 0)return{text:``,headers:t,apply:e=>e};if(e.type===`json`){let n=wj(e.value);return{text:n,headers:t,apply:Cw(n,`application/json`)}}return e.type===`binary`?{text:`[${e.contentType}]`,headers:t,apply:Sw(e.value,e.contentType)}:{text:`[multipart/form-data]`,headers:sm(t,`content-type`),apply:ww(e.value)}},_P=(e,t,n,r)=>{let i=(r??[]).filter(e=>{let t=n[e];return Array.isArray(t)?t.length>0:t!==void 0});return i.length===0?ef:S(new tj({reason:new VA({operation:`media.${i[0]}`,provider:t,route:e,message:`${t}/${e} does not support ${i.join(`, `)}`})}))};var vP=class{id;provider;route;http;providerOptions;constructor(e){this.id=nT.make(e.id),this.provider=rT.make(e.provider),this.route=e.route,this.http=e.http,this.providerOptions=e.providerOptions}};const yP=(e,t,n)=>xP(e)?pP({...bP(e,t),collect:n}):SP(e)?fP(bP(e,t)):lP(bP(e,t)),bP=(e,t)=>({protocol:e.protocol,endpoint:tP(e.path,{baseURL:t.baseURL??e.baseURL}),auth:t.auth,headers:e.headers===void 0&&t.headers===void 0?void 0:{...e.headers,...t.headers}}),xP=e=>e.protocol.kind===`stream`,SP=e=>e.protocol.kind===`queued`,CP=e=>cf({try:e,catch:e=>new tj({reason:new BA({message:e instanceof Error?e.message:String(e),cause:e})})});var wP=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,NP)})}};const TP=Ey(e=>e instanceof wP,{expected:`Image.Model`}),EP=uj;W(`Image.Request`)({model:TP,prompt:j,images:O(I(vj)),n:O(U),aspect:O(EP),resolution:O(j),providerOptions:O(lT),http:O(pT)});var DP=class extends W(`Image.Response`)({images:I(vj),usage:O(eM),providerMetadata:O(K)}){get image(){return this.images[0]}};const OP=P({type:B(`image-partial`),index:M,image:vj}).annotate({identifier:`Image.Event.Partial`}),kP=P({type:B(`image`),index:M,image:vj}).annotate({identifier:`Image.Event.Image`}),AP=P({type:B(`finish`),usage:O(eM),providerMetadata:O(K)}).annotate({identifier:`Image.Event.Finish`}),jP=L([KN,qN,OP,kP,AP]).pipe(V(`type`)),MP=Object.assign(jP,{is:{generationQueued:jP.guards[`generation-queued`],generationProgress:jP.guards[`generation-progress`],imagePartial:jP.guards[`image-partial`],image:jP.guards.image,finish:jP.guards.finish}}),NP=e=>{let t=e.find(MP.is.finish);return t===void 0?sf(/* @__PURE__ */ Error(`The image stream completed without a finish event`)):x(new DP({images:e.filter(MP.is.image).map(e=>e.image),usage:t.usage,providerMetadata:t.providerMetadata}))},PP=class extends xr()(`@opencode/ImageClient`){},FP={Service:PP,...eP(PP,{modality:`image`,responseEvents:e=>[...e.images.map((e,t)=>kP.make({index:t,image:e})),AP.make({usage:e.usage,providerMetadata:e.providerMetadata})]})};Ny(cx),F(j,A),P({cost:(e=>Hy(nb(e).pipe(sb(()=>x(dr(void 0))))))(H.check(Ob(0)))});const IP=e=>e.map(e=>e.text).join(`
|
|
11
|
-
`),LP=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`),RP=e=>`<system-update>\n${LP(IP(e))}\n</system-update>`,zP=Yf(function*(e,t){let n=[];for(let r of t.content){if(!UP(r,[`text`]))return yield*WP(e,`system`,[`text`]);n.push(r)}return n});Yf(function*(e,t){let n=yield*zP(e,t);return{type:`text`,text:RP(n),cache:n.at(-1)?.cache}});const BP=(e,t)=>new tj({reason:new BA({message:e,cause:t})}),VP=e=>new tj({reason:new VA({operation:e.operation,message:e.message,provider:e.provider,route:e.route,cause:e.cause})}),HP=e=>e.length<=1?e[0]??``:e.length===2?`${e[0]} and ${e[1]}`:`${e.slice(0,-1).join(`, `)}, and ${e.at(-1)}`,UP=(e,t)=>t.includes(e.type),WP=(e,t,n)=>BP(`${e} ${t} messages only support ${HP(n)} content for now`),GP=16777216,KP=(e,t)=>new tj({reason:new XA({message:e,body:t.body,cause:t.cause,transport:`websocket`,operation:t.operation,url:t.url,code:t.code,phase:t.phase,delivery:t.delivery})}),qP=(e,t)=>e.reason._tag===`Transport`?new tj({reason:new XA({...e.reason,message:e.reason.message,cause:e.reason.cause,phase:t.phase,delivery:t.delivery})}):e,JP=e=>`message`in e&&typeof e.message==`string`?e.message:e.type??`error`,YP=e=>{if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},XP=(e,t)=>e.readyState===globalThis.WebSocket.OPEN?ef:e.readyState===globalThis.WebSocket.CLOSING||e.readyState===globalThis.WebSocket.CLOSED?S(KP(`WebSocket closed before opening (state ${e.readyState})`,{url:t.url,operation:`request`,code:`closed`,phase:`connect`,delivery:`not-sent`})):tf((n,r)=>{let i=()=>{e.removeEventListener(`open`,o),e.removeEventListener(`error`,s),e.removeEventListener(`close`,c),r.removeEventListener(`abort`,a)},a=()=>{i(),e.readyState!==globalThis.WebSocket.CLOSED&&e.readyState!==globalThis.WebSocket.CLOSING&&(e.addEventListener(`error`,()=>{},{once:!0}),e.close(1e3))},o=()=>{i(),n(ef)},s=e=>{i(),n(S(KP(`Failed to open WebSocket: ${JP(e)}`,{cause:`error`in e?e.error??e:e,url:t.url,operation:`request`,phase:`connect`,delivery:`not-sent`})))},c=e=>{i(),n(S(KP(`WebSocket closed before opening with code ${e.code}`,{body:e.reason,cause:e,url:t.url,operation:`request`,code:String(e.code),phase:`connect`,delivery:`not-sent`})))};e.addEventListener(`open`,o,{once:!0}),e.addEventListener(`error`,s,{once:!0}),e.addEventListener(`close`,c,{once:!0}),r.addEventListener(`abort`,a,{once:!0})}),ZP=e=>rf(function*(){let t=yield*eT,n=yield*cf({try:()=>t(e.url,{headers:e.headers}),catch:t=>KP(t instanceof Error?t.message:`Failed to construct WebSocket`,{cause:t,url:e.url,operation:`request`,phase:`connect`,delivery:`not-sent`})});return yield*QP(n,e)}),QP=(e,t)=>rf(function*(){yield*XP(e,t);let n=yield*kx(),r=e=>typeof e==`string`?new Blob([e]).size>GP:e.byteLength>GP,i=i=>r(i)?(Nx(n,Zl(KP(`WebSocket message exceeds the 16 MiB limit`,{body:typeof i==`string`?i:new TextDecoder().decode(i),url:t.url,operation:`read`,code:`message-too-large`,phase:`receive`}))),e.readyState===globalThis.WebSocket.OPEN&&e.close(1009,`Message too large`),!0):!1,a=e=>{i(e)||jx(n,e)},o=e=>{if(typeof e.data==`string`)return a(e.data);let r=YP(e.data);if(r)return a(r);Nx(n,Zl(KP(`Unsupported WebSocket message payload`,{cause:e,url:t.url,operation:`read`,code:`message`,phase:`receive`})))},s=e=>{Nx(n,Zl(KP(`WebSocket error: ${JP(e)}`,{cause:`error`in e?e.error??e:e,url:t.url,operation:`read`,code:`message`,phase:`receive`})))},c=e=>{Nx(n,Zl(KP(`WebSocket closed with code ${e.code}`,{body:e.reason,cause:e,url:t.url,operation:`read`,code:String(e.code),phase:`close`})))},l=$d(()=>{e.removeEventListener(`message`,o),e.removeEventListener(`error`,s),e.removeEventListener(`close`,c)}).pipe(pf(Px(n)));return e.addEventListener(`message`,o),e.addEventListener(`error`,s),e.addEventListener(`close`,c),{sendText:n=>Qd(()=>e.readyState===globalThis.WebSocket.OPEN?cf({try:()=>e.send(n),catch:e=>KP(e instanceof Error?e.message:`Failed to send WebSocket message`,{cause:e,url:t.url,operation:`write`,phase:`send`,delivery:`not-sent`})}):S(KP(`WebSocket is not open (state ${e.readyState})`,{url:t.url,operation:`write`,phase:`send`,delivery:`not-sent`}))),messages:dC(n),close:l.pipe(pf($d(()=>{e.readyState!==globalThis.WebSocket.CLOSED&&e.readyState!==globalThis.WebSocket.CLOSING&&e.close(1e3)})))}}),$P=(e,t)=>typeof e==`string`?e:t.decode(e),eF=e=>e.type===`frame`||e.type===`completed`||e.type===`incomplete`?x(e.frame):S(e.error),tF=e=>e.type!==`frame`,nF=e=>({execute:t=>rf(function*(){let n=yield*Mf(e.open(t.connect).pipe(xf(e=>qP(e,{phase:`connect`,delivery:`not-sent`}))),e=>e.close),r=yield*t.driver.create(void 0);yield*n.sendText(r.message).pipe(xf(e=>new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:e.reason.http??n.http})})));let i=new TextDecoder,a=!1;return{http:n.http,frames:n.messages.pipe(mC(e=>(a=!0,$P(e,i))),SC(e=>qP(e,{phase:e.reason._tag===`Transport`&&e.reason.phase===`close`?`close`:`receive`,delivery:a?`accepted`:`ambiguous`})),hC(e=>t.driver.observe(r,e).pipe(xf(t=>new tj({reason:ej.make({...t.reason,message:t.reason.message,cause:t.reason.cause,body:e})})),_f(t=>`error`in t?{...t,error:new tj({reason:ej.make({...t.error.reason,message:t.error.reason.message,cause:t.error.reason.cause,body:e})})}:t))),CC(tF),hC(eF),SC(e=>new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:e.reason.http??n.http})}))),complete:ef}})});rf(function*(){let e=yield*eT;return nF({open:t=>ZP(t).pipe(jf(eT,e))})});const rF=e=>{if(e.role!==`system`||e.content.length!==1)return;let t=e.content[0];return t.type===`effort`?t:void 0},iF=e=>{let t=e.messages.filter(e=>rF(e)===void 0);return t.length===e.messages.length?e:Zj.update(e,{messages:t})},aF=e=>e.model.route.supportsEffortUpdates?.(e)?e:iF(e),oF={tools:!0,system:!0,messages:{tail:1}},sF={},cF=e=>e===`none`?sF:typeof e==`object`&&!lF(e)?e:oF,lF=e=>e===void 0||e===`auto`||typeof e==`object`&&e.tools===void 0&&e.system===void 0&&e.messages===void 0,uF=e=>typeof e.cache==`object`?e.cache.ttl:void 0,dF=/* @__PURE__ */ new Set([`alibaba-chat`,`alibaba-messages`,`anthropic-messages`,`anthropic-compatible-messages`,`bedrock-mantle-messages`,`cloudflare-ai-gateway-messages`,`google-vertex-messages`,`meta-messages`,`minimax-messages`,`moonshot-messages`,`vercel-ai-gateway-messages`,`zai-coding-messages`,`bedrock-converse`,`openrouter`,`digitalocean`]),fF={system:!0,messages:{tail:1}},pF=e=>{let t=e.replace(/^~/,``);return t.startsWith(`anthropic/`)?oF:t.startsWith(`qwen/`)||t.startsWith(`alibaba/qwen`)?fF:sF},mF=e=>e===void 0?new DT({type:`ephemeral`}):new DT({type:`ephemeral`,ttl:e}),hF=(e,t,n)=>{let r=e.at(-1);if(r===void 0)return e;if(r.type===`namespace`){let i=hF(r.tools,t,n);return i===r.tools?e:[...e.slice(0,-1),{...r,tools:i}]}return r.cache||n.remaining===0?e:(--n.remaining,[...e.slice(0,-1),new Kj({...r,cache:t})])},gF=e=>e.reduce((e,t)=>e+(t.type===`tool`?t.cache===void 0?0:1:gF(t.tools)),0),_F=(e,t,n)=>{if(e.length===0)return e;let r=!1,i=e.map((i,a)=>a!==0&&a!==e.length-1||i.cache||n.remaining===0?i:(--n.remaining,r=!0,{...i,cache:t}));return r?i:e},vF=(e,t)=>e.findLastIndex(e=>e.role===t),yF=e=>e.type!==`compaction`&&e.type!==`effort`,bF=(e,t,n,r)=>{if(t<0||t>=e.length)return e;let i=e[t];if(i.content.length===0)return e;let a=i.content.findLastIndex(e=>e.type===`text`),o=a>=0?a:i.content.findLastIndex(yF),s=i.content[o];if(!s||!yF(s)||s.cache||r.remaining===0)return e;--r.remaining;let c=i.content.map((e,t)=>t===o?{...s,cache:n}:e),l=new Uj({...i,content:c}),u=e.slice();return u[t]=l,u},xF=(e,t,n,r)=>{if(e.length===0)return e;if(t===`latest-user-message`)return bF(e,vF(e,`user`),n,r);if(t===`latest-assistant`)return bF(e,vF(e,`assistant`),n,r);let i=e.length,a=t.tail;for(;a>0&&i>0;)--i,rF(e[i])===void 0&&--a;let o=e;for(let t=i;t<e.length;t++)rF(e[t])===void 0&&(o=bF(o,t,n,r));return o},SF=e=>gF(e.tools)+e.system.reduce((e,t)=>e+(t.cache===void 0?0:1),0)+e.messages.reduce((e,t)=>e+t.content.reduce((e,t)=>e+(yF(t)&&t.cache!==void 0?1:0),0),0),CF=e=>{let t=wF(e);if(!t.tools&&!t.system&&!t.messages)return e;let n=mF(uF(e)),r={remaining:Math.max(0,4-SF(e))},i=t.tools?hF(e.tools,n,r):e.tools,a=t.system?_F(e.system,n,r):e.system,o=t.messages?xF(e.messages,t.messages,n,r):e.messages;return i===e.tools&&a===e.system&&o===e.messages?e:Zj.update(e,{tools:i,system:a,messages:o})},wF=e=>{let t=e.model.compatibility?.cacheFormat,n=e.model.route.id,r=lF(e.cache);return t===`alibaba`?r?fF:{...cF(e.cache),tools:!1}:t===`anthropic`?cF(e.cache):dF.has(n)?r?n===`openrouter`||n===`vercel-ai-gateway-messages`?pF(e.model.id):n===`alibaba-chat`?e.model.id.toLowerCase().startsWith(`qwen`)?fF:sF:oF:cF(e.cache):sF},TF=`(no tool output)`;function EF(e){let t=[],n=/* @__PURE__ */ new Map,r=[],i=()=>{n.size>0||(t.push(...r),r.length=0)},a=()=>{n.size>0&&t.push(DF(n.values())),n.clear(),i()};for(let o of e)if((o.role===`user`||o.role===`assistant`)&&a(),o.role===`tool`){let e=OF(o,n);e&&t.push(e),i()}else if(o.role===`system`&&n.size>0)r.push(o);else if(t.push(o),o.role===`assistant`)for(let e of o.content)e.type===`tool-call`&&e.providerExecuted!==!0&&n.set(e.id,e);return a(),t.length===e.length&&t.every((t,n)=>t===e[n])?e:t}function DF(e){return new Uj({role:`tool`,content:[...e].map(e=>Rj.make({id:e.id,name:e.name,namespace:e.namespace,result:`Tool result missing`,resultType:`error`}))})}function OF(e,t){let n=e.content.map(e=>{if(e.type!==`tool-result`||e.providerExecuted===!0)return e;let n=t.get(e.id);return n&&t.delete(e.id),kF(e,n)});if(n.length!==0)return n.every((t,n)=>t===e.content[n])?e:new Uj({id:e.id,role:e.role,content:n,metadata:e.metadata,providerMetadata:e.providerMetadata,native:e.native})}function kF(e,t){let n=t===void 0||e.name===t.name&&e.namespace===t.namespace?e:{...e,name:t.name,namespace:t.namespace};if(n.result.type===`text`&&n.result.value===``)return{...n,result:{type:`text`,value:TF}};if(n.result.type===`error`&&n.result.value===``)return{...n,result:{type:`error`,value:TF}};if(n.result.type!==`content`)return n;let r=n.result.value.filter(e=>e.type!==`text`||e.text!==``);return r.length===0?{...n,result:{type:`text`,value:TF}}:r.length===n.result.value.length?n:{...n,result:{type:`content`,value:r}}}var AF=/* @__PURE__ */ n({GeminiJsonSchema:()=>AF,SCHEMA_MAPS:()=>jF,VALUES:()=>MF,mapValues:()=>NF,normalize:()=>IF});const jF=/* @__PURE__ */ new Set([`properties`,`patternProperties`,`$defs`,`definitions`,`dependentSchemas`,`dependencies`]),MF=/* @__PURE__ */ new Set([`const`,`default`,`enum`,`examples`,`dependentRequired`]),NF=(e,t)=>Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n,e)])),PF=e=>{if(Array.isArray(e))return e.map(PF);if(!G(e))return e;let t=G(e.properties)?e.properties:void 0;return Object.fromEntries(Object.entries(e).flatMap(([n,r])=>MF.has(n)?[[n,r]]:jF.has(n)&&G(r)?[[n,NF(r,PF)]]:n===`required`&&t&&Array.isArray(r)?[[n,r.filter(e=>typeof e==`string`&&Object.hasOwn(t,e))]]:n===`exclusiveMinimum`&&typeof r==`boolean`?r&&typeof e.minimum==`number`?[[n,e.minimum]]:[]:n===`exclusiveMaximum`&&typeof r==`boolean`?r&&typeof e.maximum==`number`?[[n,e.maximum]]:[]:n===`minimum`&&e.exclusiveMinimum===!0||n===`maximum`&&e.exclusiveMaximum===!0?[]:n===`items`&&Array.isArray(r)?[[`prefixItems`,r.map(PF)]]:n===`additionalItems`&&Array.isArray(e.items)?[[`items`,PF(r)]]:[[n,PF(r)]]))},FF=(e,t,n)=>{if(Array.isArray(e))return e.map(e=>FF(e,t,n));if(!G(e))return e;if(e.$ref===t&&!n)return{};let r=Array.isArray(e.required)?e.required:[];return NF(e,(i,a)=>MF.has(a)?i:a===`items`?FF(i,t,n||!(Number(e.minItems)>0)):a===`properties`&&G(i)?NF(i,(e,i)=>FF(e,t,n||!r.includes(i))):jF.has(a)&&G(i)?NF(i,e=>FF(e,t,n)):FF(i,t,n))},IF=e=>{let t=PF(e);if(!G(t))return{};let n=FF(NF(t,(e,t)=>(t===`$defs`||t===`definitions`)&&G(e)?NF(e,(e,n)=>FF(e,`#/${t}/${n}`,!1)):e),`#`,!1);return G(n)?n:{}},{SCHEMA_MAPS:LF,VALUES:RF,mapValues:zF}=AF,BF=e=>{let t=e.map(HF);return t.length===0?{}:t.length===1?t[0]:{anyOf:t}},VF=e=>{let t=[...new Set(e.map(e=>e===null?`null`:Array.isArray(e)?`array`:typeof e))];if(t.length===1)return t[0];if(t.length===2&&t.includes(`null`))return[...t.filter(e=>e!==`null`),`null`]},HF=e=>{if(Array.isArray(e))return e.map(HF);if(!G(e))return e;if(typeof e.$ref==`string`)return{$ref:e.$ref};let t=e.type===void 0&&Array.isArray(e.enum)?VF(e.enum):void 0;return Object.fromEntries([...t===void 0?[]:[[`type`,t]],...Object.entries(e).flatMap(([t,n])=>{if(RF.has(t))return[[t,n]];if(LF.has(t)&&G(n))return[[t,zF(n,HF)]];if(t===`items`){if(Array.isArray(e.prefixItems))return[];if(Array.isArray(n))return[[t,BF(n)]]}if(t===`prefixItems`){if(!Array.isArray(n))return`items`in e?[]:[[`items`,{}]];let t=G(e.items)?[e.items]:Array.isArray(e.items)?e.items:[];return[[`items`,BF([...n,...t])]]}return t===`unevaluatedItems`?[]:[[t,HF(n)]]})])},UF=e=>{let t=HF(e);return G(t)?t:{}},WF=IF,GF=[[/gemini/i,`gemini`],[/kimi/i,`moonshot`]],KF=e=>(e.type===void 0||e.type===`object`)&&G(e.not)&&e.not.type===`null`&&Object.keys(e.not).length===1?{type:`object`,...Object.fromEntries(Object.entries(e).filter(([e])=>e!==`not`))}:e.type===void 0?Array.isArray(e.anyOf)&&e.anyOf.some(e=>G(e)&&e.type===`object`&&Object.keys(e).length===1)?{type:`object`,...Object.fromEntries(Object.entries(e).filter(([e])=>e!==`anyOf`))}:{type:`object`,...e}:e,qF=(e,t)=>{let n=KF(e);switch(t.compatibility?.sanitizer??t.route.sanitizer??GF.find(([e])=>e.test(t.id))?.[1]){case`gemini`:return WF(n);case`moonshot`:return UF(n);case`none`:case void 0:return n}},JF=(e,t)=>e.map(e=>e.type===`tool`?new Kj({...e,inputSchema:qF(e.inputSchema,t)}):{...e,tools:JF(e.tools,t)}),YF={gemini:WF,moonshot:UF,tools:JF};function XF(e,t){return t?.mechanism===`trigger`?e.model.route.compact?.trigger!==void 0:t?.mechanism!==void 0&&t.mechanism!==`endpoint`?!1:e.model.route.compact?.endpoint!==void 0}const ZF=(e,t)=>t!==void 0&&t!==`endpoint`&&t!==`trigger`?BP(`Unknown compaction mechanism: ${t}`):VP({operation:t===`trigger`?`compact.trigger`:`compact`,provider:e.model.provider,route:e.model.route.id,message:`${e.model.provider}/${e.model.route.id} does not support ${t===`trigger`?`trigger`:`explicit`} compaction`}),QF=class extends xr()(`@opencode/LLMClient`){},$F=e=>{let t=EF(e.messages),n=t===e.messages?e:Zj.update(e,{messages:t}),r=n.model.route.defaults,i=n.model.defaults,a=_T(r.generation,i?.generation,n.generation);return Zj.update(n,{generation:a??new hT({}),providerOptions:uT(r.providerOptions,i?.providerOptions,n.providerOptions),http:mT(r.http,i?.http,n.http)})},eI=e=>new tj({reason:new ZA({message:`The provider response ended unexpectedly.`,classification:`incomplete-stream`,route:e})});Fy(Cj);const tI=e=>{let t=$F(e),n=Zj.update(t,cP({...Zj.input(t),model:void 0})),r=e=>[...new Map(e.map(e=>[`${e.type}:${e.name}`,e])).values()].map(e=>e.type===`tool`?e:{...e,tools:r(e.tools)}),i=CF(aF(Zj.update(n,{tools:YF.tools(r(n.tools),n.model)}))),a=i.model.route.headers?.({request:i});return a===void 0?i:Zj.update(i,{http:mT(new pT({headers:a}),i.http)})},nI=Xf(`LLM.compile`)(function*(e,t){if(e.messages.flatMap(e=>e.content.flatMap(e=>{if(e.type===`media`){let t=e.media.source;return t.type===`url`?[t.url]:t.type===`ref`?[t.id]:[]}return e.type!==`tool-result`||e.result.type!==`content`?[]:e.result.value.flatMap(e=>e.type===`file`?[e.uri]:[])})).some(e=>/^\s*file:/i.test(e)))return yield*BP(`Local file references must be read with Media.file(path) before sending`);let n=tI(e),r=n.model.route,i=yield*r.body.from(n);return{request:n,route:r,body:i,prepared:yield*r.prepareTransport(i,n,t)}});Xf(`LLM.compileRequest`)(function*(e){let t=yield*nI(e);return{id:t.request.id??`request`,route:t.route.id,protocol:t.route.protocol,model:t.request.model,body:t.body,metadata:{transport:t.route.transport.id}}});const rI=e=>(t,n)=>pC(rf(function*(){let r=yield*nI(t,n);return r.route.streamPrepared(r.prepared,r.request,e,n)})),iI=e=>Xf(`LLM.generate`)(function*(t,n){let r=yield*e(t,n).pipe(EC(YM.empty,YM.reduce));return YM.complete(r)||(yield*eI(`${t.model.provider}/${t.model.route.id}`))});function aI(e,t){return pC(rf(function*(){return(yield*QF).stream(e,t)}))}function oI(e,t){return rf(function*(){return yield*(yield*QF).generate(e,t)})}function sI(e,t){return rf(function*(){let n=yield*QF;return t?.mechanism===`trigger`&&XF(e,t)||(t?.mechanism===void 0||t.mechanism===`endpoint`)&&XF(e)?yield*n.compact(e,t):yield*ZF(e,t?.mechanism)})}const cI={canCompact:XF,compact:sI,Service:QF,layer:Iu(QF,rf(function*(){let e=yield*nj,t=rI({http:e});function n(t,n){return Qd(()=>n?.mechanism===`trigger`&&XF(t,n)?t.model.route.compact.trigger(tI(t),e,n):(n?.mechanism===void 0||n.mechanism===`endpoint`)&&XF(t)?t.model.route.compact.endpoint(tI(t),e,n):ZF(t,n?.mechanism))}return QF.of({stream:t,generate:iI(t),compact:n})})),stream:aI,generate:oI};var lI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,yI)})}};const uI=Ey(e=>e instanceof lI,{expected:`Speech.Model`}),dI=L([j,P({id:j})]).annotate({identifier:`Speech.Voice`}),fI=P({text:j,startSeconds:M,endSeconds:M}).annotate({identifier:`Speech.Timestamp`});W(`Speech.Request`)({model:uI,text:j,voice:O(dI),format:O(j),speed:O(M),language:O(j),instructions:O(j),timestamps:O(N),providerOptions:O(lT),http:O(pT)});var pI=class extends W(`Speech.Response`)({audio:vj,timestamps:O(I(fI)),usage:O(eM),providerMetadata:O(K)}){};const mI=P({type:B(`audio-delta`),chunk:Wb}).annotate({identifier:`Speech.Event.AudioDelta`}),hI=P({type:B(`timestamps`),items:I(fI)}).annotate({identifier:`Speech.Event.Timestamps`}),gI=P({type:B(`finish`),audio:vj,usage:O(eM),providerMetadata:O(K)}).annotate({identifier:`Speech.Event.Finish`}),_I=L([KN,qN,mI,hI,gI]).pipe(V(`type`)),vI=Object.assign(_I,{is:{generationQueued:_I.guards[`generation-queued`],generationProgress:_I.guards[`generation-progress`],audioDelta:_I.guards[`audio-delta`],timestamps:_I.guards.timestamps,finish:_I.guards.finish}}),yI=e=>{let t=e.find(vI.is.finish);if(t===void 0)return sf(/* @__PURE__ */ Error(`The speech stream completed without a finish event`));let n=e.filter(vI.is.timestamps).flatMap(e=>e.items);return x(new pI({audio:t.audio,timestamps:n.length===0?void 0:n,usage:t.usage,providerMetadata:t.providerMetadata}))},bI=class extends xr()(`@opencode/SpeechClient`){},xI={Service:bI,...eP(bI,{modality:`speech`,responseEvents:e=>[...e.timestamps===void 0?[]:[hI.make({items:e.timestamps})],gI.make({audio:e.audio,usage:e.usage,providerMetadata:e.providerMetadata})]})};var SI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,PI)})}};const CI=Ey(e=>e instanceof SI,{expected:`Transcription.Model`}),wI=R([`none`,`segment`,`word`]);W(`Transcription.Request`)({model:CI,audio:vj,language:O(j),prompt:O(j),timestamps:O(wI),diarize:O(N),speakers:O(U),providerOptions:O(lT),http:O(pT)});const TI=P({text:j,startSeconds:M,endSeconds:M,speaker:O(j)}).annotate({identifier:`Transcription.Segment`}),EI=P({text:j,startSeconds:M,endSeconds:M,speaker:O(j),confidence:O(M)}).annotate({identifier:`Transcription.Word`}),DI={text:j,segments:O(I(TI)),words:O(I(EI)),language:O(j),durationSeconds:O(M),usage:O(eM),providerMetadata:O(K)};var OI=class extends W(`Transcription.Response`)(DI){};const kI=P({type:B(`text-delta`),delta:j}).annotate({identifier:`Transcription.Event.TextDelta`}),AI=P({type:B(`segment`),segment:TI}).annotate({identifier:`Transcription.Event.Segment`}),jI=P({type:B(`finish`),...DI}).annotate({identifier:`Transcription.Event.Finish`}),MI=L([KN,qN,kI,AI,jI]).pipe(V(`type`)),NI=Object.assign(MI,{is:{generationQueued:MI.guards[`generation-queued`],generationProgress:MI.guards[`generation-progress`],textDelta:MI.guards[`text-delta`],segment:MI.guards.segment,finish:MI.guards.finish}}),PI=e=>{let t=e.find(NI.is.finish);if(t===void 0)return sf(/* @__PURE__ */ Error(`The transcription stream completed without a finish event`));let{type:n,...r}=t;return x(new OI(r))},FI=class extends xr()(`@opencode/TranscriptionClient`){},II={Service:FI,...eP(FI,{modality:`transcription`,responseEvents:e=>[jI.make({...e})]})};var LI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,KI)})}};const RI=Ey(e=>e instanceof LI,{expected:`Video.Model`}),zI=uj,BI=P({first:O(vj),last:O(vj)}).annotate({identifier:`Video.Frames`});W(`Video.Request`)({model:RI,prompt:j,frames:O(BI),references:O(I(vj)),video:O(vj),durationSeconds:O(M),aspect:O(zI),resolution:O(j),audio:O(N),n:O(U),seed:O(M),negativePrompt:O(j),providerOptions:O(lT),http:O(pT)});var VI=class extends W(`Video.Response`)({videos:I(vj),usage:O(eM),providerMetadata:O(K)}){get video(){return this.videos[0]}};const HI=P({type:B(`video`),index:M,video:vj}).annotate({identifier:`Video.Event.Video`}),UI=P({type:B(`finish`),usage:O(eM),providerMetadata:O(K)}).annotate({identifier:`Video.Event.Finish`}),WI=L([KN,qN,HI,UI]).pipe(V(`type`)),GI=Object.assign(WI,{is:{generationQueued:WI.guards[`generation-queued`],generationProgress:WI.guards[`generation-progress`],video:WI.guards.video,finish:WI.guards.finish}}),KI=e=>{let t=e.find(GI.is.finish);return t===void 0?sf(/* @__PURE__ */ Error(`The video stream completed without a finish event`)):x(new VI({videos:e.filter(GI.is.video).map(e=>e.video),usage:t.usage,providerMetadata:t.providerMetadata}))},qI=class extends xr()(`@opencode/VideoClient`){},JI={Service:qI,...eP(qI,{modality:`video`,responseEvents:e=>[...e.videos.map((e,t)=>HI.make({index:t,video:e})),UI.make({usage:e.usage,providerMetadata:e.providerMetadata})]})},YI=(e=>Bu(cI.layer,FP.layer,JI.layer,xI.layer,II.layer,UN.layer).pipe(Uu(e)))(IN),XI=L([P({type:k(`text`),text:j}),P({type:k(`json`),value:cx}),P({type:k(`media`),media:vj,filename:O(j)})]).pipe(V(`type`)),ZI=L([j,N]),QI=I(L([P({name:j,type:k(`predicate`),instructions:j}),P({name:j,type:k(`choice`),instructions:j,choices:I(P({value:ZI,description:O(j)}))}),P({name:j,type:k(`score`),instructions:j,levels:I(P({label:j,description:O(j)}))})]).pipe(V(`type`))).pipe(ab(e=>e.length>0,{message:`Decision questions must not be empty`}),ab(e=>new Set(e.map(e=>e.name)).size===e.length,{message:`Decision question names must be unique`})),$I=M.check(Ab({minimum:0,maximum:1})),eL=P({name:j,type:k(`predicate`),probability:$I}),tL=P({name:j,type:k(`choice`),choice:ZI,probabilities:I(P({value:ZI,probability:$I})),confidence:$I}),nL=P({name:j,type:k(`score`),score:M,probabilities:I(P({value:U,label:j,probability:$I})),confidence:$I}),rL=L([k(`refusal`),j]),iL=L([eL,tL,nL,P({name:j,type:k(`error`),reason:rL,message:O(j)})]).pipe(V(`type`));var aL=class extends W(`Decision.ModelCompatibility`)({mediaInput:O(R([`assets`,`state`,`root`]))}){};(function(e){e.make=t=>t instanceof e?t:new e(t)})(aL||={});var oL=class e{id;provider;route;http;compatibility;providerOptions;constructor(e){this.id=e.id,this.provider=e.provider,this.route=e.route,this.http=e.http,this.compatibility=e.compatibility,this.providerOptions=e.providerOptions}static make(t){return new e({...t,id:nT.make(t.id),provider:rT.make(t.provider)})}};const sL=Ey(e=>e instanceof oL,{expected:`Decision.Model`});W(`Decision.Request`)({model:sL,input:I(XI),questions:QI,providerOptions:O(lT),http:O(pT)});var cL=class extends W(`Decision.Usage`)({inputTokens:O(M),outputTokens:O(M),totalTokens:O(M),cost:O(M)}){};W(`Decision.Response`)({answers:I(iL),usage:O(cL),providerMetadata:O(K)});const lL=e=>Object.entries(e).map(([e,t])=>new Kj({name:e,description:t._definition.description,inputSchema:t._definition.inputSchema,outputSchema:t._definition.outputSchema,freeform:t._definition.freeform}));function uL(e,t){return dL(e).pipe(C(e=>cI.generate(e,t)))}const dL=e=>e instanceof Zj?x(e):CP(()=>fL(e)),fL=e=>{let{system:t,prompt:n,messages:r,tools:i,toolChoice:a,generation:o,providerOptions:s,http:c,...l}=e;return new Zj({...l,system:Oj.content(t),messages:[...r?.map(Uj.make)??[],...n===void 0?[]:[Uj.user(n)]],tools:i?.map(Jj.make)??[],toolChoice:a?Yj.make(a):void 0,generation:o===void 0?void 0:hT.make(o),providerOptions:s,http:pT.make(c)})},pL=`generate_object`;var mL=class{object;response;constructor(e,t){this.object=e,this.response=t}get events(){return this.response.events}get usage(){return this.response.usage}};Xf(`LLM.generateObject`)(function*(e,t){let n=fL(e),r=Zj.update(n,{tools:lL({[pL]:t}),toolChoice:Yj.named(pL)}),i=yield*cI.generate(r),a=i.toolCalls.find(e=>e.name===pL);return a?new mL(yield*t._decode(a.input).pipe(xf(e=>new tj({reason:new ZA({message:`generateObject: tool input failed schema decode: ${e.message}`,cause:e})}))),i):yield*new tj({reason:new ZA({message:`generateObject: model did not call the forced \`${pL}\` tool`})})});var hL=class extends xr()(`@opencode/ModelResolver`){},gL=class extends xr()(`@opencode/PluginHooks`){};const _L={type:`object`,additionalProperties:!0},vL=aO({id:`yuri.llm`,methods:{ready:{input:{type:`object`,additionalProperties:!1},output:{type:`object`,properties:{version:{type:`integer`}},required:[`version`],additionalProperties:!1}},generate:{input:{type:`object`,properties:{providerID:{type:`string`,minLength:1},modelID:{type:`string`,minLength:1},variant:{type:`string`},messages:{type:`array`,minItems:1,items:_L},tools:{type:`array`,items:_L},cacheKey:{type:`string`,minLength:1,maxLength:256},maxOutputTokens:{type:`integer`,minimum:1}},required:[`providerID`,`modelID`,`messages`,`cacheKey`],additionalProperties:!1},output:_L,errors:{unavailable:_L,generation_failed:_L}}},events:{}}),yL=[`messages`,`input`,`system`,`instructions`,`tools`,`tool_choice`],bL=()=>Object.assign(/* @__PURE__ */ Error(`External OpenCode clean inference runtime is unavailable or incompatible`),{code:`unavailable`}),xL=e=>{let t=e?.reason,n=/* @__PURE__ */ new Set([`Authentication`,`RateLimit`,`QuotaExceeded`,`InvalidRequest`,`ProviderConfiguration`,`UnsupportedOperation`,`NoRoute`,`ContentPolicy`,`ProviderInternal`,`Transport`,`Timeout`,`InvalidProviderOutput`,`UnknownProvider`]);return{reason:n.has(t?._tag)?t._tag:`UnknownProvider`,...Number.isInteger(t?.http?.status)?{status:t.http.status}:{},...n.has(t?._tag)?{}:{diagnostic:e?.message?.includes(`Schema validation failed`)?`runtime_schema_mismatch`:e?.message?.includes(`Service not found`)?`missing_runtime_service`:e?.name===`TypeError`?`type_error`:e?.name===`ReferenceError`?`reference_error`:`unclassified`}}},SL=e=>{if(e.role===`tool`)return Uj.tool({id:e.tool_call_id,name:e.name,result:{type:`text`,value:e.content}});if(e.role===`assistant`)return Uj.assistant([...e.content?[Uj.text(e.content)]:[],...(e.tool_calls??[]).map(e=>({type:`tool-call`,id:e.id,name:e.function.name,input:JSON.parse(e.function.arguments)}))]);let t=[Uj.text(e.content)];for(let n of e.parts??[])if(n.mime?.startsWith(`image/`)){let e=n.url.indexOf(`,`);t.push(Uj.media(Sj(n.url.slice(e+1),n.mime)))}else t.push(Uj.text(`[file: ${n.filename||n.mime}] ${n.url}`));return Uj.user(t)},CL=Ef().pipe(C(e=>{let t=Yr(e,hL),n=Yr(e,gL);return t._tag===`Some`&&typeof t.value.resolve==`function`&&n._tag===`Some`&&typeof n.value.trigger==`function`?x({resolver:t.value,hooks:n.value}):S(bL())})),wL=t=>rf(function*(){let{resolver:n,hooks:r}=yield*CL,i=yield*n.resolve({providerID:t.providerID,id:t.modelID,...t.variant?{variant:t.variant}:{}});if(!i||[i.model.defaults?.http?.body,i.model.route.defaults?.http?.body].some(e=>yL.some(t=>Object.hasOwn(e??{},t))))return yield*S(bL());let a={sessionID:`ses_${e(`sha256`).update(t.cacheKey).digest(`hex`)}`,agent:`yuri-inference`,model:i.ref,kind:`generate`},o=fL({model:wT.make(i.model),system:t.messages.filter(e=>e.role===`system`).map(e=>e.content).join(`
|
|
7
|
+
`)}return t},Jr=/*#__PURE__*/ o(2,(e,t)=>{let n=Ar(e,t.key);return n===kr?Fr(t)?ur(Kr(t)):lr():ur(n)}),Yr=/*#__PURE__*/ o(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:Or(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),Xr=(...e)=>{let t=/* @__PURE__ */ new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return jr(t)},Zr=br,Qr=e=>e.length>0,$r=e=>e>0?Math.floor(e):0,ei=e=>Math.max(1,$r(e)),ti=Qn,ni=Xn,ri=e=>{if(pe(e))try{return ti(e())}catch(e){return ni(e)}try{return ti(e.try())}catch(t){return ni(e.catch(t))}},ii=qn,ai=Jn,oi=/*#__PURE__*/ o(2,(e,t)=>ai(e)?ti(t(e.success)):e),si=/*#__PURE__*/ o(2,(e,{onFailure:t,onSuccess:n})=>ii(e)?t(e.failure):n(e.success)),ci=kn,li=e=>{let t=e[Symbol.iterator]().next();if(t.done)throw Error(`headUnsafe: empty iterable`);return t.value},ui=/*#__PURE__*/ o(2,(e,t)=>Object.hasOwn(e,t)),di=/*#__PURE__*/ o(2,(e,t)=>{let n={...e};for(let r of fi(e))Et(n,r,t(e[r],r));return n}),fi=e=>Object.keys(e),pi=e=>o(2,(t,n)=>{for(let r of fi(t))if(!ui(n,r)||!e(t[r],n[r]))return!1;return!0}),mi=e=>{let t=pi(e);return(e,n)=>t(e,n)&&t(n,e)},hi=globalThis.Array,gi=e=>hi.isArray(e)?e:hi.from(e),_i=/*#__PURE__*/ o(2,(e,t)=>[...e,t]);hi.isArray;const vi=Qr,yi=Qr,bi=()=>[],xi=e=>[e],Si=/*#__PURE__*/ o(2,(e,t)=>e.map(t)),Ci=An,wi=`~effect/Duration`,Ti=/*#__PURE__*/ BigInt(0),Ei=/*#__PURE__*/ BigInt(1),Di=/*#__PURE__*/ BigInt(2),Oi=/*#__PURE__*/ BigInt(10),ki=/*#__PURE__*/ BigInt(24),Ai=/*#__PURE__*/ BigInt(60),ji=/*#__PURE__*/ BigInt(1e3),Mi=/*#__PURE__*/ BigInt(1e6),Ni=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),Pi=e=>Ni(e*1e6),Fi=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=Oi**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t,s=o/a+(o%a*Di>=a?Ei:Ti);return r?-s:s},Ii=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,Li=e=>{switch(typeof e){case`number`:return $i(e);case`bigint`:return Qi(e);case`string`:{if(e===`Infinity`)return Xi;if(e===`-Infinity`)return Zi;let t=Ii.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return Qi(Fi(r,Ei));if(i===`micro`||i===`micros`)return Qi(Fi(r,ji));let a=Number(r);switch(i){case`milli`:case`millis`:return $i(a);case`second`:case`seconds`:return ea(a);case`minute`:case`minutes`:return ta(a);case`hour`:case`hours`:return na(a);case`day`:case`days`:return ra(a);case`week`:case`weeks`:return ia(a)}break}case`object`:{if(e===null)break;if(wi in e)return e;if(Array.isArray(e))return e.length!==2||!e.every(ce)?Ri(e):Number.isNaN(e[0])||Number.isNaN(e[1])?Yi:e[0]===-1/0||e[1]===-1/0?Zi:e[0]===1/0||e[1]===1/0?Xi:Wi(Ni(e[0]*1e9+e[1]));let t=e,n=0;return 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?Wi(n):Wi(Ni(n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0)))}}return Ri(e)},Ri=e=>{throw Error(`Invalid Input: ${e}`)},zi=/*#__PURE__*/ _r(Li),Bi={_tag:`Millis`,millis:0},Vi={_tag:`Infinity`},Hi={_tag:`NegativeInfinity`},Ui={[wi]:wi,[be](){switch(this.value._tag){case`Millis`:{let e=this.value.millis*1e6;return Number.isFinite(e)?m(Ni(e)):Ee(this.value.millis)}case`Nanos`:return m(this.value.nanos);default:return ke(this.value)}},[Re](e){return Gi(e)&&pa(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`}}},[_t](){return this.toJSON()},pipe(){return r(this,arguments)}},Wi=e=>{let t=Object.create(Ui);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?Bi:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:Pi(e)}:e>0?Vi:Hi:e===Ti?Bi:{_tag:`Nanos`,nanos:e},t},Gi=e=>p(e,wi),Ki=e=>{switch(e.value._tag){case`Millis`:return e.value.millis===0;case`Nanos`:return e.value.nanos===Ti;case`Infinity`:case`NegativeInfinity`:return!1}},qi=e=>{switch(e.value._tag){case`Millis`:return e.value.millis<0;case`Nanos`:return e.value.nanos<Ti;case`NegativeInfinity`:return!0;case`Infinity`:return!1}},Ji=e=>{switch(e.value._tag){case`Infinity`:case`NegativeInfinity`:return Xi;case`Millis`:return e.value.millis<0?Wi(-e.value.millis):e;case`Nanos`:return e.value.nanos<Ti?Wi(-e.value.nanos):e}},Yi=/*#__PURE__*/ Wi(0),Xi=/*#__PURE__*/ Wi(1/0),Zi=/*#__PURE__*/ Wi(-1/0),Qi=e=>Wi(e),$i=e=>Wi(e),ea=e=>Wi(e*1e3),ta=e=>Wi(e*6e4),na=e=>Wi(e*36e5),ra=e=>Wi(e*864e5),ia=e=>Wi(e*6048e5),aa=e=>sa(Li(e),{onMillis:s,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),oa=e=>{let t=Li(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 Pi(t.value.millis)}},sa=/*#__PURE__*/ o(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)()}}),ca=/*#__PURE__*/ o(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(oa(e),t.value.nanos):n.onNanos(e.value.nanos,oa(t))),la=/*#__PURE__*/ $n((e,t)=>ca(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})),ua=(e,t)=>ca(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),da=/*#__PURE__*/ sr(la),fa=/*#__PURE__*/ cr(la),pa=/*#__PURE__*/ o(2,(e,t)=>ua(e,t)),ma=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=oa(e),n=t<Ti,r=n?-t:t,i=r/Mi,a=i/ji,o=a/Ai,s=o/Ai,c=s/ki,l=n?-1:1;return{days:l*Number(c),hours:l*Number(s%ki),minutes:l*Number(o%Ai),seconds:l*Number(a%Ai),millis:l*Number(i%ji),nanos:l*Number(r%Mi)}},ha=e=>{if(e.value._tag===`Infinity`)return`Infinity`;if(e.value._tag===`NegativeInfinity`)return`-Infinity`;if(Ki(e))return`0`;if(qi(e))return`-`+ha(Ji(e));let t=ma(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(` `)},ga=/*#__PURE__*/ Zr(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new xa}),_a=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},va=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},ya=e=>{try{return va(e)}catch{return _a(e)}};var ba=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}},xa=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?_a:ya)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new Sa(this.setImmediate)}},Sa=class{tasks=/*#__PURE__*/ new ba;running=void 0;setImmediate;constructor(e=ya){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 Ca=/*#__PURE__*/ Zr(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),wa=/*#__PURE__*/ Zr(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),Ta=class extends a{constructor(e){super(),e&&Dt(this,e)}},Ea=vn,Da=`~effect/encoding/EncodingError`;var Oa=class extends (/*#__PURE__*/ Ea(`EncodingError`)){[Da]=Da};const ka=e=>{switch(e){case 16:return Ma();case 32:return Na();default:{let t=``;for(let n=e>>>3;n>0;n--)t+=ja();return t}}},v=/*#__PURE__*/ Uint8Array.from(`0123456789abcdef`,e=>e.charCodeAt(0)),Aa=()=>Math.random()*4294967296>>>0,ja=()=>{let e=Aa();return String.fromCharCode(v[e>>>28],v[e>>>24&15],v[e>>>20&15],v[e>>>16&15],v[e>>>12&15],v[e>>>8&15],v[e>>>4&15],v[e&15])},Ma=()=>{let e=Aa(),t=Aa();return String.fromCharCode(v[e>>>28],v[e>>>24&15],v[e>>>20&15],v[e>>>16&15],v[e>>>12&15],v[e>>>8&15],v[e>>>4&15],v[e&15],v[t>>>28],v[t>>>24&15],v[t>>>20&15],v[t>>>16&15],v[t>>>12&15],v[t>>>8&15],v[t>>>4&15],v[t&15])},Na=()=>{let e=Aa(),t=Aa(),n=Aa(),r=Aa();return String.fromCharCode(v[e>>>28],v[e>>>24&15],v[e>>>20&15],v[e>>>16&15],v[e>>>12&15],v[e>>>8&15],v[e>>>4&15],v[e&15],v[t>>>28],v[t>>>24&15],v[t>>>20&15],v[t>>>16&15],v[t>>>12&15],v[t>>>8&15],v[t>>>4&15],v[t&15],v[n>>>28],v[n>>>24&15],v[n>>>20&15],v[n>>>16&15],v[n>>>12&15],v[n>>>8&15],v[n>>>4&15],v[n&15],v[r>>>28],v[r>>>24&15],v[r>>>20&15],v[r>>>16&15],v[r>>>12&15],v[r>>>8&15],v[r>>>4&15],v[r&15])},Pa=`effect/Tracer/ParentSpan`;var Fa=class extends (/*#__PURE__*/ br()(Pa,{fiberCached:!0})){};const Ia=e=>e,La=/*#__PURE__*/ Zr(`effect/Tracer/DisablePropagation`,{defaultValue:u}),Ra=/*#__PURE__*/ Zr(`effect/Tracer/CurrentTraceLevel`,{defaultValue:()=>`Info`}),za=/*#__PURE__*/ Zr(`effect/Tracer/MinimumTraceLevel`,{defaultValue:()=>`All`}),Ba=/*#__PURE__*/ Ia({span:e=>new Va(e)});var Va=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??=gr(this.parent)?.traceId??ka(32)}get spanId(){return this._spanId??=ka(16)}get attributes(){return this._attributes??=/* @__PURE__ */ new Map}get events(){return this._events??=[]}end(e,t){this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime}}attribute(e,t){this.attributes.set(e,t)}event(e,t,n){this.events.push([e,t,n??{}])}addLinks(e){this.links.push(...e)}};const Ha=/*#__PURE__*/ Zr(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:d}),Ua=/*#__PURE__*/ Zr(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:l}),Wa=/*#__PURE__*/ Zr(`effect/References/TracerTimingEnabled`,{defaultValue:l}),Ga=/*#__PURE__*/ Zr(`effect/References/TracerSpanAnnotations`,{defaultValue:()=>({})}),Ka=/*#__PURE__*/ Zr(`effect/References/TracerSpanLinks`,{defaultValue:()=>[]}),qa=/*#__PURE__*/ Zr(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Ja=/*#__PURE__*/ Zr(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Ya=e=>{if(e?.captureStackTrace===!1||e?.captureStackTrace!==void 0&&typeof e.captureStackTrace!=`boolean`)return e;let t=St();if(t===0&&e?.captureStackTrace!==!0)return{...e,captureStackTrace:!1};Ct(3);let n=/* @__PURE__ */ Error();return Ct(t),{...e,captureStackTrace:Za(()=>n.stack)}},Xa=e=>t=>{let n;return()=>{if(n!==void 0)return n;let r=t();if(!r)return;let i=r.split(`
|
|
8
|
+
`);if(i[e]!==void 0)return n=i[e].trim(),n}},Za=/*#__PURE__*/ Xa(3);var Qa=class extends Kt{constructor(e,t=qt){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[Re](e){return an(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[be](){return Ce(De(`${this._tag}:${this.fiberId}`))(xe(this.annotations))}};const $a=e=>new Wt([new Qa(e)]),eo=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return ti(n.error)}return ni(e)},to=e=>e.reasons.some(an),no=e=>{let t;for(let n=0;n<e.reasons.length;n++){let r=e.reasons[n];r._tag===`Interrupt`&&(t??=/* @__PURE__ */ new Set,r.fiberId!==void 0&&t.add(r.fiberId))}return t?ti(t):ni(e)},ro=/*#__PURE__*/ o(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>nn(e)?(n=!0,new Jt(t(e.error),e.annotations)):e);return n?Yt(r):e}),io=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},ao=`~effect/Fiber`,oo={_A:s,_E:s},so={id:0},co=/*#__PURE__*/ (()=>{try{return globalThis.process?.getBuiltinModule?.(`node:async_hooks`)?.AsyncResource}catch{return}})(),lo=()=>co===void 0?void 0:new co(`effect/Fiber`),uo=()=>globalThis[st];var fo=class{constructor(e,t=!0){this.setContext(e),this.id=++so.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._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[ao](){return oo}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return Wr(this.context,e)}addObserver(e){return this._exit?(e(this._exit),f):(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=$a(e);this.cache.stackFrame&&(n=tn(n,Rr(dn,this.cache.stackFrame))),t&&(n=tn(n,t)),this._interruptedCause=this._interruptedCause?Zt(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(To(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._asyncContext!==void 0){let t=this._asyncContext;return this._asyncContext=void 0,t.runInAsyncScope(this.evaluate,this,e)}if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===It){this._asyncContext=lo();return}let n=go.interruptChildren&&go.interruptChildren(this);if(n!==void 0)return this.evaluate(x(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=Ir()}runLoop(e){let t=globalThis[st];globalThis[st]=this;let n=this._running;this._running=!0;let r=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=To(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!r&&!e.preventYield&&e.scheduler.shouldYield(this)){r=!0;let e=i;i=x(ko,()=>e)}if(i=e.tracerContext?e.tracerContext(i,this):i[Mt](this),i===It){let e=this._yielded;if(`~effect/Exit`in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return It}}}catch(e){return p(i,`~effect/Effect/evaluate`)?this.runLoop(hn(e)):hn(`Fiber.runLoop: Not a valid effect: ${String(i)}`)}finally{this._running=n,globalThis[st]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,mo;for(;;){let t=this._stack.pop();if(!t)return;let n=t[Ft];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&ho-1))return un(e);let t=this.getCont(Nt);return t?t[Nt](e,this):this.yieldWith(un(e))}yieldWith(e){return this._yielded=e,It}children(){return this._children??=/* @__PURE__ */ new Set}pipe(){return r(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Nr(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=po(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 po=e=>{let t=Hr(e,`effect/Tracer`);return{scheduler:Wr(e,ga),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:Wr(e,Ua),span:Hr(e,Pa),logLevel:Wr(e,qa),minimumLogLevel:Wr(e,Ja),stackFrame:Wr(e,Ha),runtimeMetrics:Hr(e,`effect/Metric/FiberRuntimeMetrics`),maxOpsBeforeYield:Wr(e,Ca),preventYield:Wr(e,wa)}},mo={[Nt](e,t){return To(t._interruptedCause)},[Pt](e,t){return To(t._interruptedCause)}},ho=32,go={interruptChildren:void 0},_o=e=>{if(!e.cache.stackFrame)return;let t=/* @__PURE__ */ new Map;return t.set(fn.key,e.cache.stackFrame),jr(t)},vo=e=>{if(e._children!==void 0&&e._children.size!==0)return wo(e._children)},yo=e=>{let t=e;return t._exit?y(t._exit):Vo(n=>t._exit?n(y(t._exit)):Do(e.addObserver(e=>n(y(e)))))},bo=e=>Vo(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();else{i=e.value.addObserver(e=>{r.push(e),a()});return}t(y(r))}return a(),Do(()=>i?.())}),xo=e=>{let t=e;return t._exit?t._exit:Vo(n=>t._exit?n(t._exit):Do(e.addObserver(n)))},So=e=>_(t=>Co(e,t.id)),Co=/*#__PURE__*/ o(e=>p(e[0],ao),(e,t,n)=>_(r=>{let i=_o(r);return i=i&&n?Yr(i,n):i??n,e.interruptUnsafe(t,i),fs(yo(e))})),wo=e=>_(t=>{let n=_o(t),r=bi();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return fs(bo(r))}),y=un,To=pn,Eo=mn,Do=/*#__PURE__*/ cn({op:`Sync`,[Mt](e){let t=this[g](),n=e.getCont(Nt);return n?n[Nt](t,e):e.yieldWith(un(t))}}),b=/*#__PURE__*/ cn({op:`Suspend`,[Mt](e){return this[g]()}}),Oo=/*#__PURE__*/ si({onFailure:Eo,onSuccess:y}),ko=/*#__PURE__*/ (/* @__PURE__ */ cn({op:`Yield`,[Mt](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(Ds)},this[`~effect/Effect/args`]??0),e.yieldWith(()=>{t=!0})}}))(0),Ao=/*#__PURE__*/ y(/*#__PURE__*/ lr()),jo=e=>b(()=>To(e())),Mo=e=>hn(e),No=e=>b(()=>Eo(e())),Po=/*#__PURE__*/ y(void 0),Fo=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new Ul(e,`An error occurred in Effect.try`):e.catch;return b(()=>{try{return y(t())}catch(e){return Eo(n(e))}})},Io=e=>zo(function(t,n){e(n).then(e=>t(y(e)),e=>t(Mo(e)))},e.length!==0),Lo=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new Ul(e,`An error occurred in Effect.tryPromise`):e.catch;return zo(function(e,r){let i=e=>b(()=>{try{return Eo(Tt(()=>n(e)))}catch(e){return Mo(e)}});try{t(r).then(t=>e(y(t)),t=>e(i(t)))}catch(t){e(i(t))}},t.length!==0)},Ro=e=>_(t=>e(t.id)),zo=/*#__PURE__*/ function(){let e=/*#__PURE__*/ sn({op:`Async`,[Mt](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._yielded=()=>{t=!0},r===void 0&&i===void 0||e._stack.push(Bo(()=>(t=!0,r?.abort(),i??Ds))),It):n}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),Bo=/*#__PURE__*/ cn({op:`AsyncFinalizer`,[Ft](e){e.interruptible&&(e.interruptible=!1,e._stack.push(Vc))},[Pt](e,t){return to(e)?x(mc(pn(e),this[g]()),()=>To(e)):To(e)}}),Vo=e=>zo(e,e.length>=2),Ho=/*#__PURE__*/ Vo(f),Uo=(...e)=>{if(e.length===1){let t=e[0];return b(()=>Zo(t()))}let[t,n]=e;return b(()=>Zo(n.call(t.self)))},Wo=(e,...t)=>{let n=t.length===0?function(){return b(()=>Zo(e.apply(this,arguments)))}:function(){let n=b(()=>Zo(e.apply(this,arguments)));for(let e=0;e<t.length;e++)n=t[e](n,...arguments);return n};return Go(e.length,n)},Go=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),Ko=/*#__PURE__*/ Xa(2),qo=function(){let e=typeof arguments[0]==`string`,t=e?arguments[0]:`Effect.fn`,n=e?arguments[1]:void 0,r=St(),i;return r!==0&&(Ct(2),i=new globalThis.Error,Ct(r)),e?(r,...a)=>Jo(t,r,i,a,e,n):Jo(t,arguments[0],i,Array.prototype.slice.call(arguments,1),e,n)},Jo=(e,t,n,r,i,a)=>{let o=typeof t==`function`?t:r.shift().bind(t.self),s=`${e} (definition)`,c=n?Ko(()=>n.stack):d;return Go(o.length,function(...t){let n=b(()=>{let e=o.apply(this,arguments);return zt(e)?e:Zo(e)});for(let e=0;e<r.length;e++)n=r[e](n,...t);if(!zt(n))return n;let l=St(),u;return l!==0&&(Ct(2),u=new globalThis.Error,Ct(l)),Ps(i?Tl(e,a,e=>El(n,e)):n,Ha,t=>({name:e,stack:u?Ko(()=>u.stack):d,parent:{name:s,stack:c,parent:t}}))})},Yo=(e,...t)=>Go(e.length,t.length===0?function(){return Xo(()=>e.apply(this,arguments))}:function(){let n=Xo(()=>e.apply(this,arguments));for(let e of t)n=e(n,...arguments);return n}),Xo=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return y(r.value);let i=r.value;if(i&&i._tag===`Success`)n=i.value;else{if(i&&i._tag===`Failure`)return r.value;{let n=!0;return b(()=>n?(n=!1,x(r.value,e=>Zo(t,e))):b(()=>Zo(e())))}}}}catch(e){return Mo(e)}},Zo=/*#__PURE__*/ function(){let e=/*#__PURE__*/ sn({op:`Iterator`,[Nt](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return y(r.value);if(!hs(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[Mt](e){return this[Nt](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)}}(),Qo=/*#__PURE__*/ o(2,(e,t)=>new ts(e,ns,y(t))),$o=function(e){return e._stack.push(this),this[g]},es=/*#__PURE__*/ sn({op:`OnSuccess`,[Mt]:$o}),ts=function(e,t,n){this[g]=e,this[Nt]=t,this.payload=n};ts.prototype=es;const ns=function(){return this.payload},rs=function(e,t){return t.succeedWith(this.payload)},is=/*#__PURE__*/ (()=>{let e=`~effect/Effect/stackProbe`;return{[e]:function(){return(/* @__PURE__ */ Error()).stack}}[e]()?.includes(`[as `+e+`]`)===!0})(),as=function(e,t){let n=this.payload;return t.succeedWith(is?n(e):Tt(()=>n(e)))},os=function(e){let t=this.payload;return t(e)},ss=function(e){let t=this.payload;return new ts(t(e),rs,e)},cs=function(e){return new ts(this.payload,rs,e)},ls=e=>vs(e,ur),us=/*#__PURE__*/ o(2,(e,t)=>new ts(e,zt(t)?ns:os,t)),ds=/*#__PURE__*/ o(2,(e,t)=>new ts(e,zt(t)?cs:ss,t)),fs=e=>new ts(e,ns,Ds),ps=(e,t)=>_(n=>{let r=/* @__PURE__ */ new Set;return Ac(n,()=>r.size===0?void 0:wo(r)),Vo(i=>{let a=!1,o=0;for(let s of e){if(a)break;let e=o++,c=rl(n,s,!0,!0,!1);r.add(c),c.addObserver(o=>{r.delete(c);let s=!a;a=!0,i(o),s&&t?.onWinner&&t.onWinner({fiber:c,index:e,parentFiber:n})})}})}),ms=/*#__PURE__*/ o(e=>zt(e[1]),(e,t,n)=>ps([e,t],n)),x=/*#__PURE__*/ o(2,(e,t)=>new ts(e,os,t)),hs=e=>e[kt]!==void 0,gs=/*#__PURE__*/ o(2,(e,t)=>hs(e)?e._tag===`Success`?t(e.value):e:x(e,t)),_s=e=>x(e,s),vs=/*#__PURE__*/ o(2,(e,t)=>new ts(e,as,t)),ys=/*#__PURE__*/ o(2,(e,t)=>hs(e)?Os(e,t):vs(e,t)),bs=/*#__PURE__*/ o(2,(e,t)=>hs(e)?ks(e,t):qs(e,t)),xs=/*#__PURE__*/ o(2,(e,t)=>hs(e)?As(e,t):Js(e,t)),Ss=/*#__PURE__*/ o(2,(e,t)=>{if(hs(e)){if(e._tag===`Success`)return e;let n=eo(e.cause);return ii(n)?e:t(n.success)}return Ks(e,t)}),Cs=e=>pn($a(e)),ws=e=>e._tag===`Success`,Ts=e=>e._tag===`Failure`?ti(e.cause):ni(e),Es=e=>e._tag===`Failure`&&to(e.cause),Ds=/*#__PURE__*/ un(void 0),Os=/*#__PURE__*/ o(2,(e,t)=>e._tag===`Success`?un(t(e.value)):e),ks=/*#__PURE__*/ o(2,(e,t)=>{if(e._tag===`Success`)return e;let n=eo(e.cause);return ii(n)?e:mn(t(n.success))}),As=/*#__PURE__*/ o(2,(e,t)=>{if(e._tag===`Success`)return un(t.onSuccess(e.value));let n=eo(e.cause);return ii(n)?e:mn(t.onFailure(n.success))}),js=/*#__PURE__*/ o(2,(e,t)=>ws(e)?t:e),Ms=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?Ds:pn(Yt(t))},Ns=/*#__PURE__*/ o(2,(e,t)=>_(n=>{let r=n.context,i=t(r);return r===i||(n.setContext(i),Ac(n,()=>{n.setContext(r)})),e})),Ps=/*#__PURE__*/ o(3,(e,t,n)=>Ns(e,e=>{let r=Ur(e,t),i=n(r);return r===i?e:zr(e,t,i)})),Fs=()=>Is,Is=/*#__PURE__*/ _(e=>y(e.context)),Ls=e=>_(t=>e(t.context)),Rs=/*#__PURE__*/ o(2,(e,t)=>hs(e)?e:Ns(e,Yr(t))),zs=function(){return arguments.length===1?o(2,(e,t)=>Bs(e,arguments[0],t)):o(3,(e,t,n)=>Bs(e,t,n)).apply(this,arguments)},Bs=(e,t,n)=>Ns(e,zr(t,n)),Vs=/*#__PURE__*/ o(e=>zt(e[0]),(e,t)=>Jc({while:l,body:c(t?.disableYield?e:x(e,e=>ko)),step:f})),Hs=/*#__PURE__*/ o(2,(e,t)=>new Ws(e,t.length===1?t:e=>t(e))),Us=/*#__PURE__*/ sn({op:`OnFailure`,[Mt]:$o}),Ws=function(e,t){this[g]=e,this[Pt]=t};Ws.prototype=Us;const Gs=/*#__PURE__*/ o(3,(e,t,n)=>Hs(e,e=>{let r=t(e);return ii(r)?To(r.failure):n(r.success,e)})),Ks=/*#__PURE__*/ o(2,(e,t)=>Gs(e,eo,e=>t(e))),qs=/*#__PURE__*/ o(2,(e,t)=>Ks(e,e=>No(()=>t(e)))),Js=/*#__PURE__*/ o(2,(e,t)=>tc(e,{onFailure:e=>No(()=>t.onFailure(e)),onSuccess:e=>Do(()=>t.onSuccess(e))})),Ys=e=>rc(e,{onFailure:ni,onSuccess:ti}),Xs=/*#__PURE__*/ o(2,(e,t)=>new Qs(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Zs=/*#__PURE__*/ sn({op:`OnSuccessAndFailure`,[Mt]:$o}),Qs=function(e,t,n){this[g]=e,this[Nt]=t,this[Pt]=n};Qs.prototype=Zs;const $s=function(e,t){let n=this.payload;return t.succeedWith(is?n.onSuccess(e):Tt(()=>n.onSuccess(e)))},ec=/*#__PURE__*/ ((e,t)=>{let n=sn({op:e,[Mt]:$o,[Nt]:$s,[Pt]:t}),r=function(e,t){this[g]=e,this.payload=t};return r.prototype=n,r})(`Match`,function(e,t){let n=e.reasons.find(nn);if(n===void 0)return To(e);let r=this.payload;return t.succeedWith(is?r.onFailure(n.error):Tt(()=>r.onFailure(n.error)))}),tc=/*#__PURE__*/ o(2,(e,t)=>Xs(e,{onFailure:e=>{let n=e.reasons.find(nn);return n?t.onFailure(n.error):To(e)},onSuccess:t.onSuccess})),nc=/*#__PURE__*/ o(2,(e,t)=>new ec(e,t)),rc=/*#__PURE__*/ o(2,(e,t)=>{if(hs(e)){if(e._tag===`Success`)return un(t.onSuccess(e.value));let n=eo(e.cause);return ii(n)?e:un(t.onFailure(n.success))}return nc(e,t)}),ic=e=>hs(e)?un(e):ac(e),ac=/*#__PURE__*/ cn({op:`Exit`,[Mt](e){return e._stack.push(this),this[g]},[Nt](e,t,n){return t.succeedWith(n??un(e))},[Pt](e,t,n){return t.succeedWith(n??pn(e))}}),oc=/*#__PURE__*/ o(2,(e,t)=>x(sc(e,t.duration),e=>dr(e)?t.orElse():y(e.value))),sc=/*#__PURE__*/ o(2,(e,t)=>ms(ls(e),Qo(Fl(t),lr()))),cc=`~effect/Scope`,lc=`~effect/Scope/Closeable`,uc=/*#__PURE__*/ br(`effect/Scope`),dc=(e,t)=>_(n=>{let r=fc(e,t);return r===void 0?Po:(Wc(n),r)}),fc=(e,t)=>{let n=e.state;if(n._tag===`Closed`||(e.state={_tag:`Closed`,exit:t},e.parent!==void 0&&bc(e.parent,e),n._tag===`Empty`))return;if(n.finalizer!==void 0)return pc(n.finalizer,t);let r=n.finalizers;return r.size===1?pc(r.values().next().value,t):hc(e,r,t)},pc=(e,t)=>{try{return e(t)}catch(e){return hn(e)}},mc=(e,t)=>ws(e)?t:Hs(t,t=>To(Zt(e.cause,t))),hc=/*#__PURE__*/ Wo(function*(e,t,n){let r=[],i=[],a=Array.from(t.values()),o=uo();for(let t=a.length-1;t>=0;t--){let s=a[t];e.strategy===`sequential`?r.push(yield*ic(pc(s,n))):i.push(rl(o,pc(s,n),!0,!0,`inherit`))}return i.length>0&&(r=yield*bo(i)),yield*Ms(r)}),gc=(e,t)=>{let n=Sc(t,e);return e.state._tag===`Closed`?(n.state=e.state,n):(yc(e,n,e=>dc(n,e)),n)},_c=(e,t)=>b(()=>e.state._tag===`Closed`?t(e.state.exit):(yc(e,{},t),Po)),vc=(e,t)=>_c(e,c(t)),yc=(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=/* @__PURE__ */ new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0),r.finalizers.set(t,n)}},bc=(e,t)=>{if(e.state._tag!==`Open`)return;let n=e.state;n.finalizerKey===t?e.state=Cc:n.finalizers!==void 0&&(n.finalizers.delete(t),n.finalizers.size===0&&(e.state=Cc))},xc=e=>Sc(e,void 0),Sc=(e=`sequential`,t)=>({[lc]:lc,[cc]:cc,strategy:e,parent:t,state:Cc}),Cc={_tag:`Empty`},wc=uc,Tc=/*#__PURE__*/ zs(uc),Ec=e=>b(()=>{let t=xc();return jc(e(t),e=>b(()=>fc(t,e)??Po))}),Dc=(e,t,n)=>Ls(r=>Kc(i=>x(wc,a=>ds(n?.interruptible?i(e):e,e=>_c(a,n=>Rs(t(e,n),r)))))),Oc=/*#__PURE__*/ function(){let e=/*#__PURE__*/ sn({op:`OnExit`,[Mt](e){return e._stack.push(this),this.effect},[Ft](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(Vc),e.interruptible=!1)},[Nt](e,t,n){n??=un(e);let r;try{r=this.onExit(n)}catch(e){r=hn(e)}return r?x(r,e=>n):n},[Pt](e,t,n){n??=pn(e);let r;try{r=this.onExit(n)}catch(e){r=hn(e)}return r?x(mc(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,t}(),kc=(e,t,n)=>new Oc(e,t,n),Ac=(e,t)=>{e._stack.push(new Oc(void 0,t,void 0))},jc=/*#__PURE__*/ o(2,kc),Mc=/*#__PURE__*/ o(3,(e,t,n)=>jc(e,e=>{let r=t(e);return ii(r)?Po:n(r.success,e)})),Nc=/*#__PURE__*/ o(2,(e,t)=>Mc(e,Ts,t)),Pc=/*#__PURE__*/ o(3,(e,t,n)=>jc(e,e=>{if(e._tag!==`Failure`)return Po;let r=t(e.cause);return ii(r)?Po:n(r.success,e.cause)})),Fc=/*#__PURE__*/ o(2,(e,t)=>Pc(no,t)(e)),Ic=/*#__PURE__*/ c(1/0),Lc=(e,t)=>{let n=0,r,i,a=(e,t)=>(t.awaiters++,Ac(e,()=>{if(!(--t.awaiters>0||i!==t))return i=void 0,So(t.fiber)}),xo(t.fiber));return[_(o=>{if(i!==void 0)return a(o,i);if(r!==void 0&&(n===1/0||o.getRef(Ol).currentTimeMillisUnsafe()<n))return r;r=void 0;let s=o.getRef(Ol),c={fiber:void 0,awaiters:0};return i=c,c.fiber=rl(o,kc(e,e=>{if(i!==c||(i=void 0,Es(e)))return;let a=t(e);n=a===1/0?1/0:s.currentTimeMillisUnsafe()+a,r=e}),!0,!0),c.fiber._exit??a(o,c)}),Do(()=>{r=void 0})]},Rc=e=>Do(()=>Lc(e,Ic)[0]),zc=e=>_(t=>(t.interruptible&&(t.interruptible=!1,t._stack.push(Vc)),e)),Bc=/*#__PURE__*/ cn({op:`SetInterruptible`,[Ft](e){if(e.interruptible=this[g],e._interruptedCause&&e.interruptible)return()=>To(e._interruptedCause)}}),Vc=/*#__PURE__*/ Bc(!0),Hc=/*#__PURE__*/ Bc(!1),Uc=e=>{if(e.interruptible=!0,e._stack.push(Hc),e._interruptedCause)return To(e._interruptedCause)},Wc=e=>{let t=e;t.interruptible&&(t.interruptible=!1,t._stack.push(Vc))},Gc=e=>_(t=>t.interruptible?e:Uc(t)??e),Kc=e=>_(t=>t.interruptible?(t.interruptible=!1,t._stack.push(Vc),e(Gc)):e(s)),qc=(e,t)=>ye(e)?t?.mode===`result`?Yc(e,Ys,t):Yc(e,s,t):t?.discard?t.mode===`result`?Yc(Object.values(e),Ys,t):Yc(Object.values(e),s,t):b(()=>{let n={};return Qo(Yc(Object.entries(e),([e,r])=>vs(t?.mode===`result`?Ys(r):r,t=>{Et(n,e,t)}),{discard:!0,concurrency:t?.concurrency}),n)}),Jc=/*#__PURE__*/ cn({op:`While`,[Nt](e,t){return this[g].step(e),this[`~effect/Effect/args`].while()?(t._stack.push(this),this[g].body()):Ds},[Mt](e){return this[`~effect/Effect/args`].while()?(e._stack.push(this),this[g].body()):Ds}}),Yc=/*#__PURE__*/ o(e=>typeof e[1]==`function`,(e,t,n)=>b(()=>{let r=Zc(n?.concurrency);if(r===1)return Xc(e,t,n);let i=gi(e),a=i.length;if(a===0)return n?.discard?Po:y([]);let o=n?.discard?void 0:Array(a),s=tl({f:t,out:o},i,{concurrency:r});return s?Qo(s,o):y(o)})),Xc=(e,t,n)=>b(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return Qo(Jc({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),Zc=e=>e===`unbounded`?1/0:Math.max(1,e??1),Qc=()=>e=>{let t=e.onItem,n=e.step,r=(e,t,r,a,o)=>x(ic(o),o=>n(e,t[r],o,r)??i(e,t,r+1,a)??Po),i=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!hs(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},$c=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,ee,te=e=>{let t=hn(e);return f=t,c=!0,u&&u.size>0?x(zc(wo(Array.from(u))),()=>f??t):t},ne=()=>{let i=!1;for(;!f&&a<o;a++){let o=r[a],re=ee??t(e,o,a);if(hs(re)){if(f=n(e,o,re,a),f)break}else if(l){ee=void 0;let t=rl(l,re,!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=Yt(e);f=pn(f._tag===`Failure`?Zt(f.cause,t):t)}}}else{let t=n(e,o,a,r);t&&(f=t,ne())}if(i){let e=ne();e&&d(e)}else c&&u.size===0&&d(f??Po)}catch(e){d(te(e))}}),u.size<s)continue;i=!0,a++;return}else return Vo(e=>{l=uo(),u=/* @__PURE__ */ new Set,ee=re,d=e;let t;try{t=ne()}catch(t){return e(te(t))}return t?e(t):b(()=>(f??=Ds,x(u?wo(u):Po,()=>f?._tag===`Failure`?f:Po)))})}if(c=!0,f){if(u&&u.size>0){let e=_o(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(Po);else return Ds}};return ne()}},el=()=>e=>$c(e),tl=/*#__PURE__*/ $c({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)}}),nl=/*#__PURE__*/ o(e=>zt(e[0]),(e,t)=>_(n=>(Kl(),y(rl(n,e,t?.startImmediately,!1,t?.uninterruptible??!1))))),rl=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new fo(a.context,o);return n?s.evaluate(t):(s._asyncContext=lo(),a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0)),!r&&!s._exit&&(a.children().add(s),s._parent=a),s},il=/*#__PURE__*/ o(e=>zt(e[0]),(e,t,n)=>_(r=>{let i=rl(r,e,n?.startImmediately,!0,n?.uninterruptible);if(!i._exit){if(t.state._tag!==`Closed`){let e={};yc(t,e,()=>Ro(e=>e===i.id?Po:So(i))),i.addObserver(()=>bc(t,e))}else i.interruptUnsafe(r.id,_o(r))}return y(i)})),al=e=>(t,n)=>{let r=new fo(n?.scheduler?zr(e,ga,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},ol=/*#__PURE__*/ o(2,(e,t)=>{if(e._exit)return e;if(t.state._tag===`Closed`)return e.interruptUnsafe(e.id),e;let n={};return yc(t,n,()=>So(e)),e.addObserver(()=>bc(t,n)),e}),sl=/*#__PURE__*/ al(/*#__PURE__*/ Ir()),cl=e=>{let t=al(e);return(e,n)=>{let r=t(e,n);return new Promise(e=>{r.addObserver(t=>e(t))})}},ll=/*#__PURE__*/ (e=>{let t=cl(e);return(e,n)=>t(e,n).then(e=>{if(e._tag===`Failure`)throw io(e.cause);return e.value})})(/*#__PURE__*/ Ir()),ul=e=>{let t=al(e);return e=>{if(hs(e))return e;let n=new xa(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??hn(new Vl(r))}},dl=/*#__PURE__*/ ul(/*#__PURE__*/ Ir()),fl=/*#__PURE__*/ (e=>{let t=ul(e);return e=>{let n=t(e);if(n._tag===`Failure`)throw io(n.cause);return n.value}})(/*#__PURE__*/ Ir()),pl=/*#__PURE__*/ y(!0),ml=/*#__PURE__*/ y(!1);var hl=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return pl;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=[],pl}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](Ds)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](Ds)}open=/*#__PURE__*/ _(e=>this._isOpen?ml:(this._isOpen=!0,this.scheduleUnsafe(e)));release=/*#__PURE__*/ _(e=>this._isOpen?ml:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=/*#__PURE__*/ Vo(e=>this._isOpen?e(Po):(this.waiters.push(e),Do(()=>{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=/*#__PURE__*/ Do(()=>this.closeUnsafe());whenOpen=e=>x(this.await,()=>e);isOpen(){return this._isOpen}};const gl=e=>new hl(e??!1),_l=e=>Do(()=>gl(e)),vl=/*#__PURE__*/ BigInt(0),yl={_tag:`Span`,spanId:`noop`,traceId:`noop`,sampled:!1,status:{_tag:`Ended`,startTime:vl,endTime:vl,exit:Ds},attributes:/*#__PURE__*/ new Map,links:[],kind:`internal`,attribute(){},event(){},end(){},addLinks(){}},bl=e=>Object.assign(Object.create(yl),e),xl=e=>e?Wr(e.annotations,La)?e._tag===`Span`?xl(gr(e.parent)):lr():ur(e):lr(),Sl=(e,t,n)=>{let r=!e.cache.tracerEnabled||n?.annotations&&Wr(n.annotations,La),i=n?.parent===void 0?n?.root?lr():xl(e.cache.span):ur(n.parent),a;if(r)a=bl({name:t,parent:i,annotations:zr(n?.annotations??Ir(),La,!0)});else{let r=e.cache.tracer??Ba,o=e.getRef(Ol),s=e.getRef(Wa),c=e.getRef(Ga),l=e.getRef(Ka),u=n?.level??e.getRef(Ra),d=n?.links===void 0?l.length===0?[]:l.slice():[...l,...n.links];a=r.span({name:t,parent:i,annotations:n?.annotations??Ir(),links:d,startTime:s?o.currentTimeNanosUnsafe():vl,kind:n?.kind??`internal`,root:n?.root??dr(i),sampled:n?.sampled??(fr(i)&&i.value.sampled===!1?!1:!Wl(e.getRef(za),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},Cl=(e,t)=>(t=typeof t==`function`?t:d,Ps(Ha,n=>({name:e,stack:t,parent:n}))),wl=(e,t,n,r)=>Do(()=>{e.status._tag!==`Ended`&&e.end(r?n.currentTimeNanosUnsafe():vl,t)}),Tl=(e,...t)=>{let n=t.length===1?void 0:t[0],r=t[t.length-1];return _(t=>{let i=Sl(t,e,n),a=t.getRef(Ol),o=t.getRef(Wa);return Ac(t,e=>wl(i,e,a,o)),r(i)})},El=/*#__PURE__*/ zs(Fa),Dl=function(){let e=zt(arguments[0]),t=e?arguments[1]:arguments[0],n=e?arguments[2]:arguments[1],r=s;return t._tag===`Span`&&(n=Ya(n),r=Cl(t.name,n?.captureStackTrace)),e?El(r(arguments[0]),t):e=>El(r(e),t)},Ol=/*#__PURE__*/ Zr(`effect/Clock`,{defaultValue:()=>new Al}),kl=2**31-1;var Al=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=/*#__PURE__*/ Do(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return Nl()}currentTimeNanos=/*#__PURE__*/ Do(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return Ml()}monotonicTimeNanos=/*#__PURE__*/ Do(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(aa(e))}sleepMillis(e){return e<=0?ko:Number.isFinite(e)?Vo(t=>{let n=e>kl?this.sleepMillis(e-kl):Po,r=setTimeout(()=>t(n),Math.min(e,kl));return Do(()=>clearTimeout(r))}):Ho}};const jl=/*#__PURE__*/ BigInt(1e6),Ml=/*#__PURE__*/ 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=/*#__PURE__*/ BigInt(0);return()=>{let e=BigInt(Date.now())*jl;return e>t&&(t=e),t}}(),Nl=/*#__PURE__*/ function(){let e=/*#__PURE__*/ BigInt(1e9),t;return()=>{let n=Ml(),r=BigInt(Date.now())*jl;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}}(),Pl=e=>_(t=>e(t.getRef(Ol))),Fl=e=>Pl(t=>t.sleep(Li(e))),Il=/*#__PURE__*/ Pl(e=>e.currentTimeMillis),Ll=e=>p(e,`~effect/Cause/TimeoutError`),Rl=`~effect/Cause/IllegalArgumentError`;var zl=class extends (/*#__PURE__*/ vn(`IllegalArgumentError`)){[Rl]=Rl;constructor(e){super({message:e})}};const Bl=`~effect/Cause/AsyncFiberError`;var Vl=class extends (/*#__PURE__*/ vn(`AsyncFiberError`)){[Bl]=Bl;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}};const Hl=`~effect/Cause/UnknownError`;var Ul=class extends (/*#__PURE__*/ vn(`UnknownError`)){[Hl]=Hl;constructor(e,t){super({message:t,cause:e})}};const Wl=/*#__PURE__*/ ir(/* @__PURE__ */ nr(tr,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}})),Gl={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};Gl.gray,Gl.blue,Gl.green,Gl.yellow,Gl.red,Gl.bgBrightRed,Gl.black;function Kl(){go.interruptChildren??=vo}const ql=/*#__PURE__*/ y(void 0),Jl=nn,Yl=Yt,Xl=Qt,Zl=en,Ql=ro,$l=io,eu=eo,tu=to,nu=bn,ru=wn,iu=Ll,au=zl,ou=un,su=pn,cu=mn,lu=Ds,uu=ws,du={"~effect/Deferred":{_A:s,_E:s},pipe(){return r(this,arguments)}},fu=function(){this.resumes=void 0,this.effect=void 0};fu.prototype=du;const pu=()=>new fu,mu=e=>Vo(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),Do(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),hu=(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},gu=xc,_u=Tc,vu=_c,yu=vc,bu=gc,xu=dc,Su=`~effect/Layer/MemoMap`,Cu=(e,t)=>{let n={observers:0,deferred:pu(),scope:gu(),finalizer:r=>b(()=>--n.observers>0?Po:(e.map.delete(t),xu(n.scope,r)))};return n},wu=(e,t)=>t.state._tag!==`Closed`&&(e.observers++,yc(t,{},e.finalizer),!0),Tu={"~effect/Layer":{_ROut:s,_E:s,_RIn:s},pipe(){return r(this,arguments)}},Eu=e=>{let t=Object.create(Tu);return t.build=e,t},Du=e=>Eu((t,n)=>{let r=bu(n);return jc(e(t,r),e=>e._tag===`Failure`?xu(r,e):Po)}),Ou=e=>{let t=Du((n,r)=>n.getOrElseMemoize(t,r,e));return t};var ku=class{get[Su](){return Su}parent;constructor(e){this.parent=e}map=/*#__PURE__*/ new Map;get(e,t){let n=this.map.get(e);return n?(wu(n,t),n.deferred.effect??mu(n.deferred)):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return b(()=>{let r;return kc(b(()=>{let i=this.get(e,t);if(i)return i;let a=Cu(this,e);return wu(a,t)?(r=a.deferred,this.map.set(e,a),n(this,a.scope)):n(this,t)}),e=>{r&&hu(r,e)})})}};const Au=()=>new ku,ju=e=>new ku(e);var Mu=class e extends (/*#__PURE__*/ br()(`effect/Layer/CurrentMemoMap`)){static forkOrCreate(t){let n=Vr(t,e);return n?ju(n):Au()}};const Nu=/*#__PURE__*/ o(3,(e,t,n)=>zs(vs(e.build(t,n),zr(Mu,t)),Mu,t)),Pu=/*#__PURE__*/ o(2,(e,t)=>_(n=>Nu(e,Mu.forkOrCreate(n.context),t))),Fu=function(){return arguments.length===1?e=>Iu(arguments[0],e):Iu(arguments[0],arguments[1])},Iu=(e,t)=>Lu(vs(t,t=>Rr(e,t))),Lu=e=>Ou((t,n)=>_u(e,n)),Ru=(e,t,n)=>{let r=bu(n,`parallel`);return Yc(e,e=>e.build(t,bu(r,`sequential`)),{concurrency:e.length}).pipe(vs(e=>Xr(...e)))},zu=(...e)=>Du((t,n)=>Ru(e,t,n)),Bu=(e,t,n)=>Du((r,i)=>x(Array.isArray(t)?Ru(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(Rs(t),vs(e=>n(e,t))))),Vu=/*#__PURE__*/ o(2,(e,t)=>Bu(e,t,s)),Hu=/*#__PURE__*/ o(2,(e,t)=>Bu(e,t,(e,t)=>Yr(t,e))),Uu=Il,Wu=`~effect/DateTime`,Gu=`~effect/DateTime/TimeZone`,Ku={[Wu]:Wu,pipe(){return r(this,arguments)},[_t](){return this.toString()},toJSON(){return rd(this).toJSON()}},qu={...Ku,_tag:`Utc`,[be](){return Ee(this.epochMilliseconds)},[Re](e){return Yu(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${rd(this).toJSON()})`}};({...Ku});const Ju={[Gu]:Gu,[_t](){return this.toString()}};({...Ju}),{...Ju};const Yu=e=>p(e,Wu),Xu=e=>e._tag===`Utc`,Zu=e=>{let t=Object.create(qu);return t.epochMilliseconds=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},Qu=e=>{let t=e.getTime();if(Number.isNaN(t))throw new au(`Invalid date`);return Zu(t)},$u=e=>{if(Yu(e))return e;if(e instanceof Date)return Qu(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return Qu(new Date(e.epochMilliseconds));let t=/* @__PURE__ */ new Date(0);return ad(t,e),Qu(t)}return typeof e==`string`&&!ed(e)?Qu(/* @__PURE__ */ new Date(e+`Z`)):Qu(new Date(e))},ed=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e),td=/*#__PURE__*/ _r($u),nd=e=>Zu(e.epochMilliseconds),rd=e=>new Date(e.epochMilliseconds),id=e=>e.epochMilliseconds,ad=(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)},od=e=>rd(e).toISOString();globalThis.String;const sd=e=>e.trim(),cd=/*#__PURE__*/ Zr(`effect/Random`,{defaultValue:()=>({nextIntUnsafe(){return Math.floor(Math.random()*(2**53-1- -(2**53-1)+1))+-(2**53-1)},nextDoubleUnsafe(){return Math.random()}})}),ld=/*#__PURE__*/ o(2,(e,t)=>Gs(e,pd,e=>t(e))),ud=e=>e.reasons.some(dd),dd=e=>e._tag===`Fail`&&nu(e.error),fd=e=>{let t,n=!1;for(let r of e.reasons)dd(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?ni(e):n?ni(Yl(e.reasons.filter(e=>!dd(e)))):ti(t)},pd=e=>{let t=fd(e);return ii(t)?t:ti(t.success.value)},md=e=>{let t=fd(e);return ii(t)?su(t.failure):ou(t.success.value)},hd=/*#__PURE__*/ o(2,(e,t)=>Xs(e,{onSuccess:t.onSuccess,onFailure:e=>{let n=fd(e);return ii(n)?t.onFailure(n.failure):t.onDone(n.success.value)}})),gd=`~effect/Schedule`,_d=/*#__PURE__*/ cd.useSync(e=>e.nextDoubleUnsafe()),vd=/*#__PURE__*/ Zr(`effect/Schedule/CurrentMetadata`,{defaultValue:/*#__PURE__*/ c({input:void 0,output:void 0,duration:Yi,attempt:0,start:0,now:0,elapsed:0,elapsedSincePrevious:0})}),yd={[gd]:{_Out:s,_In:s,_Env:s},pipe(){return r(this,arguments)}},bd=e=>p(e,gd),xd=e=>{let t=Object.create(yd);return t.step=e,t},Sd=()=>{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}}},Cd=e=>xd(vs(e,e=>{let t=Sd();return(n,r)=>e(t(n,r))})),wd=e=>Hs(e.step,e=>y(()=>To(e))),Td=e=>Pl(t=>vs(wd(e),e=>{let n=Sd();return r=>b(()=>{let i=t.currentTimeMillisUnsafe();return x(e(i,r),([e,t])=>{let a=n(i,r);return a.output=e,a.duration=t,Qo(Fl(t),a)})})})),Ed=e=>xd(vs(qc(e.map(wd)),e=>(t,n)=>x(Yc(e,e=>hd(e(t,n),{onSuccess:e=>y(e[1]),onDone:()=>ql,onFailure:To})),e=>{let t=Dd(e);return t===void 0?ru(Yi):y([t,t])}))),Dd=e=>{let t=e[0];for(let n=1;n<e.length&&(t=e[n]&&t&&fa(t,e[n]),t!==void 0);n++);return t},Od=e=>xd(vs(qc(e.map(wd)),e=>(t,n)=>x(Yc(e,e=>hd(e(t,n),{onSuccess:e=>y(e[1]),onDone:()=>ql,onFailure:To})),e=>{let t=kd(e);return t===void 0?ru(Yi):y([t,t])}))),kd=e=>{let t;for(let n=0;n<e.length;n++){let r=e[n];r!==void 0&&(t=t===void 0?r:da(t,r))}return t},Ad=(e,t=2)=>{let n=aa(Li(e));return Cd(y(e=>{let r=$i(n*t**(e.attempt-1));return y([r,r])}))},jd=/*#__PURE__*/ o(2,(e,t)=>xd(vs(wd(e),e=>{let n=Sd();return(r,i)=>x(e(r,i),([e,a])=>vs(t({...n(r,i),output:e,duration:a}),t=>[e,Li(t)]))}))),Md=e=>jd(e,({duration:e})=>vs(_d,t=>{let n=aa(e);return $i(n*.8*(1-t)+n*1.2*t)})),Nd=e=>xd(vs(wd(e),e=>(t,n)=>hd(e(t,n),{onSuccess:e=>y([n,e[1]]),onFailure:To,onDone:()=>ru(n)}))),Pd=e=>Id(Ld,({attempt:t})=>y(t<=e)),Fd=e=>{let t=Li(e);return Cd(y(e=>y([e.attempt-1,t])))},Id=/*#__PURE__*/ o(2,(e,t)=>xd(vs(wd(e),e=>{let n=Sd();return(r,i)=>x(e(r,i),e=>{let[a,o]=e,s=t({...n(r,i),output:a,duration:o});return x(zt(s)?s:y(s),t=>t?y(e):ru(a))})}))),Ld=/*#__PURE__*/ Fd(Yi),Rd=()=>e=>e,zd=(e,t,n)=>Ec(r=>x(n?.local?Nu(t,Au(),r):Pu(t,r),t=>Rs(e,t))),Bd=/*#__PURE__*/ o(e=>zt(e[0]),(e,t,n)=>Pr(t)?Rs(e,t):zd(e,Array.isArray(t)?zu(...t):t,n)),Vd=/*#__PURE__*/ o(3,(e,t,n)=>x(Td(t),t=>{let r=vd.defaultValue();return Ks(Vs(ds(x(b(()=>zs(e,vd,r)),t),e=>Do(()=>{r=e})),{disableYield:!0}),e=>bn(e)?y(e.value):n(e,r.attempt===0?lr():ur(r)))})),Hd=/*#__PURE__*/ o(3,(e,t,n)=>x(Td(t),t=>{let r=vd.defaultValue(),i,a=Ks(b(()=>zs(e,vd,r)),e=>(i=e,x(t(e),e=>(r=e,a))));return ld(a,e=>Tt(()=>n(i,e)))})),Ud=/*#__PURE__*/ o(2,(e,t)=>{let n=typeof t==`function`?t(s):bd(t)?t:Kd(t);return Vd(e,n,Eo)}),Wd=/*#__PURE__*/ o(2,(e,t)=>{let n=typeof t==`function`?t(s):bd(t)?t:Kd(t);return Hd(e,n,Eo)}),Gd=/*#__PURE__*/ Nd(Ld),Kd=e=>{let t=e.schedule?Nd(e.schedule):Gd;return e.while&&(t=Id(t,({input:t})=>{let n=e.while(t);return zt(n)?n:y(n)})),e.until&&(t=Id(t,({input:t})=>{let n=e.until(t);return zt(n)?vs(n,e=>!e):y(!n)})),e.times!==void 0&&(t=Id(t,({attempt:t})=>y(t<=e.times))),t},qd=Jc,Jd=Io,Yd=Lo,S=y,Xd=Ao,Zd=b,Qd=Do,$d=Po,ef=Vo,tf=Ho,nf=Uo,C=Eo,rf=To,af=jo,of=Mo,sf=Fo,cf=ko,lf=_,uf=Oo,w=x,df=_s,ff=us,pf=ds,mf=Ys,hf=ic,gf=vs,_f=Qo,vf=fs,yf=Hs,bf=qs,xf=Wd,Sf=oc,Cf=ms,wf=Xs,Tf=Fs,Ef=Ls,Df=Bd,Of=Rs,kf=Ns,Af=zs,jf=Dc,Mf=Nc,Nf=jc,Pf=Rc,Ff=Fc,If=Kc,Lf=Vs,Rf=Ud,zf=Tl,Bf=Dl,Vf=nl,Hf=il,Uf=sl,Wf=al,Gf=ll,Kf=fl,qf=dl,Jf=Wo,Yf=qo,Xf=ys,Zf=bs,Qf=xs,$f=gs,ep=Ss,tp=Yo,np=`~effect/BigDecimal`,rp={[np]:np,[be](){let e=dp(this);return Ce(De(String(e.value)),Ee(e.scale))},[Re](e){return ip(e)&&hp(this,e)===0},toString(){return`BigDecimal(${_p(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[_t](){return this.toJSON()},pipe(){return r(this,arguments)}},ip=e=>p(e,np),ap=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(rp);return n.value=e,n.scale=t,n},op=(e,t)=>{let n=ap(e,t);return n.normalized=n,n},sp=/*#__PURE__*/ BigInt(0),cp=/*#__PURE__*/ BigInt(1),lp=/*#__PURE__*/ BigInt(10),up=/*#__PURE__*/ op(sp,0),dp=e=>{if(e.normalized===void 0){if(e.value===sp)e.normalized=up;else{let t=`${e.value}`,n=t.length;for(;t[n-1]===`0`;)n--;e.normalized=op(BigInt(t.slice(0,n)),e.scale-(t.length-n))}}return e.normalized},fp=[cp],pp=(e,t)=>e===t?0:e<t?-1:1,mp=(e,t)=>{let n=`${e.value<sp?-e.value:e.value}`,r=`${t.value<sp?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==sp)return i<sp?-1:1;let a=Math.max(n.length,r.length);return er(n.padEnd(a,`0`),r.padEnd(a,`0`))},hp=(e,t)=>{if(e.scale===t.scale)return pp(e.value,t.value);let n=gp(e),r=gp(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?mp(t,e):mp(e,t);let o=fp[a]??=lp**BigInt(a);return i>0?pp(e.value,t.value*o):pp(e.value*o,t.value)},gp=e=>e.value===sp?0:e.value<sp?-1:1,_p=e=>{let t=dp(e);if(Math.abs(t.scale)>=16)return vp(t);let n=t.value<sp,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},vp=e=>{if(yp(e))return`0e+0`;let t=dp(e),n=`${t.value}`,r=t.value<sp?2:1,i=n.slice(0,r),a=n.slice(r),o=a.length-t.scale;return`${i}${a===``?``:`.${a}`}e${o>=0?`+`:``}${o}`},yp=e=>e.value===sp,bp=Yu,xp=Xu,Sp=$u,Cp=td,wp=nd,Tp=id,Ep=od,Dp=e=>kp(typeof e==`string`?Ap.encode(e):e),Op=e=>{let t=jp(e),n=t.length;if(n%4!=0)return ni(new Oa({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 ni(new Oa({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));try{let e=t.endsWith(`==`)?2:+!!t.endsWith(`=`),r=new Uint8Array(n/4*3-e);for(let e=0,i=0;e<n;e+=4,i+=3){let n=Pp(t.charCodeAt(e))<<18|Pp(t.charCodeAt(e+1))<<12|Pp(t.charCodeAt(e+2))<<6|Pp(t.charCodeAt(e+3));r[i]=n>>16,r[i+1]=n>>8&255,r[i+2]=n&255}return ti(r)}catch(e){return ni(new Oa({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},kp=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=Mp[e[r-2]>>2],n+=Mp[(e[r-2]&3)<<4|e[r-1]>>4],n+=Mp[(e[r-1]&15)<<2|e[r]>>6],n+=Mp[e[r]&63];return r===t+1&&(n+=Mp[e[r-2]>>2],n+=Mp[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=Mp[e[r-2]>>2],n+=Mp[(e[r-2]&3)<<4|e[r-1]>>4],n+=Mp[(e[r-1]&15)<<2],n+=`=`),n},Ap=/*#__PURE__*/ new TextEncoder,jp=e=>e.replace(/[\n\r]/g,``),Mp=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Np=/*#__PURE__*/ (/* @__PURE__ */ new Uint8Array(123)).fill(255);for(let e=0;e<64;e++)Np[/*#__PURE__*/ Mp.charCodeAt(e)]=e;Np[61]=0;const Pp=e=>{if(e>=Np.length||Np[e]===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return Np[e]},Fp=`~effect/http/Cookies`,Ip=`~effect/http/Cookies/Cookie`,Lp={[Fp]:Fp,...yt,toJSON(){return{_id:`effect/Cookies`,cookies:di(this.cookies,e=>e.toJSON())}},pipe(){return r(this,arguments)}},Rp=e=>{let t=Object.create(Lp);return t.cookies=e,t},zp=e=>{let t={};for(let n of e)Et(t,n.name,n);return Rp(t)},Bp=e=>{let t=typeof e==`string`?[e]:e,n=[];for(let e of t){let t=Vp(e.trim());t&&n.push(t)}return zp(n)};function Vp(e){let t=e.split(`;`).map(e=>e.trim()).filter(e=>e!==``);if(t.length===0)return;let n=t[0].indexOf(`=`);if(n===-1)return;let r=t[0].slice(0,n);if(!Hp.test(r))return;let i=t[0].slice(n+1),a=Wp(i);if(t.length===1)return Object.assign(Object.create(Up),{name:r,value:a,valueEncoded:i});let o={};for(let e=1;e<t.length;e++){let n=t[e],r=n.indexOf(`=`),i=r===-1?n:n.slice(0,r).trim(),a=r===-1?void 0:n.slice(r+1).trim();switch(i.toLowerCase()){case`domain`:{if(a===void 0)break;let e=a.trim().replace(/^\./,``);e&&(o.domain=e);break}case`expires`:{if(a===void 0)break;let e=new Date(a);isNaN(e.getTime())||(o.expires=e);break}case`max-age`:{if(a===void 0)break;let e=parseInt(a,10);isNaN(e)||(o.maxAge=ea(e));break}case`path`:if(a===void 0)break;a[0]===`/`&&(o.path=a);break;case`priority`:if(a===void 0)break;switch(a.toLowerCase()){case`low`:o.priority=`low`;break;case`medium`:o.priority=`medium`;break;case`high`:o.priority=`high`}break;case`httponly`:o.httpOnly=!0;break;case`secure`:o.secure=!0;break;case`partitioned`:o.partitioned=!0;break;case`samesite`:if(a===void 0)break;switch(a.toLowerCase()){case`lax`:o.sameSite=`lax`;break;case`strict`:o.sameSite=`strict`;break;case`none`:o.sameSite=`none`}}}return Object.assign(Object.create(Up),{name:r,value:a,valueEncoded:i,options:Object.keys(o).length>0?o:void 0})}const Hp=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,Up={[Ip]:Ip,...yt,toJSON(){return{_id:`effect/Cookies/Cookie`,name:this.name,value:this.value,options:this.options}}},Wp=e=>{try{return decodeURIComponent(e)}catch{return e}},Gp=/*#__PURE__*/ new WeakMap,Kp=`~effect/Redacted`,qp=e=>p(e,Kp),Jp=(e,t)=>{let n=Object.create(Yp);return t?.label&&(n.label=t.label),Gp.set(n,e),n},Yp={[Kp]:{_A:e=>e},label:void 0,...Lt,toJSON(){return this.toString()},toString(){return`<redacted${se(this.label)?`:`+this.label:``}>`},[be](){return m(Gp.get(this))},[Re](e){return qp(e)&&ze(Gp.get(this),Gp.get(e))}},Xp=/*#__PURE__*/ Symbol.for(`~effect/http/Headers`),Zp=/*#__PURE__*/ Object.defineProperties(/*#__PURE__*/ Object.create(null),{[Xp]:{value:Xp},[rt]:{value(e){return sm(this,Wr(e,lm))}},toJSON:{value(){return at(this)}},[Re]:{value(e){return $p(this,e)}},[be]:{value(){return ke(this)}},toString:{value:yt.toString},[_t]:{value:yt[_t]}}),Qp=e=>Object.assign(Object.create(Zp),e),$p=/*#__PURE__*/ mi(/*#__PURE__*/ On()),em=/*#__PURE__*/ Object.create(Zp),tm=e=>{if(e===void 0)return em;if(Symbol.iterator in e){let t=Object.create(Zp);for(let[n,r]of e)t[n.toLowerCase()]=r;return t}let t=Object.create(Zp);for(let[n,r]of Object.entries(e))Array.isArray(r)?t[n.toLowerCase()]=r.join(`, `):r!==void 0&&(t[n.toLowerCase()]=r);return t},nm=e=>Object.setPrototypeOf(e,Zp),rm=/*#__PURE__*/ o(3,(e,t,n)=>{let r=Qp(e);return r[t.toLowerCase()]=n,r}),im=/*#__PURE__*/ o(2,(e,t)=>Qp({...e,...tm(t)})),am=/*#__PURE__*/ o(2,(e,t)=>{let n=Qp(e);return Object.assign(n,t),n}),om=/*#__PURE__*/ o(2,(e,t)=>{let n=Qp(e);return delete n[t.toLowerCase()],n}),sm=/*#__PURE__*/ o(2,(e,t)=>{let n={...e},r=t=>{if(typeof t==`string`){let r=t.toLowerCase();r in e&&(n[r]=Jp(e[r]))}else for(let r in e)r.search(t)!==-1&&(n[r]=Jp(e[r]))};if(Array.isArray(t))for(let e=0;e<t.length;e++)r(t[e]);else r(t);return n}),cm=(e,t)=>{for(let n=0;n<t.length;n++){let r=t[n];if(typeof r==`string`){if(r.toLowerCase()===e.toLowerCase())return!0}else if(e.search(r)!==-1)return!0}return!1},lm=/*#__PURE__*/ Zr(`effect/Headers/CurrentRedactedNames`,{defaultValue:()=>[`authorization`,`cookie`,`set-cookie`,`x-api-key`]}),um=`~effect/http/UrlParams`,dm=e=>p(e,um),fm={...Lt,[um]:um,[Symbol.iterator](){return this.params[Symbol.iterator]()},toJSON(){return{_id:`UrlParams`,params:Object.fromEntries(this.params)}},[Re](e){return gm(this,e)},[be](){return je(this.params.flat())}},pm=e=>{let t=Object.create(fm);return t.params=e,t},mm=e=>{if(dm(e))return e;let t=hm(e),n=[];for(let e=0;e<t.length;e++)if(Array.isArray(t[e][0])){let[r,i]=t[e];n.push([`${r[0]}[${r.slice(1).join(`][`)}]`,i])}else n.push(t[e]);return pm(n)},hm=e=>{let t=typeof e[Symbol.iterator]==`function`?gi(e):Object.entries(e),n=[];for(let[e,r]of t)if(Array.isArray(r))for(let t=0;t<r.length;t++)r[t]!==void 0&&n.push([e,String(r[t])]);else if(typeof r==`object`&&r){let t=hm(r);for(let[r,i]of t)n.push([[e,...typeof r==`string`?[r]:r],i])}else r!==void 0&&n.push([e,String(r)]);return n},gm=/*#__PURE__*/ En((e,t)=>_m(e.params,t.params)),_m=/*#__PURE__*/ Ci(/*#__PURE__*/ ci([/*#__PURE__*/ On(),/*#__PURE__*/ On()])),vm=/*#__PURE__*/ pm([]),ym=/*#__PURE__*/ o(2,(e,t)=>{let n=mm(t).params.slice(),r=/* @__PURE__ */ new Set;for(let e=0;e<n.length;e++)r.add(n[e][0]);for(let t=0;t<e.params.length;t++)r.has(e.params[t][0])||n.push(e.params[t]);return pm(n)});function bm(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}const xm=`~sentinels`,Sm=`~constructor`,Cm=/*#__PURE__*/ ee(e=>{let t=bm(e)?.identifier;return typeof t==`string`?t:e.getExpected(Cm)}),T=/*#__PURE__*/ Symbol(),wm=ou,Tm=/*#__PURE__*/ wm(T),Em=/*#__PURE__*/ wm(T),Dm=e=>e===T?lr():ur(e),Om=e=>e._tag===`None`?Tm:wm(e.value),km=`~effect/SchemaIssue/Issue`;function Am(e){return p(e,km)&&e[km]===km}function jm(e){return Object.hasOwn(e,`input`)}var Mm=class{[km]=km;constructor(e,t){t?.reportInput===!0&&e!==T&&(this.input=e)}};const Nm=class extends Mm{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},Pm=class extends Mm{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},Fm=class extends Mm{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},Im=class extends Mm{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},Lm=class extends Mm{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Rm=class extends Mm{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},zm=class extends Mm{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Bm=class extends Mm{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Vm=class extends Mm{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Hm=class extends Mm{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},Um=class extends Mm{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Wm(e,t,n){if(Am(e))return e;if(typeof e==`string`)return new Bm({message:e},t,n);let r=typeof e.issue==`string`?new Bm({message:e.issue},t,n):e.issue;return new Fm(e.path,r)}function Gm(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Bm(void 0,t,n):Wm(e,t,n)}function Km(e,t,n,r){return Array.isArray(t)?yi(t)?t.length===1?Wm(t[0],n,r):new Rm(e,Si(t,e=>Wm(e,n,r)),n,r):void 0:Gm(t,n,r)}const qm=e=>{let t=nh(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Zm(Cm(e.ast),e);case`InvalidValue`:{let t=Xm(e);if(t!==void 0)return Zm(t,e);let n=Ym(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Ym(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Ym(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},Jm=e=>nh(e.issue)??nh(e);function Ym(e){return jm(e)?h(e.input):void 0}function Xm(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Zm(e,t){let n=Ym(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function Qm(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=>Qm(e)).join(` & `)}}function $m(){return e=>th(e,``)}const eh=/*#__PURE__*/ $m();function th(e,t){let n;switch(e._tag){case`Filter`:{let r=Jm(e);if(r!==void 0)n=r;else{if(e.issue._tag!==`InvalidValue`)return th(e.issue,t);let r=Xm(e.issue);n=r===void 0?Zm(Qm(e.filter),e):Zm(r,e.issue)}break}case`Encoding`:return th(e.issue,t);case`Pointer`:return th(e.issue,t+ft(e.path));case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>th(e,t)).join(`
|
|
9
|
+
`);n=nh(e)??Zm(Cm(e.ast),e);break;default:n=qm(e)}return t?`${n}\n at ${t}`:n}function nh(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return nh(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 rh(e){let t;for(let n of e.reasons){if(!Jl(n)||!Am(n.error))return;t??=n.error}return t}function ih(e,t){let n=rh(e);if(n===void 0)throw Error(t,{cause:e});return n}const ah=e=>Dp(e).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`),oh=e=>{let t=e.replace(/[\n\r]/g,``),n=t.length;if(n%4==1)return ni(new Oa({module:`Base64Url`,kind:`Decode`,input:t,message:`Length should be a multiple of 4, but is ${n}`}));if(!/^[-_A-Z0-9]*?={0,2}$/i.test(t))return ni(new Oa({module:`Base64Url`,kind:`Decode`,input:t,message:`Invalid input`}));let r=n%4==2?`${t}==`:n%4==3?`${t}=`:t;return r=r.replace(/-/g,`+`).replace(/_/g,`/`),Op(r)},sh=e=>oi(oh(e),e=>ch.decode(e)),ch=/*#__PURE__*/ new TextDecoder,lh=e=>Object.assign(Object.create(i),e);function uh(e){return _h((t,n)=>C(e(t,n)))}function dh(e){return uh((t,n)=>{let r={message:e(t)};return fr(t)?new Vm(r,t.value,n):new Vm(r)})}const fh=/*#__PURE__*/ dh(()=>`Encoding is not supported`),ph=/*#__PURE__*/ lh({_tag:`Passthrough`});function mh(){return ph}function E(e){return lh({_tag:`Transform`,transform:e})}function hh(e){return lh({_tag:`TransformEffect`,transform:e})}function gh(e){return lh({_tag:`TransformOptional`,transform:e})}function _h(e){return lh({_tag:`TransformOptionalEffect`,transform:e})}function vh(){return E(globalThis.String)}function yh(){return E(globalThis.Number)}function bh(){return E(globalThis.BigInt)}function xh(){return E(sd)}function Sh(e){return hh((t,n)=>sf({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Bm({expected:`a valid JSON string`},t,n)}))}function Ch(e){return hh((t,n)=>sf({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 Bm({expected:`a JSON-serializable value`},t,n)}))}function wh(){return E(Dp)}function Th(){return hh((e,t)=>Zf(uf(Op(e)),()=>new Bm({expected:`a valid Base64 string`},e,t)))}const Eh=class extends a{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Eh(this.encode,this.decode)}},Dh=`~effect/SchemaTransformation/Transformation`,Oh=class extends a{[Dh]=Dh;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Oh(this.encode,this.decode)}};function kh(e){return p(e,Dh)&&e[Dh]===Dh}const Ah=e=>kh(e)?e:new Oh(e.decode,e.encode);function jh(e){return new Oh(hh(e.decode),hh(e.encode))}function Mh(e){return new Oh(E(e.decode),E(e.encode))}function Nh(){return new Oh(xh(),mh())}const Ph=/*#__PURE__*/ new Oh(/*#__PURE__*/ mh(),/*#__PURE__*/ mh());function Fh(){return Ph}const Ih=/*#__PURE__*/ new Oh(/*#__PURE__*/ yh(),/*#__PURE__*/ vh()),Lh=/*#__PURE__*/ new Oh(/*#__PURE__*/ bh(),/*#__PURE__*/ vh()),Rh=e=>ge(e)&&typeof e.message==`string`,zh=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:Uh(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},Bh=e=>{try{let t=gt(e);return t===void 0?h(e):JSON.parse(t)}catch{return h(e)}},Vh=(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},Hh=e=>{let t=/* @__PURE__ */ new WeakSet,n=r=>{if(ve(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=Vh(r,e,n);return t.delete(r),i}return Bh(r)};return n},Uh=e=>Rh(e)?zh(e):e,Wh=e=>Mh({decode:Uh,encode:Hh(e)}),Gh=/*#__PURE__*/ new Oh(/*#__PURE__*/ Th(),/*#__PURE__*/ wh());function Kh(e){return new Oh(Sh(e??{}),Ch(e))}function qh(e){return t=>t._tag===e}const Jh=/*#__PURE__*/ qh(`Declaration`),Yh=/*#__PURE__*/ qh(`Never`),Xh=/*#__PURE__*/ qh(`Literal`),Zh=/*#__PURE__*/ qh(`UniqueSymbol`),Qh=/*#__PURE__*/ qh(`Arrays`),$h=/*#__PURE__*/ qh(`Objects`),eg=/*#__PURE__*/ qh(`Union`),tg=/*#__PURE__*/ qh(`Suspend`),ng=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},rg={},ig=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}},ag=`~effect/Schema`;var og=class{[ag]=ag;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 sg=class extends og{_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)=>t===T?Tm:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=I_(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new sg(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>`}},cg=/*#__PURE__*/ new class extends og{_tag=`Null`;getParser(){return ev(this,null)}getExpected(){return`null`}},lg=class extends og{_tag=`Undefined`;getParser(){return ev(this,void 0)}toCodecJson(){return w_(this,[ug])}getExpected(){return`undefined`}},ug=/*#__PURE__*/ new ng(cg,/*#__PURE__*/ new Oh(/*#__PURE__*/ E(()=>void 0),/*#__PURE__*/ E(()=>null))),dg=/*#__PURE__*/ new lg,fg=/*#__PURE__*/ new class extends og{_tag=`Any`;getParser(){return tv(this,he)}getExpected(){return`any`}},pg=/*#__PURE__*/ new class extends og{_tag=`Unknown`;getParser(){return tv(this,he)}getExpected(){return`unknown`}};function mg(e){return typeof e==`number`?`parts[${e}]`:e}function hg(e,t,n){if(n.has(e))return!0;if(e.encoding)throw Error(`TemplateLiteral parts cannot have an encoding at ${mg(t)}`);let r;switch(e._tag){case`String`:case`Number`:case`BigInt`:r=!0;break;case`Literal`:r=!e.checks;break;case`TemplateLiteral`:{let i=mg(t);r=!e.checks&&e.parts.every((e,t)=>hg(e,`${i}.parts[${t}]`,n));break}case`Union`:{let i=mg(t);r=!e.checks&&e.types.every((e,t)=>hg(e,`${i}.types[${t}]`,n));break}default:return!1}return r&&n.add(e),r}const gg=class extends og{_tag=`TemplateLiteral`;parts;encodedParts;literals;suffixLengths;constructor(e,t,n,r,i){super(t,n,r,i);let a=[],o=[],s=/* @__PURE__ */ new Set;for(let t=0;t<e.length;t++){let n=e[t];if(!hg(n,t,s))throw Error(`Invalid TemplateLiteral part ${n._tag}`);a.push(n),o.push(n._tag===`Literal`?globalThis.String(n.literal):void 0)}let c=Array(a.length+1);c[a.length]=0;for(let e=a.length-1;e>=0;e--)c[e]=c[e+1]+(o[e]?.length??0);this.parts=e,this.encodedParts=a,this.literals=o,this.suffixLengths=c}getParser(e){let t=new Eg(!1,this.parts.map(iv),[]),n=e(H_(bg,t,_g(this)));return(e,t)=>{if(e===T)return Tm;let r=n(e,t);return r._tag===`Success`?Em:Qf(r,{onSuccess:()=>e,onFailure:n=>new Rm(this,[n],e,t)})}}getExpected(){return`string`}matchPart(e,t){return nv(this,e,t)===void 0?void 0:e}};function _g(e){return new Oh(hh((t,n)=>{let r=nv(e,t,n);return r?S(r):C(new Bm({expected:`a string matching template literal parts`},t,n))}),E(e=>e.join(``)))}const vg=class extends og{_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 ${h(e)}`);this.literal=e}getParser(){return ev(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?yg(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:yg(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function yg(e){let t=globalThis.String(e.literal);return w_(e,[new ng(new vg(t),new Oh(E(()=>e.literal),E(()=>t)))])}const bg=/*#__PURE__*/ new class extends og{_tag=`String`;getParser(){return tv(this,se)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&mv(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},xg=class extends og{_tag=`Number`;getParser(){return tv(this,ce)}matchKey(e,t){return this._match(ov,e,t)}matchPart(e,t){return this._match(av,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:mv(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(Sg(this.checks,`effect/schema/isFinite`)||Sg(this.checks,`effect/schema/isInt`))?this:w_(this,[y_])}toCodecStringTree(){return this.toCodecJson()===this?w_(this,[lv]):w_(this,[uv])}getExpected(){return`number`}};function Sg(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&Sg(e.checks,t))}const Cg=/*#__PURE__*/ new xg,wg=/*#__PURE__*/ new class extends og{_tag=`Boolean`;getParser(){return tv(this,le)}getExpected(){return`boolean`}},Tg=/*#__PURE__*/ new class extends og{_tag=`BigInt`;getParser(){return tv(this,ue)}matchPart(e,t){if(!dv.test(e))return;let n=globalThis.BigInt(e);return t.disableChecks||!this.checks?n:mv(this.checks,n,void 0,this,t)?void 0:n}toCodecStringTree(){return w_(this,[pv])}getExpected(){return`bigint`}},Eg=class extends og{_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(G_(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(G_(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 Lm(n,t[o],i),a=new Fm([o],r);if(i.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return C(new Rm(n,[a],t,i))}return e.issues?C(new Rm(n,e.issues,t,i)):wm(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:new globalThis.Array(r),issues:void 0,options:t},u=n.rest.length===0?a:Math.max(r,a+o),d=t.concurrency===void 0?1:Zc(t.concurrency),f=d===1?kg(i,e,0,u):Ag(i,e,{concurrency:d,end:u});if(!f)return c(i);if(hs(f))return $f(f,()=>c(i));let ee=!0;return Zd(()=>ee?(ee=!1,w(f,()=>c(i))):l(e,t))};return(e,a)=>{if(e===T)return Tm;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)):C(new zm(n,e,a))}catch(e){return of(e)}}}_rebuild(e,t,n){let r=I_(this.elements,e),i=I_(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new Eg(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 Dg(e,t,n,r){if(n._tag===`Failure`)return jg(e,e.ast,r,n);let i=n===Em?t:n[g];if(i!==T)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(G_(t.ast))return;let n=new Fm([r],new Im(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return cu(new Rm(e.ast,[n],e.input,e.options))}}const Og={onItem(e,t,n){let r=n<e.len?t:T;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:Dg},kg=/*#__PURE__*/ Qc()(Og),Ag=/*#__PURE__*/ el()(Og),jg=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=rh(r.cause);if(i===void 0)return su(Ql(r.cause,r=>new Rm(t,[new Fm([n],r)],e.input,e.options)));let a=new Fm([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return cu(new Rm(t,[a],e.input,e.options))},Mg=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function Ng(e,t,n=rg){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(rv(X_(t)))}const Pg=class{name;type;constructor(e,t){this.name=e,this.type=t}};function Fg(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(Fg);default:return!1}}function Ig(e){let t=E_(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(Ig);default:return!1}}function Lg(e){return Fg(e)&&Ig(e)}const Rg=class{parameter;type;constructor(e,t){if(!Lg(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,G_(t)&&!$_(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},zg=class extends og{_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 tv(n,me);let a,o,s=()=>(a||(a=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type})),o=i?n.indexSignatures.map(n=>({is:n,parserKey:e(rv(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 jg(t,n,i,s)??lu;let c=s===Em?o:s[g];if(a!==T&&c!==T){if(r&&(e.has(i)||e.has(typeof a==`number`?globalThis.String(a):a)))return lu;Et(t.out,a,c)}return lu},c=(e,r,i,a)=>{if(!a){let t=i.parserKey(r,e.options);if(!hs(t))return w(hf(t),t=>c(e,r,i,t));a=t}if(a._tag===`Failure`)return jg(e,n,r,a)??lu;let o=a===Em?r:a[g],s=e.input[r],l=i.parserValue(s,e.options);return hs(l)?t(e,r,o,s,l):w(hf(l),n=>t(e,r,o,s,n))},l=(e,n,r)=>{let i=e.input[n],a=r.parserValue(i,e.options);return hs(a)?t(e,n,n,i,a):w(hf(a),r=>t(e,n,n,i,r))},u=i?el()({onItem:(e,[t,n])=>n.is.parameter===bg?l(e,t,n):c(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0;return tp(function*(t,d){if(t===T)return T;if(typeof t!=`object`||!t||Array.isArray(t))return yield*C(new zm(n,t,d));s();let f=t,ee={},te={ast:n,input:f,out:ee,issues:void 0,options:d},ne=d.errors===`all`,re=d.onExcessProperty===`error`,ie=d.concurrency===void 0?1:Zc(d.concurrency),ae=i&&re?n.indexSignatures.map(e=>Ng(f,e.parameter,d)):void 0;if(re){let r=ae?new Set(e):e;if(ae)for(let e of ae)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 Lm(n,f[a],d),r=new Fm([a],e);if(ne){te.issues?te.issues.push(r):te.issues=[r];continue}return yield*C(new Rm(n,[r],t,d))}}}if(r){let e=ie===1?Hg(te,a):Ug(te,a,{concurrency:ie});e&&(yield*e)}if(i&&ie===1)for(let e=0;e<i;e++){let t=o[e],n=t.is.parameter===bg?l:c,r=ae?.[e]??(t.is.parameter===bg?Object.keys(f):Ng(f,t.is.parameter,d));for(let e=0;e<r.length;e++){let i=n(te,r[e],t);if(!hs(i))yield*i;else if(i._tag===`Failure`)return yield*i}}else if(u){let e=bi();for(let t=0;t<i;t++){let n=o[t],r=ae?.[t]??(n.is.parameter===bg?Object.keys(f):Ng(f,n.is.parameter,d));for(let t=0;t<r.length;t++)e.push([r[t],n])}let t=u(te,e,{concurrency:ie});t&&(yield*t)}return te.issues?yield*C(new Rm(n,te.issues,t,d)):ee})};if(i)return c();let l,u=(e,t,n)=>{let r=a[t];return w(hf(n),n=>{let i=Bg(e,r,n);if(i)return i;let o=()=>wm(e.out),s=Hg(e,a.slice(t+1));return s?$f(s,o):o()})};return(e,t)=>{if(e===T)return Tm;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&Zc(t.concurrency)!==1)return(l??=c())(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return C(new zm(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=t_(i,s),l=c?i[s]:T,d=n.parser(l,t);if(!hs(d))return u(o,e,d);if(d===Em){c&&Et(a,s,l);continue}let f=Bg(o,n,d);if(f)return f}}catch(e){return of(e)}return wm(a)}}_rebuild(e,t,n,r){let i=I_(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new Pg(t.name,n)}),a=I_(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new Rg(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new zg(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 Bg(e,t,n){if(n._tag===`Failure`)return jg(e,e.ast,t.name,n);if(n===Em)return;let r=n[g];if(r!==T)Et(e.out,t.name,r);else if(delete e.out[t.name],!G_(t.type)){let n=new Fm([t.name],new Im(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return cu(new Rm(e.ast,[n],e.input,e.options))}}const Vg={onItem(e,t){if(!t_(e.input,t.name))return t.parser(T,e.options);let n=e.input[t.name];return Et(e.out,t.name,n),t.parser(n,e.options)},step:Bg},Hg=/*#__PURE__*/ Qc()(Vg),Ug=/*#__PURE__*/ el()(Vg);function Wg(e,t){return e?t?[...e,...t]:e:t}function Gg(e,t,n){return new zg(Reflect.ownKeys(e).map(t=>new Pg(t,e[t].ast)),[],n,t)}function Kg(e){return e.ast}function qg(e,t,n){return new r_(e.map(Kg),t,void 0,n)}function Jg(e,t){if(e.encoding||t.some(e=>e.encoding))throw Error(`StructWithRest does not support encodings`);let n=e.propertySignatures,r=e.indexSignatures,i=e.checks;for(let e of t){for(let t of e.propertySignatures)if(n.some(e=>e.name===t.name))throw Error(`Duplicate identifier: ${JSON.stringify(t.name)}. ts(2300)`);n=n.concat(e.propertySignatures),r=r.concat(e.indexSignatures),i=Wg(i,e.checks)}return new zg(n,r,void 0,i)}const Yg=/*#__PURE__*/ te(e=>{for(;;){if(tg(e))return pg;let t=e.encoding;if(!t)return e.recur?.(Yg,s)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==s))return pg;e=t[t.length-1].to}});function Xg(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(Xg)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function Zg(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[xm];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!G_(t)){if(Xh(t))return[{key:e.name,literal:t.literal}];if(Zh(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!G_(e)){if(Xh(e))return[{key:t,literal:e.literal}];if(Zh(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>Zg(Yg(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return Zg(e.thunk())}}const Qg=/*#__PURE__*/ new WeakMap,$g=/*#__PURE__*/ Object.freeze([]),e_=e=>e===null?`null`:Array.isArray(e)?`array`:typeof e,t_=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function n_(e){let t=Qg.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=Yg(c);if(Yh(l))continue;if(Xh(l)||Zh(l)){a??=/* @__PURE__ */ new Map;let e=Xh(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=Zg(l);if(u.length){n??=/* @__PURE__ */ new Map,r++;for(let{key:e,literal:r}of u){let i=n.get(e);i||n.set(e,i=[/* @__PURE__ */ new Map,/* @__PURE__ */ new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=/* @__PURE__ */ new Set),a.add(t)}}else{i??={};let e=Xg(l);for(let n of e)(i[n]??=[]).push(t)}}let c={},l=e=>c[e]??=Object.freeze(i?.[e]??$g);if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??$g;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=/* @__PURE__ */ 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=t_(e,r)?e[r]:void 0;if(n!==void 0)return a.get(n)??$g;if(t)return o}return $g}}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=e_(t);if(!_e(t))return l(a);let o=new Set(i?.[a]),s;if(e){let[n,[i]]=e,c=t_(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=t_(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=t_(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(e_(e));return a?t.filter(t=>s[t]===void 0||s[t]===e):t};return Qg.set(e,t),t}const r_=class extends og{_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===T)return Tm;let i=(o??=n_(n.types))(e,r);if(i.length===0)return C(new Hm(n,[],e,t));if(i.length===1){let r=a(i[0])(e,t);return r._tag===`Success`?r:hs(r)?i_(n,r.cause,e,t):a_(n,r,e,t)}return o_(n,a,i,e,t)}}_rebuild(e,t,n){let r=I_(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new r_(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=X_(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Xh);if(t.length>0)return`${u_(n.isMutable)}[ ${t.map(t=>e(t)+d_(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Xh(e.type));if(t.length>0)return`{ ${t.map(t=>`${u_(t.type.context?.isMutable)}${dt(t.name)}${d_(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function i_(e,t,n,r){let i=rh(t);return i?cu(new Hm(e,[i],n,r)):su(t)}function a_(e,t,n,r){return yf(t,t=>i_(e,t,n,r))}function o_(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=c_(a,n);return o?s_(o,a):a.out?a.out:C(new Hm(e,a.issues??[],r,i))}function s_(e,t){return $f(e,e=>t.out===Em?S(t.input):t.out?t.out:C(new Hm(t.ast,t.issues??[],t.input,t.options)))}const c_=/*#__PURE__*/ Qc()({onItem(e,t){return e.parser(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=rh(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]),cu(new Um(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(e.ast.types[t]);else return lu}}}),l_=/*#__PURE__*/ new r_([/*#__PURE__*/ new vg(`Infinity`),/*#__PURE__*/ new vg(`-Infinity`),/*#__PURE__*/ new vg(`NaN`)]);function u_(e){return e?``:`readonly `}function d_(e){return e?`?`:``}const f_=class extends og{_tag=`Suspend`;thunk;constructor(e,t,n,r,i){if(n)throw Error(`Cannot add checks to Suspend`);super(t,void 0,r,i);let a;this.thunk=()=>a??=e()}getParser(e){let t;return(n,r)=>(t??=e(this.thunk()))(n,r)}recur(e){return new f_(()=>e(this.thunk()),this.annotations,void 0,void 0,this.context)}getExpected(e){return e(this.thunk())}},p_=class extends a{_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 p_(this.run,{...this.annotations,...e},this.aborted)}abort(){return new p_(this.run,this.annotations,!0)}and(e,t){return new m_([this,e],t)}},m_=class extends a{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new m_(this.checks,{...this.annotations,...e})}and(e,t){return new m_([this,e],t)}};function h_(e,t,n=!1){return new p_((t,n,r)=>Km(n,e(t,n,r),t,r),t,n)}function g_(e,t){return new p_((t,n,r)=>e(t)?void 0:new Bm(void 0,t,r),t,!0)}function __(e){return h_(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 v_=/*#__PURE__*/ k_(Cg,[/*#__PURE__*/ __()]),y_=/*#__PURE__*/ new ng(/*#__PURE__*/ new r_([v_,l_]),/*#__PURE__*/ new Oh(/*#__PURE__*/ yh(),/*#__PURE__*/ E(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function b_(e,t){let n=new globalThis.RegExp(e),r={source:n.source,flags:n.flags};return h_(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 x_=/*#__PURE__*/ new WeakMap;function S_(e,t){let n=Object.assign(Object.create(Object.getPrototypeOf(e)),e,t);return Reflect.ownKeys(t).every(e=>e===`context`||e===`encoding`)&&x_.set(n,C_(e)),n}function C_(e){let t=x_.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 x_.set(e,n),n}function w_(e,t){return e.encoding===t?e:S_(e,{encoding:t})}function T_(e,t){if(e.context===t)return e;let n=C_(e);return n.context===t&&n.encoding===e.encoding?n:S_(e,{context:t})}function E_(e){return e.encoding?E_(e.encoding[e.encoding.length-1].to):e}function D_(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return O_(e,_i(e.checks.slice(0,-1),n.annotate(t)))}return S_(e,{annotations:{...e.annotations,...t}})}function O_(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:S_(e,{checks:t})}function k_(e,t){return O_(e,Wg(e.checks,t))}function A_(e,t){let n=t(e.to);return n===e.to?e:new ng(n,e.transformation)}function j_(e,t){let n=e,r=n[n.length-1],i=A_(r,t);return i===r?e:_i(e.slice(0,e.length-1),i)}function M_(e){return t=>t.encoding?w_(t,j_(t.encoding,e)):t}function N_(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:w_(r,j_(r.encoding,n))}return e(r)}return te(n)}function P_(e,t){return F_(e,t,Y_(e))}function F_(e,t,n){let r=new ng(e,t);return w_(n,n.encoding?[...n.encoding,r]:[r])}function I_(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 L_(e,t){return T_(e,e.context?new ig(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new ig(!1,!1,void 0,t))}const R_=/*#__PURE__*/ te(e=>{let t=e.context?e.context.isOptional===!1?new ig(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new ig(!0,!1);return z_(T_(e,t))}),z_=/*#__PURE__*/ M_(R_),B_=/*#__PURE__*/ ee(e=>R_(new r_([e,dg])));function V_(e,t){return T_(e,e.context?new ig(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new ig(!1,!1,t))}function H_(e,t,n){return F_(e,n,t)}function U_(e){let t=[],n=[];function r(e){switch(e._tag){case`Literal`:fe(e.literal)&&!t.includes(e.literal)&&t.push(e.literal);return;case`UniqueSymbol`:t.includes(e.symbol)||t.push(e.symbol);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)r(e.types[t]);return;default:n.push(e)}}return r(e),{literals:t,parameters:n}}function W_(e,t){let{literals:n,parameters:r}=U_(e);return new zg(n.map(e=>new Pg(e,t)),r.map(e=>new Rg(e,t)))}function G_(e){return e.context?.isOptional??!1}function K_(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(K_)}function q_(e){function t(e){return K_(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return vi(n)?n:void 0}function J_(e){let t=!0;function n(e){return t=t&&!e.encoding&&!tg(e),t&&`recur`in e&&e.recur(n),e}return`recur`in e&&e.recur(n),t}const Y_=/*#__PURE__*/ te(e=>{let t=C_(e);if(t!==e){let n=Y_(t);return n===t&&e.encoding===void 0?e:T_(n,e.context)}let n=`recur`in e?e.recur(Y_):e;if(`encodingChecks`in n&&n.encodingChecks){let t=J_(e)?n.encodingChecks:Qh(n)||$h(n)||Jh(n)&&n.typeParameters.length>0?q_(n.encodingChecks):void 0;return S_(n,{encodingChecks:void 0,checks:Wg(n.checks,t)})}return n}),X_=/*#__PURE__*/ te(e=>Y_(Q_(e)));function Z_(e,t){let n=t,r=n.length,i=n[r-1],a=[new ng(Q_(w_(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new ng(Q_(n[e-1].to),n[e].transformation.flip()));let o=Q_(i.to);return o.encoding?w_(o,[...o.encoding,...a]):w_(o,a)}const Q_=/*#__PURE__*/ ee(e=>{if(e.encoding)return Z_(e,e.encoding);let t=C_(e);if(t!==e){let n=Q_(t);return n===t?e:T_(n,e.context)}return`flip`in e?e.flip(Q_):`recur`in e?e.recur(Q_):e});function $_(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some($_);default:return!1}}function ev(e,t){let n=t===0?Em:wm(t);return(r,i)=>r===T?Tm:r===t?n:C(new zm(e,r,i))}function tv(e,t){return(n,r)=>n===T?Tm:t(n)?Em:C(new zm(e,n,r))}function nv(e,t,n){let r=e.encodedParts,i=e.literals,a=t.length;for(let e=0;e<i.length;e++){let n=i[e];if(n&&!t.includes(n))return}if(e.suffixLengths[0]>a)return;let o=Array(r.length),s;function c(l,u){if(l===r.length)return u===a;if(s?.has(l*(a+1)+u))return!1;let d=r[l];if(l===r.length-1){let e=t.slice(u);if(d.matchPart(e,n)!==void 0)return o[l]=e,!0}else if(d._tag===`Literal`){let e=i[l];if(t.startsWith(e,u)&&c(l+1,u+e.length))return o[l]=e,!0}else{let r=a-e.suffixLengths[l+1],s=i[l+1],f=s===void 0?r:t.lastIndexOf(s,r);for(;f>=u;){let e=t.slice(u,f);if(d.matchPart(e,n)!==void 0&&c(l+1,f))return o[l]=e,!0;if(f===0)break;f=s===void 0?f-1:t.lastIndexOf(s,f-1)}}return s??=/* @__PURE__ */ new Set,s.add(l*(a+1)+u),!1}return c(0,0)?o:void 0}const rv=/*#__PURE__*/ N_(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(rv)}}),iv=/*#__PURE__*/ N_(e=>{switch(e._tag){default:return e;case`Number`:case`Literal`:case`BigInt`:return e.toCodecStringTree();case`Union`:return e.recur(iv)}}),av=/*#__PURE__*/ new globalThis.RegExp(`^${Mg}$`),ov=/*#__PURE__*/ new globalThis.RegExp(`^(?:${Mg}|Infinity|-Infinity|NaN)$`);function sv(e){return b_(av,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:av.source}),...e})}const cv=/*#__PURE__*/ k_(bg,[/*#__PURE__*/ sv()]),lv=/*#__PURE__*/ new ng(cv,Ih),uv=/*#__PURE__*/ new ng(/*#__PURE__*/ new r_([cv,l_]),Ih),dv=/*#__PURE__*/ new globalThis.RegExp(`^-?\\d+$`);function fv(e){return b_(dv,{expected:`a string representing a bigint`,representation:{id:`effect/schema/isStringBigInt`,payload:null},toJsonSchema:()=>({pattern:dv.source}),...e})}const pv=/*#__PURE__*/ new ng(/* @__PURE__ */ k_(bg,[/*#__PURE__*/ fv({expected:`a string representing a bigint`})]),Lh);function mv(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=mv(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 Nm(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function hv(e){if(!Jh(e))return;let t=e.annotations?.[Sm];return pe(t)?t(e.typeParameters):void 0}function gv(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function _v(e){return e===void 0||typeof e==`string`}function vv(e,t){let n=/* @__PURE__ */ 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 yv(e){return vv(e,gv)}const bv=/*#__PURE__*/ new sg([],()=>(e,t,n)=>yv(e)?Em:C(new zm(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>Sv});function xv(e){return vv(e,_v)}const Sv=/*#__PURE__*/ new ng(/* @__PURE__ */ new sg([],()=>(e,t,n)=>xv(e)?Em:C(new zm(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),/*#__PURE__*/ Fh()),Cv=(e,t,n)=>e===Em?n(t):$f(e,n);function wv(e){if(e._tag===`Middleware`)return(t,n,r)=>{let i=t===Em?e.decode(wm(Dm(n)),r):e.decode(Xf(t,Dm),r);return Tv(i)};let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===Em?wm(t):e;case`Transform`:{let e=e=>e===T?Tm:wm(t.transform(e));return(t,n)=>Cv(t,n,e)}case`TransformOptional`:{let e=e=>Om(t.transform(Dm(e)));return(t,n)=>Cv(t,n,e)}case`TransformEffect`:return(e,n,r)=>Cv(e,n,e=>e===T?Tm:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>Cv(e,n,e=>Tv(t.transform(Dm(e),r)))}}const Tv=e=>$f(e,Om),Ev=(e,t,n,r)=>yf(r,r=>af(()=>Ql(r,r=>new Pm(e,r,t,n))));function Dv(e,t){let n=wv(e.link.transformation),r;return(i,a)=>{if(i===T)return Tm;if(e.isConstructed(i))return Em;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function Ov(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==T&&r!==void 0)return t(r,i);let a=n;if(hs(a)&&a._tag===`Success`){let e=t(a[g],i);return e===Em?a:e}return $f(Ev(e,r,i,a),e=>{let n=t(e,i);return n===Em?wm(e):n})}}function kv(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:Ov(e,n)}function Av(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?hv(e):void 0,o=a?Dv(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>wv(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);if(u&&!n.disableChecks){if(hs(r)){if(r._tag===`Success`){let i=r===Em?t:r[g];if(t!==T&&i!==T){let i=mv(u,t,void 0,e,n);i&&(r=C(new Rm(e,i,t,n)))}}}else r=w(r,r=>{if(t!==T&&r!==T){let r=mv(u,t,void 0,e,n);if(r)return C(new Rm(e,r,t,n))}return S(r)})}if(s&&!n.disableChecks){if(hs(r)){if(r._tag===`Success`){let i=r===Em?t:r[g];if(i===T)return r;let a=mv(s,i,void 0,e,n);a&&(r=C(new Rm(e,a,i,n)))}}else r=w(r,t=>{if(t!==T){let r=mv(s,t,void 0,e,n);if(r)return C(new Rm(e,r,t,n))}return S(t)})}return r},ee=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[g],o=t(a,r)):o=$f(o,e=>{let n=t(e,r);return n===Em?wm(e):n})}if(o._tag===`Success`){let e=o[g],t=ee(e,r);return t===Em?o:t}return o=Ev(e,n,r,o),$f(o,e=>{let t=ee(e,r);return t===Em?wm(e):t})}:ee}const jv=/*#__PURE__*/ Symbol(),Mv=/*#__PURE__*/ new WeakMap,Nv=e=>Lv(e).parser,Pv=e=>Lv(e).makeEffect,Fv=e=>kv(e,Pv);var Iv=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Av(this.ast,Nv)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Av(this.ast,Pv,Fv)}};function Lv(e){let t=Mv.get(e);if(t!==void 0)return t;let n=new Iv(e);return Mv.set(e,n),n}function Rv(e){let t=e.ast,n;return(e,r)=>(n??=Qv(iy,Y_(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function zv(e){let t=Rv(e);return(e,n)=>{let r=qf(t(e,n));return uu(r)?ur(r.value):(ih(r.cause,`Option adapter can only return none for schema issues`),lr())}}function Bv(e){return ny(Y_(e.ast))}function Vv(e){return Uv(e.ast)}function Hv(e){{let t=$v(Xv(e));return e=>{let n=t(e,rg);return uu(n)?!0:(ih(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Uv(e){let t=Y_(e),n=e=>(n=Hv(t),n(e));return e=>n(e)}function Wv(e,t){let n=Xv(e.ast);return t===void 0?n:(e,r)=>n(e,Jv(t,r))}function Gv(e,t){return ey(Wv(e,t))}function Kv(e,t){let n=Xv(Q_(e.ast));return t===void 0?n:(e,r)=>n(e,Jv(t,r))}function qv(e,t){return ey(Kv(e,t))}const Jv=(e,t)=>t?{...e,...t}:e,Yv=e=>e===T?C(new Bm):S(e);function Xv(e){return Qv(ry,e)}function Zv(e,t){return e===Em?S(t):hs(e)?e[`~effect/Effect/args`]===T?Yv(T):e:$f(e,Yv)}function Qv(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??rg);return a===Em?S(r):hs(a)?a[`~effect/Effect/args`]===T?Yv(T):a:$f(a,Yv)}}function $v(e){return(t,n)=>qf(e(t,n))}function ey(e){let t=$v(e);return(e,n)=>{let r=t(e,n);return uu(r)?ur(r.value):(ih(r.cause,`Option adapter can only return none for schema issues`),lr())}}function ty(e,t){let n=qf(e);if(uu(n))return n.value;let r=ih(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function ny(e){let t,n;return(r,i)=>{t??=Lv(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??rg,o=t.make;if(o!==void 0&&r!==T){let e;try{e=o(r,a)}catch(e){throw ih(Zl(e),`Constructor adapter can only throw schema issues`),e}if(e!==jv&&e!==T)return e}return ty(Zv((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}const ry=e=>Lv(e).parser,iy=e=>Lv(e).makeEffect,ay=`~effect/Schema/Schema`,oy=/*#__PURE__*/ Symbol(),sy={[ay]:ay,get make(){let e=Bv(this);return Object.defineProperty(this,"make",{value:e,enumerable:!0}),e},get makeEffect(){let e=Rv(this);return Object.defineProperty(this,"makeEffect",{value:e,enumerable:!0}),e},get makeOption(){let e=zv(this);return Object.defineProperty(this,"makeOption",{value:e,enumerable:!0}),e},pipe(){return r(this,arguments)},annotate(e){return this.rebuild(D_(this.ast,e))},annotateKey(e){return this.rebuild(L_(this.ast,e))},check(...e){return this.rebuild(k_(this.ast,e))},rebuild(e){return cy(e,this[oy])}};function cy(e,t){function n(){}let r=Object.setPrototypeOf(n,sy);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[oy]=t,r.ast=e,r}globalThis.RegExp;const ly=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`),uy=/*#__PURE__*/ ee(e=>dy(e));function dy(e){let t=bm(e)?.toEquivalence;if(t)return t(Jh(e)?e.typeParameters.map(dy):[]);switch(e._tag){case`Never`:return On();case`Declaration`:return fy(e);case`Null`:case`Undefined`:case`Void`:case`Unknown`:case`Any`:case`String`:case`Number`:case`Boolean`:case`BigInt`:case`Symbol`:case`Literal`:case`UniqueSymbol`:case`ObjectKeyword`:case`Enum`:case`TemplateLiteral`:return ze;case`Arrays`:{let t=e.elements.map(dy),n=e.rest.map(dy),[r,...i]=n,a=i.length;return En((o,s)=>{if(!Array.isArray(o)||!Array.isArray(s))return!1;let c=o.length;if(c!==s.length)return!1;let l=0;for(;l<Math.min(c,e.elements.length);l++)if(!t[l](o[l],s[l]))return!1;if(n.length>0){for(;l<c-a;l++)if(!r(o[l],s[l]))return!1;for(let e=0;e<a;e++)if(!i[e](o[l+e],s[l+e]))return!1}return!0})}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return ze;let t=e.propertySignatures.map(e=>dy(e.type)),n=e.indexSignatures.map(e=>dy(e.type));return En((r,i)=>{if(!ge(r)||!ge(i))return!1;for(let n=0;n<t.length;n++){let a=e.propertySignatures[n],o=a.name,s=Object.hasOwn(r,o),c=Object.hasOwn(i,o);if(G_(a.type)&&s!==c||s&&c&&!t[n](r[o],i[o]))return!1}for(let t=0;t<n.length;t++){let a=e.indexSignatures[t],o=Ng(r,a.parameter),s=Ng(i,a.parameter);if(o.length!==s.length)return!1;for(let e=0;e<o.length;e++){let a=o[e];if(!Object.hasOwn(i,a)||!n[t](r[a],i[a]))return!1}}return!0})}case`Union`:{let t=Y_(e).types,n=n_(t),r=t.map((t,n)=>[Uv(t),dy(e.types[n])]);return En((e,t)=>{let i=n(e,!1);for(let n=0;n<i.length;n++){let[a,o]=r[i[n]];if(a(e)&&a(t))return o(e,t)}return!1})}case`Suspend`:{let t;return En((n,r)=>(t??=uy(e.thunk()))(n,r))}}}function fy(e){let t=e.annotations?.representation;if(t===void 0)return ze;switch(t.id){case`effect/schema/Option`:{let[t]=py(e);return(e,n)=>e._tag===n._tag&&(e._tag===`None`||t(e.value,n.value))}case`effect/schema/Result`:{let[t,n]=py(e);return(e,r)=>e._tag===r._tag&&(e._tag===`Success`?t(e.success,r.success):n(e.failure,r.failure))}case`effect/schema/CauseReason`:{let[t,n]=py(e);return my(t,n)}case`effect/schema/Cause`:{let[t,n]=py(e);return hy(t,n)}case`effect/schema/Exit`:{let[t,n,r]=py(e),i=hy(n,r);return(e,n)=>e._tag===n._tag&&(e._tag===`Success`?t(e.value,n.value):i(e.cause,n.cause))}case`effect/schema/ReadonlyMap`:{let[t,n]=py(e);return et(t,n)}case`effect/schema/ReadonlySet`:return tt(py(e)[0]);case`effect/schema/RegExp`:return(e,t)=>e.source===t.source&&e.flags===t.flags;case`effect/schema/URL`:return(e,t)=>e.toString()===t.toString();default:return ze}}function py(e){return e.typeParameters.map(dy)}function my(e,t){return(n,r)=>{if(n._tag!==r._tag)return!1;switch(n._tag){case`Fail`:return e(n.error,r.error);case`Die`:return t(n.defect,r.defect);case`Interrupt`:return n.fiberId===r.fiberId}}}function hy(e,t){let n=An(my(e,t));return(e,t)=>n(e.reasons,t.reasons)}const gy=/*#__PURE__*/ o(2,(e,t)=>by(e,(e,n)=>yy(t,e)?[e,n]:void 0)),_y=/*#__PURE__*/ o(2,(e,t)=>by(e,(e,n)=>yy(t,e)?void 0:[e,n])),vy=e=>e;function yy(e,t){return e.some(e=>e===t||typeof e==`number`&&String(e)===t)}function by(e,t){let n={};for(let r of Reflect.ownKeys(e)){if(!Object.prototype.propertyIsEnumerable.call(e,r))continue;let i=t(r,e[r]);if(i){let[e,t]=i;Et(n,e,t)}}return n}const xy=`~effect/Schema/SchemaError`;function Sy(e){return p(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}const Cy=ay;function wy(){return(e,t,n)=>O(new sg(e.map(Kg),e=>t(e.map(e=>O(e))),n))}function Ty(e,t){return wy()([],()=>(t,n,r)=>e(t)?S(t):C(new zm(n,t,r)),t)}function D(e){return t=>t.annotate(e)}var Ey=class extends (/*#__PURE__*/ Ea(`SchemaError`)){[xy]=xy;constructor(e){let t=St();Ct(0);try{super({issue:e})}finally{Ct(t)}}get message(){return eh(this.issue)}toString(){return`SchemaError(${this.message})`}};function Dy(e){return Sy(e)}function Oy(e){return hs(e)?ky(e):yf(e,e=>af(()=>Ql(e,e=>new Ey(e))))}function ky(e){return uu(e)?e:su(Ql(e.cause,e=>new Ey(e)))}function Ay(e,t){let n;for(let r of e.reasons){if(!Jl(r)||!Dy(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 jy(e){let t=qf(e);if(uu(t))return t.value;throw Ay(t.cause,`Sync adapter can only throw schema errors`)}const My=Vv;function Ny(e,t){let n=Wv(e,t);return(e,t)=>Oy(n(e,t))}const Py=Gv;function Fy(e,t){let n=Ny(e,t);return(e,t)=>jy(n(e,t))}function Iy(e,t){let n=Kv(e,t);return(e,t)=>Oy(n(e,t))}const Ly=qv;function Ry(e,t){let n=Iy(e,t);return(e,t)=>jy(n(e,t))}const zy=Ry,O=cy;function By(e){return p(e,Cy)&&e[Cy]===Cy}const Vy=/*#__PURE__*/ vy(e=>O(R_(e.ast),{schema:e})),k=/*#__PURE__*/ vy(e=>{let t=tb(e);return O(B_(e.ast),{schema:t})}),Hy=/*#__PURE__*/ vy(e=>O(Y_(e.ast),{schema:e})),Uy=/*#__PURE__*/ vy(e=>O(X_(e.ast),{schema:e}));function A(e){let t=O(new vg(e),{literal:e,transform(n){return t.pipe(cb(A(n),{decode:E(()=>n),encode:E(()=>e)}))}});return t}function Wy(e){return e.map(e=>By(e)?e.ast:new vg(e))}function Gy(e){return O(new gg(Wy(e)),{parts:e})}const Ky=/*#__PURE__*/ O(fg),j=/*#__PURE__*/ O(pg),qy=/*#__PURE__*/ O(cg),Jy=/*#__PURE__*/ O(dg),M=/*#__PURE__*/ O(bg),N=/*#__PURE__*/ O(Cg),P=/*#__PURE__*/ O(wg),Yy=/*#__PURE__*/ O(Tg);function Xy(e,t){return O(e,{fields:t,mapFields(e,t){let n=e(this.fields);return Xy(Gg(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function F(e){return Xy(Gg(e,void 0),e)}function I(e,t){return O(W_(e.ast,t.ast),{key:e,value:t})}function Zy(e,t){return O(Jg(e.ast,t.map(Kg)),{schema:e,records:t})}const L=/*#__PURE__*/ vy(e=>O(new Eg(!1,[],[e.ast]),{value:e})),Qy=/*#__PURE__*/ vy(e=>O(new Eg(!1,[e.ast],[e.ast]),{value:e}));function $y(e,t){return O(e,{members:t,mapMembers(e,t){let n=e(this.members);return $y(qg(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function R(e,t){return $y(qg(e,t,void 0),e)}function z(e){let t=e.map(A);return O(qg(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return R(e(this.members))},pick(e){return z(e)},transform(e){return R(t.map((t,n)=>t.transform(e[n])))}})}const eb=/*#__PURE__*/ vy(e=>R([e,qy])),tb=/*#__PURE__*/ vy(e=>R([e,Jy]));function nb(e){return O(new f_(()=>e().ast))}function rb(...e){return t=>t.check(...e)}function ib(e,t){return n=>O(k_(n.ast,[g_(e,t)]),{schema:n})}function B(e){return t=>O(t.ast,{schema:t,identifier:e})}function ab(e){return t=>O(P_(t.ast,new Eh(e,s)),{schema:t})}function ob(e){return sb(e)}function sb(e){return t=>ab(ep(e))(t)}function cb(e,t){return n=>O(H_(n.ast,e.ast,t?Ah(t):Fh()),{from:n,to:e})}function lb(){return(e,t)=>mb()(e,{decode:t,encode:fh})}function ub(e,t){return n=>t?cb(n,t)(e):cb(n)(e)}function db(e){return t=>O(V_(t.ast,e),{schema:t})}function V(e){return A(e).pipe(db(S(e)))}function fb(e,t){return F({_tag:V(e),...t})}function H(e){return t=>{let n={},r=[],i=/* @__PURE__ */ new Set,a={};return o(t),Object.assign(t,{cases:n,discriminants:r,isAnyOf:t=>n=>t.includes(n[e]),guards:a,match:s,matchOrElse:c});function o(t){let s=t.ast;if(eg(s)&&`members`in t&&globalThis.Array.isArray(t.members)&&t.members.every(By))return t.members.forEach(o);let c=Zg(s);if(c.length>0){let o=c.find(t=>t.key===e)?.literal;if(fe(o)){let e=typeof o==`number`?globalThis.String(o):o;if(i.has(e))throw new globalThis.Error(`Duplicate discriminant: ${globalThis.String(o)}`);i.add(e),r.push(o),Et(n,o,t),Et(a,o,Vv(Hy(t)));return}}throw new globalThis.Error(`No literal or unique symbol found`)}function s(){if(arguments.length===1){let t=arguments[0];return function(n){let r=n[e];return(Object.hasOwn(t,r)?t[r]:void 0)(n)}}let t=arguments[0],n=arguments[1],r=t[e];return(Object.hasOwn(n,r)?n[r]:void 0)(t)}function c(){if(arguments.length===2){let t=arguments[0],n=arguments[1];return function(r){let i=r[e];return(Object.hasOwn(t,i)?t[i]??n:n)(r)}}let t=arguments[0],n=arguments[1],r=arguments[2],i=t[e];return(Object.hasOwn(n,i)?n[i]??r:r)(t)}}}function pb(e,t){return Ty(t=>t instanceof e,t)}function mb(){return(e,t)=>new ng(e.ast,Ah(t))}const hb=h_,gb=`^\\S[\\s\\S]*\\S$|^\\S$|^$`;function _b(e){let t=new globalThis.RegExp(gb);return hb(e=>e.trim()===e,{expected:`a string with no leading or trailing whitespace`,representation:{id:`effect/schema/isTrimmed`,payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:`Schema.isTrimmed()`}),arbitraryConstraint:{patterns:[{source:gb,flags:``}]},...e})}function vb(e,t){let n=e.source,r=e.flags,i=/^[dg]*uy?$/.test(r),a=r===``?`new RegExp(${h(n)})`:`new RegExp(${h(n)}, ${h(r)})`;return b_(e,{toJsonSchema:()=>i?{pattern:r.endsWith(`y`)?`^(?:${n})`:n}:[{},!0],toCode:()=>({runtime:`Schema.isPattern(${a})`}),...t})}function yb(e,t,n){if(e.length===0)return t.length===0?{}:[{},!0];let r={pattern:new globalThis.RegExp(n).source};return e===t?r:[r,!0]}function bb(e,t){let n=JSON.stringify(e),r=new globalThis.RegExp(`^${ly(e)}`),i=e.replace(/[\uD800-\uDBFF]$/,``);return hb(t=>t.startsWith(e),{expected:`a string starting with ${n}`,representation:{id:`effect/schema/isStartingWith`,payload:{startsWith:e}},toJsonSchema:()=>yb(i,e,`^${ly(i)}`),toCode:()=>({runtime:`Schema.isStartingWith(${h(e)})`}),arbitraryConstraint:{patterns:[{source:r.source,flags:r.flags}]},...t})}const U=/*#__PURE__*/ O(v_);function xb(e){let t=ir(e.order),n=e.formatter??h;return(r,i)=>hb(e=>t(e,r),{expected:`a value greater than ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r,exclusiveMinimum:!0},...e.annotate?.(r),...i})}function Sb(e){let t=or(e.order),n=e.formatter??h;return(r,i)=>hb(e=>t(e,r),{expected:`a value greater than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,minimum:r},...e.annotate?.(r),...i})}function Cb(e){let t=ar(e.order),n=e.formatter??h;return(r,i)=>hb(e=>t(e,r),{expected:`a value less than or equal to ${n(r)}`,arbitraryConstraint:{order:e.order,maximum:r},...e.annotate?.(r),...i})}function wb(e){let t=or(e.order),n=ir(e.order),r=ar(e.order),i=rr(e.order),a=e.formatter??h;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return hb(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 Tb(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${h(e)}`);return e}const Eb=/*#__PURE__*/ xb({order:tr,annotate:e=>({representation:{id:`effect/schema/isGreaterThan`,payload:{exclusiveMinimum:Tb(e)}},toJsonSchema:()=>({exclusiveMinimum:e}),toCode:()=>({runtime:`Schema.isGreaterThan(${h(e)})`})})}),Db=/*#__PURE__*/ Sb({order:tr,annotate:e=>({representation:{id:`effect/schema/isGreaterThanOrEqualTo`,payload:{minimum:Tb(e)}},toJsonSchema:()=>({minimum:e}),toCode:()=>({runtime:`Schema.isGreaterThanOrEqualTo(${h(e)})`})})}),Ob=/*#__PURE__*/ Cb({order:tr,annotate:e=>({representation:{id:`effect/schema/isLessThanOrEqualTo`,payload:{maximum:Tb(e)}},toJsonSchema:()=>({maximum:e}),toCode:()=>({runtime:`Schema.isLessThanOrEqualTo(${h(e)})`})})}),kb=/*#__PURE__*/ wb({order:tr,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:Tb(e.minimum),maximum:Tb(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${h(e.minimum)}, maximum: ${h(e.maximum)}, exclusiveMinimum: ${h(t)}, exclusiveMaximum: ${h(n)} })`})}}});function Ab(e){return hb(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>[{type:`integer`},!0],toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}const W=/*#__PURE__*/ N.check(/*#__PURE__*/ Ab()),jb=/*#__PURE__*/ W.check(/*#__PURE__*/ Db(0));function Mb(e,t,n){return hb(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 Nb(e){return Mb(1,1,e)}const Pb=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),Fb=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},Ib=[];function Lb(e){let t=Pb(e),n=Ib[t];if(n!==void 0)return n;let r=sx.pipe(cb(j,Wh(Fb(t))));return Ib[t]=r,r}globalThis.RegExp,globalThis.URL;const Rb=/*#__PURE__*/ M.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function zb(e,t){return Rb.pipe(cb(e,Kh(t)))}globalThis.File,globalThis.FormData,globalThis.URLSearchParams;const Bb=/*#__PURE__*/ M.check(/*#__PURE__*/ _b()),Vb=/*#__PURE__*/ M.annotate({expected:`a string that will be decoded as a trimmed string`}).pipe(/*#__PURE__*/ cb(Bb,/*#__PURE__*/ Nh())),Hb=/*#__PURE__*/ M.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),Ub=/*#__PURE__*/ pb(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>mb()(Hb,Gh)}),Wb=/*#__PURE__*/ jh({decode:(e,t)=>pr(Cp(e),{onNone:()=>C(new Bm({expected:`a valid UTC DateTime string`},e,t)),onSome:e=>S(wp(e))}),encode:e=>S(Ep(e))});function Gb(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 Kb(e,t){return W.check(kb({minimum:e,maximum:t}))}const qb=/*#__PURE__*/ Ty(e=>bp(e)&&xp(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]=Gb(e,-864e13,864e13);return lb()(Kb(t,n),E(Sp))},toCodecJson:()=>mb()(M,Wb),toFormatter:()=>e=>e.toString()}),Jb=/*#__PURE__*/ jh({decode:(e,t)=>pr(zi(e),{onNone:()=>C(new Bm({expected:`a valid Duration string`},e,t)),onSome:S}),encode:e=>S(globalThis.String(e))}),Yb=/*#__PURE__*/ Ty(Gi,{representation:{id:`effect/schema/Duration`,payload:null},toCode:()=>({runtime:`Schema.Duration`,Type:`Duration.Duration`,importDeclarations:[`import * as Duration from "effect/Duration"`]}),expected:`Duration`,toCodecJson:()=>mb()(R([F({_tag:A(`Infinity`)}),F({_tag:A(`NegativeInfinity`)}),F({_tag:A(`Nanos`),value:Yy}),F({_tag:A(`Millis`),value:W})]),Mh({decode:e=>{switch(e._tag){case`Infinity`:return Xi;case`NegativeInfinity`:return Zi;case`Nanos`:return Qi(e.value);case`Millis`:return $i(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}}}}))}),Xb=/*#__PURE__*/ (/* @__PURE__ */ M.annotate({expected:`a string that will be decoded as a Duration`})).pipe(/*#__PURE__*/ cb(Yb,Jb)),Zb=/*#__PURE__*/ globalThis.Symbol.for(`immer-draftable`),Qb={};function $b(e,t,n,i,a){let o=nx(n,t,i),s=tx(t),c=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===Qb?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:Qb,value:i}})}static[Cy]=Cy;get[s](){return s}static[Zb]=!0;static identifier=t;static fields=n.fields;static get ast(){return o(this).ast}static pipe(){return r(this,arguments)}static rebuild(e){return o(this).rebuild(e)}static make(e,t){return Bv(o(this))(e??{},t)}static makeOption(e,t){return zv(o(this))(e??{},t)}static makeEffect(e,t){return o(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(D_(this.ast,e))}static annotateKey(e){return this.rebuild(L_(this.ast,e))}static check(...e){return this.rebuild(k_(this.ast,e))}static extend(e){return(t,r)=>{let i=rx(t)?t:F(t),o={...n.fields,...i.fields},s=Gg(o,n.ast.checks,{identifier:e});return $b(this,e,Xy(k_(s,i.ast.checks),o),r,a)}}static mapFields(e,t){return n.mapFields(e,t)}};return a!==void 0&&Object.assign(c.prototype,a(t)),c}function ex(e){return new Oh(E(t=>new e(t,{"~payload":{token:Qb,value:t}})),mh())}function tx(e){return`~effect/Schema/Class/${e}`}function nx(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=tx(t),o=e=>e instanceof i||p(e,a),s=ex(i);return r=cb(O(new sg([e.ast],()=>(e,t,n)=>o(e)?S(e):C(new zm(t,e,n)),{identifier:t,[Sm]:([e])=>({isConstructed:o,link:new ng(e,s)}),toCodec:([e])=>new ng(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[xm]:Zg(e.ast),...n})),s)(e)}}function rx(e){return By(e)}const G=e=>(t,n)=>{let r=rx(t)?t:F(t);return $b(Ta,e,r,n,e=>({toString(){return`${e}(${h({...this})})`}}))},ix=e=>(t,n)=>{let r=rx(t)?t:F(t);return $b(_n,e,r,n,e=>({name:e}))},ax=e=>(t,n,r)=>{let i=rx(n)?n.mapFields(e=>({_tag:V(t),...e}),{unsafePreserveChecks:!0}):fb(t,n);return ix(e??t)(i,r)};function ox(e){return uy(e.ast)}const sx=/*#__PURE__*/ O(/*#__PURE__*/ D_(bv,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),cx=xo,lx=So,ux=ol,dx=gl,fx=_l,px=`~effect/MutableRef`,mx={[px]:px,...Lt,toJSON(){return{_id:`MutableRef`,current:vt(this.current)}}},hx=e=>{let t=Object.create(mx);return t.current=e,t},gx=/*#__PURE__*/ Symbol.for(`effect/MutableList/Empty`),_x=()=>({head:void 0,tail:void 0,length:0}),vx=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})},yx=()=>({array:[],mutable:!0,offset:0,next:void 0}),bx=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=yx(),e.tail=e.tail.next):e.head=e.tail=yx(),e.tail.array.push(t),e.length++},xx=e=>{e.head=e.tail=void 0,e.length=0},Sx=(e,t)=>{if(t=$r(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 xx(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?xx(e):vx(e),n;i=i.next}return xx(e),n},Cx=e=>{if(!e.head)return gx;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:xx(e):vx(e),t},wx={_A:s,_E:s},Tx={"~effect/Queue":wx,"~effect/Queue/Enqueue":wx,"~effect/Queue/Dequeue":wx,...Lt,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:zx(this)}}},Ex=e=>_(t=>{let n=Object.create(Tx);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=_x(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:/* @__PURE__ */ new Set,offers:/* @__PURE__ */ new Set,awaiters:/* @__PURE__ */ new Set},y(n)}),Dx=e=>Ex({capacity:e}),Ox=()=>Ex(),kx=/*#__PURE__*/ o(2,(e,t)=>b(()=>Ax(e,t)?Vx:e.state._tag===`Open`&&e.strategy===`suspend`?Yx(e,t):Bx)),Ax=(e,t)=>e.state._tag===`Open`?e.messages.length>=e.capacity?e.strategy===`sliding`?(Cx(e.messages),bx(e.messages,t),!0):e.capacity<=0&&e.state.takers.size>0&&(bx(e.messages,t),Wx(e),!0):(bx(e.messages,t),Gx(e),!0):!1,jx=/*#__PURE__*/ o(2,(e,t)=>Do(()=>Mx(e,t))),Mx=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=pn(t),r=js(n,Hx);return e.state.offers.size===0&&e.messages.length===0?(eS(e,r),!0):(e.state={...e.state,_tag:`Closing`,exit:r},Gx(e),!0)},Nx=e=>Do(()=>Px(e)),Px=e=>{if(e.state._tag===`Done`)return!1;xx(e.messages);let t=e.state.offers;eS(e,e.state._tag===`Open`?Ux:e.state.exit);for(let e of t)Zx(e);return!0},Fx=e=>Ix(e,1,1/0),Ix=/*#__PURE__*/ o(3,(e,t,n)=>(t=$r(t),n=$r(n),b(()=>Kx(e,t,n)??us(Jx(e,()=>qx(e,t)),Ix(e,t,n))))),Lx=e=>b(()=>Rx(e)??us(Jx(e,()=>qx(e,1)),Lx(e))),Rx=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=Cx(e.messages);return $x(e),un(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=Qx(e.state.offers);return $x(e),un(t)}},zx=e=>e.state._tag===`Done`?0:e.messages.length,Bx=/*#__PURE__*/ un(!1),Vx=/*#__PURE__*/ un(!0),Hx=/*#__PURE__*/ mn(/*#__PURE__*/ Sn()),Ux=/*#__PURE__*/ Cs(),Wx=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(Ds),e.messages.length===0))break}},Gx=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,Wx(e)},0))},Kx=(e,t,n)=>{if(e.state._tag===`Done`)return e.state.exit;if(n<=0||t<=0)return un([]);if(!qx(e,t))return;let r=e.messages.length>0?Sx(e.messages,n):[Qx(e.state.offers)];return $x(e),un(r)},qx=(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,Jx=(e,t)=>Vo(n=>{if(e.state._tag===`Done`)return n(e.state.exit);if(t())return n(Ds);let r={ready:t,resume:n};return e.state.takers.add(r),Do(()=>{e.state._tag!==`Done`&&e.state.takers.delete(r)})}),Yx=(e,t)=>Vo(n=>Ax(e,t)?n(Vx):Xx(e,{_tag:`Single`,message:t,resume:n})),Xx=(e,t)=>{if(e.state._tag!==`Open`)return Zx(t);let n=e.state.offers;return n.add(t),Do(()=>{e.state._tag!==`Done`&&(n.delete(t),e.state._tag===`Closing`&&n.size===0&&e.messages.length===0&&eS(e,e.state.exit))})},Zx=e=>e._tag===`Single`?e.resume(Bx):e.resume(un(e.remaining.slice(e.offset))),Qx=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(Vx),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(un([]))),n},$x=e=>{if(e.state._tag===`Done`)return ud(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(eS(e,e.state.exit),ud(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`)bx(e.messages,t.message),e.state.offers.delete(t),t.resume(Vx);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;bx(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(un([]))}}return!1},eS=(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()},tS=e=>new rS(e),nS=(e,t,n)=>Vo(r=>{if(e.free>=t)return r(n);let i=()=>{e.free<t||(e.waiters.delete(i),r(n))};return e.waiters.add(i),Do(()=>{e.waiters.delete(i)})});var rS=class{waiters=/*#__PURE__*/ new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){let t=b(()=>this.free<e?nS(this,e,t):(this.taken+=e,y(e)));return t}takeIfAvailable(e){return b(()=>this.free<e?y(!1):(this.taken+=e,y(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{for(let e of this.waiters){if(this.free<=0)break;e()}},0),this.free}resize(e){return _(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),Po))}release(e){return _(t=>y(this.releaseUnsafe(t,e)))}get releaseAll(){return _(e=>y(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>Kc(n=>{let r=b(()=>{if(this.free<e){let t=nS(this,e,Po);return x(n(t),()=>r)}return this.taken+=e,kc(n(t),()=>{this.releaseUnsafe(uo(),e)},!0)});return r})}withPermit=/*#__PURE__*/ this.withPermits(1);withPermitsIfAvailable(e){return t=>Kc(n=>this.free<e?Ao:(this.taken+=e,kc(n(ls(t)),()=>{this.releaseUnsafe(uo(),e)},!0)))}};const iS=`~effect/Channel`,aS=e=>p(e,iS),oS={[iS]:{_Env:s,_InErr:s,_InElem:s,_OutErr:s,_OutElem:s},pipe(){return r(this,arguments)}},sS=e=>{let t=Object.create(oS);return t.transform=(t,n)=>yf(e(t,n),e=>S(rf(e))),t},cS=(e,t)=>sS((n,r)=>w(dS(e)(n,r),e=>t(e,r))),lS=e=>sS((t,n)=>e),uS=e=>sS(Jf(function*(t,n){let r=bu(n),i=e=>xu(r,md(e)),a=yield*Mf(e(t,n,r),i);return Mf(a,i)})),dS=e=>e.transform,fS=4096,pS=e=>sS((t,n)=>Zd(()=>dS(e())(t,n))),mS=e=>lS(Qd(()=>{let t=e();return Zd(()=>{let e=t.next();return e.done?ru(e.value):S(e.value)})})),hS=(e,t=fS)=>{let n=ei(t);return lS(Qd(()=>{let t=e(),r=lr();return Zd(()=>{if(r._tag===`Some`)return ru(r.value);let e=[];for(;e.length<n;){let n=t.next();if(n.done){if(e.length===0)return ru(n.value);r=ur(n.value);break}e.push(n.value)}return S(e)})}))},gS=(e,t=fS)=>hS(()=>e[Symbol.iterator](),t),_S=e=>xS(S(e)),vS=/*#__PURE__*/ lS(/*#__PURE__*/ S(/*#__PURE__*/ ru())),yS=e=>lS(S(C(e))),bS=e=>lS(rf(e)),xS=e=>lS(Qd(()=>{let t=!1;return Zd(()=>t?ru():(t=!0,e))})),SS=e=>lS(S(Fx(e))),CS=e=>sS((t,n)=>wS({scope:n,readable:e.evaluate(),onError:e.onError,releaseLockOnEnd:e.releaseLockOnEnd})),wS=e=>{let t=e.readable.getReader(),n=e.exit??hx(void 0),r=Zd(()=>n.current?n.current:wf(Yd({try:()=>t.read(),catch:e.onError}),{onFailure:e=>n.current??rf(e),onSuccess:({done:e,value:t})=>n.current?n.current:e?ru():S(xi(t))}));return _f(yu(e.scope,e.releaseLockOnEnd?Qd(()=>t.releaseLock()):Jd(()=>t.cancel().catch(f))),r)},TS=/*#__PURE__*/ o(2,(e,t)=>cS(e,e=>Qd(()=>{let n=0;return gf(e,e=>t(e,n++))}))),ES=e=>e===void 0||e!==`unbounded`&&e<=1,DS=/*#__PURE__*/ o(e=>aS(e[0]),(e,t,n)=>ES(n?.concurrency)?OS(e,t):kS(e,t,n)),OS=(e,t)=>sS((n,r)=>{let i=0;return gf(dS(e)(n,r),w(e=>t(e,i++)))}),kS=(e,t,n)=>uS(Jf(function*(r,i,a){let o=0,s=yield*dS(e)(r,i),l=n.concurrency===`unbounded`?2**53-1:n.concurrency,u=yield*Dx(0);yield*yu(a,Nx(u));let d=Wf(yield*Tf()),f=ux(a);if(n.unordered){let e=tS(l),n=c(e.release(1)),r=wf({onFailure:e=>w(jx(u,e),n),onSuccess:e=>w(kx(u,e),n)});yield*e.take(1).pipe(w(()=>s),w(e=>{let n=o++;return f(d(r(Zd(()=>t(e,n))))),$d}),Lf({disableYield:!0}),yf(t=>e.withPermits(l-1)(jx(u,t))),Hf(a))}else{let e=yield*Dx(l-2);yield*yu(a,Nx(e)),yield*Lx(e).pipe(df,w(e=>kx(u,e)),Lf({disableYield:!0}),yf(e=>jx(u,e)),Hf(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,Mx(u,e.cause))};yield*s.pipe(w(i=>{if(n)return rf(n);let a=o++,s=d(Zd(()=>t(i,a)));return f(s),s.addObserver(r),kx(e,cx(s))}),Lf({disableYield:!0}),yf(t=>kx(e,su(t)).pipe(ff(jx(e,t)))),Hf(a))}return Lx(u)})),AS=/*#__PURE__*/ o(e=>aS(e[0]),(e,t,n)=>ES(n?.concurrency)?jS(e,t):MS(e,t,n)),jS=(e,t)=>sS((n,r)=>gf(dS(e)(n,r),e=>{let i,a,o=w(e,e=>(a??=bu(r),$f(dS(t(e))(n,a),e=>(i=s(e),i)))),s=ld(e=>{if(i=void 0,a.state._tag===`Empty`)return o;let t=xu(a,lu);return a=void 0,w(t,()=>o)});return Zd(()=>i??o)})),MS=(e,t,n)=>e.pipe(TS(t),BS(n)),NS=e=>AS(e,s),PS=e=>cS(e,e=>{let t,n=0,r=Zd(function r(){if(t===void 0)return w(e,e=>{switch(e.length){case 0:return r();case 1:return S(e[0]);default:return t=e,S(e[n++])}});let i=t[n++];return n>=t.length&&(t=void 0,n=0),S(i)});return S(r)}),FS=/*#__PURE__*/ o(2,(e,t)=>cS(e,e=>S(w(e,function n(r){let i=[];for(let e=0;e<r.length;e++)t(r[e])&&i.push(r[e]);return yi(i)?S(i):w(e,n)})))),IS=/*#__PURE__*/ o(2,(e,t)=>sS((n,r)=>{let i=bu(r);return gf(dS(e)(n,i),e=>{let a=e.pipe(yf(e=>{if(ud(e))return rf(e);let o=i;return i=bu(r),xu(o,su(e)).pipe(ff(dS(t(e))(n,i)),w(e=>(a=e,e)))}));return Zd(()=>a)})})),LS=/*#__PURE__*/ o(3,(e,t,n)=>IS(e,e=>{let r=t(e);return ii(r)?bS(r.failure):n(r.success,e)})),RS=/*#__PURE__*/ o(2,(e,t)=>LS(e,eu,e=>t(e))),zS=/*#__PURE__*/ o(2,(e,t)=>RS(e,e=>yS(t(e)))),BS=/*#__PURE__*/ o(2,(e,{bufferSize:t=16,concurrency:n,switch:r=!1})=>uS(Jf(function*(i,a,o){let s=n===`unbounded`?2**53-1:Math.max(1,n),c=r?void 0:tS(s),l=yield*fx(!0),u=/* @__PURE__ */ new Set,d=yield*Dx(t);yield*yu(o,Nx(d));let f=yield*dS(e)(i,a);return yield*nf(function*(){for(;;){let e;c&&(u.size<s?yield*c.take(1):(e=yield*Vf(f),yield*Cf(c.take(1),ff(cx(e),tf))));let t=e===void 0?yield*f:yield*cx(e),n=bu(o),r=yield*dS(t)(i,n);for(;u.size>=s;){let e=li(u);u.delete(e),u.size===0&&(yield*l.open),yield*lx(e)}let a=yield*r.pipe(pf(()=>cf),w(e=>kx(d,e)),Lf({disableYield:!0}),Mf(Jf(function*(e){let t=fd(e);if(yield*hf(xu(n,ii(t)?su(t.failure):ou(t.success.value))),u.has(a)&&(u.delete(a),c&&(yield*c.release(1)),u.size===0&&(yield*l.open),!ai(t)))return yield*jx(d,e)})),Vf);l.closeUnsafe(),u.add(a)}}).pipe(yf(e=>{let t=fd(e);return ai(t)?l.whenOpen(jx(d,e)):jx(d,e)}),Hf(o)),Lx(d)}))),VS=e=>sS((t,n)=>{let r;return S(Zd(()=>r||e.pipe(_u(n),w(e=>dS(e)(t,n)),w(e=>r=e))))}),HS=/*#__PURE__*/ o(2,(e,t)=>uS((n,r,i)=>vu(i,t).pipe(ff(dS(e)(n,r))))),US=/*#__PURE__*/ o(2,(e,t)=>HS(e,e=>t)),WS=(e,t,n)=>Zd(()=>{let r=gu(),i=dS(e)(ru(),r);return ld(w(i,t),n||S).pipe(Nf(e=>xu(r,e)))}),GS=/*#__PURE__*/ o(2,(e,t)=>WS(e,e=>Lf(w(e,t),{disableYield:!0}))),KS=/*#__PURE__*/ o(3,(e,t,n)=>Zd(()=>{let r=t();return WS(e,e=>qd({while:l,body:()=>e,step:e=>{r=n(r,e)}}),()=>S(r))})),qS=(e,t)=>dS(e)(ru(),t),JS={_R:s,_E:s,_A:s},YS=function(e){this.channel=e};YS.prototype={"~effect/Stream":JS,pipe(){return r(this,arguments)}};const XS=e=>new YS(e),ZS=e=>p(e,`~effect/Stream`),QS=XS,$S=(e,t)=>eC(nf(function*(){let n=yield*Td(t),r=yield*Af(e,vd,vd.defaultValue()),i=!0,a=Zd(()=>n(r)).pipe(w(t=>Af(e,vd,t)),gf(e=>(r=e,xi(e))));return Zd(()=>i?(i=!1,S(xi(r))):a)})),eC=e=>QS(lS(e)),tC=(e,t)=>QS(sS((n,r)=>w(qS(e.channel,r),e=>t(e,r)))),nC=e=>e.channel,rC=/*#__PURE__*/ QS(vS),iC=(...e)=>lC(e),aC=e=>QS(pS(()=>e().channel)),oC=e=>QS(yS(e)),sC=(e,t)=>Array.isArray(e)&&t?.chunkSize===void 0?lC(e):QS(gS(e,t?.chunkSize)),cC=e=>fC(gf(e,sC)),lC=e=>yi(e)?QS(_S(e)):rC,uC=e=>QS(SS(e)),dC=e=>QS(CS(e)),fC=e=>QS(VS(gf(e,nC))),pC=/*#__PURE__*/ o(2,(e,t)=>aC(()=>{let n=0;return QS(TS(e.channel,Si(e=>t(e,n++))))})),mC=/*#__PURE__*/ o(e=>ZS(e[0]),(e,t,n)=>e.channel.pipe(PS,DS(t,n),TS(xi),QS)),hC=/*#__PURE__*/ o(e=>ZS(e[0]),(e,t,n)=>e.channel.pipe(PS,AS(e=>t(e).channel,n),QS)),gC=e=>hC(e,sC),_C=/*#__PURE__*/ o(2,(e,t)=>{let n=QS(NS(mS(()=>yC(e,t))));return vC.set(n,[e,t]),n}),vC=/*#__PURE__*/ new WeakMap;function*yC(e,t){let n=[t,e];for(;n.length>0;){let e=n.pop(),t=vC.get(e);t===void 0?yield e.channel:n.push(t[1],t[0])}}const bC=/*#__PURE__*/ o(2,(e,t)=>QS(FS(nC(e),t))),xC=/*#__PURE__*/ o(2,(e,t)=>QS(zS(e.channel,t))),SC=/*#__PURE__*/ o(e=>ZS(e[0]),(e,t,n)=>tC(e,(e,r)=>Qd(()=>{let r=0,i=!1;return w(Zd(()=>i?ru():e),e=>{let a=e.findIndex(e=>t(e,r++));if(a>=0){i=!0;let t=e.slice(0,n?.excludeLast?a:a+1);return yi(t)?S(t):ru()}return S(e)})}))),CC=/*#__PURE__*/ o(2,(e,t)=>QS(US(e.channel,t))),wC=e=>KS(e.channel,()=>[],(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n]);return e}),TC=/*#__PURE__*/ o(3,(e,t,n)=>KS(e.channel,t,(e,t)=>{for(let r=0;r<t.length;r++)e=n(e,t[r]);return e})),EC=/*#__PURE__*/ o(2,(e,t)=>GS(e.channel,t)),DC=/*#__PURE__*/ o(e=>ZS(e[0]),(e,t,n)=>{let r,i,a=dx(!1);return new ReadableStream({start(n){i=Uf(Of(EC(e,e=>a.whenOpen(Qd(()=>{a.closeUnsafe();for(let t=0;t<e.length;t++)n.enqueue(e[t]);r(),r=void 0}))),t)),i.addObserver(e=>{e._tag===`Failure`?n.error($l(e.cause)):n.close()})},pull(){return new Promise(e=>{r=e,a.openUnsafe()})},cancel(){if(i)return Gf(vf(lx(i)))}},n?.strategy)}),OC=/*#__PURE__*/ o(e=>ZS(e[0]),(e,t)=>gf(Tf(),n=>DC(e,n,t))),kC=`~effect/http/HttpBody`;var AC=class{[kC];constructor(){this[kC]=kC}[_t](){return this.toJSON()}toString(){return h(this,{ignoreToString:!0})}};const jC=/*#__PURE__*/ new class extends AC{_tag=`Empty`;toJSON(){return{_id:`effect/HttpBody`,_tag:`Empty`}}};var MC=class extends AC{_tag=`Raw`;body;contentType;contentLength;constructor(e,t,n){super(),this.body=e,this.contentType=t,this.contentLength=n}toJSON(){return{_id:`effect/HttpBody`,_tag:`Raw`,body:this.body,contentType:this.contentType,contentLength:this.contentLength}}};const NC=(e,t)=>new MC(e,t?.contentType,t?.contentLength);var PC=class extends AC{_tag=`Uint8Array`;contentType;contentLength;text;_body;constructor(e,t,n,r){super(),this._body=e,this.text=r,this.contentType=t,this.contentLength=n}get body(){return this._body??=RC(this.text)}toJSON(){return{_id:`effect/HttpBody`,_tag:`Uint8Array`,body:this.contentType.startsWith(`text/`)||this.contentType.endsWith(`json`)?new TextDecoder().decode(this.body):`Uint8Array(${this.body.length})`,contentType:this.contentType,contentLength:this.contentLength}}};const FC=(e,t)=>new PC(e,t??`application/octet-stream`,e.length),IC=/*#__PURE__*/ new TextEncoder,LC=globalThis.Buffer,RC=LC===void 0?e=>IC.encode(e):e=>LC.from(e,`utf8`),zC=(e,t)=>{if(typeof e!=`string`&&(e=e===void 0?``:String(e)),LC!==void 0)return new PC(void 0,t??`text/plain`,LC.byteLength(e,`utf8`),e);let n=IC.encode(e);return new PC(n,t??`text/plain`,n.length,e)};var BC=class extends AC{_tag=`FormData`;contentType=void 0;contentLength=void 0;formData;constructor(e){super(),this.formData=e}toJSON(){return{_id:`effect/HttpBody`,_tag:`FormData`,formData:this.formData}}};const VC=e=>new BC(e),HC=`~effect/http/HttpClientError`,UC=e=>p(e,HC);var WC=class extends (/*#__PURE__*/ Ea(`HttpClientError`)){constructor(e){`cause`in e.reason?super({...e,cause:e.reason.cause}):super(e)}[HC]=HC;get request(){return this.reason.request}get response(){return`response`in this.reason?this.reason.response:void 0}get message(){return this.reason.message}};const GC=e=>e.endsWith(`Error`)?e.slice(0,-5):e,KC=(e,t,n)=>t?`${e}: ${t} (${n})`:`${e} error (${n})`;var qC=class extends (/*#__PURE__*/ Ea(`TransportError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return KC(GC(this._tag),this.description,this.methodAndUrl)}},JC=class extends (/*#__PURE__*/ Ea(`InvalidUrlError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return KC(GC(this._tag),this.description,this.methodAndUrl)}},YC=class extends (/*#__PURE__*/ Ea(`DecodeError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return KC(GC(this._tag),this.description,e)}},XC=class extends (/*#__PURE__*/ Ea(`EmptyBodyError`)){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return KC(GC(this._tag),this.description,e)}};const ZC=e=>e!==`GET`&&e!==`HEAD`&&e!==`OPTIONS`&&e!==`TRACE`,QC=[[`GET`,`get`],[`POST`,`post`],[`PUT`,`put`],[`DELETE`,`del`],[`PATCH`,`patch`],[`HEAD`,`head`],[`OPTIONS`,`options`],[`TRACE`,`trace`],[`QUERY`,`query`]],$C=(e,t)=>t._tag===`Empty`||t._tag===`FormData`?om(om(e,`content-type`),`content-length`):(e=t.contentType===void 0?om(e,`content-type`):rm(e,`content-type`,t.contentType),t.contentLength===void 0?om(e,`content-length`):rm(e,`content-length`,t.contentLength.toString())),ew=e=>{if(e==null||!/^\d+$/.test(e))return;let t=Number(e);return Number.isSafeInteger(t)?t:void 0};var tw=class extends (/*#__PURE__*/ Ea(`UrlError`)){};const nw=(e,t,n)=>ri({try:()=>{let r=new URL(e,rw());for(let e=0;e<t.params.length;e++){let[n,i]=t.params[e];i!==void 0&&r.searchParams.append(n,i)}return n!==void 0&&(r.hash=n),r},catch:e=>new tw({cause:e})}),rw=()=>{if(`location`in globalThis&&globalThis.location!==void 0&&globalThis.location.origin!==void 0&&globalThis.location.pathname!==void 0)return location.origin+location.pathname},iw=`~effect/http/HttpClientRequest`,aw=e=>p(e,iw),ow={[iw]:iw,...yt,toJSON(){return{_id:`HttpClientRequest`,method:this.method,url:this.url,urlParams:this.urlParams,hash:this.hash,headers:at(this.headers),body:this.body.toJSON()}},pipe(){return r(this,arguments)}};function sw(e,t,n,r,i,a){let o=Object.create(ow);return o.method=e,o.url=t,o.urlParams=n,o.hash=r,o.headers=i,o.body=a,o}const cw=/*#__PURE__*/ sw(`GET`,``,vm,/*#__PURE__*/ lr(),em,jC),lw=e=>(t,n)=>dw(cw,{method:e,url:t,...n??void 0}),uw=/*#__PURE__*/ lw(`GET`),dw=/*#__PURE__*/ o(2,(e,t)=>{let n=e;return t.method&&(n=fw(n,t.method)),t.url&&(n=_w(n,t.url)),t.headers&&(n=mw(n,t.headers)),t.urlParams&&(n=vw(n,t.urlParams)),t.hash&&(n=yw(n,t.hash)),t.body&&(n=bw(n,t.body)),t.accept&&(n=hw(n,t.accept)),t.acceptJson&&(n=gw(n)),n}),fw=/*#__PURE__*/ o(2,(e,t)=>sw(t,e.url,e.urlParams,e.hash,e.headers,e.body)),pw=/*#__PURE__*/ o(3,(e,t,n)=>sw(e.method,e.url,e.urlParams,e.hash,rm(e.headers,t,n),e.body)),mw=/*#__PURE__*/ o(2,(e,t)=>sw(e.method,e.url,e.urlParams,e.hash,im(e.headers,t),e.body)),hw=/*#__PURE__*/ o(2,(e,t)=>pw(e,`Accept`,t)),gw=/*#__PURE__*/ hw(`application/json`),_w=/*#__PURE__*/ o(2,(e,t)=>{if(typeof t==`string`)return sw(e.method,t,e.urlParams,e.hash,e.headers,e.body);let n=new URL(t.toString()),r=mm(n.searchParams),i=hr(n.hash===``?void 0:n.hash.slice(1));return n.search=``,n.hash=``,sw(e.method,n.toString(),r,i,e.headers,e.body)}),vw=/*#__PURE__*/ o(2,(e,t)=>sw(e.method,e.url,ym(e.urlParams,t),e.hash,e.headers,e.body)),yw=/*#__PURE__*/ o(2,(e,t)=>sw(e.method,e.url,e.urlParams,ur(t),e.headers,e.body)),bw=/*#__PURE__*/ o(2,(e,t)=>sw(e.method,e.url,e.urlParams,e.hash,$C(e.headers,t),t)),xw=/*#__PURE__*/ o(e=>aw(e[0]),(e,t,n)=>bw(e,FC(t,n))),Sw=/*#__PURE__*/ o(e=>aw(e[0]),(e,t,n)=>bw(e,zC(t,n))),Cw=/*#__PURE__*/ o(2,(e,t)=>bw(e,VC(t)));function ww(e){let t=nw(e.url,e.urlParams,gr(e.hash));return ai(t)?ur(t.success):lr()}const Tw=e=>{let t=e.method.toUpperCase();return dw(cw,{method:t,url:new URL(e.url),headers:e.headers,body:Ew(e,t)})},Ew=(e,t)=>!ZC(t)||e.body===null?jC:NC(e.body,{contentType:e.headers.get(`content-type`)??void 0,contentLength:ew(e.headers.get(`content-length`))}),Dw=(e,t)=>{let n=nw(e.url,e.urlParams,gr(e.hash));if(ii(n))return ni(n.failure);let r={method:e.method,headers:e.headers};if(t?.signal&&(r.signal=t.signal),ZC(e.method))switch(e.body._tag){case`Empty`:break;case`Raw`:r.body=e.body.body,Ow(e.body.body)&&(r.duplex=`half`);break;case`Uint8Array`:r.body=e.body.body;break;case`FormData`:r.body=e.body.formData;break;case`Stream`:r.body=DC(e.body.stream,t?.context??Ir()),r.duplex=`half`}return ri({try:()=>new Request(n.success,r),catch:e=>new tw({cause:e})})},Ow=e=>typeof ReadableStream<`u`&&e instanceof ReadableStream,kw=(e,t)=>Ef(n=>uf(Dw(e,{context:n,signal:t?.signal}))),Aw=`~effect/http/HttpIncomingMessage`,jw=(e,t)=>{let n=e.headers[`content-type`]??``,r;if(n.includes(`application/json`))try{r=Kf(e.json)}catch{}else if(n.includes(`text/`)||n.includes(`urlencoded`))try{r=Kf(e.text)}catch{}let i={...t,headers:at(e.headers),remoteAddress:e.remoteAddress};return r!==void 0&&(i.body=r),i},Mw=`~effect/http/HttpClientResponse`,Nw=(e,t)=>new Pw(e,t);var Pw=class extends bt{[Aw];[Mw];request;source;constructor(e,t){super(),this.request=e,this.source=t,this[Aw]=Aw,this[Mw]=Mw}toJSON(){return jw(this,{_id:`HttpClientResponse`,request:this.request.toJSON(),status:this.status})}get status(){return this.source.status}get url(){if(this.source.url)return this.source.url.split(`#`)[0];let e=ww(this.request);return dr(e)?``:(e.value.hash=``,e.value.href)}get headers(){return tm(this.source.headers)}cachedCookies;get cookies(){return this.cachedCookies?this.cachedCookies:this.cachedCookies=Bp(this.source.headers.getSetCookie())}get remoteAddress(){return lr()}get stream(){return this.source.body?dC({evaluate:()=>this.source.body,onError:e=>new WC({reason:new YC({request:this.request,response:this,cause:e})})}):oC(new WC({reason:new XC({request:this.request,response:this,description:`can not create stream from empty body`})}))}get json(){return w(this.text,e=>sf({try:()=>e===``?null:JSON.parse(e),catch:e=>new WC({reason:new YC({request:this.request,response:this,cause:e})})}))}textBody;get text(){return this.textBody??=gf(this.arrayBuffer,e=>new TextDecoder().decode(e))}get urlParamsBody(){return w(this.text,e=>sf({try:()=>mm(new URLSearchParams(e)),catch:e=>new WC({reason:new YC({request:this.request,response:this,cause:e})})}))}formDataBody;get formData(){return this.formDataBody??=Yd({try:()=>this.source.formData(),catch:e=>new WC({reason:new YC({request:this.request,response:this,cause:e})})}).pipe(Pf,Kf)}arrayBufferBody;get arrayBuffer(){return this.arrayBufferBody||=Yd({try:()=>this.source.arrayBuffer(),catch:e=>new WC({reason:new YC({request:this.request,response:this,cause:e})})}).pipe(Pf,Kf),this.arrayBufferBody}pipe(){return r(this,arguments)}};const Fw=e=>nm({b3:`${e.traceId}-${e.spanId}-${e.sampled?`1`:`0`}${pr(e.parent,{onNone:()=>``,onSome:e=>`-${e.spanId}`})}`,traceparent:`00-${e.traceId}-${e.spanId}-${e.sampled?`01`:`00`}`}),Iw=`~effect/http/HttpClient`,Lw=/*#__PURE__*/ br(`effect/HttpClient`),Rw=/*#__PURE__*/ o(2,(e,t)=>zw(n=>t(e.postprocess(n)),e.preprocess)),zw=(e,t)=>{let n=Object.create(Bw);return n.preprocess=t,n.postprocess=e,n.execute=function(n){return e(t(n))},n},Bw={[Iw]:Iw,pipe(){return r(this,arguments)},...yt,toJSON(){return{_id:`effect/HttpClient`}},.../*#__PURE__*/ Object.fromEntries(/*#__PURE__*/ QC.map(([e,t])=>[t,function(t,n){return this.execute(lw(e)(t,n))}]))},Vw=e=>zw(t=>w(t,t=>lf(n=>{let r=Jw.get(t),i=r??new AbortController,a=nw(t.url,t.urlParams,gr(t.hash));if(ii(a))return C(new WC({reason:new JC({request:t,cause:a.failure})}));let o=a.success;if(n.getRef(La)||n.getRef(Hw)(t)){let a=e(t,o,i.signal,n);return r?a:If(e=>wf(e(a),{onSuccess(e){return qw.register(e,i),S(new Yw(e,i))},onFailure(e){return tu(e)&&i.abort(),rf(e)}}))}return zf(n.getRef(Gw)(t),{kind:`client`},a=>{a.attribute(`http.request.method`,t.method),a.attribute(`server.address`,o.origin),o.port!==``&&a.attribute(`server.port`,+o.port),a.attribute(`url.full`,o.toString()),a.attribute(`url.path`,o.pathname),a.attribute(`url.scheme`,o.protocol.slice(0,-1));let s=o.search.slice(1);s!==``&&a.attribute(`url.query`,s);let c=n.getRef(lm),l=n.getRef(Uw);for(let e in t.headers)l(e,`request`)&&a.attribute(`http.request.header.${e}`,cm(e,c)?`<redacted>`:t.headers[e]);return t=n.getRef(Ww)?mw(t,Fw(a)):t,If(s=>s(e(t,o,i.signal,n)).pipe(Bf(a,{captureStackTrace:!1}),wf({onSuccess:e=>{a.attribute(`http.response.status_code`,e.status);for(let t in e.headers)l(t,`response`)&&a.attribute(`http.response.header.${t}`,cm(t,c)?`<redacted>`:e.headers[t]);return r?S(e):(qw.register(e,i),S(new Yw(e,i)))},onFailure(e){return!r&&tu(e)&&i.abort(),rf(e)}})))})})),S),Hw=/*#__PURE__*/ Zr(`effect/http/HttpClient/TracerDisabledWhen`,{defaultValue:()=>u}),Uw=/*#__PURE__*/ Zr(`effect/http/HttpClient/TracerHeaderFilter`,{defaultValue:()=>l}),Ww=/*#__PURE__*/ Zr(`effect/http/HttpClient/TracerPropagationEnabled`,{defaultValue:l}),Gw=/*#__PURE__*/ Zr(`effect/http/HttpClient/SpanNameGenerator`,{defaultValue:()=>e=>`http.client ${e.method}`}),Kw=e=>Fu(Lw)(Ef(t=>gf(e,e=>Rw(e,kf(e=>Yr(t,e)))))),qw=/*#__PURE__*/ (()=>{if(`FinalizationRegistry`in globalThis&&globalThis.FinalizationRegistry){let e=/*#__PURE__*/ new FinalizationRegistry(e=>{e.abort()});return{register(t,n){e.register(t,n,t)},unregister(t){e.unregister(t)}}}let e=/*#__PURE__*/ new Map;return{register(t,n){e.set(t,setTimeout(()=>n.abort(),5e3))},unregister(t){let n=e.get(t);n!==void 0&&(clearTimeout(n),e.delete(t))}}})(),Jw=/*#__PURE__*/ new WeakMap;var Yw=class{original;controller;constructor(e,t){this.original=e,this.controller=t}[Mw]=Mw;[Aw]=Aw;applyInterrupt(e){return Zd(()=>(qw.unregister(this.original),Ff(e,()=>Qd(()=>{this.controller.abort()}))))}get request(){return this.original.request}get url(){return this.original.url}get status(){return this.original.status}get headers(){return this.original.headers}get cookies(){return this.original.cookies}get remoteAddress(){return this.original.remoteAddress}get formData(){return this.applyInterrupt(this.original.formData)}get text(){return this.applyInterrupt(this.original.text)}get json(){return this.applyInterrupt(this.original.json)}get urlParamsBody(){return this.applyInterrupt(this.original.urlParamsBody)}get arrayBuffer(){return this.applyInterrupt(this.original.arrayBuffer)}get stream(){return aC(()=>(qw.unregister(this.original),CC(this.original.stream,Qd(()=>{this.controller.abort()}))))}toJSON(){return this.original.toJSON()}[_t](){return this.original[_t]()}pipe(){return r(this,arguments)}};const Xw=/*#__PURE__*/ Zr(`effect/http/FetchHttpClient/Fetch`,{defaultValue:()=>globalThis.fetch});var Zw=class extends (/*#__PURE__*/ br()(`effect/http/FetchHttpClient/RequestInit`)){};const Qw=/*#__PURE__*/ Kw(/*#__PURE__*/ S(/* @__PURE__ */ Vw((e,t,n,r)=>{let i=r.getRef(Xw),a=Vr(r.context,Zw)??{},o=a.headers?am(tm(a.headers),e.headers):e.headers;o[`content-length`]&&(o=om(o,`content-length`));let s=r=>gf(Yd({try:()=>i(t,{...a,method:e.method,headers:o,body:r,duplex:typeof ReadableStream<`u`&&r instanceof ReadableStream?`half`:void 0,signal:n}),catch:t=>new WC({reason:new qC({request:e,cause:t})})}),t=>Nw(e,t));switch(e.body._tag){case`Raw`:case`Uint8Array`:return s(e.body.body);case`FormData`:return s(e.body.formData);case`Stream`:return w(OC(e.body.stream),s)}return s(void 0)})));var $w=class extends (/*#__PURE__*/ br()(`@effect/platform/Socket/WebSocketConstructor`)){};const eT=M,tT=M.pipe(B(`AI.ModelID`)),nT=M.pipe(B(`AI.ProviderID`)),rT=M,iT=M,K=e=>typeof e==`object`&&!!e&&!Array.isArray(e),aT=I(M,j),oT=(...e)=>{let t=e.filter(e=>e!==void 0);if(t.length===0)return;if(t.length===1&&Object.values(t[0]).every(e=>e!==void 0))return t[0];let n={};for(let e of t)for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=K(n[t])&&K(r)?oT(n[t],r):r);return Object.keys(n).length===0?void 0:n},sT=(...e)=>{let t=e.filter(e=>e!==void 0);if(t.length===0)return;if(t.length===1)return t[0];let n=Object.fromEntries(t.flatMap(e=>Object.entries(e).filter(e=>e[1]!==void 0)));return Object.keys(n).length===0?void 0:n},cT=I(M,j),q=I(M,I(M,j)).annotate({identifier:`LLM.ProviderMetadata`}),lT=(...e)=>oT(...e),uT=R([N.check(Eb(0)),A(!1)]),dT=z([`zstd`,`gzip`,`none`]);var fT=class extends G(`AI.HttpOptions`)({body:k(aT),headers:k(I(M,M)),query:k(I(M,M)),timeout:k(uT),headerTimeout:k(uT),chunkTimeout:k(uT),encoding:k(dT)}){};(function(e){function t(t){return t===void 0||t instanceof e?t:new e(t)}e.make=t})(fT||={});const pT=(...e)=>{let t=oT(...e.map(e=>e?.body)),n=sT(...e.map(e=>e?.headers)),r=sT(...e.map(e=>e?.query)),i=e.findLast(e=>e?.timeout!==void 0)?.timeout,a=e.findLast(e=>e?.headerTimeout!==void 0)?.headerTimeout,o=e.findLast(e=>e?.chunkTimeout!==void 0)?.chunkTimeout,s=e.findLast(e=>e?.encoding!==void 0)?.encoding;if(t||n||r||i!==void 0||a!==void 0||o!==void 0||s!==void 0)return new fT({body:t,headers:n,query:r,timeout:i,headerTimeout:a,chunkTimeout:o,encoding:s})};var mT=class extends G(`LLM.GenerationOptions`)({maxTokens:k(N),temperature:k(N),topP:k(N),topK:k(N),frequencyPenalty:k(N),presencePenalty:k(N),seed:k(N),stop:k(L(M))}){};(function(e){e.make=(t={})=>t instanceof e?t:new e(t)})(mT||={});const hT=(e,t)=>e.findLast(e=>e?.[t]!==void 0)?.[t],gT=(...e)=>{let t=new mT({maxTokens:hT(e,`maxTokens`),temperature:hT(e,`temperature`),topP:hT(e,`topP`),topK:hT(e,`topK`),frequencyPenalty:hT(e,`frequencyPenalty`),presencePenalty:hT(e,`presencePenalty`),seed:hT(e,`seed`),stop:hT(e,`stop`)});return Object.values(t).some(e=>e!==void 0)?t:void 0};var _T=class extends G(`LLM.LanguageModelDefaults`)({generation:k(mT),providerOptions:k(cT),http:k(fT)}){};(function(e){e.make=t=>t instanceof e?t:new e({generation:t.generation===void 0?void 0:mT.make(t.generation),providerOptions:t.providerOptions,http:fT.make(t.http)})})(_T||={});const vT=Ty(e=>typeof e==`string`,{title:`ReasoningEffort`}),yT=z([`gemini`,`moonshot`,`none`]),bT=z([`max_completion_tokens`,`max_tokens`]),xT=z([`anthropic`,`alibaba`]);var ST=class extends G(`LLM.LanguageModelCompatibility`)({sanitizer:k(yT),reasoningField:k(M),requireReasoning:k(P),maxTokensField:k(bT),requireFinishReason:k(P),requireAssistantAfterTool:k(P),supportsStore:k(P),streamUsage:k(P),supportsStrictMode:k(P),supportsPromptCacheKey:k(P),cacheFormat:k(xT),zaiToolStream:k(P),requireSignature:k(P),supportsThinkingBlockBinding:k(P),supportsEffortUpdates:k(P)}){};(function(e){e.make=t=>t instanceof e?t:new e(t)})(ST||={});var CT=class e{id;provider;route;defaults;compatibility;constructor(e){this.id=e.id,this.provider=e.provider,this.route=e.route,this.defaults=e.defaults,this.compatibility=e.compatibility}static make(t){return new e({id:tT.make(t.id),provider:nT.make(t.provider),route:t.route,defaults:t.defaults===void 0?void 0:_T.make(t.defaults),compatibility:t.compatibility===void 0?void 0:ST.make(t.compatibility)})}static input(e){return{id:e.id,provider:e.provider,route:e.route,defaults:e.defaults,compatibility:e.compatibility}}static update(t,n){return Object.keys(n).length===0?t:e.make({...e.input(t),...n,route:n.route??t.route})}};const wT=Ty(e=>e instanceof CT,{expected:`LLM.LanguageModel`}),TT=Gy([N,z([`ms`,`s`,`m`,`h`,`d`])]).check(vb(/^\d+(ms|s|m|h|d)$/));var ET=class extends G(`LLM.CacheHint`)({type:z([`ephemeral`,`persistent`]),ttl:k(TT)}){};const DT=F({tools:k(P),system:k(P),messages:k(R([A(`latest-user-message`),A(`latest-assistant`),F({tail:jb})])),ttl:k(TT)}),OT=R([A(`auto`),A(`none`),DT]),kT=W.check(Eb(0)),J=W.check(Db(0)),AT=M.pipe(B(`RelativePath`),D({identifier:`RelativePath`})),jT=M.pipe(B(`AbsolutePath`),D({identifier:`AbsolutePath`})),Y=e=>Vy(e).pipe(cb(k(Hy(e)),{decode:mh({strict:!1}),encode:gh(vr(e=>e!==void 0))})),MT=(e,t)=>Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)),NT=e=>t=>MT(t,e(t)),PT=U.pipe(cb(qb,{decode:E(e=>Sp(e)),encode:E(e=>Tp(e))}));M.pipe(B(`Tool.CallID`)),ax()(`Tool.Error`,{message:M,error:k(Lb()),metadata:k(I(M,j))});const FT=R([F({type:A(`text`),text:M}).annotate({identifier:`Tool.TextContent`}),F({type:A(`file`),uri:M,mime:M,name:k(M)}).annotate({identifier:`Tool.FileContent`})]).pipe(H(`type`)).annotate({identifier:`Tool.Content`});let IT=0,LT=0;function RT(){return BT(!1)}function zT(){return BT(!0)}function BT(e,t=Date.now()){t!==IT&&(IT=t,LT=0),LT++;let n=BigInt(t)*4096n+BigInt(LT),r=e?~n:n,i=Array.from({length:6},(e,t)=>Number(r>>BigInt(40-8*t)&255n).toString(16).padStart(2,`0`)).join(``),a=crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(14));return i+Array.from(a,e=>`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`[e%62]).join(``)}const VT=M.pipe(B(`Project.ID`),D({identifier:`Project.ID`}),NT(e=>({global:e.make(`global`)}))),HT=M.check(bb(`wrk`)).pipe(B(`Workspace.ID`),D({identifier:`Workspace.ID`}),NT(e=>{let t=()=>e.make(`wrk_`+RT());return{ascending:n=>n?e.make(n):t(),create:t}})),UT=F({directory:jT,workspaceID:Y(HT)}).annotate({identifier:`Location.Ref`});F(_y(UT.fields,[`workspaceID`])).annotate({identifier:`Location.PublicRef`}),F(_y(class extends G(`Location.Info`)({directory:jT,workspaceID:Y(HT),project:F({id:VT,directory:jT,canonical:jT})}){}.fields,[`workspaceID`])).annotate({identifier:`Location.PublicInfo`});const WT=M.check(bb(`evt_`)).pipe(B(`Event.ID`),D({identifier:`Event.ID`}),NT(e=>({create:()=>e.make(`evt_`+RT())}))),GT=W.check(Db(0)).pipe(B(`Event.Seq`),D({identifier:`Event.Seq`})),KT=W.check(Db(1)).pipe(B(`Event.Version`),D({identifier:`Event.Version`})),qT=F({aggregateID:M,seq:GT,version:KT});function X(e){let t=F(e.schema),n=F({aggregateID:qT.fields.aggregateID,seq:qT.fields.seq,version:A(e.durable.version).pipe(cb(Hy(KT),Mh({decode:()=>KT.make(e.durable.version),encode:()=>e.durable.version})))});return F({id:WT,created:U,metadata:Y(I(M,j)),type:A(e.type),durable:n,location:Y(UT),data:t}).annotate({identifier:e.identifier??e.type}).pipe(NT(()=>({type:e.type,durability:`durable`,durable:e.durable,data:t})))}function Z(e){let t=F(e.schema);return F({id:WT,created:U,metadata:Y(I(M,j)),type:A(e.type),location:Y(UT),data:t}).annotate({identifier:e.identifier??e.type}).pipe(NT(()=>({type:e.type,durability:`ephemeral`,durable:void 0,data:t})))}function JT(...e){return Object.freeze(e)}const YT=M.pipe(B(`Integration.ID`),D({identifier:`Integration.ID`})),XT=M.pipe(B(`Integration.MethodID`),D({identifier:`Integration.MethodID`})),ZT=M.pipe(B(`Credential.ID`),D({identifier:`Credential.ID`}),NT(e=>({create:()=>e.make(`cred_`+RT())})));JT(Z({type:`credential.updated`,schema:{}}),Z({type:`credential.switched`,schema:{integrationID:YT,credentialID:eb(ZT)}}));const QT=R([F({type:A(`oauth`),methodID:XT,refresh:M,access:M,expires:J,metadata:Y(I(M,j))}).annotate({identifier:`Credential.OAuth`}),F({type:A(`key`),key:M,metadata:Y(I(M,j))}).annotate({identifier:`Credential.Key`}),F({type:A(`external`),methodID:XT,metadata:Y(I(M,j))}).annotate({identifier:`Credential.External`})]).pipe(H(`type`)).annotate({identifier:`Credential.Value`});F({id:ZT,integrationID:YT,label:M,active:P,value:QT}).annotate({identifier:`Credential.Entry`}),F({id:Y(ZT),integrationID:YT,label:Y(M),value:QT,activate:Y(P)}).annotate({identifier:`Credential.CreateInput`});const $T=F({status:z([`needs_auth`]),message:M,url:Y(M)}).annotate({identifier:`Connection.Status`}),eE=R([F({type:A(`credential`),id:ZT,label:M,method:z([`key`,`oauth`,`external`]),status:Y($T)}).annotate({identifier:`Connection.CredentialInfo`}),F({type:A(`env`),name:M,status:Y($T)}).annotate({identifier:`Connection.EnvInfo`})]).pipe(H(`type`)).annotate({identifier:`Connection.Info`}),tE=M.check(bb(`frm_`)).pipe(B(`Form.ID`),D({identifier:`Form.ID`})).pipe(NT(e=>({create:t=>e.make(t??`frm_`+RT())}))),nE=I(M,j).annotate({identifier:`Form.Metadata`}),rE=F({value:M,label:M,description:M.pipe(Y)}).annotate({identifier:`Form.Option`}),iE=F({key:M,op:z([`eq`,`neq`]),value:R([M,N,P])}).annotate({identifier:`Form.When`}),aE={key:M,title:M.pipe(Y),description:M.pipe(Y),required:P.pipe(Y),hidden:P.pipe(Y).annotate({description:`Skip the interactive authentication prompt and use the default unless an answer is supplied`}),when:L(iE).pipe(Y)},oE=Qy(R([F({...aE,type:A(`string`),format:z([`email`,`uri`,`date`,`date-time`]).pipe(Y),minLength:J.pipe(Y),maxLength:J.pipe(Y),pattern:M.pipe(Y),placeholder:M.pipe(Y),default:M.pipe(Y),options:L(rE).pipe(Y),custom:P.pipe(Y)}).annotate({identifier:`Form.StringField`}),F({...aE,type:A(`number`),minimum:N.pipe(Y),maximum:N.pipe(Y),default:N.pipe(Y)}).annotate({identifier:`Form.NumberField`}),F({...aE,type:A(`integer`),minimum:N.pipe(Y),maximum:N.pipe(Y),default:N.pipe(Y)}).annotate({identifier:`Form.IntegerField`}),F({...aE,type:A(`boolean`),default:P.pipe(Y)}).annotate({identifier:`Form.BooleanField`}),F({...aE,type:A(`multiselect`),options:L(rE),minItems:J.pipe(Y),maxItems:J.pipe(Y),custom:P.pipe(Y),default:L(M).pipe(Y)}).annotate({identifier:`Form.MultiselectField`}),F({key:M,type:A(`external`),url:M,title:M.pipe(Y),description:M.pipe(Y)}).annotate({identifier:`Form.ExternalField`})]).pipe(H(`type`),D({identifier:`Form.Field`}))).annotate({identifier:`Form.Fields`}),sE=F({id:tE,sessionID:M,title:M,metadata:nE.pipe(Y),fields:oE}).annotate({identifier:`Form.Info`}),cE=I(M,R([M,N,P,L(M)]).annotate({identifier:`Form.Value`})).annotate({identifier:`Form.Answer`}),lE=R([F({status:A(`pending`)}),F({status:A(`answered`),answer:cE}),F({status:A(`cancelled`),message:M.pipe(Y)})]).pipe(H(`status`)).annotate({identifier:`Form.State`});F({...sE.fields,state:lE}).annotate({identifier:`Form.Detail`}),F({answer:cE}).annotate({identifier:`Form.Reply`}),JT(Z({type:`form.created`,schema:{form:sE}}),Z({type:`form.replied`,schema:{id:tE,sessionID:M,answer:cE}}),Z({type:`form.cancelled`,schema:{id:tE,sessionID:M}}));const uE=YT,dE=XT,fE=R([F({id:dE,type:A(`oauth`),label:M,form:Y(oE)}).annotate({identifier:`Integration.OAuthMethod`}),F({id:dE,type:A(`command`),label:M,command:L(M)}).annotate({identifier:`Integration.CommandMethod`}),F({type:A(`key`),label:Y(M),form:Y(oE)}).annotate({identifier:`Integration.KeyMethod`}),F({id:dE,type:A(`external`),label:M,form:Y(oE)}).annotate({identifier:`Integration.ExternalMethod`}),F({type:A(`env`),names:L(M)}).annotate({identifier:`Integration.EnvMethod`})]).pipe(H(`type`)).annotate({identifier:`Integration.Method`});JT(Z({type:`integration.updated`,schema:{}})),F({id:uE,name:M,metadata:Y(I(M,Ky))}).annotate({identifier:`Integration.Ref`}),F({id:uE,name:M,metadata:Y(I(M,Ky)),methods:L(fE),connections:L(eE)}).annotate({identifier:`Integration.Info`});const pE=M.pipe(B(`Integration.AttemptID`),D({identifier:`Integration.AttemptID`}),NT(e=>({create:()=>e.make(`con_`+RT())}))),mE=F({created:N,expires:N});G(`Integration.Attempt`)({attemptID:pE,url:M,instructions:M,mode:z([`auto`,`code`]),time:mE}),R([F({status:A(`pending`),time:mE}),F({status:A(`complete`),time:mE}),F({status:A(`failed`),message:M,time:mE}),F({status:A(`expired`),time:mE})]).pipe(H(`status`)).annotate({identifier:`Integration.AttemptStatus`}),F({attemptID:pE,time:mE}).annotate({identifier:`Integration.CommandAttempt`}),R([F({status:A(`pending`),message:Y(M),time:mE}),F({status:A(`complete`),time:mE}),F({status:A(`failed`),message:M,time:mE}),F({status:A(`expired`),time:mE})]).pipe(H(`status`)).annotate({identifier:`Integration.CommandAttemptStatus`});const hE=R([z([`reasoning`,`reasoning_content`,`reasoning_text`]),M]).annotate({identifier:`Model.ReasoningField`}),gE=z([`max_completion_tokens`,`max_tokens`]).annotate({identifier:`Model.MaxTokensField`}),_E=z([`assets`,`state`,`root`]).annotate({identifier:`Model.MediaInput`}),vE=z([`anthropic`,`alibaba`]).annotate({identifier:`Model.CacheFormat`}),yE=F({reasoningField:hE.pipe(Y),requireReasoning:P.pipe(Y),maxTokensField:gE.pipe(Y),requireFinishReason:P.pipe(Y),requireAssistantAfterTool:P.pipe(Y),supportsPromptCacheKey:P.pipe(Y),streamUsage:P.pipe(Y),cacheFormat:vE.pipe(Y),supportsThinkingBlockBinding:P.pipe(Y),supportsEffortUpdates:P.pipe(Y),mediaInput:_E.pipe(Y)}).annotate({identifier:`Model.Compatibility`}),bE=F(_y(yE.fields,[`supportsThinkingBlockBinding`,`supportsEffortUpdates`])).annotate({identifier:`Provider.Compatibility`}),xE=M.pipe(B(`Provider.ID`),D({identifier:`Provider.ID`}),NT(e=>({opencode:e.make(`opencode`),anthropic:e.make(`anthropic`),openai:e.make(`openai`),google:e.make(`google`),googleVertex:e.make(`google-vertex`),githubCopilot:e.make(`github-copilot`),amazonBedrock:e.make(`amazon-bedrock`),azure:e.make(`azure`),openrouter:e.make(`openrouter`),mistral:e.make(`mistral`),gitlab:e.make(`gitlab`)})));JT(Z({type:`provider.updated`,schema:{}}));const SE=M,CE=z([`auto`,`enabled`,`disabled`]),wE=R([F({type:A(`summary`)}),F({type:A(`native`)})]).pipe(H(`type`)).annotate({identifier:`Provider.Compaction`}),TE=z([`http`,`websocket`]).annotate({identifier:`Provider.Transport`}),EE=F({ttl:Gy([N,z([`ms`,`s`,`m`,`h`,`d`])]).check(vb(/^\d+(ms|s|m|h|d)$/)).annotate({identifier:`Provider.CacheTTL`}).pipe(Y)}).annotate({identifier:`Provider.Cache`}),DE=z([`zstd`,`gzip`,`none`]).annotate({identifier:`Provider.Encoding`}),OE=R([U,A(!1)]).pipe(Y),kE=Zy(F({timeout:OE,headerTimeout:OE,chunkTimeout:OE,compaction:wE.pipe(Y),cache:EE.pipe(Y),transport:TE.pipe(Y),encoding:DE.pipe(Y)}),[I(M,Ky)]).annotate({identifier:`Provider.Settings`}),AE={settings:kE.pipe(Y),headers:I(M,M).pipe(Y),body:I(M,Ky).pipe(Y)},jE=F({settings:kE.pipe(db(S({}))),headers:I(M,M),body:I(M,Ky)}).annotate({identifier:`Provider.Request`});F({id:xE,canonical:xE.pipe(Y),integrationID:uE.pipe(Y),name:M,activation:CE,package:SE,compatibility:bE.pipe(Y),...AE}).annotate({identifier:`Provider.Info`}).pipe(NT(()=>({empty:e=>({id:e,name:e,activation:`auto`,package:``})})));const ME=U.pipe(B(`Money.USD`),D({identifier:`Money.USD`}),NT(e=>({zero:e.make(0)}))),NE=U.pipe(B(`Money.USDPerMillionTokens`),D({identifier:`Money.USDPerMillionTokens`}),NT(e=>({zero:e.make(0)}))),PE=M.pipe(B(`Model.ID`));JT(Z({type:`model.updated`,schema:{}}));const FE=M.pipe(B(`Model.VariantID`)),IE=F({id:PE,providerID:xE,variant:FE.pipe(Y)}).annotate({identifier:`Model.Ref`}).pipe(NT(e=>({parse:t=>{let n=t.indexOf(`/`);if(n<=0)throw Error(`Invalid model reference: ${t}`);let r=t.slice(0,n),i=t.indexOf(`#`,n+1),a=t.slice(n+1,i===-1?void 0:i),o=i===-1?void 0:t.slice(i+1);if(!a||r.includes(`#`)||o!==void 0&&(!o||o.includes(`#`)))throw Error(`Invalid model reference: ${t}`);return e.make({providerID:xE.make(r),id:PE.make(a),...o?{variant:FE.make(o)}:{}})}}))),LE=M.pipe(B(`Model.Family`)),RE=R([z([`chat`,`decision`,`image`]),M]).annotate({identifier:`Model.Type`}),zE=Zy(F(gy(kE.schema.fields,[`compaction`,`cache`,`encoding`])),[I(M,Ky)]).annotate({identifier:`Model.Settings`}),BE=Zy(F(_y(zE.schema.fields,[`cache`])),zE.records).annotate({identifier:`Model.VariantSettings`}),VE={settings:zE.pipe(Y),headers:I(M,M).pipe(Y),body:I(M,Ky).pipe(Y)},HE=F({tools:P,input:L(M),output:L(M),temperature:P.pipe(Y)}).annotate({identifier:`Model.Capabilities`}).pipe(NT(()=>({default:()=>({tools:!0,input:[`text`,`image`],output:[`text`]})}))),UE=F({tier:F({type:V(`context`),size:W}).pipe(Y),input:NE,output:NE,cache:F({read:NE,write:NE})}).annotate({identifier:`Model.Cost`}),WE=F({id:FE,...VE,settings:BE.pipe(Y)}).annotate({identifier:`Model.Variant`});F({id:PE,modelID:PE,providerID:xE,canonical:xE.pipe(Y),type:RE.pipe(Y),family:LE.pipe(Y),name:M,compatibility:yE.pipe(Y),package:SE.pipe(Y),...VE,capabilities:HE,variants:L(WE),time:F({released:U}),cost:L(UE),status:z([`alpha`,`beta`,`deprecated`,`active`]),enabled:P,limit:F({context:W,input:W.pipe(Y),output:W})}).annotate({identifier:`Model.Info`}).pipe(NT(()=>({default:(e,t)=>({id:t,modelID:t,providerID:e,name:t,capabilities:HE.default(),variants:[],time:{released:0},cost:[],status:`active`,enabled:!0,limit:{context:2e5,output:32e3}})})));const GE=M.check(bb(`ses`)).pipe(B(`SessionID`),D({identifier:`Session.ID`}),NT(e=>({create:()=>e.make(`ses_`+zT())}))),KE=M.check(bb(`per`)).pipe(B(`Permission.ID`),D({identifier:`Permission.ID`}),NT(e=>({create:t=>e.make(t??`per_`+RT())}))),qE=R([F({type:A(`tool`),messageID:M,id:M})]).annotate({identifier:`Permission.Source`}),JE=F({id:KE,sessionID:GE,action:M,resources:L(M),save:L(M).pipe(Y),metadata:I(M,j).pipe(Y),source:qE.pipe(Y),message:M.pipe(Y)}).annotate({identifier:`Permission.Request`}),YE=z([`once`,`always`,`reject`]).annotate({identifier:`Permission.Reply`});JT(Z({type:`permission.asked`,schema:JE.fields}),Z({type:`permission.replied`,schema:{sessionID:GE,requestID:KE,reply:YE}}));const XE=L(F({action:M,resource:M,effect:z([`allow`,`deny`,`ask`]).annotate({identifier:`Permission.Effect`})}).annotate({identifier:`Permission.Rule`})).annotate({identifier:`Permission.Ruleset`}),ZE=Z({type:`agent.updated`,schema:{}}),QE=M.pipe(B(`Agent.ID`),D({identifier:`Agent.ID`})),$E=M.pipe(B(`Agent.Name`)),eD=M.annotate({identifier:`Agent.Color`});F({id:QE,name:$E,model:IE.pipe(Y),request:jE,system:M.pipe(Y),description:M.pipe(Y),mode:z([`subagent`,`primary`,`all`]),hidden:P,color:eD.pipe(Y),steps:kT.pipe(Y),permissions:XE}).annotate({identifier:`Agent.Info`}).pipe(NT(()=>({default:e=>({id:e,name:$E.make(e),request:{settings:{},headers:{},body:{}},mode:`primary`,hidden:!1,permissions:[{action:`*`,resource:`*`,effect:`allow`},{action:`read`,resource:`*.env`,effect:`ask`},{action:`read`,resource:`*.env.*`,effect:`ask`},{action:`read`,resource:`*.env.example`,effect:`allow`}]})}))),JT(ZE);const tD=Z({type:`command.updated`,schema:{}});F({name:M,description:M.pipe(Y)}).annotate({identifier:`Command.Info`}),JT(tD);const nD=F({providerID:xE.check(vb(/^[^/#]+$/u)),model:PE.check(vb(/^[^#]+$/u)),variant:FE.check(vb(/^[^#]+$/u)).pipe(Y)}),rD=R([M.check(vb(/^[^/#]+\/[^#]+(?:#[^#]+)?$/u)),nD]).pipe(cb(nD,{decode:E(e=>typeof e==`string`?iD(e):e),encode:mh({strict:!1})})).annotate({identifier:`Config.ModelSelection`});function iD(e){let t=IE.parse(e);return{providerID:t.providerID,model:t.id,...t.variant?{variant:t.variant}:{}}}const aD=Zy(F(kE.schema.fields),[I(M,tb(sx))]).annotate({identifier:`Config.Provider.Settings`}),oD=Zy(F(zE.schema.fields),[I(M,tb(sx))]).annotate({identifier:`Config.Model.Settings`}),sD=I(M,sx),cD={settings:aD.pipe(Y),headers:I(M,M).pipe(Y),body:sD.pipe(Y)},lD={settings:oD.pipe(Y),headers:I(M,M).pipe(Y),body:sD.pipe(Y)};var uD=class extends G(`Config.Provider.Request`)({headers:cD.headers,body:cD.body}){},dD=class extends G(`Config.Model.Cost.Cache`)({read:NE.pipe(Y),write:NE.pipe(Y)}){},fD=class extends G(`Config.Model.Cost`)({tier:F({type:A(`context`),size:W}).pipe(Y),input:NE,output:NE,cache:dD.pipe(Y)}){},pD=class extends G(`Config.Model.Limit`)({context:W.pipe(Y),input:W.pipe(Y),output:W.pipe(Y)}){};const mD=R([F({supported:A(!1)}),F({supported:A(!0),toggle:P.pipe(Y),effort:M.pipe(L,Y),budget:F({min:W.pipe(Y),max:W.pipe(Y)}).pipe(Y)})]).annotate({identifier:`Config.Model.Reasoning`});var hD=class extends G(`Config.Model`)({modelID:PE.pipe(Y),type:RE.pipe(Y),family:LE.pipe(Y),name:M.pipe(Y),releaseDate:M.check(vb(/^\d{4}-\d{2}(-\d{2})?$/u)).annotate({description:`Release date as YYYY-MM-DD or YYYY-MM`}).pipe(Y),compatibility:yE.pipe(Y),package:M.pipe(Y),...lD,capabilities:HE.mapFields(e=>({tools:Y(e.tools),input:Y(e.input),output:Y(e.output),temperature:e.temperature,reasoning:mD.pipe(Y)})).annotate({identifier:`Config.Model.Capabilities`}).pipe(Y),variants:F({id:FE,...lD,settings:Zy(F(_y(oD.schema.fields,[`cache`])),oD.records).annotate({identifier:`Config.Model.VariantSettings`}).pipe(Y)}).pipe(L,Y),cost:R([fD,fD.pipe(L)]).pipe(Y),disabled:P.pipe(Y),limit:pD.pipe(Y)}){},gD=class extends G(`Config.Provider`)({canonical:xE.pipe(Y),name:M.pipe(Y),env:M.pipe(L,Y),package:M.pipe(Y),compatibility:bE.pipe(Y),...cD,models:I(M,hD).pipe(Y)}){};const _D=M.check(vb(/^#[0-9a-fA-F]{6}$/u));var vD=class extends G(`Config.Agent`)({model:rD.pipe(Y),request:uD.pipe(Y),system:M.pipe(Y),description:M.pipe(Y),mode:z([`subagent`,`primary`,`all`]).pipe(Y),hidden:P.pipe(Y),color:_D.pipe(ob(()=>Xd),Y),steps:kT.pipe(Y),disabled:P.pipe(Y),permissions:XE.pipe(Y)}){},yD=class extends G(`Config.Media.Image`)({auto_resize:P.pipe(Y),max_width:kT.pipe(Y),max_height:kT.pipe(Y),max_base64_bytes:kT.pipe(Y)}){},bD=class extends G(`Config.Media`)({image:yD.pipe(Y)}){},xD=class extends G(`Config.Compaction.Keep`)({tokens:J.pipe(Y)}){},SD=class extends G(`Config.Compaction`)({auto:P.pipe(Y),keep:xD.pipe(Y),buffer:J.pipe(Y)}){},CD=class extends G(`Config.Command`)({template:M,description:M.pipe(Y),agent:M.pipe(Y),model:rD.pipe(Y),subagent:P.pipe(Y),subtask:P.annotate({description:`Deprecated alias for subagent.`}).pipe(Y)}){};const wD=z([`allow`,`deny`]),TD=F({action:z([`provider.use`,`tool.use`,`integration.use`]),resource:M,effect:wD});var ED=class extends G(`ConfigExperimental.Info`)({portable_shell_scanner:P.pipe(Y).annotate({description:`Enable the experimental portable shell permission scanner. Defaults to false.`}),todo:P.pipe(Y).annotate({description:`Enable the experimental todowrite tool. Defaults to false.`}),background_compaction:P.pipe(Y).annotate({description:`Enable experimental background compaction: summarize the conversation in the background as it nears the compaction threshold, so automatic compaction does not wait for the summary. Background summaries that are never used still cost tokens. Defaults to false.`}),media_blob:P.pipe(Y).annotate({description:`Store new session media once in a deduplicated blob table instead of inline in every message row. Defaults to false.`}),image_generate:R([P,F({model:rD.pipe(Y).annotate({description:`Default model for the image_generate tool when the agent doesn't choose one, as providerID/modelID. Falls back to automatic selection when it isn't available.`})})]).pipe(Y).annotate({description:`Enable the experimental image_generate tool, offered while a connected provider has an image model. Set to true, or to an object with an optional default model. Defaults to false.`}),schedules:P.pipe(Y).annotate({description:`Enable experimental scheduled tasks that wake a session with a prompt. Defaults to false.`}),subagent_depth:J.pipe(Y).annotate({description:`Maximum subagent nesting depth. Defaults to 1.`}),location_idle_timeout:R([Xb,A(!1)]).pipe(Y).annotate({description:`How long a location can go without session activity before its services are unloaded. Running sessions and background jobs keep a location loaded. Set to false to never unload (default: "60 minutes")`}),policies:TD.pipe(L,Y).annotate({description:`Deprecated: use top-level policies. Ordered policies controlling access to configured resources`})}){};const DD=R([P,I(M,class extends G(`Config.Formatter.Entry`)({disabled:P.pipe(Y),command:M.pipe(L,Y),environment:I(M,M).pipe(Y),extensions:M.pipe(L,Y)}){})]),OD=R([P,I(M,R([F({disabled:A(!0)}),class extends G(`Config.LSP.Server`)({command:M.pipe(L),extensions:M.pipe(L,Y),disabled:P.pipe(Y),env:I(M,M).pipe(Y),initialization:I(M,j).pipe(Y)}){}]))]);var kD=class extends G(`Mcp.TimeoutConfig`)({startup:kT.pipe(Y).annotate({description:`Maximum time in milliseconds to establish and initialize the MCP server.`}),catalog:kT.pipe(Y).annotate({description:`Maximum time in milliseconds to wait for MCP discovery requests such as tools/list and prompts/list.`}),execution:kT.pipe(Y).annotate({description:`Maximum time in milliseconds to wait for MCP tool and prompt execution.`})}){};const AD=z([`legacy`,`auto`,`2026-07-28`]).annotate({identifier:`Mcp.Protocol`,description:`MCP protocol negotiation. "legacy" (default) opens with the initialize handshake and speaks protocol revisions up to 2025-11-25. "auto" probes for the 2026-07-28 revision and falls back to legacy when the server does not support it. "2026-07-28" requires that revision and fails otherwise.`});var jD=class extends G(`Mcp.LocalConfig`)({type:A(`local`),command:M.pipe(L),cwd:M.pipe(Y).annotate({description:`Working directory for the MCP server process. Relative paths resolve from the workspace directory.`}),environment:I(M,M).pipe(Y),disabled:P.pipe(Y),codemode:P.pipe(Y).annotate({description:`Expose this server's tools through Code Mode. Defaults to true.`}),timeout:kD.pipe(Y),protocol:AD.pipe(Y)}){},MD=class extends G(`Mcp.OAuthConfig`)({client_id:M.pipe(Y),client_secret:M.pipe(Y),scope:M.pipe(Y),callback_port:W.check(kb({minimum:1,maximum:65535})).pipe(Y),redirect_uri:M.pipe(Y),auth_server_metadata_url:M.pipe(Y).annotate({description:`URL of the OAuth or OpenID Connect authorization server metadata document. Set when the MCP server does not publish protected resource metadata that names its authorization server.`})}){};const ND=R([jD,class extends G(`Mcp.RemoteConfig`)({type:A(`remote`),url:M,headers:I(M,M).pipe(Y),oauth:R([MD,A(!1)]).pipe(Y),disabled:P.pipe(Y),codemode:P.pipe(Y).annotate({description:`Expose this server's tools through Code Mode. Defaults to true.`}),timeout:kD.pipe(Y),protocol:AD.pipe(Y)}){}]).pipe(H(`type`));F({name:M,status:R([F({status:A(`connected`)}).annotate({identifier:`Mcp.Status.Connected`}),F({status:A(`pending`)}).annotate({identifier:`Mcp.Status.Pending`}),F({status:A(`disabled`)}).annotate({identifier:`Mcp.Status.Disabled`}),F({status:A(`failed`),error:M}).annotate({identifier:`Mcp.Status.Failed`}),F({status:A(`needs_auth`),error:M}).annotate({identifier:`Mcp.Status.NeedsAuth`})]).pipe(H(`status`)),title:Y(M),integrationID:Y(YT)}).annotate({identifier:`Mcp.Server`});const PD=F({server:M,name:M,uri:M,description:Y(M),mimeType:Y(M)}).annotate({identifier:`Mcp.Resource`}),FD=F({server:M,name:M,uriTemplate:M,description:Y(M),mimeType:Y(M)}).annotate({identifier:`Mcp.ResourceTemplate`});F({resources:L(PD),templates:L(FD)}).annotate({identifier:`Mcp.ResourceCatalog`}),F({server:M,uri:M,contents:L(R([F({type:A(`text`),uri:M,text:M,mimeType:Y(M)}),F({type:A(`blob`),uri:M,blob:M,mimeType:Y(M)})]).pipe(H(`type`),D({identifier:`Mcp.ResourceContentPart`})))}).annotate({identifier:`Mcp.ResourceContent`});const ID=kD,LD=ND;var RD=class extends G(`Config.MCP`)({timeout:ID.pipe(Y),servers:I(M,LD).pipe(Y)}){};const zD=R([M,class extends G(`Config.Plugin.Entry`)({package:M,options:I(M,j).pipe(Y)}){}]).pipe(L),BD=I(M,R([M,class extends G(`Config.Reference.Git`)({repository:M,branch:M.pipe(Y),description:M.pipe(Y),hidden:P.pipe(Y)}){},class extends G(`Config.Reference.Local`)({path:M,description:M.pipe(Y),hidden:P.pipe(Y)}){}])),VD=M.pipe(B(`WebSearch.ID`),D({identifier:`WebSearch.ID`}));F({id:VD,name:M}).annotate({identifier:`WebSearch.Provider`}),F({query:M,providerID:VD.pipe(Y)}).annotate({identifier:`WebSearch.Input`});const HD=F({url:M,title:M.pipe(Y),content:M.pipe(Y),time:F({published:U.pipe(Y).annotate({description:`Publication time in milliseconds since the Unix epoch`})})}).annotate({identifier:`WebSearch.Result`});G(`WebSearch.Response`)({providerID:VD,results:L(HD)}),JT(Z({type:`websearch.updated`,schema:{}}));var UD=class extends G(`ConfigWebSearch.Info`)({provider:R([A(`random`).annotate({description:`Reuse a randomly selected provider until it is rate limited, then switch to another available provider.`}),VD])}){};const WD=R([A(!1),UD]);var GD=class extends G(`Config.ToolOutput`)({max_lines:kT.pipe(Y),max_bytes:kT.pipe(Y)}){},KD=class extends G(`Config.Watcher`)({ignore:M.pipe(L,Y)}){};const qD=R([P,class extends G(`Config.Warming`)({prompt:M.pipe(Y).annotate({description:`Prompt sent for keep-alive requests`}),interval:Xb.pipe(Y).annotate({description:`Idle time between keep-alive requests (default: "4 minutes")`}),duration:Xb.pipe(Y).annotate({description:`Time after the last active request to keep a session warm (default: "30 minutes")`})}){}]),JD=F({directory:Vb.pipe(rb(Nb())).annotate({description:`Parent directory for new worktrees, relative to the project's primary checkout when not absolute`})}).annotate({identifier:`Config.Worktree`});var YD=class extends G(`Config.Info`)({$schema:Y(M).annotate({description:`JSON schema reference for configuration validation`}),shell:M.pipe(Y).annotate({description:`Default shell to use for terminal and shell tool execution`}),model:rD.pipe(Y).annotate({description:`Default model to use when no session or agent model is selected`}),default_agent:M.pipe(Y).annotate({description:`Default primary agent to use when no session agent is selected`}),update:z([`disable`,`notify`,`auto`]).pipe(Y).annotate({description:`Disable updates, notify when one is available, or install updates automatically`}),share:z([`manual`,`auto`,`disabled`]).pipe(Y).annotate({description:`Control whether sessions may be shared manually, automatically, or not at all`}),enterprise:F({url:M.pipe(Y)}).pipe(Y).annotate({description:`Enterprise sharing service configuration`}),username:M.pipe(Y).annotate({description:`Username displayed in conversations and used for telemetry identity`}),timezone:M.pipe(Y).annotate({description:`IANA time zone for schedules, e.g. America/Los_Angeles. Defaults to the server's local zone`}),permissions:XE.pipe(Y).annotate({description:`Ordered tool permission rules applied to agent tool use`}),policies:TD.pipe(L,Y).annotate({description:`Ordered policies controlling access to providers, tools, and integrations`}),agents:I(M,vD).pipe(Y).annotate({description:`Named built-in agent overrides and custom agent definitions`}),snapshots:P.pipe(Y).annotate({description:`Enable snapshots used for undo and revert behavior`}),watcher:KD.pipe(Y).annotate({description:`Filesystem watcher configuration`}),formatter:DD.pipe(Y).annotate({description:`Enable built-in formatters or configure formatter overrides`}),lsp:OD.pipe(Y).annotate({description:`Enable built-in language servers or configure server overrides`}),media:bD.pipe(Y).annotate({description:`Media processing configuration`}),tool_output:GD.pipe(Y).annotate({description:`Tool output truncation thresholds`}),mcp:RD.pipe(Y).annotate({description:`MCP server configuration`}),compaction:SD.pipe(Y).annotate({description:`Conversation compaction behavior`}),skills:M.pipe(L,Y).annotate({description:`Additional paths or URLs to discover skills from`}),commands:I(M,CD).pipe(Y).annotate({description:`Named slash command definitions`}),instructions:M.pipe(L,Y).annotate({description:`Additional paths or URLs supplying ambient instructions`}),references:BD.pipe(Y).annotate({description:`Named local directories or Git repositories available as external context`}),websearch:WD.pipe(Y).annotate({description:`Web search provider selection`}),plugins:zD.pipe(Y).annotate({description:`Ordered plugin enablement directives and external package declarations`}),worktree:JD.pipe(Y).annotate({description:`Directory defaults for local worktree creation`}),warming:qD.pipe(Y).annotate({description:`Keep recently active sessions warm with transient model requests (default: false)`}),providers:I(M,gD).pipe(Y),experimental:ED.pipe(Y)}){};F({shell:eb(M)}).annotate({identifier:`Config.Patch`}),R([class extends G(`Config.Document`)({type:A(`document`),path:jT.pipe(Y),info:YD}){},class extends G(`Config.Directory`)({type:A(`directory`),path:jT}){}]).annotate({identifier:`Config.Entry`}),JT(Z({type:`config.updated`,schema:{}})),JT(Z({type:`filesystem.changed`,schema:{file:M,event:z([`add`,`change`,`unlink`])}})),F({entry:F({path:AT,type:z([`file`,`directory`])}).annotate({identifier:`FileSystem.Entry`}),line:kT,offset:J,text:M,submatches:L(F({text:M,start:J,end:J}).annotate({identifier:`FileSystem.Submatch`}))}).annotate({identifier:`FileSystem.Match`}),G(`FileSystem.FindInput`)({query:M,type:z([`file`,`directory`]).pipe(Y),limit:kT.pipe(Y)}),F({path:jT}).annotate({identifier:`FileSystem.Write`});const XD=z([`stop`,`length`,`tool-calls`,`content-filter`,`error`,`unknown`]);F({id:M.pipe(B(`PermissionSaved.ID`),D({identifier:`PermissionSaved.ID`}),NT(e=>({create:()=>e.make(`psv_`+RT())}))),projectID:VT,action:M,resource:M,time:F({created:PT,updated:PT})}).annotate({identifier:`PermissionSaved.Info`});const ZD=VT,QD=M.check(vb(/^[a-z][a-z0-9._-]*$/u)).annotate({identifier:`Project.Vcs`});F({id:ZD,directory:jT,canonical:jT}).annotate({identifier:`Project.Current`});const $D=F({url:Y(M),override:Y(M),color:Y(M)}).annotate({identifier:`Project.Icon`}),eO=F({start:Y(M.annotate({description:`Startup script to run when creating a new workspace (worktree)`}))}).annotate({identifier:`Project.Commands`}),tO=F({created:J,updated:J,active:J,archived:Y(J)}).annotate({identifier:`Project.Time`}),nO=F({id:ZD,canonical:jT,vcs:Y(QD),name:Y(M),icon:Y($D),commands:Y(eO),time:tO,sandboxes:L(M)}).annotate({identifier:`Project`});F({projectID:ZD,canonical:Y(jT),name:Y(M),icon:Y($D),commands:Y(eO)}).annotate({identifier:`Project.UpdateInput`}),JT(Z({type:`project.updated`,schema:nO.fields})),Vb.pipe(rb(Nb()),B(`Worktree.StrategyID`)),F({projectID:ZD,from:Y(jT),branch:Y(Vb.pipe(rb(Nb()))),directory:Y(jT).annotate({description:`Parent directory for the new worktree. Uses the project's canonical configuration, then defaults to the server's data directory under worktree/<first six project ID characters>.`}),name:Y(M)}).annotate({identifier:`Worktree.CreateInput`}),F({projectID:ZD,directory:jT,force:P}).annotate({identifier:`Worktree.RemoveInput`}),F({directory:jT}).annotate({identifier:`Worktree.Info`});const rO=F({directory:jT,strategy:Y(M)}).annotate({identifier:`Worktree.Directory`});F({directory:jT,type:z([`root`,`worktree`])}).annotate({identifier:`Worktree.ListEntry`}),ax()(`Worktree.OperationError`,{message:M,forceRequired:Y(P)}),L(rO).annotate({identifier:`Worktree.List`}),JT(Z({type:`worktree.updated`,schema:{projectID:ZD}}),X({type:`worktree.resolved`,durable:{aggregate:`projectID`,version:1},schema:{projectID:ZD,directory:jT,previous:ZD,adopted:Y(L(ZD))}})),JT(Z({type:`reference.updated`,schema:{}}));const iO=R([F({type:A(`local`),path:jT,description:M.pipe(Y),hidden:P.pipe(Y)}).annotate({identifier:`Reference.LocalSource`}),F({type:A(`git`),repository:M,branch:M.pipe(Y),description:M.pipe(Y),hidden:P.pipe(Y)}).annotate({identifier:`Reference.GitSource`})]).pipe(H(`type`)).annotate({identifier:`Reference.Source`});F({name:M,path:jT,description:M.pipe(Y),hidden:P.pipe(Y),source:iO}).annotate({identifier:`Reference.Info`});function aO(e){let t=Object.values(e.methods).flatMap(e=>Object.keys(e.errors??{})).find(e=>e.startsWith(`rpc.`));if(t)throw Error(`RPC error names starting with "rpc." are reserved: ${t}`);return e}const oO=I(M,sx).annotate({identifier:`Session.Metadata`}),sO=M.pipe(B(`Skill.ID`),D({identifier:`Skill.ID`})),cO=M.pipe(B(`Skill.Name`),D({identifier:`Skill.Name`})),lO=F({type:V(`directory`),path:jT}).annotate({identifier:`Skill.DirectorySource`}),uO=F({type:V(`url`),url:M}).annotate({identifier:`Skill.UrlSource`}),dO=F({id:sO,name:cO,description:M.pipe(Y),autoinvoke:P.pipe(Y),path:jT,content:M}).annotate({identifier:`Skill.Info`});JT(Z({type:`skill.updated`,schema:{}}));const fO=F({type:V(`embedded`),skill:nb(()=>dO)}).annotate({identifier:`Skill.EmbeddedSource`});Object.assign(R([lO,uO,fO]).pipe(H(`type`),D({identifier:`Skill.Source`})),{equals:(e,t)=>e.type===t.type?e.type===`directory`&&t.type===`directory`?e.path===t.path:e.type===`url`&&t.type===`url`?e.url===t.url:e.type===`embedded`&&t.type===`embedded`&&e.skill.id===t.skill.id:!1,key:e=>e.type===`directory`?`directory:${e.path}`:e.type===`url`?`url:${e.url}`:`embedded:${e.skill.id}`});const pO=F({start:U,end:U,text:M}).annotate({identifier:`Prompt.Mention`}),mO=R([F({type:A(`inline`)}),F({type:A(`uri`),uri:M})]).pipe(H(`type`)).annotate({identifier:`Prompt.FileSource`}),hO=F({data:M.check(hb(e=>e.length%4==0&&/^[A-Za-z0-9+/]*={0,2}$/u.test(e),vb(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u).annotations)).annotate({identifier:`Prompt.Base64`}),mime:M,source:mO,name:M.pipe(Y),description:M.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`Prompt.FileAttachment`}).pipe(NT(e=>({create:t=>e.make({data:t.data,mime:t.mime,source:t.source,name:t.name,description:t.description,mention:t.mention})}))),gO=M.check(vb(/^media:[0-9a-f]{64}$/)).annotate({identifier:`Prompt.MediaRef`}),{data:_O,...vO}=hO.fields,yO=R([hO,F({...vO,uri:gO,bytes:W.pipe(Y),width:W.pipe(Y),height:W.pipe(Y)}).annotate({identifier:`Prompt.MediaFileAttachment`})]).annotate({identifier:`Prompt.Attachment`}),bO=F({name:M,mention:pO.pipe(Y)}).annotate({identifier:`Prompt.AgentAttachment`}),xO=F({id:sO,name:cO,text:M.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`Prompt.SkillAttachment`}),SO=F({text:M,files:L(hO).pipe(Y),agents:L(bO).pipe(Y),skills:L(xO).pipe(Y)}).annotate({identifier:`Prompt`}).pipe(NT(e=>({equivalence:ox(e),fromUserMessage:t=>e.make({text:t.text,...t.files===void 0?{}:{files:t.files},...t.agents===void 0?{}:{agents:t.agents},...t.skills===void 0?{}:{skills:t.skills}})}))),CO=M.check(bb(`sh_`)).pipe(B(`Shell.ID`),D({identifier:`Shell.ID`})).pipe(NT(e=>{let t=()=>e.make(`sh_`+RT());return{create:t,ascending:n=>n===void 0?t():e.make(n)}})),wO=z([`running`,`exited`,`timeout`,`killed`]),TO=F({started:U.annotate({description:`Start time in milliseconds since the Unix epoch`}),completed:Y(U).annotate({description:`Completion time in milliseconds since the Unix epoch`})}),EO=I(M,j),DO=F({id:CO,status:wO,command:M,cwd:M,shell:M,file:M,pid:Y(J),exit:Y(U),signal:Y(M),metadata:EO,time:TO}).annotate({identifier:`Shell.Info`});JT(Z({type:`shell.created`,schema:{info:DO}}),Z({type:`shell.exited`,schema:{id:CO,exit:Y(U),status:wO}}),Z({type:`shell.deleted`,schema:{id:CO}})),F({command:M,cwd:Y(M),timeout:Y(J),metadata:Y(EO)}),F({cursor:Y(J),limit:Y(J)});const OO=F({output:M,cursor:J,size:J,truncated:P}),kO=F({type:M,message:M,status:W.check(kb({minimum:100,maximum:599})).pipe(Y),response:F({body:M}).pipe(Y),retryAfterMs:J.pipe(Y)}).annotate({identifier:`Session.StructuredError`}),AO=M.pipe(B(`Snapshot.ID`),D({identifier:`Snapshot.ID`})),jO=F({input:U,output:U,reasoning:U,cache:F({read:U,write:U})}).annotate({identifier:`TokenUsage.Info`}),MO=M.check(bb(`msg_`)).pipe(B(`Session.Message.ID`),D({identifier:`Session.Message.ID`}),NT(e=>({create:()=>e.make(`msg_`+RT()),fromEvent:t=>e.make(t.replace(/^evt_/,`msg_`))}))),NO={id:MO,metadata:I(M,j).pipe(Y),time:F({created:PT})},PO=I(M,j).annotate({identifier:`Session.Message.Native`}),FO=F({...NO,type:V(`agent-switched`),agent:QE,previous:QE.pipe(Y)}).annotate({identifier:`Session.Message.AgentSelected`}),IO=F({...NO,type:V(`model-switched`),model:IE,previous:IE.pipe(Y)}).annotate({identifier:`Session.Message.ModelSelected`}),LO=F({...NO,type:V(`location-switched`),location:UT,projectID:ZD.pipe(Y),subpath:AT.pipe(Y),previous:F({location:UT,projectID:ZD.pipe(Y),subpath:AT.pipe(Y)}).pipe(Y)}).annotate({identifier:`Session.Message.LocationSwitched`}),RO=F({...NO,text:SO.fields.text,files:SO.fields.files,agents:SO.fields.agents,skills:SO.fields.skills,type:V(`user`)}).annotate({identifier:`Session.Message.User`}),zO=F({...RO.fields,files:L(yO).pipe(Y)}).annotate({identifier:`Session.Message.MediaUser`}),BO=F({...NO,text:M,description:M.pipe(Y),type:V(`synthetic`)}).annotate({identifier:`Session.Message.Synthetic`}),VO=F({...NO,type:V(`system`),text:M,description:M.pipe(Y)}).annotate({identifier:`Session.Message.System`}),HO=F({...NO,type:V(`skill`),skill:sO,name:cO,text:M}).annotate({identifier:`Session.Message.Skill`}),UO=F({...NO,type:V(`shell`),shellID:CO,command:M,status:wO,exit:N.pipe(Y),output:OO.pipe(Y),time:F({created:PT,completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Shell`}),WO=R([F({status:V(`streaming`),input:M}).annotate({identifier:`Session.Message.ToolState.Streaming`}),F({status:V(`running`),input:I(M,j),metadata:I(M,sx)}).annotate({identifier:`Session.Message.ToolState.Running`}),F({status:V(`completed`),input:I(M,j),content:Qy(FT),metadata:I(M,sx).pipe(Y)}).annotate({identifier:`Session.Message.ToolState.Completed`}),F({status:V(`error`),input:I(M,j),error:kO,content:Qy(FT).pipe(Y),metadata:I(M,sx).pipe(Y)}).annotate({identifier:`Session.Message.ToolState.Error`})]).pipe(H(`status`)),GO=F({type:V(`tool`),id:M,name:M,executed:P.pipe(Y),native:PO.pipe(Y),state:WO,time:F({created:PT,ran:PT.pipe(Y),completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Assistant.Tool`}),KO=R([F({type:V(`text`),text:M,native:PO.pipe(Y)}).annotate({identifier:`Session.Message.Assistant.Text`}),F({type:V(`reasoning`),text:M,native:PO.pipe(Y),time:F({created:PT,completed:PT.pipe(Y)}).pipe(Y)}).annotate({identifier:`Session.Message.Assistant.Reasoning`}),GO]).pipe(H(`type`)),qO=Uy(KO).annotate({identifier:`Session.Message.AssistantContent.Encoded`}),JO=F({attempt:kT,at:PT,error:kO}).annotate({identifier:`Session.Message.Assistant.Retry`}),YO=F({...NO,type:V(`assistant`),agent:QE,model:IE,content:KO.pipe(L),snapshot:F({start:AO.pipe(Y),end:AO.pipe(Y),files:L(AT).pipe(Y)}).pipe(Y),finish:XD.pipe(Y),rawFinish:M.pipe(Y),native:PO.pipe(Y),cost:ME.pipe(Y),tokens:jO.pipe(Y),error:kO.pipe(Y),retry:JO.pipe(Y),time:F({created:PT,streamed:PT.pipe(Y),completed:PT.pipe(Y)})}).annotate({identifier:`Session.Message.Assistant`}),XO={type:V(`compaction`),...NO},ZO={cost:ME.pipe(Y),tokens:jO.pipe(Y)},QO=F({...XO,status:V(`running`),reason:z([`auto`,`manual`]),summary:M}).annotate({identifier:`Session.Message.Compaction.Running`}),$O=F({...XO,status:V(`completed`),reason:z([`auto`,`manual`]),model:IE.pipe(Y),native:PO.pipe(Y),summary:M,...ZO}).annotate({identifier:`Session.Message.Compaction.Completed`}),ek=F({...XO,status:V(`failed`),reason:z([`auto`,`manual`]),error:kO,...ZO}).annotate({identifier:`Session.Message.Compaction.Failed`}),tk=R([QO,$O,ek]).pipe(H(`status`),D({identifier:`Session.Message.Compaction`})),nk=F({...NO,type:V(`idle`),outcome:z([`succeeded`,`failed`,`interrupted`]),error:kO.pipe(Y)}).annotate({identifier:`Session.Message.Idle`}),rk=R([FO,IO,LO,RO,BO,VO,HO,UO,YO,tk,nk]).annotate({identifier:`Session.Message.Info`});R([FO,IO,LO,zO,BO,VO,HO,UO,YO,tk,nk]).annotate({identifier:`Session.Message.MediaInfo`});const ik=F({file:M,patch:M,additions:J,deletions:J,status:z([`added`,`deleted`,`modified`]),more:A(!0).pipe(Y)}).annotate({identifier:`FileDiff.Info`});F({file:M.pipe(Y),patch:M.pipe(Y),additions:U,deletions:U,status:z([`added`,`deleted`,`modified`]).pipe(Y)}).annotate({identifier:`FileDiff.LegacyInfo`});const ak=F({messageID:MO,partID:M.pipe(Y),snapshot:AO.pipe(Y),files:L(ik).pipe(Y)}).annotate({identifier:`Session.Revert`}),ok=F({path:M,status:z([`added`,`modified`,`deleted`]),additions:U,deletions:U,patch:M}),sk=F({messageID:MO,partID:M.pipe(Y),snapshot:M.pipe(Y),diff:M.pipe(Y),files:L(ok).pipe(Y)}).annotate({identifier:`Session.RevertV1`});R([ak.pipe(cb(F({source:V(`current`),revert:Hy(ak)}),Mh({decode:e=>({source:`current`,revert:e}),encode:e=>e.revert}))),sk.pipe(cb(F({source:V(`legacy`),revert:Hy(sk)}),Mh({decode:e=>({source:`legacy`,revert:e}),encode:e=>e.revert})))]).pipe(H(`source`),cb(Hy(ak),Mh({decode:e=>e.source===`current`?e.revert:ak.make({messageID:e.revert.messageID,partID:e.revert.partID,snapshot:e.revert.snapshot?AO.make(e.revert.snapshot):void 0,files:e.revert.files?.map(e=>({file:e.path,status:e.status,additions:e.additions,deletions:e.deletions,patch:e.patch}))}),encode:e=>({source:`current`,revert:e})})),D({identifier:`Session.Revert.Persisted`}));const ck=M.check(vb(/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._/-]*$/u)).pipe(B(`Instruction.Key`),D({identifier:`Instruction.Key`})),lk=M.check(vb(/^[a-f0-9]{64}$/u)).pipe(B(`Instruction.Hash`),D({identifier:`Instruction.Hash`})),uk=I(ck,lk),dk=A(`removed`);dk.make(`removed`);const fk=I(M,R([lk,dk])),pk=L(F({...F({key:M.check(vb(/^[a-z0-9][a-z0-9._-]*$/u)).annotate({identifier:`InstructionEntry.Key`,description:`Instruction entry key (lowercase alphanumerics plus . _ -)`}),value:sx.annotate({description:`JSON value attached to the session's instructions`})}).annotate({identifier:`InstructionEntry.Info`}).fields,removed:P})).annotate({identifier:`InstructionEntry.Snapshot`});ax()(`InstructionEntryValueTooLargeError`,{actualBytes:W,maxBytes:W,message:M},{httpApiStatus:413});const mk=z([`steer`,`queue`]).annotate({identifier:`Session.Inbox.Delivery`}),hk=F({...SO.fields,metadata:I(M,j).pipe(Y)}).annotate({identifier:`Session.Inbox.UserPayload`}),gk=F({...hk.fields,files:L(yO).pipe(Y)}).annotate({identifier:`Session.Inbox.MediaUserPayload`}),_k=F({text:M,description:M.pipe(Y),metadata:I(M,j).pipe(Y)}).annotate({identifier:`Session.Inbox.SyntheticPayload`}),vk=F({}).annotate({identifier:`Session.Inbox.CompactionPayload`}),yk=F({location:UT,projectID:ZD,subpath:AT.pipe(Y)}).annotate({identifier:`Session.Inbox.MovePayload`}),bk=F({type:V(`user`),payload:hk,delivery:mk}),xk=F({type:V(`synthetic`),payload:_k,delivery:mk}),Sk=F({type:V(`compaction`),payload:vk,delivery:mk}),Ck=F({type:V(`move`),payload:yk,delivery:mk}),wk=R([bk,xk,Sk,Ck]).pipe(H(`type`),D({identifier:`Session.Inbox.Item`})),Tk={id:MO,sessionID:GE,time:F({created:PT})},Ek=F({...Tk,...bk.fields}).annotate({identifier:`Session.Inbox.User`}),Dk=F({...Ek.fields,payload:gk}).annotate({identifier:`Session.Inbox.MediaUser`}),Ok=F({...Tk,...xk.fields}).annotate({identifier:`Session.Inbox.Synthetic`}),kk=F({...Tk,...Sk.fields}).annotate({identifier:`Session.Inbox.Compaction`}),Ak=F({...Tk,...Ck.fields}).annotate({identifier:`Session.Inbox.Move`});R([Ek,Ok,kk,Ak]).pipe(H(`type`),D({identifier:`Session.Inbox.Info`})),R([Dk,Ok,kk,Ak]).pipe(H(`type`),D({identifier:`Session.Inbox.MediaInfo`}));const jk=R([F({type:A(`before`),messageID:MO}),F({type:A(`through`),messageID:MO})]).annotate({identifier:`Session.ForkBoundary`}),Q={sessionID:GE},$={durable:{aggregate:`sessionID`,version:1}},Mk=X({type:`session.created`,...$,schema:{...Q,projectID:ZD,location:UT,subpath:AT.pipe(Y),parentID:GE.pipe(Y),slug:M,title:M.pipe(Y),agent:QE.pipe(Y),model:IE.pipe(Y),metadata:oO.pipe(Y),permissions:XE.pipe(Y),version:M}}),Nk=X({type:`session.agent.selected`,...$,schema:{...Q,agent:QE,previous:QE.pipe(Y)}}),Pk=X({type:`session.model.selected`,...$,schema:{...Q,model:IE,previous:IE.pipe(Y)}}),Fk=X({type:`session.moved`,...$,schema:{...Q,...yk.fields}}),Ik=X({type:`session.renamed`,...$,schema:{...Q,title:M}}),Lk=X({type:`session.metadata.updated`,...$,schema:{...Q,metadata:oO}}),Rk=X({type:`session.permissions`,...$,schema:{...Q,permissions:XE}}),zk=X({type:`session.viewed`,...$,schema:{...Q,idle:U}}),Bk=X({type:`session.archived`,...$,schema:Q}),Vk=X({type:`session.unarchived`,...$,schema:Q}),Hk=X({type:`session.message.content.updated`,...$,schema:{...Q,messageID:MO,content:L(qO)}}),Uk=X({type:`session.usage.recorded`,...$,schema:{...Q,source:z([`title`,`compaction`]),cost:ME,tokens:jO}}),Wk=Z({type:`session.usage.updated`,schema:{...Q,cost:ME,tokens:jO}}),Gk=X({type:`session.deleted`,durable:{aggregate:`sessionID`,version:2},schema:Q}),Kk=X({type:`session.forked`,durable:{aggregate:`sessionID`,version:2},schema:{...Q,parentID:GE,boundary:jk,instructions:uk.pipe(Y),instructionEntries:pk.pipe(Y)}}),qk={...Q,inboxID:MO},Jk=X({type:`session.inbox.delivered`,...$,schema:qk}),Yk=X({type:`session.inbox.enqueued`,...$,schema:{...qk,item:wk}}),Xk=X({type:`session.inbox.cancelled`,...$,schema:qk}),Zk=X({type:`session.inbox.delivery.changed`,...$,schema:{...qk,delivery:mk}});var Qk;(function(e){e.Started=X({type:`session.execution.started`,...$,schema:Q}),e.Succeeded=X({type:`session.execution.succeeded`,...$,schema:Q}),e.Failed=X({type:`session.execution.failed`,...$,schema:{...Q,error:kO}}),e.Interrupted=X({type:`session.execution.interrupted`,...$,schema:{...Q,reason:z([`user`,`shutdown`,`superseded`,`inactivity`])}})})(Qk||={});const $k=X({type:`session.instructions.updated`,durable:{aggregate:`sessionID`,version:2},schema:{...Q,delta:fk,text:M.pipe(Y)}}),eA=X({type:`session.synthetic`,...$,schema:{...Q,text:M,description:M.pipe(Y),metadata:I(M,j).pipe(Y)}});var tA;(function(e){e.Activated=X({type:`session.skill.activated`,...$,schema:{...Q,id:sO,name:cO,text:M}})})(tA||={});var nA;(function(e){e.Started=X({type:`session.shell.started`,...$,schema:{...Q,shell:DO}}),e.Ended=X({type:`session.shell.ended`,...$,schema:{...Q,shell:DO,output:OO}})})(nA||={});var rA;(function(e){e.Started=X({type:`session.step.started`,...$,schema:{...Q,assistantMessageID:MO,agent:QE,model:IE,snapshot:AO.pipe(Y),started:J}}),e.Streamed=X({type:`session.step.streamed`,...$,schema:{...Q,assistantMessageID:MO}}),e.Ended=X({type:`session.step.ended`,...$,schema:{...Q,assistantMessageID:MO,finish:XD,rawFinish:M.pipe(Y),native:PO.pipe(Y),cost:ME,tokens:jO,snapshot:AO.pipe(Y),files:L(AT).pipe(Y)}}),e.Failed=X({type:`session.step.failed`,...$,schema:{...Q,assistantMessageID:MO,error:kO,finish:z([`content-filter`]).pipe(Y),rawFinish:M.pipe(Y),native:PO.pipe(Y),cost:ME.pipe(Y),tokens:jO.pipe(Y),snapshot:AO.pipe(Y),files:L(AT).pipe(Y)}})})(rA||={});var iA;(function(e){e.Started=X({type:`session.text.started`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J}}),e.Delta=Z({type:`session.text.delta`,schema:{...Q,assistantMessageID:MO,ordinal:J,delta:M}}),e.Ended=X({type:`session.text.ended`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,text:M,native:PO.pipe(Y)}})})(iA||={});var aA;(function(e){e.Started=X({type:`session.reasoning.started`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,native:PO.pipe(Y)}}),e.Delta=Z({type:`session.reasoning.delta`,schema:{...Q,assistantMessageID:MO,ordinal:J,delta:M}}),e.Ended=X({type:`session.reasoning.ended`,...$,schema:{...Q,assistantMessageID:MO,ordinal:J,text:M,native:PO.pipe(Y)}})})(aA||={});var oA;(function(e){let t={...Q,assistantMessageID:MO,id:M};(function(e){e.Started=X({type:`session.tool.input.started`,...$,schema:{...t,name:M}}),e.Delta=Z({type:`session.tool.input.delta`,schema:{...t,delta:M}}),e.Ended=X({type:`session.tool.input.ended`,...$,schema:{...t,text:M}})})(e.Input||={}),e.Called=X({type:`session.tool.called`,...$,schema:{...t,input:I(M,j),executed:P,native:PO.pipe(Y)}}),e.Progress=Z({type:`session.tool.progress`,schema:{...t,metadata:I(M,sx)}}),e.Success=X({type:`session.tool.success`,durable:{aggregate:`sessionID`,version:2},schema:{...t,content:Qy(FT),metadata:I(M,sx).pipe(Y),executed:P,native:PO.pipe(Y)}}),e.Failed=X({type:`session.tool.failed`,durable:{aggregate:`sessionID`,version:2},schema:{...t,error:kO,content:Qy(FT).pipe(Y),metadata:I(M,sx).pipe(Y),executed:P,native:PO.pipe(Y)}})})(oA||={});const sA=X({type:`session.retry.scheduled`,...$,schema:{...Q,assistantMessageID:MO,attempt:kT,at:J,error:kO}});var cA;(function(e){e.Started=X({type:`session.compaction.started`,...$,schema:{...Q,reason:z([`auto`,`manual`]),inputID:MO.pipe(Y)}}),e.Delta=Z({type:`session.compaction.delta`,schema:{...Q,text:M}}),e.Ended=X({type:`session.compaction.ended`,...$,schema:{...Q,reason:e.Started.data.fields.reason,model:$O.fields.model,native:$O.fields.native,text:M,cost:$O.fields.cost,tokens:$O.fields.tokens}}),e.Failed=X({type:`session.compaction.failed`,...$,schema:{...Q,reason:e.Started.data.fields.reason,error:kO,inputID:MO.pipe(Y),cost:ek.fields.cost,tokens:ek.fields.tokens}})})(cA||={});var lA;(function(e){e.Staged=X({type:`session.revert.staged`,...$,schema:{...Q,revert:ak}}),e.Cleared=X({type:`session.revert.cleared`,...$,schema:Q}),e.Committed=X({type:`session.revert.committed`,...$,schema:{...Q,to:MO}})})(lA||={});const uA=JT(Mk,Nk,Pk,Fk,Ik,Lk,Rk,zk,Bk,Vk,Wk,Gk,Kk,Jk,Yk,Xk,Zk,Qk.Started,Qk.Succeeded,Qk.Failed,Qk.Interrupted,$k,eA,tA.Activated,nA.Started,nA.Ended,rA.Started,rA.Streamed,rA.Ended,rA.Failed,iA.Started,iA.Delta,iA.Ended,aA.Started,aA.Delta,aA.Ended,oA.Input.Started,oA.Input.Delta,oA.Input.Ended,oA.Called,oA.Progress,oA.Success,oA.Failed,sA,cA.Started,cA.Delta,cA.Ended,cA.Failed,lA.Staged,lA.Cleared,lA.Committed),dA=JT(...uA.filter(e=>e.durability===`durable`),Uk,Hk),fA=JT(...uA.filter(e=>e.durability===`ephemeral`));R([R(dA,{mode:`oneOf`}).annotate({identifier:`Session.Event.Durable`}).pipe(H(`type`)),...fA],{mode:`oneOf`}).pipe(H(`type`));const pA=GE,mA=oO,hA=jk,gA=F({id:pA,parentID:pA.pipe(Y),fork:F({sessionID:pA,boundary:hA}).pipe(Y),projectID:ZD,agent:QE.pipe(Y),model:IE.pipe(Y),cost:ME,tokens:jO,outcome:z([`succeeded`,`failed`,`interrupted`]).pipe(Y),time:F({created:PT,updated:PT,idle:PT.pipe(Y),viewed:PT.pipe(Y),archived:PT.pipe(Y)}),title:M.pipe(Y),location:UT,subpath:AT.pipe(Y),metadata:mA.pipe(Y),permissions:XE.pipe(Y),revert:ak.pipe(Y)}).annotate({identifier:`Session.Info`}),_A=F({id:pA,time:U,direction:z([`previous`,`next`])}).annotate({identifier:`Session.ListAnchor`}),vA={order:z([`asc`,`desc`]).pipe(k).annotate({description:`Session order for the first page. Use desc for newest first or asc for oldest first.`}),search:M.pipe(k),parentID:R([pA,qy.pipe(ub(A(`null`),{decode:E(()=>null),encode:E(()=>`null`)}))]).annotate({description:`Filter by parent session. Use null to return only root sessions.`}).pipe(k),archived:z([`true`,`false`]).pipe(cb(P,{decode:E(e=>e===`true`),encode:E(e=>e?`true`:`false`)})).annotate({description:`Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.`}).pipe(k)};F({...vA,directory:jT.pipe(k),project:ZD.pipe(k),subpath:AT.pipe(k)}).annotate({identifier:`Session.ListFilter`});const yA=zb(R([F({...vA,directory:jT,anchor:_A}),F({...vA,project:ZD,subpath:AT.pipe(k),anchor:_A}),F({...vA,anchor:_A})])),bA=zy(yA),xA=Ny(yA);M.pipe(B(`SessionsCursor`),D({identifier:`SessionsCursor`,description:`Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response.`}),NT(e=>{let t=Bv(e);return{make:e=>t(ah(bA(e))),parse:e=>Zd(()=>{let t=sh(e);return ii(t)?C(`Invalid cursor`):xA(t.success).pipe(bf(()=>`Invalid cursor`))})}}));const SA=F({current:Y(M),default:Y(M)}).annotate({identifier:`Vcs.Branch`});F({provider:Y(M),branch:SA}).annotate({identifier:`Vcs.Info`}),L(M).annotate({identifier:`Vcs.BranchList`}),F({name:M,ref:M,source:z([`reflog`,`default`])}).annotate({identifier:`Vcs.Base`}),z([`working`,`branch`,`committed`]).annotate({identifier:`Vcs.Mode`}),z([`files`,`folders`]).annotate({identifier:`Vcs.Untracked`}),F({file:M,additions:J,deletions:J,status:z([`added`,`deleted`,`modified`])}).annotate({identifier:`Vcs.FileStatus`});const CA=F({date:M,steps:J}).annotate({identifier:`SessionStats.Activity`}),wA=F({model:IE,steps:J,tokens:jO,cost:ME}).annotate({identifier:`SessionStats.ModelUsage`}),TA=F({name:M,calls:J,succeeded:J,failed:J,unfinished:J,durationP50:U.pipe(Y)}).annotate({identifier:`SessionStats.ToolUsage`});z([`none`,`summary`,`detail`]);const EA=F({calls:J,succeeded:J,failed:J,unfinished:J}).annotate({identifier:`SessionStats.ToolTotals`}),DA=R([F({mode:A(`none`)}),F({mode:A(`summary`),totals:EA}),F({mode:A(`detail`),totals:EA,usage:L(TA)})]).annotate({identifier:`SessionStats.Tools`});F({range:F({from:PT,to:PT}),sessions:J,subagents:J,prompts:J,steps:J,tokens:jO,cost:ME,tools:DA,activeDays:J,streak:J,activity:L(CA),models:L(wA)}).annotate({identifier:`SessionStats.Info`}),F({info:gA,messages:L(rk)}).annotate({identifier:`SessionTransfer.Data`});const OA=M.check(bb(`pty`)).pipe(B(`PtyID`),D({identifier:`Pty.ID`})).pipe(NT(e=>{let t=()=>e.make(`pty_`+RT());return{create:t,ascending:n=>n===void 0?t():e.make(n)}})),kA=F({id:OA,title:M,command:M,args:L(M),cwd:M,status:z([`running`,`exited`]),pid:J,exitCode:Y(J)}).annotate({identifier:`Pty`});JT(Z({type:`pty.created`,schema:{info:kA}}),Z({type:`pty.updated`,schema:{info:kA}}),Z({type:`pty.exited`,schema:{id:OA,exitCode:J}}),Z({type:`pty.deleted`,schema:{id:OA}})),F({command:Y(M),args:Y(L(M)),cwd:Y(M),title:Y(M),env:Y(I(M,M))}),F({title:Y(M),size:Y(F({rows:kT,cols:kT}))});const AA=F({...kA.fields,sessionID:pA,foregroundProcess:eb(M),size:F({cols:kT,rows:kT}),output:F({head:J,tail:J})}).annotate({identifier:`PersistentPty.Info`});F({directory:M,instanceID:M,ticket:M,expiresAt:N}).annotate({identifier:`PersistentPty.Handoff`}),F({command:Y(M),args:L(M),cwd:Y(M),title:M,env:I(M,M),size:Y(F({cols:kT,rows:kT}))}).annotate({identifier:`PersistentPty.CreateInput`}),F({attachmentID:Y(M),size:F({cols:kT,rows:kT})}).annotate({identifier:`PersistentPty.UpdateInput`});const jA=F({info:AA,text:M,checkpoint:Ub,cursor:F({x:J,y:J})}).annotate({identifier:`PersistentPty.Snapshot`});kT.check(Ob(65535)).annotate({identifier:`PersistentPty.ReadLines`}),F({ptyID:OA,title:M,cwd:M,foregroundProcess:eb(M),screen:F({text:M,cols:kT,rows:kT,cursor:jA.fields.cursor})}).annotate({identifier:`PersistentPty.ReadResult`}),JT(Z({type:`persistent-pty.added`,schema:{sessionID:pA,terminal:AA}}),Z({type:`persistent-pty.removed`,schema:{sessionID:pA,ptyID:OA}})),F({ticket:M,expires_in:kT}).annotate({identifier:`PtyTicket.ConnectToken`});const MA=F({label:M.annotate({description:`Display text (1-5 words, concise)`}),description:M.annotate({description:`Explanation of choice`})});F({question:M.annotate({description:`Complete question`}),header:M.annotate({description:`Very short label (max 30 chars)`}),options:L(MA).annotate({description:`Available choices`}),multiple:P.pipe(Y).annotate({description:`Allow selecting multiple choices`})}).annotate({identifier:`Question.Prompt`}),L(M).annotate({identifier:`Question.Answer`});const NA=F({workspaceID:HT,status:z([`connected`,`connecting`,`disconnected`,`error`])}).annotate({identifier:`WorkspaceEvent.ConnectionStatus`});JT(Z({type:`workspace.ready`,schema:{name:M}}),Z({type:`workspace.failed`,schema:{message:M}}),Z({type:`workspace.status`,schema:NA.fields})),F({destroyed:P.annotate({description:`True when this request transitioned the workspace from existing to destroyed.`})}).annotate({identifier:`WorkspaceDestroyResult`,description:`Reports whether this request destroyed an existing workspace.`});const PA=F({uri:M,name:M.pipe(Y),description:M.pipe(Y),mention:pO.pipe(Y)}).annotate({identifier:`PromptInput.FileAttachment`}),FA=F({id:sO,mention:pO.pipe(Y)}).annotate({identifier:`PromptInput.SkillAttachment`});F({text:M,files:L(PA).pipe(Y),agents:L(bO).pipe(Y),skills:L(FA).pipe(Y)}).annotate({identifier:`PromptInput`});const IA=z([`context-overflow`,`payload-too-large`]);var LA=class extends G(`AI.HttpContext`)({url:M,status:W.check(kb({minimum:100,maximum:599})),headers:I(M,M)}){},RA=class extends G(`AI.HttpRateLimitDetails`)({retryAfterMs:k(J),limit:k(I(M,M)),remaining:k(I(M,M)),reset:k(I(M,M))}){};const zA={message:M,body:k(M),http:k(LA),cause:k(Lb({includeStack:!0}))};var BA=class extends ax(`AI.Error.InvalidRequest`)(`InvalidRequest`,{...zA,parameter:k(M),classification:k(IA)}){},VA=class extends ax(`AI.Error.UnsupportedOperation`)(`UnsupportedOperation`,{...zA,operation:M,provider:k(nT),route:k(eT)}){};ax(`AI.Error.ProviderConfiguration`)(`ProviderConfiguration`,{provider:nT,message:M});var HA=class extends ax(`AI.Error.NoRoute`)(`NoRoute`,{...zA,route:eT,provider:nT,model:tT}){},UA=class extends ax(`AI.Error.Authentication`)(`Authentication`,zA){},WA=class extends ax(`AI.Error.RateLimit`)(`RateLimit`,{...zA,retryAfterMs:k(J),rateLimit:k(RA)}){},GA=class extends ax(`AI.Error.QuotaExceeded`)(`QuotaExceeded`,{...zA,retryAfterMs:k(J)}){},KA=class extends ax(`AI.Error.ContentPolicy`)(`ContentPolicy`,zA){},qA=class extends ax(`AI.Error.ProviderInternal`)(`ProviderInternal`,{...zA,retryAfterMs:k(J)}){};const JA=z([`http`,`websocket`]),YA=z([`request`,`read`,`write`]);var XA=class extends ax(`AI.Error.Transport`)(`Transport`,{...zA,transport:JA,operation:YA,code:k(M),url:k(M),phase:k(z([`prepare`,`queue`,`connect`,`send`,`receive`,`decode`,`complete`,`fallback`,`close`])),delivery:k(z([`not-sent`,`rejected`,`ambiguous`,`accepted`])),recovery:k(z([`retry-connect`,`retry-full`,`rotate-and-retry-full`,`fallback-http`,`fail`]))}){},ZA=class extends ax(`AI.Error.InvalidProviderOutput`)(`InvalidProviderOutput`,{...zA,classification:k(z([`incomplete-stream`])),route:k(M)}){},QA=class extends ax(`AI.Error.UnknownProvider`)(`UnknownProvider`,zA){},$A=class extends ax(`AI.Error.Timeout`)(`Timeout`,{...zA,timeoutMs:k(J)}){};const ej=R([BA,VA,HA,UA,WA,GA,KA,qA,XA,ZA,QA,$A]).pipe(H(`_tag`));var tj=class extends ax()(`AI.Error`,{reason:ej}){cause=this.reason;get message(){return this.reason.message}};const nj=class extends br()(`@opencode/AI/RequestExecutor`){},rj=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t])),ij=e=>new LA({url:e.request.url,status:e.status,headers:rj(e.headers)}),aj=(e,t,n)=>String.fromCharCode(...e.subarray(t,n)),oj=(e,t)=>e.length>=t.length&&t.every((t,n)=>e[n]===t),sj=e=>{if(oj(e,[137,80,78,71,13,10,26,10]))return`image/png`;if(oj(e,[255,216,255]))return`image/jpeg`;if(oj(e,[71,73,70,56]))return`image/gif`;if(e.length>=12&&aj(e,0,4)===`RIFF`){let t=aj(e,8,12);if(t===`WEBP`)return`image/webp`;if(t===`WAVE`)return`audio/wav`}if(oj(e,[37,80,68,70]))return`application/pdf`;if(e.length>=12&&aj(e,4,8)===`ftyp`){let t=aj(e,8,12),n=Math.min(new DataView(e.buffer,e.byteOffset).getUint32(0),e.length),r=Array.from({length:Math.floor((n-16)/4)},(t,n)=>aj(e,16+n*4,20+n*4)),i=t===`mif1`||t===`msf1`;return t===`avif`||t===`avis`||i&&(r.includes(`avif`)||r.includes(`avis`))?`image/avif`:i||[`heic`,`heix`,`hevc`,`hevx`].includes(t)?`image/heic`:t===`qt `?`video/quicktime`:t===`M4A `?`audio/mp4`:`video/mp4`}if(oj(e,[26,69,223,163]))return`video/webm`;if(oj(e,[73,68,51]))return`audio/mpeg`;if(e.length>=2&&e[0]===255&&(e[1]&224)==224)return e[1]&6?`audio/mpeg`:`audio/aac`;if(oj(e,[79,103,103,83]))return`audio/ogg`;if(oj(e,[102,76,97,67]))return`audio/flac`},cj=`application/octet-stream`,lj=R([F({type:A(`bytes`),data:Ub,mediaType:M}),F({type:A(`base64`),data:M,mediaType:M}),F({type:A(`url`),url:M,mediaType:k(M),expiresAt:k(N)}),F({type:A(`ref`),provider:nT,id:M,mediaType:k(M)})]).pipe(H(`type`)).annotate({identifier:`Media.Source`}),uj=Ty(e=>typeof e==`string`&&/^\d+(?:\.\d+)?:\d+(?:\.\d+)?$/.test(e),{title:`Media.AspectRatio`});z([`image`,`video`,`audio`,`document`,`other`]);const dj=e=>{let t=e.toLowerCase();return t.startsWith(`image/`)?`image`:t.startsWith(`video/`)?`video`:t.startsWith(`audio/`)?`audio`:t===`application/pdf`||t.startsWith(`text/`)?`document`:`other`},fj=F({width:k(N),height:k(N),durationSeconds:k(N),sampleRate:k(N),channels:k(N),encoding:k(M),format:k(M)}).annotate({identifier:`Media.Info`}),pj=(e,t)=>new tj({reason:new BA({message:e,cause:t})});var mj=class{source;mediaType;kind;info;expiresAt;providerMetadata;headers;#e;#t;constructor(e){this.source=e.source,this.mediaType=e.source.mediaType??(e.source.type===`bytes`?sj(e.source.data):void 0)??cj,this.kind=dj(this.mediaType),this.info=e.info,this.expiresAt=e.source.type===`url`?e.source.expiresAt:void 0,this.providerMetadata=e.providerMetadata,this.headers=e.source.type===`url`?e.headers:void 0}inline(){let e=this.source;if(e.type!==`bytes`&&e.type!==`base64`)return;let t=e.type===`base64`?e.data:this.#t??=Dp(e.data),n=this.mediaType.toLowerCase();return{mime:n,base64:t,dataUrl:`data:${n};base64,${t}`}}bytes(){return Zd(()=>{let e=this.source;return e.type===`bytes`?S(e.data):this.#e===void 0?e.type===`ref`?C(pj(`Cannot materialize provider ref ${e.provider}:${e.id}`)):(e.type===`base64`?uf(Op(e.data)).pipe(bf(e=>pj(`Media asset contains invalid base64 data`,e))):yj(e,this.headers)).pipe(pf(e=>Qd(()=>this.#e=e))):S(this.#e)})}base64(){return Zd(()=>{let e=this.source;return e.type===`base64`?S(e.data):this.#t===void 0?this.bytes().pipe(gf(e=>this.#t=Dp(e))):S(this.#t)})}dataUrl(){return this.base64().pipe(gf(e=>`data:${this.mediaType};base64,${e}`))}toJSON(){let e=this.source;return{source:e.type===`bytes`?{...e,data:Dp(e.data)}:e,info:this.info,providerMetadata:this.providerMetadata}}materialize(){return this.source.type===`bytes`||this.source.type===`base64`?S(this):this.bytes().pipe(gf(e=>xj(e,this.source.mediaType,{info:this.info,providerMetadata:this.providerMetadata})))}};const hj=F({source:lj,info:k(fj),providerMetadata:k(q)}).annotate({identifier:`Media.AssetEncoded`}),gj=e=>({source:e.source,info:e.info,providerMetadata:e.providerMetadata}),_j=Ty(e=>e instanceof mj,{expected:`Media.Asset`}),vj=hj.pipe(cb(_j,{decode:E(e=>new mj(e)),encode:E(gj)})),yj=Yf(`Media.download`)(function*(e,t){let n=yield*(yield*nj).execute(uw(e.url).pipe(mw(t??{}))),r=yield*n.arrayBuffer.pipe(bf(t=>new tj({reason:new ZA({message:`Failed to read media from ${e.url}`,http:ij(n),cause:t})})));return new Uint8Array(r)}),bj=(e,t)=>new mj({...t,source:e}),xj=(e,t,n)=>bj({type:`bytes`,data:e,mediaType:t??sj(e)??cj},n),Sj=(e,t,n)=>bj({type:`base64`,data:e,mediaType:t},n),Cj=zb(j);Fy(Cj);const wj=zy(Cj),Tj=z([`system`,`user`,`assistant`,`tool`]),Ej=F({type:A(`text`),text:M,cache:k(ET),metadata:k(I(M,j))}).annotate({identifier:`LLM.SystemPart`}),Dj=e=>({type:`text`,text:e}),Oj=MT(Ej,{make:Dj,content:e=>e===void 0?[]:typeof e==`string`?[Dj(e)]:Array.isArray(e)?[...e]:[e]}),kj=F({type:A(`text`),text:M,cache:k(ET),metadata:k(I(M,j)),providerMetadata:k(q)}).annotate({identifier:`LLM.Content.Text`}),Aj=F({type:A(`media`),media:vj,filename:k(M),cache:k(ET),metadata:k(I(M,j)),providerMetadata:k(q)}).annotate({identifier:`LLM.Content.Media`}),jj=R([F({type:A(`json`),value:j}),F({type:A(`text`),value:j}),F({type:A(`error`),value:j}),F({type:A(`content`),value:L(FT)})]).annotate({identifier:`LLM.ToolResult`}),Mj=My(jj),Nj=MT(jj,{is:Mj,make:(e,t=`json`)=>Mj(e)?e:t===`content`?{type:t,value:Array.isArray(e)?e:[]}:{type:t,value:e}}),Pj=MT(F({structured:j,content:L(FT)}).annotate({identifier:`LLM.ToolOutput`}),{make:(e,t=[])=>({structured:e,content:t}),fromResultValue:e=>{switch(e.type){case`json`:return{structured:e.value,content:[]};case`text`:return{structured:{},content:[{type:`text`,text:Ij(e.value)}]};case`content`:return{structured:{},content:e.value};case`error`:return}},toResultValue:e=>e.content.length===0?{type:`json`,value:e.structured}:e.content.length===1&&e.content[0]?.type===`text`?{type:`text`,value:e.content[0].text}:{type:`content`,value:e.content}}),Fj=Ly(Cj),Ij=e=>typeof e==`string`?e:mr(Fj(e),()=>String(e)),Lj=MT(F({type:A(`tool-call`),id:M,name:M,namespace:k(M),input:j,providerExecuted:k(P),cache:k(ET),metadata:k(I(M,j)),providerMetadata:k(q)}).annotate({identifier:`LLM.Content.ToolCall`}),{make:e=>({type:`tool-call`,...e})}),Rj=MT(F({type:A(`tool-result`),id:M,name:M,namespace:k(M),result:Nj,providerExecuted:k(P),cache:k(ET),metadata:k(I(M,j)),providerMetadata:k(q)}).annotate({identifier:`LLM.Content.ToolResult`}),{make:e=>({type:`tool-result`,id:e.id,name:e.name,namespace:e.namespace,result:Nj.make(e.result,e.resultType),providerExecuted:e.providerExecuted,cache:e.cache,metadata:e.metadata,providerMetadata:e.providerMetadata})}),zj=F({type:A(`reasoning`),text:M,encrypted:k(M),cache:k(ET),metadata:k(I(M,j)),providerMetadata:k(q)}).annotate({identifier:`LLM.Content.Reasoning`}),Bj=F({type:A(`compaction`),provider:nT,id:k(M),encrypted:k(M),text:k(eb(M))}).pipe(ib(e=>e.encrypted!==void 0!=(e.text!==void 0),{message:`Compaction requires either encrypted content or a summary`})).annotate({identifier:`LLM.Content.Compaction`}),Vj=MT(Bj,{make:e=>Fy(Bj)({type:`compaction`,...e})}),Hj=R([kj,Aj,Lj,Rj,zj,Vj,F({type:A(`effort`),effort:k(vT),previous:k(vT)}).annotate({identifier:`LLM.Content.Effort`})]).pipe(H(`type`));var Uj=class extends G(`LLM.Message`)({id:k(M),role:Tj,content:L(Hj),metadata:k(I(M,j)),providerMetadata:k(q),native:k(I(M,j))}){};(function(e){e.text=e=>({type:`text`,text:e}),e.media=(e,t)=>({type:`media`,media:e,...t}),e.content=t=>typeof t==`string`?[e.text(t)]:Array.isArray(t)?[...t]:[t],e.make=t=>t instanceof e?t:new e({...t,content:e.content(t.content)}),e.user=t=>e.make({role:`user`,content:t}),e.assistant=t=>e.make({role:`assistant`,content:t}),e.system=t=>e.make({role:`system`,content:t}),e.effort=t=>e.make({role:`system`,content:[{type:`effort`,effort:t.effort,previous:t.previous}]}),e.tool=t=>e.make({role:`tool`,content:[`type`in t?t:Rj.make(t)]})})(Uj||={});const Wj=R([F({type:A(`text`)}),F({type:A(`regex`),pattern:M}),F({type:A(`lark`),grammar:M})]).annotate({identifier:`LLM.Freeform`}),Gj={name:M,description:M,inputSchema:aT,outputSchema:k(aT),freeform:k(Wj),cache:k(ET),metadata:k(I(M,j)),native:k(I(M,j))};var Kj=class extends G(`LLM.ToolDefinition`)({type:A(`tool`),...Gj}){constructor(e){super({...e,type:`tool`})}};(function(e){e.make=t=>t instanceof e?t:new e(t),e.freeformField=e=>{let t=Object.entries(My(aT)(e.properties)?e.properties:{});if(t.length!==1)return;let[n,r]=t[0];if(My(aT)(r)&&r.type===`string`)return Array.isArray(e.required)&&e.required.includes(n)?n:void 0}})(Kj||={});const qj=MT(F({type:A(`namespace`),name:M,description:k(tb(M)),tools:L(nb(()=>Jj))}).annotate({identifier:`LLM.ToolNamespace`}),{make:e=>({...e,type:`namespace`,tools:e.tools.map(Jj.make)})}),Jj=MT(R([Kj,qj]).pipe(H(`type`),D({identifier:`LLM.ToolEntry`})),{make:e=>`type`in e&&e.type===`namespace`?qj.make(e):Kj.make(e)});var Yj=class extends G(`LLM.ToolChoice`)({type:z([`auto`,`none`,`required`,`tool`]),name:k(M),disableParallelToolUse:k(P)}){};(function(e){let t=e=>e===`auto`||e===`none`||e===`required`;e.named=t=>new e({type:`tool`,name:t}),e.make=n=>n instanceof e?n:n instanceof Kj?e.named(n.name):typeof n==`string`?t(n)?new e({type:n}):e.named(n):new e(n)})(Yj||={});const Xj=F({id:k(M),model:wT,system:L(Oj),messages:L(Uj),tools:L(Jj),toolChoice:k(Yj),generation:k(mT),providerOptions:k(cT),http:k(fT),cache:k(OT),promptCacheKey:k(M),metadata:k(I(M,j)),includeRaw:k(P)});var Zj=class extends G(`LLM.Request`)(Xj.fields){constructor(e){super(e)}};(function(e){e.input=e=>({id:e.id,model:e.model,system:e.system,messages:e.messages,tools:e.tools,toolChoice:e.toolChoice,generation:e.generation,providerOptions:e.providerOptions,http:e.http,cache:e.cache,promptCacheKey:e.promptCacheKey,metadata:e.metadata,includeRaw:e.includeRaw});function t(t,n){return Object.keys(n).length===0?t:new e({...e.input(t),...n,model:n.model??t.model})}e.update=t})(Zj||={});const Qj=XD;var $j=class e extends G(`AI.Usage`)({contextTokens:k(N),inputTokens:k(N),outputTokens:k(N),nonCachedInputTokens:k(N),cacheReadInputTokens:k(N),cacheWriteInputTokens:k(N),reasoningTokens:k(N),totalTokens:k(N),cost:k(N),providerMetadata:k(q)}){get visibleOutputTokens(){return Math.max(0,(this.outputTokens??0)-(this.reasoningTokens??0))}static from(t){return t instanceof e?t:new e(t)}};const eM=R([F({type:A(`tokens`),input:k(N),output:k(N),total:k(N),details:k(I(M,j))}),F({type:A(`seconds`),seconds:N}),F({type:A(`characters`),characters:N}),F({type:A(`credits`),credits:N}),F({type:A(`compute`),seconds:N})]).pipe(H(`type`)).annotate({identifier:`AI.MediaUsage`});G(`LLM.CompactionResponse`)({replacement:L(Uj),usage:k($j)}),G(`LLM.CompactionCheckpointResponse`)({checkpoint:Vj.pipe(ib(e=>e.encrypted!==void 0&&e.encrypted.length>0,{message:`A checkpoint response requires encrypted compaction content`})),responseID:M.check(vb(/\S/)),usage:k($j)});const tM=F({type:V(`step-start`),index:N}).annotate({identifier:`LLM.Event.StepStart`}),nM=F({type:V(`text-start`),id:rT,providerMetadata:k(q)}).annotate({identifier:`LLM.Event.TextStart`}),rM=F({type:V(`text-delta`),id:rT,text:M,providerMetadata:k(q)}).annotate({identifier:`LLM.Event.TextDelta`}),iM=F({type:V(`text-end`),id:rT,text:k(M),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.TextEnd`}),aM=F({type:V(`reasoning-start`),id:rT,providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ReasoningStart`}),oM=F({type:V(`reasoning-delta`),id:rT,text:M,providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ReasoningDelta`}),sM=F({type:V(`reasoning-end`),id:rT,text:k(M),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ReasoningEnd`}),cM=F({type:V(`tool-input-start`),id:iT,name:M,namespace:k(M),providerExecuted:k(P),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ToolInputStart`}),lM=F({type:V(`tool-input-delta`),id:iT,name:M,namespace:k(M),text:M,input:k(j)}).annotate({identifier:`LLM.Event.ToolInputDelta`}),uM=F({type:V(`tool-input-end`),id:iT,name:M,namespace:k(M),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ToolInputEnd`}),dM=F({type:V(`tool-input-error`),id:iT,name:M,namespace:k(M),raw:M}).annotate({identifier:`LLM.Event.ToolInputError`}),fM=F({type:V(`tool-call`),id:iT,name:M,namespace:k(M),input:j,providerExecuted:k(P),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ToolCall`}),pM=F({type:V(`tool-result`),id:iT,name:M,namespace:k(M),result:Nj,output:k(Pj),providerExecuted:k(P),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ToolResult`}),mM=F({type:V(`tool-error`),id:iT,name:M,namespace:k(M),message:M,error:k(Lb()),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ToolError`}),hM=F({normalized:Qj,raw:k(M),category:k(M),explanation:k(M)}).annotate({identifier:`LLM.FinishReasonDetails`}),gM=F({type:V(`step-finish`),index:N,reason:hM,usage:k($j),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.StepFinish`}),_M=F({type:V(`finish`),reason:hM,usage:k($j),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.Finish`}),vM=F({type:V(`media`),media:vj,providerMetadata:k(q)}).annotate({identifier:`LLM.Event.Media`}),yM=F({type:V(`provider-error`),message:M,classification:k(IA),providerMetadata:k(q)}).annotate({identifier:`LLM.Event.ProviderError`}),bM=F({type:V(`raw`),data:j}).annotate({identifier:`LLM.Event.Raw`}),xM=R([Vj,tM,nM,rM,iM,aM,oM,sM,cM,lM,uM,dM,fM,pM,mM,vM,gM,_M,yM,bM]).pipe(H(`type`)),SM=e=>rT.make(e),CM=e=>iT.make(e),wM=Object.assign(xM,{compaction:Vj.make,stepStart:tM.make,textStart:e=>nM.make({...e,id:SM(e.id)}),textDelta:e=>rM.make({...e,id:SM(e.id)}),textEnd:e=>iM.make({...e,id:SM(e.id)}),reasoningStart:e=>aM.make({...e,id:SM(e.id)}),reasoningDelta:e=>oM.make({...e,id:SM(e.id)}),reasoningEnd:e=>sM.make({...e,id:SM(e.id)}),toolInputStart:e=>cM.make({...e,id:CM(e.id)}),toolInputDelta:e=>lM.make({...e,id:CM(e.id)}),toolInputEnd:e=>uM.make({...e,id:CM(e.id)}),toolInputError:e=>dM.make({...e,id:CM(e.id)}),toolCall:e=>fM.make({...e,id:CM(e.id)}),toolResult:e=>pM.make({...e,id:CM(e.id),output:e.output===void 0?void 0:Pj.make(e.output.structured,e.output.content)}),toolError:e=>mM.make({...e,id:CM(e.id)}),media:vM.make,stepFinish:e=>gM.make({...e,usage:e.usage===void 0?void 0:$j.from(e.usage)}),finish:e=>_M.make({...e,usage:e.usage===void 0?void 0:$j.from(e.usage)}),providerError:yM.make,raw:bM.make,is:{compaction:xM.guards.compaction,stepStart:xM.guards[`step-start`],textStart:xM.guards[`text-start`],textDelta:xM.guards[`text-delta`],textEnd:xM.guards[`text-end`],reasoningStart:xM.guards[`reasoning-start`],reasoningDelta:xM.guards[`reasoning-delta`],reasoningEnd:xM.guards[`reasoning-end`],toolInputStart:xM.guards[`tool-input-start`],toolInputDelta:xM.guards[`tool-input-delta`],toolInputEnd:xM.guards[`tool-input-end`],toolInputError:xM.guards[`tool-input-error`],toolCall:xM.guards[`tool-call`],toolResult:xM.guards[`tool-result`],toolError:xM.guards[`tool-error`],media:xM.guards.media,stepFinish:xM.guards[`step-finish`],finish:xM.guards.finish,providerError:xM.guards[`provider-error`],raw:xM.guards.raw}}),TM=(e,t,n)=>{let r=[],i=/* @__PURE__ */ new Map;for(let a of e)t(a)&&(i.has(a.id)||r.push(a.id),i.set(a.id,(i.get(a.id)??``)+a.text)),n(a)&&a.text!==void 0&&(i.has(a.id)||r.push(a.id),i.set(a.id,a.text));return r.map(e=>i.get(e)).join(``)},EM=e=>TM(e,wM.is.textDelta,wM.is.textEnd),DM=e=>TM(e,wM.is.reasoningDelta,wM.is.reasoningEnd),OM=e=>e.reduce((e,t)=>`usage`in t&&t.usage!==void 0?t.usage:e,void 0),kM=()=>({events:[],message:Uj.assistant([]),textParts:{},reasoningParts:{},toolInputs:{}}),AM=(e,t)=>{let n=[...e.events,t];return wM.is.finish(t)?{...e,events:n,usage:t.usage??e.usage,finishReason:t.reason}:wM.is.providerError(t)?{...e,events:n,finishReason:e.finishReason??{normalized:`error`}}:{...e,events:n,usage:`usage`in t&&t.usage!==void 0?t.usage:e.usage}},jM=(e,t)=>t===void 0?{type:`text`,text:e}:{type:`text`,text:e,providerMetadata:t},MM=(e,t)=>t===void 0?{type:`reasoning`,text:e}:{type:`reasoning`,text:e,providerMetadata:t},NM=(e,t)=>({...e,message:Uj.assistant(t)}),PM=(e,t)=>NM(e,[...e.message.content,t]),FM=(e,t,n)=>NM(e,e.message.content.map((e,r)=>r===t?n:e)),IM=(e,t,n)=>e.textParts[t]?e:{...PM(e,jM(``,n)),textParts:{...e.textParts,[t]:{contentIndex:e.message.content.length,text:``,providerMetadata:n}}},LM=(e,t)=>{let n=IM(e,t.id,t.providerMetadata),r=n.textParts[t.id];if(!r)return n;let i=r.text+t.text,a=t.providerMetadata??r.providerMetadata;return{...FM(n,r.contentIndex,jM(i,a)),textParts:{...n.textParts,[t.id]:{...r,text:i,providerMetadata:a}}}},RM=(e,t)=>{let n=e.textParts[t.id];if(!n)return e;let r=t.text??n.text,i=t.providerMetadata??n.providerMetadata;return{...FM(e,n.contentIndex,jM(r,i)),textParts:{...e.textParts,[t.id]:{...n,text:r,providerMetadata:i}}}},zM=(e,t,n)=>e.reasoningParts[t]?e:{...PM(e,MM(``,n)),reasoningParts:{...e.reasoningParts,[t]:{contentIndex:e.message.content.length,text:``,providerMetadata:n}}},BM=(e,t)=>{let n=zM(e,t.id,t.providerMetadata),r=n.reasoningParts[t.id];if(!r)return n;let i=r.text+t.text,a=t.providerMetadata??r.providerMetadata;return{...FM(n,r.contentIndex,MM(i,a)),reasoningParts:{...n.reasoningParts,[t.id]:{...r,text:i,providerMetadata:a}}}},VM=(e,t)=>{let n=e.reasoningParts[t.id];if(!n)return e;let r=t.text??n.text,i=t.providerMetadata??n.providerMetadata;return{...FM(e,n.contentIndex,MM(r,i)),reasoningParts:{...e.reasoningParts,[t.id]:{...n,text:r,providerMetadata:i}}}},HM=(e,t)=>({...e,toolInputs:{...e.toolInputs,[t.id]:{name:t.name,namespace:t.namespace,text:``,providerMetadata:t.providerMetadata}}}),UM=(e,t)=>{let n=e.toolInputs[t.id]??{name:t.name,namespace:t.namespace,text:``};return{...e,toolInputs:{...e.toolInputs,[t.id]:{...n,text:n.text+t.text}}}},WM=(e,t)=>{let n=e.toolInputs[t.id]??{name:t.name,namespace:t.namespace,text:``};return{...e,toolInputs:{...e.toolInputs,[t.id]:{...n,name:t.name,namespace:t.namespace,providerMetadata:t.providerMetadata??n.providerMetadata}}}},GM=e=>Lj.make({id:e.id,name:e.name,namespace:e.namespace,input:e.input,...e.providerExecuted===void 0?{}:{providerExecuted:e.providerExecuted},...e.providerMetadata===void 0?{}:{providerMetadata:e.providerMetadata}}),KM=e=>Rj.make({id:e.id,name:e.name,namespace:e.namespace,result:e.result,...e.providerExecuted===void 0?{}:{providerExecuted:e.providerExecuted},...e.providerMetadata===void 0?{}:{providerMetadata:e.providerMetadata}}),qM=(e,t)=>{let{[t.id]:n,...r}=e.toolInputs;return{...PM(e,GM(t)),toolInputs:r}},JM=(e,t)=>{if(t.type===`raw`)return e;let n=AM(e,t);switch(t.type){case`compaction`:return PM(n,t);case`text-start`:return IM(n,t.id,t.providerMetadata);case`text-delta`:return LM(n,t);case`text-end`:return RM(n,t);case`reasoning-start`:return zM(n,t.id,t.providerMetadata);case`reasoning-delta`:return BM(n,t);case`reasoning-end`:return VM(n,t);case`tool-input-start`:return HM(n,t);case`tool-input-delta`:return UM(n,t);case`tool-input-end`:return WM(n,t);case`tool-input-error`:{let{[t.id]:e,...r}=n.toolInputs;return{...n,toolInputs:r}}case`tool-call`:return qM(n,t);case`tool-result`:return PM(n,KM(t));case`media`:return PM(n,t.providerMetadata===void 0?{type:`media`,media:t.media}:{type:`media`,media:t.media,providerMetadata:t.providerMetadata});default:return n}};var YM=class extends G(`LLM.Response`)({message:Uj,events:L(wM),usage:k($j),finishReason:hM}){get text(){return EM(this.events)}get reasoning(){return DM(this.events)}get toolCalls(){return this.events.filter(wM.is.toolCall)}};(function(e){e.empty=kM,e.reduce=JM,e.complete=t=>t.finishReason===void 0?void 0:new e({message:t.message,events:[...t.events],usage:t.usage,finishReason:t.finishReason}),e.fromEvents=t=>e.complete(t.reduce(e.reduce,e.empty())),e.text=e=>EM(e.events),e.usage=e=>e.usage??OM(e.events),e.toolCalls=e=>e.events.filter(wM.is.toolCall),e.reasoning=e=>DM(e.events)})(YM||={});const XM=[/prompt is too long/i,/input is too long for (?:the )?(?:requested|selected) model/i,/too large for the model'?s configured input limit/i,/exceeded this model context window limit/i,/exceeds the context window/i,/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,/input token count.*exceeds the maximum/i,/number of input tokens exceeds maximum length/i,/tokens in request more than max tokens allowed/i,/maximum prompt length is \d+/i,/reduce the length of the messages/i,/requested input length \d+ exceeds maximum input length/i,/maximum context length is \d+ tokens/i,/exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,/input(?: \(\d+ tokens\))? is longer than the model'?s context length/i,/exceeds the limit of \d+/i,/exceeds the available context size/i,/greater than the context length/i,/`inputs` tokens \+ `max_new_tokens` must be <= \d+/i,/context window exceeds limit/i,/exceeded model token limit/i,/context[_ ]length[_ ]exceeded/i,/context length is only \d+ tokens/i,/input length.*exceeds.*context length/i,/prompt (?:too long|exceeds max length|超长)/i,/too large for model with \d+ maximum context length/i,/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,/model_context_window_exceeded/i,/range of input length should be/i,/too many tokens/i,/token limit exceeded/i,/request_too_large/i],ZM=[/request entity too large/i,/payload too large/i,/request too large/i],QM=[/^(throttling error|service unavailable):/i,/rate limit/i,/too many requests/i,/max[_ ]tokens must be less than/i,/too many tokens(?: per day)?, please wait/i],$M=e=>!QM.some(t=>t.test(e))&&(XM.some(t=>t.test(e))||/^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(e)),eN=e=>ZM.some(t=>t.test(e)),tN=e=>{let t=e.reason.http?.headers[`x-should-retry`];if(t===`true`)return!0;if(t===`false`)return!1;switch(e.reason._tag){case`RateLimit`:case`ProviderInternal`:return!0;case`Transport`:return e.reason.delivery!==`rejected`&&(e.reason.delivery!==`accepted`||e.reason.operation===`read`);case`InvalidProviderOutput`:return e.reason.classification===`incomplete-stream`;case`UnknownProvider`:return!0;case`Authentication`:case`QuotaExceeded`:case`ContentPolicy`:case`InvalidRequest`:case`UnsupportedOperation`:case`NoRoute`:case`Timeout`:return!1;default:return e.reason}},nN=Py(Cj),rN=/* @__PURE__ */ new Set([`insufficient_quota`,`usage_not_included`,`billing_error`,`gousagelimiterror`,`budgetlimiterror`,`freeusagelimiterror`,`creditlimitexceeded`]),iN=/* @__PURE__ */ new Set([`authentication_error`,`permission_error`,`permission_denied`,`api_key_invalid`]),aN=/* @__PURE__ */ new Set([`api_error`,`internal_error`,`internalserverexception`,`modelstreamerrorexception`,`overloaded_error`,`server_error`,`server_is_overloaded`,`slow_down`,`serviceunavailableexception`]),oN=/* @__PURE__ */ new Set([`model_not_found`,`invalid_prompt`,`invalid_request`,`invalid_request_error`,`validationexception`]),sN=/* @__PURE__ */ new Set([`content_filter`,`content_moderation`,`responsibleaipolicyviolation`,`content_policy_violation`,`image_content_policy_violation`,`refusal`,`datainspectionfailed`,`moderation_blocked`]),cN=/^[^:\n]+: \[([A-Za-z0-9_.-]+)\]/,lN=/incorrect api key provided/i,uN=/rate increased too quickly|rate[-_\s]?limit|too[_\s]?many[_\s]?requests/i,dN=/insufficient[-_\s]?(?:quota|balance)|(?<!token_)quota[-_\s]?exceeded|budget exceeded|usage limit|limit exhausted|package has expired|plan does not yet include/i,fN=/violating our usage policy|blocked by content filtering policy|content[-_\s]?policy|rejected (?:as a result of our|by the) safety system|detected potentially unsafe or sensitive content/i,pN=/\b(?:try again|(?:please |you can )?retry (?:the |this |your )?request|try (?:the |this |your )?request again|(?:currently |temporarily )?at capacity|overloaded|temporarily unavailable|service[-_\s]?unavailable|(?:server|internal)[-_\s]?error|server (?:is )?busy|provider returned (?:an )?error|resource[-_\s]?exhausted|upstream (?:connect|connection|request)|request buffer limit while retrying upstream)\b/i,mN=M.check(vb(/\S/)),hN=(e,t)=>F(e).pipe(cb(M,{decode:E(t),encode:dh(()=>`Provider error messages are decode-only`)})),gN=Py(zb(R([hN({error:F({message:mN})},e=>e.error.message),hN({error:mN},e=>e.error),hN({message:mN},e=>e.message),hN({Message:mN},e=>e.Message),hN({detail:mN},e=>e.detail),hN({errors:Qy(F({message:mN}))},e=>e.errors[0].message)]))),_N=e=>gr(gN(e));function vN(e){let t={message:e.message,body:e.rawBody,http:e.http,cause:e.cause},n=e.rawBody??``,r=[...yN(e.data),...yN(n),...yN(e.message),...cN.exec(e.message)?.slice(1)??[],...bN(e.http?.headers[`x-amzn-errortype`])].map(e=>e.toLowerCase()),i=[e.message,n].filter(e=>e.length>0).join(`
|
|
10
|
+
`),a=e.status===void 0||e.status>=400&&e.status<500;return a&&(r.includes(`context_length_exceeded`)||r.includes(`model_context_window_exceeded`)||r.includes(`request_too_large`)||e.status!==429&&!r.includes(`throttlingexception`)&&$M(i))?new BA({...t,classification:`context-overflow`}):e.status===413||eN(i)?new BA({...t,classification:`payload-too-large`}):r.some(e=>sN.has(e))||a&&fN.test(e.message)?new KA(t):e.status===402||r.some(e=>rN.has(e))||e.status===429&&dN.test(i)?new GA({...t,retryAfterMs:e.retryAfterMs}):e.status===401||e.status===403||r.some(e=>iN.has(e))||e.status===400&&lN.test(i)?new UA(t):e.status===429||r.some(e=>e.includes(`rate_limit`)||e===`too_many_requests`||e===`throttlingexception`)||uN.test(i)?new WA({...t,retryAfterMs:e.retryAfterMs,rateLimit:e.rateLimit}):e.status===408||e.status===409||e.status!==void 0&&e.status>=500||(e.status===void 0||e.status<400)&&(!r.some(e=>oN.has(e))&&pN.test(i)||r.some(e=>aN.has(e)||e.includes(`exhausted`)||e.includes(`unavailable`)))?new qA({...t,retryAfterMs:e.retryAfterMs}):r.some(e=>oN.has(e))||e.status!==void 0&&e.status>=400&&e.status<500?new BA(t):new QA(t)}function yN(e){let t=typeof e==`string`?gr(nN(e)):e;if(!K(t))return[];let n=K(t.error)?t.error:void 0,r=n&&K(n.innererror)?n.innererror:void 0,i=n&&K(n.metadata)?n.metadata:void 0,a=K(t.response)?t.response:void 0,o=a&&K(a.error)?a.error:void 0,s=K(t.exception)?t.exception:void 0;return[t.code,...bN(t.__type),...bN(t.code),t.error_type,n?.code,n?.type,n?.status,n?.error_type,...Array.isArray(n?.details)?n.details.map(e=>K(e)?e.reason:void 0):[],r?.code,i?.error_type,o?.code,a?.error_type,s?.type].filter(e=>typeof e==`string`)}function bN(e){return typeof e==`string`?[e.replace(/:.*/s,``).replace(/^[^#]*#/,``)]:[]}const xN=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t])),SN=e=>Math.min(2**53-1,Math.max(0,Math.ceil(e))),CN=e=>{let t=Number(e[`retry-after-ms`]);if(Number.isFinite(t))return SN(t);let n=e[`retry-after`];if(!n)return;let r=Number(n);if(Number.isFinite(r))return SN(r*1e3);let i=Date.parse(n);if(!Number.isNaN(i))return SN(i-Date.now())},wN=(e,t,n)=>{t.length>0&&(e[t]=n)},TN=(e,t)=>{let n={},r={},i={};if(Object.entries(e).forEach(([e,t])=>{let a=/^x-ratelimit-limit-(.+)$/.exec(e)?.[1];if(a)return wN(n,a,t);let o=/^x-ratelimit-remaining-(.+)$/.exec(e)?.[1];if(o)return wN(r,o,t);let s=/^x-ratelimit-reset-(.+)$/.exec(e)?.[1];if(s)return wN(i,s,t);let c=/^anthropic-ratelimit-(.+)-(limit|remaining|reset)$/.exec(e);if(c)return c[2]===`limit`?wN(n,c[1],t):c[2]===`remaining`?wN(r,c[1],t):wN(i,c[1],t)}),t!==void 0||Object.keys(n).length!==0||Object.keys(r).length!==0||Object.keys(i).length!==0)return new RA({retryAfterMs:t,limit:Object.keys(n).length===0?void 0:n,remaining:Object.keys(r).length===0?void 0:r,reset:Object.keys(i).length===0?void 0:i})},EN=2e3,DN=(e,t)=>{let n=`Provider request failed with HTTP ${e}`,r=t?.trim()??``;return _N(r)||(!r||/^<(?:!doctype|html)/i.test(r)?n:`${n}: ${r.length>EN?`${r.slice(0,EN)}…`:r}`)},ON=e=>nf(function*(){if(e.status<400)return e;let t=yield*e.text.pipe(mf);return yield*kN({message:DN(e.status,t._tag===`Success`?t.success:void 0),url:e.request.url,status:e.status,responseHeaders:rj(e.headers),responseBody:t._tag===`Success`?t.success:void 0,cause:t._tag===`Failure`?t.failure.cause??t.failure:void 0})}),kN=e=>{let t=xN(tm(e.responseHeaders)),n=CN(t),r=TN(t,n);return new tj({reason:vN({message:e.message,status:e.status,data:e.data,rawBody:e.responseBody,retryAfterMs:n,rateLimit:r,cause:e.cause,http:e.status===void 0||e.url===void 0?void 0:new LA({url:e.url,status:e.status,headers:t})})})},AN=Py(F({message:M,code:Vy(M),cause:Vy(j)})),jN=e=>{let t=gr(AN(e));if(!t)return;if(t.code!==void 0)return t;let n=gr(AN(t.cause));return n?.code===void 0?t:n},MN=e=>UC(e)&&`cause`in e.reason&&e.reason.cause!==void 0?MN(e.reason.cause):e,NN=`Connection lost while reading the response`,PN=e=>{let t=UC(e.error)?e.error.request:e.request,n=n=>new tj({reason:new XA({message:n.message,cause:r,http:e.http,transport:`http`,operation:e.operation,code:n.code,url:t.url})}),r=MN(e.error),i=jN(r),a=i?.code,o=a&&i?.message&&!i.message.includes(a)?`${a}: ${i.message}`:i?.message,s=o??(e.error instanceof Error?e.error.message:void 0);return iu(e.error)||iu(r)?n({message:s??`HTTP transport timed out`,code:a??`Timeout`}):UC(e.error)?e.operation===`read`&&e.error.reason._tag===`DecodeError`?n({message:o?`${NN}: ${o}`:NN,code:a}):e.error.reason._tag===`TransportError`?n({message:s??e.error.reason.description??`HTTP transport failed`,code:a??e.error.reason._tag}):n({message:s??`HTTP transport failed: ${e.error.reason._tag}`,code:a??e.error.reason._tag}):n({message:s??`HTTP transport failed`,code:a})},FN=e=>e.stream.pipe(xC(t=>PN({error:t,request:e.request,operation:`read`,http:ij(e)}))),IN=Fu(nj,nf(function*(){let e=yield*Lw;return nj.of({execute:(t,n)=>nf(function*(){if(!n)return yield*e.execute(t).pipe(bf(e=>PN({error:e,request:t,operation:`request`})),w(ON));let r=yield*n(t,t=>e.execute(t).pipe(bf(e=>e instanceof Error?e:Error(String(e))))).pipe(bf(e=>PN({error:e,request:t,operation:`request`})));return yield*ON(r)})})})).pipe(Vu(Qw));var LN=class extends br()(`@opencode/AI/DecisionClient`){};const RN=e=>w(LN,t=>t.generate(e)),zN=Fu(LN,nf(function*(){let e=yield*nj;return LN.of({generate:Jf(function*(t){let n=t.model.route,r=yield*n.generate(t,e.execute);return VN(t.questions,r.answers)?r:yield*new tj({reason:new ZA({route:n.id,message:`Decision answers do not match the requested questions`,cause:r.answers})})})})})),BN=zN.pipe(Hu(IN)),VN=(e,t)=>e.length===t.length&&e.every((e,n)=>{let r=t[n];if(r.name!==e.name)return!1;if(r.type===`error`)return!0;if(e.type===`predicate`)return r.type===`predicate`;if(e.type===`choice`){if(r.type!==`choice`)return!1;let t=e.choices.map(e=>e.value);return t.includes(r.choice)&&HN(t,r.probabilities.map(e=>e.value))}return r.type!==`score`||r.score<0||r.score>e.levels.length-1?!1:HN(e.levels.map((e,t)=>t),r.probabilities.map(e=>e.value))}),HN=(e,t)=>e.length===t.length&&new Set(t).size===t.length&&t.every(t=>e.includes(t)),UN={Service:LN,layer:zN,fetchLayer:BN,generate:RN};z([`queued`,`running`,`completed`,`failed`,`cancelled`,`expired`]);const WN=ea(5),GN=ta(10),KN=F({type:V(`generation-queued`),id:M,position:k(N)}).annotate({identifier:`Generation.Event.Queued`}),qN=F({type:V(`generation-progress`),id:M,progress:k(N)}).annotate({identifier:`Generation.Event.Progress`}),JN=/* @__PURE__ */ new Set([`completed`,`failed`,`cancelled`,`expired`]),YN=e=>JN.has(e);var XN=class e{route;token;id;status;progress;position;constructor(e,t,n){this.route=e,this.token=t,this.id=n.id,this.status=n.status,this.progress=n.progress,this.position=n.position}get snapshot(){return{id:this.id,status:this.status,progress:this.progress,position:this.position}}get terminal(){return YN(this.status)}refresh(){return this.route.status.pipe(gf(t=>new e(this.route,this.token,t)))}result(){return this.route.result}await(e){let t=Li(e?.poll?.timeout??GN);return(this.terminal?S(this):this.poll(e?.poll)).pipe(w(e=>e.result()),Sf({duration:t,orElse:()=>$N(this.id,t)}))}cancel(){return this.route.cancel??$d}events(e){if(this.terminal)return iC(this.event());let t=Li(e?.poll?.timeout??GN);return fC(Uu.pipe(gf(n=>{let r=n+aa(t),i=QN(this.refresh(),this.id,t,r),a=this.schedule(e?.poll).pipe(jd(e=>S(da(e.duration,$i(Math.max(0,r-e.now))))));return $S(i,a).pipe(SC(e=>e.terminal),pC(e=>e.event()))})))}event(){return this.terminal?{type:`generation-finished`,id:this.id,status:this.status}:this.status===`queued`?{type:`generation-queued`,id:this.id,position:this.position}:{type:`generation-progress`,id:this.id,progress:this.progress}}poll(e){return this.refresh().pipe(Rf({schedule:this.schedule(e),until:e=>e.terminal}))}schedule(e){return Fd(e?.interval??WN)}};const ZN=(e,t,n)=>{let r=Li(n?.poll?.timeout??GN);return fC(Uu.pipe(gf(i=>e.events(n).pipe(bC(e=>e.type!==`generation-finished`),_C(cC(QN(e.result(),e.id,r,i+aa(r)).pipe(gf(t))))))))},QN=(e,t,n,r)=>Uu.pipe(w(i=>i>=r?C($N(t,n)):e.pipe(Sf({duration:$i(r-i),orElse:()=>C($N(t,n))})))),$N=(e,t)=>new tj({reason:new $A({message:`Generation ${e} did not finish within ${ha(t)}`,timeoutMs:Math.min(2**53-1,Math.max(0,Math.ceil(aa(t))))})}),eP=(e,t)=>({responseEvents:t.responseEvents,layer:Fu(e,nf(function*(){let n=yield*nj,r=(e,n)=>new tj({reason:new VA({operation:`${t.modality}.${n}`,provider:e.provider,route:e.id,message:`${e.provider}/${e.id} is not a queued route; use generate or stream`})}),i=e=>{let t=e.model.route;return t.kind===`queued`?t.start(e,n.execute):C(r(t,`start`))};return e.of({start:i,resume:(e,t)=>e.route.kind===`queued`?e.route.resume(e,t,n.execute):C(r(e.route,`resume`)),generate:(e,t)=>{let r=e.model.route;return r.kind===`queued`?i(e).pipe(w(e=>e.await(t))):r.generate(e,n.execute)},stream:(e,r)=>{let a=e.model.route;return a.kind===`stream`?a.stream(e,n.execute):a.kind===`queued`?fC(i(e).pipe(gf(e=>ZN(e,t.responseEvents,r)))):cC(gf(a.generate(e,n.execute),t.responseEvents))}})})),generate:(t,n)=>e.use(e=>e.generate(t,n)),stream:(t,n)=>fC(e.useSync(e=>e.stream(t,n))),start:t=>e.use(e=>e.start(t)),resume:(t,n)=>e.use(e=>e.resume(t,n))}),tP=(e,t={})=>({...t,path:e}),nP=e=>e.replace(/\/+$/,``),rP=(e,t)=>typeof e==`function`?e(t):e,iP=(e,t)=>{let n=new URL(`${nP(e.baseURL??``)}${rP(e.path,t)}`);for(let[t,r]of Object.entries(e.query??{}))n.searchParams.set(t,r);return n};var aP=class extends Error{source;_tag=`MissingCredentialError`;constructor(e,t=`Missing auth credential: ${e}`){super(t),this.source=e}};const oP=e=>e instanceof tj?e:new tj({reason:new UA({message:e instanceof aP?e.message:`Failed to resolve auth config: ${e.message}`,cause:e})}),sP=e=>t=>e.apply(t).pipe(bf(oP)),cP=e=>{if(typeof e==`string`)return e.isWellFormed()?e:e.toWellFormed();if(Array.isArray(e)){let t=e.map(cP);return Object.getPrototypeOf(e)===Array.prototype&&t.every((t,n)=>t===e[n])?e:t}if(e instanceof Uint8Array||e instanceof Error||e instanceof mj||!K(e))return e;let t=Object.entries(e),n=t.map(([e,t])=>[cP(e),cP(t)]);return n.every(([e,n],r)=>e===t[r][0]&&n===t[r][1])&&(Object.getPrototypeOf(e)===Object.prototype||By(e.constructor))?e:Object.fromEntries(n)},lP=e=>{let t=mP(e);return{kind:`inline`,id:e.protocol.id,provider:e.protocol.provider,protocol:e.protocol.id,generate:Yf(`MediaRoute.generate`)(function*(n,r){let i=yield*t.submit(n,{unsupported:e.protocol.unsupported,from:e.protocol.body.from},r);return yield*e.protocol.response.decode(i.response,i.context)})}},uP=ea(30),dP=Ed([Od([Ad(`1 second`),Fd(uP)]),Pd(8)]).pipe(Md,Rd(),jd(({input:e,duration:t})=>S(da(e.reason._tag===`RateLimit`||e.reason._tag===`ProviderInternal`?fa(t,$i(e.reason.retryAfterMs??0)):t,uP)))),fP=e=>{let t=mP(e),n=e.protocol,r=Ny(n.token),i=zy(n.token),a=(e,r,i)=>{let a=n=>t.call(`GET`,n.path(e),r,i).pipe(xf({schedule:dP,while:tN}),w(t=>n.decode(t.response,{token:e,auth:t.auth}))),o=a(n.status),s=n.cancel,c=s===void 0?void 0:t.call(s.method,s.path(e),r,i).pipe(vf);return{status:o,result:a(n.result),cancel:c!==void 0&&s?.activeOnly?o.pipe(w(e=>YN(e.status)?$d:c)):c}},o=Yf(`MediaRoute.start`)(function*(e,r){let o=yield*t.submit(e,{unsupported:n.unsupported,prepare:n.start.prepare,from:n.start.body.from},r),s=yield*n.start.decode(o.response,o.context);return new XN(a(s.token,o.context.request.http,r),i(s.token),s.snapshot)}),s=Yf(`MediaRoute.resume`)(function*(e,o,s){let c=yield*r(o).pipe(bf(e=>new tj({reason:new BA({message:`${n.id} cannot resume a generation from this token`,cause:e})}))),l=a(c,t.http(e),s);return new XN(l,i(c),yield*l.status)});return{kind:`queued`,id:n.id,provider:n.provider,protocol:n.id,start:o,resume:s}},pP=e=>{let t=mP(e),n=e.protocol,r=(e,r,i)=>fC(nf(function*(){let a=yield*t.submit({...e,mode:i},{unsupported:n.unsupported,from:n.body.from},r),o=ij(a.response);return aC(()=>{let e=n.initial();return n.frames(FN(a.response),a.context).pipe(mC(t=>n.step(e,t).pipe(gf(([t,n])=>(e=t,n)))),gC,_C(aC(()=>cC(n.finish(e,{...a.context,http:o})))),xC(e=>e.reason.http===void 0?new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:o})}):e))})}));return{kind:`stream`,id:n.id,provider:n.provider,protocol:n.id,stream:(e,t)=>r(e,t,`stream`),generate:(t,n)=>r(t,n,`generate`).pipe(wC,w(e.collect))}},mP=e=>{let t=e.headers===void 0?void 0:new fT({headers:e.headers}),n=sP(e.auth),r=t=>new URL(`${nP(e.endpoint.baseURL??``)}${t}`),i=Yf(`MediaRoute.send`)(function*(e,t){let r=gP(e.body,e.headers),i=e.url.toString(),a=yield*n({request:e.request,method:e.method,url:i,body:r.text,headers:r.headers});return{response:yield*t(r.apply(lw(e.method)(i).pipe(mw(a)))),auth:Object.fromEntries(Object.entries(a).filter(([e,t])=>r.headers[e]!==t))}});return{http:e=>pT(t,e.http),submit:Yf(`MediaRoute.submit`)(function*(n,a,o){yield*_P(e.protocol.id,e.protocol.provider,n,a.unsupported);let s=pT(t,n.model.http,n.http),c=lT(n.model.providerOptions,n.providerOptions),l=tm(s?.headers),u=a.prepare===void 0?n:yield*a.prepare(n,(e,t)=>i({method:`POST`,url:r(e),headers:l,request:n,body:t},o).pipe(gf(e=>e.response))),d={...cP({...u,http:s,providerOptions:c}),model:n.model},f=yield*a.from(d),ee=hP(hP(iP(e.endpoint,{request:d,body:f}),f.type===`multipart`?void 0:f.query),s?.query);return{response:(yield*i({method:`POST`,url:ee,headers:l,request:d,body:f},o)).response,context:{request:d,body:f}}}),call:(t,n,a,o)=>{let s=hP(/^https?:\/\//.test(n)?new URL(n):r(n),a?.query);for(let[t,n]of Object.entries(e.endpoint.query??{}))s.searchParams.set(t,n);return i({method:t,url:s,headers:tm(a?.headers),request:{http:a}},o)}}},hP=(e,t)=>{for(let[n,r]of Object.entries(t??{})){e.searchParams.delete(n);for(let t of typeof r==`string`?[r]:r)e.searchParams.append(n,t)}return e},gP=(e,t)=>{if(e===void 0)return{text:``,headers:t,apply:e=>e};if(e.type===`json`){let n=wj(e.value);return{text:n,headers:t,apply:Sw(n,`application/json`)}}return e.type===`binary`?{text:`[${e.contentType}]`,headers:t,apply:xw(e.value,e.contentType)}:{text:`[multipart/form-data]`,headers:om(t,`content-type`),apply:Cw(e.value)}},_P=(e,t,n,r)=>{let i=(r??[]).filter(e=>{let t=n[e];return Array.isArray(t)?t.length>0:t!==void 0});return i.length===0?$d:C(new tj({reason:new VA({operation:`media.${i[0]}`,provider:t,route:e,message:`${t}/${e} does not support ${i.join(`, `)}`})}))};var vP=class{id;provider;route;http;providerOptions;constructor(e){this.id=tT.make(e.id),this.provider=nT.make(e.provider),this.route=e.route,this.http=e.http,this.providerOptions=e.providerOptions}};const yP=(e,t,n)=>xP(e)?pP({...bP(e,t),collect:n}):SP(e)?fP(bP(e,t)):lP(bP(e,t)),bP=(e,t)=>({protocol:e.protocol,endpoint:tP(e.path,{baseURL:t.baseURL??e.baseURL}),auth:t.auth,headers:e.headers===void 0&&t.headers===void 0?void 0:{...e.headers,...t.headers}}),xP=e=>e.protocol.kind===`stream`,SP=e=>e.protocol.kind===`queued`,CP=e=>sf({try:e,catch:e=>new tj({reason:new BA({message:e instanceof Error?e.message:String(e),cause:e})})});var wP=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,NP)})}};const TP=Ty(e=>e instanceof wP,{expected:`Image.Model`}),EP=uj;G(`Image.Request`)({model:TP,prompt:M,images:k(L(vj)),n:k(W),aspect:k(EP),resolution:k(M),providerOptions:k(cT),http:k(fT)});var DP=class extends G(`Image.Response`)({images:L(vj),usage:k(eM),providerMetadata:k(q)}){get image(){return this.images[0]}};const OP=F({type:V(`image-partial`),index:N,image:vj}).annotate({identifier:`Image.Event.Partial`}),kP=F({type:V(`image`),index:N,image:vj}).annotate({identifier:`Image.Event.Image`}),AP=F({type:V(`finish`),usage:k(eM),providerMetadata:k(q)}).annotate({identifier:`Image.Event.Finish`}),jP=R([KN,qN,OP,kP,AP]).pipe(H(`type`)),MP=Object.assign(jP,{is:{generationQueued:jP.guards[`generation-queued`],generationProgress:jP.guards[`generation-progress`],imagePartial:jP.guards[`image-partial`],image:jP.guards.image,finish:jP.guards.finish}}),NP=e=>{let t=e.find(MP.is.finish);return t===void 0?of(/* @__PURE__ */ Error(`The image stream completed without a finish event`)):S(new DP({images:e.filter(MP.is.image).map(e=>e.image),usage:t.usage,providerMetadata:t.providerMetadata}))},PP=class extends br()(`@opencode/ImageClient`){},FP={Service:PP,...eP(PP,{modality:`image`,responseEvents:e=>[...e.images.map((e,t)=>kP.make({index:t,image:e})),AP.make({usage:e.usage,providerMetadata:e.providerMetadata})]})};My(sx),I(M,j),F({cost:(e=>Vy(tb(e).pipe(ob(()=>S(ur(void 0))))))(U.check(Db(0)))});const IP=e=>e.map(e=>e.text).join(`
|
|
11
|
+
`),LP=e=>e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`),RP=e=>`<system-update>\n${LP(IP(e))}\n</system-update>`,zP=Jf(function*(e,t){let n=[];for(let r of t.content){if(!UP(r,[`text`]))return yield*WP(e,`system`,[`text`]);n.push(r)}return n});Jf(function*(e,t){let n=yield*zP(e,t);return{type:`text`,text:RP(n),cache:n.at(-1)?.cache}});const BP=(e,t)=>new tj({reason:new BA({message:e,cause:t})}),VP=e=>new tj({reason:new VA({operation:e.operation,message:e.message,provider:e.provider,route:e.route,cause:e.cause})}),HP=e=>e.length<=1?e[0]??``:e.length===2?`${e[0]} and ${e[1]}`:`${e.slice(0,-1).join(`, `)}, and ${e.at(-1)}`,UP=(e,t)=>t.includes(e.type),WP=(e,t,n)=>BP(`${e} ${t} messages only support ${HP(n)} content for now`),GP=16777216,KP=(e,t)=>new tj({reason:new XA({message:e,body:t.body,cause:t.cause,transport:`websocket`,operation:t.operation,url:t.url,code:t.code,phase:t.phase,delivery:t.delivery})}),qP=(e,t)=>e.reason._tag===`Transport`?new tj({reason:new XA({...e.reason,message:e.reason.message,cause:e.reason.cause,phase:t.phase,delivery:t.delivery})}):e,JP=e=>`message`in e&&typeof e.message==`string`?e.message:e.type??`error`,YP=e=>{if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},XP=(e,t)=>e.readyState===globalThis.WebSocket.OPEN?$d:e.readyState===globalThis.WebSocket.CLOSING||e.readyState===globalThis.WebSocket.CLOSED?C(KP(`WebSocket closed before opening (state ${e.readyState})`,{url:t.url,operation:`request`,code:`closed`,phase:`connect`,delivery:`not-sent`})):ef((n,r)=>{let i=()=>{e.removeEventListener(`open`,o),e.removeEventListener(`error`,s),e.removeEventListener(`close`,c),r.removeEventListener(`abort`,a)},a=()=>{i(),e.readyState!==globalThis.WebSocket.CLOSED&&e.readyState!==globalThis.WebSocket.CLOSING&&(e.addEventListener(`error`,()=>{},{once:!0}),e.close(1e3))},o=()=>{i(),n($d)},s=e=>{i(),n(C(KP(`Failed to open WebSocket: ${JP(e)}`,{cause:`error`in e?e.error??e:e,url:t.url,operation:`request`,phase:`connect`,delivery:`not-sent`})))},c=e=>{i(),n(C(KP(`WebSocket closed before opening with code ${e.code}`,{body:e.reason,cause:e,url:t.url,operation:`request`,code:String(e.code),phase:`connect`,delivery:`not-sent`})))};e.addEventListener(`open`,o,{once:!0}),e.addEventListener(`error`,s,{once:!0}),e.addEventListener(`close`,c,{once:!0}),r.addEventListener(`abort`,a,{once:!0})}),ZP=e=>nf(function*(){let t=yield*$w,n=yield*sf({try:()=>t(e.url,{headers:e.headers}),catch:t=>KP(t instanceof Error?t.message:`Failed to construct WebSocket`,{cause:t,url:e.url,operation:`request`,phase:`connect`,delivery:`not-sent`})});return yield*QP(n,e)}),QP=(e,t)=>nf(function*(){yield*XP(e,t);let n=yield*Ox(),r=e=>typeof e==`string`?new Blob([e]).size>GP:e.byteLength>GP,i=i=>r(i)?(Mx(n,Xl(KP(`WebSocket message exceeds the 16 MiB limit`,{body:typeof i==`string`?i:new TextDecoder().decode(i),url:t.url,operation:`read`,code:`message-too-large`,phase:`receive`}))),e.readyState===globalThis.WebSocket.OPEN&&e.close(1009,`Message too large`),!0):!1,a=e=>{i(e)||Ax(n,e)},o=e=>{if(typeof e.data==`string`)return a(e.data);let r=YP(e.data);if(r)return a(r);Mx(n,Xl(KP(`Unsupported WebSocket message payload`,{cause:e,url:t.url,operation:`read`,code:`message`,phase:`receive`})))},s=e=>{Mx(n,Xl(KP(`WebSocket error: ${JP(e)}`,{cause:`error`in e?e.error??e:e,url:t.url,operation:`read`,code:`message`,phase:`receive`})))},c=e=>{Mx(n,Xl(KP(`WebSocket closed with code ${e.code}`,{body:e.reason,cause:e,url:t.url,operation:`read`,code:String(e.code),phase:`close`})))},l=Qd(()=>{e.removeEventListener(`message`,o),e.removeEventListener(`error`,s),e.removeEventListener(`close`,c)}).pipe(ff(Nx(n)));return e.addEventListener(`message`,o),e.addEventListener(`error`,s),e.addEventListener(`close`,c),{sendText:n=>Zd(()=>e.readyState===globalThis.WebSocket.OPEN?sf({try:()=>e.send(n),catch:e=>KP(e instanceof Error?e.message:`Failed to send WebSocket message`,{cause:e,url:t.url,operation:`write`,phase:`send`,delivery:`not-sent`})}):C(KP(`WebSocket is not open (state ${e.readyState})`,{url:t.url,operation:`write`,phase:`send`,delivery:`not-sent`}))),messages:uC(n),close:l.pipe(ff(Qd(()=>{e.readyState!==globalThis.WebSocket.CLOSED&&e.readyState!==globalThis.WebSocket.CLOSING&&e.close(1e3)})))}}),$P=(e,t)=>typeof e==`string`?e:t.decode(e),eF=e=>e.type===`frame`||e.type===`completed`||e.type===`incomplete`?S(e.frame):C(e.error),tF=e=>e.type!==`frame`,nF=e=>({execute:t=>nf(function*(){let n=yield*jf(e.open(t.connect).pipe(bf(e=>qP(e,{phase:`connect`,delivery:`not-sent`}))),e=>e.close),r=yield*t.driver.create(void 0);yield*n.sendText(r.message).pipe(bf(e=>new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:e.reason.http??n.http})})));let i=new TextDecoder,a=!1;return{http:n.http,frames:n.messages.pipe(pC(e=>(a=!0,$P(e,i))),xC(e=>qP(e,{phase:e.reason._tag===`Transport`&&e.reason.phase===`close`?`close`:`receive`,delivery:a?`accepted`:`ambiguous`})),mC(e=>t.driver.observe(r,e).pipe(bf(t=>new tj({reason:ej.make({...t.reason,message:t.reason.message,cause:t.reason.cause,body:e})})),gf(t=>`error`in t?{...t,error:new tj({reason:ej.make({...t.error.reason,message:t.error.reason.message,cause:t.error.reason.cause,body:e})})}:t))),SC(tF),mC(eF),xC(e=>new tj({reason:ej.make({...e.reason,message:e.reason.message,cause:e.reason.cause,http:e.reason.http??n.http})}))),complete:$d}})});nf(function*(){let e=yield*$w;return nF({open:t=>ZP(t).pipe(Af($w,e))})});const rF=e=>{if(e.role!==`system`||e.content.length!==1)return;let t=e.content[0];return t.type===`effort`?t:void 0},iF=e=>{let t=e.messages.filter(e=>rF(e)===void 0);return t.length===e.messages.length?e:Zj.update(e,{messages:t})},aF=e=>e.model.route.supportsEffortUpdates?.(e)?e:iF(e),oF={tools:!0,system:!0,messages:{tail:1}},sF={},cF=e=>e===`none`?sF:typeof e==`object`&&!lF(e)?e:oF,lF=e=>e===void 0||e===`auto`||typeof e==`object`&&e.tools===void 0&&e.system===void 0&&e.messages===void 0,uF=e=>typeof e.cache==`object`?e.cache.ttl:void 0,dF=/* @__PURE__ */ new Set([`alibaba-chat`,`alibaba-messages`,`anthropic-messages`,`anthropic-compatible-messages`,`bedrock-mantle-messages`,`cloudflare-ai-gateway-messages`,`google-vertex-messages`,`meta-messages`,`minimax-messages`,`moonshot-messages`,`vercel-ai-gateway-messages`,`zai-coding-messages`,`bedrock-converse`,`openrouter`,`digitalocean`]),fF={system:!0,messages:{tail:1}},pF=e=>{let t=e.replace(/^~/,``);return t.startsWith(`anthropic/`)?oF:t.startsWith(`qwen/`)||t.startsWith(`alibaba/qwen`)?fF:sF},mF=e=>e===void 0?new ET({type:`ephemeral`}):new ET({type:`ephemeral`,ttl:e}),hF=(e,t,n)=>{let r=e.at(-1);if(r===void 0)return e;if(r.type===`namespace`){let i=hF(r.tools,t,n);return i===r.tools?e:[...e.slice(0,-1),{...r,tools:i}]}return r.cache||n.remaining===0?e:(--n.remaining,[...e.slice(0,-1),new Kj({...r,cache:t})])},gF=e=>e.reduce((e,t)=>e+(t.type===`tool`?t.cache===void 0?0:1:gF(t.tools)),0),_F=(e,t,n)=>{if(e.length===0)return e;let r=!1,i=e.map((i,a)=>a!==0&&a!==e.length-1||i.cache||n.remaining===0?i:(--n.remaining,r=!0,{...i,cache:t}));return r?i:e},vF=(e,t)=>e.findLastIndex(e=>e.role===t),yF=e=>e.type!==`compaction`&&e.type!==`effort`,bF=(e,t,n,r)=>{if(t<0||t>=e.length)return e;let i=e[t];if(i.content.length===0)return e;let a=i.content.findLastIndex(e=>e.type===`text`),o=a>=0?a:i.content.findLastIndex(yF),s=i.content[o];if(!s||!yF(s)||s.cache||r.remaining===0)return e;--r.remaining;let c=i.content.map((e,t)=>t===o?{...s,cache:n}:e),l=new Uj({...i,content:c}),u=e.slice();return u[t]=l,u},xF=(e,t,n,r)=>{if(e.length===0)return e;if(t===`latest-user-message`)return bF(e,vF(e,`user`),n,r);if(t===`latest-assistant`)return bF(e,vF(e,`assistant`),n,r);let i=e.length,a=t.tail;for(;a>0&&i>0;)--i,rF(e[i])===void 0&&--a;let o=e;for(let t=i;t<e.length;t++)rF(e[t])===void 0&&(o=bF(o,t,n,r));return o},SF=e=>gF(e.tools)+e.system.reduce((e,t)=>e+(t.cache===void 0?0:1),0)+e.messages.reduce((e,t)=>e+t.content.reduce((e,t)=>e+(yF(t)&&t.cache!==void 0?1:0),0),0),CF=e=>{let t=wF(e);if(!t.tools&&!t.system&&!t.messages)return e;let n=mF(uF(e)),r={remaining:Math.max(0,4-SF(e))},i=t.tools?hF(e.tools,n,r):e.tools,a=t.system?_F(e.system,n,r):e.system,o=t.messages?xF(e.messages,t.messages,n,r):e.messages;return i===e.tools&&a===e.system&&o===e.messages?e:Zj.update(e,{tools:i,system:a,messages:o})},wF=e=>{let t=e.model.compatibility?.cacheFormat,n=e.model.route.id,r=lF(e.cache);return t===`alibaba`?r?fF:{...cF(e.cache),tools:!1}:t===`anthropic`?cF(e.cache):dF.has(n)?r?n===`openrouter`||n===`vercel-ai-gateway-messages`?pF(e.model.id):n===`alibaba-chat`?e.model.id.toLowerCase().startsWith(`qwen`)?fF:sF:oF:cF(e.cache):sF},TF=`(no tool output)`;function EF(e){let t=[],n=/* @__PURE__ */ new Map,r=[],i=()=>{n.size>0||(t.push(...r),r.length=0)},a=()=>{n.size>0&&t.push(DF(n.values())),n.clear(),i()};for(let o of e)if((o.role===`user`||o.role===`assistant`)&&a(),o.role===`tool`){let e=OF(o,n);e&&t.push(e),i()}else if(o.role===`system`&&n.size>0)r.push(o);else if(t.push(o),o.role===`assistant`)for(let e of o.content)e.type===`tool-call`&&e.providerExecuted!==!0&&n.set(e.id,e);return a(),t.length===e.length&&t.every((t,n)=>t===e[n])?e:t}function DF(e){return new Uj({role:`tool`,content:[...e].map(e=>Rj.make({id:e.id,name:e.name,namespace:e.namespace,result:`Tool result missing`,resultType:`error`}))})}function OF(e,t){let n=e.content.map(e=>{if(e.type!==`tool-result`||e.providerExecuted===!0)return e;let n=t.get(e.id);return n&&t.delete(e.id),kF(e,n)});if(n.length!==0)return n.every((t,n)=>t===e.content[n])?e:new Uj({id:e.id,role:e.role,content:n,metadata:e.metadata,providerMetadata:e.providerMetadata,native:e.native})}function kF(e,t){let n=t===void 0||e.name===t.name&&e.namespace===t.namespace?e:{...e,name:t.name,namespace:t.namespace};if(n.result.type===`text`&&n.result.value===``)return{...n,result:{type:`text`,value:TF}};if(n.result.type===`error`&&n.result.value===``)return{...n,result:{type:`error`,value:TF}};if(n.result.type!==`content`)return n;let r=n.result.value.filter(e=>e.type!==`text`||e.text!==``);return r.length===0?{...n,result:{type:`text`,value:TF}}:r.length===n.result.value.length?n:{...n,result:{type:`content`,value:r}}}var AF=/* @__PURE__ */ n({GeminiJsonSchema:()=>AF,SCHEMA_MAPS:()=>jF,VALUES:()=>MF,mapValues:()=>NF,normalize:()=>IF});const jF=/* @__PURE__ */ new Set([`properties`,`patternProperties`,`$defs`,`definitions`,`dependentSchemas`,`dependencies`]),MF=/* @__PURE__ */ new Set([`const`,`default`,`enum`,`examples`,`dependentRequired`]),NF=(e,t)=>Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n,e)])),PF=e=>{if(Array.isArray(e))return e.map(PF);if(!K(e))return e;let t=K(e.properties)?e.properties:void 0;return Object.fromEntries(Object.entries(e).flatMap(([n,r])=>MF.has(n)?[[n,r]]:jF.has(n)&&K(r)?[[n,NF(r,PF)]]:n===`required`&&t&&Array.isArray(r)?[[n,r.filter(e=>typeof e==`string`&&Object.hasOwn(t,e))]]:n===`exclusiveMinimum`&&typeof r==`boolean`?r&&typeof e.minimum==`number`?[[n,e.minimum]]:[]:n===`exclusiveMaximum`&&typeof r==`boolean`?r&&typeof e.maximum==`number`?[[n,e.maximum]]:[]:n===`minimum`&&e.exclusiveMinimum===!0||n===`maximum`&&e.exclusiveMaximum===!0?[]:n===`items`&&Array.isArray(r)?[[`prefixItems`,r.map(PF)]]:n===`additionalItems`&&Array.isArray(e.items)?[[`items`,PF(r)]]:[[n,PF(r)]]))},FF=(e,t,n)=>{if(Array.isArray(e))return e.map(e=>FF(e,t,n));if(!K(e))return e;if(e.$ref===t&&!n)return{};let r=Array.isArray(e.required)?e.required:[];return NF(e,(i,a)=>MF.has(a)?i:a===`items`?FF(i,t,n||!(Number(e.minItems)>0)):a===`properties`&&K(i)?NF(i,(e,i)=>FF(e,t,n||!r.includes(i))):jF.has(a)&&K(i)?NF(i,e=>FF(e,t,n)):FF(i,t,n))},IF=e=>{let t=PF(e);if(!K(t))return{};let n=FF(NF(t,(e,t)=>(t===`$defs`||t===`definitions`)&&K(e)?NF(e,(e,n)=>FF(e,`#/${t}/${n}`,!1)):e),`#`,!1);return K(n)?n:{}},{SCHEMA_MAPS:LF,VALUES:RF,mapValues:zF}=AF,BF=e=>{let t=e.map(HF);return t.length===0?{}:t.length===1?t[0]:{anyOf:t}},VF=e=>{let t=[...new Set(e.map(e=>e===null?`null`:Array.isArray(e)?`array`:typeof e))];if(t.length===1)return t[0];if(t.length===2&&t.includes(`null`))return[...t.filter(e=>e!==`null`),`null`]},HF=e=>{if(Array.isArray(e))return e.map(HF);if(!K(e))return e;if(typeof e.$ref==`string`)return{$ref:e.$ref};let t=e.type===void 0&&Array.isArray(e.enum)?VF(e.enum):void 0;return Object.fromEntries([...t===void 0?[]:[[`type`,t]],...Object.entries(e).flatMap(([t,n])=>{if(RF.has(t))return[[t,n]];if(LF.has(t)&&K(n))return[[t,zF(n,HF)]];if(t===`items`){if(Array.isArray(e.prefixItems))return[];if(Array.isArray(n))return[[t,BF(n)]]}if(t===`prefixItems`){if(!Array.isArray(n))return`items`in e?[]:[[`items`,{}]];let t=K(e.items)?[e.items]:Array.isArray(e.items)?e.items:[];return[[`items`,BF([...n,...t])]]}return t===`unevaluatedItems`?[]:[[t,HF(n)]]})])},UF=e=>{let t=HF(e);return K(t)?t:{}},WF=IF,GF=[[/gemini/i,`gemini`],[/kimi/i,`moonshot`]],KF=e=>(e.type===void 0||e.type===`object`)&&K(e.not)&&e.not.type===`null`&&Object.keys(e.not).length===1?{type:`object`,...Object.fromEntries(Object.entries(e).filter(([e])=>e!==`not`))}:e.type===void 0?Array.isArray(e.anyOf)&&e.anyOf.some(e=>K(e)&&e.type===`object`&&Object.keys(e).length===1)?{type:`object`,...Object.fromEntries(Object.entries(e).filter(([e])=>e!==`anyOf`))}:{type:`object`,...e}:e,qF=(e,t)=>{let n=KF(e);switch(t.compatibility?.sanitizer??t.route.sanitizer??GF.find(([e])=>e.test(t.id))?.[1]){case`gemini`:return WF(n);case`moonshot`:return UF(n);case`none`:case void 0:return n}},JF=(e,t)=>e.map(e=>e.type===`tool`?new Kj({...e,inputSchema:qF(e.inputSchema,t)}):{...e,tools:JF(e.tools,t)}),YF={gemini:WF,moonshot:UF,tools:JF};function XF(e,t){return t?.mechanism===`trigger`?e.model.route.compact?.trigger!==void 0:t?.mechanism!==void 0&&t.mechanism!==`endpoint`?!1:e.model.route.compact?.endpoint!==void 0}const ZF=(e,t)=>t!==void 0&&t!==`endpoint`&&t!==`trigger`?BP(`Unknown compaction mechanism: ${t}`):VP({operation:t===`trigger`?`compact.trigger`:`compact`,provider:e.model.provider,route:e.model.route.id,message:`${e.model.provider}/${e.model.route.id} does not support ${t===`trigger`?`trigger`:`explicit`} compaction`}),QF=class extends br()(`@opencode/LLMClient`){},$F=e=>{let t=EF(e.messages),n=t===e.messages?e:Zj.update(e,{messages:t}),r=n.model.route.defaults,i=n.model.defaults,a=gT(r.generation,i?.generation,n.generation);return Zj.update(n,{generation:a??new mT({}),providerOptions:lT(r.providerOptions,i?.providerOptions,n.providerOptions),http:pT(r.http,i?.http,n.http)})},eI=e=>new tj({reason:new ZA({message:`The provider response ended unexpectedly.`,classification:`incomplete-stream`,route:e})});Py(Cj);const tI=e=>{let t=$F(e),n=Zj.update(t,cP({...Zj.input(t),model:void 0})),r=e=>[...new Map(e.map(e=>[`${e.type}:${e.name}`,e])).values()].map(e=>e.type===`tool`?e:{...e,tools:r(e.tools)}),i=CF(aF(Zj.update(n,{tools:YF.tools(r(n.tools),n.model)}))),a=i.model.route.headers?.({request:i});return a===void 0?i:Zj.update(i,{http:pT(new fT({headers:a}),i.http)})},nI=Yf(`LLM.compile`)(function*(e,t){if(e.messages.flatMap(e=>e.content.flatMap(e=>{if(e.type===`media`){let t=e.media.source;return t.type===`url`?[t.url]:t.type===`ref`?[t.id]:[]}return e.type!==`tool-result`||e.result.type!==`content`?[]:e.result.value.flatMap(e=>e.type===`file`?[e.uri]:[])})).some(e=>/^\s*file:/i.test(e)))return yield*BP(`Local file references must be read with Media.file(path) before sending`);let n=tI(e),r=n.model.route,i=yield*r.body.from(n);return{request:n,route:r,body:i,prepared:yield*r.prepareTransport(i,n,t)}});Yf(`LLM.compileRequest`)(function*(e){let t=yield*nI(e);return{id:t.request.id??`request`,route:t.route.id,protocol:t.route.protocol,model:t.request.model,body:t.body,metadata:{transport:t.route.transport.id}}});const rI=e=>(t,n)=>fC(nf(function*(){let r=yield*nI(t,n);return r.route.streamPrepared(r.prepared,r.request,e,n)})),iI=e=>Yf(`LLM.generate`)(function*(t,n){let r=yield*e(t,n).pipe(TC(YM.empty,YM.reduce));return YM.complete(r)||(yield*eI(`${t.model.provider}/${t.model.route.id}`))});function aI(e,t){return fC(nf(function*(){return(yield*QF).stream(e,t)}))}function oI(e,t){return nf(function*(){return yield*(yield*QF).generate(e,t)})}function sI(e,t){return nf(function*(){let n=yield*QF;return t?.mechanism===`trigger`&&XF(e,t)||(t?.mechanism===void 0||t.mechanism===`endpoint`)&&XF(e)?yield*n.compact(e,t):yield*ZF(e,t?.mechanism)})}const cI={canCompact:XF,compact:sI,Service:QF,layer:Fu(QF,nf(function*(){let e=yield*nj,t=rI({http:e});function n(t,n){return Zd(()=>n?.mechanism===`trigger`&&XF(t,n)?t.model.route.compact.trigger(tI(t),e,n):(n?.mechanism===void 0||n.mechanism===`endpoint`)&&XF(t)?t.model.route.compact.endpoint(tI(t),e,n):ZF(t,n?.mechanism))}return QF.of({stream:t,generate:iI(t),compact:n})})),stream:aI,generate:oI};var lI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,yI)})}};const uI=Ty(e=>e instanceof lI,{expected:`Speech.Model`}),dI=R([M,F({id:M})]).annotate({identifier:`Speech.Voice`}),fI=F({text:M,startSeconds:N,endSeconds:N}).annotate({identifier:`Speech.Timestamp`});G(`Speech.Request`)({model:uI,text:M,voice:k(dI),format:k(M),speed:k(N),language:k(M),instructions:k(M),timestamps:k(P),providerOptions:k(cT),http:k(fT)});var pI=class extends G(`Speech.Response`)({audio:vj,timestamps:k(L(fI)),usage:k(eM),providerMetadata:k(q)}){};const mI=F({type:V(`audio-delta`),chunk:Ub}).annotate({identifier:`Speech.Event.AudioDelta`}),hI=F({type:V(`timestamps`),items:L(fI)}).annotate({identifier:`Speech.Event.Timestamps`}),gI=F({type:V(`finish`),audio:vj,usage:k(eM),providerMetadata:k(q)}).annotate({identifier:`Speech.Event.Finish`}),_I=R([KN,qN,mI,hI,gI]).pipe(H(`type`)),vI=Object.assign(_I,{is:{generationQueued:_I.guards[`generation-queued`],generationProgress:_I.guards[`generation-progress`],audioDelta:_I.guards[`audio-delta`],timestamps:_I.guards.timestamps,finish:_I.guards.finish}}),yI=e=>{let t=e.find(vI.is.finish);if(t===void 0)return of(/* @__PURE__ */ Error(`The speech stream completed without a finish event`));let n=e.filter(vI.is.timestamps).flatMap(e=>e.items);return S(new pI({audio:t.audio,timestamps:n.length===0?void 0:n,usage:t.usage,providerMetadata:t.providerMetadata}))},bI=class extends br()(`@opencode/SpeechClient`){},xI={Service:bI,...eP(bI,{modality:`speech`,responseEvents:e=>[...e.timestamps===void 0?[]:[hI.make({items:e.timestamps})],gI.make({audio:e.audio,usage:e.usage,providerMetadata:e.providerMetadata})]})};var SI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,PI)})}};const CI=Ty(e=>e instanceof SI,{expected:`Transcription.Model`}),wI=z([`none`,`segment`,`word`]);G(`Transcription.Request`)({model:CI,audio:vj,language:k(M),prompt:k(M),timestamps:k(wI),diarize:k(P),speakers:k(W),providerOptions:k(cT),http:k(fT)});const TI=F({text:M,startSeconds:N,endSeconds:N,speaker:k(M)}).annotate({identifier:`Transcription.Segment`}),EI=F({text:M,startSeconds:N,endSeconds:N,speaker:k(M),confidence:k(N)}).annotate({identifier:`Transcription.Word`}),DI={text:M,segments:k(L(TI)),words:k(L(EI)),language:k(M),durationSeconds:k(N),usage:k(eM),providerMetadata:k(q)};var OI=class extends G(`Transcription.Response`)(DI){};const kI=F({type:V(`text-delta`),delta:M}).annotate({identifier:`Transcription.Event.TextDelta`}),AI=F({type:V(`segment`),segment:TI}).annotate({identifier:`Transcription.Event.Segment`}),jI=F({type:V(`finish`),...DI}).annotate({identifier:`Transcription.Event.Finish`}),MI=R([KN,qN,kI,AI,jI]).pipe(H(`type`)),NI=Object.assign(MI,{is:{generationQueued:MI.guards[`generation-queued`],generationProgress:MI.guards[`generation-progress`],textDelta:MI.guards[`text-delta`],segment:MI.guards.segment,finish:MI.guards.finish}}),PI=e=>{let t=e.find(NI.is.finish);if(t===void 0)return of(/* @__PURE__ */ Error(`The transcription stream completed without a finish event`));let{type:n,...r}=t;return S(new OI(r))},FI=class extends br()(`@opencode/TranscriptionClient`){},II={Service:FI,...eP(FI,{modality:`transcription`,responseEvents:e=>[jI.make({...e})]})};var LI=class e extends vP{static fromRoute(t,n){return new e({id:n.id,provider:t.protocol.provider,http:n.http,providerOptions:n.providerOptions,route:yP(t,n,KI)})}};const RI=Ty(e=>e instanceof LI,{expected:`Video.Model`}),zI=uj,BI=F({first:k(vj),last:k(vj)}).annotate({identifier:`Video.Frames`});G(`Video.Request`)({model:RI,prompt:M,frames:k(BI),references:k(L(vj)),video:k(vj),durationSeconds:k(N),aspect:k(zI),resolution:k(M),audio:k(P),n:k(W),seed:k(N),negativePrompt:k(M),providerOptions:k(cT),http:k(fT)});var VI=class extends G(`Video.Response`)({videos:L(vj),usage:k(eM),providerMetadata:k(q)}){get video(){return this.videos[0]}};const HI=F({type:V(`video`),index:N,video:vj}).annotate({identifier:`Video.Event.Video`}),UI=F({type:V(`finish`),usage:k(eM),providerMetadata:k(q)}).annotate({identifier:`Video.Event.Finish`}),WI=R([KN,qN,HI,UI]).pipe(H(`type`)),GI=Object.assign(WI,{is:{generationQueued:WI.guards[`generation-queued`],generationProgress:WI.guards[`generation-progress`],video:WI.guards.video,finish:WI.guards.finish}}),KI=e=>{let t=e.find(GI.is.finish);return t===void 0?of(/* @__PURE__ */ Error(`The video stream completed without a finish event`)):S(new VI({videos:e.filter(GI.is.video).map(e=>e.video),usage:t.usage,providerMetadata:t.providerMetadata}))},qI=class extends br()(`@opencode/VideoClient`){},JI={Service:qI,...eP(qI,{modality:`video`,responseEvents:e=>[...e.videos.map((e,t)=>HI.make({index:t,video:e})),UI.make({usage:e.usage,providerMetadata:e.providerMetadata})]})},YI=(e=>zu(cI.layer,FP.layer,JI.layer,xI.layer,II.layer,UN.layer).pipe(Hu(e)))(IN),XI=R([F({type:A(`text`),text:M}),F({type:A(`json`),value:sx}),F({type:A(`media`),media:vj,filename:k(M)})]).pipe(H(`type`)),ZI=R([M,P]),QI=L(R([F({name:M,type:A(`predicate`),instructions:M}),F({name:M,type:A(`choice`),instructions:M,choices:L(F({value:ZI,description:k(M)}))}),F({name:M,type:A(`score`),instructions:M,levels:L(F({label:M,description:k(M)}))})]).pipe(H(`type`))).pipe(ib(e=>e.length>0,{message:`Decision questions must not be empty`}),ib(e=>new Set(e.map(e=>e.name)).size===e.length,{message:`Decision question names must be unique`})),$I=N.check(kb({minimum:0,maximum:1})),eL=F({name:M,type:A(`predicate`),probability:$I}),tL=F({name:M,type:A(`choice`),choice:ZI,probabilities:L(F({value:ZI,probability:$I})),confidence:$I}),nL=F({name:M,type:A(`score`),score:N,probabilities:L(F({value:W,label:M,probability:$I})),confidence:$I}),rL=R([A(`refusal`),M]),iL=R([eL,tL,nL,F({name:M,type:A(`error`),reason:rL,message:k(M)})]).pipe(H(`type`));var aL=class extends G(`Decision.ModelCompatibility`)({mediaInput:k(z([`assets`,`state`,`root`]))}){};(function(e){e.make=t=>t instanceof e?t:new e(t)})(aL||={});var oL=class e{id;provider;route;http;compatibility;providerOptions;constructor(e){this.id=e.id,this.provider=e.provider,this.route=e.route,this.http=e.http,this.compatibility=e.compatibility,this.providerOptions=e.providerOptions}static make(t){return new e({...t,id:tT.make(t.id),provider:nT.make(t.provider)})}};const sL=Ty(e=>e instanceof oL,{expected:`Decision.Model`});G(`Decision.Request`)({model:sL,input:L(XI),questions:QI,providerOptions:k(cT),http:k(fT)});var cL=class extends G(`Decision.Usage`)({inputTokens:k(N),outputTokens:k(N),totalTokens:k(N),cost:k(N)}){};G(`Decision.Response`)({answers:L(iL),usage:k(cL),providerMetadata:k(q)});const lL=e=>Object.entries(e).map(([e,t])=>new Kj({name:e,description:t._definition.description,inputSchema:t._definition.inputSchema,outputSchema:t._definition.outputSchema,freeform:t._definition.freeform}));function uL(e,t){return dL(e).pipe(w(e=>cI.generate(e,t)))}const dL=e=>e instanceof Zj?S(e):CP(()=>fL(e)),fL=e=>{let{system:t,prompt:n,messages:r,tools:i,toolChoice:a,generation:o,providerOptions:s,http:c,...l}=e;return new Zj({...l,system:Oj.content(t),messages:[...r?.map(Uj.make)??[],...n===void 0?[]:[Uj.user(n)]],tools:i?.map(Jj.make)??[],toolChoice:a?Yj.make(a):void 0,generation:o===void 0?void 0:mT.make(o),providerOptions:s,http:fT.make(c)})},pL=`generate_object`;var mL=class{object;response;constructor(e,t){this.object=e,this.response=t}get events(){return this.response.events}get usage(){return this.response.usage}};Yf(`LLM.generateObject`)(function*(e,t){let n=fL(e),r=Zj.update(n,{tools:lL({[pL]:t}),toolChoice:Yj.named(pL)}),i=yield*cI.generate(r),a=i.toolCalls.find(e=>e.name===pL);return a?new mL(yield*t._decode(a.input).pipe(bf(e=>new tj({reason:new ZA({message:`generateObject: tool input failed schema decode: ${e.message}`,cause:e})}))),i):yield*new tj({reason:new ZA({message:`generateObject: model did not call the forced \`${pL}\` tool`})})});var hL=class extends br()(`@opencode/ModelResolver`){},gL=class extends br()(`@opencode/PluginHooks`){};const _L={type:`object`,additionalProperties:!0},vL=aO({id:`yuri.llm`,methods:{ready:{input:{type:`object`,additionalProperties:!1},output:{type:`object`,properties:{version:{type:`integer`}},required:[`version`],additionalProperties:!1}},generate:{input:{type:`object`,properties:{providerID:{type:`string`,minLength:1},modelID:{type:`string`,minLength:1},variant:{type:`string`},messages:{type:`array`,minItems:1,items:_L},tools:{type:`array`,items:_L},cacheKey:{type:`string`,minLength:1,maxLength:256},maxOutputTokens:{type:`integer`,minimum:1}},required:[`providerID`,`modelID`,`messages`,`cacheKey`],additionalProperties:!1},output:_L,errors:{unavailable:_L,generation_failed:_L}}},events:{}}),yL=[`messages`,`input`,`system`,`instructions`,`tools`,`tool_choice`],bL=[`maxTokens`,`temperature`,`topP`,`topK`,`frequencyPenalty`,`presencePenalty`,`seed`,`stop`],xL=e=>e&&{generation:Object.fromEntries(bL.filter(t=>e[t]!==void 0).map(t=>[t,e[t]])),providerOptions:e.providerOptions,http:{...e.http,headers:e.headers,timeout:typeof e.timeout==`object`?e.timeout.total:e.timeout,headerTimeout:e.timeout?.headers,chunkTimeout:e.timeout?.chunk}},SL=(e,t)=>{let{generation:n,http:r,...i}=e,{headers:a,timeout:o,headerTimeout:s,chunkTimeout:c,...l}=r??{};return{...i,...n,model:t,headers:a,http:l,timeout:{total:o,headers:s,chunk:c}}},CL=()=>Object.assign(/* @__PURE__ */ Error(`External OpenCode clean inference runtime is unavailable or incompatible`),{code:`unavailable`}),wL=e=>{let t=e?.reason,n=/* @__PURE__ */ new Set([`Authentication`,`RateLimit`,`QuotaExceeded`,`InvalidRequest`,`ProviderConfiguration`,`UnsupportedOperation`,`NoRoute`,`ContentPolicy`,`ProviderInternal`,`Transport`,`Timeout`,`InvalidProviderOutput`,`UnknownProvider`]);return{reason:n.has(t?._tag)?t._tag:`UnknownProvider`,...Number.isInteger(t?.http?.status)?{status:t.http.status}:{},...n.has(t?._tag)?{}:{diagnostic:e?.message?.includes(`Schema validation failed`)?`runtime_schema_mismatch`:e?.message?.includes(`Service not found`)?`missing_runtime_service`:e?.name===`TypeError`?`type_error`:e?.name===`ReferenceError`?`reference_error`:`unclassified`}}},TL=e=>{if(e.role===`tool`)return Uj.tool({id:e.tool_call_id,name:e.name,result:{type:`text`,value:e.content}});if(e.role===`assistant`)return Uj.assistant([...e.content?[Uj.text(e.content)]:[],...(e.tool_calls??[]).map(e=>({type:`tool-call`,id:e.id,name:e.function.name,input:JSON.parse(e.function.arguments)}))]);let t=[Uj.text(e.content)];for(let n of e.parts??[])if(n.mime?.startsWith(`image/`)){let e=n.url.indexOf(`,`);t.push(Uj.media(Sj(n.url.slice(e+1),n.mime)))}else t.push(Uj.text(`[file: ${n.filename||n.mime}] ${n.url}`));return Uj.user(t)},EL=Tf().pipe(w(e=>{let t=Jr(e,hL),n=Jr(e,gL);return t._tag===`Some`&&typeof t.value.resolve==`function`&&n._tag===`Some`&&typeof n.value.trigger==`function`?S({resolver:t.value,hooks:n.value}):C(CL())})),DL=t=>nf(function*(){let{resolver:n,hooks:r}=yield*EL,i=yield*n.resolve({providerID:t.providerID,id:t.modelID,...t.variant?{variant:t.variant}:{}});if(!i||[i.model.defaults?.http?.body,i.model.route.defaults?.http?.body,i.model.options?.http?.body,i.model.route.options?.http?.body].some(e=>yL.some(t=>Object.hasOwn(e??{},t))))return yield*C(CL());let a=i.model.route.defaults===void 0,o={sessionID:`ses_${e(`sha256`).update(t.cacheKey).digest(`hex`)}`,agent:`yuri-inference`,model:i.ref,kind:`generate`},s=fL({model:CT.make(a?{...i.model,defaults:xL(i.model.options),compatibility:{...i.model.compatibility,supportsPromptCacheKey:i.model.capabilities?.promptCacheKey,supportsEffortUpdates:i.model.capabilities?.reasoning?.updates}}:i.model),system:t.messages.filter(e=>e.role===`system`).map(e=>e.content).join(`
|
|
12
12
|
|
|
13
|
-
`),messages:t.messages.filter(e=>e.role!==`system`).map(
|
|
13
|
+
`),messages:t.messages.filter(e=>e.role!==`system`).map(TL),tools:t.tools??[],promptCacheKey:t.cacheKey,...i.cache?.ttl===void 0?{}:{cache:{ttl:i.cache.ttl}},http:{headers:{"x-opencode-session":t.cacheKey,"x-session-affinity":t.cacheKey,"X-Session-Id":t.cacheKey,"X-Magpie-Session":t.cacheKey}},...t.maxOutputTokens?{generation:{maxTokens:t.maxOutputTokens}}:{}}),c=yield*r.trigger(`session`,`model.request`,{...o,baseURL:s.model.route.endpoint.baseURL,headers:{...s.http?.headers}}),l=c.baseURL!==void 0&&c.baseURL!==s.model.route.endpoint.baseURL?s.model.route.with({endpoint:{baseURL:c.baseURL}}):s.model.route,u=l===i.model.route?i.model:i.model.constructor.update(i.model,{route:l}),d=e=>a?SL(e,u):{...e,model:u},f={...l,...a?{defaults:{},headers:l.headers&&(({request:e})=>l.headers({request:d(e)}))}:{},body:{...l.body,from:e=>l.body.from(d(e))},prepareTransport:(e,t,n)=>l.prepareTransport(e,d(t),n),streamPrepared:(e,t,n,r)=>l.streamPrepared(e,d(t),n,r)},ee=yield*uL(Zj.update(s,{model:CT.update(s.model,{route:f}),http:new fT({...s.http,headers:c.headers})}),{http:(e,t)=>nf(function*(){let n=yield*kw(e),i=yield*r.trigger(`session`,`http.request`,{...o,request:n}),a=i.request===n?bw(Tw(n),e.body):i.request.body?xw(Tw(i.request),new Uint8Array(yield*Jd(()=>i.request.clone().arrayBuffer())),i.request.headers.get(`content-type`)??void 0):Tw(i.request),s=yield*t(a),c=yield*r.trigger(`session`,`http.response`,{...o,request:i.request,response:new Response([204,205,304].includes(s.status)?null:yield*OC(s.stream),{status:s.status,headers:s.headers})});return Nw(a,c.response)})}).pipe(Df(YI));return{text:ee.text,toolCalls:ee.toolCalls.map(e=>({id:e.id,name:e.name,arguments:e.input})),finishReason:ee.finishReason.normalized,usage:{inputTokens:ee.usage?.inputTokens??0,outputTokens:ee.usage?.outputTokens??0,cacheReadInputTokens:ee.usage?.cacheReadInputTokens??0}}});var OL={id:`yuri.llm.bridge`,effect:e=>e.rpc.register(vL,{ready:()=>EL.pipe(_f({version:2})),generate:(e,t)=>DL(e).pipe(yf(e=>{if(tu(e))return rf(e);let n=$l(e);return C(t.error(n?.code===`unavailable`?`unavailable`:`generation_failed`,n?.code===`unavailable`?CL().message:`LLM provider generation failed`,n?.code===`unavailable`?{}:wL(n)))}))})};export{OL as default,DL as generateBridgeResponse};
|