@adhd/backlog 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var mp=Object.create;var Yi=Object.defineProperty;var gp=Object.getOwnPropertyDescriptor;var yp=Object.getOwnPropertyNames;var vp=Object.getPrototypeOf,$p=Object.prototype.hasOwnProperty;var wp=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yp(t))!$p.call(e,o)&&o!==n&&Yi(e,o,{get:()=>t[o],enumerable:!(r=gp(t,o))||r.enumerable});return e};var bp=(e,t,n)=>(n=e!=null?mp(vp(e)):{},wp(t||!e||!e.__esModule?Yi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("node:fs"),fr=require("node:url"),Qi=require("ts-morph"),D=require("node:path"),dt=require("ts-json-schema-generator"),Ee=require("pino"),os=require("ajv"),ss=require("ajv-formats"),Ep=require("better-sqlite3"),Sp=require("@adhd/sox-graph-store"),Lt=require("node:os"),au=require("node:crypto"),Op=require("fastify"),Zi=require("node:http"),Np=require("@modelcontextprotocol/sdk/server/index.js"),_p=require("@modelcontextprotocol/sdk/server/stdio.js"),kp=require("@modelcontextprotocol/sdk/server/sse.js"),Ap=require("@modelcontextprotocol/sdk/server/streamableHttp.js"),Xi=require("@modelcontextprotocol/sdk/types.js"),ea=require("yaml");var Se=typeof document<"u"?document.currentScript:null;function Ip(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ho=Ip(D),mo="$apigen";let ta=class extends Error{constructor(t){super(t),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}};function jp(e){const t=new Map;return{register(n,r){if(t.has(n.id)&&!(r!=null&&r.override))throw new ta(`E_DUP_CODEC: a codec is already registered for id "${n.id}"`);t.set(n.id,n)},resolve(n){for(const r of t.values())if(r.matches(n))return r},get(n){return t.get(n)},ids(){return[...t.keys()]},freeze(){const n=new Map(t),r={register(){throw new ta("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(o){for(const s of n.values())if(s.matches(o))return s},get(o){return n.get(o)},ids(){return[...n.keys()]},freeze(){return r}};return r}}}const is="x-apigen-logical",as="x-apigen-codec",go="x-apigen-ctor",yo="x-apigen-tojson",Pp="0.1.0";function na(e,t){return{registry:e,resolve:n=>{throw new Error(`[apigen-logical] $ref "${n}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:"",mode:"strict",...t}}function kt(e,t,n){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return kt(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=cu(e,s,t);return kt(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return Wr(e,t,n);const a=t.items;if(!a)return e.map(u=>pt(u));const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?pt(u):kt(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>kt(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return Wr(e,t,n);const a=t.properties;if(!a)return pt(e);const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=kt(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?Wr(e,t,n):pt(e)}function At(e,t,n){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return At(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=cu(e,s,t);return At(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return e;const a=t.items;if(!a)return e;const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?u:At(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>At(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const a=t.properties;if(!a)return e;const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=At(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?xp(e,n):e}function cu(e,t,n,r){const o=n.discriminator;if(o!=null&&o.propertyName){const s=e!==null&&typeof e=="object"?e[o.propertyName]:void 0;if(typeof s=="string"&&o.mapping){const i=o.mapping[s];if(i){const a=t.find(c=>c.$ref===i);if(a)return a}}}return t[0]??{}}function Wr(e,t,n){for(const r of n.registry.ids()){const o=n.registry.get(r);if(o)try{const s=o.encode(e,o.schema,n);return{[mo]:r,v:s}}catch{}}return pt(e)}function xp(e,t){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&mo in e){const n=e,r=n[mo],o=t.registry.get(r);if(o)return o.decode(n.v,o.schema,t)}return e}function pt(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(pt);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))r!==void 0&&(t[n]=pt(r));return t}return null}function Tp(e){return{encode(t,n,r){const o=na(e,r);return kt(t,n,o)},decode(t,n,r){const o=na(e,r);return At(t,n,o)}}}const cs={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},us={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}},ls={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,t,n){return e},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e)}if(n.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return e}},fs={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,t,n){return Buffer.from(e).toString("base64")},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array(0)}if(n.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},Cp=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,ds={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode==="strict"&&!Cp.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},vo="NaN",$o="Infinity",wo="-Infinity",Rp=new Set([vo,$o,wo]),ps={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,t,n){return Number.isNaN(e)?vo:e===1/0?$o:e===-1/0?wo:e},decode(e,t,n){if(typeof e=="number")return e;if(typeof e=="string"){if(e===vo)return NaN;if(e===$o)return 1/0;if(e===wo)return-1/0;const r=Number(e);if(!Number.isNaN(r))return r}if(n.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...Rp].join(", ")}.`);return NaN}},Mp=[cs,us,ls,fs,ds,ps];function Dp(e,t={}){for(const n of Mp)e.register(n,{override:t.override??!1})}cs.id,us.id,ls.id,fs.id,ds.id,ps.id;const uu=jp();Dp(uu);const lu=Tp(uu.freeze());function fu(e,t){var n;const r=((n=e.input)==null?void 0:n.properties)??{};return t in r}function bo(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data;return Object.keys((r==null?void 0:r.properties)??{})}function Lp(e,t){var n,r,o;const s=(o=(r=(n=e.input)==null?void 0:n.properties)==null?void 0:r.data)==null?void 0:o.properties,i=s==null?void 0:s[t];return i!==void 0?i:void 0}function Bp(e,t){return t===void 0||e===void 0?e:lu.decode(e,t)}function Hr(e,t){const n=t.output;return!n||Object.keys(n).length===0?e:lu.encode(e,n)}async function Up(e,t,n,r,o,s){const i=bo(n).map(c=>Bp(s[c],Lp(n,c)));if(fu(n,"session")&&t){const c=await t({session:o.session}),u=await e[r](c,...i);return Hr(u,n)}if(n.hasCtx){const c=t?await t(o):void 0,u=await e[r](c,...i);return Hr(u,n)}const a=await e[r](...i);return Hr(a,n)}let Fp=class{constructor(){this._map=new Map}set(t,n){this._map.set(t,n)}get(t){return this._map.get(t)}has(t){return this._map.has(t)}};function Vp(e=[]){return async function(t,n,r){const o=r.schemas[t];if(!o)throw new Error(`apigen/invoke: no schema found for operation "${t}"`);const s=()=>Up(r.fns,r.createClient,o,t,n.envelope,n.domainArgs);return e.reduceRight((i,a)=>()=>a(n,i),s)()}}const qp={"decimal.js":"Decimal"};function Kp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(qp).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${Kp(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Gp(e={}){const t=e.level??"info",n=typeof e.destination=="string"&&e.destination.length>0,r=!n&&!!process.stderr.isTTY,o=e.format??(r?"pretty":"json"),s={level:t};if(o==="pretty")return s.transport={target:"pino-pretty",options:{colorize:!n,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...n?{destination:e.destination,mkdir:!0}:{destination:2}}},Ee(s);const i=n?Ee.destination({dest:e.destination,mkdir:!0,sync:!0}):Ee.destination(2);return Ee(s,i)}function du(e){return e?e.type==="array"?`${du(e.items)}[]`:e.enum?"enum":e.$ref?String(e.$ref).split("/").pop()||"object":e.anyOf||e.oneOf?"union":e.type??"object":"unknown"}function zp(e){var t;const n=(t=((e==null?void 0:e.input)??{}).properties)==null?void 0:t.data,r=(n==null?void 0:n.properties)??{},o=new Set((n==null?void 0:n.required)??[]),s=Object.entries(r).map(([a,c])=>({name:a,type:du(c),required:o.has(a)})),i=s.map(a=>`${a.name}${a.required?"":"?"}: ${a.type}`).join(", ");return{params:s,text:i}}let Wp=class extends Error{constructor(t,n,r){super(n),this.name="ApiError",this.code=t,this.details=r,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}};const dr=new os({allErrors:!0});ss(dr);for(const e of[is,as,go,yo,"discriminator"])dr.addKeyword({keyword:e,valid:!0});dr.addFormat("decimal",/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function Hp(e){return e.map(t=>`${t.instancePath||"(root)"} ${t.message??"failed schema check"}`).join("; ")}function Jp(e){return async function(t,n){const r=t.operation.id,o=e[r];if(o===void 0)return n();const s={data:t.domainArgs,...t.envelope},i=dr.compile(o.input);if(!i(s)){const a=i.errors??[];throw new Wp("invalid_argument",`Validation failed: ${Hp(a)}`,a)}return n()}}function Yp(e){return e!==null&&typeof e=="object"&&Symbol.asyncIterator in e}let rt=class extends Error{constructor(t,n){super(n),this.name="UnionCodecError",this.code=t}};function Jr(e){const t=e.discriminator;if(t===null||typeof t!="object"||Array.isArray(t))return;const n=t;if(typeof n.propertyName!="string")return;const r=n.mapping;if(!(r===null||typeof r!="object"||Array.isArray(r)))return{propertyName:n.propertyName,mapping:r}}function pu(e,t){const n=e[as];if(typeof n=="string"){const r=t.registry.get(n);if(r)return r}return t.registry.resolve(e)}function Qp(e,t,n){const r=pu(t,n);return r?r.encode(e,t,n):e}function Zp(e,t,n){const r=pu(t,n);return r?r.decode(e,t,n):e}function Xp(e){const{id:t,schema:n}=e;return{id:t,kind:"union",schema:n,matches(r){if(r[is]==="union")return!0;const o=r.oneOf;return!Array.isArray(o)||o.length===0?!1:Jr(r)!==void 0},encode(r,o,s){const i=Jr(o);if(!i)throw new rt("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:a,mapping:c}=i,u=r[a];if(u==null)throw new rt("E_UNION_NO_DISCRIMINATOR",`[${t}] value at "${s.path}" is missing the discriminator property "${a}".`);const l=String(u),f=c[l];if(!f)throw new rt("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${l}" at "${s.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`);const p=s.resolve(f);return Qp(r,p,{...s,path:`${s.path}[${l}]`})},decode(r,o,s){if(r===null||typeof r!="object"||Array.isArray(r)){let d;throw r===null?d="null":Array.isArray(r)?d="array":d=typeof r,new rt("E_UNION_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${s.path}", got ${d}.`)}const i=r,a=Jr(o);if(!a)throw new rt("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:c,mapping:u}=a,l=i[c];if(l==null)throw new rt("E_UNION_NO_DISCRIMINATOR",`[${t}] wire object at "${s.path}" is missing the discriminator property "${c}".`);const f=String(l),p=u[f];if(!p)throw new rt("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${f}" on the wire at "${s.path}" is not in the mapping (known: ${Object.keys(u).join(", ")}).`);const h=s.resolve(p);return Zp(r,h,{...s,path:`${s.path}[${f}]`})}}}const eh="x-apigen-instances";let _n=class extends Error{constructor(t,n){super(n),this.name="NominalCodecError",this.code=t}};function ra(e){const t=e.properties;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function th(e){const t=e.required;return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}function oa(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n)}return e}function nh(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n)}return e}function rh(e){const{id:t,schema:n,ctor:r}=e;return{id:t,kind:"nominal",schema:n,matches(o){return o[is]==="nominal"?!0:o[as]===t},encode(o,s,i){if(o===null||typeof o!="object")return o;if(i.seen.has(o)){if(i.mode==="strict")throw new _n("E_NOMINAL_CYCLE",`[${t}] cycle detected at "${i.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN §8.3); break the cycle or use 'lossy' mode.`);return null}i.seen.add(o);try{const a=ra(s),c=typeof s[yo]=="string"?s[yo]:"toJSON",u=o[c];if(typeof u=="function"){const d=u.call(o);if(d!==null&&typeof d=="object"&&!Array.isArray(d)){const v={};for(const[m,y]of Object.entries(d))v[m]=oa(y,a[m],{...i,path:`${i.path}/${m}`});return v}return d}const l={},f=Object.keys(a),p=o,h=f.length>0?f:Object.keys(p);for(const d of h){const v=p[d];v!==void 0&&(l[d]=oa(v,a[d],{...i,path:`${i.path}/${d}`}))}return l}finally{i.seen.delete(o)}},decode(o,s,i){if(o===null||typeof o!="object"||Array.isArray(o)){let l;throw o===null?l="null":Array.isArray(o)?l="array":l=typeof o,new _n("E_NOMINAL_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${i.path}", got ${l}.`)}const a=o;for(const l of th(s))if(!(l in a))throw new _n("E_NOMINAL_INVALID_WIRE",`[${t}] required field "${l}" missing on the wire at "${i.path}".`);if(s[eh]===!1)throw new _n("E_NOMINAL_NONRECONSTRUCTABLE",`[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);const c=ra(s),u={};for(const[l,f]of Object.entries(a))u[l]=nh(f,c[l],{...i,path:`${i.path}/${l}`});if(r){const l=typeof s[go]=="string"?s[go]:"fromJSON",f=r[l];if(typeof f=="function")return f.call(r,u);const p=r;return new p(u)}return u}}}const oh=[cs,us,ls,fs,ds,ps],sh={type:"object","x-apigen-logical":"nominal","x-apigen-codec":"ts.NominalSentinel"},sa=rh({id:"ts.NominalSentinel",schema:sh}),ih={oneOf:[],discriminator:{propertyName:"kind",mapping:{}},"x-apigen-logical":"union","x-apigen-codec":"ts.UnionSentinel"},ia=Xp({id:"ts.UnionSentinel",schema:ih});function ah(){const e=[...oh.map(t=>[t.id,t]),[sa.id,sa],[ia.id,ia]];return Object.freeze(new Map(e))}Object.freeze({host:"ts",logicalTypeVersion:Pp,codecs:ah()});const aa=new Set(["string","number","boolean","integer"]);function ch(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?aa.has(n):Array.isArray(n)?n.every(r=>aa.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function uh(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(ch)}const lh={"decimal.js":"Decimal"};function fh(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(lh).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${fh(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function ca(e){return e.words.join("-")}function ua(e){return e.words.map(gh).join("")}function la(e){return e.words.join("_")}function dh(e,t={}){var n,r;const o=[e.namespace,...e.path],s=e.safe||uh(e.input)?"GET":"POST",i=((r=(n=t.http)==null?void 0:n.verb)==null?void 0:r[e.id])??s,a="/"+o.map(h=>ca(h)).join("/"),c=o.map(h=>la(h)).join("_"),u=o.map(h=>la(h)).slice(0,-1).join("."),l=ua(o[o.length-2]??o[0]),f=ua(o[o.length-1]),p=o.map(h=>ca(h));return{http:{verb:i,route:a},mcp:{name:c},grpc:{package:u,service:l,method:f},cli:{path:p}}}function ph(e,t){return`x-${e}-${t}`}function hh(e,t){return`--${e}-${t}`}function mh(e,t){const n=r=>r.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function gh(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function hu(e){return e.anyOf??e.oneOf}function yh(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=hu(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="array"||r.type==="object")}return!1}function vh(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=hu(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="boolean")}return!1}function $h(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function wh(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data,o=(r==null?void 0:r.properties)??{},s=(r==null?void 0:r.required)??[];return{props:o,required:s}}function fa(e){return typeof e.handler=="function"}function bh(e){var t;const n=((t=e.input)==null?void 0:t.properties)??{},r=e["x-apigen-envelope"],o=[];for(const s of Object.keys(n)){if(s==="data")continue;const i=(r==null?void 0:r[s])??"adhd",a=ph(i,s);o.push({field:s,pluginId:i,httpHeader:a,mcpMetaKey:a,cliFlag:hh(i,s),envVar:mh(i,s)})}return o}function Eh(e,t){const n=new Map,{props:r}=wh(e);for(const[o,s]of Object.entries(r)){let i="string";vh(s)?i="boolean":yh(s)&&(i="json"),n.set($h(o),{camelKey:o,kind:"domain",valueKind:i})}for(const o of t){const s=o.cliFlag.replace(/^--/,"");n.set(s,{camelKey:o.field,kind:"envelope",valueKind:"string",envVar:o.envVar})}return n}function mu(e){const{op:t,schema:n,transport:r,projection:o}=e,s=dh(t,o),i=n?bh(n):[],a=n?Eh(n,i):new Map,c=n?zp(n).params:void 0,u={op:t,transport:r,http:s.http,mcp:s.mcp,cli:s.cli,grpc:s.grpc,params:c,envelope:i,cliFlags:a,streaming:t.streaming,isMount:fa(t)};if(fa(t)){const l=t.handler;u.mountHandler=async f=>l(f)}return u}function Sh(e){const t=e.usePlugins;return Array.isArray(t)?t:[]}function Oh(e){const t=e.useOptions;return t&&typeof t=="object"?t:{}}function Nh(e){return async function(t,n){const r=Object.assign(t,{data:t.domainArgs});return await e.layer(r,n)}}function da(e,t){var n;const r=[];for(const o of t){const s=(n=o.capabilities)==null?void 0:n.layer;s&&r.push(Nh(s))}return r.push(Jp(e)),Vp(r)}function _h(){const e=new Map;return{get:t=>e.get(t),set:(t,n)=>{e.set(t,n)}}}const kh={input:{type:"object",properties:{data:{type:"object",properties:{}}}},output:{}};async function pa(e,t,n,r){const o={...n,operation:{id:e.op.id},ctx:new Fp};if(e.isMount){const s=e.mountHandler;if(!s)throw new Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);const i={operation:e.op,data:n.domainArgs,envelope:n.envelope,ctx:_h(),transport:e.transport,signal:n.signal??new AbortController().signal},a={...r,fns:{[e.op.id]:()=>s(i)},schemas:{[e.op.id]:kh}};return t(e.op.id,o,a)}return t(e.op.id,o,r)}const Ah={"decimal.js":"Decimal"};function Ih(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(Ah).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${Ih(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function jh(e,t){return`--${e}-${t}`}function Ph(e,t){const n=r=>r.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function ha(e){let t=e.replace(/[^a-zA-Z0-9_$]/g,"_");return(t===""||/^[0-9]/.test(t))&&(t=`_${t}`),t}const xh=["invalid_argument","unauthenticated","permission_denied","not_found","internal"],ma={invalid_argument:2,unauthenticated:3,permission_denied:3,not_found:4,internal:1};let tr=class extends Error{constructor(t,n,r){super(n),this.name="ApiError",this.code=t,this.details=r,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}};function ga(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&xh.includes(e.code)&&typeof e.toJSON=="function"}function gu(e){return e.anyOf??e.oneOf}function Th(e){var t;const n=((t=e.input)==null?void 0:t.properties)??{},r=e["x-apigen-envelope"],o=[];for(const s of Object.keys(n)){if(s==="data")continue;const i=(r==null?void 0:r[s])??"adhd";o.push({field:s,pluginId:i,flag:jh(i,s),envVar:Ph(i,s)})}return o}function ya(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=gu(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="array"||r.type==="object")}return!1}function Ch(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=gu(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="boolean")}return!1}function va(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data,o=(r==null?void 0:r.properties)??{},s=(r==null?void 0:r.required)??[];return{props:o,required:s}}function Rh(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Mh(e,t){if(!ho.isAbsolute(t))return t;const n=ho.relative(e,t);return!n.startsWith(".")&&!n.startsWith("/")?`./${n}`:n}const Dh=["function __apigenParseJsonArg(flag: string, raw: unknown): unknown {"," if (raw === undefined) return undefined"," if (typeof raw !== 'string') return raw"," try {"," return JSON.parse(raw)"," } catch (err) {"," throw new Error(`Invalid JSON for --${flag}: ${(err as Error).message}`)"," }","}"].join(`
3
+ `);function Lh(e){var t;const n=e.options.name??"cli",r=e.options.version??"0.1.0",o=e.packages.some(i=>Object.values(i.schemas).some(a=>{const{props:c}=va(a);return bo(a).some(u=>ya(c[u]))})),s=["#!/usr/bin/env node","// Auto-generated by @adhd/apigen-cli — do not edit","import { Command } from 'commander'","import { dispatch, buildFnTable } from '@adhd/apigen-engine-runtime'"];for(const i of e.packages){const a=ha(i.id),c=Mh(e.outputDir,i.importPath);s.push(`import * as ${a}_ns from '${c}'`),s.push(`const ${a}_fns = buildFnTable(${a}_ns as Record<string, unknown>)`)}s.push(""),o&&(s.push(Dh),s.push("")),s.push(`const schemas: Record<string, unknown> = ${JSON.stringify(Object.fromEntries(e.packages.flatMap(i=>Object.entries(i.schemas).map(([a,c])=>[`${i.id}:${a}`,c]))),null,2)}`),s.push(""),s.push(`const program = new Command().name('${n}').version('${r}')`),s.push("");for(const i of e.packages){const a=ha(i.id);for(const[c,u]of Object.entries(i.schemas)){const l=bo(u),f=fu(u,"session"),p=Th(u),{props:h,required:d}=va(u);s.push("program"),s.push(` .command('${c}')`);for(const m of p){const y=m.flag.replace(/^--/,"");s.push(` .option('${m.flag} <${y}>', '${m.field} (env: ${m.envVar})')`)}f&&!p.some(m=>m.field==="session")&&s.push(" .option('--session <key>', 'Session key')");const v=Rh;for(const m of l){const y=v(m),$=Ch(h[m]),S=d.includes(m);$?(s.push(` .option('--${y}')`),((t=h[m])==null?void 0:t.default)===!0&&s.push(` .option('--no-${y}')`)):S?s.push(` .requiredOption('--${y} <${y}>')`):s.push(` .option('--${y} <${y}>')`)}if(s.push(" .action(async (opts: Record<string, unknown>) => {"),s.push(` const domainArgs: Record<string, unknown> = { ${l.map(m=>ya(h[m])?`'${m}': __apigenParseJsonArg('${v(m)}', opts['${m}'])`:`'${m}': opts['${m}']`).join(", ")} }`),p.length>0){const m=p.map(y=>{const $=y.flag.replace(/^--/,"").replace(/-([a-z])/g,(S,b)=>b.toUpperCase());return`'${y.field}': opts['${$}'] ?? process.env['${y.envVar}']`});s.push(` const envelope: Record<string, unknown> = { ${m.join(", ")} }`)}else f?s.push(" const envelope: Record<string, unknown> = { session: opts['session'] }"):s.push(" const envelope: Record<string, unknown> = {}");s.push(` const result = await dispatch(${a}_fns as any, undefined, schemas['${i.id}:${c}'] as any, '${c}', envelope, domainArgs)`),s.push(" console.log(JSON.stringify(result))"),s.push(" })")}}return s.push(""),s.push("program.parseAsync()"),{files:[{path:"cli.ts",content:s.join(`
4
+ `)}]}}function Bh(e){const t=[],n=/"([^"]*)"|'([^']*)'|(\S+)/g;let r;for(;r=n.exec(e);)t.push(r[1]??r[2]??r[3]);return t}function Uh(e){const t=e.argv;return Array.isArray(t)?t.map(String):typeof t=="string"?Bh(t):process.argv.slice(2)}function Fh(e,t){return{id:e,host:"ts",namespace:{raw:e,words:[e]},path:[],kind:"action",async:!1,streaming:!1,safe:t["x-apigen-safe"]??!1,input:t.input??{},output:t.output??{},envelope:{},typeText:null}}function Vh(e){const t=new Map;for(const r of e.operations??[]){const o=r.path[r.path.length-1];o&&t.set(`${r.namespace.raw}:${o.raw}`,r)}const n=new Map;for(const r of e.packages)for(const[o,s]of Object.entries(r.schemas)){const i=t.get(`${r.id}:${o}`)??Fh(o,s),a=mu({op:i,schema:s,transport:"cli"}),c=a.cli.path;n.set(c.join(" "),{pkgId:r.id,fnName:o,schema:s,cliPath:c,plan:a})}return n}function qh(e,t){let n=0;for(;n<e.length&&!e[n].startsWith("-");)n++;for(let r=n;r>=1;r--){const o=t.get(e.slice(0,r).join(" "));if(o)return{entry:o,rest:e.slice(r)}}return null}function yu(e){return!e||e.length===0?"":e.map(t=>`${t.name}${t.required?"":"?"}: ${t.type}`).join(", ")}function $a(e){const t=["Available commands:",""],n=[...e.entries()].sort(([r],[o])=>r.localeCompare(o));for(const[r,{plan:o}]of n){const s=yu(o.params);t.push(` ${r}${s?` { ${s} }`:""}`)}return t.join(`
5
+ `)}function kn(e){return new tr("invalid_argument",e)}function Kh(e,t){var n;const r={},o={};let s=0;for(;s<e.length;){const i=e[s];if(!i.startsWith("--"))throw kn(`Unexpected positional argument: "${i}"`);let a=i.slice(2),c;const u=a.indexOf("=");u!==-1&&(c=a.slice(u+1),a=a.slice(0,u));let l=!1,f=a;a.startsWith("no-")&&((n=t.get(a.slice(3)))==null?void 0:n.valueKind)==="boolean"&&(l=!0,f=a.slice(3));const p=t.get(f);if(!p)throw kn(`Unknown option: --${a}. Available: ${[...t.keys()].sort().map(d=>`--${d}`).join(", ")}`);s++;let h;if(p.valueKind==="boolean")l?h=!1:c===void 0?h=!0:h=c!=="false";else{const d=c!==void 0?c:e[s++];if(d===void 0)throw kn(`Missing value for --${a}`);if(p.valueKind==="json")try{h=JSON.parse(d)}catch(v){throw kn(`Invalid JSON for --${a}: ${v.message}`)}else h=d}p.kind==="domain"?r[p.camelKey]=h:o[p.camelKey]=h}for(const i of t.values()){if(i.kind!=="envelope"||!i.envVar||o[i.camelKey]!==void 0)continue;const a=process.env[i.envVar];a!==void 0&&(o[i.camelKey]=a)}return{domainArgs:r,envelope:o}}function vu(e){const t=ga(e)?e.toJSON():{code:"internal",message:e instanceof Error?e.message:String(e)};console.error(JSON.stringify(t)),process.exitCode=ga(e)?ma[e.code]:ma.internal}let Gh=class{constructor(t){this.signal=t,this.routes=new Map}registerRoute(t,n){this.routes.set(t.cli.path.join(" "),{plan:t,dispatch:n})}routeTable(){return this.routes}readCall(t,n){const{domainArgs:r,envelope:o}=Kh(t.rest,n.cliFlags);return{domainArgs:r,envelope:o,signal:this.signal}}writeResult(t,n,r){if(Yp(n))throw new tr("invalid_argument",`Command "${r.cli.path.join(" ")}" produced a streaming result, which is not supported over the cli transport.`);console.log(JSON.stringify(n===void 0?null:n))}writeError(t,n,r){vu(n)}};function zh(e,t,n,r){var o;const s=[],i={host:n,operations:r};for(const a of e){const c=(o=a.capabilities)==null?void 0:o.mount;if(!c)continue;const u=c.operations(i,t[a.id]);for(const l of u)l.transports&&!l.transports.includes("cli")||s.push(l)}return s}async function Wh(e){var t,n;const r=e.logger??Gp();if((t=e.signal)!=null&&t.aborted){r.info("cli run: signal already aborted before dispatch — skipping");return}let o=Uh(e.options);o[0]==="--"&&(o=o.slice(1));const s=Sh(e.options),i=Oh(e.options),a=new Gh(e.signal),c=Vh(e),u=new Map;for(const b of c.values()){const N=u.get(b.pkgId);N?N.push(b):u.set(b.pkgId,[b])}for(const b of e.packages){const N=u.get(b.id);if(!N||N.length===0)continue;if(!b.fns)throw new Error(`apigen-plugin-cli-output: package "${b.id}" has no functions`);const j=b.fns,M={},H={};for(const fe of N)M[fe.plan.op.id]=fe.schema,H[fe.plan.op.id]=j[fe.fnName];const Z=da(M,s),le={fns:H,createClient:b.createClient,schemas:M};for(const fe of N)a.registerRoute(fe.plan,ye=>pa(fe.plan,Z,ye,le))}const l=((n=e.packages[0])==null?void 0:n.id)??"ts",f=zh(s,i,l,e.operations??[]);if(f.length>0){const b=da({},s),N={fns:{},schemas:{}};for(const j of f){const M=mu({op:j,transport:"cli"});a.registerRoute(M,H=>pa(M,b,H,N))}}const p=a.routeTable();if(o.length===0||o[0]==="--help"||o[0]==="-h"){console.log($a(p));return}const h=qh(o,p);if(!h){vu(new tr("not_found",`Unknown command: ${o.join(" ")}
6
+
7
+ ${$a(p)}`));return}const{entry:d,rest:v}=h,{plan:m,dispatch:y}=d,$=m.cli.path.join(" ");if(v.includes("--help")||v.includes("-h")){const b=yu(m.params);console.log(`${$}${b?` { ${b} }`:""}`);return}const S={rest:v};try{if(m.streaming)throw new tr("invalid_argument",`Command "${$}" is a streaming operation and is not supported over the cli transport (DEBT-APIGEN-SERVE-CORE-002 cli half).`);const b=await a.readCall(S,m),N=Date.now(),j=await y(b);await a.writeResult(S,j,m),r.info({command:$,ms:Date.now()-N},`→ ${$}`)}catch(b){r.error({command:$,err:b},`✗ ${$}`),await a.writeError(S,b,m)}}const Hh={id:"cli",description:"Emit a Commander CLI program where each exported function becomes a subcommand",language:"ts",optionsSchema:{type:"object",properties:{name:{type:"string",default:"cli"},version:{type:"string",default:"0.1.0"},argv:{anyOf:[{type:"array",items:{type:"string"}},{type:"string"}]}}},generate(e){return Lh(e)},run(e){return Wh(e)}},wa=new Set(["string","number","boolean","integer"]);function Jh(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?wa.has(n):Array.isArray(n)?n.every(r=>wa.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function Yh(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(Jh)}const Qh={"decimal.js":"Decimal"};function Zh(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(Qh).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${Zh(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function ba(e){return e.words.join("-")}function Ea(e){return e.words.map(em).join("")}function Sa(e){return e.words.join("_")}function Xh(e,t={}){var n,r;const o=[e.namespace,...e.path],s=e.safe||Yh(e.input)?"GET":"POST",i=((r=(n=t.http)==null?void 0:n.verb)==null?void 0:r[e.id])??s,a="/"+o.map(h=>ba(h)).join("/"),c=o.map(h=>Sa(h)).join("_"),u=o.map(h=>Sa(h)).slice(0,-1).join("."),l=Ea(o[o.length-2]??o[0]),f=Ea(o[o.length-1]),p=o.map(h=>ba(h));return{http:{verb:i,route:a},mcp:{name:c},grpc:{package:u,service:l,method:f},cli:{path:p}}}function em(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function hs(e,t=5e3){e!==":memory:"&&K.mkdirSync(D.dirname(e),{recursive:!0});const n=new Ep(e);if(n.pragma("journal_mode = WAL"),!Number.isInteger(t)||t<0)throw new RangeError(`openGraphBacklogStore: busyTimeoutMs must be a non-negative integer, got ${t}`);const r=Sp.createGraphBackend(n);return r.applySchema(),n.pragma(`busy_timeout = ${t}`),{db:n,graph:r}}function ms(e){e.db.close()}const tm=[".git",".adhd","adhd.environment.yaml"];function Yr(e){let t=D.resolve(e);const{root:n}=D.parse(t);for(;;){for(const o of tm)if(K.existsSync(`${t}/${o}`))return t;if(t===n)return;const r=D.dirname(t);if(r===t)return;t=r}}const nm=new Set(["system","global","project"]);function rm(e,t){const n=e.cwd??process.cwd();if(e.scope)return e.scope==="project"?{scope:"project",projectRoot:Yr(n)??n}:{scope:e.scope};const r=t.ADHD_ENV_SCOPE;if(r!==void 0&&nm.has(r)){const s=r;return s==="project"?{scope:"project",projectRoot:Yr(n)??n}:{scope:s}}const o=Yr(n);return o?{scope:"project",projectRoot:o}:{scope:"global"}}function Oa(e){return`.${e}`}function om(e){const t=Lt.homedir();if(process.platform==="darwin")return D.join(t,"Library","Application Support",e);if(process.platform==="win32"){const r=process.env.APPDATA??D.join(t,"AppData","Roaming");return D.join(r,e)}const n=process.env.XDG_DATA_HOME??D.join(t,".local","share");return D.join(n,e)}function sm(e){const t=e.orgNamespace,n=e.adhdRoot??D.join(Lt.homedir(),Oa(t)),r=e.adhdRoot??om(t),o={system:D.join(r,e.project,e.namespace),global:D.join(n,e.project,e.namespace)};return e.projectRoot&&(o.project=D.join(e.projectRoot,Oa(t),e.project,e.namespace)),o}function $u(e,t){return t==="project"?e.project??e.global:e[t]}function im(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function am(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}),n}const ee={ANCHOR:"&",COMMENT:"#",TAG:"!",DIRECTIVES_END:"-",DOCUMENT_END:"."},k={ALIAS:"ALIAS",BLANK_LINE:"BLANK_LINE",BLOCK_FOLDED:"BLOCK_FOLDED",BLOCK_LITERAL:"BLOCK_LITERAL",COMMENT:"COMMENT",DIRECTIVE:"DIRECTIVE",DOCUMENT:"DOCUMENT",FLOW_MAP:"FLOW_MAP",FLOW_SEQ:"FLOW_SEQ",MAP:"MAP",MAP_KEY:"MAP_KEY",MAP_VALUE:"MAP_VALUE",PLAIN:"PLAIN",QUOTE_DOUBLE:"QUOTE_DOUBLE",QUOTE_SINGLE:"QUOTE_SINGLE",SEQ:"SEQ",SEQ_ITEM:"SEQ_ITEM"},Vn="tag:yaml.org,2002:",Ye={MAP:"tag:yaml.org,2002:map",SEQ:"tag:yaml.org,2002:seq",STR:"tag:yaml.org,2002:str"};function Na(e){const t=[0];let n=e.indexOf(`
8
+ `);for(;n!==-1;)n+=1,t.push(n),n=e.indexOf(`
9
+ `,n);return t}function wu(e){let t,n;return typeof e=="string"?(t=Na(e),n=e):(Array.isArray(e)&&(e=e[0]),e&&e.context&&(e.lineStarts||(e.lineStarts=Na(e.context.src)),t=e.lineStarts,n=e.context.src)),{lineStarts:t,src:n}}function Eo(e,t){if(typeof e!="number"||e<0)return null;const{lineStarts:n,src:r}=wu(t);if(!n||!r||e>r.length)return null;for(let s=0;s<n.length;++s){const i=n[s];if(e<i)return{line:s,col:e-n[s-1]+1};if(e===i)return{line:s+1,col:1}}const o=n.length;return{line:o,col:e-n[o-1]+1}}function cm(e,t){const{lineStarts:n,src:r}=wu(t);if(!n||!(e>=1)||e>n.length)return null;const o=n[e-1];let s=n[e];for(;s&&s>o&&r[s-1]===`
10
+ `;)--s;return r.slice(o,s)}function um({start:e,end:t},n,r=80){let o=cm(e.line,n);if(!o)return null;let{col:s}=e;if(o.length>r)if(s<=r-10)o=o.substr(0,r-1)+"…";else{const l=Math.round(r/2);o.length>s+l&&(o=o.substr(0,s+l-1)+"…"),s-=o.length-r,o="…"+o.substr(1-r)}let i=1,a="";t&&(t.line===e.line&&s+(t.col-e.col)<=r+1?i=t.col-e.col:(i=Math.min(o.length+1,r)-s,a="…"));const c=s>1?" ".repeat(s-1):"",u="^".repeat(i);return`${o}
11
+ ${c}${u}${a}`}let Q=class bu{static copy(t){return new bu(t.start,t.end)}constructor(t,n){this.start=t,this.end=n||t}isEmpty(){return typeof this.start!="number"||!this.end||this.end<=this.start}setOrigRange(t,n){const{start:r,end:o}=this;if(t.length===0||o<=t[0])return this.origStart=r,this.origEnd=o,n;let s=n;for(;s<t.length&&!(t[s]>r);)++s;this.origStart=r+s;const i=s;for(;s<t.length&&!(t[s]>=o);)++s;return this.origEnd=o+s,i}},I=class Me{static addStringTerminator(t,n,r){if(r[r.length-1]===`
12
+ `)return r;const o=Me.endOfWhiteSpace(t,n);return o>=t.length||t[o]===`
13
+ `?r+`
14
+ `:r}static atDocumentBoundary(t,n,r){const o=t[n];if(!o)return!0;const s=t[n-1];if(s&&s!==`
15
+ `)return!1;if(r){if(o!==r)return!1}else if(o!==ee.DIRECTIVES_END&&o!==ee.DOCUMENT_END)return!1;const i=t[n+1],a=t[n+2];if(i!==o||a!==o)return!1;const c=t[n+3];return!c||c===`
16
+ `||c===" "||c===" "}static endOfIdentifier(t,n){let r=t[n];const o=r==="<",s=o?[`
17
+ `," "," ",">"]:[`
18
+ `," "," ","[","]","{","}",","];for(;r&&s.indexOf(r)===-1;)r=t[n+=1];return o&&r===">"&&(n+=1),n}static endOfIndent(t,n){let r=t[n];for(;r===" ";)r=t[n+=1];return n}static endOfLine(t,n){let r=t[n];for(;r&&r!==`
19
+ `;)r=t[n+=1];return n}static endOfWhiteSpace(t,n){let r=t[n];for(;r===" "||r===" ";)r=t[n+=1];return n}static startOfLine(t,n){let r=t[n-1];if(r===`
20
+ `)return n;for(;r&&r!==`
21
+ `;)r=t[n-=1];return n+1}static endOfBlockIndent(t,n,r){const o=Me.endOfIndent(t,r);if(o>r+n)return o;{const s=Me.endOfWhiteSpace(t,o),i=t[s];if(!i||i===`
22
+ `)return s}return null}static atBlank(t,n,r){const o=t[n];return o===`
23
+ `||o===" "||o===" "||r&&!o}static nextNodeIsIndented(t,n,r){return!t||n<0?!1:n>0?!0:r&&t==="-"}static normalizeOffset(t,n){const r=t[n];return r?r!==`
24
+ `&&t[n-1]===`
25
+ `?n-1:Me.endOfWhiteSpace(t,n):n}static foldNewline(t,n,r){let o=0,s=!1,i="",a=t[n+1];for(;a===" "||a===" "||a===`
26
+ `;){switch(a){case`
27
+ `:o=0,n+=1,i+=`
28
+ `;break;case" ":o<=r&&(s=!0),n=Me.endOfWhiteSpace(t,n+2)-1;break;case" ":o+=1,n+=1;break}a=t[n+1]}return i||(i=" "),a&&o<=r&&(s=!0),{fold:i,offset:n,error:s}}constructor(t,n,r){Object.defineProperty(this,"context",{value:r||null,writable:!0}),this.error=null,this.range=null,this.valueRange=null,this.props=n||[],this.type=t,this.value=null}getPropValue(t,n,r){if(!this.context)return null;const{src:o}=this.context,s=this.props[t];return s&&o[s.start]===n?o.slice(s.start+(r?1:0),s.end):null}get anchor(){for(let t=0;t<this.props.length;++t){const n=this.getPropValue(t,ee.ANCHOR,!0);if(n!=null)return n}return null}get comment(){const t=[];for(let n=0;n<this.props.length;++n){const r=this.getPropValue(n,ee.COMMENT,!0);r!=null&&t.push(r)}return t.length>0?t.join(`
29
+ `):null}commentHasRequiredWhitespace(t){const{src:n}=this.context;if(this.header&&t===this.header.end||!this.valueRange)return!1;const{end:r}=this.valueRange;return t!==r||Me.atBlank(n,r-1)}get hasComment(){if(this.context){const{src:t}=this.context;for(let n=0;n<this.props.length;++n)if(t[this.props[n].start]===ee.COMMENT)return!0}return!1}get hasProps(){if(this.context){const{src:t}=this.context;for(let n=0;n<this.props.length;++n)if(t[this.props[n].start]!==ee.COMMENT)return!0}return!1}get includesTrailingLines(){return!1}get jsonLike(){return[k.FLOW_MAP,k.FLOW_SEQ,k.QUOTE_DOUBLE,k.QUOTE_SINGLE].indexOf(this.type)!==-1}get rangeAsLinePos(){if(!this.range||!this.context)return;const t=Eo(this.range.start,this.context.root);if(!t)return;const n=Eo(this.range.end,this.context.root);return{start:t,end:n}}get rawValue(){if(!this.valueRange||!this.context)return null;const{start:t,end:n}=this.valueRange;return this.context.src.slice(t,n)}get tag(){for(let t=0;t<this.props.length;++t){const n=this.getPropValue(t,ee.TAG,!1);if(n!=null){if(n[1]==="<")return{verbatim:n.slice(2,-1)};{const[r,o,s]=n.match(/^(.*!)([^!]*)$/);return{handle:o,suffix:s}}}}return null}get valueRangeContainsNewline(){if(!this.valueRange||!this.context)return!1;const{start:t,end:n}=this.valueRange,{src:r}=this.context;for(let o=t;o<n;++o)if(r[o]===`
30
+ `)return!0;return!1}parseComment(t){const{src:n}=this.context;if(n[t]===ee.COMMENT){const r=Me.endOfLine(n,t+1),o=new Q(t,r);return this.props.push(o),r}return t}setOrigRanges(t,n){return this.range&&(n=this.range.setOrigRange(t,n)),this.valueRange&&this.valueRange.setOrigRange(t,n),this.props.forEach(r=>r.setOrigRange(t,n)),n}toString(){const{context:{src:t},range:n,value:r}=this;if(r!=null)return r;const o=t.slice(n.start,n.end);return Me.addStringTerminator(t,n.end,o)}},vt=class extends Error{constructor(t,n,r){if(!r||!(n instanceof I))throw new Error(`Invalid arguments for new ${t}`);super(),this.name=t,this.message=r,this.source=n}makePretty(){if(!this.source)return;this.nodeType=this.source.type;const t=this.source.context&&this.source.context.root;if(typeof this.offset=="number"){this.range=new Q(this.offset,this.offset+1);const n=t&&Eo(this.offset,t);if(n){const r={line:n.line,col:n.col+1};this.linePos={start:n,end:r}}delete this.offset}else this.range=this.source.range,this.linePos=this.source.rangeAsLinePos;if(this.linePos){const{line:n,col:r}=this.linePos.start;this.message+=` at line ${n}, column ${r}`;const o=t&&um(this.linePos,t);o&&(this.message+=`:
31
+
32
+ ${o}
33
+ `)}delete this.source}},dn=class extends vt{constructor(t,n){super("YAMLReferenceError",t,n)}},B=class extends vt{constructor(t,n){super("YAMLSemanticError",t,n)}},ae=class extends vt{constructor(t,n){super("YAMLSyntaxError",t,n)}},qt=class extends vt{constructor(t,n){super("YAMLWarning",t,n)}};function ue(e,t,n){return(t=fm(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function lm(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function fm(e){var t=lm(e,"string");return typeof t=="symbol"?t:t+""}let Eu=class So extends I{static endOfLine(t,n,r){let o=t[n],s=n;for(;o&&o!==`
34
+ `&&!(r&&(o==="["||o==="]"||o==="{"||o==="}"||o===","));){const i=t[s+1];if(o===":"&&(!i||i===`
35
+ `||i===" "||i===" "||r&&i===",")||(o===" "||o===" ")&&i==="#")break;s+=1,o=i}return s}get strValue(){if(!this.valueRange||!this.context)return null;let{start:t,end:n}=this.valueRange;const{src:r}=this.context;let o=r[n-1];for(;t<n&&(o===`
36
+ `||o===" "||o===" ");)o=r[--n-1];let s="";for(let a=t;a<n;++a){const c=r[a];if(c===`
37
+ `){const{fold:u,offset:l}=I.foldNewline(r,a,-1);s+=u,a=l}else if(c===" "||c===" "){const u=a;let l=r[a+1];for(;a<n&&(l===" "||l===" ");)a+=1,l=r[a+1];l!==`
38
+ `&&(s+=a>u?r.slice(u,a+1):c)}else s+=c}const i=r[t];switch(i){case" ":{const a="Plain value cannot start with a tab character";return{errors:[new B(this,a)],str:s}}case"@":case"`":{const a=`Plain value cannot start with reserved character ${i}`;return{errors:[new B(this,a)],str:s}}default:return s}}parseBlockValue(t){const{indent:n,inFlow:r,src:o}=this.context;let s=t,i=t;for(let a=o[s];a===`
39
+ `&&!I.atDocumentBoundary(o,s+1);a=o[s]){const c=I.endOfBlockIndent(o,n,s+1);if(c===null||o[c]==="#")break;o[c]===`
40
+ `?s=c:(i=So.endOfLine(o,c,r),s=i)}return this.valueRange.isEmpty()&&(this.valueRange.start=t),this.valueRange.end=i,i}parse(t,n){this.context=t;const{inFlow:r,src:o}=t;let s=n;const i=o[s];return i&&i!=="#"&&i!==`
41
+ `&&(s=So.endOfLine(o,n,r)),this.valueRange=new Q(n,s),s=I.endOfWhiteSpace(o,s),s=this.parseComment(s),(!this.hasComment||this.valueRange.isEmpty())&&(s=this.parseBlockValue(s)),s}},pn=class extends I{constructor(){super(k.BLANK_LINE)}get includesTrailingLines(){return!0}parse(t,n){return this.context=t,this.range=new Q(n,n+1),n+1}};class gs extends I{constructor(t,n){super(t,n),this.node=null}get includesTrailingLines(){return!!this.node&&this.node.includesTrailingLines}parse(t,n){this.context=t;const{parseNode:r,src:o}=t;let{atLineStart:s,lineStart:i}=t;!s&&this.type===k.SEQ_ITEM&&(this.error=new B(this,"Sequence items must not have preceding content on the same line"));const a=s?n-i:t.indent;let c=I.endOfWhiteSpace(o,n+1),u=o[c];const l=u==="#",f=[];let p=null;for(;u===`
42
+ `||u==="#";){if(u==="#"){const d=I.endOfLine(o,c+1);f.push(new Q(c,d)),c=d}else{s=!0,i=c+1;const d=I.endOfWhiteSpace(o,i);o[d]===`
43
+ `&&f.length===0&&(p=new pn,i=p.parse({src:o},i)),c=I.endOfIndent(o,i)}u=o[c]}if(I.nextNodeIsIndented(u,c-(i+a),this.type!==k.SEQ_ITEM)?this.node=r({atLineStart:s,inCollection:!1,indent:a,lineStart:i,parent:this},c):u&&i>n+1&&(c=i-1),this.node){if(p){const d=t.parent.items||t.parent.contents;d&&d.push(p)}f.length&&Array.prototype.push.apply(this.props,f),c=this.node.range.end}else if(l){const d=f[0];this.props.push(d),c=d.end}else c=I.endOfLine(o,n+1);const h=this.node?this.node.valueRange.end:c;return this.valueRange=new Q(n,h),c}setOrigRanges(t,n){return n=super.setOrigRanges(t,n),this.node?this.node.setOrigRanges(t,n):n}toString(){const{context:{src:t},node:n,range:r,value:o}=this;if(o!=null)return o;const s=n?t.slice(r.start,n.range.start)+String(n):t.slice(r.start,r.end);return I.addStringTerminator(t,r.end,s)}}class rn extends I{constructor(){super(k.COMMENT)}parse(t,n){this.context=t;const r=this.parseComment(n);return this.range=new Q(n,r),r}}function Oo(e){let t=e;for(;t instanceof gs;)t=t.node;if(!(t instanceof Su))return null;const n=t.items.length;let r=-1;for(let i=n-1;i>=0;--i){const a=t.items[i];if(a.type===k.COMMENT){const{indent:c,lineStart:u}=a.context;if(c>0&&a.range.start>=u+c)break;r=i}else if(a.type===k.BLANK_LINE)r=i;else break}if(r===-1)return null;const o=t.items.splice(r,n-r),s=o[0].range.start;for(;t.range.end=s,t.valueRange&&t.valueRange.end>s&&(t.valueRange.end=s),t!==e;)t=t.context.parent;return o}let Su=class No extends I{static nextContentHasIndent(t,n,r){const o=I.endOfLine(t,n)+1;n=I.endOfWhiteSpace(t,o);const s=t[n];return s?n>=o+r?!0:s!=="#"&&s!==`
44
+ `?!1:No.nextContentHasIndent(t,n,r):!1}constructor(t){super(t.type===k.SEQ_ITEM?k.SEQ:k.MAP);for(let r=t.props.length-1;r>=0;--r)if(t.props[r].start<t.context.lineStart){this.props=t.props.slice(0,r+1),t.props=t.props.slice(r+1);const o=t.props[0]||t.valueRange;t.range.start=o.start;break}this.items=[t];const n=Oo(t);n&&Array.prototype.push.apply(this.items,n)}get includesTrailingLines(){return this.items.length>0}parse(t,n){this.context=t;const{parseNode:r,src:o}=t;let s=I.startOfLine(o,n);const i=this.items[0];i.context.parent=this,this.valueRange=Q.copy(i.valueRange);const a=i.range.start-i.context.lineStart;let c=n;c=I.normalizeOffset(o,c);let u=o[c],l=I.endOfWhiteSpace(o,s)===c,f=!1;for(;u;){for(;u===`
45
+ `||u==="#";){if(l&&u===`
46
+ `&&!f){const d=new pn;if(c=d.parse({src:o},c),this.valueRange.end=c,c>=o.length){u=null;break}this.items.push(d),c-=1}else if(u==="#"){if(c<s+a&&!No.nextContentHasIndent(o,c,a))return c;const d=new rn;if(c=d.parse({indent:a,lineStart:s,src:o},c),this.items.push(d),this.valueRange.end=c,c>=o.length){u=null;break}}if(s=c+1,c=I.endOfIndent(o,s),I.atBlank(o,c)){const d=I.endOfWhiteSpace(o,c),v=o[d];(!v||v===`
47
+ `||v==="#")&&(c=d)}u=o[c],l=!0}if(!u)break;if(c!==s+a&&(l||u!==":")){if(c<s+a){s>n&&(c=s);break}else if(!this.error){const d="All collection items must start at the same column";this.error=new ae(this,d)}}if(i.type===k.SEQ_ITEM){if(u!=="-"){s>n&&(c=s);break}}else if(u==="-"&&!this.error){const d=o[c+1];if(!d||d===`
48
+ `||d===" "||d===" "){const v="A collection cannot be both a mapping and a sequence";this.error=new ae(this,v)}}const p=r({atLineStart:l,inCollection:!0,indent:a,lineStart:s,parent:this},c);if(!p)return c;if(this.items.push(p),this.valueRange.end=p.valueRange.end,c=I.normalizeOffset(o,p.range.end),u=o[c],l=!1,f=p.includesTrailingLines,u){let d=c-1,v=o[d];for(;v===" "||v===" ";)v=o[--d];v===`
49
+ `&&(s=d+1,l=!0)}const h=Oo(p);h&&Array.prototype.push.apply(this.items,h)}return c}setOrigRanges(t,n){return n=super.setOrigRanges(t,n),this.items.forEach(r=>{n=r.setOrigRanges(t,n)}),n}toString(){const{context:{src:t},items:n,range:r,value:o}=this;if(o!=null)return o;let s=t.slice(r.start,n[0].range.start)+String(n[0]);for(let i=1;i<n.length;++i){const a=n[i],{atLineStart:c,indent:u}=a.context;if(c)for(let l=0;l<u;++l)s+=" ";s+=String(a)}return I.addStringTerminator(t,r.end,s)}};class dm extends I{constructor(){super(k.DIRECTIVE),this.name=null}get parameters(){const t=this.rawValue;return t?t.trim().split(/[ \t]+/):[]}parseName(t){const{src:n}=this.context;let r=t,o=n[r];for(;o&&o!==`
50
+ `&&o!==" "&&o!==" ";)o=n[r+=1];return this.name=n.slice(t,r),r}parseParameters(t){const{src:n}=this.context;let r=t,o=n[r];for(;o&&o!==`
51
+ `&&o!=="#";)o=n[r+=1];return this.valueRange=new Q(t,r),r}parse(t,n){this.context=t;let r=this.parseName(n+1);return r=this.parseParameters(r),r=this.parseComment(r),this.range=new Q(n,r),r}}let pm=class _o extends I{static startCommentOrEndBlankLine(t,n){const r=I.endOfWhiteSpace(t,n),o=t[r];return o==="#"||o===`
52
+ `?r:n}constructor(){super(k.DOCUMENT),this.directives=null,this.contents=null,this.directivesEndMarker=null,this.documentEndMarker=null}parseDirectives(t){const{src:n}=this.context;this.directives=[];let r=!0,o=!1,s=t;for(;!I.atDocumentBoundary(n,s,ee.DIRECTIVES_END);)switch(s=_o.startCommentOrEndBlankLine(n,s),n[s]){case`
53
+ `:if(r){const i=new pn;s=i.parse({src:n},s),s<n.length&&this.directives.push(i)}else s+=1,r=!0;break;case"#":{const i=new rn;s=i.parse({src:n},s),this.directives.push(i),r=!1}break;case"%":{const i=new dm;s=i.parse({parent:this,src:n},s),this.directives.push(i),o=!0,r=!1}break;default:return o?this.error=new B(this,"Missing directives-end indicator line"):this.directives.length>0&&(this.contents=this.directives,this.directives=[]),s}return n[s]?(this.directivesEndMarker=new Q(s,s+3),s+3):(o?this.error=new B(this,"Missing directives-end indicator line"):this.directives.length>0&&(this.contents=this.directives,this.directives=[]),s)}parseContents(t){const{parseNode:n,src:r}=this.context;this.contents||(this.contents=[]);let o=t;for(;r[o-1]==="-";)o-=1;let s=I.endOfWhiteSpace(r,t),i=o===t;for(this.valueRange=new Q(s);!I.atDocumentBoundary(r,s,ee.DOCUMENT_END);){switch(r[s]){case`
54
+ `:if(i){const a=new pn;s=a.parse({src:r},s),s<r.length&&this.contents.push(a)}else s+=1,i=!0;o=s;break;case"#":{const a=new rn;s=a.parse({src:r},s),this.contents.push(a),i=!1}break;default:{const a=I.endOfIndent(r,s),c=n({atLineStart:i,indent:-1,inFlow:!1,inCollection:!1,lineStart:o,parent:this},a);if(!c)return this.valueRange.end=a;this.contents.push(c),s=c.range.end,i=!1;const u=Oo(c);u&&Array.prototype.push.apply(this.contents,u)}}s=_o.startCommentOrEndBlankLine(r,s)}if(this.valueRange.end=s,r[s]&&(this.documentEndMarker=new Q(s,s+3),s+=3,r[s])){if(s=I.endOfWhiteSpace(r,s),r[s]==="#"){const a=new rn;s=a.parse({src:r},s),this.contents.push(a)}switch(r[s]){case`
55
+ `:s+=1;break;case void 0:break;default:this.error=new ae(this,"Document end marker line cannot have a non-comment suffix")}}return s}parse(t,n){t.root=this,this.context=t;const{src:r}=t;let o=r.charCodeAt(n)===65279?n+1:n;return o=this.parseDirectives(o),o=this.parseContents(o),o}setOrigRanges(t,n){return n=super.setOrigRanges(t,n),this.directives.forEach(r=>{n=r.setOrigRanges(t,n)}),this.directivesEndMarker&&(n=this.directivesEndMarker.setOrigRange(t,n)),this.contents.forEach(r=>{n=r.setOrigRanges(t,n)}),this.documentEndMarker&&(n=this.documentEndMarker.setOrigRange(t,n)),n}toString(){const{contents:t,directives:n,value:r}=this;if(r!=null)return r;let o=n.join("");return t.length>0&&((n.length>0||t[0].type===k.COMMENT)&&(o+=`---
56
+ `),o+=t.join("")),o[o.length-1]!==`
57
+ `&&(o+=`
58
+ `),o}},hm=class extends I{parse(e,t){this.context=e;const{src:n}=e;let r=I.endOfIdentifier(n,t+1);return this.valueRange=new Q(t+1,r),r=I.endOfWhiteSpace(n,r),r=this.parseComment(r),r}};const ze={CLIP:"CLIP",KEEP:"KEEP",STRIP:"STRIP"};class mm extends I{constructor(t,n){super(t,n),this.blockIndent=null,this.chomping=ze.CLIP,this.header=null}get includesTrailingLines(){return this.chomping===ze.KEEP}get strValue(){if(!this.valueRange||!this.context)return null;let{start:t,end:n}=this.valueRange;const{indent:r,src:o}=this.context;if(this.valueRange.isEmpty())return"";let s=null,i=o[n-1];for(;i===`
59
+ `||i===" "||i===" ";){if(n-=1,n<=t){if(this.chomping===ze.KEEP)break;return""}i===`
60
+ `&&(s=n),i=o[n-1]}let a=n+1;s&&(this.chomping===ze.KEEP?(a=s,n=this.valueRange.end):n=s);const c=r+this.blockIndent,u=this.type===k.BLOCK_FOLDED;let l=!0,f="",p="",h=!1;for(let d=t;d<n;++d){for(let m=0;m<c&&o[d]===" ";++m)d+=1;const v=o[d];if(v===`
61
+ `)p===`
62
+ `?f+=`
63
+ `:p=`
64
+ `;else{const m=I.endOfLine(o,d),y=o.slice(d,m);d=m,u&&(v===" "||v===" ")&&d<a?(p===" "?p=`
65
+ `:!h&&!l&&p===`
66
+ `&&(p=`
67
+
68
+ `),f+=p+y,p=m<n&&o[m]||"",h=!0):(f+=p+y,p=u&&d<a?" ":`
69
+ `,h=!1),l&&y!==""&&(l=!1)}}return this.chomping===ze.STRIP?f:f+`
70
+ `}parseBlockHeader(t){const{src:n}=this.context;let r=t+1,o="";for(;;){const s=n[r];switch(s){case"-":this.chomping=ze.STRIP;break;case"+":this.chomping=ze.KEEP;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":o+=s;break;default:return this.blockIndent=Number(o)||null,this.header=new Q(t,r),r}r+=1}}parseBlockValue(t){const{indent:n,src:r}=this.context,o=!!this.blockIndent;let s=t,i=t,a=1;for(let c=r[s];c===`
71
+ `&&(s+=1,!I.atDocumentBoundary(r,s));c=r[s]){const u=I.endOfBlockIndent(r,n,s);if(u===null)break;const l=r[u],f=u-(s+n);if(this.blockIndent){if(l&&l!==`
72
+ `&&f<this.blockIndent){if(r[u]==="#")break;if(!this.error){const p=`Block scalars must not be less indented than their ${o?"explicit indentation indicator":"first line"}`;this.error=new B(this,p)}}}else if(r[u]!==`
73
+ `){if(f<a){const p="Block scalars with more-indented leading empty lines must use an explicit indentation indicator";this.error=new B(this,p)}this.blockIndent=f}else f>a&&(a=f);r[u]===`
74
+ `?s=u:s=i=I.endOfLine(r,u)}return this.chomping!==ze.KEEP&&(s=r[i]?i+1:i),this.valueRange=new Q(t+1,s),s}parse(t,n){this.context=t;const{src:r}=t;let o=this.parseBlockHeader(n);return o=I.endOfWhiteSpace(r,o),o=this.parseComment(o),o=this.parseBlockValue(o),o}setOrigRanges(t,n){return n=super.setOrigRanges(t,n),this.header?this.header.setOrigRange(t,n):n}}class gm extends I{constructor(t,n){super(t,n),this.items=null}prevNodeIsJsonLike(t=this.items.length){const n=this.items[t-1];return!!n&&(n.jsonLike||n.type===k.COMMENT&&this.prevNodeIsJsonLike(t-1))}parse(t,n){this.context=t;const{parseNode:r,src:o}=t;let{indent:s,lineStart:i}=t,a=o[n];this.items=[{char:a,offset:n}];let c=I.endOfWhiteSpace(o,n+1);for(a=o[c];a&&a!=="]"&&a!=="}";){switch(a){case`
75
+ `:{i=c+1;const u=I.endOfWhiteSpace(o,i);if(o[u]===`
76
+ `){const l=new pn;i=l.parse({src:o},i),this.items.push(l)}if(c=I.endOfIndent(o,i),c<=i+s&&(a=o[c],c<i+s||a!=="]"&&a!=="}")){const l="Insufficient indentation in flow collection";this.error=new B(this,l)}}break;case",":this.items.push({char:a,offset:c}),c+=1;break;case"#":{const u=new rn;c=u.parse({src:o},c),this.items.push(u)}break;case"?":case":":{const u=o[c+1];if(u===`
77
+ `||u===" "||u===" "||u===","||a===":"&&this.prevNodeIsJsonLike()){this.items.push({char:a,offset:c}),c+=1;break}}default:{const u=r({atLineStart:!1,inCollection:!1,inFlow:!0,indent:-1,lineStart:i,parent:this},c);if(!u)return this.valueRange=new Q(n,c),c;this.items.push(u),c=I.normalizeOffset(o,u.range.end)}}c=I.endOfWhiteSpace(o,c),a=o[c]}return this.valueRange=new Q(n,c+1),a&&(this.items.push({char:a,offset:c}),c=I.endOfWhiteSpace(o,c+1),c=this.parseComment(c)),c}setOrigRanges(t,n){return n=super.setOrigRanges(t,n),this.items.forEach(r=>{if(r instanceof I)n=r.setOrigRanges(t,n);else if(t.length===0)r.origOffset=r.offset;else{let o=n;for(;o<t.length&&!(t[o]>r.offset);)++o;r.origOffset=r.offset+o,n=o}}),n}toString(){const{context:{src:t},items:n,range:r,value:o}=this;if(o!=null)return o;const s=n.filter(c=>c instanceof I);let i="",a=r.start;return s.forEach(c=>{const u=t.slice(a,c.range.start);a=c.range.end,i+=u+String(c),i[i.length-1]===`
78
+ `&&t[a-1]!==`
79
+ `&&t[a]===`
80
+ `&&(a+=1)}),i+=t.slice(a,r.end),I.addStringTerminator(t,r.end,i)}}class ys extends I{static endOfQuote(t,n){let r=t[n];for(;r&&r!=='"';)n+=r==="\\"?2:1,r=t[n];return n+1}get strValue(){if(!this.valueRange||!this.context)return null;const t=[],{start:n,end:r}=this.valueRange,{indent:o,src:s}=this.context;s[r-1]!=='"'&&t.push(new ae(this,'Missing closing "quote'));let i="";for(let a=n+1;a<r-1;++a){const c=s[a];if(c===`
81
+ `){I.atDocumentBoundary(s,a+1)&&t.push(new B(this,"Document boundary indicators are not allowed within string values"));const{fold:u,offset:l,error:f}=I.foldNewline(s,a,o);i+=u,a=l,f&&t.push(new B(this,"Multi-line double-quoted string needs to be sufficiently indented"))}else if(c==="\\")switch(a+=1,s[a]){case"0":i+="\0";break;case"a":i+="\x07";break;case"b":i+="\b";break;case"e":i+="\x1B";break;case"f":i+="\f";break;case"n":i+=`
82
+ `;break;case"r":i+="\r";break;case"t":i+=" ";break;case"v":i+="\v";break;case"N":i+="…";break;case"_":i+=" ";break;case"L":i+="\u2028";break;case"P":i+="\u2029";break;case" ":i+=" ";break;case'"':i+='"';break;case"/":i+="/";break;case"\\":i+="\\";break;case" ":i+=" ";break;case"x":i+=this.parseCharCode(a+1,2,t),a+=2;break;case"u":i+=this.parseCharCode(a+1,4,t),a+=4;break;case"U":i+=this.parseCharCode(a+1,8,t),a+=8;break;case`
83
+ `:for(;s[a+1]===" "||s[a+1]===" ";)a+=1;break;default:t.push(new ae(this,`Invalid escape sequence ${s.substr(a-1,2)}`)),i+="\\"+s[a]}else if(c===" "||c===" "){const u=a;let l=s[a+1];for(;l===" "||l===" ";)a+=1,l=s[a+1];l!==`
84
+ `&&(i+=a>u?s.slice(u,a+1):c)}else i+=c}return t.length>0?{errors:t,str:i}:i}parseCharCode(t,n,r){const{src:o}=this.context,s=o.substr(t,n),i=s.length===n&&/^[0-9a-fA-F]+$/.test(s)?parseInt(s,16):NaN;return isNaN(i)?(r.push(new ae(this,`Invalid escape sequence ${o.substr(t-2,n+2)}`)),o.substr(t-2,n+2)):String.fromCodePoint(i)}parse(t,n){this.context=t;const{src:r}=t;let o=ys.endOfQuote(r,n+1);return this.valueRange=new Q(n,o),o=I.endOfWhiteSpace(r,o),o=this.parseComment(o),o}}class vs extends I{static endOfQuote(t,n){let r=t[n];for(;r;)if(r==="'"){if(t[n+1]!=="'")break;r=t[n+=2]}else r=t[n+=1];return n+1}get strValue(){if(!this.valueRange||!this.context)return null;const t=[],{start:n,end:r}=this.valueRange,{indent:o,src:s}=this.context;s[r-1]!=="'"&&t.push(new ae(this,"Missing closing 'quote"));let i="";for(let a=n+1;a<r-1;++a){const c=s[a];if(c===`
85
+ `){I.atDocumentBoundary(s,a+1)&&t.push(new B(this,"Document boundary indicators are not allowed within string values"));const{fold:u,offset:l,error:f}=I.foldNewline(s,a,o);i+=u,a=l,f&&t.push(new B(this,"Multi-line single-quoted string needs to be sufficiently indented"))}else if(c==="'")i+=c,a+=1,s[a]!=="'"&&t.push(new ae(this,"Unescaped single quote? This should not happen."));else if(c===" "||c===" "){const u=a;let l=s[a+1];for(;l===" "||l===" ";)a+=1,l=s[a+1];l!==`
86
+ `&&(i+=a>u?s.slice(u,a+1):c)}else i+=c}return t.length>0?{errors:t,str:i}:i}parse(t,n){this.context=t;const{src:r}=t;let o=vs.endOfQuote(r,n+1);return this.valueRange=new Q(n,o),o=I.endOfWhiteSpace(r,o),o=this.parseComment(o),o}}function ym(e,t){switch(e){case k.ALIAS:return new hm(e,t);case k.BLOCK_FOLDED:case k.BLOCK_LITERAL:return new mm(e,t);case k.FLOW_MAP:case k.FLOW_SEQ:return new gm(e,t);case k.MAP_KEY:case k.MAP_VALUE:case k.SEQ_ITEM:return new gs(e,t);case k.COMMENT:case k.PLAIN:return new Eu(e,t);case k.QUOTE_DOUBLE:return new ys(e,t);case k.QUOTE_SINGLE:return new vs(e,t);default:return null}}class on{static parseType(t,n,r){switch(t[n]){case"*":return k.ALIAS;case">":return k.BLOCK_FOLDED;case"|":return k.BLOCK_LITERAL;case"{":return k.FLOW_MAP;case"[":return k.FLOW_SEQ;case"?":return!r&&I.atBlank(t,n+1,!0)?k.MAP_KEY:k.PLAIN;case":":return!r&&I.atBlank(t,n+1,!0)?k.MAP_VALUE:k.PLAIN;case"-":return!r&&I.atBlank(t,n+1,!0)?k.SEQ_ITEM:k.PLAIN;case'"':return k.QUOTE_DOUBLE;case"'":return k.QUOTE_SINGLE;default:return k.PLAIN}}constructor(t={},{atLineStart:n,inCollection:r,inFlow:o,indent:s,lineStart:i,parent:a}={}){ue(this,"parseNode",(c,u)=>{if(I.atDocumentBoundary(this.src,u))return null;const l=new on(this,c),{props:f,type:p,valueStart:h}=l.parseProps(u),d=ym(p,f);let v=u;try{v=d.parse(l,h)}catch(m){const y=m instanceof Error?m.message:String(m);d.error||(d.error=new ae(d,y))}if(d.range=new Q(u,v),v<=u&&(d.error||(d.error=new Error("Node#parse consumed no characters")),d.error.parseEnd=v,d.error.source=d,d.range.end=u+1),l.nodeStartsCollection(d)){!d.error&&!l.atLineStart&&l.parent.type===k.DOCUMENT&&(d.error=new ae(d,"Block collection must not have preceding content here (e.g. directives-end indicator)"));const m=new Su(d);return v=m.parse(new on(l),v),m.range=new Q(u,v),m}return d}),this.atLineStart=n??(t.atLineStart||!1),this.inCollection=r??(t.inCollection||!1),this.inFlow=o??(t.inFlow||!1),this.indent=s??t.indent,this.lineStart=i??t.lineStart,this.parent=a??(t.parent||{}),this.root=t.root,this.src=t.src}nodeStartsCollection(t){const{inCollection:n,inFlow:r,src:o}=this;if(n||r)return!1;if(t instanceof gs)return!0;let s=t.range.end;return o[s]===`
87
+ `||o[s-1]===`
88
+ `?!1:(s=I.endOfWhiteSpace(o,s),o[s]===":")}parseProps(t){const{inFlow:n,parent:r,src:o}=this,s=[];let i=!1;t=this.atLineStart?I.endOfIndent(o,t):I.endOfWhiteSpace(o,t);let a=o[t];for(;a===ee.ANCHOR||a===ee.COMMENT||a===ee.TAG||a===`
89
+ `;){if(a===`
90
+ `){let u=t,l;do l=u+1,u=I.endOfIndent(o,l);while(o[u]===`
91
+ `);const f=u-(l+this.indent),p=r.type===k.SEQ_ITEM&&r.context.atLineStart;if(o[u]!=="#"&&!I.nextNodeIsIndented(o[u],f,!p))break;this.atLineStart=!0,this.lineStart=l,i=!1,t=u}else if(a===ee.COMMENT){const u=I.endOfLine(o,t+1);s.push(new Q(t,u)),t=u}else{let u=I.endOfIdentifier(o,t+1);a===ee.TAG&&o[u]===","&&/^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(o.slice(t+1,u+13))&&(u=I.endOfIdentifier(o,u+5)),s.push(new Q(t,u)),i=!0,t=I.endOfWhiteSpace(o,u)}a=o[t]}i&&a===":"&&I.atBlank(o,t+1,!0)&&(t-=1);const c=on.parseType(o,t,n);return{props:s,type:c,valueStart:t}}}function $s(e){const t=[];e.indexOf("\r")!==-1&&(e=e.replace(/\r\n?/g,(o,s)=>(o.length>1&&t.push(s),`
92
+ `)));const n=[];let r=0;do{const o=new pm,s=new on({src:e});r=o.parse(s,r),n.push(o)}while(r<e.length);return n.setOrigRanges=()=>{if(t.length===0)return!1;for(let s=1;s<t.length;++s)t[s]-=s;let o=0;for(let s=0;s<n.length;++s)o=n[s].setOrigRanges(t,o);return t.splice(0,t.length),!0},n.toString=()=>n.join(`...
93
+ `),n}function vm(e,t,n){return n?`#${n.replace(/[\s\S]^/gm,`$&${t}#`)}
94
+ ${t}${e}`:e}function Ct(e,t,n){return n?n.indexOf(`
95
+ `)===-1?`${e} #${n}`:`${e}
96
+ `+n.replace(/^/gm,`${t||""}#`):e}let he=class{};function Ae(e,t,n){if(Array.isArray(e))return e.map((r,o)=>Ae(r,String(o),n));if(e&&typeof e.toJSON=="function"){const r=n&&n.anchors&&n.anchors.get(e);r&&(n.onCreate=s=>{r.res=s,delete n.onCreate});const o=e.toJSON(t,n);return r&&n.onCreate&&n.onCreate(o),o}return(!n||!n.keep)&&typeof e=="bigint"?Number(e):e}let W=class extends he{constructor(t){super(),this.value=t}toJSON(t,n){return n&&n.keep?this.value:Ae(this.value,t,n)}toString(){return String(this.value)}};function _a(e,t,n){let r=n;for(let o=t.length-1;o>=0;--o){const s=t[o];if(Number.isInteger(s)&&s>=0){const i=[];i[s]=r,r=i}else{const i={};Object.defineProperty(i,s,{value:r,writable:!0,enumerable:!0,configurable:!0}),r=i}}return e.createNode(r,!1)}const Xt=e=>e==null||typeof e=="object"&&e[Symbol.iterator]().next().done;let ie=class at extends he{constructor(t){super(),ue(this,"items",[]),this.schema=t}addIn(t,n){if(Xt(t))this.add(n);else{const[r,...o]=t,s=this.get(r,!0);if(s instanceof at)s.addIn(o,n);else if(s===void 0&&this.schema)this.set(r,_a(this.schema,o,n));else throw new Error(`Expected YAML collection at ${r}. Remaining path: ${o}`)}}deleteIn([t,...n]){if(n.length===0)return this.delete(t);const r=this.get(t,!0);if(r instanceof at)return r.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn([t,...n],r){const o=this.get(t,!0);return n.length===0?!r&&o instanceof W?o.value:o:o instanceof at?o.getIn(n,r):void 0}hasAllNullValues(){return this.items.every(t=>{if(!t||t.type!=="PAIR")return!1;const n=t.value;return n==null||n instanceof W&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn([t,...n]){if(n.length===0)return this.has(t);const r=this.get(t,!0);return r instanceof at?r.hasIn(n):!1}setIn([t,...n],r){if(n.length===0)this.set(t,r);else{const o=this.get(t,!0);if(o instanceof at)o.setIn(n,r);else if(o===void 0&&this.schema)this.set(t,_a(this.schema,n,r));else throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}}toJSON(){return null}toString(t,{blockItem:n,flowChars:r,isMap:o,itemIndent:s},i,a){const{indent:c,indentStep:u,stringify:l}=t,f=this.type===k.FLOW_MAP||this.type===k.FLOW_SEQ||t.inFlow;f&&(s+=u);const p=o&&this.hasAllNullValues();t=Object.assign({},t,{allNullValues:p,indent:s,inFlow:f,type:null});let h=!1,d=!1;const v=this.items.reduce((y,$,S)=>{let b;$&&(!h&&$.spaceBefore&&y.push({type:"comment",str:""}),$.commentBefore&&$.commentBefore.match(/^.*$/gm).forEach(j=>{y.push({type:"comment",str:`#${j}`})}),$.comment&&(b=$.comment),f&&(!h&&$.spaceBefore||$.commentBefore||$.comment||$.key&&($.key.commentBefore||$.key.comment)||$.value&&($.value.commentBefore||$.value.comment))&&(d=!0)),h=!1;let N=l($,t,()=>b=null,()=>h=!0);return f&&!d&&N.includes(`
97
+ `)&&(d=!0),f&&S<this.items.length-1&&(N+=","),N=Ct(N,s,b),h&&(b||f)&&(h=!1),y.push({type:"item",str:N}),y},[]);let m;if(v.length===0)m=r.start+r.end;else if(f){const{start:y,end:$}=r,S=v.map(b=>b.str);if(d||S.reduce((b,N)=>b+N.length+2,2)>at.maxFlowStringSingleLineLength){m=y;for(const b of S)m+=b?`
98
+ ${u}${c}${b}`:`
99
+ `;m+=`
100
+ ${c}${$}`}else m=`${y} ${S.join(" ")} ${$}`}else{const y=v.map(n);m=y.shift();for(const $ of y)m+=$?`
101
+ ${c}${$}`:`
102
+ `}return this.comment?(m+=`
103
+ `+this.comment.replace(/^/gm,`${c}#`),i&&i()):h&&a&&a(),m}};ue(ie,"maxFlowStringSingleLineLength",60);function An(e){let t=e instanceof W?e.value:e;return t&&typeof t=="string"&&(t=Number(t)),Number.isInteger(t)&&t>=0?t:null}let Te=class extends ie{add(t){this.items.push(t)}delete(t){const n=An(t);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(t,n){const r=An(t);if(typeof r!="number")return;const o=this.items[r];return!n&&o instanceof W?o.value:o}has(t){const n=An(t);return typeof n=="number"&&n<this.items.length}set(t,n){const r=An(t);if(typeof r!="number")throw new Error(`Expected a valid index, not ${t}.`);this.items[r]=n}toJSON(t,n){const r=[];n&&n.onCreate&&n.onCreate(r);let o=0;for(const s of this.items)r.push(Ae(s,String(o++),n));return r}toString(t,n,r){return t?super.toString(t,{blockItem:o=>o.type==="comment"?o.str:`- ${o.str}`,flowChars:{start:"[",end:"]"},isMap:!1,itemIndent:(t.indent||"")+" "},n,r):JSON.stringify(this)}};const $m=(e,t,n)=>t===null?"":typeof t!="object"?String(t):e instanceof he&&n&&n.doc?e.toString({anchors:Object.create(null),doc:n.doc,indent:"",indentStep:n.indentStep,inFlow:!0,inStringifyKey:!0,stringify:n.stringify}):JSON.stringify(t);let q=class Ou extends he{constructor(t,n=null){super(),this.key=t,this.value=n,this.type=Ou.Type.PAIR}get commentBefore(){return this.key instanceof he?this.key.commentBefore:void 0}set commentBefore(t){if(this.key==null&&(this.key=new W(null)),this.key instanceof he)this.key.commentBefore=t;else{const n="Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.";throw new Error(n)}}addToJSMap(t,n){const r=Ae(this.key,"",t);if(n instanceof Map){const o=Ae(this.value,r,t);n.set(r,o)}else if(n instanceof Set)n.add(r);else{const o=$m(this.key,r,t),s=Ae(this.value,o,t);o in n?Object.defineProperty(n,o,{value:s,writable:!0,enumerable:!0,configurable:!0}):n[o]=s}return n}toJSON(t,n){const r=n&&n.mapAsMap?new Map:{};return this.addToJSMap(n,r)}toString(t,n,r){if(!t||!t.doc)return JSON.stringify(this);const{indent:o,indentSeq:s,simpleKeys:i}=t.doc.options;let{key:a,value:c}=this,u=a instanceof he&&a.comment;if(i){if(u)throw new Error("With simple keys, key nodes cannot have comments");if(a instanceof ie){const N="With simple keys, collection cannot be used as a key value";throw new Error(N)}}let l=!i&&(!a||u||(a instanceof he?a instanceof ie||a.type===k.BLOCK_FOLDED||a.type===k.BLOCK_LITERAL:typeof a=="object"));const{doc:f,indent:p,indentStep:h,stringify:d}=t;t=Object.assign({},t,{implicitKey:!l,indent:p+h});let v=!1,m=d(a,t,()=>u=null,()=>v=!0);if(m=Ct(m,t.indent,u),!l&&m.length>1024){if(i)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");l=!0}if(t.allNullValues&&!i)return this.comment?(m=Ct(m,t.indent,this.comment),n&&n()):v&&!u&&r&&r(),t.inFlow&&!l?m:`? ${m}`;m=l?`? ${m}
104
+ ${p}:`:`${m}:`,this.comment&&(m=Ct(m,t.indent,this.comment),n&&n());let y="",$=null;if(c instanceof he){if(c.spaceBefore&&(y=`
105
+ `),c.commentBefore){const N=c.commentBefore.replace(/^/gm,`${t.indent}#`);y+=`
106
+ ${N}`}$=c.comment}else c&&typeof c=="object"&&(c=f.schema.createNode(c,!0));t.implicitKey=!1,!l&&!this.comment&&c instanceof W&&(t.indentAtStart=m.length+1),v=!1,!s&&o>=2&&!t.inFlow&&!l&&c instanceof Te&&c.type!==k.FLOW_SEQ&&!c.tag&&!f.anchors.getName(c)&&(t.indent=t.indent.substr(2));const S=d(c,t,()=>$=null,()=>v=!0);let b=" ";return y||this.comment?b=`${y}
107
+ ${t.indent}`:!l&&c instanceof ie?(!(S[0]==="["||S[0]==="{")||S.includes(`
108
+ `))&&(b=`
109
+ ${t.indent}`):S[0]===`
110
+ `&&(b=""),v&&!$&&r&&r(),Ct(m+b+S,t.indent,$)}};ue(q,"Type",{PAIR:"PAIR",MERGE_PAIR:"MERGE_PAIR"});const qn=(e,t)=>{if(e instanceof Ve){const n=t.get(e.source);return n.count*n.aliasCount}else if(e instanceof ie){let n=0;for(const r of e.items){const o=qn(r,t);o>n&&(n=o)}return n}else if(e instanceof q){const n=qn(e.key,t),r=qn(e.value,t);return Math.max(n,r)}return 1};let Ve=class Nu extends he{static stringify({range:t,source:n},{anchors:r,doc:o,implicitKey:s,inStringifyKey:i}){let a=Object.keys(r).find(u=>r[u]===n);if(!a&&i&&(a=o.anchors.getName(n)||o.anchors.newName()),a)return`*${a}${s?" ":""}`;const c=o.anchors.getName(n)?"Alias node must be after source node":"Source node not found for alias node";throw new Error(`${c} [${t}]`)}constructor(t){super(),this.source=t,this.type=k.ALIAS}set tag(t){throw new Error("Alias nodes cannot have tags")}toJSON(t,n){if(!n)return Ae(this.source,t,n);const{anchors:r,maxAliasCount:o}=n,s=r.get(this.source);if(!s||s.res===void 0){const i="This should not happen: Alias anchor was not resolved?";throw this.cstNode?new dn(this.cstNode,i):new ReferenceError(i)}if(o>=0&&(s.count+=1,s.aliasCount===0&&(s.aliasCount=qn(this.source,r)),s.count*s.aliasCount>o)){const i="Excessive alias count indicates a resource exhaustion attack";throw this.cstNode?new dn(this.cstNode,i):new ReferenceError(i)}return s.res}toString(t){return Nu.stringify(this,t)}};ue(Ve,"default",!0);function ht(e,t){const n=t instanceof W?t.value:t;for(const r of e)if(r instanceof q&&(r.key===t||r.key===n||r.key&&r.key.value===n))return r}let me=class extends ie{add(t,n){t?t instanceof q||(t=new q(t.key||t,t.value)):t=new q(t);const r=ht(this.items,t.key),o=this.schema&&this.schema.sortMapEntries;if(r)if(n)r.value=t.value;else throw new Error(`Key ${t.key} already set`);else if(o){const s=this.items.findIndex(i=>o(t,i)<0);s===-1?this.items.push(t):this.items.splice(s,0,t)}else this.items.push(t)}delete(t){const n=ht(this.items,t);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(t,n){const r=ht(this.items,t),o=r&&r.value;return!n&&o instanceof W?o.value:o}has(t){return!!ht(this.items,t)}set(t,n){this.add(new q(t,n),!0)}toJSON(t,n,r){const o=r?new r:n&&n.mapAsMap?new Map:{};n&&n.onCreate&&n.onCreate(o);for(const s of this.items)s.addToJSMap(n,o);return o}toString(t,n,r){if(!t)return JSON.stringify(this);for(const o of this.items)if(!(o instanceof q))throw new Error(`Map items must all be pairs; found ${JSON.stringify(o)} instead`);return super.toString(t,{blockItem:o=>o.str,flowChars:{start:"{",end:"}"},isMap:!0,itemIndent:t.indent||""},n,r)}};const _u="<<";class ku extends q{constructor(t){if(t instanceof q){let n=t.value;n instanceof Te||(n=new Te,n.items.push(t.value),n.range=t.value.range),super(t.key,n),this.range=t.range}else super(new W(_u),new Te);this.type=q.Type.MERGE_PAIR}addToJSMap(t,n){for(const{source:r}of this.value.items){if(!(r instanceof me))throw new Error("Merge sources must be maps");const o=r.toJSON(null,t,Map);for(const[s,i]of o)n instanceof Map?n.has(s)||n.set(s,i):n instanceof Set?n.add(s):Object.prototype.hasOwnProperty.call(n,s)||Object.defineProperty(n,s,{value:i,writable:!0,enumerable:!0,configurable:!0})}return n}toString(t,n){const r=this.value;if(r.items.length>1)return super.toString(t,n);this.value=r.items[0];const o=super.toString(t,n);return this.value=r,o}}const sn={defaultType:k.BLOCK_LITERAL,lineWidth:76},Le={trueStr:"true",falseStr:"false"},tt={asBigInt:!1},Bt={nullStr:"null"},qe={defaultType:k.PLAIN,doubleQuoted:{jsonEncoding:!1,minMultiLineLength:40},fold:{lineWidth:80,minContentWidth:20}};function ws(e,t,n){for(const{format:r,test:o,resolve:s}of t)if(o){const i=e.match(o);if(i){let a=s.apply(null,i);return a instanceof W||(a=new W(a)),r&&(a.format=r),a}}return n&&(e=n(e)),new W(e)}const Au="flow",ko="block",Kn="quoted",ka=(e,t)=>{let n=e[t+1];for(;n===" "||n===" ";){do n=e[t+=1];while(n&&n!==`
111
+ `);n=e[t+1]}return t};function pr(e,t,n,{indentAtStart:r,lineWidth:o=80,minContentWidth:s=20,onFold:i,onOverflow:a}){if(!o||o<0)return e;const c=Math.max(1+s,1+o-t.length);if(e.length<=c)return e;const u=[],l={};let f=o-t.length;typeof r=="number"&&(r>o-Math.max(2,s)?u.push(0):f=o-r);let p,h,d=!1,v=-1,m=-1,y=-1;n===ko&&(v=ka(e,v),v!==-1&&(f=v+c));for(let S;S=e[v+=1];){if(n===Kn&&S==="\\"){switch(m=v,e[v+1]){case"x":v+=3;break;case"u":v+=5;break;case"U":v+=9;break;default:v+=1}y=v}if(S===`
112
+ `)n===ko&&(v=ka(e,v)),f=v+c,p=void 0;else{if(S===" "&&h&&h!==" "&&h!==`
113
+ `&&h!==" "){const b=e[v+1];b&&b!==" "&&b!==`
114
+ `&&b!==" "&&(p=v)}if(v>=f)if(p)u.push(p),f=p+c,p=void 0;else if(n===Kn){for(;h===" "||h===" ";)h=S,S=e[v+=1],d=!0;const b=v>y+1?v-2:m-1;if(l[b])return e;u.push(b),l[b]=!0,f=b+c,p=void 0}else d=!0}h=S}if(d&&a&&a(),u.length===0)return e;i&&i();let $=e.slice(0,u[0]);for(let S=0;S<u.length;++S){const b=u[S],N=u[S+1]||e.length;b===0?$=`
115
+ ${t}${e.slice(0,N)}`:(n===Kn&&l[b]&&($+=`${e[b]}\\`),$+=`
116
+ ${t}${e.slice(b+1,N)}`)}return $}const bs=({indentAtStart:e})=>e?Object.assign({indentAtStart:e},qe.fold):qe.fold,hr=e=>/^(%|---|\.\.\.)/m.test(e);function wm(e,t,n){if(!t||t<0)return!1;const r=t-n,o=e.length;if(o<=r)return!1;for(let s=0,i=0;s<o;++s)if(e[s]===`
117
+ `){if(s-i>r)return!0;if(i=s+1,o-i<=r)return!1}return!0}function yt(e,t){const{implicitKey:n}=t,{jsonEncoding:r,minMultiLineLength:o}=qe.doubleQuoted,s=JSON.stringify(e);if(r)return s;const i=t.indent||(hr(e)?" ":"");let a="",c=0;for(let u=0,l=s[u];l;l=s[++u])if(l===" "&&s[u+1]==="\\"&&s[u+2]==="n"&&(a+=s.slice(c,u)+"\\ ",u+=1,c=u,l="\\"),l==="\\")switch(s[u+1]){case"u":{a+=s.slice(c,u);const f=s.substr(u+2,4);switch(f){case"0000":a+="\\0";break;case"0007":a+="\\a";break;case"000b":a+="\\v";break;case"001b":a+="\\e";break;case"0085":a+="\\N";break;case"00a0":a+="\\_";break;case"2028":a+="\\L";break;case"2029":a+="\\P";break;default:f.substr(0,2)==="00"?a+="\\x"+f.substr(2):a+=s.substr(u,6)}u+=5,c=u+1}break;case"n":if(n||s[u+2]==='"'||s.length<o)u+=1;else{for(a+=s.slice(c,u)+`
118
+
119
+ `;s[u+2]==="\\"&&s[u+3]==="n"&&s[u+4]!=='"';)a+=`
120
+ `,u+=2;a+=i,s[u+2]===" "&&(a+="\\"),u+=1,c=u+1}break;default:u+=1}return a=c?a+s.slice(c):s,n?a:pr(a,i,Kn,bs(t))}function Iu(e,t){if(t.implicitKey){if(/\n/.test(e))return yt(e,t)}else if(/[ \t]\n|\n[ \t]/.test(e))return yt(e,t);const n=t.indent||(hr(e)?" ":""),r="'"+e.replace(/'/g,"''").replace(/\n+/g,`$&
121
+ ${n}`)+"'";return t.implicitKey?r:pr(r,n,Au,bs(t))}function Gn({comment:e,type:t,value:n},r,o,s){if(/\n[\t ]+$/.test(n)||/^\s*$/.test(n))return yt(n,r);const i=r.indent||(r.forceBlockIndent||hr(n)?" ":""),a=i?"2":"1",c=t===k.BLOCK_FOLDED?!1:t===k.BLOCK_LITERAL?!0:!wm(n,qe.fold.lineWidth,i.length);let u=c?"|":">";if(!n)return u+`
122
+ `;let l="",f="";if(n=n.replace(/[\n\t ]*$/,h=>{const d=h.indexOf(`
123
+ `);return d===-1?u+="-":(n===h||d!==h.length-1)&&(u+="+",s&&s()),f=h.replace(/\n$/,""),""}).replace(/^[\n ]*/,h=>{h.indexOf(" ")!==-1&&(u+=a);const d=h.match(/ +$/);return d?(l=h.slice(0,-d[0].length),d[0]):(l=h,"")}),f&&(f=f.replace(/\n+(?!\n|$)/g,`$&${i}`)),l&&(l=l.replace(/\n+/g,`$&${i}`)),e&&(u+=" #"+e.replace(/ ?[\r\n]+/g," "),o&&o()),!n)return`${u}${a}
124
+ ${i}${f}`;if(c)return n=n.replace(/\n+/g,`$&${i}`),`${u}
125
+ ${i}${l}${n}${f}`;n=n.replace(/\n+/g,`
126
+ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${i}`);const p=pr(`${l}${n}${f}`,i,ko,qe.fold);return`${u}
127
+ ${i}${p}`}function bm(e,t,n,r){const{comment:o,type:s,value:i}=e,{actualString:a,implicitKey:c,indent:u,inFlow:l}=t;if(c&&/[\n[\]{},]/.test(i)||l&&/[[\]{},]/.test(i))return yt(i,t);if(!i||/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(i))return c||l||i.indexOf(`
128
+ `)===-1?i.indexOf('"')!==-1&&i.indexOf("'")===-1?Iu(i,t):yt(i,t):Gn(e,t,n,r);if(!c&&!l&&s!==k.PLAIN&&i.indexOf(`
129
+ `)!==-1)return Gn(e,t,n,r);if(u===""&&hr(i))return t.forceBlockIndent=!0,Gn(e,t,n,r);const f=i.replace(/\n+/g,`$&
130
+ ${u}`);if(a){const{tags:h}=t.doc.schema;if(typeof ws(f,h,h.scalarFallback).value!="string")return yt(i,t)}const p=c?f:pr(f,u,Au,bs(t));return o&&!l&&(p.indexOf(`
131
+ `)!==-1||o.indexOf(`
132
+ `)!==-1)?(n&&n(),vm(p,u,o)):p}function Es(e,t,n,r){const{defaultType:o}=qe,{implicitKey:s,inFlow:i}=t;let{type:a,value:c}=e;typeof c!="string"&&(c=String(c),e=Object.assign({},e,{value:c}));const u=f=>{switch(f){case k.BLOCK_FOLDED:case k.BLOCK_LITERAL:return Gn(e,t,n,r);case k.QUOTE_DOUBLE:return yt(c,t);case k.QUOTE_SINGLE:return Iu(c,t);case k.PLAIN:return bm(e,t,n,r);default:return null}};(a!==k.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(c)||(s||i)&&(a===k.BLOCK_FOLDED||a===k.BLOCK_LITERAL))&&(a=k.QUOTE_DOUBLE);let l=u(a);if(l===null&&(l=u(o),l===null))throw new Error(`Unsupported default string type ${o}`);return l}function Be({format:e,minFractionDigits:t,tag:n,value:r}){if(typeof r=="bigint")return String(r);if(!isFinite(r))return isNaN(r)?".nan":r<0?"-.inf":".inf";let o=JSON.stringify(r);if(!e&&t&&(!n||n==="tag:yaml.org,2002:float")&&/^\d/.test(o)){let s=o.indexOf(".");s<0&&(s=o.length,o+=".");let i=t-(o.length-s-1);for(;i-- >0;)o+="0"}return o}function ju(e,t){let n,r;switch(t.type){case k.FLOW_MAP:n="}",r="flow map";break;case k.FLOW_SEQ:n="]",r="flow sequence";break;default:e.push(new B(t,"Not a flow collection!?"));return}let o;for(let s=t.items.length-1;s>=0;--s){const i=t.items[s];if(!i||i.type!==k.COMMENT){o=i;break}}if(o&&o.char!==n){const s=`Expected ${r} to end with ${n}`;let i;typeof o.offset=="number"?(i=new B(t,s),i.offset=o.offset+1):(i=new B(o,s),o.range&&o.range.end&&(i.offset=o.range.end-o.range.start)),e.push(i)}}function Pu(e,t){const n=t.context.src[t.range.start-1];if(n!==`
133
+ `&&n!==" "&&n!==" "){const r="Comments must be separated from other tokens by white space characters";e.push(new B(t,r))}}function xu(e,t){const n=String(t),r=n.substr(0,8)+"..."+n.substr(-8);return new B(e,`The "${r}" key is too long`)}function Tu(e,t){for(const{afterKey:n,before:r,comment:o}of t){let s=e.items[r];s?(n&&s.value&&(s=s.value),o===void 0?(n||!s.commentBefore)&&(s.spaceBefore=!0):s.commentBefore?s.commentBefore+=`
134
+ `+o:s.commentBefore=o):o!==void 0&&(e.comment?e.comment+=`
135
+ `+o:e.comment=o)}}function wn(e,t){const n=t.strValue;return n?typeof n=="string"?n:(n.errors.forEach(r=>{r.source||(r.source=t),e.errors.push(r)}),n.str):""}function Em(e,t){const{handle:n,suffix:r}=t.tag;let o=e.tagPrefixes.find(s=>s.handle===n);if(!o){const s=e.getDefaults().tagPrefixes;if(s&&(o=s.find(i=>i.handle===n)),!o)throw new B(t,`The ${n} tag handle is non-default and was not declared.`)}if(!r)throw new B(t,`The ${n} tag has no suffix.`);if(n==="!"&&(e.version||e.options.version)==="1.0"){if(r[0]==="^")return e.warnings.push(new qt(t,"YAML 1.0 ^ tag expansion is not supported")),r;if(/[:/]/.test(r)){const s=r.match(/^([a-z0-9-]+)\/(.*)/i);return s?`tag:${s[1]}.yaml.org,2002:${s[2]}`:`tag:${r}`}}return o.prefix+decodeURIComponent(r)}function Sm(e,t){const{tag:n,type:r}=t;let o=!1;if(n){const{handle:s,suffix:i,verbatim:a}=n;if(a){if(a!=="!"&&a!=="!!")return a;const c=`Verbatim tags aren't resolved, so ${a} is invalid.`;e.errors.push(new B(t,c))}else if(s==="!"&&!i)o=!0;else try{return Em(e,t)}catch(c){e.errors.push(c)}}switch(r){case k.BLOCK_FOLDED:case k.BLOCK_LITERAL:case k.QUOTE_DOUBLE:case k.QUOTE_SINGLE:return Ye.STR;case k.FLOW_MAP:case k.MAP:return Ye.MAP;case k.FLOW_SEQ:case k.SEQ:return Ye.SEQ;case k.PLAIN:return o?Ye.STR:null;default:return null}}function Aa(e,t,n){const{tags:r}=e.schema,o=[];for(const i of r)if(i.tag===n)if(i.test)o.push(i);else{const a=i.resolve(e,t);return a instanceof ie?a:new W(a)}const s=wn(e,t);return typeof s=="string"&&o.length>0?ws(s,o,r.scalarFallback):null}function Om({type:e}){switch(e){case k.FLOW_MAP:case k.MAP:return Ye.MAP;case k.FLOW_SEQ:case k.SEQ:return Ye.SEQ;default:return Ye.STR}}function Nm(e,t,n){try{const r=Aa(e,t,n);if(r)return n&&t.tag&&(r.tag=n),r}catch(r){if(r instanceof vt)r.source||(r.source=t),e.errors.push(r);else{const o=r instanceof Error?r.message:String(r);e.errors.push(new B(t,o))}return null}try{const r=Om(t);if(!r)throw new Error(`The tag ${n} is unavailable`);const o=`The tag ${n} is unavailable, falling back to ${r}`;e.warnings.push(new qt(t,o));const s=Aa(e,t,r);return s.tag=n,s}catch(r){const o=new dn(t,r.message);return o.stack=r.stack,e.errors.push(o),null}}const _m=e=>{if(!e)return!1;const{type:t}=e;return t===k.MAP_KEY||t===k.MAP_VALUE||t===k.SEQ_ITEM};function km(e,t){const n={before:[],after:[]};let r=!1,o=!1;const s=_m(t.context.parent)?t.context.parent.props.concat(t.props):t.props;for(const{start:i,end:a}of s)switch(t.context.src[i]){case ee.COMMENT:{if(!t.commentHasRequiredWhitespace(i)){const l="Comments must be separated from other tokens by white space characters";e.push(new B(t,l))}const{header:c,valueRange:u}=t;(u&&(i>u.start||c&&i>c.start)?n.after:n.before).push(t.context.src.slice(i+1,a));break}case ee.ANCHOR:if(r){const c="A node can have at most one anchor";e.push(new B(t,c))}r=!0;break;case ee.TAG:if(o){const c="A node can have at most one tag";e.push(new B(t,c))}o=!0;break}return{comments:n,hasAnchor:r,hasTag:o}}function Am(e,t){const{anchors:n,errors:r,schema:o}=e;if(t.type===k.ALIAS){const i=t.rawValue,a=n.getNode(i);if(!a){const u=`Aliased anchor not found: ${i}`;return r.push(new dn(t,u)),null}const c=new Ve(a);return n._cstAliases.push(c),c}const s=Sm(e,t);if(s)return Nm(e,t,s);if(t.type!==k.PLAIN){const i=`Failed to resolve ${t.type} node here`;return r.push(new ae(t,i)),null}try{const i=wn(e,t);return ws(i,o.tags,o.tags.scalarFallback)}catch(i){return i.source||(i.source=t),r.push(i),null}}function Xe(e,t){if(!t)return null;t.error&&e.errors.push(t.error);const{comments:n,hasAnchor:r,hasTag:o}=km(e.errors,t);if(r){const{anchors:i}=e,a=t.anchor,c=i.getNode(a);c&&(i.map[i.newName(a)]=c),i.map[a]=t}if(t.type===k.ALIAS&&(r||o)){const i="An alias node must not specify any properties";e.errors.push(new B(t,i))}const s=Am(e,t);if(s){s.range=[t.range.start,t.range.end],e.options.keepCstNodes&&(s.cstNode=t),e.options.keepNodeTypes&&(s.type=t.type);const i=n.before.join(`
136
+ `);i&&(s.commentBefore=s.commentBefore?`${s.commentBefore}
137
+ ${i}`:i);const a=n.after.join(`
138
+ `);a&&(s.comment=s.comment?`${s.comment}
139
+ ${a}`:a)}return t.resolved=s}function Cu(e,t){if(t.type!==k.MAP&&t.type!==k.FLOW_MAP){const i=`A ${t.type} node cannot be resolved as a mapping`;return e.errors.push(new ae(t,i)),null}const{comments:n,items:r}=t.type===k.FLOW_MAP?xm(e,t):Pm(e,t),o=new me;o.items=r,Tu(o,n);let s=!1;for(let i=0;i<r.length;++i){const{key:a}=r[i];if(a instanceof ie&&(s=!0),e.schema.merge&&a&&a.value===_u){r[i]=new ku(r[i]);const c=r[i].value.items;let u=null;c.some(l=>{if(l instanceof Ve){const{type:f}=l.source;return f===k.MAP||f===k.FLOW_MAP?!1:u="Merge nodes aliases can only point to maps"}return u="Merge nodes can only have Alias nodes as values"}),u&&e.errors.push(new B(t,u))}else for(let c=i+1;c<r.length;++c){const{key:u}=r[c];if(a===u||a&&u&&Object.prototype.hasOwnProperty.call(a,"value")&&a.value===u.value){const l=`Map keys must be unique; "${a}" is repeated`;e.errors.push(new B(t,l));break}}}if(s&&!e.options.mapAsMap){const i="Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.";e.warnings.push(new qt(t,i))}return t.resolved=o,o}const Im=({context:{lineStart:e,node:t,src:n},props:r})=>{if(r.length===0)return!1;const{start:o}=r[0];if(t&&o>t.valueRange.start||n[o]!==ee.COMMENT)return!1;for(let s=e;s<o;++s)if(n[s]===`
140
+ `)return!1;return!0};function jm(e,t){if(!Im(e))return;const n=e.getPropValue(0,ee.COMMENT,!0);let r=!1;const o=t.value.commentBefore;if(o&&o.startsWith(n))t.value.commentBefore=o.substr(n.length+1),r=!0;else{const s=t.value.comment;!e.node&&s&&s.startsWith(n)&&(t.value.comment=s.substr(n.length+1),r=!0)}r&&(t.comment=n)}function Pm(e,t){const n=[],r=[];let o,s=null;for(let i=0;i<t.items.length;++i){const a=t.items[i];switch(a.type){case k.BLANK_LINE:n.push({afterKey:!!o,before:r.length});break;case k.COMMENT:n.push({afterKey:!!o,before:r.length,comment:a.comment});break;case k.MAP_KEY:o!==void 0&&r.push(new q(o)),a.error&&e.errors.push(a.error),o=Xe(e,a.node),s=null;break;case k.MAP_VALUE:{if(o===void 0&&(o=null),a.error&&e.errors.push(a.error),!a.context.atLineStart&&a.node&&a.node.type===k.MAP&&!a.node.context.atLineStart){const l="Nested mappings are not allowed in compact mappings";e.errors.push(new B(a.node,l))}let c=a.node;if(!c&&a.props.length>0){c=new Eu(k.PLAIN,[]),c.context={parent:a,src:a.context.src};const l=a.range.start+1;if(c.range={start:l,end:l},c.valueRange={start:l,end:l},typeof a.range.origStart=="number"){const f=a.range.origStart+1;c.range.origStart=c.range.origEnd=f,c.valueRange.origStart=c.valueRange.origEnd=f}}const u=new q(o,Xe(e,c));jm(a,u),r.push(u),o&&typeof s=="number"&&a.range.start>s+1024&&e.errors.push(xu(t,o)),o=void 0,s=null}break;default:o!==void 0&&r.push(new q(o)),o=Xe(e,a),s=a.range.start,a.error&&e.errors.push(a.error);e:for(let c=i+1;;++c){const u=t.items[c];switch(u&&u.type){case k.BLANK_LINE:case k.COMMENT:continue e;case k.MAP_VALUE:break e;default:{const l="Implicit map keys need to be followed by map values";e.errors.push(new B(a,l));break e}}}if(a.valueRangeContainsNewline){const c="Implicit map keys need to be on a single line";e.errors.push(new B(a,c))}}}return o!==void 0&&r.push(new q(o)),{comments:n,items:r}}function xm(e,t){const n=[],r=[];let o,s=!1,i="{";for(let a=0;a<t.items.length;++a){const c=t.items[a];if(typeof c.char=="string"){const{char:u,offset:l}=c;if(u==="?"&&o===void 0&&!s){s=!0,i=":";continue}if(u===":"){if(o===void 0&&(o=null),i===":"){i=",";continue}}else if(s&&(o===void 0&&u!==","&&(o=null),s=!1),o!==void 0&&(r.push(new q(o)),o=void 0,u===",")){i=":";continue}if(u==="}"){if(a===t.items.length-1)continue}else if(u===i){i=":";continue}const f=`Flow map contains an unexpected ${u}`,p=new ae(t,f);p.offset=l,e.errors.push(p)}else c.type===k.BLANK_LINE?n.push({afterKey:!!o,before:r.length}):c.type===k.COMMENT?(Pu(e.errors,c),n.push({afterKey:!!o,before:r.length,comment:c.comment})):o===void 0?(i===","&&e.errors.push(new B(c,"Separator , missing in flow map")),o=Xe(e,c)):(i!==","&&e.errors.push(new B(c,"Indicator : missing in flow map entry")),r.push(new q(o,Xe(e,c))),o=void 0,s=!1)}return ju(e.errors,t),o!==void 0&&r.push(new q(o)),{comments:n,items:r}}function Ru(e,t){if(t.type!==k.SEQ&&t.type!==k.FLOW_SEQ){const s=`A ${t.type} node cannot be resolved as a sequence`;return e.errors.push(new ae(t,s)),null}const{comments:n,items:r}=t.type===k.FLOW_SEQ?Cm(e,t):Tm(e,t),o=new Te;if(o.items=r,Tu(o,n),!e.options.mapAsMap&&r.some(s=>s instanceof q&&s.key instanceof ie)){const s="Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.";e.warnings.push(new qt(t,s))}return t.resolved=o,o}function Tm(e,t){const n=[],r=[];for(let o=0;o<t.items.length;++o){const s=t.items[o];switch(s.type){case k.BLANK_LINE:n.push({before:r.length});break;case k.COMMENT:n.push({comment:s.comment,before:r.length});break;case k.SEQ_ITEM:if(s.error&&e.errors.push(s.error),r.push(Xe(e,s.node)),s.hasProps){const i="Sequence items cannot have tags or anchors before the - indicator";e.errors.push(new B(s,i))}break;default:s.error&&e.errors.push(s.error),e.errors.push(new ae(s,`Unexpected ${s.type} node in sequence`))}}return{comments:n,items:r}}function Cm(e,t){const n=[],r=[];let o=!1,s,i=null,a="[",c=null;for(let u=0;u<t.items.length;++u){const l=t.items[u];if(typeof l.char=="string"){const{char:f,offset:p}=l;if(f!==":"&&(o||s!==void 0)&&(o&&s===void 0&&(s=a?r.pop():null),r.push(new q(s)),o=!1,s=void 0,i=null),f===a)a=null;else if(!a&&f==="?")o=!0;else if(a!=="["&&f===":"&&s===void 0){if(a===","){if(s=r.pop(),s instanceof q){const h="Chaining flow sequence pairs is invalid",d=new B(t,h);d.offset=p,e.errors.push(d)}if(!o&&typeof i=="number"){const h=l.range?l.range.start:l.offset;h>i+1024&&e.errors.push(xu(t,s));const{src:d}=c.context;for(let v=i;v<h;++v)if(d[v]===`
141
+ `){const m="Implicit keys of flow sequence pairs need to be on a single line";e.errors.push(new B(c,m));break}}}else s=null;i=null,o=!1,a=null}else if(a==="["||f!=="]"||u<t.items.length-1){const h=`Flow sequence contains an unexpected ${f}`,d=new ae(t,h);d.offset=p,e.errors.push(d)}}else if(l.type===k.BLANK_LINE)n.push({before:r.length});else if(l.type===k.COMMENT)Pu(e.errors,l),n.push({comment:l.comment,before:r.length});else{if(a){const p=`Expected a ${a} in flow sequence`;e.errors.push(new B(l,p))}const f=Xe(e,l);s===void 0?(r.push(f),c=l):(r.push(new q(s,f)),s=void 0),i=l.range.start,a=","}}return ju(e.errors,t),s!==void 0&&r.push(new q(s)),{comments:n,items:r}}const Mu={identify:e=>e instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve:(e,t)=>{const n=wn(e,t);if(typeof Buffer=="function")return Buffer.from(n,"base64");if(typeof atob=="function"){const r=atob(n.replace(/[\n\r]/g,"")),o=new Uint8Array(r.length);for(let s=0;s<r.length;++s)o[s]=r.charCodeAt(s);return o}else{const r="This environment does not support reading binary tags; either Buffer or atob is required";return e.errors.push(new dn(t,r)),null}},options:sn,stringify:({comment:e,type:t,value:n},r,o,s)=>{let i;if(typeof Buffer=="function")i=n instanceof Buffer?n.toString("base64"):Buffer.from(n.buffer).toString("base64");else if(typeof btoa=="function"){let a="";for(let c=0;c<n.length;++c)a+=String.fromCharCode(n[c]);i=btoa(a)}else throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");if(t||(t=sn.defaultType),t===k.QUOTE_DOUBLE)n=i;else{const{lineWidth:a}=sn,c=Math.ceil(i.length/a),u=new Array(c);for(let l=0,f=0;l<c;++l,f+=a)u[l]=i.substr(f,a);n=u.join(t===k.BLOCK_LITERAL?`
142
+ `:" ")}return Es({comment:e,type:t,value:n},r,o,s)}};function Du(e,t){const n=Ru(e,t);for(let r=0;r<n.items.length;++r){let o=n.items[r];if(!(o instanceof q)){if(o instanceof me){if(o.items.length>1){const i="Each pair must have its own sequence indicator";throw new B(t,i)}const s=o.items[0]||new q;o.commentBefore&&(s.commentBefore=s.commentBefore?`${o.commentBefore}
143
+ ${s.commentBefore}`:o.commentBefore),o.comment&&(s.comment=s.comment?`${o.comment}
144
+ ${s.comment}`:o.comment),o=s}n.items[r]=o instanceof q?o:new q(o)}}return n}function Lu(e,t,n){const r=new Te(e);r.tag="tag:yaml.org,2002:pairs";for(const o of t){let s,i;if(Array.isArray(o))if(o.length===2)s=o[0],i=o[1];else throw new TypeError(`Expected [key, value] tuple: ${o}`);else if(o&&o instanceof Object){const c=Object.keys(o);if(c.length===1)s=c[0],i=o[s];else throw new TypeError(`Expected { key: value } tuple: ${o}`)}else s=o;const a=e.createPair(s,i,n);r.items.push(a)}return r}const Bu={default:!1,tag:"tag:yaml.org,2002:pairs",resolve:Du,createNode:Lu};let mr=class Uu extends Te{constructor(){super(),ue(this,"add",me.prototype.add.bind(this)),ue(this,"delete",me.prototype.delete.bind(this)),ue(this,"get",me.prototype.get.bind(this)),ue(this,"has",me.prototype.has.bind(this)),ue(this,"set",me.prototype.set.bind(this)),this.tag=Uu.tag}toJSON(t,n){const r=new Map;n&&n.onCreate&&n.onCreate(r);for(const o of this.items){let s,i;if(o instanceof q?(s=Ae(o.key,"",n),i=Ae(o.value,s,n)):s=Ae(o,"",n),r.has(s))throw new Error("Ordered maps must not include duplicate keys");r.set(s,i)}return r}};ue(mr,"tag","tag:yaml.org,2002:omap");function Rm(e,t){const n=Du(e,t),r=[];for(const{key:o}of n.items)if(o instanceof W)if(r.includes(o.value)){const s="Ordered maps must not include duplicate keys";throw new B(t,s)}else r.push(o.value);return Object.assign(new mr,n)}function Mm(e,t,n){const r=Lu(e,t,n),o=new mr;return o.items=r.items,o}const Fu={identify:e=>e instanceof Map,nodeClass:mr,default:!1,tag:"tag:yaml.org,2002:omap",resolve:Rm,createNode:Mm};let gr=class Vu extends me{constructor(){super(),this.tag=Vu.tag}add(t){const n=t instanceof q?t:new q(t);ht(this.items,n.key)||this.items.push(n)}get(t,n){const r=ht(this.items,t);return!n&&r instanceof q?r.key instanceof W?r.key.value:r.key:r}set(t,n){if(typeof n!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof n}`);const r=ht(this.items,t);r&&!n?this.items.splice(this.items.indexOf(r),1):!r&&n&&this.items.push(new q(t))}toJSON(t,n){return super.toJSON(t,n,Set)}toString(t,n,r){if(!t)return JSON.stringify(this);if(this.hasAllNullValues())return super.toString(t,n,r);throw new Error("Set items must all have null values")}};ue(gr,"tag","tag:yaml.org,2002:set");function Dm(e,t){const n=Cu(e,t);if(!n.hasAllNullValues())throw new B(t,"Set items must all have null values");return Object.assign(new gr,n)}function Lm(e,t,n){const r=new gr;for(const o of t)r.items.push(e.createPair(o,null,n));return r}const qu={identify:e=>e instanceof Set,nodeClass:gr,default:!1,tag:"tag:yaml.org,2002:set",resolve:Dm,createNode:Lm},Ss=(e,t)=>{const n=t.split(":").reduce((r,o)=>r*60+Number(o),0);return e==="-"?-n:n},Ku=({value:e})=>{if(isNaN(e)||!isFinite(e))return Be(e);let t="";e<0&&(t="-",e=Math.abs(e));const n=[e%60];return e<60?n.unshift(0):(e=Math.round((e-n[0])/60),n.unshift(e%60),e>=60&&(e=Math.round((e-n[0])/60),n.unshift(e))),t+n.map(r=>r<10?"0"+String(r):String(r)).join(":").replace(/000000\d*$/,"")},Gu={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,resolve:(e,t,n)=>Ss(t,n.replace(/_/g,"")),stringify:Ku},zu={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,resolve:(e,t,n)=>Ss(t,n.replace(/_/g,"")),stringify:Ku},Wu={identify:e=>e instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^(?:([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?)$"),resolve:(e,t,n,r,o,s,i,a,c)=>{a&&(a=(a+"00").substr(1,3));let u=Date.UTC(t,n-1,r,o||0,s||0,i||0,a||0);if(c&&c!=="Z"){let l=Ss(c[0],c.slice(1));Math.abs(l)<30&&(l*=60),u-=6e4*l}return new Date(u)},stringify:({value:e})=>e.toISOString().replace(/((T00:00)?:00)?\.000Z$/,"")};function Hu(e){const t=typeof process<"u"&&process.env||{};return e?typeof YAML_SILENCE_DEPRECATION_WARNINGS<"u"?!YAML_SILENCE_DEPRECATION_WARNINGS:!t.YAML_SILENCE_DEPRECATION_WARNINGS:typeof YAML_SILENCE_WARNINGS<"u"?!YAML_SILENCE_WARNINGS:!t.YAML_SILENCE_WARNINGS}function Ju(e,t){if(Hu(!1)){const n=typeof process<"u"&&process.emitWarning;n?n(e,t):console.warn(t?`${t}: ${e}`:e)}}const Ia={};function Bm(e,t){if(!Ia[e]&&Hu(!0)){Ia[e]=!0;let n=`The option '${e}' will be removed in a future release`;n+=`, use '${t}' instead.`,Ju(n,"DeprecationWarning")}}function Um(e,t,n){const r=new me(e);if(t instanceof Map)for(const[o,s]of t)r.items.push(e.createPair(o,s,n));else if(t&&typeof t=="object")for(const o of Object.keys(t))r.items.push(e.createPair(o,t[o],n));return typeof e.sortMapEntries=="function"&&r.items.sort(e.sortMapEntries),r}const hn={createNode:Um,default:!0,nodeClass:me,tag:"tag:yaml.org,2002:map",resolve:Cu};function Fm(e,t,n){const r=new Te(e);if(t&&t[Symbol.iterator])for(const o of t){const s=e.createNode(o,n.wrapScalars,null,n);r.items.push(s)}return r}const yr={createNode:Fm,default:!0,nodeClass:Te,tag:"tag:yaml.org,2002:seq",resolve:Ru},Vm={identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:wn,stringify(e,t,n,r){return t=Object.assign({actualString:!0},t),Es(e,t,n,r)},options:qe},Os=[hn,yr,Vm],vr=e=>typeof e=="bigint"||Number.isInteger(e),Ns=(e,t,n)=>tt.asBigInt?BigInt(e):parseInt(t,n);function Yu(e,t,n){const{value:r}=e;return vr(r)&&r>=0?n+r.toString(t):Be(e)}const Qu={identify:e=>e==null,createNode:(e,t,n)=>n.wrapScalars?new W(null):null,default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>null,options:Bt,stringify:()=>Bt.nullStr},Zu={identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:e=>e[0]==="t"||e[0]==="T",options:Le,stringify:({value:e})=>e?Le.trueStr:Le.falseStr},Xu={identify:e=>vr(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o([0-7]+)$/,resolve:(e,t)=>Ns(e,t,8),options:tt,stringify:e=>Yu(e,8,"0o")},el={identify:vr,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:e=>Ns(e,e,10),options:tt,stringify:Be},tl={identify:e=>vr(e)&&e>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x([0-9a-fA-F]+)$/,resolve:(e,t)=>Ns(e,t,16),options:tt,stringify:e=>Yu(e,16,"0x")},nl={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.inf|(\.nan))$/i,resolve:(e,t)=>t?NaN:e[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Be},rl={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e),stringify:({value:e})=>Number(e).toExponential()},ol={identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,resolve(e,t,n){const r=t||n,o=new W(parseFloat(e));return r&&r[r.length-1]==="0"&&(o.minFractionDigits=r.length),o},stringify:Be},qm=Os.concat([Qu,Zu,Xu,el,tl,nl,rl,ol]),ja=e=>typeof e=="bigint"||Number.isInteger(e),In=({value:e})=>JSON.stringify(e),sl=[hn,yr,{identify:e=>typeof e=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:wn,stringify:In},{identify:e=>e==null,createNode:(e,t,n)=>n.wrapScalars?new W(null):null,default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:In},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true|false$/,resolve:e=>e==="true",stringify:In},{identify:ja,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:e=>tt.asBigInt?BigInt(e):parseInt(e,10),stringify:({value:e})=>ja(e)?e.toString():JSON.stringify(e)},{identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:e=>parseFloat(e),stringify:In}];sl.scalarFallback=e=>{throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(e)}`)};const Pa=({value:e})=>e?Le.trueStr:Le.falseStr,en=e=>typeof e=="bigint"||Number.isInteger(e);function jn(e,t,n){let r=t.replace(/_/g,"");if(tt.asBigInt){switch(n){case 2:r=`0b${r}`;break;case 8:r=`0o${r}`;break;case 16:r=`0x${r}`;break}const s=BigInt(r);return e==="-"?BigInt(-1)*s:s}const o=parseInt(r,n);return e==="-"?-1*o:o}function Qr(e,t,n){const{value:r}=e;if(en(r)){const o=r.toString(t);return r<0?"-"+n+o.substr(1):n+o}return Be(e)}const Km=Os.concat([{identify:e=>e==null,createNode:(e,t,n)=>n.wrapScalars?new W(null):null,default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>null,options:Bt,stringify:()=>Bt.nullStr},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>!0,options:Le,stringify:Pa},{identify:e=>typeof e=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,resolve:()=>!1,options:Le,stringify:Pa},{identify:en,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^([-+]?)0b([0-1_]+)$/,resolve:(e,t,n)=>jn(t,n,2),stringify:e=>Qr(e,2,"0b")},{identify:en,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^([-+]?)0([0-7_]+)$/,resolve:(e,t,n)=>jn(t,n,8),stringify:e=>Qr(e,8,"0")},{identify:en,default:!0,tag:"tag:yaml.org,2002:int",test:/^([-+]?)([0-9][0-9_]*)$/,resolve:(e,t,n)=>jn(t,n,10),stringify:Be},{identify:en,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^([-+]?)0x([0-9a-fA-F_]+)$/,resolve:(e,t,n)=>jn(t,n,16),stringify:e=>Qr(e,16,"0x")},{identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.inf|(\.nan))$/i,resolve:(e,t)=>t?NaN:e[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Be},{identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:e=>parseFloat(e.replace(/_/g,"")),stringify:({value:e})=>Number(e).toExponential()},{identify:e=>typeof e=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,resolve(e,t){const n=new W(parseFloat(e.replace(/_/g,"")));if(t){const r=t.replace(/_/g,"");r[r.length-1]==="0"&&(n.minFractionDigits=r.length)}return n},stringify:Be}],Mu,Fu,Bu,qu,Gu,zu,Wu),Gm={core:qm,failsafe:Os,json:sl,yaml11:Km},zm={binary:Mu,bool:Zu,float:ol,floatExp:rl,floatNaN:nl,floatTime:zu,int:el,intHex:tl,intOct:Xu,intTime:Gu,map:hn,null:Qu,omap:Fu,pairs:Bu,seq:yr,set:qu,timestamp:Wu};function Wm(e,t,n){if(t){const r=n.filter(s=>s.tag===t),o=r.find(s=>!s.format)||r[0];if(!o)throw new Error(`Tag ${t} not found`);return o}return n.find(r=>(r.identify&&r.identify(e)||r.class&&e instanceof r.class)&&!r.format)}function Hm(e,t,n){if(e instanceof he)return e;const{defaultPrefix:r,onTagObj:o,prevObjects:s,schema:i,wrapScalars:a}=n;t&&t.startsWith("!!")&&(t=r+t.slice(2));let c=Wm(e,t,i.tags);if(!c){if(typeof e.toJSON=="function"&&(e=e.toJSON()),!e||typeof e!="object")return a?new W(e):e;c=e instanceof Map?hn:e[Symbol.iterator]?yr:hn}o&&(o(c),delete n.onTagObj);const u={value:void 0,node:void 0};if(e&&typeof e=="object"&&s){const l=s.get(e);if(l){const f=new Ve(l);return n.aliasNodes.push(f),f}u.value=e,s.set(e,u)}return u.node=c.createNode?c.createNode(n.schema,e,n):a?new W(e):e,t&&u.node instanceof he&&(u.node.tag=t),u.node}function Jm(e,t,n,r){let o=e[r.replace(/\W/g,"")];if(!o){const s=Object.keys(e).map(i=>JSON.stringify(i)).join(", ");throw new Error(`Unknown schema "${r}"; use one of ${s}`)}if(Array.isArray(n))for(const s of n)o=o.concat(s);else typeof n=="function"&&(o=n(o.slice()));for(let s=0;s<o.length;++s){const i=o[s];if(typeof i=="string"){const a=t[i];if(!a){const c=Object.keys(t).map(u=>JSON.stringify(u)).join(", ");throw new Error(`Unknown custom tag "${i}"; use one of ${c}`)}o[s]=a}}return o}const Ym=(e,t)=>e.key<t.key?-1:e.key>t.key?1:0;let mn=class il{constructor({customTags:t,merge:n,schema:r,sortMapEntries:o,tags:s}){this.merge=!!n,this.name=r,this.sortMapEntries=o===!0?Ym:o||null,!t&&s&&Bm("tags","customTags"),this.tags=Jm(Gm,zm,t||s,r)}createNode(t,n,r,o){const s={defaultPrefix:il.defaultPrefix,schema:this,wrapScalars:n},i=o?Object.assign(o,s):s;return Hm(t,r,i)}createPair(t,n,r){r||(r={wrapScalars:!0});const o=this.createNode(t,r.wrapScalars,null,r),s=this.createNode(n,r.wrapScalars,null,r);return new q(o,s)}};ue(mn,"defaultPrefix",Vn);ue(mn,"defaultTags",Ye);const nr={anchorPrefix:"a",customTags:null,indent:2,indentSeq:!0,keepCstNodes:!1,keepNodeTypes:!0,keepBlobsInJSON:!0,mapAsMap:!1,maxAliasCount:100,prettyErrors:!1,simpleKeys:!1,version:"1.2"},Qm={get binary(){return sn},set binary(e){Object.assign(sn,e)},get bool(){return Le},set bool(e){Object.assign(Le,e)},get int(){return tt},set int(e){Object.assign(tt,e)},get null(){return Bt},set null(e){Object.assign(Bt,e)},get str(){return qe},set str(e){Object.assign(qe,e)}},al={"1.0":{schema:"yaml-1.1",merge:!0,tagPrefixes:[{handle:"!",prefix:Vn},{handle:"!!",prefix:"tag:private.yaml.org,2002:"}]},1.1:{schema:"yaml-1.1",merge:!0,tagPrefixes:[{handle:"!",prefix:"!"},{handle:"!!",prefix:Vn}]},1.2:{schema:"core",merge:!1,tagPrefixes:[{handle:"!",prefix:"!"},{handle:"!!",prefix:Vn}]}};function xa(e,t){if((e.version||e.options.version)==="1.0"){const o=t.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);if(o)return"!"+o[1];const s=t.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);return s?`!${s[1]}/${s[2]}`:`!${t.replace(/^tag:/,"")}`}let n=e.tagPrefixes.find(o=>t.indexOf(o.prefix)===0);if(!n){const o=e.getDefaults().tagPrefixes;n=o&&o.find(s=>t.indexOf(s.prefix)===0)}if(!n)return t[0]==="!"?t:`!<${t}>`;const r=t.substr(n.prefix.length).replace(/[!,[\]{}]/g,o=>({"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"})[o]);return n.handle+r}function Zm(e,t){if(t instanceof Ve)return Ve;if(t.tag){const o=e.filter(s=>s.tag===t.tag);if(o.length>0)return o.find(s=>s.format===t.format)||o[0]}let n,r;if(t instanceof W){r=t.value;const o=e.filter(s=>s.identify&&s.identify(r)||s.class&&r instanceof s.class);n=o.find(s=>s.format===t.format)||o.find(s=>!s.format)}else r=t,n=e.find(o=>o.nodeClass&&r instanceof o.nodeClass);if(!n){const o=r&&r.constructor?r.constructor.name:typeof r;throw new Error(`Tag not resolved for ${o} value`)}return n}function Xm(e,t,{anchors:n,doc:r}){const o=[],s=r.anchors.getName(e);return s&&(n[s]=e,o.push(`&${s}`)),e.tag?o.push(xa(r,e.tag)):t.default||o.push(xa(r,t.tag)),o.join(" ")}function Pn(e,t,n,r){const{anchors:o,schema:s}=t.doc;let i;if(!(e instanceof he)){const u={aliasNodes:[],onTagObj:l=>i=l,prevObjects:new Map};e=s.createNode(e,!0,null,u);for(const l of u.aliasNodes){l.source=l.source.node;let f=o.getName(l.source);f||(f=o.newName(),o.map[f]=l.source)}}if(e instanceof q)return e.toString(t,n,r);i||(i=Zm(s.tags,e));const a=Xm(e,i,t);a.length>0&&(t.indentAtStart=(t.indentAtStart||0)+a.length+1);const c=typeof i.stringify=="function"?i.stringify(e,t,n,r):e instanceof W?Es(e,t,n,r):e.toString(t,n,r);return a?e instanceof W||c[0]==="{"||c[0]==="["?`${a} ${c}`:`${a}
145
+ ${t.indent}${c}`:c}class _s{static validAnchorNode(t){return t instanceof W||t instanceof Te||t instanceof me}constructor(t){ue(this,"map",Object.create(null)),this.prefix=t}createAlias(t,n){return this.setAnchor(t,n),new Ve(t)}createMergePair(...t){const n=new ku;return n.value.items=t.map(r=>{if(r instanceof Ve){if(r.source instanceof me)return r}else if(r instanceof me)return this.createAlias(r);throw new Error("Merge sources must be Map nodes or their Aliases")}),n}getName(t){const{map:n}=this;return Object.keys(n).find(r=>n[r]===t)}getNames(){return Object.keys(this.map)}getNode(t){return this.map[t]}newName(t){t||(t=this.prefix);const n=Object.keys(this.map);for(let r=1;;++r){const o=`${t}${r}`;if(!n.includes(o))return o}}resolveNodes(){const{map:t,_cstAliases:n}=this;Object.keys(t).forEach(r=>{t[r]=t[r].resolved}),n.forEach(r=>{r.source=r.source.resolved}),delete this._cstAliases}setAnchor(t,n){if(t!=null&&!_s.validAnchorNode(t))throw new Error("Anchors may only be set for Scalar, Seq and Map nodes");if(n&&/[\x00-\x19\s,[\]{}]/.test(n))throw new Error("Anchor names must not contain whitespace or control characters");const{map:r}=this,o=t&&Object.keys(r).find(s=>r[s]===t);if(o)if(n)o!==n&&(delete r[o],r[n]=t);else return o;else{if(!n){if(!t)return null;n=this.newName()}r[n]=t}return n}}const zn=(e,t)=>{if(e&&typeof e=="object"){const{tag:n}=e;e instanceof ie?(n&&(t[n]=!0),e.items.forEach(r=>zn(r,t))):e instanceof q?(zn(e.key,t),zn(e.value,t)):e instanceof W&&n&&(t[n]=!0)}return t},eg=e=>Object.keys(zn(e,{}));function tg(e,t){const n={before:[],after:[]};let r,o=!1;for(const s of t)if(s.valueRange){if(r!==void 0){const a="Document contains trailing content not separated by a ... or --- line";e.errors.push(new ae(s,a));break}const i=Xe(e,s);o&&(i.spaceBefore=!0,o=!1),r=i}else s.comment!==null?(r===void 0?n.before:n.after).push(s.comment):s.type===k.BLANK_LINE&&(o=!0,r===void 0&&n.before.length>0&&!e.commentBefore&&(e.commentBefore=n.before.join(`
146
+ `),n.before=[]));if(e.contents=r||null,!r)e.comment=n.before.concat(n.after).join(`
147
+ `)||null;else{const s=n.before.join(`
148
+ `);if(s){const i=r instanceof ie&&r.items[0]?r.items[0]:r;i.commentBefore=i.commentBefore?`${s}
149
+ ${i.commentBefore}`:s}e.comment=n.after.join(`
150
+ `)||null}}function ng({tagPrefixes:e},t){const[n,r]=t.parameters;if(!n||!r){const o="Insufficient parameters given for %TAG directive";throw new B(t,o)}if(e.some(o=>o.handle===n)){const o="The %TAG directive must only be given at most once per handle in the same document.";throw new B(t,o)}return{handle:n,prefix:r}}function rg(e,t){let[n]=t.parameters;if(t.name==="YAML:1.0"&&(n="1.0"),!n){const r="Insufficient parameters given for %YAML directive";throw new B(t,r)}if(!al[n]){const r=`Document will be parsed as YAML ${e.version||e.options.version} rather than YAML ${n}`;e.warnings.push(new qt(t,r))}return n}function og(e,t,n){const r=[];let o=!1;for(const s of t){const{comment:i,name:a}=s;switch(a){case"TAG":try{e.tagPrefixes.push(ng(e,s))}catch(c){e.errors.push(c)}o=!0;break;case"YAML":case"YAML:1.0":if(e.version){const c="The %YAML directive must only be given at most once per document.";e.errors.push(new B(s,c))}try{e.version=rg(e,s)}catch(c){e.errors.push(c)}o=!0;break;default:if(a){const c=`YAML only supports %TAG and %YAML directives, and not %${a}`;e.warnings.push(new qt(s,c))}}i&&r.push(i)}if(n&&!o&&(e.version||n.version||e.options.version)==="1.1"){const s=({handle:i,prefix:a})=>({handle:i,prefix:a});e.tagPrefixes=n.tagPrefixes.map(s),e.version=n.version}e.commentBefore=r.join(`
151
+ `)||null}function Ot(e){if(e instanceof ie)return!0;throw new Error("Expected a YAML collection as document contents")}let ks=class Ao{constructor(t){this.anchors=new _s(t.anchorPrefix),this.commentBefore=null,this.comment=null,this.contents=null,this.directivesEndMarker=null,this.errors=[],this.options=t,this.schema=null,this.tagPrefixes=[],this.version=null,this.warnings=[]}add(t){return Ot(this.contents),this.contents.add(t)}addIn(t,n){Ot(this.contents),this.contents.addIn(t,n)}delete(t){return Ot(this.contents),this.contents.delete(t)}deleteIn(t){return Xt(t)?this.contents==null?!1:(this.contents=null,!0):(Ot(this.contents),this.contents.deleteIn(t))}getDefaults(){return Ao.defaults[this.version]||Ao.defaults[this.options.version]||{}}get(t,n){return this.contents instanceof ie?this.contents.get(t,n):void 0}getIn(t,n){return Xt(t)?!n&&this.contents instanceof W?this.contents.value:this.contents:this.contents instanceof ie?this.contents.getIn(t,n):void 0}has(t){return this.contents instanceof ie?this.contents.has(t):!1}hasIn(t){return Xt(t)?this.contents!==void 0:this.contents instanceof ie?this.contents.hasIn(t):!1}set(t,n){Ot(this.contents),this.contents.set(t,n)}setIn(t,n){Xt(t)?this.contents=n:(Ot(this.contents),this.contents.setIn(t,n))}setSchema(t,n){if(!t&&!n&&this.schema)return;typeof t=="number"&&(t=t.toFixed(1)),t==="1.0"||t==="1.1"||t==="1.2"?(this.version?this.version=t:this.options.version=t,delete this.options.schema):t&&typeof t=="string"&&(this.options.schema=t),Array.isArray(n)&&(this.options.customTags=n);const r=Object.assign({},this.getDefaults(),this.options);this.schema=new mn(r)}parse(t,n){this.options.keepCstNodes&&(this.cstNode=t),this.options.keepNodeTypes&&(this.type="DOCUMENT");const{directives:r=[],contents:o=[],directivesEndMarker:s,error:i,valueRange:a}=t;if(i&&(i.source||(i.source=this),this.errors.push(i)),og(this,r,n),s&&(this.directivesEndMarker=!0),this.range=a?[a.start,a.end]:null,this.setSchema(),this.anchors._cstAliases=[],tg(this,o),this.anchors.resolveNodes(),this.options.prettyErrors){for(const c of this.errors)c instanceof vt&&c.makePretty();for(const c of this.warnings)c instanceof vt&&c.makePretty()}return this}listNonDefaultTags(){return eg(this.contents).filter(t=>t.indexOf(mn.defaultPrefix)!==0)}setTagPrefix(t,n){if(t[0]!=="!"||t[t.length-1]!=="!")throw new Error("Handle must start and end with !");if(n){const r=this.tagPrefixes.find(o=>o.handle===t);r?r.prefix=n:this.tagPrefixes.push({handle:t,prefix:n})}else this.tagPrefixes=this.tagPrefixes.filter(r=>r.handle!==t)}toJSON(t,n){const{keepBlobsInJSON:r,mapAsMap:o,maxAliasCount:s}=this.options,i=r&&(typeof t!="string"||!(this.contents instanceof W)),a={doc:this,indentStep:" ",keep:i,mapAsMap:i&&!!o,maxAliasCount:s,stringify:Pn},c=Object.keys(this.anchors.map);c.length>0&&(a.anchors=new Map(c.map(l=>[this.anchors.map[l],{alias:[],aliasCount:0,count:1}])));const u=Ae(this.contents,t,a);if(typeof n=="function"&&a.anchors)for(const{count:l,res:f}of a.anchors.values())n(f,l);return u}toString(){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");const t=this.options.indent;if(!Number.isInteger(t)||t<=0){const c=JSON.stringify(t);throw new Error(`"indent" option must be a positive integer, not ${c}`)}this.setSchema();const n=[];let r=!1;if(this.version){let c="%YAML 1.2";this.schema.name==="yaml-1.1"&&(this.version==="1.0"?c="%YAML:1.0":this.version==="1.1"&&(c="%YAML 1.1")),n.push(c),r=!0}const o=this.listNonDefaultTags();this.tagPrefixes.forEach(({handle:c,prefix:u})=>{o.some(l=>l.indexOf(u)===0)&&(n.push(`%TAG ${c} ${u}`),r=!0)}),(r||this.directivesEndMarker)&&n.push("---"),this.commentBefore&&((r||!this.directivesEndMarker)&&n.unshift(""),n.unshift(this.commentBefore.replace(/^/gm,"#")));const s={anchors:Object.create(null),doc:this,indent:"",indentStep:" ".repeat(t),stringify:Pn};let i=!1,a=null;if(this.contents){this.contents instanceof he&&(this.contents.spaceBefore&&(r||this.directivesEndMarker)&&n.push(""),this.contents.commentBefore&&n.push(this.contents.commentBefore.replace(/^/gm,"#")),s.forceBlockIndent=!!this.comment,a=this.contents.comment);const c=a?null:()=>i=!0,u=Pn(this.contents,s,()=>a=null,c);n.push(Ct(u,"",a))}else this.contents!==void 0&&n.push(Pn(this.contents,s));return this.comment&&((!i||a)&&n[n.length-1]!==""&&n.push(""),n.push(this.comment.replace(/^/gm,"#"))),n.join(`
152
+ `)+`
153
+ `}};ue(ks,"defaults",al);function sg(e,t=!0,n){n===void 0&&typeof t=="string"&&(n=t,t=!0);const r=Object.assign({},ks.defaults[nr.version],nr);return new mn(r).createNode(e,t,n)}class $r extends ks{constructor(t){super(Object.assign({},nr,t))}}function ig(e,t){const n=[];let r;for(const o of $s(e)){const s=new $r(t);s.parse(o,r),n.push(s),r=s}return n}function cl(e,t){const n=$s(e),r=new $r(t).parse(n[0]);if(n.length>1){const o="Source contains multiple documents; please use YAML.parseAllDocuments()";r.errors.unshift(new B(n[1],o))}return r}function ag(e,t){const n=cl(e,t);if(n.warnings.forEach(r=>Ju(r)),n.errors.length>0)throw n.errors[0];return n.toJSON()}function cg(e,t){const n=new $r(t);return n.contents=e,String(n)}const ug={createNode:sg,defaultOptions:nr,Document:$r,parse:ag,parseAllDocuments:ig,parseCST:$s,parseDocument:cl,scalarOptions:Qm,stringify:cg},lg=Object.freeze(Object.defineProperty({__proto__:null,YAML:ug},Symbol.toStringTag,{value:"Module"})),fg=am(lg);var dg=fg.YAML;const pg="1.0.0-redesign.1",hg="adhd",mg="default",gg="adhd-environment.json",Zr="config.yaml",yg="config.local.yaml",vg={data:"shared",cache:"shared",state:"shared",config:"shared",run:"shared",logs:"per-instance",temp:"per-instance"};class Ta extends Error{constructor(t,n){super(`contentHash: lone surrogate in ${t} (not well-formed Unicode)`),this.location=t,this.offending=n,this.name="LoneSurrogateError"}}function Ca(e){for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);if(n>=55296&&n<=56319){const r=t+1<e.length?e.charCodeAt(t+1):0;if(r<56320||r>57343)return!0;t++}else if(n>=56320&&n<=57343)return!0}return!1}function ul(e,t){const n=Array.from(e),r=Array.from(t),o=Math.min(n.length,r.length);for(let s=0;s<o;s++){const i=n[s].codePointAt(0)??0,a=r[s].codePointAt(0)??0;if(i!==a)return i<a?-1:1}return n.length===r.length?0:n.length<r.length?-1:1}function Ra(e){return new TextEncoder().encode(e).length}function $g(e){const t=Object.keys(e).sort(ul);let n="";for(const r of t){const o=e[r];if(Ca(r))throw new Ta("key",r);if(Ca(o))throw new Ta("value",o);n+=`${Ra(r)}:${r}=${Ra(o)}:${o}
154
+ `}return`sha256-${ll(n)}`}function wg(e){const t=[...e].sort((n,r)=>ul(n.name,r.name)).map(n=>`${n.name}:${n.kind}:${n.scope}`).join(`
155
+ `);return`sha256-${ll(t)}`}function bg(e){return`ADHD_${e.toUpperCase().replace(/[.-]/g,"_")}`}function Eg(e,t){return`${e}_${t.toUpperCase().replace(/[.-]/g,"_")}`}function Sg(e){const t={type:"object",properties:{}},n=e;for(const r of Object.keys(n)){const o=n[r],s=r.split(".");let i=t;s.forEach((a,c)=>{if(c===s.length-1){i.properties[a]=Og(o);return}const u=i.properties[a];if(u===void 0){const l={type:"object",properties:{}};i.properties[a]=l,i=l}else i=u})}return t}function Og(e){const t={type:e.type};return e.default!==void 0&&e.secret!==!0&&(t.default=e.default),e.description!==void 0&&(t.description=e.description),e.minimum!==void 0&&(t.minimum=e.minimum),e.maximum!==void 0&&(t.maximum=e.maximum),e.enum!==void 0&&(t.enum=e.enum),e.pattern!==void 0&&(t.pattern=e.pattern),e.minLength!==void 0&&(t.minLength=e.minLength),e.maxLength!==void 0&&(t.maxLength=e.maxLength),e.items!==void 0&&(t.items=e.items),t}const Ng="adhd-env-ref:";function _g(e){return`${Ng}${e}`}const kg=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],Ag=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function je(e,t){return(e>>>t|e<<32-t)>>>0}function Ig(e){const t=Uint32Array.from(Ag),n=e.length*8;let r=e.length+1;for(;r%64!==56;)r++;r+=8;const o=new Uint8Array(r);o.set(e),o[e.length]=128;const s=Math.floor(n/4294967296),i=n>>>0,a=new DataView(o.buffer);a.setUint32(r-8,s,!1),a.setUint32(r-4,i,!1);const c=new Uint32Array(64);for(let f=0;f<r;f+=64){for(let b=0;b<16;b++)c[b]=a.getUint32(f+b*4,!1);for(let b=16;b<64;b++){const N=c[b-15],j=c[b-2],M=je(N,7)^je(N,18)^N>>>3,H=je(j,17)^je(j,19)^j>>>10;c[b]=c[b-16]+M+c[b-7]+H>>>0}let p=t[0],h=t[1],d=t[2],v=t[3],m=t[4],y=t[5],$=t[6],S=t[7];for(let b=0;b<64;b++){const N=je(m,6)^je(m,11)^je(m,25),j=m&y^~m&$,M=S+N+j+kg[b]+c[b]>>>0,H=je(p,2)^je(p,13)^je(p,22),Z=p&h^p&d^h&d,le=H+Z>>>0;S=$,$=y,y=m,m=v+M>>>0,v=d,d=h,h=p,p=M+le>>>0}t[0]=t[0]+p>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+d>>>0,t[3]=t[3]+v>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+y>>>0,t[6]=t[6]+$>>>0,t[7]=t[7]+S>>>0}const u=new Uint8Array(32),l=new DataView(u.buffer);for(let f=0;f<8;f++)l.setUint32(f*4,t[f],!1);return u}function jg(e){let t="";for(const n of e)t+=n.toString(16).padStart(2,"0");return t}function ll(e){const t=new TextEncoder().encode(e);return jg(Ig(t))}function fl(e,t=""){const n={};if(e===null||typeof e!="object"||Array.isArray(e))return t&&(n[t]=e),n;for(const[r,o]of Object.entries(e)){const s=t?`${t}.${r}`:r;o!==null&&typeof o=="object"&&!Array.isArray(o)?Object.assign(n,fl(o,s)):n[s]=o}return n}function xn(e){if(K.existsSync(e))try{const t=K.readFileSync(e,"utf8"),n=dg.parse(t);return n===null||typeof n!="object"||Array.isArray(n)?void 0:fl(n)}catch{return}}function Pg(e){return{system:xn(D.join(e.system,Zr)),global:xn(D.join(e.global,Zr)),project:e.project?xn(D.join(e.project,Zr)):void 0,local:e.project?xn(D.join(e.project,yg)):void 0}}function xg(e){const t={source:e.source,scope:e.scope};return e.source==="env"&&e.env!==void 0&&(t.env=e.env),t}function Io(e,t){if(e===void 0)return e;switch(t){case"integer":{if(typeof e=="number")return e;const n=parseInt(String(e),10);return Number.isNaN(n)?e:n}case"number":{if(typeof e=="number")return e;const n=parseFloat(String(e));return Number.isNaN(n)?e:n}case"boolean":{if(typeof e=="boolean")return e;const n=String(e).toLowerCase();return n==="true"?!0:n==="false"?!1:e}case"array":return Array.isArray(e)?e:typeof e=="string"?e.length===0?[]:e.split(",").map(n=>n.trim()):e;case"string":return typeof e=="string"?e:String(e);default:return e}}function dl(e){const t={};for(const n of Object.keys(e)){const r=n.split(".");let o=t;r.forEach((s,i)=>{if(i===r.length-1){o[s]=e[n];return}const a=o[s];(typeof a!="object"||a===null||Array.isArray(a))&&(o[s]={}),o=o[s]})}return t}const Tg=[["system","system"],["global","global"],["project","project"],["local","local"]];function Cg(e,t,n,r){const o={},s={},i={},a={};for(const c of Object.keys(e)){const u=e[c],l=u.env&&u.env!==""?u.env:Eg(r.prefix,c),f=u.at==="runtime"||u.secret===!0,p=u.scope??r.activeScope;let h=u.default,d="default";for(const[S,b]of Tg){const N=t[S];N&&Object.prototype.hasOwnProperty.call(N,c)&&(h=Io(N[c],u.type),d=b)}const v=n[l];let m,y,$;v!==void 0?(m=Io(v,u.type),y="env",$=l):(m=h,y=d),o[c]=f?_g(l):m,s[c]=m,i[c]=xg(f?{source:"env",scope:p,env:l}:{source:y,scope:p,env:$}),a[c]={...u,env:l,live:f,fallbackValue:h}}return{raw:o,nested:dl(o),typedRaw:s,provenance:i,fields:a}}function Rg(e,t){return e.replace(/\$\{HOME\}/g,Lt.homedir()).replace(/\$HOME\b/g,Lt.homedir()).replace(/\$\{PROJECT_ROOT\}/g,t.projectRoot??process.cwd()).replace(/\$\{NAMESPACE\}/g,t.namespace)}function Mg(e,t){const n={};for(const[r,o]of Object.entries(e??{})){const s=o.scope??t.activeScope,i=o.share??vg[o.kind],a=o.path?Rg(o.path,t):D.join($u(t.roots,s),r),c=i==="per-instance"?D.join(a,t.instanceId):a;n[r]={name:r,kind:o.kind,path:c,scope:s,share:i}}return n}function Dg(e,t){const n={};for(const[r,o]of Object.entries(e??{})){const s=t[o.in];if(!s)throw new Error(`files.${r}.in references unknown dirs key "${o.in}"`);n[r]={name:r,in:o.in,path:D.join(s.path,o.name),share:o.share??"shared"}}return n}var jo={exports:{}},pl={},Ie={},Ut={},bn={},V={},gn={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.regexpCode=e.getEsmExportName=e.getProperty=e.safeStringify=e.stringify=e.strConcat=e.addCodeArg=e.str=e._=e.nil=e._Code=e.Name=e.IDENTIFIER=e._CodeOrName=void 0;class t{}e._CodeOrName=t,e.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class n extends t{constructor($){if(super(),!e.IDENTIFIER.test($))throw new Error("CodeGen: name must be a valid identifier");this.str=$}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}e.Name=n;class r extends t{constructor($){super(),this._items=typeof $=="string"?[$]:$}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;const $=this._items[0];return $===""||$==='""'}get str(){var $;return($=this._str)!==null&&$!==void 0?$:this._str=this._items.reduce((S,b)=>`${S}${b}`,"")}get names(){var $;return($=this._names)!==null&&$!==void 0?$:this._names=this._items.reduce((S,b)=>(b instanceof n&&(S[b.str]=(S[b.str]||0)+1),S),{})}}e._Code=r,e.nil=new r("");function o(y,...$){const S=[y[0]];let b=0;for(;b<$.length;)a(S,$[b]),S.push(y[++b]);return new r(S)}e._=o;const s=new r("+");function i(y,...$){const S=[h(y[0])];let b=0;for(;b<$.length;)S.push(s),a(S,$[b]),S.push(s,h(y[++b]));return c(S),new r(S)}e.str=i;function a(y,$){$ instanceof r?y.push(...$._items):$ instanceof n?y.push($):y.push(f($))}e.addCodeArg=a;function c(y){let $=1;for(;$<y.length-1;){if(y[$]===s){const S=u(y[$-1],y[$+1]);if(S!==void 0){y.splice($-1,3,S);continue}y[$++]="+"}$++}}function u(y,$){if($==='""')return y;if(y==='""')return $;if(typeof y=="string")return $ instanceof n||y[y.length-1]!=='"'?void 0:typeof $!="string"?`${y.slice(0,-1)}${$}"`:$[0]==='"'?y.slice(0,-1)+$.slice(1):void 0;if(typeof $=="string"&&$[0]==='"'&&!(y instanceof n))return`"${y}${$.slice(1)}`}function l(y,$){return $.emptyStr()?y:y.emptyStr()?$:i`${y}${$}`}e.strConcat=l;function f(y){return typeof y=="number"||typeof y=="boolean"||y===null?y:h(Array.isArray(y)?y.join(","):y)}function p(y){return new r(h(y))}e.stringify=p;function h(y){return JSON.stringify(y).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}e.safeStringify=h;function d(y){return typeof y=="string"&&e.IDENTIFIER.test(y)?new r(`.${y}`):o`[${y}]`}e.getProperty=d;function v(y){if(typeof y=="string"&&e.IDENTIFIER.test(y))return new r(`${y}`);throw new Error(`CodeGen: invalid export name: ${y}, use explicit $id name mapping`)}e.getEsmExportName=v;function m(y){return new r(y.toString())}e.regexpCode=m})(gn);var Po={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ValueScope=e.ValueScopeName=e.Scope=e.varKinds=e.UsedValueState=void 0;const t=gn;class n extends Error{constructor(u){super(`CodeGen: "code" for ${u} not defined`),this.value=u.value}}var r;(function(c){c[c.Started=0]="Started",c[c.Completed=1]="Completed"})(r||(e.UsedValueState=r={})),e.varKinds={const:new t.Name("const"),let:new t.Name("let"),var:new t.Name("var")};class o{constructor({prefixes:u,parent:l}={}){this._names={},this._prefixes=u,this._parent=l}toName(u){return u instanceof t.Name?u:this.name(u)}name(u){return new t.Name(this._newName(u))}_newName(u){const l=this._names[u]||this._nameGroup(u);return`${u}${l.index++}`}_nameGroup(u){var l,f;if(!((f=(l=this._parent)===null||l===void 0?void 0:l._prefixes)===null||f===void 0)&&f.has(u)||this._prefixes&&!this._prefixes.has(u))throw new Error(`CodeGen: prefix "${u}" is not allowed in this scope`);return this._names[u]={prefix:u,index:0}}}e.Scope=o;class s extends t.Name{constructor(u,l){super(l),this.prefix=u}setValue(u,{property:l,itemIndex:f}){this.value=u,this.scopePath=(0,t._)`.${new t.Name(l)}[${f}]`}}e.ValueScopeName=s;const i=(0,t._)`\n`;class a extends o{constructor(u){super(u),this._values={},this._scope=u.scope,this.opts={...u,_n:u.lines?i:t.nil}}get(){return this._scope}name(u){return new s(u,this._newName(u))}value(u,l){var f;if(l.ref===void 0)throw new Error("CodeGen: ref must be passed in value");const p=this.toName(u),{prefix:h}=p,d=(f=l.key)!==null&&f!==void 0?f:l.ref;let v=this._values[h];if(v){const $=v.get(d);if($)return $}else v=this._values[h]=new Map;v.set(d,p);const m=this._scope[h]||(this._scope[h]=[]),y=m.length;return m[y]=l.ref,p.setValue(l,{property:h,itemIndex:y}),p}getValue(u,l){const f=this._values[u];if(f)return f.get(l)}scopeRefs(u,l=this._values){return this._reduceValues(l,f=>{if(f.scopePath===void 0)throw new Error(`CodeGen: name "${f}" has no value`);return(0,t._)`${u}${f.scopePath}`})}scopeCode(u=this._values,l,f){return this._reduceValues(u,p=>{if(p.value===void 0)throw new Error(`CodeGen: name "${p}" has no value`);return p.value.code},l,f)}_reduceValues(u,l,f={},p){let h=t.nil;for(const d in u){const v=u[d];if(!v)continue;const m=f[d]=f[d]||new Map;v.forEach(y=>{if(m.has(y))return;m.set(y,r.Started);let $=l(y);if($){const S=this.opts.es5?e.varKinds.var:e.varKinds.const;h=(0,t._)`${h}${S} ${y} = ${$};${this.opts._n}`}else if($=p==null?void 0:p(y))h=(0,t._)`${h}${$}${this.opts._n}`;else throw new n(y);m.set(y,r.Completed)})}return h}}e.ValueScope=a})(Po);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.or=e.and=e.not=e.CodeGen=e.operators=e.varKinds=e.ValueScopeName=e.ValueScope=e.Scope=e.Name=e.regexpCode=e.stringify=e.getProperty=e.nil=e.strConcat=e.str=e._=void 0;const t=gn,n=Po;var r=gn;Object.defineProperty(e,"_",{enumerable:!0,get:function(){return r._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return r.str}}),Object.defineProperty(e,"strConcat",{enumerable:!0,get:function(){return r.strConcat}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return r.nil}}),Object.defineProperty(e,"getProperty",{enumerable:!0,get:function(){return r.getProperty}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return r.stringify}}),Object.defineProperty(e,"regexpCode",{enumerable:!0,get:function(){return r.regexpCode}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return r.Name}});var o=Po;Object.defineProperty(e,"Scope",{enumerable:!0,get:function(){return o.Scope}}),Object.defineProperty(e,"ValueScope",{enumerable:!0,get:function(){return o.ValueScope}}),Object.defineProperty(e,"ValueScopeName",{enumerable:!0,get:function(){return o.ValueScopeName}}),Object.defineProperty(e,"varKinds",{enumerable:!0,get:function(){return o.varKinds}}),e.operators={GT:new t._Code(">"),GTE:new t._Code(">="),LT:new t._Code("<"),LTE:new t._Code("<="),EQ:new t._Code("==="),NEQ:new t._Code("!=="),NOT:new t._Code("!"),OR:new t._Code("||"),AND:new t._Code("&&"),ADD:new t._Code("+")};class s{optimizeNodes(){return this}optimizeNames(g,w){return this}}class i extends s{constructor(g,w,_){super(),this.varKind=g,this.name=w,this.rhs=_}render({es5:g,_n:w}){const _=g?n.varKinds.var:this.varKind,C=this.rhs===void 0?"":` = ${this.rhs}`;return`${_} ${this.name}${C};`+w}optimizeNames(g,w){if(g[this.name.str])return this.rhs&&(this.rhs=Ge(this.rhs,g,w)),this}get names(){return this.rhs instanceof t._CodeOrName?this.rhs.names:{}}}class a extends s{constructor(g,w,_){super(),this.lhs=g,this.rhs=w,this.sideEffects=_}render({_n:g}){return`${this.lhs} = ${this.rhs};`+g}optimizeNames(g,w){if(!(this.lhs instanceof t.Name&&!g[this.lhs.str]&&!this.sideEffects))return this.rhs=Ge(this.rhs,g,w),this}get names(){const g=this.lhs instanceof t.Name?{}:{...this.lhs.names};return Et(g,this.rhs)}}class c extends a{constructor(g,w,_,C){super(g,_,C),this.op=w}render({_n:g}){return`${this.lhs} ${this.op}= ${this.rhs};`+g}}class u extends s{constructor(g){super(),this.label=g,this.names={}}render({_n:g}){return`${this.label}:`+g}}class l extends s{constructor(g){super(),this.label=g,this.names={}}render({_n:g}){return`break${this.label?` ${this.label}`:""};`+g}}class f extends s{constructor(g){super(),this.error=g}render({_n:g}){return`throw ${this.error};`+g}get names(){return this.error.names}}class p extends s{constructor(g){super(),this.code=g}render({_n:g}){return`${this.code};`+g}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(g,w){return this.code=Ge(this.code,g,w),this}get names(){return this.code instanceof t._CodeOrName?this.code.names:{}}}class h extends s{constructor(g=[]){super(),this.nodes=g}render(g){return this.nodes.reduce((w,_)=>w+_.render(g),"")}optimizeNodes(){const{nodes:g}=this;let w=g.length;for(;w--;){const _=g[w].optimizeNodes();Array.isArray(_)?g.splice(w,1,..._):_?g[w]=_:g.splice(w,1)}return g.length>0?this:void 0}optimizeNames(g,w){const{nodes:_}=this;let C=_.length;for(;C--;){const R=_[C];R.optimizeNames(g,w)||(Wt(g,R.names),_.splice(C,1))}return _.length>0?this:void 0}get names(){return this.nodes.reduce((g,w)=>ye(g,w.names),{})}}class d extends h{render(g){return"{"+g._n+super.render(g)+"}"+g._n}}class v extends h{}class m extends d{}m.kind="else";class y extends d{constructor(g,w){super(w),this.condition=g}render(g){let w=`if(${this.condition})`+super.render(g);return this.else&&(w+="else "+this.else.render(g)),w}optimizeNodes(){super.optimizeNodes();const g=this.condition;if(g===!0)return this.nodes;let w=this.else;if(w){const _=w.optimizeNodes();w=this.else=Array.isArray(_)?new m(_):_}if(w)return g===!1?w instanceof y?w:w.nodes:this.nodes.length?this:new y(On(g),w instanceof y?[w]:w.nodes);if(!(g===!1||!this.nodes.length))return this}optimizeNames(g,w){var _;if(this.else=(_=this.else)===null||_===void 0?void 0:_.optimizeNames(g,w),!!(super.optimizeNames(g,w)||this.else))return this.condition=Ge(this.condition,g,w),this}get names(){const g=super.names;return Et(g,this.condition),this.else&&ye(g,this.else.names),g}}y.kind="if";class $ extends d{}$.kind="for";class S extends ${constructor(g){super(),this.iteration=g}render(g){return`for(${this.iteration})`+super.render(g)}optimizeNames(g,w){if(super.optimizeNames(g,w))return this.iteration=Ge(this.iteration,g,w),this}get names(){return ye(super.names,this.iteration.names)}}class b extends ${constructor(g,w,_,C){super(),this.varKind=g,this.name=w,this.from=_,this.to=C}render(g){const w=g.es5?n.varKinds.var:this.varKind,{name:_,from:C,to:R}=this;return`for(${w} ${_}=${C}; ${_}<${R}; ${_}++)`+super.render(g)}get names(){const g=Et(super.names,this.from);return Et(g,this.to)}}class N extends ${constructor(g,w,_,C){super(),this.loop=g,this.varKind=w,this.name=_,this.iterable=C}render(g){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(g)}optimizeNames(g,w){if(super.optimizeNames(g,w))return this.iterable=Ge(this.iterable,g,w),this}get names(){return ye(super.names,this.iterable.names)}}class j extends d{constructor(g,w,_){super(),this.name=g,this.args=w,this.async=_}render(g){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(g)}}j.kind="func";class M extends h{render(g){return"return "+super.render(g)}}M.kind="return";class H extends d{render(g){let w="try"+super.render(g);return this.catch&&(w+=this.catch.render(g)),this.finally&&(w+=this.finally.render(g)),w}optimizeNodes(){var g,w;return super.optimizeNodes(),(g=this.catch)===null||g===void 0||g.optimizeNodes(),(w=this.finally)===null||w===void 0||w.optimizeNodes(),this}optimizeNames(g,w){var _,C;return super.optimizeNames(g,w),(_=this.catch)===null||_===void 0||_.optimizeNames(g,w),(C=this.finally)===null||C===void 0||C.optimizeNames(g,w),this}get names(){const g=super.names;return this.catch&&ye(g,this.catch.names),this.finally&&ye(g,this.finally.names),g}}class Z extends d{constructor(g){super(),this.error=g}render(g){return`catch(${this.error})`+super.render(g)}}Z.kind="catch";class le extends d{render(g){return"finally"+super.render(g)}}le.kind="finally";class fe{constructor(g,w={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...w,_n:w.lines?`
156
+ `:""},this._extScope=g,this._scope=new n.Scope({parent:g}),this._nodes=[new v]}toString(){return this._root.render(this.opts)}name(g){return this._scope.name(g)}scopeName(g){return this._extScope.name(g)}scopeValue(g,w){const _=this._extScope.value(g,w);return(this._values[_.prefix]||(this._values[_.prefix]=new Set)).add(_),_}getScopeValue(g,w){return this._extScope.getValue(g,w)}scopeRefs(g){return this._extScope.scopeRefs(g,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(g,w,_,C){const R=this._scope.toName(w);return _!==void 0&&C&&(this._constants[R.str]=_),this._leafNode(new i(g,R,_)),R}const(g,w,_){return this._def(n.varKinds.const,g,w,_)}let(g,w,_){return this._def(n.varKinds.let,g,w,_)}var(g,w,_){return this._def(n.varKinds.var,g,w,_)}assign(g,w,_){return this._leafNode(new a(g,w,_))}add(g,w){return this._leafNode(new c(g,e.operators.ADD,w))}code(g){return typeof g=="function"?g():g!==t.nil&&this._leafNode(new p(g)),this}object(...g){const w=["{"];for(const[_,C]of g)w.length>1&&w.push(","),w.push(_),(_!==C||this.opts.es5)&&(w.push(":"),(0,t.addCodeArg)(w,C));return w.push("}"),new t._Code(w)}if(g,w,_){if(this._blockNode(new y(g)),w&&_)this.code(w).else().code(_).endIf();else if(w)this.code(w).endIf();else if(_)throw new Error('CodeGen: "else" body without "then" body');return this}elseIf(g){return this._elseNode(new y(g))}else(){return this._elseNode(new m)}endIf(){return this._endBlockNode(y,m)}_for(g,w){return this._blockNode(g),w&&this.code(w).endFor(),this}for(g,w){return this._for(new S(g),w)}forRange(g,w,_,C,R=this.opts.es5?n.varKinds.var:n.varKinds.let){const z=this._scope.toName(g);return this._for(new b(R,z,w,_),()=>C(z))}forOf(g,w,_,C=n.varKinds.const){const R=this._scope.toName(g);if(this.opts.es5){const z=w instanceof t.Name?w:this.var("_arr",w);return this.forRange("_i",0,(0,t._)`${z}.length`,G=>{this.var(R,(0,t._)`${z}[${G}]`),_(R)})}return this._for(new N("of",C,R,w),()=>_(R))}forIn(g,w,_,C=this.opts.es5?n.varKinds.var:n.varKinds.const){if(this.opts.ownProperties)return this.forOf(g,(0,t._)`Object.keys(${w})`,_);const R=this._scope.toName(g);return this._for(new N("in",C,R,w),()=>_(R))}endFor(){return this._endBlockNode($)}label(g){return this._leafNode(new u(g))}break(g){return this._leafNode(new l(g))}return(g){const w=new M;if(this._blockNode(w),this.code(g),w.nodes.length!==1)throw new Error('CodeGen: "return" should have one node');return this._endBlockNode(M)}try(g,w,_){if(!w&&!_)throw new Error('CodeGen: "try" without "catch" and "finally"');const C=new H;if(this._blockNode(C),this.code(g),w){const R=this.name("e");this._currNode=C.catch=new Z(R),w(R)}return _&&(this._currNode=C.finally=new le,this.code(_)),this._endBlockNode(Z,le)}throw(g){return this._leafNode(new f(g))}block(g,w){return this._blockStarts.push(this._nodes.length),g&&this.code(g).endBlock(w),this}endBlock(g){const w=this._blockStarts.pop();if(w===void 0)throw new Error("CodeGen: not in self-balancing block");const _=this._nodes.length-w;if(_<0||g!==void 0&&_!==g)throw new Error(`CodeGen: wrong number of nodes: ${_} vs ${g} expected`);return this._nodes.length=w,this}func(g,w=t.nil,_,C){return this._blockNode(new j(g,w,_)),C&&this.code(C).endFunc(),this}endFunc(){return this._endBlockNode(j)}optimize(g=1){for(;g-- >0;)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(g){return this._currNode.nodes.push(g),this}_blockNode(g){this._currNode.nodes.push(g),this._nodes.push(g)}_endBlockNode(g,w){const _=this._currNode;if(_ instanceof g||w&&_ instanceof w)return this._nodes.pop(),this;throw new Error(`CodeGen: not in block "${w?`${g.kind}/${w.kind}`:g.kind}"`)}_elseNode(g){const w=this._currNode;if(!(w instanceof y))throw new Error('CodeGen: "else" without "if"');return this._currNode=w.else=g,this}get _root(){return this._nodes[0]}get _currNode(){const g=this._nodes;return g[g.length-1]}set _currNode(g){const w=this._nodes;w[w.length-1]=g}}e.CodeGen=fe;function ye(O,g){for(const w in g)O[w]=(O[w]||0)+(g[w]||0);return O}function Et(O,g){return g instanceof t._CodeOrName?ye(O,g.names):O}function Ge(O,g,w){if(O instanceof t.Name)return _(O);if(!C(O))return O;return new t._Code(O._items.reduce((R,z)=>(z instanceof t.Name&&(z=_(z)),z instanceof t._Code?R.push(...z._items):R.push(z),R),[]));function _(R){const z=w[R.str];return z===void 0||g[R.str]!==1?R:(delete g[R.str],z)}function C(R){return R instanceof t._Code&&R._items.some(z=>z instanceof t.Name&&g[z.str]===1&&w[z.str]!==void 0)}}function Wt(O,g){for(const w in g)O[w]=(O[w]||0)-(g[w]||0)}function On(O){return typeof O=="boolean"||typeof O=="number"||O===null?!O:(0,t._)`!${A(O)}`}e.not=On;const Pr=E(e.operators.AND);function xr(...O){return O.reduce(Pr)}e.and=xr;const Nn=E(e.operators.OR);function P(...O){return O.reduce(Nn)}e.or=P;function E(O){return(g,w)=>g===t.nil?w:w===t.nil?g:(0,t._)`${A(g)} ${O} ${A(w)}`}function A(O){return O instanceof t.Name?O:(0,t._)`(${O})`}})(V);var x={};Object.defineProperty(x,"__esModule",{value:!0});x.checkStrictMode=x.getErrorPath=x.Type=x.useFunc=x.setEvaluated=x.evaluatedPropsToName=x.mergeEvaluated=x.eachItem=x.unescapeJsonPointer=x.escapeJsonPointer=x.escapeFragment=x.unescapeFragment=x.schemaRefOrVal=x.schemaHasRulesButRef=x.schemaHasRules=x.checkUnknownRules=x.alwaysValidSchema=x.toHash=void 0;const J=V,Lg=gn;function Bg(e){const t={};for(const n of e)t[n]=!0;return t}x.toHash=Bg;function Ug(e,t){return typeof t=="boolean"?t:Object.keys(t).length===0?!0:(hl(e,t),!ml(t,e.self.RULES.all))}x.alwaysValidSchema=Ug;function hl(e,t=e.schema){const{opts:n,self:r}=e;if(!n.strictSchema||typeof t=="boolean")return;const o=r.RULES.keywords;for(const s in t)o[s]||vl(e,`unknown keyword: "${s}"`)}x.checkUnknownRules=hl;function ml(e,t){if(typeof e=="boolean")return!e;for(const n in e)if(t[n])return!0;return!1}x.schemaHasRules=ml;function Fg(e,t){if(typeof e=="boolean")return!e;for(const n in e)if(n!=="$ref"&&t.all[n])return!0;return!1}x.schemaHasRulesButRef=Fg;function Vg({topSchemaRef:e,schemaPath:t},n,r,o){if(!o){if(typeof n=="number"||typeof n=="boolean")return n;if(typeof n=="string")return(0,J._)`${n}`}return(0,J._)`${e}${t}${(0,J.getProperty)(r)}`}x.schemaRefOrVal=Vg;function qg(e){return gl(decodeURIComponent(e))}x.unescapeFragment=qg;function Kg(e){return encodeURIComponent(As(e))}x.escapeFragment=Kg;function As(e){return typeof e=="number"?`${e}`:e.replace(/~/g,"~0").replace(/\//g,"~1")}x.escapeJsonPointer=As;function gl(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}x.unescapeJsonPointer=gl;function Gg(e,t){if(Array.isArray(e))for(const n of e)t(n);else t(e)}x.eachItem=Gg;function Ma({mergeNames:e,mergeToName:t,mergeValues:n,resultToName:r}){return(o,s,i,a)=>{const c=i===void 0?s:i instanceof J.Name?(s instanceof J.Name?e(o,s,i):t(o,s,i),i):s instanceof J.Name?(t(o,i,s),s):n(s,i);return a===J.Name&&!(c instanceof J.Name)?r(o,c):c}}x.mergeEvaluated={props:Ma({mergeNames:(e,t,n)=>e.if((0,J._)`${n} !== true && ${t} !== undefined`,()=>{e.if((0,J._)`${t} === true`,()=>e.assign(n,!0),()=>e.assign(n,(0,J._)`${n} || {}`).code((0,J._)`Object.assign(${n}, ${t})`))}),mergeToName:(e,t,n)=>e.if((0,J._)`${n} !== true`,()=>{t===!0?e.assign(n,!0):(e.assign(n,(0,J._)`${n} || {}`),Is(e,n,t))}),mergeValues:(e,t)=>e===!0?!0:{...e,...t},resultToName:yl}),items:Ma({mergeNames:(e,t,n)=>e.if((0,J._)`${n} !== true && ${t} !== undefined`,()=>e.assign(n,(0,J._)`${t} === true ? true : ${n} > ${t} ? ${n} : ${t}`)),mergeToName:(e,t,n)=>e.if((0,J._)`${n} !== true`,()=>e.assign(n,t===!0?!0:(0,J._)`${n} > ${t} ? ${n} : ${t}`)),mergeValues:(e,t)=>e===!0?!0:Math.max(e,t),resultToName:(e,t)=>e.var("items",t)})};function yl(e,t){if(t===!0)return e.var("props",!0);const n=e.var("props",(0,J._)`{}`);return t!==void 0&&Is(e,n,t),n}x.evaluatedPropsToName=yl;function Is(e,t,n){Object.keys(n).forEach(r=>e.assign((0,J._)`${t}${(0,J.getProperty)(r)}`,!0))}x.setEvaluated=Is;const Da={};function zg(e,t){return e.scopeValue("func",{ref:t,code:Da[t.code]||(Da[t.code]=new Lg._Code(t.code))})}x.useFunc=zg;var xo;(function(e){e[e.Num=0]="Num",e[e.Str=1]="Str"})(xo||(x.Type=xo={}));function Wg(e,t,n){if(e instanceof J.Name){const r=t===xo.Num;return n?r?(0,J._)`"[" + ${e} + "]"`:(0,J._)`"['" + ${e} + "']"`:r?(0,J._)`"/" + ${e}`:(0,J._)`"/" + ${e}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return n?(0,J.getProperty)(e).toString():"/"+As(e)}x.getErrorPath=Wg;function vl(e,t,n=e.opts.strictSchema){if(n){if(t=`strict mode: ${t}`,n===!0)throw new Error(t);e.self.logger.warn(t)}}x.checkStrictMode=vl;var Re={};Object.defineProperty(Re,"__esModule",{value:!0});const ce=V,Hg={data:new ce.Name("data"),valCxt:new ce.Name("valCxt"),instancePath:new ce.Name("instancePath"),parentData:new ce.Name("parentData"),parentDataProperty:new ce.Name("parentDataProperty"),rootData:new ce.Name("rootData"),dynamicAnchors:new ce.Name("dynamicAnchors"),vErrors:new ce.Name("vErrors"),errors:new ce.Name("errors"),this:new ce.Name("this"),self:new ce.Name("self"),scope:new ce.Name("scope"),json:new ce.Name("json"),jsonPos:new ce.Name("jsonPos"),jsonLen:new ce.Name("jsonLen"),jsonPart:new ce.Name("jsonPart")};Re.default=Hg;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.extendErrors=e.resetErrorsCount=e.reportExtraError=e.reportError=e.keyword$DataError=e.keywordError=void 0;const t=V,n=x,r=Re;e.keywordError={message:({keyword:m})=>(0,t.str)`must pass "${m}" keyword validation`},e.keyword$DataError={message:({keyword:m,schemaType:y})=>y?(0,t.str)`"${m}" keyword must be ${y} ($data)`:(0,t.str)`"${m}" keyword is invalid ($data)`};function o(m,y=e.keywordError,$,S){const{it:b}=m,{gen:N,compositeRule:j,allErrors:M}=b,H=f(m,y,$);S??(j||M)?c(N,H):u(b,(0,t._)`[${H}]`)}e.reportError=o;function s(m,y=e.keywordError,$){const{it:S}=m,{gen:b,compositeRule:N,allErrors:j}=S,M=f(m,y,$);c(b,M),N||j||u(S,r.default.vErrors)}e.reportExtraError=s;function i(m,y){m.assign(r.default.errors,y),m.if((0,t._)`${r.default.vErrors} !== null`,()=>m.if(y,()=>m.assign((0,t._)`${r.default.vErrors}.length`,y),()=>m.assign(r.default.vErrors,null)))}e.resetErrorsCount=i;function a({gen:m,keyword:y,schemaValue:$,data:S,errsCount:b,it:N}){if(b===void 0)throw new Error("ajv implementation error");const j=m.name("err");m.forRange("i",b,r.default.errors,M=>{m.const(j,(0,t._)`${r.default.vErrors}[${M}]`),m.if((0,t._)`${j}.instancePath === undefined`,()=>m.assign((0,t._)`${j}.instancePath`,(0,t.strConcat)(r.default.instancePath,N.errorPath))),m.assign((0,t._)`${j}.schemaPath`,(0,t.str)`${N.errSchemaPath}/${y}`),N.opts.verbose&&(m.assign((0,t._)`${j}.schema`,$),m.assign((0,t._)`${j}.data`,S))})}e.extendErrors=a;function c(m,y){const $=m.const("err",y);m.if((0,t._)`${r.default.vErrors} === null`,()=>m.assign(r.default.vErrors,(0,t._)`[${$}]`),(0,t._)`${r.default.vErrors}.push(${$})`),m.code((0,t._)`${r.default.errors}++`)}function u(m,y){const{gen:$,validateName:S,schemaEnv:b}=m;b.$async?$.throw((0,t._)`new ${m.ValidationError}(${y})`):($.assign((0,t._)`${S}.errors`,y),$.return(!1))}const l={keyword:new t.Name("keyword"),schemaPath:new t.Name("schemaPath"),params:new t.Name("params"),propertyName:new t.Name("propertyName"),message:new t.Name("message"),schema:new t.Name("schema"),parentSchema:new t.Name("parentSchema")};function f(m,y,$){const{createErrors:S}=m.it;return S===!1?(0,t._)`{}`:p(m,y,$)}function p(m,y,$={}){const{gen:S,it:b}=m,N=[h(b,$),d(m,$)];return v(m,y,N),S.object(...N)}function h({errorPath:m},{instancePath:y}){const $=y?(0,t.str)`${m}${(0,n.getErrorPath)(y,n.Type.Str)}`:m;return[r.default.instancePath,(0,t.strConcat)(r.default.instancePath,$)]}function d({keyword:m,it:{errSchemaPath:y}},{schemaPath:$,parentSchema:S}){let b=S?y:(0,t.str)`${y}/${m}`;return $&&(b=(0,t.str)`${b}${(0,n.getErrorPath)($,n.Type.Str)}`),[l.schemaPath,b]}function v(m,{params:y,message:$},S){const{keyword:b,data:N,schemaValue:j,it:M}=m,{opts:H,propertyName:Z,topSchemaRef:le,schemaPath:fe}=M;S.push([l.keyword,b],[l.params,typeof y=="function"?y(m):y||(0,t._)`{}`]),H.messages&&S.push([l.message,typeof $=="function"?$(m):$]),H.verbose&&S.push([l.schema,j],[l.parentSchema,(0,t._)`${le}${fe}`],[r.default.data,N]),Z&&S.push([l.propertyName,Z])}})(bn);Object.defineProperty(Ut,"__esModule",{value:!0});Ut.boolOrEmptySchema=Ut.topBoolOrEmptySchema=void 0;const Jg=bn,Yg=V,Qg=Re,Zg={message:"boolean schema is false"};function Xg(e){const{gen:t,schema:n,validateName:r}=e;n===!1?$l(e,!1):typeof n=="object"&&n.$async===!0?t.return(Qg.default.data):(t.assign((0,Yg._)`${r}.errors`,null),t.return(!0))}Ut.topBoolOrEmptySchema=Xg;function ey(e,t){const{gen:n,schema:r}=e;r===!1?(n.var(t,!1),$l(e)):n.var(t,!0)}Ut.boolOrEmptySchema=ey;function $l(e,t){const{gen:n,data:r}=e,o={gen:n,keyword:"false schema",data:r,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:e};(0,Jg.reportError)(o,Zg,void 0,t)}var te={},$t={};Object.defineProperty($t,"__esModule",{value:!0});$t.getRules=$t.isJSONType=void 0;const ty=["string","number","integer","boolean","null","object","array"],ny=new Set(ty);function ry(e){return typeof e=="string"&&ny.has(e)}$t.isJSONType=ry;function oy(){const e={number:{type:"number",rules:[]},string:{type:"string",rules:[]},array:{type:"array",rules:[]},object:{type:"object",rules:[]}};return{types:{...e,integer:!0,boolean:!0,null:!0},rules:[{rules:[]},e.number,e.string,e.array,e.object],post:{rules:[]},all:{},keywords:{}}}$t.getRules=oy;var Ue={};Object.defineProperty(Ue,"__esModule",{value:!0});Ue.shouldUseRule=Ue.shouldUseGroup=Ue.schemaHasRulesForType=void 0;function sy({schema:e,self:t},n){const r=t.RULES.types[n];return r&&r!==!0&&wl(e,r)}Ue.schemaHasRulesForType=sy;function wl(e,t){return t.rules.some(n=>bl(e,n))}Ue.shouldUseGroup=wl;function bl(e,t){var n;return e[t.keyword]!==void 0||((n=t.definition.implements)===null||n===void 0?void 0:n.some(r=>e[r]!==void 0))}Ue.shouldUseRule=bl;Object.defineProperty(te,"__esModule",{value:!0});te.reportTypeError=te.checkDataTypes=te.checkDataType=te.coerceAndCheckDataType=te.getJSONTypes=te.getSchemaTypes=te.DataType=void 0;const iy=$t,ay=Ue,cy=bn,U=V,El=x;var Mt;(function(e){e[e.Correct=0]="Correct",e[e.Wrong=1]="Wrong"})(Mt||(te.DataType=Mt={}));function uy(e){const t=Sl(e.type);if(t.includes("null")){if(e.nullable===!1)throw new Error("type: null contradicts nullable: false")}else{if(!t.length&&e.nullable!==void 0)throw new Error('"nullable" cannot be used without "type"');e.nullable===!0&&t.push("null")}return t}te.getSchemaTypes=uy;function Sl(e){const t=Array.isArray(e)?e:e?[e]:[];if(t.every(iy.isJSONType))return t;throw new Error("type must be JSONType or JSONType[]: "+t.join(","))}te.getJSONTypes=Sl;function ly(e,t){const{gen:n,data:r,opts:o}=e,s=fy(t,o.coerceTypes),i=t.length>0&&!(s.length===0&&t.length===1&&(0,ay.schemaHasRulesForType)(e,t[0]));if(i){const a=js(t,r,o.strictNumbers,Mt.Wrong);n.if(a,()=>{s.length?dy(e,t,s):Ps(e)})}return i}te.coerceAndCheckDataType=ly;const Ol=new Set(["string","number","integer","boolean","null"]);function fy(e,t){return t?e.filter(n=>Ol.has(n)||t==="array"&&n==="array"):[]}function dy(e,t,n){const{gen:r,data:o,opts:s}=e,i=r.let("dataType",(0,U._)`typeof ${o}`),a=r.let("coerced",(0,U._)`undefined`);s.coerceTypes==="array"&&r.if((0,U._)`${i} == 'object' && Array.isArray(${o}) && ${o}.length == 1`,()=>r.assign(o,(0,U._)`${o}[0]`).assign(i,(0,U._)`typeof ${o}`).if(js(t,o,s.strictNumbers),()=>r.assign(a,o))),r.if((0,U._)`${a} !== undefined`);for(const u of n)(Ol.has(u)||u==="array"&&s.coerceTypes==="array")&&c(u);r.else(),Ps(e),r.endIf(),r.if((0,U._)`${a} !== undefined`,()=>{r.assign(o,a),py(e,a)});function c(u){switch(u){case"string":r.elseIf((0,U._)`${i} == "number" || ${i} == "boolean"`).assign(a,(0,U._)`"" + ${o}`).elseIf((0,U._)`${o} === null`).assign(a,(0,U._)`""`);return;case"number":r.elseIf((0,U._)`${i} == "boolean" || ${o} === null
157
+ || (${i} == "string" && ${o} && ${o} == +${o})`).assign(a,(0,U._)`+${o}`);return;case"integer":r.elseIf((0,U._)`${i} === "boolean" || ${o} === null
158
+ || (${i} === "string" && ${o} && ${o} == +${o} && !(${o} % 1))`).assign(a,(0,U._)`+${o}`);return;case"boolean":r.elseIf((0,U._)`${o} === "false" || ${o} === 0 || ${o} === null`).assign(a,!1).elseIf((0,U._)`${o} === "true" || ${o} === 1`).assign(a,!0);return;case"null":r.elseIf((0,U._)`${o} === "" || ${o} === 0 || ${o} === false`),r.assign(a,null);return;case"array":r.elseIf((0,U._)`${i} === "string" || ${i} === "number"
159
+ || ${i} === "boolean" || ${o} === null`).assign(a,(0,U._)`[${o}]`)}}}function py({gen:e,parentData:t,parentDataProperty:n},r){e.if((0,U._)`${t} !== undefined`,()=>e.assign((0,U._)`${t}[${n}]`,r))}function To(e,t,n,r=Mt.Correct){const o=r===Mt.Correct?U.operators.EQ:U.operators.NEQ;let s;switch(e){case"null":return(0,U._)`${t} ${o} null`;case"array":s=(0,U._)`Array.isArray(${t})`;break;case"object":s=(0,U._)`${t} && typeof ${t} == "object" && !Array.isArray(${t})`;break;case"integer":s=i((0,U._)`!(${t} % 1) && !isNaN(${t})`);break;case"number":s=i();break;default:return(0,U._)`typeof ${t} ${o} ${e}`}return r===Mt.Correct?s:(0,U.not)(s);function i(a=U.nil){return(0,U.and)((0,U._)`typeof ${t} == "number"`,a,n?(0,U._)`isFinite(${t})`:U.nil)}}te.checkDataType=To;function js(e,t,n,r){if(e.length===1)return To(e[0],t,n,r);let o;const s=(0,El.toHash)(e);if(s.array&&s.object){const i=(0,U._)`typeof ${t} != "object"`;o=s.null?i:(0,U._)`!${t} || ${i}`,delete s.null,delete s.array,delete s.object}else o=U.nil;s.number&&delete s.integer;for(const i in s)o=(0,U.and)(o,To(i,t,n,r));return o}te.checkDataTypes=js;const hy={message:({schema:e})=>`must be ${e}`,params:({schema:e,schemaValue:t})=>typeof e=="string"?(0,U._)`{type: ${e}}`:(0,U._)`{type: ${t}}`};function Ps(e){const t=my(e);(0,cy.reportError)(t,hy)}te.reportTypeError=Ps;function my(e){const{gen:t,data:n,schema:r}=e,o=(0,El.schemaRefOrVal)(e,r,"type");return{gen:t,keyword:"type",data:n,schema:r.type,schemaCode:o,schemaValue:o,parentSchema:r,params:{},it:e}}var wr={};Object.defineProperty(wr,"__esModule",{value:!0});wr.assignDefaults=void 0;const Nt=V,gy=x;function yy(e,t){const{properties:n,items:r}=e.schema;if(t==="object"&&n)for(const o in n)La(e,o,n[o].default);else t==="array"&&Array.isArray(r)&&r.forEach((o,s)=>La(e,s,o.default))}wr.assignDefaults=yy;function La(e,t,n){const{gen:r,compositeRule:o,data:s,opts:i}=e;if(n===void 0)return;const a=(0,Nt._)`${s}${(0,Nt.getProperty)(t)}`;if(o){(0,gy.checkStrictMode)(e,`default is ignored for: ${a}`);return}let c=(0,Nt._)`${a} === undefined`;i.useDefaults==="empty"&&(c=(0,Nt._)`${c} || ${a} === null || ${a} === ""`),r.if(c,(0,Nt._)`${a} = ${(0,Nt.stringify)(n)}`)}var xe={},F={};Object.defineProperty(F,"__esModule",{value:!0});F.validateUnion=F.validateArray=F.usePattern=F.callValidateCode=F.schemaProperties=F.allSchemaProperties=F.noPropertyInData=F.propertyInData=F.isOwnProperty=F.hasPropFunc=F.reportMissingProp=F.checkMissingProp=F.checkReportMissingProp=void 0;const Y=V,xs=x,We=Re,vy=x;function $y(e,t){const{gen:n,data:r,it:o}=e;n.if(Cs(n,r,t,o.opts.ownProperties),()=>{e.setParams({missingProperty:(0,Y._)`${t}`},!0),e.error()})}F.checkReportMissingProp=$y;function wy({gen:e,data:t,it:{opts:n}},r,o){return(0,Y.or)(...r.map(s=>(0,Y.and)(Cs(e,t,s,n.ownProperties),(0,Y._)`${o} = ${s}`)))}F.checkMissingProp=wy;function by(e,t){e.setParams({missingProperty:t},!0),e.error()}F.reportMissingProp=by;function Nl(e){return e.scopeValue("func",{ref:Object.prototype.hasOwnProperty,code:(0,Y._)`Object.prototype.hasOwnProperty`})}F.hasPropFunc=Nl;function Ts(e,t,n){return(0,Y._)`${Nl(e)}.call(${t}, ${n})`}F.isOwnProperty=Ts;function Ey(e,t,n,r){const o=(0,Y._)`${t}${(0,Y.getProperty)(n)} !== undefined`;return r?(0,Y._)`${o} && ${Ts(e,t,n)}`:o}F.propertyInData=Ey;function Cs(e,t,n,r){const o=(0,Y._)`${t}${(0,Y.getProperty)(n)} === undefined`;return r?(0,Y.or)(o,(0,Y.not)(Ts(e,t,n))):o}F.noPropertyInData=Cs;function _l(e){return e?Object.keys(e).filter(t=>t!=="__proto__"):[]}F.allSchemaProperties=_l;function Sy(e,t){return _l(t).filter(n=>!(0,xs.alwaysValidSchema)(e,t[n]))}F.schemaProperties=Sy;function Oy({schemaCode:e,data:t,it:{gen:n,topSchemaRef:r,schemaPath:o,errorPath:s},it:i},a,c,u){const l=u?(0,Y._)`${e}, ${t}, ${r}${o}`:t,f=[[We.default.instancePath,(0,Y.strConcat)(We.default.instancePath,s)],[We.default.parentData,i.parentData],[We.default.parentDataProperty,i.parentDataProperty],[We.default.rootData,We.default.rootData]];i.opts.dynamicRef&&f.push([We.default.dynamicAnchors,We.default.dynamicAnchors]);const p=(0,Y._)`${l}, ${n.object(...f)}`;return c!==Y.nil?(0,Y._)`${a}.call(${c}, ${p})`:(0,Y._)`${a}(${p})`}F.callValidateCode=Oy;const Ny=(0,Y._)`new RegExp`;function _y({gen:e,it:{opts:t}},n){const r=t.unicodeRegExp?"u":"",{regExp:o}=t.code,s=o(n,r);return e.scopeValue("pattern",{key:s.toString(),ref:s,code:(0,Y._)`${o.code==="new RegExp"?Ny:(0,vy.useFunc)(e,o)}(${n}, ${r})`})}F.usePattern=_y;function ky(e){const{gen:t,data:n,keyword:r,it:o}=e,s=t.name("valid");if(o.allErrors){const a=t.let("valid",!0);return i(()=>t.assign(a,!1)),a}return t.var(s,!0),i(()=>t.break()),s;function i(a){const c=t.const("len",(0,Y._)`${n}.length`);t.forRange("i",0,c,u=>{e.subschema({keyword:r,dataProp:u,dataPropType:xs.Type.Num},s),t.if((0,Y.not)(s),a)})}}F.validateArray=ky;function Ay(e){const{gen:t,schema:n,keyword:r,it:o}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");if(n.some(a=>(0,xs.alwaysValidSchema)(o,a))&&!o.opts.unevaluated)return;const s=t.let("valid",!1),i=t.name("_valid");t.block(()=>n.forEach((a,c)=>{const u=e.subschema({keyword:r,schemaProp:c,compositeRule:!0},i);t.assign(s,(0,Y._)`${s} || ${i}`),e.mergeValidEvaluated(u,i)||t.if((0,Y.not)(s))})),e.result(s,()=>e.reset(),()=>e.error(!0))}F.validateUnion=Ay;Object.defineProperty(xe,"__esModule",{value:!0});xe.validateKeywordUsage=xe.validSchemaType=xe.funcKeywordCode=xe.macroKeywordCode=void 0;const de=V,ut=Re,Iy=F,jy=bn;function Py(e,t){const{gen:n,keyword:r,schema:o,parentSchema:s,it:i}=e,a=t.macro.call(i.self,o,s,i),c=kl(n,r,a);i.opts.validateSchema!==!1&&i.self.validateSchema(a,!0);const u=n.name("valid");e.subschema({schema:a,schemaPath:de.nil,errSchemaPath:`${i.errSchemaPath}/${r}`,topSchemaRef:c,compositeRule:!0},u),e.pass(u,()=>e.error(!0))}xe.macroKeywordCode=Py;function xy(e,t){var n;const{gen:r,keyword:o,schema:s,parentSchema:i,$data:a,it:c}=e;Cy(c,t);const u=!a&&t.compile?t.compile.call(c.self,s,i,c):t.validate,l=kl(r,o,u),f=r.let("valid");e.block$data(f,p),e.ok((n=t.valid)!==null&&n!==void 0?n:f);function p(){if(t.errors===!1)v(),t.modifying&&Ba(e),m(()=>e.error());else{const y=t.async?h():d();t.modifying&&Ba(e),m(()=>Ty(e,y))}}function h(){const y=r.let("ruleErrs",null);return r.try(()=>v((0,de._)`await `),$=>r.assign(f,!1).if((0,de._)`${$} instanceof ${c.ValidationError}`,()=>r.assign(y,(0,de._)`${$}.errors`),()=>r.throw($))),y}function d(){const y=(0,de._)`${l}.errors`;return r.assign(y,null),v(de.nil),y}function v(y=t.async?(0,de._)`await `:de.nil){const $=c.opts.passContext?ut.default.this:ut.default.self,S=!("compile"in t&&!a||t.schema===!1);r.assign(f,(0,de._)`${y}${(0,Iy.callValidateCode)(e,l,$,S)}`,t.modifying)}function m(y){var $;r.if((0,de.not)(($=t.valid)!==null&&$!==void 0?$:f),y)}}xe.funcKeywordCode=xy;function Ba(e){const{gen:t,data:n,it:r}=e;t.if(r.parentData,()=>t.assign(n,(0,de._)`${r.parentData}[${r.parentDataProperty}]`))}function Ty(e,t){const{gen:n}=e;n.if((0,de._)`Array.isArray(${t})`,()=>{n.assign(ut.default.vErrors,(0,de._)`${ut.default.vErrors} === null ? ${t} : ${ut.default.vErrors}.concat(${t})`).assign(ut.default.errors,(0,de._)`${ut.default.vErrors}.length`),(0,jy.extendErrors)(e)},()=>e.error())}function Cy({schemaEnv:e},t){if(t.async&&!e.$async)throw new Error("async keyword in sync schema")}function kl(e,t,n){if(n===void 0)throw new Error(`keyword "${t}" failed to compile`);return e.scopeValue("keyword",typeof n=="function"?{ref:n}:{ref:n,code:(0,de.stringify)(n)})}function Ry(e,t,n=!1){return!t.length||t.some(r=>r==="array"?Array.isArray(e):r==="object"?e&&typeof e=="object"&&!Array.isArray(e):typeof e==r||n&&typeof e>"u")}xe.validSchemaType=Ry;function My({schema:e,opts:t,self:n,errSchemaPath:r},o,s){if(Array.isArray(o.keyword)?!o.keyword.includes(s):o.keyword!==s)throw new Error("ajv implementation error");const i=o.dependencies;if(i!=null&&i.some(a=>!Object.prototype.hasOwnProperty.call(e,a)))throw new Error(`parent schema must have dependencies of ${s}: ${i.join(",")}`);if(o.validateSchema&&!o.validateSchema(e[s])){const a=`keyword "${s}" value is invalid at path "${r}": `+n.errorsText(o.validateSchema.errors);if(t.validateSchema==="log")n.logger.error(a);else throw new Error(a)}}xe.validateKeywordUsage=My;var et={};Object.defineProperty(et,"__esModule",{value:!0});et.extendSubschemaMode=et.extendSubschemaData=et.getSubschema=void 0;const Pe=V,Al=x;function Dy(e,{keyword:t,schemaProp:n,schema:r,schemaPath:o,errSchemaPath:s,topSchemaRef:i}){if(t!==void 0&&r!==void 0)throw new Error('both "keyword" and "schema" passed, only one allowed');if(t!==void 0){const a=e.schema[t];return n===void 0?{schema:a,schemaPath:(0,Pe._)`${e.schemaPath}${(0,Pe.getProperty)(t)}`,errSchemaPath:`${e.errSchemaPath}/${t}`}:{schema:a[n],schemaPath:(0,Pe._)`${e.schemaPath}${(0,Pe.getProperty)(t)}${(0,Pe.getProperty)(n)}`,errSchemaPath:`${e.errSchemaPath}/${t}/${(0,Al.escapeFragment)(n)}`}}if(r!==void 0){if(o===void 0||s===void 0||i===void 0)throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');return{schema:r,schemaPath:o,topSchemaRef:i,errSchemaPath:s}}throw new Error('either "keyword" or "schema" must be passed')}et.getSubschema=Dy;function Ly(e,t,{dataProp:n,dataPropType:r,data:o,dataTypes:s,propertyName:i}){if(o!==void 0&&n!==void 0)throw new Error('both "data" and "dataProp" passed, only one allowed');const{gen:a}=t;if(n!==void 0){const{errorPath:u,dataPathArr:l,opts:f}=t,p=a.let("data",(0,Pe._)`${t.data}${(0,Pe.getProperty)(n)}`,!0);c(p),e.errorPath=(0,Pe.str)`${u}${(0,Al.getErrorPath)(n,r,f.jsPropertySyntax)}`,e.parentDataProperty=(0,Pe._)`${n}`,e.dataPathArr=[...l,e.parentDataProperty]}if(o!==void 0){const u=o instanceof Pe.Name?o:a.let("data",o,!0);c(u),i!==void 0&&(e.propertyName=i)}s&&(e.dataTypes=s);function c(u){e.data=u,e.dataLevel=t.dataLevel+1,e.dataTypes=[],t.definedProperties=new Set,e.parentData=t.data,e.dataNames=[...t.dataNames,u]}}et.extendSubschemaData=Ly;function By(e,{jtdDiscriminator:t,jtdMetadata:n,compositeRule:r,createErrors:o,allErrors:s}){r!==void 0&&(e.compositeRule=r),o!==void 0&&(e.createErrors=o),s!==void 0&&(e.allErrors=s),e.jtdDiscriminator=t,e.jtdMetadata=n}et.extendSubschemaMode=By;var se={},Il=function e(t,n){if(t===n)return!0;if(t&&n&&typeof t=="object"&&typeof n=="object"){if(t.constructor!==n.constructor)return!1;var r,o,s;if(Array.isArray(t)){if(r=t.length,r!=n.length)return!1;for(o=r;o--!==0;)if(!e(t[o],n[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(s=Object.keys(t),r=s.length,r!==Object.keys(n).length)return!1;for(o=r;o--!==0;)if(!Object.prototype.hasOwnProperty.call(n,s[o]))return!1;for(o=r;o--!==0;){var i=s[o];if(!e(t[i],n[i]))return!1}return!0}return t!==t&&n!==n},jl={exports:{}},Qe=jl.exports=function(e,t,n){typeof t=="function"&&(n=t,t={}),n=t.cb||n;var r=typeof n=="function"?n:n.pre||function(){},o=n.post||function(){};Wn(t,r,o,e,"",e)};Qe.keywords={additionalItems:!0,items:!0,contains:!0,additionalProperties:!0,propertyNames:!0,not:!0,if:!0,then:!0,else:!0};Qe.arrayKeywords={items:!0,allOf:!0,anyOf:!0,oneOf:!0};Qe.propsKeywords={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependencies:!0};Qe.skipKeywords={default:!0,enum:!0,const:!0,required:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0};function Wn(e,t,n,r,o,s,i,a,c,u){if(r&&typeof r=="object"&&!Array.isArray(r)){t(r,o,s,i,a,c,u);for(var l in r){var f=r[l];if(Array.isArray(f)){if(l in Qe.arrayKeywords)for(var p=0;p<f.length;p++)Wn(e,t,n,f[p],o+"/"+l+"/"+p,s,o,l,r,p)}else if(l in Qe.propsKeywords){if(f&&typeof f=="object")for(var h in f)Wn(e,t,n,f[h],o+"/"+l+"/"+Uy(h),s,o,l,r,h)}else(l in Qe.keywords||e.allKeys&&!(l in Qe.skipKeywords))&&Wn(e,t,n,f,o+"/"+l,s,o,l,r)}n(r,o,s,i,a,c,u)}}function Uy(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var Fy=jl.exports;Object.defineProperty(se,"__esModule",{value:!0});se.getSchemaRefs=se.resolveUrl=se.normalizeId=se._getFullPath=se.getFullPath=se.inlineRef=void 0;const Vy=x,qy=Il,Ky=Fy,Gy=new Set(["type","format","pattern","maxLength","minLength","maxProperties","minProperties","maxItems","minItems","maximum","minimum","uniqueItems","multipleOf","required","enum","const"]);function zy(e,t=!0){return typeof e=="boolean"?!0:t===!0?!Co(e):t?Pl(e)<=t:!1}se.inlineRef=zy;const Wy=new Set(["$ref","$recursiveRef","$recursiveAnchor","$dynamicRef","$dynamicAnchor"]);function Co(e){for(const t in e){if(Wy.has(t))return!0;const n=e[t];if(Array.isArray(n)&&n.some(Co)||typeof n=="object"&&Co(n))return!0}return!1}function Pl(e){let t=0;for(const n in e)if(n==="$ref"||(t++,!Gy.has(n)&&(typeof e[n]=="object"&&(0,Vy.eachItem)(e[n],r=>t+=Pl(r)),t===1/0)))return 1/0;return t}function xl(e,t="",n){n!==!1&&(t=Dt(t));const r=e.parse(t);return Tl(e,r)}se.getFullPath=xl;function Tl(e,t){return e.serialize(t).split("#")[0]+"#"}se._getFullPath=Tl;const Hy=/#\/?$/;function Dt(e){return e?e.replace(Hy,""):""}se.normalizeId=Dt;function Jy(e,t,n){return n=Dt(n),e.resolve(t,n)}se.resolveUrl=Jy;const Yy=/^[a-z_][-a-z0-9._]*$/i;function Qy(e,t){if(typeof e=="boolean")return{};const{schemaId:n,uriResolver:r}=this.opts,o=Dt(e[n]||t),s={"":o},i=xl(r,o,!1),a={},c=new Set;return Ky(e,{allKeys:!0},(f,p,h,d)=>{if(d===void 0)return;const v=i+p;let m=s[d];typeof f[n]=="string"&&(m=y.call(this,f[n])),$.call(this,f.$anchor),$.call(this,f.$dynamicAnchor),s[p]=m;function y(S){const b=this.opts.uriResolver.resolve;if(S=Dt(m?b(m,S):S),c.has(S))throw l(S);c.add(S);let N=this.refs[S];return typeof N=="string"&&(N=this.refs[N]),typeof N=="object"?u(f,N.schema,S):S!==Dt(v)&&(S[0]==="#"?(u(f,a[S],S),a[S]=f):this.refs[S]=v),S}function $(S){if(typeof S=="string"){if(!Yy.test(S))throw new Error(`invalid anchor "${S}"`);y.call(this,`#${S}`)}}}),a;function u(f,p,h){if(p!==void 0&&!qy(f,p))throw l(h)}function l(f){return new Error(`reference "${f}" resolves to more than one schema`)}}se.getSchemaRefs=Qy;Object.defineProperty(Ie,"__esModule",{value:!0});Ie.getData=Ie.KeywordCxt=Ie.validateFunctionCode=void 0;const Cl=Ut,Ua=te,Rs=Ue,rr=te,Zy=wr,an=xe,Xr=et,T=V,L=Re,Xy=se,Fe=x,Jt=bn;function ev(e){if(Dl(e)&&(Ll(e),Ml(e))){rv(e);return}Rl(e,()=>(0,Cl.topBoolOrEmptySchema)(e))}Ie.validateFunctionCode=ev;function Rl({gen:e,validateName:t,schema:n,schemaEnv:r,opts:o},s){o.code.es5?e.func(t,(0,T._)`${L.default.data}, ${L.default.valCxt}`,r.$async,()=>{e.code((0,T._)`"use strict"; ${Fa(n,o)}`),nv(e,o),e.code(s)}):e.func(t,(0,T._)`${L.default.data}, ${tv(o)}`,r.$async,()=>e.code(Fa(n,o)).code(s))}function tv(e){return(0,T._)`{${L.default.instancePath}="", ${L.default.parentData}, ${L.default.parentDataProperty}, ${L.default.rootData}=${L.default.data}${e.dynamicRef?(0,T._)`, ${L.default.dynamicAnchors}={}`:T.nil}}={}`}function nv(e,t){e.if(L.default.valCxt,()=>{e.var(L.default.instancePath,(0,T._)`${L.default.valCxt}.${L.default.instancePath}`),e.var(L.default.parentData,(0,T._)`${L.default.valCxt}.${L.default.parentData}`),e.var(L.default.parentDataProperty,(0,T._)`${L.default.valCxt}.${L.default.parentDataProperty}`),e.var(L.default.rootData,(0,T._)`${L.default.valCxt}.${L.default.rootData}`),t.dynamicRef&&e.var(L.default.dynamicAnchors,(0,T._)`${L.default.valCxt}.${L.default.dynamicAnchors}`)},()=>{e.var(L.default.instancePath,(0,T._)`""`),e.var(L.default.parentData,(0,T._)`undefined`),e.var(L.default.parentDataProperty,(0,T._)`undefined`),e.var(L.default.rootData,L.default.data),t.dynamicRef&&e.var(L.default.dynamicAnchors,(0,T._)`{}`)})}function rv(e){const{schema:t,opts:n,gen:r}=e;Rl(e,()=>{n.$comment&&t.$comment&&Ul(e),cv(e),r.let(L.default.vErrors,null),r.let(L.default.errors,0),n.unevaluated&&ov(e),Bl(e),fv(e)})}function ov(e){const{gen:t,validateName:n}=e;e.evaluated=t.const("evaluated",(0,T._)`${n}.evaluated`),t.if((0,T._)`${e.evaluated}.dynamicProps`,()=>t.assign((0,T._)`${e.evaluated}.props`,(0,T._)`undefined`)),t.if((0,T._)`${e.evaluated}.dynamicItems`,()=>t.assign((0,T._)`${e.evaluated}.items`,(0,T._)`undefined`))}function Fa(e,t){const n=typeof e=="object"&&e[t.schemaId];return n&&(t.code.source||t.code.process)?(0,T._)`/*# sourceURL=${n} */`:T.nil}function sv(e,t){if(Dl(e)&&(Ll(e),Ml(e))){iv(e,t);return}(0,Cl.boolOrEmptySchema)(e,t)}function Ml({schema:e,self:t}){if(typeof e=="boolean")return!e;for(const n in e)if(t.RULES.all[n])return!0;return!1}function Dl(e){return typeof e.schema!="boolean"}function iv(e,t){const{schema:n,gen:r,opts:o}=e;o.$comment&&n.$comment&&Ul(e),uv(e),lv(e);const s=r.const("_errs",L.default.errors);Bl(e,s),r.var(t,(0,T._)`${s} === ${L.default.errors}`)}function Ll(e){(0,Fe.checkUnknownRules)(e),av(e)}function Bl(e,t){if(e.opts.jtd)return Va(e,[],!1,t);const n=(0,Ua.getSchemaTypes)(e.schema),r=(0,Ua.coerceAndCheckDataType)(e,n);Va(e,n,!r,t)}function av(e){const{schema:t,errSchemaPath:n,opts:r,self:o}=e;t.$ref&&r.ignoreKeywordsWithRef&&(0,Fe.schemaHasRulesButRef)(t,o.RULES)&&o.logger.warn(`$ref: keywords ignored in schema at path "${n}"`)}function cv(e){const{schema:t,opts:n}=e;t.default!==void 0&&n.useDefaults&&n.strictSchema&&(0,Fe.checkStrictMode)(e,"default is ignored in the schema root")}function uv(e){const t=e.schema[e.opts.schemaId];t&&(e.baseId=(0,Xy.resolveUrl)(e.opts.uriResolver,e.baseId,t))}function lv(e){if(e.schema.$async&&!e.schemaEnv.$async)throw new Error("async schema in sync schema")}function Ul({gen:e,schemaEnv:t,schema:n,errSchemaPath:r,opts:o}){const s=n.$comment;if(o.$comment===!0)e.code((0,T._)`${L.default.self}.logger.log(${s})`);else if(typeof o.$comment=="function"){const i=(0,T.str)`${r}/$comment`,a=e.scopeValue("root",{ref:t.root});e.code((0,T._)`${L.default.self}.opts.$comment(${s}, ${i}, ${a}.schema)`)}}function fv(e){const{gen:t,schemaEnv:n,validateName:r,ValidationError:o,opts:s}=e;n.$async?t.if((0,T._)`${L.default.errors} === 0`,()=>t.return(L.default.data),()=>t.throw((0,T._)`new ${o}(${L.default.vErrors})`)):(t.assign((0,T._)`${r}.errors`,L.default.vErrors),s.unevaluated&&dv(e),t.return((0,T._)`${L.default.errors} === 0`))}function dv({gen:e,evaluated:t,props:n,items:r}){n instanceof T.Name&&e.assign((0,T._)`${t}.props`,n),r instanceof T.Name&&e.assign((0,T._)`${t}.items`,r)}function Va(e,t,n,r){const{gen:o,schema:s,data:i,allErrors:a,opts:c,self:u}=e,{RULES:l}=u;if(s.$ref&&(c.ignoreKeywordsWithRef||!(0,Fe.schemaHasRulesButRef)(s,l))){o.block(()=>ql(e,"$ref",l.all.$ref.definition));return}c.jtd||pv(e,t),o.block(()=>{for(const p of l.rules)f(p);f(l.post)});function f(p){(0,Rs.shouldUseGroup)(s,p)&&(p.type?(o.if((0,rr.checkDataType)(p.type,i,c.strictNumbers)),qa(e,p),t.length===1&&t[0]===p.type&&n&&(o.else(),(0,rr.reportTypeError)(e)),o.endIf()):qa(e,p),a||o.if((0,T._)`${L.default.errors} === ${r||0}`))}}function qa(e,t){const{gen:n,schema:r,opts:{useDefaults:o}}=e;o&&(0,Zy.assignDefaults)(e,t.type),n.block(()=>{for(const s of t.rules)(0,Rs.shouldUseRule)(r,s)&&ql(e,s.keyword,s.definition,t.type)})}function pv(e,t){e.schemaEnv.meta||!e.opts.strictTypes||(hv(e,t),e.opts.allowUnionTypes||mv(e,t),gv(e,e.dataTypes))}function hv(e,t){if(t.length){if(!e.dataTypes.length){e.dataTypes=t;return}t.forEach(n=>{Fl(e.dataTypes,n)||Ms(e,`type "${n}" not allowed by context "${e.dataTypes.join(",")}"`)}),vv(e,t)}}function mv(e,t){t.length>1&&!(t.length===2&&t.includes("null"))&&Ms(e,"use allowUnionTypes to allow union type keyword")}function gv(e,t){const n=e.self.RULES.all;for(const r in n){const o=n[r];if(typeof o=="object"&&(0,Rs.shouldUseRule)(e.schema,o)){const{type:s}=o.definition;s.length&&!s.some(i=>yv(t,i))&&Ms(e,`missing type "${s.join(",")}" for keyword "${r}"`)}}}function yv(e,t){return e.includes(t)||t==="number"&&e.includes("integer")}function Fl(e,t){return e.includes(t)||t==="integer"&&e.includes("number")}function vv(e,t){const n=[];for(const r of e.dataTypes)Fl(t,r)?n.push(r):t.includes("integer")&&r==="number"&&n.push("integer");e.dataTypes=n}function Ms(e,t){const n=e.schemaEnv.baseId+e.errSchemaPath;t+=` at "${n}" (strictTypes)`,(0,Fe.checkStrictMode)(e,t,e.opts.strictTypes)}class Vl{constructor(t,n,r){if((0,an.validateKeywordUsage)(t,n,r),this.gen=t.gen,this.allErrors=t.allErrors,this.keyword=r,this.data=t.data,this.schema=t.schema[r],this.$data=n.$data&&t.opts.$data&&this.schema&&this.schema.$data,this.schemaValue=(0,Fe.schemaRefOrVal)(t,this.schema,r,this.$data),this.schemaType=n.schemaType,this.parentSchema=t.schema,this.params={},this.it=t,this.def=n,this.$data)this.schemaCode=t.gen.const("vSchema",Kl(this.$data,t));else if(this.schemaCode=this.schemaValue,!(0,an.validSchemaType)(this.schema,n.schemaType,n.allowUndefined))throw new Error(`${r} value must be ${JSON.stringify(n.schemaType)}`);("code"in n?n.trackErrors:n.errors!==!1)&&(this.errsCount=t.gen.const("_errs",L.default.errors))}result(t,n,r){this.failResult((0,T.not)(t),n,r)}failResult(t,n,r){this.gen.if(t),r?r():this.error(),n?(this.gen.else(),n(),this.allErrors&&this.gen.endIf()):this.allErrors?this.gen.endIf():this.gen.else()}pass(t,n){this.failResult((0,T.not)(t),void 0,n)}fail(t){if(t===void 0){this.error(),this.allErrors||this.gen.if(!1);return}this.gen.if(t),this.error(),this.allErrors?this.gen.endIf():this.gen.else()}fail$data(t){if(!this.$data)return this.fail(t);const{schemaCode:n}=this;this.fail((0,T._)`${n} !== undefined && (${(0,T.or)(this.invalid$data(),t)})`)}error(t,n,r){if(n){this.setParams(n),this._error(t,r),this.setParams({});return}this._error(t,r)}_error(t,n){(t?Jt.reportExtraError:Jt.reportError)(this,this.def.error,n)}$dataError(){(0,Jt.reportError)(this,this.def.$dataError||Jt.keyword$DataError)}reset(){if(this.errsCount===void 0)throw new Error('add "trackErrors" to keyword definition');(0,Jt.resetErrorsCount)(this.gen,this.errsCount)}ok(t){this.allErrors||this.gen.if(t)}setParams(t,n){n?Object.assign(this.params,t):this.params=t}block$data(t,n,r=T.nil){this.gen.block(()=>{this.check$data(t,r),n()})}check$data(t=T.nil,n=T.nil){if(!this.$data)return;const{gen:r,schemaCode:o,schemaType:s,def:i}=this;r.if((0,T.or)((0,T._)`${o} === undefined`,n)),t!==T.nil&&r.assign(t,!0),(s.length||i.validateSchema)&&(r.elseIf(this.invalid$data()),this.$dataError(),t!==T.nil&&r.assign(t,!1)),r.else()}invalid$data(){const{gen:t,schemaCode:n,schemaType:r,def:o,it:s}=this;return(0,T.or)(i(),a());function i(){if(r.length){if(!(n instanceof T.Name))throw new Error("ajv implementation error");const c=Array.isArray(r)?r:[r];return(0,T._)`${(0,rr.checkDataTypes)(c,n,s.opts.strictNumbers,rr.DataType.Wrong)}`}return T.nil}function a(){if(o.validateSchema){const c=t.scopeValue("validate$data",{ref:o.validateSchema});return(0,T._)`!${c}(${n})`}return T.nil}}subschema(t,n){const r=(0,Xr.getSubschema)(this.it,t);(0,Xr.extendSubschemaData)(r,this.it,t),(0,Xr.extendSubschemaMode)(r,t);const o={...this.it,...r,items:void 0,props:void 0};return sv(o,n),o}mergeEvaluated(t,n){const{it:r,gen:o}=this;r.opts.unevaluated&&(r.props!==!0&&t.props!==void 0&&(r.props=Fe.mergeEvaluated.props(o,t.props,r.props,n)),r.items!==!0&&t.items!==void 0&&(r.items=Fe.mergeEvaluated.items(o,t.items,r.items,n)))}mergeValidEvaluated(t,n){const{it:r,gen:o}=this;if(r.opts.unevaluated&&(r.props!==!0||r.items!==!0))return o.if(n,()=>this.mergeEvaluated(t,T.Name)),!0}}Ie.KeywordCxt=Vl;function ql(e,t,n,r){const o=new Vl(e,n,t);"code"in n?n.code(o,r):o.$data&&n.validate?(0,an.funcKeywordCode)(o,n):"macro"in n?(0,an.macroKeywordCode)(o,n):(n.compile||n.validate)&&(0,an.funcKeywordCode)(o,n)}const $v=/^\/(?:[^~]|~0|~1)*$/,wv=/^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;function Kl(e,{dataLevel:t,dataNames:n,dataPathArr:r}){let o,s;if(e==="")return L.default.rootData;if(e[0]==="/"){if(!$v.test(e))throw new Error(`Invalid JSON-pointer: ${e}`);o=e,s=L.default.rootData}else{const u=wv.exec(e);if(!u)throw new Error(`Invalid JSON-pointer: ${e}`);const l=+u[1];if(o=u[2],o==="#"){if(l>=t)throw new Error(c("property/index",l));return r[t-l]}if(l>t)throw new Error(c("data",l));if(s=n[t-l],!o)return s}let i=s;const a=o.split("/");for(const u of a)u&&(s=(0,T._)`${s}${(0,T.getProperty)((0,Fe.unescapeJsonPointer)(u))}`,i=(0,T._)`${i} && ${s}`);return i;function c(u,l){return`Cannot access ${u} ${l} levels up, current level is ${t}`}}Ie.getData=Kl;var En={};Object.defineProperty(En,"__esModule",{value:!0});let bv=class extends Error{constructor(e){super("validation failed"),this.errors=e,this.ajv=this.validation=!0}};En.default=bv;var Kt={};Object.defineProperty(Kt,"__esModule",{value:!0});const eo=se;class Ev extends Error{constructor(t,n,r,o){super(o||`can't resolve reference ${r} from id ${n}`),this.missingRef=(0,eo.resolveUrl)(t,n,r),this.missingSchema=(0,eo.normalizeId)((0,eo.getFullPath)(t,this.missingRef))}}Kt.default=Ev;var ge={};Object.defineProperty(ge,"__esModule",{value:!0});ge.resolveSchema=ge.getCompilingSchema=ge.resolveRef=ge.compileSchema=ge.SchemaEnv=void 0;const Oe=V,Sv=En,ot=Re,_e=se,Ka=x,Ov=Ie;class br{constructor(t){var n;this.refs={},this.dynamicAnchors={};let r;typeof t.schema=="object"&&(r=t.schema),this.schema=t.schema,this.schemaId=t.schemaId,this.root=t.root||this,this.baseId=(n=t.baseId)!==null&&n!==void 0?n:(0,_e.normalizeId)(r==null?void 0:r[t.schemaId||"$id"]),this.schemaPath=t.schemaPath,this.localRefs=t.localRefs,this.meta=t.meta,this.$async=r==null?void 0:r.$async,this.refs={}}}ge.SchemaEnv=br;function Ds(e){const t=Gl.call(this,e);if(t)return t;const n=(0,_e.getFullPath)(this.opts.uriResolver,e.root.baseId),{es5:r,lines:o}=this.opts.code,{ownProperties:s}=this.opts,i=new Oe.CodeGen(this.scope,{es5:r,lines:o,ownProperties:s});let a;e.$async&&(a=i.scopeValue("Error",{ref:Sv.default,code:(0,Oe._)`require("ajv/dist/runtime/validation_error").default`}));const c=i.scopeName("validate");e.validateName=c;const u={gen:i,allErrors:this.opts.allErrors,data:ot.default.data,parentData:ot.default.parentData,parentDataProperty:ot.default.parentDataProperty,dataNames:[ot.default.data],dataPathArr:[Oe.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:i.scopeValue("schema",this.opts.code.source===!0?{ref:e.schema,code:(0,Oe.stringify)(e.schema)}:{ref:e.schema}),validateName:c,ValidationError:a,schema:e.schema,schemaEnv:e,rootId:n,baseId:e.baseId||n,schemaPath:Oe.nil,errSchemaPath:e.schemaPath||(this.opts.jtd?"":"#"),errorPath:(0,Oe._)`""`,opts:this.opts,self:this};let l;try{this._compilations.add(e),(0,Ov.validateFunctionCode)(u),i.optimize(this.opts.code.optimize);const f=i.toString();l=`${i.scopeRefs(ot.default.scope)}return ${f}`,this.opts.code.process&&(l=this.opts.code.process(l,e));const p=new Function(`${ot.default.self}`,`${ot.default.scope}`,l)(this,this.scope.get());if(this.scope.value(c,{ref:p}),p.errors=null,p.schema=e.schema,p.schemaEnv=e,e.$async&&(p.$async=!0),this.opts.code.source===!0&&(p.source={validateName:c,validateCode:f,scopeValues:i._values}),this.opts.unevaluated){const{props:h,items:d}=u;p.evaluated={props:h instanceof Oe.Name?void 0:h,items:d instanceof Oe.Name?void 0:d,dynamicProps:h instanceof Oe.Name,dynamicItems:d instanceof Oe.Name},p.source&&(p.source.evaluated=(0,Oe.stringify)(p.evaluated))}return e.validate=p,e}catch(f){throw delete e.validate,delete e.validateName,l&&this.logger.error("Error compiling schema, function code:",l),f}finally{this._compilations.delete(e)}}ge.compileSchema=Ds;function Nv(e,t,n){var r;n=(0,_e.resolveUrl)(this.opts.uriResolver,t,n);const o=e.refs[n];if(o)return o;let s=Av.call(this,e,n);if(s===void 0){const i=(r=e.localRefs)===null||r===void 0?void 0:r[n],{schemaId:a}=this.opts;i&&(s=new br({schema:i,schemaId:a,root:e,baseId:t}))}if(s!==void 0)return e.refs[n]=_v.call(this,s)}ge.resolveRef=Nv;function _v(e){return(0,_e.inlineRef)(e.schema,this.opts.inlineRefs)?e.schema:e.validate?e:Ds.call(this,e)}function Gl(e){for(const t of this._compilations)if(kv(t,e))return t}ge.getCompilingSchema=Gl;function kv(e,t){return e.schema===t.schema&&e.root===t.root&&e.baseId===t.baseId}function Av(e,t){let n;for(;typeof(n=this.refs[t])=="string";)t=n;return n||this.schemas[t]||Er.call(this,e,t)}function Er(e,t){const n=this.opts.uriResolver.parse(t),r=(0,_e._getFullPath)(this.opts.uriResolver,n);let o=(0,_e.getFullPath)(this.opts.uriResolver,e.baseId,void 0);if(Object.keys(e.schema).length>0&&r===o)return to.call(this,n,e);const s=(0,_e.normalizeId)(r),i=this.refs[s]||this.schemas[s];if(typeof i=="string"){const a=Er.call(this,e,i);return typeof(a==null?void 0:a.schema)!="object"?void 0:to.call(this,n,a)}if(typeof(i==null?void 0:i.schema)=="object"){if(i.validate||Ds.call(this,i),s===(0,_e.normalizeId)(t)){const{schema:a}=i,{schemaId:c}=this.opts,u=a[c];return u&&(o=(0,_e.resolveUrl)(this.opts.uriResolver,o,u)),new br({schema:a,schemaId:c,root:e,baseId:o})}return to.call(this,n,i)}}ge.resolveSchema=Er;const Iv=new Set(["properties","patternProperties","enum","dependencies","definitions"]);function to(e,{baseId:t,schema:n,root:r}){var o;if(((o=e.fragment)===null||o===void 0?void 0:o[0])!=="/")return;for(const a of e.fragment.slice(1).split("/")){if(typeof n=="boolean")return;const c=n[(0,Ka.unescapeFragment)(a)];if(c===void 0)return;n=c;const u=typeof n=="object"&&n[this.opts.schemaId];!Iv.has(a)&&u&&(t=(0,_e.resolveUrl)(this.opts.uriResolver,t,u))}let s;if(typeof n!="boolean"&&n.$ref&&!(0,Ka.schemaHasRulesButRef)(n,this.RULES)){const a=(0,_e.resolveUrl)(this.opts.uriResolver,t,n.$ref);s=Er.call(this,r,a)}const{schemaId:i}=this.opts;if(s=s||new br({schema:n,schemaId:i,root:r,baseId:t}),s.schema!==s.root.schema)return s}const jv="https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",Pv="Meta-schema for $data reference (JSON AnySchema extension proposal)",xv="object",Tv=["$data"],Cv={$data:{type:"string",anyOf:[{format:"relative-json-pointer"},{format:"json-pointer"}]}},Rv=!1,Mv={$id:jv,description:Pv,type:xv,required:Tv,properties:Cv,additionalProperties:Rv};var Ls={},Sr={exports:{}};const Dv=RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu),zl=RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u),Bs=RegExp.prototype.test.bind(/^[\da-f]{2}$/iu),Wl=RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu),Lv=RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);function Hl(e){let t="",n=0,r=0;for(r=0;r<e.length;r++)if(n=e[r].charCodeAt(0),n!==48){if(!(n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102))return"";t+=e[r];break}for(r+=1;r<e.length;r++){if(n=e[r].charCodeAt(0),!(n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102))return"";t+=e[r]}return t}const Bv=RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);function Ga(e){return e.length=0,!0}function Uv(e,t,n){if(e.length){const r=Hl(e);if(r!=="")t.push(r);else return n.error=!0,!1;e.length=0}return!0}function Fv(e){let t=0;const n={error:!1,address:"",zone:""},r=[],o=[];let s=!1,i=!1,a=Uv;for(let c=0;c<e.length;c++){const u=e[c];if(!(u==="["||u==="]"))if(u===":"){if(s===!0&&(i=!0),!a(o,r,n))break;if(++t>7){n.error=!0;break}c>0&&e[c-1]===":"&&(s=!0),r.push(":");continue}else if(u==="%"){if(!a(o,r,n))break;a=Ga}else{o.push(u);continue}}return o.length&&(a===Ga?n.zone=o.join(""):i?r.push(o.join("")):r.push(Hl(o))),n.address=r.join(""),n}function Jl(e){if(Vv(e,":")<2)return{host:e,isIPV6:!1};const t=Fv(e);if(t.error)return{host:e,isIPV6:!1};{let n=t.address,r=t.address;return t.zone&&(n+="%"+t.zone,r+="%25"+t.zone),{host:n,isIPV6:!0,escapedHost:r}}}function Vv(e,t){let n=0;for(let r=0;r<e.length;r++)e[r]===t&&n++;return n}function qv(e){let t=e;const n=[];let r=-1,o=0;for(;o=t.length;){if(o===1){if(t===".")break;if(t==="/"){n.push("/");break}else{n.push(t);break}}else if(o===2){if(t[0]==="."){if(t[1]===".")break;if(t[1]==="/"){t=t.slice(2);continue}}else if(t[0]==="/"&&(t[1]==="."||t[1]==="/")){n.push("/");break}}else if(o===3&&t==="/.."){n.length!==0&&n.pop(),n.push("/");break}if(t[0]==="."){if(t[1]==="."){if(t[2]==="/"){t=t.slice(3);continue}}else if(t[1]==="/"){t=t.slice(2);continue}}else if(t[0]==="/"&&t[1]==="."){if(t[2]==="/"){t=t.slice(2);continue}else if(t[2]==="."&&t[3]==="/"){t=t.slice(3),n.length!==0&&n.pop();continue}}if((r=t.indexOf("/",1))===-1){n.push(t);break}else n.push(t.slice(0,r)),t=t.slice(r)}return n.join("")}const Kv={"@":"%40","/":"%2F","?":"%3F","#":"%23",":":"%3A"},Gv=/[@/?#:]/g,zv=/[@/?#]/g;function Yl(e,t){const n=t?zv:Gv;return n.lastIndex=0,e.replace(n,r=>Kv[r])}function Wv(e,t=!1){if(e.indexOf("%")===-1)return e;let n="";for(let r=0;r<e.length;r++){if(e[r]==="%"&&r+2<e.length){const o=e.slice(r+1,r+3);if(Bs(o)){const s=o.toUpperCase(),i=String.fromCharCode(parseInt(s,16));t&&Wl(i)?n+=i:n+="%"+s,r+=2;continue}}n+=e[r]}return n}function Hv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]==="%"&&n+2<e.length){const r=e.slice(n+1,n+3);if(Bs(r)){const o=r.toUpperCase(),s=String.fromCharCode(parseInt(o,16));s!=="."&&Wl(s)?t+=s:t+="%"+o,n+=2;continue}}Lv(e[n])?t+=e[n]:t+=escape(e[n])}return t}function Jv(e){let t="";for(let n=0;n<e.length;n++){if(e[n]==="%"&&n+2<e.length){const r=e.slice(n+1,n+3);if(Bs(r)){t+="%"+r.toUpperCase(),n+=2;continue}}t+=escape(e[n])}return t}function Yv(e){const t=[];if(e.userinfo!==void 0&&(t.push(e.userinfo),t.push("@")),e.host!==void 0){let n=unescape(e.host);if(!zl(n)){const r=Jl(n);r.isIPV6===!0?n=`[${r.escapedHost}]`:n=Yl(n,!1)}t.push(n)}return(typeof e.port=="number"||typeof e.port=="string")&&(t.push(":"),t.push(String(e.port))),t.length?t.join(""):void 0}var Ql={nonSimpleDomain:Bv,recomposeAuthority:Yv,reescapeHostDelimiters:Yl,normalizePercentEncoding:Wv,normalizePathEncoding:Hv,escapePreservingEscapes:Jv,removeDotSegments:qv,isIPv4:zl,isUUID:Dv,normalizeIPv6:Jl};const{isUUID:Qv}=Ql,Zv=/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;function Zl(e){return e.secure===!0?!0:e.secure===!1?!1:e.scheme?e.scheme.length===3&&(e.scheme[0]==="w"||e.scheme[0]==="W")&&(e.scheme[1]==="s"||e.scheme[1]==="S")&&(e.scheme[2]==="s"||e.scheme[2]==="S"):!1}function Xl(e){return e.host||(e.error=e.error||"HTTP URIs must have a host."),e}function ef(e){const t=String(e.scheme).toLowerCase()==="https";return(e.port===(t?443:80)||e.port==="")&&(e.port=void 0),e.path||(e.path="/"),e}function Xv(e){return e.secure=Zl(e),e.resourceName=(e.path||"/")+(e.query?"?"+e.query:""),e.path=void 0,e.query=void 0,e}function e$(e){if((e.port===(Zl(e)?443:80)||e.port==="")&&(e.port=void 0),typeof e.secure=="boolean"&&(e.scheme=e.secure?"wss":"ws",e.secure=void 0),e.resourceName){const[t,n]=e.resourceName.split("?");e.path=t&&t!=="/"?t:void 0,e.query=n,e.resourceName=void 0}return e.fragment=void 0,e}function t$(e,t){if(!e.path)return e.error="URN can not be parsed",e;const n=e.path.match(Zv);if(n){const r=t.scheme||e.scheme||"urn";e.nid=n[1].toLowerCase(),e.nss=n[2];const o=`${r}:${t.nid||e.nid}`,s=Us(o);e.path=void 0,s&&(e=s.parse(e,t))}else e.error=e.error||"URN can not be parsed.";return e}function n$(e,t){if(e.nid===void 0)throw new Error("URN without nid cannot be serialized");const n=t.scheme||e.scheme||"urn",r=e.nid.toLowerCase(),o=`${n}:${t.nid||r}`,s=Us(o);s&&(e=s.serialize(e,t));const i=e,a=e.nss;return i.path=`${r||t.nid}:${a}`,t.skipEscape=!0,i}function r$(e,t){const n=e;return n.uuid=n.nss,n.nss=void 0,!t.tolerant&&(!n.uuid||!Qv(n.uuid))&&(n.error=n.error||"UUID is not valid."),n}function o$(e){const t=e;return t.nss=(e.uuid||"").toLowerCase(),t}const tf={scheme:"http",domainHost:!0,parse:Xl,serialize:ef},s$={scheme:"https",domainHost:tf.domainHost,parse:Xl,serialize:ef},Hn={scheme:"ws",domainHost:!0,parse:Xv,serialize:e$},i$={scheme:"wss",domainHost:Hn.domainHost,parse:Hn.parse,serialize:Hn.serialize},a$={scheme:"urn",parse:t$,serialize:n$,skipNormalize:!0},c$={scheme:"urn:uuid",parse:r$,serialize:o$,skipNormalize:!0},or={http:tf,https:s$,ws:Hn,wss:i$,urn:a$,"urn:uuid":c$};Object.setPrototypeOf(or,null);function Us(e){return e&&(or[e]||or[e.toLowerCase()])||void 0}var u$={SCHEMES:or,getSchemeHandler:Us};const{normalizeIPv6:l$,removeDotSegments:tn,recomposeAuthority:f$,normalizePercentEncoding:d$,normalizePathEncoding:p$,escapePreservingEscapes:h$,reescapeHostDelimiters:m$,isIPv4:g$,nonSimpleDomain:y$}=Ql,{SCHEMES:v$,getSchemeHandler:nf}=u$;function $$(e,t){return typeof e=="string"?e=O$(e,t):typeof e=="object"&&(e=Ft(wt(e,t),t)),e}function w$(e,t,n){const r=n?Object.assign({scheme:"null"},n):{scheme:"null"},o=rf(Ft(e,r),Ft(t,r),r,!0);return r.skipEscape=!0,wt(o,r)}function rf(e,t,n,r){const o={};return r||(e=Ft(wt(e,n),n),t=Ft(wt(t,n),n)),n=n||{},!n.tolerant&&t.scheme?(o.scheme=t.scheme,o.userinfo=t.userinfo,o.host=t.host,o.port=t.port,o.path=tn(t.path||""),o.query=t.query):(t.userinfo!==void 0||t.host!==void 0||t.port!==void 0?(o.userinfo=t.userinfo,o.host=t.host,o.port=t.port,o.path=tn(t.path||""),o.query=t.query):(t.path?(t.path[0]==="/"?o.path=tn(t.path):((e.userinfo!==void 0||e.host!==void 0||e.port!==void 0)&&!e.path?o.path="/"+t.path:e.path?o.path=e.path.slice(0,e.path.lastIndexOf("/")+1)+t.path:o.path=t.path,o.path=tn(o.path)),o.query=t.query):(o.path=e.path,t.query!==void 0?o.query=t.query:o.query=e.query),o.userinfo=e.userinfo,o.host=e.host,o.port=e.port),o.scheme=e.scheme),o.fragment=t.fragment,o}function b$(e,t,n){const r=za(e,n),o=za(t,n);return r!==void 0&&o!==void 0&&r.toLowerCase()===o.toLowerCase()}function wt(e,t){const n={host:e.host,scheme:e.scheme,userinfo:e.userinfo,port:e.port,path:e.path,query:e.query,nid:e.nid,nss:e.nss,uuid:e.uuid,fragment:e.fragment,reference:e.reference,resourceName:e.resourceName,secure:e.secure,error:""},r=Object.assign({},t),o=[],s=nf(r.scheme||n.scheme);s&&s.serialize&&s.serialize(n,r),n.path!==void 0&&(r.skipEscape?n.path=d$(n.path):(n.path=h$(n.path),n.scheme!==void 0&&(n.path=n.path.split("%3A").join(":")))),r.reference!=="suffix"&&n.scheme&&o.push(n.scheme,":");const i=f$(n);if(i!==void 0&&(r.reference!=="suffix"&&o.push("//"),o.push(i),n.path&&n.path[0]!=="/"&&o.push("/")),n.path!==void 0){let a=n.path;!r.absolutePath&&(!s||!s.absolutePath)&&(a=tn(a)),i===void 0&&a[0]==="/"&&a[1]==="/"&&(a="/%2F"+a.slice(2)),o.push(a)}return n.query!==void 0&&o.push("?",n.query),n.fragment!==void 0&&o.push("#",n.fragment),o.join("")}const E$=/^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;function S$(e,t){if(t[2]!==void 0&&e.path&&e.path[0]!=="/")return'URI path must start with "/" when authority is present.';if(typeof e.port=="number"&&(e.port<0||e.port>65535))return"URI port is malformed."}function of(e,t){const n=Object.assign({},t),r={scheme:void 0,userinfo:void 0,host:"",port:void 0,path:"",query:void 0,fragment:void 0};let o=!1,s=!1;n.reference==="suffix"&&(n.scheme?e=n.scheme+":"+e:e="//"+e);const i=e.match(E$);if(i){r.scheme=i[1],r.userinfo=i[3],r.host=i[4],r.port=parseInt(i[5],10),r.path=i[6]||"",r.query=i[7],r.fragment=i[8],isNaN(r.port)&&(r.port=i[5]);const a=S$(r,i);if(a!==void 0&&(r.error=r.error||a,o=!0),r.host)if(g$(r.host)===!1){const u=l$(r.host);r.host=u.host.toLowerCase(),s=u.isIPV6}else s=!0;r.scheme===void 0&&r.userinfo===void 0&&r.host===void 0&&r.port===void 0&&r.query===void 0&&!r.path?r.reference="same-document":r.scheme===void 0?r.reference="relative":r.fragment===void 0?r.reference="absolute":r.reference="uri",n.reference&&n.reference!=="suffix"&&n.reference!==r.reference&&(r.error=r.error||"URI is not a "+n.reference+" reference.");const c=nf(n.scheme||r.scheme);if(!n.unicodeSupport&&(!c||!c.unicodeSupport)&&r.host&&(n.domainHost||c&&c.domainHost)&&s===!1&&y$(r.host))try{r.host=new URL("http://"+r.host).hostname}catch(u){r.error=r.error||"Host's domain name can not be converted to ASCII: "+u}if((!c||c&&!c.skipNormalize)&&(e.indexOf("%")!==-1&&(r.scheme!==void 0&&(r.scheme=unescape(r.scheme)),r.host!==void 0&&(r.host=m$(unescape(r.host),s))),r.path&&(r.path=p$(r.path)),r.fragment))try{r.fragment=encodeURI(decodeURIComponent(r.fragment))}catch{r.error=r.error||"URI malformed"}c&&c.parse&&c.parse(r,n)}else r.error=r.error||"URI can not be parsed.";return{parsed:r,malformedAuthorityOrPort:o}}function Ft(e,t){return of(e,t).parsed}function O$(e,t){return sf(e,t).normalized}function sf(e,t){const{parsed:n,malformedAuthorityOrPort:r}=of(e,t);return{normalized:r?e:wt(n,t),malformedAuthorityOrPort:r}}function za(e,t){if(typeof e=="string"){const{normalized:n,malformedAuthorityOrPort:r}=sf(e,t);return r?void 0:n}if(typeof e=="object")return wt(e,t)}const Fs={SCHEMES:v$,normalize:$$,resolve:w$,resolveComponent:rf,equal:b$,serialize:wt,parse:Ft};Sr.exports=Fs;Sr.exports.default=Fs;Sr.exports.fastUri=Fs;var N$=Sr.exports;Object.defineProperty(Ls,"__esModule",{value:!0});const af=N$;af.code='require("ajv/dist/runtime/uri").default';Ls.default=af;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.CodeGen=e.Name=e.nil=e.stringify=e.str=e._=e.KeywordCxt=void 0;var t=Ie;Object.defineProperty(e,"KeywordCxt",{enumerable:!0,get:function(){return t.KeywordCxt}});var n=V;Object.defineProperty(e,"_",{enumerable:!0,get:function(){return n._}}),Object.defineProperty(e,"str",{enumerable:!0,get:function(){return n.str}}),Object.defineProperty(e,"stringify",{enumerable:!0,get:function(){return n.stringify}}),Object.defineProperty(e,"nil",{enumerable:!0,get:function(){return n.nil}}),Object.defineProperty(e,"Name",{enumerable:!0,get:function(){return n.Name}}),Object.defineProperty(e,"CodeGen",{enumerable:!0,get:function(){return n.CodeGen}});const r=En,o=Kt,s=$t,i=ge,a=V,c=se,u=te,l=x,f=Mv,p=Ls,h=(P,E)=>new RegExp(P,E);h.code="new RegExp";const d=["removeAdditional","useDefaults","coerceTypes"],v=new Set(["validate","serialize","parse","wrapper","root","schema","keyword","pattern","formats","validate$data","func","obj","Error"]),m={errorDataPath:"",format:"`validateFormats: false` can be used instead.",nullable:'"nullable" keyword is supported by default.',jsonPointers:"Deprecated jsPropertySyntax can be used instead.",extendRefs:"Deprecated ignoreKeywordsWithRef can be used instead.",missingRefs:"Pass empty schema with $id that should be ignored to ajv.addSchema.",processCode:"Use option `code: {process: (code, schemaEnv: object) => string}`",sourceCode:"Use option `code: {source: true}`",strictDefaults:"It is default now, see option `strict`.",strictKeywords:"It is default now, see option `strict`.",uniqueItems:'"uniqueItems" keyword is always validated.',unknownFormats:"Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",cache:"Map is used as cache, schema object as key.",serialize:"Map is used as cache, schema object as key.",ajvErrors:"It is default now."},y={ignoreKeywordsWithRef:"",jsPropertySyntax:"",unicode:'"minLength"/"maxLength" account for unicode characters by default.'},$=200;function S(P){var E,A,O,g,w,_,C,R,z,G,re,St,Tr,Cr,Rr,Mr,Dr,Lr,Br,Ur,Fr,Vr,qr,Kr,Gr;const Ht=P.strict,zr=(E=P.code)===null||E===void 0?void 0:E.optimize,Hi=zr===!0||zr===void 0?1:zr||0,Ji=(O=(A=P.code)===null||A===void 0?void 0:A.regExp)!==null&&O!==void 0?O:h,hp=(g=P.uriResolver)!==null&&g!==void 0?g:p.default;return{strictSchema:(_=(w=P.strictSchema)!==null&&w!==void 0?w:Ht)!==null&&_!==void 0?_:!0,strictNumbers:(R=(C=P.strictNumbers)!==null&&C!==void 0?C:Ht)!==null&&R!==void 0?R:!0,strictTypes:(G=(z=P.strictTypes)!==null&&z!==void 0?z:Ht)!==null&&G!==void 0?G:"log",strictTuples:(St=(re=P.strictTuples)!==null&&re!==void 0?re:Ht)!==null&&St!==void 0?St:"log",strictRequired:(Cr=(Tr=P.strictRequired)!==null&&Tr!==void 0?Tr:Ht)!==null&&Cr!==void 0?Cr:!1,code:P.code?{...P.code,optimize:Hi,regExp:Ji}:{optimize:Hi,regExp:Ji},loopRequired:(Rr=P.loopRequired)!==null&&Rr!==void 0?Rr:$,loopEnum:(Mr=P.loopEnum)!==null&&Mr!==void 0?Mr:$,meta:(Dr=P.meta)!==null&&Dr!==void 0?Dr:!0,messages:(Lr=P.messages)!==null&&Lr!==void 0?Lr:!0,inlineRefs:(Br=P.inlineRefs)!==null&&Br!==void 0?Br:!0,schemaId:(Ur=P.schemaId)!==null&&Ur!==void 0?Ur:"$id",addUsedSchema:(Fr=P.addUsedSchema)!==null&&Fr!==void 0?Fr:!0,validateSchema:(Vr=P.validateSchema)!==null&&Vr!==void 0?Vr:!0,validateFormats:(qr=P.validateFormats)!==null&&qr!==void 0?qr:!0,unicodeRegExp:(Kr=P.unicodeRegExp)!==null&&Kr!==void 0?Kr:!0,int32range:(Gr=P.int32range)!==null&&Gr!==void 0?Gr:!0,uriResolver:hp}}class b{constructor(E={}){this.schemas={},this.refs={},this.formats=Object.create(null),this._compilations=new Set,this._loading={},this._cache=new Map,E=this.opts={...E,...S(E)};const{es5:A,lines:O}=this.opts.code;this.scope=new a.ValueScope({scope:{},prefixes:v,es5:A,lines:O}),this.logger=ye(E.logger);const g=E.validateFormats;E.validateFormats=!1,this.RULES=(0,s.getRules)(),N.call(this,m,E,"NOT SUPPORTED"),N.call(this,y,E,"DEPRECATED","warn"),this._metaOpts=le.call(this),E.formats&&H.call(this),this._addVocabularies(),this._addDefaultMetaSchema(),E.keywords&&Z.call(this,E.keywords),typeof E.meta=="object"&&this.addMetaSchema(E.meta),M.call(this),E.validateFormats=g}_addVocabularies(){this.addKeyword("$async")}_addDefaultMetaSchema(){const{$data:E,meta:A,schemaId:O}=this.opts;let g=f;O==="id"&&(g={...f},g.id=g.$id,delete g.$id),A&&E&&this.addMetaSchema(g,g[O],!1)}defaultMeta(){const{meta:E,schemaId:A}=this.opts;return this.opts.defaultMeta=typeof E=="object"?E[A]||E:void 0}validate(E,A){let O;if(typeof E=="string"){if(O=this.getSchema(E),!O)throw new Error(`no schema with key or ref "${E}"`)}else O=this.compile(E);const g=O(A);return"$async"in O||(this.errors=O.errors),g}compile(E,A){const O=this._addSchema(E,A);return O.validate||this._compileSchemaEnv(O)}compileAsync(E,A){if(typeof this.opts.loadSchema!="function")throw new Error("options.loadSchema should be a function");const{loadSchema:O}=this.opts;return g.call(this,E,A);async function g(G,re){await w.call(this,G.$schema);const St=this._addSchema(G,re);return St.validate||_.call(this,St)}async function w(G){G&&!this.getSchema(G)&&await g.call(this,{$ref:G},!0)}async function _(G){try{return this._compileSchemaEnv(G)}catch(re){if(!(re instanceof o.default))throw re;return C.call(this,re),await R.call(this,re.missingSchema),_.call(this,G)}}function C({missingSchema:G,missingRef:re}){if(this.refs[G])throw new Error(`AnySchema ${G} is loaded but ${re} cannot be resolved`)}async function R(G){const re=await z.call(this,G);this.refs[G]||await w.call(this,re.$schema),this.refs[G]||this.addSchema(re,G,A)}async function z(G){const re=this._loading[G];if(re)return re;try{return await(this._loading[G]=O(G))}finally{delete this._loading[G]}}}addSchema(E,A,O,g=this.opts.validateSchema){if(Array.isArray(E)){for(const _ of E)this.addSchema(_,void 0,O,g);return this}let w;if(typeof E=="object"){const{schemaId:_}=this.opts;if(w=E[_],w!==void 0&&typeof w!="string")throw new Error(`schema ${_} must be string`)}return A=(0,c.normalizeId)(A||w),this._checkUnique(A),this.schemas[A]=this._addSchema(E,O,A,g,!0),this}addMetaSchema(E,A,O=this.opts.validateSchema){return this.addSchema(E,A,!0,O),this}validateSchema(E,A){if(typeof E=="boolean")return!0;let O;if(O=E.$schema,O!==void 0&&typeof O!="string")throw new Error("$schema must be a string");if(O=O||this.opts.defaultMeta||this.defaultMeta(),!O)return this.logger.warn("meta-schema not available"),this.errors=null,!0;const g=this.validate(O,E);if(!g&&A){const w="schema is invalid: "+this.errorsText();if(this.opts.validateSchema==="log")this.logger.error(w);else throw new Error(w)}return g}getSchema(E){let A;for(;typeof(A=j.call(this,E))=="string";)E=A;if(A===void 0){const{schemaId:O}=this.opts,g=new i.SchemaEnv({schema:{},schemaId:O});if(A=i.resolveSchema.call(this,g,E),!A)return;this.refs[E]=A}return A.validate||this._compileSchemaEnv(A)}removeSchema(E){if(E instanceof RegExp)return this._removeAllSchemas(this.schemas,E),this._removeAllSchemas(this.refs,E),this;switch(typeof E){case"undefined":return this._removeAllSchemas(this.schemas),this._removeAllSchemas(this.refs),this._cache.clear(),this;case"string":{const A=j.call(this,E);return typeof A=="object"&&this._cache.delete(A.schema),delete this.schemas[E],delete this.refs[E],this}case"object":{const A=E;this._cache.delete(A);let O=E[this.opts.schemaId];return O&&(O=(0,c.normalizeId)(O),delete this.schemas[O],delete this.refs[O]),this}default:throw new Error("ajv.removeSchema: invalid parameter")}}addVocabulary(E){for(const A of E)this.addKeyword(A);return this}addKeyword(E,A){let O;if(typeof E=="string")O=E,typeof A=="object"&&(this.logger.warn("these parameters are deprecated, see docs for addKeyword"),A.keyword=O);else if(typeof E=="object"&&A===void 0){if(A=E,O=A.keyword,Array.isArray(O)&&!O.length)throw new Error("addKeywords: keyword must be string or non-empty array")}else throw new Error("invalid addKeywords parameters");if(Ge.call(this,O,A),!A)return(0,l.eachItem)(O,w=>Wt.call(this,w)),this;Pr.call(this,A);const g={...A,type:(0,u.getJSONTypes)(A.type),schemaType:(0,u.getJSONTypes)(A.schemaType)};return(0,l.eachItem)(O,g.type.length===0?w=>Wt.call(this,w,g):w=>g.type.forEach(_=>Wt.call(this,w,g,_))),this}getKeyword(E){const A=this.RULES.all[E];return typeof A=="object"?A.definition:!!A}removeKeyword(E){const{RULES:A}=this;delete A.keywords[E],delete A.all[E];for(const O of A.rules){const g=O.rules.findIndex(w=>w.keyword===E);g>=0&&O.rules.splice(g,1)}return this}addFormat(E,A){return typeof A=="string"&&(A=new RegExp(A)),this.formats[E]=A,this}errorsText(E=this.errors,{separator:A=", ",dataVar:O="data"}={}){return!E||E.length===0?"No errors":E.map(g=>`${O}${g.instancePath} ${g.message}`).reduce((g,w)=>g+A+w)}$dataMetaSchema(E,A){const O=this.RULES.all;E=JSON.parse(JSON.stringify(E));for(const g of A){const w=g.split("/").slice(1);let _=E;for(const C of w)_=_[C];for(const C in O){const R=O[C];if(typeof R!="object")continue;const{$data:z}=R.definition,G=_[C];z&&G&&(_[C]=Nn(G))}}return E}_removeAllSchemas(E,A){for(const O in E){const g=E[O];(!A||A.test(O))&&(typeof g=="string"?delete E[O]:g&&!g.meta&&(this._cache.delete(g.schema),delete E[O]))}}_addSchema(E,A,O,g=this.opts.validateSchema,w=this.opts.addUsedSchema){let _;const{schemaId:C}=this.opts;if(typeof E=="object")_=E[C];else{if(this.opts.jtd)throw new Error("schema must be object");if(typeof E!="boolean")throw new Error("schema must be object or boolean")}let R=this._cache.get(E);if(R!==void 0)return R;O=(0,c.normalizeId)(_||O);const z=c.getSchemaRefs.call(this,E,O);return R=new i.SchemaEnv({schema:E,schemaId:C,meta:A,baseId:O,localRefs:z}),this._cache.set(R.schema,R),w&&!O.startsWith("#")&&(O&&this._checkUnique(O),this.refs[O]=R),g&&this.validateSchema(E,!0),R}_checkUnique(E){if(this.schemas[E]||this.refs[E])throw new Error(`schema with key or id "${E}" already exists`)}_compileSchemaEnv(E){if(E.meta?this._compileMetaSchema(E):i.compileSchema.call(this,E),!E.validate)throw new Error("ajv implementation error");return E.validate}_compileMetaSchema(E){const A=this.opts;this.opts=this._metaOpts;try{i.compileSchema.call(this,E)}finally{this.opts=A}}}b.ValidationError=r.default,b.MissingRefError=o.default,e.default=b;function N(P,E,A,O="error"){for(const g in P){const w=g;w in E&&this.logger[O](`${A}: option ${g}. ${P[w]}`)}}function j(P){return P=(0,c.normalizeId)(P),this.schemas[P]||this.refs[P]}function M(){const P=this.opts.schemas;if(P)if(Array.isArray(P))this.addSchema(P);else for(const E in P)this.addSchema(P[E],E)}function H(){for(const P in this.opts.formats){const E=this.opts.formats[P];E&&this.addFormat(P,E)}}function Z(P){if(Array.isArray(P)){this.addVocabulary(P);return}this.logger.warn("keywords option as map is deprecated, pass array");for(const E in P){const A=P[E];A.keyword||(A.keyword=E),this.addKeyword(A)}}function le(){const P={...this.opts};for(const E of d)delete P[E];return P}const fe={log(){},warn(){},error(){}};function ye(P){if(P===!1)return fe;if(P===void 0)return console;if(P.log&&P.warn&&P.error)return P;throw new Error("logger must implement log, warn and error methods")}const Et=/^[a-z_$][a-z0-9_$:-]*$/i;function Ge(P,E){const{RULES:A}=this;if((0,l.eachItem)(P,O=>{if(A.keywords[O])throw new Error(`Keyword ${O} is already defined`);if(!Et.test(O))throw new Error(`Keyword ${O} has invalid name`)}),!!E&&E.$data&&!("code"in E||"validate"in E))throw new Error('$data keyword must have "code" or "validate" function')}function Wt(P,E,A){var O;const g=E==null?void 0:E.post;if(A&&g)throw new Error('keyword with "post" flag cannot have "type"');const{RULES:w}=this;let _=g?w.post:w.rules.find(({type:R})=>R===A);if(_||(_={type:A,rules:[]},w.rules.push(_)),w.keywords[P]=!0,!E)return;const C={keyword:P,definition:{...E,type:(0,u.getJSONTypes)(E.type),schemaType:(0,u.getJSONTypes)(E.schemaType)}};E.before?On.call(this,_,C,E.before):_.rules.push(C),w.all[P]=C,(O=E.implements)===null||O===void 0||O.forEach(R=>this.addKeyword(R))}function On(P,E,A){const O=P.rules.findIndex(g=>g.keyword===A);O>=0?P.rules.splice(O,0,E):(P.rules.push(E),this.logger.warn(`rule ${A} is not defined`))}function Pr(P){let{metaSchema:E}=P;E!==void 0&&(P.$data&&this.opts.$data&&(E=Nn(E)),P.validateSchema=this.compile(E,!0))}const xr={$ref:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#"};function Nn(P){return{anyOf:[P,xr]}}})(pl);var Vs={},qs={},Ks={};Object.defineProperty(Ks,"__esModule",{value:!0});const _$={keyword:"id",code(){throw new Error('NOT SUPPORTED: keyword "id", use "$id" for schema ID')}};Ks.default=_$;var bt={};Object.defineProperty(bt,"__esModule",{value:!0});bt.callRef=bt.getValidate=void 0;const k$=Kt,Wa=F,pe=V,_t=Re,Ha=ge,Tn=x,A$={keyword:"$ref",schemaType:"string",code(e){const{gen:t,schema:n,it:r}=e,{baseId:o,schemaEnv:s,validateName:i,opts:a,self:c}=r,{root:u}=s;if((n==="#"||n==="#/")&&o===u.baseId)return f();const l=Ha.resolveRef.call(c,u,o,n);if(l===void 0)throw new k$.default(r.opts.uriResolver,o,n);if(l instanceof Ha.SchemaEnv)return p(l);return h(l);function f(){if(s===u)return Jn(e,i,s,s.$async);const d=t.scopeValue("root",{ref:u});return Jn(e,(0,pe._)`${d}.validate`,u,u.$async)}function p(d){const v=cf(e,d);Jn(e,v,d,d.$async)}function h(d){const v=t.scopeValue("schema",a.code.source===!0?{ref:d,code:(0,pe.stringify)(d)}:{ref:d}),m=t.name("valid"),y=e.subschema({schema:d,dataTypes:[],schemaPath:pe.nil,topSchemaRef:v,errSchemaPath:n},m);e.mergeEvaluated(y),e.ok(m)}}};function cf(e,t){const{gen:n}=e;return t.validate?n.scopeValue("validate",{ref:t.validate}):(0,pe._)`${n.scopeValue("wrapper",{ref:t})}.validate`}bt.getValidate=cf;function Jn(e,t,n,r){const{gen:o,it:s}=e,{allErrors:i,schemaEnv:a,opts:c}=s,u=c.passContext?_t.default.this:pe.nil;r?l():f();function l(){if(!a.$async)throw new Error("async schema referenced by sync schema");const d=o.let("valid");o.try(()=>{o.code((0,pe._)`await ${(0,Wa.callValidateCode)(e,t,u)}`),h(t),i||o.assign(d,!0)},v=>{o.if((0,pe._)`!(${v} instanceof ${s.ValidationError})`,()=>o.throw(v)),p(v),i||o.assign(d,!1)}),e.ok(d)}function f(){e.result((0,Wa.callValidateCode)(e,t,u),()=>h(t),()=>p(t))}function p(d){const v=(0,pe._)`${d}.errors`;o.assign(_t.default.vErrors,(0,pe._)`${_t.default.vErrors} === null ? ${v} : ${_t.default.vErrors}.concat(${v})`),o.assign(_t.default.errors,(0,pe._)`${_t.default.vErrors}.length`)}function h(d){var v;if(!s.opts.unevaluated)return;const m=(v=n==null?void 0:n.validate)===null||v===void 0?void 0:v.evaluated;if(s.props!==!0)if(m&&!m.dynamicProps)m.props!==void 0&&(s.props=Tn.mergeEvaluated.props(o,m.props,s.props));else{const y=o.var("props",(0,pe._)`${d}.evaluated.props`);s.props=Tn.mergeEvaluated.props(o,y,s.props,pe.Name)}if(s.items!==!0)if(m&&!m.dynamicItems)m.items!==void 0&&(s.items=Tn.mergeEvaluated.items(o,m.items,s.items));else{const y=o.var("items",(0,pe._)`${d}.evaluated.items`);s.items=Tn.mergeEvaluated.items(o,y,s.items,pe.Name)}}}bt.callRef=Jn;bt.default=A$;Object.defineProperty(qs,"__esModule",{value:!0});const I$=Ks,j$=bt,P$=["$schema","$id","$defs","$vocabulary",{keyword:"$comment"},"definitions",I$.default,j$.default];qs.default=P$;var Gs={},zs={};Object.defineProperty(zs,"__esModule",{value:!0});const sr=V,He=sr.operators,ir={maximum:{okStr:"<=",ok:He.LTE,fail:He.GT},minimum:{okStr:">=",ok:He.GTE,fail:He.LT},exclusiveMaximum:{okStr:"<",ok:He.LT,fail:He.GTE},exclusiveMinimum:{okStr:">",ok:He.GT,fail:He.LTE}},x$={message:({keyword:e,schemaCode:t})=>(0,sr.str)`must be ${ir[e].okStr} ${t}`,params:({keyword:e,schemaCode:t})=>(0,sr._)`{comparison: ${ir[e].okStr}, limit: ${t}}`},T$={keyword:Object.keys(ir),type:"number",schemaType:"number",$data:!0,error:x$,code(e){const{keyword:t,data:n,schemaCode:r}=e;e.fail$data((0,sr._)`${n} ${ir[t].fail} ${r} || isNaN(${n})`)}};zs.default=T$;var Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});const cn=V,C$={message:({schemaCode:e})=>(0,cn.str)`must be multiple of ${e}`,params:({schemaCode:e})=>(0,cn._)`{multipleOf: ${e}}`},R$={keyword:"multipleOf",type:"number",schemaType:"number",$data:!0,error:C$,code(e){const{gen:t,data:n,schemaCode:r,it:o}=e,s=o.opts.multipleOfPrecision,i=t.let("res"),a=s?(0,cn._)`Math.abs(Math.round(${i}) - ${i}) > 1e-${s}`:(0,cn._)`${i} !== parseInt(${i})`;e.fail$data((0,cn._)`(${r} === 0 || (${i} = ${n}/${r}, ${a}))`)}};Ws.default=R$;var Hs={},Js={};Object.defineProperty(Js,"__esModule",{value:!0});function uf(e){const t=e.length;let n=0,r=0,o;for(;r<t;)n++,o=e.charCodeAt(r++),o>=55296&&o<=56319&&r<t&&(o=e.charCodeAt(r),(o&64512)===56320&&r++);return n}Js.default=uf;uf.code='require("ajv/dist/runtime/ucs2length").default';Object.defineProperty(Hs,"__esModule",{value:!0});const lt=V,M$=x,D$=Js,L$={message({keyword:e,schemaCode:t}){const n=e==="maxLength"?"more":"fewer";return(0,lt.str)`must NOT have ${n} than ${t} characters`},params:({schemaCode:e})=>(0,lt._)`{limit: ${e}}`},B$={keyword:["maxLength","minLength"],type:"string",schemaType:"number",$data:!0,error:L$,code(e){const{keyword:t,data:n,schemaCode:r,it:o}=e,s=t==="maxLength"?lt.operators.GT:lt.operators.LT,i=o.opts.unicode===!1?(0,lt._)`${n}.length`:(0,lt._)`${(0,M$.useFunc)(e.gen,D$.default)}(${n})`;e.fail$data((0,lt._)`${i} ${s} ${r}`)}};Hs.default=B$;var Ys={};Object.defineProperty(Ys,"__esModule",{value:!0});const U$=F,F$=x,Rt=V,V$={message:({schemaCode:e})=>(0,Rt.str)`must match pattern "${e}"`,params:({schemaCode:e})=>(0,Rt._)`{pattern: ${e}}`},q$={keyword:"pattern",type:"string",schemaType:"string",$data:!0,error:V$,code(e){const{gen:t,data:n,$data:r,schema:o,schemaCode:s,it:i}=e,a=i.opts.unicodeRegExp?"u":"";if(r){const{regExp:c}=i.opts.code,u=c.code==="new RegExp"?(0,Rt._)`new RegExp`:(0,F$.useFunc)(t,c),l=t.let("valid");t.try(()=>t.assign(l,(0,Rt._)`${u}(${s}, ${a}).test(${n})`),()=>t.assign(l,!1)),e.fail$data((0,Rt._)`!${l}`)}else{const c=(0,U$.usePattern)(e,o);e.fail$data((0,Rt._)`!${c}.test(${n})`)}}};Ys.default=q$;var Qs={};Object.defineProperty(Qs,"__esModule",{value:!0});const un=V,K$={message({keyword:e,schemaCode:t}){const n=e==="maxProperties"?"more":"fewer";return(0,un.str)`must NOT have ${n} than ${t} properties`},params:({schemaCode:e})=>(0,un._)`{limit: ${e}}`},G$={keyword:["maxProperties","minProperties"],type:"object",schemaType:"number",$data:!0,error:K$,code(e){const{keyword:t,data:n,schemaCode:r}=e,o=t==="maxProperties"?un.operators.GT:un.operators.LT;e.fail$data((0,un._)`Object.keys(${n}).length ${o} ${r}`)}};Qs.default=G$;var Zs={};Object.defineProperty(Zs,"__esModule",{value:!0});const Yt=F,ln=V,z$=x,W$={message:({params:{missingProperty:e}})=>(0,ln.str)`must have required property '${e}'`,params:({params:{missingProperty:e}})=>(0,ln._)`{missingProperty: ${e}}`},H$={keyword:"required",type:"object",schemaType:"array",$data:!0,error:W$,code(e){const{gen:t,schema:n,schemaCode:r,data:o,$data:s,it:i}=e,{opts:a}=i;if(!s&&n.length===0)return;const c=n.length>=a.loopRequired;if(i.allErrors?u():l(),a.strictRequired){const h=e.parentSchema.properties,{definedProperties:d}=e.it;for(const v of n)if((h==null?void 0:h[v])===void 0&&!d.has(v)){const m=i.schemaEnv.baseId+i.errSchemaPath,y=`required property "${v}" is not defined at "${m}" (strictRequired)`;(0,z$.checkStrictMode)(i,y,i.opts.strictRequired)}}function u(){if(c||s)e.block$data(ln.nil,f);else for(const h of n)(0,Yt.checkReportMissingProp)(e,h)}function l(){const h=t.let("missing");if(c||s){const d=t.let("valid",!0);e.block$data(d,()=>p(h,d)),e.ok(d)}else t.if((0,Yt.checkMissingProp)(e,n,h)),(0,Yt.reportMissingProp)(e,h),t.else()}function f(){t.forOf("prop",r,h=>{e.setParams({missingProperty:h}),t.if((0,Yt.noPropertyInData)(t,o,h,a.ownProperties),()=>e.error())})}function p(h,d){e.setParams({missingProperty:h}),t.forOf(h,r,()=>{t.assign(d,(0,Yt.propertyInData)(t,o,h,a.ownProperties)),t.if((0,ln.not)(d),()=>{e.error(),t.break()})},ln.nil)}}};Zs.default=H$;var Xs={};Object.defineProperty(Xs,"__esModule",{value:!0});const fn=V,J$={message({keyword:e,schemaCode:t}){const n=e==="maxItems"?"more":"fewer";return(0,fn.str)`must NOT have ${n} than ${t} items`},params:({schemaCode:e})=>(0,fn._)`{limit: ${e}}`},Y$={keyword:["maxItems","minItems"],type:"array",schemaType:"number",$data:!0,error:J$,code(e){const{keyword:t,data:n,schemaCode:r}=e,o=t==="maxItems"?fn.operators.GT:fn.operators.LT;e.fail$data((0,fn._)`${n}.length ${o} ${r}`)}};Xs.default=Y$;var ei={},Sn={};Object.defineProperty(Sn,"__esModule",{value:!0});const lf=Il;lf.code='require("ajv/dist/runtime/equal").default';Sn.default=lf;Object.defineProperty(ei,"__esModule",{value:!0});const no=te,oe=V,Q$=x,Z$=Sn,X$={message:({params:{i:e,j:t}})=>(0,oe.str)`must NOT have duplicate items (items ## ${t} and ${e} are identical)`,params:({params:{i:e,j:t}})=>(0,oe._)`{i: ${e}, j: ${t}}`},e0={keyword:"uniqueItems",type:"array",schemaType:"boolean",$data:!0,error:X$,code(e){const{gen:t,data:n,$data:r,schema:o,parentSchema:s,schemaCode:i,it:a}=e;if(!r&&!o)return;const c=t.let("valid"),u=s.items?(0,no.getSchemaTypes)(s.items):[];e.block$data(c,l,(0,oe._)`${i} === false`),e.ok(c);function l(){const d=t.let("i",(0,oe._)`${n}.length`),v=t.let("j");e.setParams({i:d,j:v}),t.assign(c,!0),t.if((0,oe._)`${d} > 1`,()=>(f()?p:h)(d,v))}function f(){return u.length>0&&!u.some(d=>d==="object"||d==="array")}function p(d,v){const m=t.name("item"),y=(0,no.checkDataTypes)(u,m,a.opts.strictNumbers,no.DataType.Wrong),$=t.const("indices",(0,oe._)`{}`);t.for((0,oe._)`;${d}--;`,()=>{t.let(m,(0,oe._)`${n}[${d}]`),t.if(y,(0,oe._)`continue`),u.length>1&&t.if((0,oe._)`typeof ${m} == "string"`,(0,oe._)`${m} += "_"`),t.if((0,oe._)`typeof ${$}[${m}] == "number"`,()=>{t.assign(v,(0,oe._)`${$}[${m}]`),e.error(),t.assign(c,!1).break()}).code((0,oe._)`${$}[${m}] = ${d}`)})}function h(d,v){const m=(0,Q$.useFunc)(t,Z$.default),y=t.name("outer");t.label(y).for((0,oe._)`;${d}--;`,()=>t.for((0,oe._)`${v} = ${d}; ${v}--;`,()=>t.if((0,oe._)`${m}(${n}[${d}], ${n}[${v}])`,()=>{e.error(),t.assign(c,!1).break(y)})))}}};ei.default=e0;var ti={};Object.defineProperty(ti,"__esModule",{value:!0});const Ro=V,t0=x,n0=Sn,r0={message:"must be equal to constant",params:({schemaCode:e})=>(0,Ro._)`{allowedValue: ${e}}`},o0={keyword:"const",$data:!0,error:r0,code(e){const{gen:t,data:n,$data:r,schemaCode:o,schema:s}=e;r||s&&typeof s=="object"?e.fail$data((0,Ro._)`!${(0,t0.useFunc)(t,n0.default)}(${n}, ${o})`):e.fail((0,Ro._)`${s} !== ${n}`)}};ti.default=o0;var ni={};Object.defineProperty(ni,"__esModule",{value:!0});const nn=V,s0=x,i0=Sn,a0={message:"must be equal to one of the allowed values",params:({schemaCode:e})=>(0,nn._)`{allowedValues: ${e}}`},c0={keyword:"enum",schemaType:"array",$data:!0,error:a0,code(e){const{gen:t,data:n,$data:r,schema:o,schemaCode:s,it:i}=e;if(!r&&o.length===0)throw new Error("enum must have non-empty array");const a=o.length>=i.opts.loopEnum;let c;const u=()=>c??(c=(0,s0.useFunc)(t,i0.default));let l;if(a||r)l=t.let("valid"),e.block$data(l,f);else{if(!Array.isArray(o))throw new Error("ajv implementation error");const h=t.const("vSchema",s);l=(0,nn.or)(...o.map((d,v)=>p(h,v)))}e.pass(l);function f(){t.assign(l,!1),t.forOf("v",s,h=>t.if((0,nn._)`${u()}(${n}, ${h})`,()=>t.assign(l,!0).break()))}function p(h,d){const v=o[d];return typeof v=="object"&&v!==null?(0,nn._)`${u()}(${n}, ${h}[${d}])`:(0,nn._)`${n} === ${v}`}}};ni.default=c0;Object.defineProperty(Gs,"__esModule",{value:!0});const u0=zs,l0=Ws,f0=Hs,d0=Ys,p0=Qs,h0=Zs,m0=Xs,g0=ei,y0=ti,v0=ni,$0=[u0.default,l0.default,f0.default,d0.default,p0.default,h0.default,m0.default,g0.default,{keyword:"type",schemaType:["string","array"]},{keyword:"nullable",schemaType:"boolean"},y0.default,v0.default];Gs.default=$0;var ri={},Gt={};Object.defineProperty(Gt,"__esModule",{value:!0});Gt.validateAdditionalItems=void 0;const ft=V,Mo=x,w0={message:({params:{len:e}})=>(0,ft.str)`must NOT have more than ${e} items`,params:({params:{len:e}})=>(0,ft._)`{limit: ${e}}`},b0={keyword:"additionalItems",type:"array",schemaType:["boolean","object"],before:"uniqueItems",error:w0,code(e){const{parentSchema:t,it:n}=e,{items:r}=t;if(!Array.isArray(r)){(0,Mo.checkStrictMode)(n,'"additionalItems" is ignored when "items" is not an array of schemas');return}ff(e,r)}};function ff(e,t){const{gen:n,schema:r,data:o,keyword:s,it:i}=e;i.items=!0;const a=n.const("len",(0,ft._)`${o}.length`);if(r===!1)e.setParams({len:t.length}),e.pass((0,ft._)`${a} <= ${t.length}`);else if(typeof r=="object"&&!(0,Mo.alwaysValidSchema)(i,r)){const u=n.var("valid",(0,ft._)`${a} <= ${t.length}`);n.if((0,ft.not)(u),()=>c(u)),e.ok(u)}function c(u){n.forRange("i",t.length,a,l=>{e.subschema({keyword:s,dataProp:l,dataPropType:Mo.Type.Num},u),i.allErrors||n.if((0,ft.not)(u),()=>n.break())})}}Gt.validateAdditionalItems=ff;Gt.default=b0;var oi={},zt={};Object.defineProperty(zt,"__esModule",{value:!0});zt.validateTuple=void 0;const Ja=V,Yn=x,E0=F,S0={keyword:"items",type:"array",schemaType:["object","array","boolean"],before:"uniqueItems",code(e){const{schema:t,it:n}=e;if(Array.isArray(t))return df(e,"additionalItems",t);n.items=!0,!(0,Yn.alwaysValidSchema)(n,t)&&e.ok((0,E0.validateArray)(e))}};function df(e,t,n=e.schema){const{gen:r,parentSchema:o,data:s,keyword:i,it:a}=e;l(o),a.opts.unevaluated&&n.length&&a.items!==!0&&(a.items=Yn.mergeEvaluated.items(r,n.length,a.items));const c=r.name("valid"),u=r.const("len",(0,Ja._)`${s}.length`);n.forEach((f,p)=>{(0,Yn.alwaysValidSchema)(a,f)||(r.if((0,Ja._)`${u} > ${p}`,()=>e.subschema({keyword:i,schemaProp:p,dataProp:p},c)),e.ok(c))});function l(f){const{opts:p,errSchemaPath:h}=a,d=n.length,v=d===f.minItems&&(d===f.maxItems||f[t]===!1);if(p.strictTuples&&!v){const m=`"${i}" is ${d}-tuple, but minItems or maxItems/${t} are not specified or different at path "${h}"`;(0,Yn.checkStrictMode)(a,m,p.strictTuples)}}}zt.validateTuple=df;zt.default=S0;Object.defineProperty(oi,"__esModule",{value:!0});const O0=zt,N0={keyword:"prefixItems",type:"array",schemaType:["array"],before:"uniqueItems",code:e=>(0,O0.validateTuple)(e,"items")};oi.default=N0;var si={};Object.defineProperty(si,"__esModule",{value:!0});const Ya=V,_0=x,k0=F,A0=Gt,I0={message:({params:{len:e}})=>(0,Ya.str)`must NOT have more than ${e} items`,params:({params:{len:e}})=>(0,Ya._)`{limit: ${e}}`},j0={keyword:"items",type:"array",schemaType:["object","boolean"],before:"uniqueItems",error:I0,code(e){const{schema:t,parentSchema:n,it:r}=e,{prefixItems:o}=n;r.items=!0,!(0,_0.alwaysValidSchema)(r,t)&&(o?(0,A0.validateAdditionalItems)(e,o):e.ok((0,k0.validateArray)(e)))}};si.default=j0;var ii={};Object.defineProperty(ii,"__esModule",{value:!0});const be=V,Cn=x,P0={message:({params:{min:e,max:t}})=>t===void 0?(0,be.str)`must contain at least ${e} valid item(s)`:(0,be.str)`must contain at least ${e} and no more than ${t} valid item(s)`,params:({params:{min:e,max:t}})=>t===void 0?(0,be._)`{minContains: ${e}}`:(0,be._)`{minContains: ${e}, maxContains: ${t}}`},x0={keyword:"contains",type:"array",schemaType:["object","boolean"],before:"uniqueItems",trackErrors:!0,error:P0,code(e){const{gen:t,schema:n,parentSchema:r,data:o,it:s}=e;let i,a;const{minContains:c,maxContains:u}=r;s.opts.next?(i=c===void 0?1:c,a=u):i=1;const l=t.const("len",(0,be._)`${o}.length`);if(e.setParams({min:i,max:a}),a===void 0&&i===0){(0,Cn.checkStrictMode)(s,'"minContains" == 0 without "maxContains": "contains" keyword ignored');return}if(a!==void 0&&i>a){(0,Cn.checkStrictMode)(s,'"minContains" > "maxContains" is always invalid'),e.fail();return}if((0,Cn.alwaysValidSchema)(s,n)){let v=(0,be._)`${l} >= ${i}`;a!==void 0&&(v=(0,be._)`${v} && ${l} <= ${a}`),e.pass(v);return}s.items=!0;const f=t.name("valid");a===void 0&&i===1?h(f,()=>t.if(f,()=>t.break())):i===0?(t.let(f,!0),a!==void 0&&t.if((0,be._)`${o}.length > 0`,p)):(t.let(f,!1),p()),e.result(f,()=>e.reset());function p(){const v=t.name("_valid"),m=t.let("count",0);h(v,()=>t.if(v,()=>d(m)))}function h(v,m){t.forRange("i",0,l,y=>{e.subschema({keyword:"contains",dataProp:y,dataPropType:Cn.Type.Num,compositeRule:!0},v),m()})}function d(v){t.code((0,be._)`${v}++`),a===void 0?t.if((0,be._)`${v} >= ${i}`,()=>t.assign(f,!0).break()):(t.if((0,be._)`${v} > ${a}`,()=>t.assign(f,!1).break()),i===1?t.assign(f,!0):t.if((0,be._)`${v} >= ${i}`,()=>t.assign(f,!0)))}}};ii.default=x0;var pf={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.validateSchemaDeps=e.validatePropertyDeps=e.error=void 0;const t=V,n=x,r=F;e.error={message:({params:{property:c,depsCount:u,deps:l}})=>{const f=u===1?"property":"properties";return(0,t.str)`must have ${f} ${l} when property ${c} is present`},params:({params:{property:c,depsCount:u,deps:l,missingProperty:f}})=>(0,t._)`{property: ${c},
160
+ missingProperty: ${f},
161
+ depsCount: ${u},
162
+ deps: ${l}}`};const o={keyword:"dependencies",type:"object",schemaType:"object",error:e.error,code(c){const[u,l]=s(c);i(c,u),a(c,l)}};function s({schema:c}){const u={},l={};for(const f in c){if(f==="__proto__")continue;const p=Array.isArray(c[f])?u:l;p[f]=c[f]}return[u,l]}function i(c,u=c.schema){const{gen:l,data:f,it:p}=c;if(Object.keys(u).length===0)return;const h=l.let("missing");for(const d in u){const v=u[d];if(v.length===0)continue;const m=(0,r.propertyInData)(l,f,d,p.opts.ownProperties);c.setParams({property:d,depsCount:v.length,deps:v.join(", ")}),p.allErrors?l.if(m,()=>{for(const y of v)(0,r.checkReportMissingProp)(c,y)}):(l.if((0,t._)`${m} && (${(0,r.checkMissingProp)(c,v,h)})`),(0,r.reportMissingProp)(c,h),l.else())}}e.validatePropertyDeps=i;function a(c,u=c.schema){const{gen:l,data:f,keyword:p,it:h}=c,d=l.name("valid");for(const v in u)(0,n.alwaysValidSchema)(h,u[v])||(l.if((0,r.propertyInData)(l,f,v,h.opts.ownProperties),()=>{const m=c.subschema({keyword:p,schemaProp:v},d);c.mergeValidEvaluated(m,d)},()=>l.var(d,!0)),c.ok(d))}e.validateSchemaDeps=a,e.default=o})(pf);var ai={};Object.defineProperty(ai,"__esModule",{value:!0});const hf=V,T0=x,C0={message:"property name must be valid",params:({params:e})=>(0,hf._)`{propertyName: ${e.propertyName}}`},R0={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:C0,code(e){const{gen:t,schema:n,data:r,it:o}=e;if((0,T0.alwaysValidSchema)(o,n))return;const s=t.name("valid");t.forIn("key",r,i=>{e.setParams({propertyName:i}),e.subschema({keyword:"propertyNames",data:i,dataTypes:["string"],propertyName:i,compositeRule:!0},s),t.if((0,hf.not)(s),()=>{e.error(!0),o.allErrors||t.break()})}),e.ok(s)}};ai.default=R0;var Or={};Object.defineProperty(Or,"__esModule",{value:!0});const Rn=F,Ne=V,M0=Re,Mn=x,D0={message:"must NOT have additional properties",params:({params:e})=>(0,Ne._)`{additionalProperty: ${e.additionalProperty}}`},L0={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:D0,code(e){const{gen:t,schema:n,parentSchema:r,data:o,errsCount:s,it:i}=e;if(!s)throw new Error("ajv implementation error");const{allErrors:a,opts:c}=i;if(i.props=!0,c.removeAdditional!=="all"&&(0,Mn.alwaysValidSchema)(i,n))return;const u=(0,Rn.allSchemaProperties)(r.properties),l=(0,Rn.allSchemaProperties)(r.patternProperties);f(),e.ok((0,Ne._)`${s} === ${M0.default.errors}`);function f(){t.forIn("key",o,m=>{!u.length&&!l.length?d(m):t.if(p(m),()=>d(m))})}function p(m){let y;if(u.length>8){const $=(0,Mn.schemaRefOrVal)(i,r.properties,"properties");y=(0,Rn.isOwnProperty)(t,$,m)}else u.length?y=(0,Ne.or)(...u.map($=>(0,Ne._)`${m} === ${$}`)):y=Ne.nil;return l.length&&(y=(0,Ne.or)(y,...l.map($=>(0,Ne._)`${(0,Rn.usePattern)(e,$)}.test(${m})`))),(0,Ne.not)(y)}function h(m){t.code((0,Ne._)`delete ${o}[${m}]`)}function d(m){if(c.removeAdditional==="all"||c.removeAdditional&&n===!1){h(m);return}if(n===!1){e.setParams({additionalProperty:m}),e.error(),a||t.break();return}if(typeof n=="object"&&!(0,Mn.alwaysValidSchema)(i,n)){const y=t.name("valid");c.removeAdditional==="failing"?(v(m,y,!1),t.if((0,Ne.not)(y),()=>{e.reset(),h(m)})):(v(m,y),a||t.if((0,Ne.not)(y),()=>t.break()))}}function v(m,y,$){const S={keyword:"additionalProperties",dataProp:m,dataPropType:Mn.Type.Str};$===!1&&Object.assign(S,{compositeRule:!0,createErrors:!1,allErrors:!1}),e.subschema(S,y)}}};Or.default=L0;var ci={};Object.defineProperty(ci,"__esModule",{value:!0});const B0=Ie,Qa=F,ro=x,Za=Or,U0={keyword:"properties",type:"object",schemaType:"object",code(e){const{gen:t,schema:n,parentSchema:r,data:o,it:s}=e;s.opts.removeAdditional==="all"&&r.additionalProperties===void 0&&Za.default.code(new B0.KeywordCxt(s,Za.default,"additionalProperties"));const i=(0,Qa.allSchemaProperties)(n);for(const f of i)s.definedProperties.add(f);s.opts.unevaluated&&i.length&&s.props!==!0&&(s.props=ro.mergeEvaluated.props(t,(0,ro.toHash)(i),s.props));const a=i.filter(f=>!(0,ro.alwaysValidSchema)(s,n[f]));if(a.length===0)return;const c=t.name("valid");for(const f of a)u(f)?l(f):(t.if((0,Qa.propertyInData)(t,o,f,s.opts.ownProperties)),l(f),s.allErrors||t.else().var(c,!0),t.endIf()),e.it.definedProperties.add(f),e.ok(c);function u(f){return s.opts.useDefaults&&!s.compositeRule&&n[f].default!==void 0}function l(f){e.subschema({keyword:"properties",schemaProp:f,dataProp:f},c)}}};ci.default=U0;var ui={};Object.defineProperty(ui,"__esModule",{value:!0});const Xa=F,Dn=V,ec=x,tc=x,F0={keyword:"patternProperties",type:"object",schemaType:"object",code(e){const{gen:t,schema:n,data:r,parentSchema:o,it:s}=e,{opts:i}=s,a=(0,Xa.allSchemaProperties)(n),c=a.filter(v=>(0,ec.alwaysValidSchema)(s,n[v]));if(a.length===0||c.length===a.length&&(!s.opts.unevaluated||s.props===!0))return;const u=i.strictSchema&&!i.allowMatchingProperties&&o.properties,l=t.name("valid");s.props!==!0&&!(s.props instanceof Dn.Name)&&(s.props=(0,tc.evaluatedPropsToName)(t,s.props));const{props:f}=s;p();function p(){for(const v of a)u&&h(v),s.allErrors?d(v):(t.var(l,!0),d(v),t.if(l))}function h(v){for(const m in u)new RegExp(v).test(m)&&(0,ec.checkStrictMode)(s,`property ${m} matches pattern ${v} (use allowMatchingProperties)`)}function d(v){t.forIn("key",r,m=>{t.if((0,Dn._)`${(0,Xa.usePattern)(e,v)}.test(${m})`,()=>{const y=c.includes(v);y||e.subschema({keyword:"patternProperties",schemaProp:v,dataProp:m,dataPropType:tc.Type.Str},l),s.opts.unevaluated&&f!==!0?t.assign((0,Dn._)`${f}[${m}]`,!0):!y&&!s.allErrors&&t.if((0,Dn.not)(l),()=>t.break())})})}}};ui.default=F0;var li={};Object.defineProperty(li,"__esModule",{value:!0});const V0=x,q0={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(e){const{gen:t,schema:n,it:r}=e;if((0,V0.alwaysValidSchema)(r,n)){e.fail();return}const o=t.name("valid");e.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},o),e.failResult(o,()=>e.reset(),()=>e.error())},error:{message:"must NOT be valid"}};li.default=q0;var fi={};Object.defineProperty(fi,"__esModule",{value:!0});const K0=F,G0={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:K0.validateUnion,error:{message:"must match a schema in anyOf"}};fi.default=G0;var di={};Object.defineProperty(di,"__esModule",{value:!0});const Qn=V,z0=x,W0={message:"must match exactly one schema in oneOf",params:({params:e})=>(0,Qn._)`{passingSchemas: ${e.passing}}`},H0={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:W0,code(e){const{gen:t,schema:n,parentSchema:r,it:o}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");if(o.opts.discriminator&&r.discriminator)return;const s=n,i=t.let("valid",!1),a=t.let("passing",null),c=t.name("_valid");e.setParams({passing:a}),t.block(u),e.result(i,()=>e.reset(),()=>e.error(!0));function u(){s.forEach((l,f)=>{let p;(0,z0.alwaysValidSchema)(o,l)?t.var(c,!0):p=e.subschema({keyword:"oneOf",schemaProp:f,compositeRule:!0},c),f>0&&t.if((0,Qn._)`${c} && ${i}`).assign(i,!1).assign(a,(0,Qn._)`[${a}, ${f}]`).else(),t.if(c,()=>{t.assign(i,!0),t.assign(a,f),p&&e.mergeEvaluated(p,Qn.Name)})})}}};di.default=H0;var pi={};Object.defineProperty(pi,"__esModule",{value:!0});const J0=x,Y0={keyword:"allOf",schemaType:"array",code(e){const{gen:t,schema:n,it:r}=e;if(!Array.isArray(n))throw new Error("ajv implementation error");const o=t.name("valid");n.forEach((s,i)=>{if((0,J0.alwaysValidSchema)(r,s))return;const a=e.subschema({keyword:"allOf",schemaProp:i},o);e.ok(o),e.mergeEvaluated(a)})}};pi.default=Y0;var hi={};Object.defineProperty(hi,"__esModule",{value:!0});const ar=V,mf=x,Q0={message:({params:e})=>(0,ar.str)`must match "${e.ifClause}" schema`,params:({params:e})=>(0,ar._)`{failingKeyword: ${e.ifClause}}`},Z0={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:Q0,code(e){const{gen:t,parentSchema:n,it:r}=e;n.then===void 0&&n.else===void 0&&(0,mf.checkStrictMode)(r,'"if" without "then" and "else" is ignored');const o=nc(r,"then"),s=nc(r,"else");if(!o&&!s)return;const i=t.let("valid",!0),a=t.name("_valid");if(c(),e.reset(),o&&s){const l=t.let("ifClause");e.setParams({ifClause:l}),t.if(a,u("then",l),u("else",l))}else o?t.if(a,u("then")):t.if((0,ar.not)(a),u("else"));e.pass(i,()=>e.error(!0));function c(){const l=e.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},a);e.mergeEvaluated(l)}function u(l,f){return()=>{const p=e.subschema({keyword:l},a);t.assign(i,a),e.mergeValidEvaluated(p,i),f?t.assign(f,(0,ar._)`${l}`):e.setParams({ifClause:l})}}}};function nc(e,t){const n=e.schema[t];return n!==void 0&&!(0,mf.alwaysValidSchema)(e,n)}hi.default=Z0;var mi={};Object.defineProperty(mi,"__esModule",{value:!0});const X0=x,ew={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:e,parentSchema:t,it:n}){t.if===void 0&&(0,X0.checkStrictMode)(n,`"${e}" without "if" is ignored`)}};mi.default=ew;Object.defineProperty(ri,"__esModule",{value:!0});const tw=Gt,nw=oi,rw=zt,ow=si,sw=ii,iw=pf,aw=ai,cw=Or,uw=ci,lw=ui,fw=li,dw=fi,pw=di,hw=pi,mw=hi,gw=mi;function yw(e=!1){const t=[fw.default,dw.default,pw.default,hw.default,mw.default,gw.default,aw.default,cw.default,iw.default,uw.default,lw.default];return e?t.push(nw.default,ow.default):t.push(tw.default,rw.default),t.push(sw.default),t}ri.default=yw;var gi={},yi={};Object.defineProperty(yi,"__esModule",{value:!0});const X=V,vw={message:({schemaCode:e})=>(0,X.str)`must match format "${e}"`,params:({schemaCode:e})=>(0,X._)`{format: ${e}}`},$w={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:vw,code(e,t){const{gen:n,data:r,$data:o,schema:s,schemaCode:i,it:a}=e,{opts:c,errSchemaPath:u,schemaEnv:l,self:f}=a;if(!c.validateFormats)return;o?p():h();function p(){const d=n.scopeValue("formats",{ref:f.formats,code:c.code.formats}),v=n.const("fDef",(0,X._)`${d}[${i}]`),m=n.let("fType"),y=n.let("format");n.if((0,X._)`typeof ${v} == "object" && !(${v} instanceof RegExp)`,()=>n.assign(m,(0,X._)`${v}.type || "string"`).assign(y,(0,X._)`${v}.validate`),()=>n.assign(m,(0,X._)`"string"`).assign(y,v)),e.fail$data((0,X.or)($(),S()));function $(){return c.strictSchema===!1?X.nil:(0,X._)`${i} && !${y}`}function S(){const b=l.$async?(0,X._)`(${v}.async ? await ${y}(${r}) : ${y}(${r}))`:(0,X._)`${y}(${r})`,N=(0,X._)`(typeof ${y} == "function" ? ${b} : ${y}.test(${r}))`;return(0,X._)`${y} && ${y} !== true && ${m} === ${t} && !${N}`}}function h(){const d=f.formats[s];if(!d){$();return}if(d===!0)return;const[v,m,y]=S(d);v===t&&e.pass(b());function $(){if(c.strictSchema===!1){f.logger.warn(N());return}throw new Error(N());function N(){return`unknown format "${s}" ignored in schema at path "${u}"`}}function S(N){const j=N instanceof RegExp?(0,X.regexpCode)(N):c.code.formats?(0,X._)`${c.code.formats}${(0,X.getProperty)(s)}`:void 0,M=n.scopeValue("formats",{key:s,ref:N,code:j});return typeof N=="object"&&!(N instanceof RegExp)?[N.type||"string",N.validate,(0,X._)`${M}.validate`]:["string",N,M]}function b(){if(typeof d=="object"&&!(d instanceof RegExp)&&d.async){if(!l.$async)throw new Error("async format in sync schema");return(0,X._)`await ${y}(${r})`}return typeof m=="function"?(0,X._)`${y}(${r})`:(0,X._)`${y}.test(${r})`}}}};yi.default=$w;Object.defineProperty(gi,"__esModule",{value:!0});const ww=yi,bw=[ww.default];gi.default=bw;var Vt={};Object.defineProperty(Vt,"__esModule",{value:!0});Vt.contentVocabulary=Vt.metadataVocabulary=void 0;Vt.metadataVocabulary=["title","description","default","deprecated","readOnly","writeOnly","examples"];Vt.contentVocabulary=["contentMediaType","contentEncoding","contentSchema"];Object.defineProperty(Vs,"__esModule",{value:!0});const Ew=qs,Sw=Gs,Ow=ri,Nw=gi,rc=Vt,_w=[Ew.default,Sw.default,(0,Ow.default)(),Nw.default,rc.metadataVocabulary,rc.contentVocabulary];Vs.default=_w;var vi={},Nr={};Object.defineProperty(Nr,"__esModule",{value:!0});Nr.DiscrError=void 0;var oc;(function(e){e.Tag="tag",e.Mapping="mapping"})(oc||(Nr.DiscrError=oc={}));Object.defineProperty(vi,"__esModule",{value:!0});const It=V,Do=Nr,sc=ge,kw=Kt,Aw=x,Iw={message:({params:{discrError:e,tagName:t}})=>e===Do.DiscrError.Tag?`tag "${t}" must be string`:`value of tag "${t}" must be in oneOf`,params:({params:{discrError:e,tag:t,tagName:n}})=>(0,It._)`{error: ${e}, tag: ${n}, tagValue: ${t}}`},jw={keyword:"discriminator",type:"object",schemaType:"object",error:Iw,code(e){const{gen:t,data:n,schema:r,parentSchema:o,it:s}=e,{oneOf:i}=o;if(!s.opts.discriminator)throw new Error("discriminator: requires discriminator option");const a=r.propertyName;if(typeof a!="string")throw new Error("discriminator: requires propertyName");if(r.mapping)throw new Error("discriminator: mapping is not supported");if(!i)throw new Error("discriminator: requires oneOf keyword");const c=t.let("valid",!1),u=t.const("tag",(0,It._)`${n}${(0,It.getProperty)(a)}`);t.if((0,It._)`typeof ${u} == "string"`,()=>l(),()=>e.error(!1,{discrError:Do.DiscrError.Tag,tag:u,tagName:a})),e.ok(c);function l(){const h=p();t.if(!1);for(const d in h)t.elseIf((0,It._)`${u} === ${d}`),t.assign(c,f(h[d]));t.else(),e.error(!1,{discrError:Do.DiscrError.Mapping,tag:u,tagName:a}),t.endIf()}function f(h){const d=t.name("valid"),v=e.subschema({keyword:"oneOf",schemaProp:h},d);return e.mergeEvaluated(v,It.Name),d}function p(){var h;const d={},v=y(o);let m=!0;for(let b=0;b<i.length;b++){let N=i[b];if(N!=null&&N.$ref&&!(0,Aw.schemaHasRulesButRef)(N,s.self.RULES)){const M=N.$ref;if(N=sc.resolveRef.call(s.self,s.schemaEnv.root,s.baseId,M),N instanceof sc.SchemaEnv&&(N=N.schema),N===void 0)throw new kw.default(s.opts.uriResolver,s.baseId,M)}const j=(h=N==null?void 0:N.properties)===null||h===void 0?void 0:h[a];if(typeof j!="object")throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${a}"`);m=m&&(v||y(N)),$(j,b)}if(!m)throw new Error(`discriminator: "${a}" must be required`);return d;function y({required:b}){return Array.isArray(b)&&b.includes(a)}function $(b,N){if(b.const)S(b.const,N);else if(b.enum)for(const j of b.enum)S(j,N);else throw new Error(`discriminator: "properties/${a}" must have "const" or "enum"`)}function S(b,N){if(typeof b!="string"||b in d)throw new Error(`discriminator: "${a}" values must be unique strings`);d[b]=N}}}};vi.default=jw;const Pw="http://json-schema.org/draft-07/schema#",xw="http://json-schema.org/draft-07/schema#",Tw="Core schema meta-schema",Cw={schemaArray:{type:"array",minItems:1,items:{$ref:"#"}},nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{allOf:[{$ref:"#/definitions/nonNegativeInteger"},{default:0}]},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}},Rw=["object","boolean"],Mw={$id:{type:"string",format:"uri-reference"},$schema:{type:"string",format:"uri"},$ref:{type:"string",format:"uri-reference"},$comment:{type:"string"},title:{type:"string"},description:{type:"string"},default:!0,readOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/definitions/nonNegativeInteger"},minLength:{$ref:"#/definitions/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},additionalItems:{$ref:"#"},items:{anyOf:[{$ref:"#"},{$ref:"#/definitions/schemaArray"}],default:!0},maxItems:{$ref:"#/definitions/nonNegativeInteger"},minItems:{$ref:"#/definitions/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},contains:{$ref:"#"},maxProperties:{$ref:"#/definitions/nonNegativeInteger"},minProperties:{$ref:"#/definitions/nonNegativeIntegerDefault0"},required:{$ref:"#/definitions/stringArray"},additionalProperties:{$ref:"#"},definitions:{type:"object",additionalProperties:{$ref:"#"},default:{}},properties:{type:"object",additionalProperties:{$ref:"#"},default:{}},patternProperties:{type:"object",additionalProperties:{$ref:"#"},propertyNames:{format:"regex"},default:{}},dependencies:{type:"object",additionalProperties:{anyOf:[{$ref:"#"},{$ref:"#/definitions/stringArray"}]}},propertyNames:{$ref:"#"},const:!0,enum:{type:"array",items:!0,minItems:1,uniqueItems:!0},type:{anyOf:[{$ref:"#/definitions/simpleTypes"},{type:"array",items:{$ref:"#/definitions/simpleTypes"},minItems:1,uniqueItems:!0}]},format:{type:"string"},contentMediaType:{type:"string"},contentEncoding:{type:"string"},if:{$ref:"#"},then:{$ref:"#"},else:{$ref:"#"},allOf:{$ref:"#/definitions/schemaArray"},anyOf:{$ref:"#/definitions/schemaArray"},oneOf:{$ref:"#/definitions/schemaArray"},not:{$ref:"#"}},Dw={$schema:Pw,$id:xw,title:Tw,definitions:Cw,type:Rw,properties:Mw,default:!0};(function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MissingRefError=t.ValidationError=t.CodeGen=t.Name=t.nil=t.stringify=t.str=t._=t.KeywordCxt=t.Ajv=void 0;const n=pl,r=Vs,o=vi,s=Dw,i=["/properties"],a="http://json-schema.org/draft-07/schema";class c extends n.default{_addVocabularies(){super._addVocabularies(),r.default.forEach(d=>this.addVocabulary(d)),this.opts.discriminator&&this.addKeyword(o.default)}_addDefaultMetaSchema(){if(super._addDefaultMetaSchema(),!this.opts.meta)return;const d=this.opts.$data?this.$dataMetaSchema(s,i):s;this.addMetaSchema(d,a,!1),this.refs["http://json-schema.org/schema"]=a}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(a)?a:void 0)}}t.Ajv=c,e.exports=t=c,e.exports.Ajv=c,Object.defineProperty(t,"__esModule",{value:!0}),t.default=c;var u=Ie;Object.defineProperty(t,"KeywordCxt",{enumerable:!0,get:function(){return u.KeywordCxt}});var l=V;Object.defineProperty(t,"_",{enumerable:!0,get:function(){return l._}}),Object.defineProperty(t,"str",{enumerable:!0,get:function(){return l.str}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return l.stringify}}),Object.defineProperty(t,"nil",{enumerable:!0,get:function(){return l.nil}}),Object.defineProperty(t,"Name",{enumerable:!0,get:function(){return l.Name}}),Object.defineProperty(t,"CodeGen",{enumerable:!0,get:function(){return l.CodeGen}});var f=En;Object.defineProperty(t,"ValidationError",{enumerable:!0,get:function(){return f.default}});var p=Kt;Object.defineProperty(t,"MissingRefError",{enumerable:!0,get:function(){return p.default}})})(jo,jo.exports);var Lw=jo.exports;const Bw=im(Lw);class gf extends Error{constructor(t){super(t.length>0?`Config validation failed: ${t.map(n=>`${n.field} ${n.message}`).join("; ")}`:"Config validation failed"),this.fieldErrors=t,this.name="ValidationError"}}function Uw(e,t){if(!t)return;const n=t,r=n.properties;if(r!==void 0&&Object.keys(r).length===0)return;const o=new Bw({allErrors:!0,strict:!1}).compile(n);if(!o(e))throw new gf(Fw(o.errors??[]))}function Fw(e){return e.map(t=>({field:Vw(t),message:t.message??"is invalid",keyword:t.keyword}))}function Vw(e){var t;return(e.instancePath??"").replace(/^\//,"").replace(/\//g,".")||(((t=e.params)==null?void 0:t.missingProperty)??"(root)")}function qw(e,t){return D.join($u(e,t),gg)}const Kw=384,Gw=448;function zw(e,t,n={}){const r=n.mode??Kw,o=n.dirMode??Gw,s=D.dirname(e);K.mkdirSync(s,{recursive:!0,mode:o}),K.chmodSync(s,o);const i=`${e}.tmp`,a=typeof t=="string"?t:JSON.stringify(t,null,2);try{K.writeFileSync(i,a,{encoding:"utf8",mode:r}),K.chmodSync(i,r),K.renameSync(i,e),K.chmodSync(e,r)}catch(c){try{K.existsSync(i)&&K.unlinkSync(i)}catch{}throw c}}const Ww="0.1.0";function ic(e,t){if(!e||e==="."||e===".."||e.includes("/")||e.includes("\\")||e.includes("\0"))throw new Error(`${t} must be a non-empty path segment with no '.', '..', path separators, or NUL: ${JSON.stringify(e)}`)}function Hw(){return`${process.pid}-${au.randomBytes(3).toString("hex")}`}function yf(e,t,n={}){if(!e)throw new Error("Environment requires a non-empty 'project' name");ic(e,"project");const r=t.orgNamespace??hg,o=t.envPrefixOverride??bg(e),s=t.namespaces&&t.namespaces.length>0?t.namespaces:[mg],i=n.namespace??s[0];if(!s.includes(i))throw new Error(`Namespace "${i}" is not declared for project "${e}" (declared: ${s.join(", ")})`);ic(i,"namespace");const a=n.processEnv??process.env,{scope:c,projectRoot:u}=rm({scope:n.scope,cwd:n.cwd},a),l=sm({project:e,namespace:i,orgNamespace:r,projectRoot:u,adhdRoot:n.adhdRoot});return{project:e,namespace:i,orgNamespace:r,envPrefix:o,scope:c,projectRoot:u,roots:l}}function Jw(e,t,n={}){const{namespace:r,orgNamespace:o,envPrefix:s,scope:i,projectRoot:a,roots:c}=yf(e,t,n),u=n.processEnv??process.env,l=Pg(c),f=n.instanceId??Hw(),{raw:p,nested:h,typedRaw:d,provenance:v,fields:m}=Cg(t.config,l,u,{prefix:s,activeScope:i}),y={};for(const N of Object.keys(m)){const j=m[N];j.live&&(y[N]={env:j.env,type:j.type,fallback:j.secret===!0?void 0:j.fallbackValue})}const $=Sg(t.config);Uw(dl(d),$);const S=Mg(t.dirs,{roots:c,activeScope:i,instanceId:f,projectRoot:a,namespace:r}),b=Dg(t.files,S);return{version:pg,libraryVersion:Ww,generatedAt:new Date().toISOString(),project:e,namespace:r,orgNamespace:o,envPrefix:s,scope:i,instanceId:f,config:h,raw:p,liveFields:y,fieldSchema:$,configHash:$g(Object.fromEntries(Object.entries(d).map(([N,j])=>[N,String(j)]))),structureHash:wg(Object.values(S).map(N=>({name:N.name,kind:N.kind,scope:N.scope}))),dirs:Object.values(S),files:Object.values(b),provenance:v}}let yn=class extends Error{constructor(t){super(t),this.name="EnvironmentError"}};class Yw extends yn{constructor(t){super(`adhd-environment snapshot not found: ${t}`),this.snapshotPath=t,this.name="SnapshotNotFoundError"}}class Qw extends yn{constructor(t,n){super(`lock "${t}" is already held (${n})`),this.lockName=t,this.lockPath=n,this.name="LockHeldError"}}function Zw(e,t){let n=e;for(const r of t.split("."))if(n!==null&&typeof n=="object"&&r in n)n=n[r];else return;return n}function Lo(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>Lo(n));const t={};for(const[n,r]of Object.entries(e))t[n]=Lo(r);return t}function Xw(e,t){const n=Lo(e);for(const r of Object.keys(t)){const o=t[r],s=r.split(".");let i=n;for(let c=0;c<s.length-1;c++){const u=s[c],l=i[u];(typeof l!="object"||l===null||Array.isArray(l))&&(i[u]={}),i=i[u]}const a=s[s.length-1];Object.defineProperty(i,a,{enumerable:!0,configurable:!0,get(){const c=process.env[o.env];return c!==void 0?Io(c,o.type):o.fallback}})}return n}function eb(e){if(!e||e==="."||e===".."||e.includes("/")||e.includes("\\")||e.includes("\0"))throw new yn(`lock name must be a non-empty path segment with no path separators: ${JSON.stringify(e)}`)}class $i{constructor(t,n,r={}){let o,s;try{o=Jw(t,n,r);const i=yf(t,n,r);s=qw(i.roots,o.scope)}catch(i){throw i instanceof gf||i instanceof yn?i:new yn(i instanceof Error?i.message:String(i))}return ac(this,o,s)}static fromSnapshot(t){if(!K.existsSync(t))throw new Yw(t);const n=JSON.parse(K.readFileSync(t,"utf8")),r=Object.create($i.prototype);return ac(r,n,t)}get(t){const n=t.indexOf(".");if(n===-1)return;const r=t.slice(0,n),o=t.slice(n+1);switch(r){case"config":return Zw(this.config,o);case"path":return this.paths[o];case"env":return this.resolveEnvName(o);case"provenance":return this._data.provenance[o];default:return}}isEnvNameAllowed(t){return t.startsWith(this.prefix)}resolveEnvName(t){if(this.isEnvNameAllowed(t))return process.env[t]}lock(t="singleton"){eb(t);const n=this.paths.run??this._runDirFallback();K.mkdirSync(n,{recursive:!0});const r=D.join(n,`${t}.lock`);let o;try{o=K.openSync(r,"wx")}catch(i){throw(i==null?void 0:i.code)==="EEXIST"?new Qw(t,r):i}K.writeSync(o,`${process.pid}
163
+ ${this.instanceId}
164
+ `),K.closeSync(o);let s=!1;return()=>{if(!s){s=!0;try{K.unlinkSync(r)}catch{}}}}_runDirFallback(){return D.join(D.dirname(this.snapshotPath),"run")}ensureDirs(){for(const t of Object.values(this.paths))K.mkdirSync(t,{recursive:!0})}write(){return zw(this.snapshotPath,this._data),this.snapshotPath}toJSON(){return Object.freeze(JSON.parse(JSON.stringify(this._data)))}}function ac(e,t,n){const r={};for(const i of t.dirs)r[i.name]=i.path;const o={};for(const i of t.files)o[i.name]=i.path;const s=Xw(t.config,t.liveFields??{});return Object.defineProperties(e,{project:{value:t.project,enumerable:!0},namespace:{value:t.namespace,enumerable:!0},orgNamespace:{value:t.orgNamespace,enumerable:!0},scope:{value:t.scope,enumerable:!0},prefix:{value:t.envPrefix,enumerable:!0},instanceId:{value:t.instanceId,enumerable:!0},hash:{value:t.configHash,enumerable:!0},version:{value:{configHash:t.configHash,structureHash:t.structureHash,generatedAt:t.generatedAt,libraryVersion:t.libraryVersion},enumerable:!0},provenance:{value:t.provenance,enumerable:!0},dirs:{value:t.dirs,enumerable:!0},snapshotPath:{value:n,enumerable:!0},config:{value:s,enumerable:!0},paths:{value:r,enumerable:!0},files:{value:o,enumerable:!0},_data:{value:t,enumerable:!1}}),new Proxy(e,{get(i,a,c){return typeof a=="string"&&!(a in i)?i.get(a):Reflect.get(i,a,c)}})}const vf={envPrefixOverride:"ADHD_BACKLOG",namespaces:["production"],dirs:{data:{kind:"data"}},files:{db:{in:"data",name:"backlog.db"}},config:{"db.path":{type:"string",env:"ADHD_BACKLOG_DATABASE_PATH",description:"SQLite backlog-graph DB path. Unset ⇒ falls back to env.files.db under the resolved scope root."},"db.busyTimeoutMs":{type:"integer",env:"ADHD_BACKLOG_DATABASE_BUSY_TIMEOUT_MS",default:5e3,description:"SQLite `busy_timeout` (ms) each write waits for a contended lock before retrying (DEBT-BACKLOG-CONCURRENCY-BUSY-RETRY-001). Raise this when scaling toward more concurrent agents writing the same global-scope store."},"logging.level":{type:"string",env:"ADHD_BACKLOG_LOG_LEVEL",default:"info",enum:["trace","debug","info","warn","error","fatal","silent"]},"migration.phase":{type:"string",env:"ADHD_BACKLOG_MIGRATION_PHASE",default:"not-started",enum:["not-started","phase-1","phase-2","phase-3","phase-4","phase-5","complete"],description:"MIGRATION.md §4.4 — a queried signal (never hardcoded prose) for whether BACKLOG.md or the tool is authoritative right now. Read via `migrationStatus(ctx)`/`backlog migration-status`. NOT yet per-repo-keyed (MIGRATION.md §9 open decision 6) — one global value."}}};function $f(e){if(e)return e;const t=process.env.ADHD_BACKLOG_SCOPE;if(t)return t;const n=process.env.ADHD_ENV_SCOPE;return n||"global"}function wi(e={}){const t={namespace:"production",scope:$f(e.scope)};return e.adhdRoot!==void 0&&(t.adhdRoot=e.adhdRoot),e.cwd!==void 0&&(t.cwd=e.cwd),e.instanceId!==void 0&&(t.instanceId=e.instanceId),new $i("backlog",vf,t)}function tb(e,t){return`${e}:${t}`}const wf=Symbol.for("adhd.apigen.extraction-session");function bf(e,t){const n=[...e.getImportDeclarations().map(r=>r.getModuleSpecifierSourceFile()),...e.getExportDeclarations().map(r=>r.getModuleSpecifierSourceFile())];for(const r of n){if(!r)continue;const o=r.getFilePath();if(!o.includes("/node_modules/")&&!t.has(o)){t.add(o);try{r.refreshFromFileSystemSync()}catch{}bf(r,t)}}}function Ef(e){try{const t=K.statSync(e);return`${t.mtimeMs}:${t.size}`}catch{return"nostat"}}const Zn=new Map,cc=new Map;function nb(e,t,n){const r=t??"",o=Zn.get(r);let s=n;if(o&&o.fileVersions.size>0){const c=[n],u=[...o.fileVersions.entries()].sort(([l],[f])=>l.localeCompare(f));for(const[l,f]of u)l!==e&&c.push(`${l}:${f}`);s=c.join("|")}const i=`${e}\0${t??""}`;let a=cc.get(i);return(!a||a.version!==s)&&(a={version:s,schemas:new Map},cc.set(i,a)),a.schemas}function rb(){const e={projectsBuilt:0,generatorsBuilt:0,schemaCacheHits:0,schemaCacheMisses:0},t=new Map;let n=!1;return{[wf]:!0,stats:e,schemaCache:new Map,aliasCache:new WeakMap,zodImportCache:new WeakMap,generatorCache:new Map,projectFor(r){if(n)throw new Error("apigen-core: ExtractionSession used after dispose()");const o=r??"",s=r?this.statVersion(r):"";let i=Zn.get(o);return i&&i.tsconfigVersion!==s&&(i=void 0),i||(i={project:r?new Qi.Project({tsConfigFilePath:r,skipAddingFilesFromTsConfig:!0}):new Qi.Project({skipAddingFilesFromTsConfig:!0}),tsconfigVersion:s,fileVersions:new Map},Zn.set(o,i),e.projectsBuilt++),i.project},sourceFileFor(r,o){const s=this.projectFor(o),i=Zn.get(o??""),a=this.statVersion(r);let c=s.getSourceFile(r);if(c===void 0?c=s.addSourceFileAtPath(r):i&&i.fileVersions.get(r)!==a&&c.refreshFromFileSystemSync(),i==null||i.fileVersions.set(r,a),i){const u=new Set([r]);bf(c,u);for(const l of u)l!==r&&i.fileVersions.set(l,this.statVersion(l))}return c},statVersion(r){let o=t.get(r);return o===void 0&&(o=Ef(r),t.set(r,o)),o},dispose(){n=!0,this.schemaCache.clear(),this.generatorCache.clear(),t.clear()}}}function ob(e){const t=e;if(t[wf]!==!0)throw new Error("apigen-core: unknown ExtractionSession implementation — create sessions with createExtractionSession()");return t}const cr="x-apigen-logical";function uc(e,t){const n=new Set,r=[e];for(;r.length>0;){const o=r.pop();if(!o||n.has(o))continue;n.add(o);const s=o.$ref;if(typeof s=="string"){if(t){const f=t[s];if(!f){const p=Object.keys(t).join(", ")||"(none)";throw new Error(`[apigen-logical] $ref "${s}" cannot be resolved. Available $defs: ${p}`)}r.push(f)}continue}const i=o.oneOf;if(Array.isArray(i))for(const f of i)typeof f=="object"&&f!==null&&r.push(f);const a=o.properties;if(a)for(const f of Object.values(a))r.push(f);const c=o.items;if(Array.isArray(c))for(const f of c)typeof f=="object"&&f!==null&&r.push(f);else typeof c=="object"&&c!==null&&r.push(c);const u=o.additionalProperties;typeof u=="object"&&u!==null&&r.push(u);const l=o.propertyNames;typeof l=="object"&&l!==null&&r.push(l)}}const lc=new Set(["string","number","boolean","integer"]);function sb(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?lc.has(n):Array.isArray(n)?n.every(r=>lc.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function ib(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(sb)}function ab(e){const t={},n=r=>{for(const o of["definitions","$defs"]){const s=r[o];if(s)for(const[i,a]of Object.entries(s)){const c=i.startsWith("#/")?i:`#/${o}/${i}`;t[c]=a}}};for(const r of Object.values(e.schemas))n(r.input),n(r.output);if(Object.keys(t).length!==0)for(const[r,o]of Object.entries(e.schemas))try{uc(o.input,t),uc(o.output,t)}catch(s){throw new Error(`[apigen-core-client] Schema validation failed for function "${r}": ${s.message}`)}}function cb(e,t){const n=['apigen calling convention: all domain parameters go inside a "data" envelope — e.g. { "data": { ... } }'+(t?".":" (an empty object for this zero-parameter tool).")];return e.length>0&&n.push(`Field(s) ${e.map(r=>`"${r}"`).join(", ")} are transport-level envelope metadata, NOT domain data — do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`),n.join(" ")}function ub(e,t,n){ab(e);const r={};for(const[o,s]of Object.entries(e.schemas)){const i={},a=s.input.properties??{},c=s.input.required??[],u={},l=[],f={};for(const m of t)if(m.envelope&&i[m.id]!==!1)for(const[y,$]of Object.entries(m.envelope))u[y]=$,f[y]=m.id,l.includes(y)||l.push(y);const p={type:"object",properties:a,additionalProperties:!1,...c.length>0?{required:c}:{}},h=s.safe===!0||ib(s.input),d=s.input.definitions,v=s.input.$defs;r[o]={input:{type:"object",properties:{...u,data:p},required:[...l,...c.length>0?["data"]:[]],additionalProperties:!1,description:cb(Object.keys(u),Object.keys(a).length>0),...d?{definitions:d}:{},...v?{$defs:v}:{}},output:s.output,...s.hasCtx?{hasCtx:!0}:{},"x-apigen-safe":h,...Object.keys(f).length>0?{"x-apigen-envelope":f}:{}}}return r}const lb=8;function fb(e,t){try{return t?e.getText(t):e.getText()}catch{try{return e.getText()}catch{return}}}let db=0;async function pb(e,t,n,r){const o=`__ApigenProbe_${process.pid}_${db++}`;let s;try{s=t.addTypeAlias({name:o,type:n});const i=s.getType();return await r(i)}catch{return}finally{try{s==null||s.remove()}catch{}}}async function Sf(e,t,n){if(n>lb)return{};if(e.isString()||e.isStringLiteral())return e.isStringLiteral()?{type:"string",enum:[e.getLiteralValue()]}:{type:"string"};if(e.isNumber()||e.isNumberLiteral())return e.isNumberLiteral()?{type:"number",enum:[e.getLiteralValue()]}:{type:"number"};if(e.isBoolean())return{type:"boolean"};if(e.isBooleanLiteral())return{type:"boolean"};if(e.isNull()||e.isUndefined()||e.isVoid())return{type:"null"};if(e.isUnion()){const r=e.getUnionTypes();if(r.every(i=>i.isStringLiteral())&&r.length>0)return{type:"string",enum:r.map(i=>i.getLiteralValue())};if(r.every(i=>i.isNumberLiteral())&&r.length>0)return{type:"number",enum:r.map(i=>i.getLiteralValue())};const o=await Promise.all(r.map(i=>Sf(i,t,n+1))),s=bi(o);return{oneOf:o,...s?{discriminator:s}:{},[cr]:"union"}}if(e.isArray()){const r=e.getArrayElementType();return{type:"array",items:r?await t(r.getText()):{}}}if(e.isTuple()){const r=e.getTupleElements(),o=await Promise.all(r.map(s=>t(s.getText())));return{type:"array",items:o,minItems:o.length,maxItems:o.length}}if(e.isObject()){const r=e.getStringIndexType(),o=e.getNumberIndexType(),s=r??o,i=e.getProperties();if(s&&i.length===0)return{type:"object",additionalProperties:await t(s.getText())};const a={};for(const c of i){const u=c.getName(),l=c.getDeclarations()[0];let f;if(l)try{f=c.getTypeAtLocation(l)}catch{f=void 0}if(f!==void 0&&f.getCallSignatures().length>0)continue;const p=f!==void 0?fb(f,l):void 0;a[u]=p!==void 0?await t(p):{}}return Object.keys(a).length>0?{type:"object",properties:a}:{}}return{}}function bi(e){if(e.length<2)return;const t=[];for(const r of e){if(r.type!=="object")return;const o=r.properties;if(!o||typeof o!="object")return;t.push(o)}const n=Object.keys(t[0]).filter(r=>t.every(o=>Object.prototype.hasOwnProperty.call(o,r)));for(const r of n){const o=[];let s=!0;for(const a of t){const c=a[r],u=c&&(c.type==="string"||c.type==="number"),l=c==null?void 0:c.enum;if(!u||!Array.isArray(l)||l.length!==1){s=!1;break}o.push(String(l[0]))}if(!s||new Set(o).size!==o.length)continue;const i={};return o.forEach((a,c)=>{i[a]=`#/oneOf/${c}`}),{propertyName:r,mapping:i}}}function Xn(e,t,n){if(t>6)return{};const r=e.trim();if(r==="string")return{type:"string"};if(r==="number")return{type:"number"};if(r==="boolean")return{type:"boolean"};if(r==="null")return{type:"null"};if(r==="undefined")return{type:"null"};const o=Bo[r];if(o!==void 0)return o;if(n!=null&&n.size){const s=n.get(r);if(s!==void 0){const i=Bo[s];if(i!==void 0)return i}}if(r.endsWith("[]"))return{type:"array",items:Xn(r.slice(0,-2),t+1,n)};if(r.includes("|")){const s=r.split("|").map(c=>c.trim());if(s.every(c=>c.startsWith("'")))return{type:"string",enum:s.map(c=>c.replace(/'/g,""))};const i=s.map(c=>Xn(c,t+1,n)),a=bi(i);return{oneOf:i,...a?{discriminator:a}:{},[cr]:"union"}}if(r.startsWith("{")&&r.endsWith("}")){const s=r.slice(1,-1).trim(),i={};for(const a of s.split(";").filter(Boolean)){const[c,u]=a.split(":").map(l=>l.trim());c&&u&&(i[c.replace("?","")]=Xn(u,t+1,n))}return{type:"object",properties:i}}return{}}function Of(e){const t=[];let n=0,r=0;for(let s=0;s<e.length;s++){const i=e[s];i==="<"||i==="["||i==="{"||i==="("?n++:i===">"||i==="]"||i==="}"||i===")"?n--:i===","&&n===0&&(t.push(e.slice(r,s).trim()),r=s+1)}const o=e.slice(r).trim();return o.length>0&&t.push(o),t}function hb(e){const t=/^(?:Readonly)?Map<(.+)>$/.exec(e);return t?t[1]:void 0}function mb(e){const t=/^(?:Readonly)?Set<(.+)>$/.exec(e);return t?t[1]:void 0}function gb(e){let t=e.trim();if(t.startsWith("readonly ")&&(t=t.slice(9).trim()),!t.startsWith("[")||!t.endsWith("]"))return;const n=t.slice(1,-1).trim();if(n.length!==0)return Of(n)}async function yb(e,t){const n=e.trim(),r=hb(n);if(r!==void 0){const i=Of(r);if(i.length===2){const[a,c]=await Promise.all([t(i[0]),t(i[1])]);return{type:"array",items:{type:"array",items:[a,c],minItems:2,maxItems:2}}}}const o=mb(n);if(o!==void 0)return{type:"array",items:await t(o),uniqueItems:!0};const s=gb(n);if(s!==void 0){const i=await Promise.all(s.map(a=>t(a)));return{type:"array",items:i,minItems:i.length,maxItems:i.length}}}const Nf={"decimal.js":"Decimal"},Bo={Date:{type:"string",format:"date-time"},bigint:{type:"string",format:"int64"},Uint8Array:{type:"string",format:"byte"},Buffer:{type:"string",format:"byte"},URL:{type:"string",format:"uri"},RegExp:{type:"string",format:"regex"},Decimal:{type:"string",format:"decimal"}},fc={Uint8Array:"byte",Buffer:"byte",Decimal:"decimal"};function dc(e){var t;const n=new Map;for(const r of e.getImportDeclarations()){const o=r.getModuleSpecifierValue(),s=Nf[o];if(!s)continue;const i=r.getDefaultImport();if(i){const a=i.getText();a!==s&&n.set(a,s)}for(const a of r.getNamedImports()){const c=((t=a.getAliasNode())==null?void 0:t.getText())??a.getName();c!==s&&n.set(c,s)}}return n}function vb(e,t){return n=>{n.addNodeParser({supportsNode(r){var o,s,i;if(r.kind!==t)return!1;const a=((o=r.typeName)==null?void 0:o.escapedText)??((i=(s=r.typeName)==null?void 0:s.right)==null?void 0:i.escapedText);return a!==void 0&&Object.prototype.hasOwnProperty.call(fc,a)},createType(r){var o,s,i;const a=((o=r.typeName)==null?void 0:o.escapedText)??((i=(s=r.typeName)==null?void 0:s.right)==null?void 0:i.escapedText);return new dt.AnnotatedType(new dt.StringType,{format:fc[a]},!1)}}),n.addNodeParser({supportsNode(r){return r.kind===e},createType(){return new dt.AnnotatedType(new dt.StringType,{format:"int64"},!1)}})}}let Qt;function $b(){if(Qt)return Qt;try{const e=D.dirname(require.resolve("ts-json-schema-generator/package.json"));Qt=require(require.resolve("typescript",{paths:[e]}))}catch{Qt=require("typescript")}return Qt}const Je=new Map;function wb(){const e=process.env.APIGEN_PROGRAM_CACHE,t=e===void 0?NaN:Number(e);return Number.isFinite(t)&&t>=0?t:8}function bb(e){const t=Je.get(e);return t&&(Je.delete(e),Je.set(e,t)),t}function Eb(e,t){const n=wb();if(n!==0)for(Je.delete(e),Je.set(e,t);Je.size>n;){const r=Je.keys().next().value;Je.delete(r)}}function Sb(e,t){return`${e}\0${t??""}`}const Ob=new Set(["zod",/^zod\/./]);function Nb(e){for(const t of e.getImportDeclarations()){const n=t.getModuleSpecifierValue();for(const r of Ob)if(typeof r=="string"){if(n===r)return!0}else if(r.test(n))return!0}return!1}function _b(e){for(const t of["$defs","definitions"]){const n=e[t];if(!n||typeof n!="object")continue;const r=Object.keys(n);if(r.length===0)continue;const o=new Set(r.filter(s=>/zod/i.test(s)));for(const[s,i]of Object.entries(n)){if(o.has(s)||typeof i!="object"||i===null)continue;const a=i,c=typeof a.$ref=="string"?a.$ref:"";if(c){for(const u of o)if(c.includes(u)){o.add(s);break}}}for(const s of o)delete n[s]}Uo(e)}function Uo(e,t){if(!e||typeof e!="object")return;const n=t??new WeakSet;if(!n.has(e)){n.add(e);for(const r of Object.keys(e))if(r==="$ref"&&typeof e[r]=="string"){const o=e[r];/zod/i.test(o)&&delete e[r]}for(const[,r]of Object.entries(e))if(typeof r=="object"&&r!==null)if(Array.isArray(r))for(const o of r)typeof o=="object"&&o!==null&&Uo(o,n);else Uo(r,n)}}function kb(e){const t=new Set;for(const r of["$defs","definitions"]){const o=e[r];if(o&&typeof o=="object")for(const s of Object.keys(o))t.add(s)}const n=Fo(e,t);if(n.length>0)throw new Error(`[apigen-core-client] Generated schema contains ${n.length} unresolvable $ref(s): ${n.join(", ")}. This usually means zod-internal definitions were stripped but $ref references to them remain. Check the source file's imports or the ts-json-schema-generator output.`)}function Fo(e,t){if(!e||typeof e!="object")return[];const n=[];for(const[r,o]of Object.entries(e))if(r==="$ref"&&typeof o=="string"){const s=o.match(/#\/(?:\$defs|definitions)\/(.+)$/);s&&!t.has(s[1])&&n.push(o)}else if(typeof o=="object"&&o!==null)if(Array.isArray(o))for(const s of o)typeof s=="object"&&s!==null&&n.push(...Fo(s,t));else n.push(...Fo(o,t));return n}function Ab(e){const t=e.anyOf;if(!Array.isArray(t)||t.length<2)return e;const n=t,r=bi(n),o={...e};return delete o.anyOf,{...o,oneOf:n,...r?{discriminator:r}:{},[cr]:o[cr]??"union"}}function Ib(e,t,n){const{DEFAULT_CONFIG:r}=require("ts-json-schema-generator/dist/src/Config.js"),o={...r,...e},s=o.path,i=Sb(s,o.tsconfig);let a;a=n?n.statVersion(s):Ef(s);let c;if(i!==void 0){const l=(n==null?void 0:n.generatorCache.get(i))??bb(i);l&&l.version===a&&(c=l.gen)}if(!c){const{createProgram:l}=require("ts-json-schema-generator/dist/factory/program.js"),f=$b(),p=vb(f.SyntaxKind.BigIntKeyword,f.SyntaxKind.TypeReference),h=l(o),d=dt.createParser(h,o,p),v=dt.createFormatter(o);if(c=new dt.SchemaGenerator(h,d,v,o),n&&n.stats.generatorsBuilt++,i!==void 0&&a!==void 0){const m={version:a,gen:c};Eb(i,m),n==null||n.generatorCache.set(i,m)}}const u=c.createSchema(o.type);return _b(u),kb(u),u}function jb(e,t){let n=e.trim();if(n=kf(n),t!=null&&t.size){const o=t.get(n);if(o!==void 0)return o}const r=n.match(/^ReadonlyArray<(.+)>$/);for(r&&(n=`${r[1].trim()}[]`);n.startsWith("readonly ");)n=n.slice(9).trim();return n}function _f(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const Pb=Object.entries(Nf).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${_f(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function kf(e){let t=e;for(const{pattern:n,key:r}of Pb)t=t.replace(n,r);return t}function xb(e,t){let n=kf(e);for(const[r,o]of t)n=n.replace(new RegExp(`\\b${_f(r)}\\b`,"g"),o);return n}async function vn(e,t,n,r,o,s){const i=t.getFilePath(),a=`${i}\0${r??""}\0${n}`,c=s??new Set;if(c.has(a))return{};if(!o){const d=new Set(c);return d.add(a),pc(e,t,n,r,void 0,d)}const u=o.schemaCache.get(a);if(u!==void 0)return o.stats.schemaCacheHits++,u;const l=nb(i,r,o.statVersion(i)),f=l.get(n);if(f!==void 0)return o.stats.schemaCacheHits++,o.schemaCache.set(a,Promise.resolve(f)),f;o.stats.schemaCacheMisses++;const p=new Set(c);p.add(a);const h=pc(e,t,n,r,o,p).then(d=>(l.set(n,d),d)).catch(d=>{throw o.schemaCache.delete(a),d});return o.schemaCache.set(a,h),h}async function pc(e,t,n,r,o,s){if(["void","undefined","null","Promise<void>"].includes(n))return{type:"null"};let i;if(o){const p=o.aliasCache.get(t);i=p??dc(t),p||o.aliasCache.set(t,i)}else i=dc(t);const a=jb(n,i),c=Bo[a];if(c!==void 0)return c;const u=await yb(a,p=>vn(e,t,p,r,o,s));if(u!==void 0)return u;const l=(o==null?void 0:o.zodImportCache.get(t))??Nb(t);if(o&&o.zodImportCache.set(t,l),!l)try{const p={path:t.getFilePath(),type:a,skipTypeCheck:!0,tsconfig:r,topRef:!1},h=Ib(p,!0,o);return Ab(h)}catch{}try{const p=await pb(e,t,a,h=>Sf(h,d=>vn(e,t,d,r,o,s),0));if(p!==void 0)return p}catch{}const f=xb(a,i);return Xn(f,0,i)}function Ei(e,t,n){if(e!=null&&e.hasInitializer()){const r=e.getInitializer();if(r)return r.getText()}return Tb(n,t)}function Tb(e,t){var n;const r=e,o=((n=r==null?void 0:r.getJsDocs)==null?void 0:n.call(r))??[],s=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`\\[\\s*${s}\\s*=\\s*([^\\]]+)\\]`);for(const a of o)for(const c of a.getTags()){if(c.getTagName()!=="param")continue;const u=c.getText().match(i);if(u)return u[1].trim()}}function Cb(e){const t=e.trim(),n=t.match(/^(['"`])([\s\S]*)\1$/);if(n)return n[2];if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null;if(t!=="undefined"){if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);try{return JSON.parse(t)}catch{return t}}}function Rb(e,t){const n=Cb(t);if(n===void 0)return;e.default=n;const r=typeof n=="string"?n:JSON.stringify(n),o=typeof e.description=="string"?e.description:void 0;e.description=o?`${o} (default: ${r})`:`(default: ${r})`}async function Mb(e){const t=e.session===void 0,n=ob(e.session??rb());try{return await Db(e,n)}finally{t&&n.dispose()}}async function Db(e,t){const{sourceFile:n,namespace:r="",dropFileSegment:o=!1,tsconfig:s}=e,i=t.projectFor(s),a=t.sourceFileFor(n,s),c=D.basename(n),u=De(Fb(c)),l=o?null:u,f=De(r),p=[];for(const[v,m]of a.getExportedDeclarations()){if(v==="default"||Bn(v))continue;const y=qb(m);if(y){const N=y.getSignature(),j=hc(N,y),M=N.getReturnType().getText();p.push(await Ln(i,a,f,l,v,j,M,y.isAsync(),s,t));continue}const $=m.find(N=>N.getKindName()==="VariableDeclaration");if(!$)continue;const S=$.getInitializer(),b=S==null?void 0:S.getKindName();if(S&&["ArrowFunction","FunctionExpression"].includes(b??"")){const N=$.getType().getCallSignatures();if(N.length===0)continue;const j=N[0],M=mc(j,$,$.getVariableStatement()),H=j.getReturnType().getText(),Z=S.isAsync();p.push(await Ln(i,a,f,l,v,M,H,Z,s,t))}else if(b==="ObjectLiteralExpression"){const N=$.getType();for(const j of N.getProperties()){const M=j.getName();if(Bn(M))continue;const H=j.getTypeAtLocation($).getCallSignatures();if(H.length===0)continue;const Z=H[0],le=mc(Z,$,$.getVariableStatement()),fe=Z.getReturnType().getText(),ye=[...l?[l]:[],De(v),De(M)];p.push(await er(i,a,f,ye,M,le,fe,!1,s,t))}}else{const N=$.getType(),j=N.getText();if(ct(N,$)){const M=await vn(i,a,j,s,t);p.push(Bb(f,l,v,M))}else console.warn(`[apigen-core] Skipping non-callable, non-serializable export: ${v}`)}}const h=a.getDefaultExportSymbol();if(h){const v=a.getExportAssignment(m=>!m.isExportEquals());if(v){const m=v.getExpression(),y=m.getKindName();if(["ArrowFunction","FunctionExpression"].includes(y)){const $=m.getType().getCallSignatures();if($.length>0){const S=$[0],b=oo(S,v),N=S.getReturnType().getText(),j=m.isAsync();p.push(await Ln(i,a,f,l,"default",b,N,j,s,t))}}else{const $=m.getType();for(const S of $.getProperties()){const b=S.getName();if(Bn(b))continue;const N=S.getTypeAtLocation(v).getCallSignatures();if(N.length===0)continue;const j=N[0],M=oo(j,v),H=j.getReturnType().getText(),Z=[...l?[l]:[],De("default"),De(b)];p.push(await er(i,a,f,Z,b,M,H,!1,s,t))}}}else{const m=h.getDeclarations();for(const y of m){if(y.getKindName()!=="FunctionDeclaration")continue;const $=y,S=$.getName(),b=S&&S.length>0?S:"default",N=$.getSignature(),j=hc(N,$),M=N.getReturnType().getText();p.push(await Ln(i,a,f,l,b,j,M,$.isAsync(),s,t))}}}const d=Vb(a);if(d.length>0)for(const{name:v,sig:m}of d){if(Bn(v))continue;const y=oo(m),$=m.getReturnType().getText(),S=[...l?[l]:[],De(v)];p.push(await er(i,a,f,S,v,y,$,!1,s,t))}return p}function Lb(e,t,n,r){const o=new Set,s=i=>{if(Array.isArray(i))return i.map(s);if(!i||typeof i!="object"||o.has(i))return i;o.add(i);try{const a=i,c={};for(const[u,l]of Object.entries(a)){if(u==="definitions"||u==="$defs"){const f=u,p=t[f];for(const[h,d]of Object.entries(l)){const v=s(d),m=p[h];if(m!==void 0&&JSON.stringify(m)!==JSON.stringify(v))throw new Error(`[apigen-core-client] Function "${n}": param "${r}" contributes a "${f}.${h}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`);p[h]=v}continue}c[u]=s(l)}return c}finally{o.delete(i)}};return s(e)}async function Ln(e,t,n,r,o,s,i,a,c,u){const l=De(o);return er(e,t,n,r?[r,l]:[l],o,s,i,a,c,u)}async function er(e,t,n,r,o,s,i,a,c,u){const l=s.length>0&&s[0].name==="ctx",f=s.filter($=>$.name!=="ctx"),p=f.filter($=>!$.optional).map($=>$.name),h={},d={definitions:{},$defs:{}};for(const $ of f){const S=await vn(e,t,$.type,c,u),b=Lb(S,d,o,$.name);$.defaultValue!==void 0&&Rb(b,$.defaultValue),h[$.name]=b}const v=i.replace(/^Promise<(.+)>$/,"$1").trim(),m=await vn(e,t,v,c,u),y={type:"object",properties:h,required:p,...Object.keys(d.definitions).length>0?{definitions:d.definitions}:{},...Object.keys(d.$defs).length>0?{$defs:d.$defs}:{}};return{id:Af(n,r),host:"ts",namespace:n,path:r,kind:"action",async:a,streaming:!1,safe:!1,input:y,output:m,envelope:{},typeText:{lang:"ts",input:Kb(s),output:v},...l?{hasCtx:!0}:{}}}function Bb(e,t,n,r){const o=De(n),s=t?[t,o]:[o];return{id:Af(e,s),host:"ts",namespace:e,path:s,kind:"query",async:!1,streaming:!1,safe:!0,input:{type:"object",properties:{},required:[]},output:r,envelope:{},typeText:null}}function Af(e,t){return(e.raw?[e,...t]:t).map(n=>n.words.join("-")).join("/")}function Ub(e){return e.split(/[-_.]+/).flatMap(t=>t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").split("_").filter(Boolean)).map(t=>t.toLowerCase()).filter(Boolean)}function De(e){return{raw:e,words:Ub(e)}}function Fb(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function Vb(e){const t=[];for(const n of e.getStatements()){if(n.getKindName()!=="ExpressionStatement")continue;const r=n.getExpression();if(r.getKindName()!=="BinaryExpression")continue;const o=r;if(o.getLeft().getText().trim()!=="module.exports"||o.getOperatorToken().getKindName()!=="EqualsToken")continue;const s=o.getRight(),i=s.getType();for(const a of i.getProperties()){const c=a.getTypeAtLocation(s).getCallSignatures();c.length!==0&&t.push({name:a.getName(),sig:c[0]})}}return t}function qb(e){let t;for(const n of e){if(n.getKindName()!=="FunctionDeclaration")continue;const r=n;if(t||(t=r),r.getBody())return r}return t}function hc(e,t){return e.getParameters().map(n=>{var r;const o=n.getDeclarations(),s=o.length>0&&o[0].getKindName()==="Parameter"?o[0]:null,i=n.isOptional()||((s==null?void 0:s.hasInitializer())??!1)||(((r=s==null?void 0:s.hasQuestionToken)==null?void 0:r.call(s))??!1);return{name:n.getName(),type:n.getTypeAtLocation(e.getDeclaration()).getText(),optional:i,defaultValue:Ei(s,n.getName(),t)}})}function mc(e,t,n){return e.getParameters().map(r=>{var o;const s=r.getDeclarations(),i=s.length>0&&s[0].getKindName()==="Parameter"?s[0]:null,a=r.isOptional()||((i==null?void 0:i.hasInitializer())??!1)||(((o=i==null?void 0:i.hasQuestionToken)==null?void 0:o.call(i))??!1);return{name:r.getName(),type:r.getTypeAtLocation(t).getText(),optional:a,defaultValue:Ei(i,r.getName(),n??t)}})}function oo(e,t){return e.getParameters().map(n=>{var r,o,s;const i=n.getDeclarations(),a=i.length>0&&i[0].getKindName()==="Parameter"?i[0]:null,c=n.isOptional()||((a==null?void 0:a.hasInitializer())??!1)||(((r=a==null?void 0:a.hasQuestionToken)==null?void 0:r.call(a))??!1);return{name:n.getName(),type:a?a.getType().getText():((s=(o=n.getValueDeclaration())==null?void 0:o.getType())==null?void 0:s.getText())??"unknown",optional:c,defaultValue:Ei(a,n.getName(),t)}})}function Kb(e){const t=e.filter(n=>n.name!=="ctx");return t.length===0?"()":"("+t.map(n=>`${n.name}${n.optional?"?":""}: ${n.type}`).join(", ")+")"}function Bn(e){return!!(e==="__samples__"||e.startsWith("__"))}function ct(e,t,n=new Set){if(e.getCallSignatures().length>0||e.getConstructSignatures().length>0)return!1;if(e.isString()||e.isNumber()||e.isBoolean()||e.isNull()||e.isUndefined()||e.isStringLiteral()||e.isNumberLiteral()||e.isBooleanLiteral()||e.isEnumLiteral())return!0;if(e.isArray()||e.isReadonlyArray()){const r=e.getArrayElementType();return r?ct(r,t,n):!1}if(e.isTuple())return e.getTupleElements().every(r=>ct(r,t,n));if(e.isUnion())return e.getUnionTypes().every(r=>ct(r,t,n));if(e.isIntersection())return e.getIntersectionTypes().every(r=>ct(r,t,n));if(e.isObject()){const r=e.getText(t);if(n.has(r))return!0;n.add(r);const o=e.getStringIndexType(),s=e.getNumberIndexType();if(o||s)return[o,s].every(a=>!a||ct(a,t,n));const i=e.getProperties();return i.length===0?!0:i.every(a=>{const c=a.getTypeAtLocation(t);return ct(c,t,n)})}return!1}const Gb={"decimal.js":"Decimal"};function zb(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(Gb).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${zb(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));const Wb=["invalid_argument","unauthenticated","permission_denied","not_found","internal"],Hb={invalid_argument:400,unauthenticated:401,permission_denied:403,not_found:404,internal:500};let Jb=class extends Error{constructor(t,n,r){super(n),this.name="ApiError",this.code=t,this.details=r,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}};function Si(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&Wb.includes(e.code)&&typeof e.toJSON=="function"}const Vo="$apigen";let gc=class extends Error{constructor(t){super(t),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}};function Yb(e){const t=new Map;return{register(n,r){if(t.has(n.id)&&!(r!=null&&r.override))throw new gc(`E_DUP_CODEC: a codec is already registered for id "${n.id}"`);t.set(n.id,n)},resolve(n){for(const r of t.values())if(r.matches(n))return r},get(n){return t.get(n)},ids(){return[...t.keys()]},freeze(){const n=new Map(t),r={register(){throw new gc("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(o){for(const s of n.values())if(s.matches(o))return s},get(o){return n.get(o)},ids(){return[...n.keys()]},freeze(){return r}};return r}}}const Oi="x-apigen-logical",Ni="x-apigen-codec",qo="x-apigen-ctor",Ko="x-apigen-tojson",Qb="0.1.0";function yc(e,t){return{registry:e,resolve:n=>{throw new Error(`[apigen-logical] $ref "${n}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:"",mode:"strict",...t}}function jt(e,t,n){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return jt(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=If(e,s,t);return jt(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return so(e,t,n);const a=t.items;if(!a)return e.map(u=>mt(u));const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?mt(u):jt(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>jt(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return so(e,t,n);const a=t.properties;if(!a)return mt(e);const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=jt(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?so(e,t,n):mt(e)}function Pt(e,t,n){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return Pt(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=If(e,s,t);return Pt(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return e;const a=t.items;if(!a)return e;const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?u:Pt(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>Pt(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const a=t.properties;if(!a)return e;const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=Pt(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?Zb(e,n):e}function If(e,t,n,r){const o=n.discriminator;if(o!=null&&o.propertyName){const s=e!==null&&typeof e=="object"?e[o.propertyName]:void 0;if(typeof s=="string"&&o.mapping){const i=o.mapping[s];if(i){const a=t.find(c=>c.$ref===i);if(a)return a}}}return t[0]??{}}function so(e,t,n){for(const r of n.registry.ids()){const o=n.registry.get(r);if(o)try{const s=o.encode(e,o.schema,n);return{[Vo]:r,v:s}}catch{}}return mt(e)}function Zb(e,t){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&Vo in e){const n=e,r=n[Vo],o=t.registry.get(r);if(o)return o.decode(n.v,o.schema,t)}return e}function mt(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(mt);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))r!==void 0&&(t[n]=mt(r));return t}return null}function Xb(e){return{encode(t,n,r){const o=yc(e,r);return jt(t,n,o)},decode(t,n,r){const o=yc(e,r);return Pt(t,n,o)}}}const _i={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},ki={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}},Ai={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,t,n){return e},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e)}if(n.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return e}},Ii={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,t,n){return Buffer.from(e).toString("base64")},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array(0)}if(n.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},eE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,ji={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode==="strict"&&!eE.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},Go="NaN",zo="Infinity",Wo="-Infinity",tE=new Set([Go,zo,Wo]),Pi={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,t,n){return Number.isNaN(e)?Go:e===1/0?zo:e===-1/0?Wo:e},decode(e,t,n){if(typeof e=="number")return e;if(typeof e=="string"){if(e===Go)return NaN;if(e===zo)return 1/0;if(e===Wo)return-1/0;const r=Number(e);if(!Number.isNaN(r))return r}if(n.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...tE].join(", ")}.`);return NaN}},nE=[_i,ki,Ai,Ii,ji,Pi];function rE(e,t={}){for(const n of nE)e.register(n,{override:t.override??!1})}_i.id,ki.id,Ai.id,Ii.id,ji.id,Pi.id;const jf=Yb();rE(jf);const Pf=Xb(jf.freeze());function oE(e,t){var n;const r=((n=e.input)==null?void 0:n.properties)??{};return t in r}function sE(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data;return Object.keys((r==null?void 0:r.properties)??{})}function iE(e,t){var n,r,o;const s=(o=(r=(n=e.input)==null?void 0:n.properties)==null?void 0:r.data)==null?void 0:o.properties,i=s==null?void 0:s[t];return i!==void 0?i:void 0}function aE(e,t){return t===void 0||e===void 0?e:Pf.decode(e,t)}function io(e,t){const n=t.output;return!n||Object.keys(n).length===0?e:Pf.encode(e,n)}async function cE(e,t,n,r,o,s){const i=sE(n).map(c=>aE(s[c],iE(n,c)));if(oE(n,"session")&&t){const c=await t({session:o.session}),u=await e[r](c,...i);return io(u,n)}if(n.hasCtx){const c=t?await t(o):void 0,u=await e[r](c,...i);return io(u,n)}const a=await e[r](...i);return io(a,n)}let uE=class{constructor(){this._map=new Map}set(t,n){this._map.set(t,n)}get(t){return this._map.get(t)}has(t){return this._map.has(t)}};function lE(e=[]){return async function(t,n,r){const o=r.schemas[t];if(!o)throw new Error(`apigen/invoke: no schema found for operation "${t}"`);const s=()=>cE(r.fns,r.createClient,o,t,n.envelope,n.domainArgs);return e.reduceRight((i,a)=>()=>a(n,i),s)()}}const fE={"decimal.js":"Decimal"};function dE(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(fE).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${dE(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function pE(e={}){const t=e.level??"info",n=typeof e.destination=="string"&&e.destination.length>0,r=!n&&!!process.stderr.isTTY,o=e.format??(r?"pretty":"json"),s={level:t};if(o==="pretty")return s.transport={target:"pino-pretty",options:{colorize:!n,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...n?{destination:e.destination,mkdir:!0}:{destination:2}}},Ee(s);const i=n?Ee.destination({dest:e.destination,mkdir:!0,sync:!0}):Ee.destination(2);return Ee(s,i)}function xf(e){return e?e.type==="array"?`${xf(e.items)}[]`:e.enum?"enum":e.$ref?String(e.$ref).split("/").pop()||"object":e.anyOf||e.oneOf?"union":e.type??"object":"unknown"}function Tf(e){var t;const n=(t=((e==null?void 0:e.input)??{}).properties)==null?void 0:t.data,r=(n==null?void 0:n.properties)??{},o=new Set((n==null?void 0:n.required)??[]),s=Object.entries(r).map(([a,c])=>({name:a,type:xf(c),required:o.has(a)})),i=s.map(a=>`${a.name}${a.required?"":"?"}: ${a.type}`).join(", ");return{params:s,text:i}}function hE(e){let t;return Array.isArray(e)?t=e:e?t=[e]:t=[],t.find(n=>n==="number"||n==="integer"||n==="boolean")}function mE(e,t){var n,r;const o=((r=(n=((t==null?void 0:t.input)??{}).properties)==null?void 0:n.data)==null?void 0:r.properties)??{},s={...e};for(const[i,a]of Object.entries(o)){const c=s[i];if(typeof c!="string")continue;const u=hE(a==null?void 0:a.type);if(u==="number"||u==="integer"){const l=Number(c);!Number.isNaN(l)&&c.trim()!==""&&(s[i]=l)}else u==="boolean"&&(c==="true"?s[i]=!0:c==="false"&&(s[i]=!1))}return s}let gE=class extends Error{constructor(t,n,r){super(n),this.name="ApiError",this.code=t,this.details=r,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}};const _r=new os({allErrors:!0});ss(_r);for(const e of[Oi,Ni,qo,Ko,"discriminator"])_r.addKeyword({keyword:e,valid:!0});_r.addFormat("decimal",/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function yE(e){return e.map(t=>`${t.instancePath||"(root)"} ${t.message??"failed schema check"}`).join("; ")}function vE(e){return async function(t,n){const r=t.operation.id,o=e[r];if(o===void 0)return n();const s={data:t.domainArgs,...t.envelope},i=_r.compile(o.input);if(!i(s)){const a=i.errors??[];throw new gE("invalid_argument",`Validation failed: ${yE(a)}`,a)}return n()}}function $E(e){return e!==null&&typeof e=="object"&&Symbol.asyncIterator in e}let st=class extends Error{constructor(t,n){super(n),this.name="UnionCodecError",this.code=t}};function ao(e){const t=e.discriminator;if(t===null||typeof t!="object"||Array.isArray(t))return;const n=t;if(typeof n.propertyName!="string")return;const r=n.mapping;if(!(r===null||typeof r!="object"||Array.isArray(r)))return{propertyName:n.propertyName,mapping:r}}function Cf(e,t){const n=e[Ni];if(typeof n=="string"){const r=t.registry.get(n);if(r)return r}return t.registry.resolve(e)}function wE(e,t,n){const r=Cf(t,n);return r?r.encode(e,t,n):e}function bE(e,t,n){const r=Cf(t,n);return r?r.decode(e,t,n):e}function EE(e){const{id:t,schema:n}=e;return{id:t,kind:"union",schema:n,matches(r){if(r[Oi]==="union")return!0;const o=r.oneOf;return!Array.isArray(o)||o.length===0?!1:ao(r)!==void 0},encode(r,o,s){const i=ao(o);if(!i)throw new st("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:a,mapping:c}=i,u=r[a];if(u==null)throw new st("E_UNION_NO_DISCRIMINATOR",`[${t}] value at "${s.path}" is missing the discriminator property "${a}".`);const l=String(u),f=c[l];if(!f)throw new st("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${l}" at "${s.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`);const p=s.resolve(f);return wE(r,p,{...s,path:`${s.path}[${l}]`})},decode(r,o,s){if(r===null||typeof r!="object"||Array.isArray(r)){let d;throw r===null?d="null":Array.isArray(r)?d="array":d=typeof r,new st("E_UNION_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${s.path}", got ${d}.`)}const i=r,a=ao(o);if(!a)throw new st("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:c,mapping:u}=a,l=i[c];if(l==null)throw new st("E_UNION_NO_DISCRIMINATOR",`[${t}] wire object at "${s.path}" is missing the discriminator property "${c}".`);const f=String(l),p=u[f];if(!p)throw new st("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${f}" on the wire at "${s.path}" is not in the mapping (known: ${Object.keys(u).join(", ")}).`);const h=s.resolve(p);return bE(r,h,{...s,path:`${s.path}[${f}]`})}}}const SE="x-apigen-instances";let Un=class extends Error{constructor(t,n){super(n),this.name="NominalCodecError",this.code=t}};function vc(e){const t=e.properties;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function OE(e){const t=e.required;return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}function $c(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n)}return e}function NE(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n)}return e}function _E(e){const{id:t,schema:n,ctor:r}=e;return{id:t,kind:"nominal",schema:n,matches(o){return o[Oi]==="nominal"?!0:o[Ni]===t},encode(o,s,i){if(o===null||typeof o!="object")return o;if(i.seen.has(o)){if(i.mode==="strict")throw new Un("E_NOMINAL_CYCLE",`[${t}] cycle detected at "${i.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN §8.3); break the cycle or use 'lossy' mode.`);return null}i.seen.add(o);try{const a=vc(s),c=typeof s[Ko]=="string"?s[Ko]:"toJSON",u=o[c];if(typeof u=="function"){const d=u.call(o);if(d!==null&&typeof d=="object"&&!Array.isArray(d)){const v={};for(const[m,y]of Object.entries(d))v[m]=$c(y,a[m],{...i,path:`${i.path}/${m}`});return v}return d}const l={},f=Object.keys(a),p=o,h=f.length>0?f:Object.keys(p);for(const d of h){const v=p[d];v!==void 0&&(l[d]=$c(v,a[d],{...i,path:`${i.path}/${d}`}))}return l}finally{i.seen.delete(o)}},decode(o,s,i){if(o===null||typeof o!="object"||Array.isArray(o)){let l;throw o===null?l="null":Array.isArray(o)?l="array":l=typeof o,new Un("E_NOMINAL_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${i.path}", got ${l}.`)}const a=o;for(const l of OE(s))if(!(l in a))throw new Un("E_NOMINAL_INVALID_WIRE",`[${t}] required field "${l}" missing on the wire at "${i.path}".`);if(s[SE]===!1)throw new Un("E_NOMINAL_NONRECONSTRUCTABLE",`[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);const c=vc(s),u={};for(const[l,f]of Object.entries(a))u[l]=NE(f,c[l],{...i,path:`${i.path}/${l}`});if(r){const l=typeof s[qo]=="string"?s[qo]:"fromJSON",f=r[l];if(typeof f=="function")return f.call(r,u);const p=r;return new p(u)}return u}}}const kE=[_i,ki,Ai,Ii,ji,Pi],AE={type:"object","x-apigen-logical":"nominal","x-apigen-codec":"ts.NominalSentinel"},wc=_E({id:"ts.NominalSentinel",schema:AE}),IE={oneOf:[],discriminator:{propertyName:"kind",mapping:{}},"x-apigen-logical":"union","x-apigen-codec":"ts.UnionSentinel"},bc=EE({id:"ts.UnionSentinel",schema:IE});function jE(){const e=[...kE.map(t=>[t.id,t]),[wc.id,wc],[bc.id,bc]];return Object.freeze(new Map(e))}Object.freeze({host:"ts",logicalTypeVersion:Qb,codecs:jE()});const Ec=new Set(["string","number","boolean","integer"]);function PE(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?Ec.has(n):Array.isArray(n)?n.every(r=>Ec.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function xE(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(PE)}const TE={"decimal.js":"Decimal"};function CE(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(TE).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${CE(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Sc(e){return e.words.join("-")}function Oc(e){return e.words.map(BE).join("")}function Nc(e){return e.words.join("_")}function RE(e,t={}){var n,r;const o=[e.namespace,...e.path],s=e.safe||xE(e.input)?"GET":"POST",i=((r=(n=t.http)==null?void 0:n.verb)==null?void 0:r[e.id])??s,a="/"+o.map(h=>Sc(h)).join("/"),c=o.map(h=>Nc(h)).join("_"),u=o.map(h=>Nc(h)).slice(0,-1).join("."),l=Oc(o[o.length-2]??o[0]),f=Oc(o[o.length-1]),p=o.map(h=>Sc(h));return{http:{verb:i,route:a},mcp:{name:c},grpc:{package:u,service:l,method:f},cli:{path:p}}}function ME(e,t){return`x-${e}-${t}`}function DE(e,t){return`--${e}-${t}`}function LE(e,t){const n=r=>r.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function BE(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function Rf(e){return e.anyOf??e.oneOf}function UE(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=Rf(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="array"||r.type==="object")}return!1}function FE(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=Rf(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="boolean")}return!1}function VE(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function qE(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data,o=(r==null?void 0:r.properties)??{},s=(r==null?void 0:r.required)??[];return{props:o,required:s}}function _c(e){return typeof e.handler=="function"}function KE(e){var t;const n=((t=e.input)==null?void 0:t.properties)??{},r=e["x-apigen-envelope"],o=[];for(const s of Object.keys(n)){if(s==="data")continue;const i=(r==null?void 0:r[s])??"adhd",a=ME(i,s);o.push({field:s,pluginId:i,httpHeader:a,mcpMetaKey:a,cliFlag:DE(i,s),envVar:LE(i,s)})}return o}function GE(e,t){const n=new Map,{props:r}=qE(e);for(const[o,s]of Object.entries(r)){let i="string";FE(s)?i="boolean":UE(s)&&(i="json"),n.set(VE(o),{camelKey:o,kind:"domain",valueKind:i})}for(const o of t){const s=o.cliFlag.replace(/^--/,"");n.set(s,{camelKey:o.field,kind:"envelope",valueKind:"string",envVar:o.envVar})}return n}function kc(e){const{op:t,schema:n,transport:r,projection:o}=e,s=RE(t,o),i=n?KE(n):[],a=n?GE(n,i):new Map,c=n?Tf(n).params:void 0,u={op:t,transport:r,http:s.http,mcp:s.mcp,cli:s.cli,grpc:s.grpc,params:c,envelope:i,cliFlags:a,streaming:t.streaming,isMount:_c(t)};if(_c(t)){const l=t.handler;u.mountHandler=async f=>l(f)}return u}function zE(e){const t=e.usePlugins;return Array.isArray(t)?t:[]}function WE(e){const t=e.useOptions;return t&&typeof t=="object"?t:{}}function HE(e){return async function(t,n){const r=Object.assign(t,{data:t.domainArgs});return await e.layer(r,n)}}function Ac(e,t){var n;const r=[];for(const o of t){const s=(n=o.capabilities)==null?void 0:n.layer;s&&r.push(HE(s))}return r.push(vE(e)),lE(r)}function JE(){const e=new Map;return{get:t=>e.get(t),set:(t,n)=>{e.set(t,n)}}}const YE={input:{type:"object",properties:{data:{type:"object",properties:{}}}},output:{}};async function Ic(e,t,n,r){const o={...n,operation:{id:e.op.id},ctx:new uE};if(e.isMount){const s=e.mountHandler;if(!s)throw new Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);const i={operation:e.op,data:n.domainArgs,envelope:n.envelope,ctx:JE(),transport:e.transport,signal:n.signal??new AbortController().signal},a={...r,fns:{[e.op.id]:()=>s(i)},schemas:{[e.op.id]:YE}};return t(e.op.id,o,a)}return t(e.op.id,o,r)}const QE={"decimal.js":"Decimal"};function ZE(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(QE).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${ZE(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Ho(e){return e.split(/[-_.]+/).flatMap(t=>t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").split("_").filter(Boolean)).map(t=>t.toLowerCase()).filter(Boolean)}function jc(e){return{raw:e,words:Ho(e)}}function XE(e,t,n,r){for(const o of r??[]){const s=o.path[o.path.length-1];if(o.namespace.raw===e&&(s==null?void 0:s.raw)===t)return o}return{id:`${Ho(e).join("-")}/${Ho(t).join("-")}`,host:"ts",namespace:jc(e),path:[jc(t)],kind:"action",async:!1,streaming:!1,safe:n["x-apigen-safe"]??!1,input:n.input??{},output:n.output??{},envelope:{},typeText:null}}function eS(e){return`data: ${e}
165
+
166
+ `}function tS(e){return`event: error
167
+ data: ${e}
168
+
169
+ `}async function nS(e,t,n){const r=new AbortController;t.raw.once("close",()=>r.abort());const o=n.raw;let s=!1;try{for await(const i of e){if(r.signal.aborted)break;s||(o.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Transfer-Encoding":"chunked"}),s=!0),o.write(eS(JSON.stringify(i)))}s||o.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),o.end()}catch(i){const a=Si(i)?i:new Jb("internal",i instanceof Error?i.message:String(i));if(s)o.write(tS(JSON.stringify(a.toJSON()))),o.end();else{const c=oS(a.code);o.writeHead(c,{"Content-Type":"application/json"}),o.end(JSON.stringify(a.toJSON()))}}n.hijack()}const rS={invalid_argument:400,unauthenticated:401,permission_denied:403,not_found:404,internal:500};function oS(e){return rS[e]??500}function Mf(e){return Si(e)?Hb[e.code]??500:500}function Df(e){return Si(e)?e.toJSON():{code:"internal",message:e instanceof Error?e.message:"Internal error"}}function sS(e,t){if(e)for(const n of t){const r={method:n.method,route:n.route};let o=`${n.method} ${n.route}`;n.params.length&&(r.method==="GET"?o+=` params {${n.text?` ${n.text} `:""}}`:o+=` body { data: {${n.text?` ${n.text} `:""}} }`),e.info(n,o)}}let iS=class{constructor(t,n,r){this.app=t,this.routePrefix=n,this.signal=r,this.schemasByOpId=new Map}bindSchema(t,n){this.schemasByOpId.set(t,n)}routeFor(t){return t.isMount?`${this.routePrefix}/${t.op.id}`:this.routePrefix+t.http.route}registerRoute(t,n){const r=this.routeFor(t),o=async(s,i)=>{const a={req:s,reply:i};try{const c=await this.readCall(a,t),u=await n(c);await this.writeResult(a,u,t)}catch(c){await this.writeError(a,c,t)}};t.http.verb==="GET"?this.app.get(r,o):this.app.post(r,o)}readCall(t,n){const{req:r}=t,o=r.headers,s={};for(const a of n.envelope){const c=o[a.httpHeader];c!==void 0&&(s[a.field]=c)}let i={};if(!n.isMount){const a=this.schemasByOpId.get(n.op.id);if(n.http.verb==="GET"){const c=r.query??{};i=a?mE(c,a):c}else{const{data:c={}}=r.body??{};i=c}}return{envelope:s,domainArgs:i,signal:this.signal}}async writeResult(t,n,r){const{req:o,reply:s}=t;if($E(n)){await nS(n,o,s);return}s.type("application/json"),s.send(JSON.stringify(n===void 0?null:n))}writeError(t,n,r){const{reply:o}=t;o.status(Mf(n)).send(Df(n))}};function aS(e,t,n,r){var o;const s=[],i={host:n,operations:r};for(const a of e){const c=(o=a.capabilities)==null?void 0:o.mount;if(!c)continue;const u=c.operations(i,t[a.id]);for(const l of u)l.transports&&!l.transports.includes("http")||s.push(l)}return s}async function cS(e){var t;const n=e.options.port??3e3,r=e.options.host??"127.0.0.1",o=e.options.routePrefix??"",s=e.options.projection??{},i=zE(e.options),a=WE(e.options),c=e.logger??pE(),u=Op({logger:c});u.setErrorHandler((d,v,m)=>{m.status(Mf(d)).send(Df(d))});const l=new iS(u,o,e.signal),f=[];for(const d of e.packages){if(!d.fns)throw new Error(`Package "${d.id}" is missing fns`);const v=d.fns,m=Object.entries(d.schemas).map(([N,j])=>({fnName:N,fnSchema:j,op:XE(d.id,N,j,e.operations)})),y={},$={};for(const{fnName:N,fnSchema:j,op:M}of m)y[M.id]=j,$[M.id]=v[N];const S=Ac(y,i),b={fns:$,createClient:d.createClient,schemas:y};for(const{fnSchema:N,op:j}of m){const M=kc({op:j,schema:N,transport:"http",projection:s});l.bindSchema(j.id,N),l.registerRoute(M,le=>Ic(M,S,le,b));const{params:H,text:Z}=Tf(N);f.push({method:M.http.verb,route:o+M.http.route,text:Z,params:H})}}const p=((t=e.packages[0])==null?void 0:t.id)??"ts",h=aS(i,a,p,e.operations??[]);if(h.length>0){const d=Ac({},i),v={fns:{},schemas:{}};for(const m of h){const y=kc({op:m,transport:"http",projection:s});l.registerRoute(y,$=>Ic(y,d,$,v)),f.push({method:y.http.verb,route:`${o}/${m.id}`,text:"",params:[]})}}return await u.listen({port:n,host:r}),c.info({host:r,port:n},`listening on http://${r}:${n}`),sS(c,f),new Promise(d=>{e.signal&&e.signal.addEventListener("abort",async()=>{await u.close(),d()})})}const uS={id:"api-fastify",run(e){return cS(e)}},Pc=new Set(["string","number","boolean","integer"]);function lS(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?Pc.has(n):Array.isArray(n)?n.every(r=>Pc.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function fS(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(lS)}const dS={"decimal.js":"Decimal"};function pS(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(dS).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${pS(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function xc(e){return e.words.join("-")}function Tc(e){return e.words.map(mS).join("")}function Cc(e){return e.words.join("_")}function hS(e,t={}){var n,r;const o=[e.namespace,...e.path],s=e.safe||fS(e.input)?"GET":"POST",i=((r=(n=t.http)==null?void 0:n.verb)==null?void 0:r[e.id])??s,a="/"+o.map(h=>xc(h)).join("/"),c=o.map(h=>Cc(h)).join("_"),u=o.map(h=>Cc(h)).slice(0,-1).join("."),l=Tc(o[o.length-2]??o[0]),f=Tc(o[o.length-1]),p=o.map(h=>xc(h));return{http:{verb:i,route:a},mcp:{name:c},grpc:{package:u,service:l,method:f},cli:{path:p}}}function mS(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function gS(e,t={}){const n=t.title??"API",r=t.version??"0.0.0",o={};for(const s of e){const i=hS(s),{verb:a,route:c}=i.http,u=a.toLowerCase(),l={operationId:s.id,summary:s.id,responses:{200:yS(s.output)}};if(a==="GET")l.parameters=vS(s.input);else{const f=s.input;typeof f=="object"&&f!==null&&Object.keys(f).length>0&&(l.requestBody={required:!0,content:{"application/json":{schema:f}}})}o[c]===void 0&&(o[c]={}),o[c][u]=l}return{openapi:"3.1.0",info:{title:n,version:r},paths:o}}function yS(e){return typeof e=="object"&&e!==null&&Object.keys(e).length>0?{description:"Success",content:{"application/json":{schema:e}}}:{description:"Success"}}function vS(e){if(typeof e!="object"||e===null||typeof e.properties!="object"||e.properties===null)return[];const t=Array.isArray(e.required)?e.required:[],n=e.properties;return Object.entries(n).map(([r,o])=>({name:r,in:"query",required:t.includes(r),schema:o}))}function Rc(e){return{raw:e,words:e.split(/(?=[A-Z])|[-_]/).map(t=>t.toLowerCase()).filter(Boolean)}}function $S(e,t={}){return[{id:"_meta/openapi",host:e.host,namespace:Rc("meta"),path:[Rc("openapi")],kind:"query",async:!1,streaming:!1,safe:!0,input:{},output:{type:"object"},envelope:{},typeText:null,transports:["http"],handler:n=>gS(e.operations,{title:t.title,version:t.version})}]}const wS={id:"openapi",description:"Mount plugin: serves the OpenAPI 3.1 doc at GET /meta/openapi",language:"ts",optionsSchema:{type:"object",properties:{title:{type:"string",description:"OpenAPI info.title"},version:{type:"string",description:"OpenAPI info.version"}},additionalProperties:!1},capabilities:{mount:{operations(e,t){return $S(e,t)}}}},Jo="$apigen";class Mc extends Error{constructor(t){super(t),this.code="E_DUP_CODEC",this.name="CodecRegistryError"}}function bS(e){const t=new Map;return{register(n,r){if(t.has(n.id)&&!(r!=null&&r.override))throw new Mc(`E_DUP_CODEC: a codec is already registered for id "${n.id}"`);t.set(n.id,n)},resolve(n){for(const r of t.values())if(r.matches(n))return r},get(n){return t.get(n)},ids(){return[...t.keys()]},freeze(){const n=new Map(t),r={register(){throw new Mc("E_DUP_CODEC: registry is frozen and cannot accept new codecs")},resolve(o){for(const s of n.values())if(s.matches(o))return s},get(o){return n.get(o)},ids(){return[...n.keys()]},freeze(){return r}};return r}}}const xi="x-apigen-logical",Ti="x-apigen-codec",Yo="x-apigen-ctor",Qo="x-apigen-tojson",ES="0.1.0";function Dc(e,t){return{registry:e,resolve:n=>{throw new Error(`[apigen-logical] $ref "${n}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`)},seen:new WeakSet,path:"",mode:"strict",...t}}function xt(e,t,n){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return xt(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=Lf(e,s,t);return xt(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return co(e,t,n);const a=t.items;if(!a)return e.map(u=>gt(u));const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?gt(u):xt(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>xt(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return co(e,t,n);const a=t.properties;if(!a)return gt(e);const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=xt(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?co(e,t,n):gt(e)}function Tt(e,t,n){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n);const o=t.$ref;if(typeof o=="string"){const a=n.resolve(o);return Tt(e,a,n)}const s=t.oneOf;if(Array.isArray(s)){const a=Lf(e,s,t);return Tt(e,a,n)}const i=t.type;if(i==="array"){if(!Array.isArray(e))return e;const a=t.items;if(!a)return e;const c=n.path;return Array.isArray(a)?e.map((u,l)=>{const f=a[l];return f===void 0?u:Tt(u,f,{...n,path:`${c}/${l}`})}):e.map((u,l)=>Tt(u,a,{...n,path:`${c}/${l}`}))}if(i==="object"){if(e===null||typeof e!="object"||Array.isArray(e))return e;const a=t.properties;if(!a)return e;const c=n.path,u={};for(const[l,f]of Object.entries(a)){const p=e[l];p!==void 0&&(u[l]=Tt(p,f,{...n,path:`${c}/${l}`}))}return u}return i==null?SS(e,n):e}function Lf(e,t,n,r){const o=n.discriminator;if(o!=null&&o.propertyName){const s=e!==null&&typeof e=="object"?e[o.propertyName]:void 0;if(typeof s=="string"&&o.mapping){const i=o.mapping[s];if(i){const a=t.find(c=>c.$ref===i);if(a)return a}}}return t[0]??{}}function co(e,t,n){for(const r of n.registry.ids()){const o=n.registry.get(r);if(o)try{const s=o.encode(e,o.schema,n);return{[Jo]:r,v:s}}catch{}}return gt(e)}function SS(e,t){if(e!==null&&typeof e=="object"&&!Array.isArray(e)&&Jo in e){const n=e,r=n[Jo],o=t.registry.get(r);if(o)return o.decode(n.v,o.schema,t)}return e}function gt(e){if(e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(gt);if(typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))r!==void 0&&(t[n]=gt(r));return t}return null}function OS(e){return{encode(t,n,r){const o=Dc(e,r);return xt(t,n,o)},decode(t,n,r){const o=Dc(e,r);return Tt(t,n,o)}}}const Ci={id:"date-time",kind:"scalar",schema:{type:"string",format:"date-time"},matches(e){return e.type==="string"&&e.format==="date-time"},encode(e,t,n){return e.toISOString()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);return new Date(String(e))}if(n.mode==="strict"&&Number.isNaN(new Date(e).getTime()))throw new TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);return new Date(e)}},Ri={id:"int64",kind:"scalar",schema:{type:"string",format:"int64"},matches(e){return e.type==="string"&&e.format==="int64"},encode(e,t,n){return String(e)},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);try{return BigInt(Math.trunc(Number(e)))}catch{return BigInt(0)}}if(n.mode==="strict")return BigInt(e);if(/^-?\d+$/.test(e))try{return BigInt(e)}catch{return BigInt(0)}return BigInt(0)}},Mi={id:"decimal",kind:"scalar",schema:{type:"string",format:"decimal"},matches(e){return e.type==="string"&&e.format==="decimal"},encode(e,t,n){return e},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e)}if(n.mode==="strict"&&!/^-?\d+(\.\d+)?$/.test(e))throw new TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);return e}},Di={id:"byte",kind:"scalar",schema:{type:"string",format:"byte"},matches(e){return e.type==="string"&&e.format==="byte"},encode(e,t,n){return Buffer.from(e).toString("base64")},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);return new Uint8Array(0)}if(n.mode==="strict"&&!/^[A-Za-z0-9+/]*={0,2}$/.test(e))throw new TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);return new Uint8Array(Buffer.from(e,"base64"))}},NS=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Li={id:"uuid",kind:"scalar",schema:{type:"string",format:"uuid"},matches(e){return e.type==="string"&&e.format==="uuid"},encode(e,t,n){return e.toLowerCase()},decode(e,t,n){if(typeof e!="string"){if(n.mode==="strict")throw new TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);return String(e).toLowerCase()}if(n.mode==="strict"&&!NS.test(e))throw new TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);return e}},Zo="NaN",Xo="Infinity",es="-Infinity",_S=new Set([Zo,Xo,es]),Bi={id:"number-special",kind:"scalar",schema:{type:"number"},matches(e){return e.type==="number"&&e.format===void 0},encode(e,t,n){return Number.isNaN(e)?Zo:e===1/0?Xo:e===-1/0?es:e},decode(e,t,n){if(typeof e=="number")return e;if(typeof e=="string"){if(e===Zo)return NaN;if(e===Xo)return 1/0;if(e===es)return-1/0;const r=Number(e);if(!Number.isNaN(r))return r}if(n.mode==="strict")throw new TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[..._S].join(", ")}.`);return NaN}},kS=[Ci,Ri,Mi,Di,Li,Bi];function AS(e,t={}){for(const n of kS)e.register(n,{override:t.override??!1})}Ci.id,Ri.id,Mi.id,Di.id,Li.id,Bi.id;const Bf=bS();AS(Bf);const Uf=OS(Bf.freeze());function IS(e,t){var n;const r=((n=e.input)==null?void 0:n.properties)??{};return t in r}function jS(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data;return Object.keys((r==null?void 0:r.properties)??{})}function PS(e,t){var n,r,o;const s=(o=(r=(n=e.input)==null?void 0:n.properties)==null?void 0:r.data)==null?void 0:o.properties,i=s==null?void 0:s[t];return i!==void 0?i:void 0}function xS(e,t){return t===void 0||e===void 0?e:Uf.decode(e,t)}function uo(e,t){const n=t.output;return!n||Object.keys(n).length===0?e:Uf.encode(e,n)}async function TS(e,t,n,r,o,s){const i=jS(n).map(c=>xS(s[c],PS(n,c)));if(IS(n,"session")&&t){const c=await t({session:o.session}),u=await e[r](c,...i);return uo(u,n)}if(n.hasCtx){const c=t?await t(o):void 0,u=await e[r](c,...i);return uo(u,n)}const a=await e[r](...i);return uo(a,n)}class CS{constructor(){this._map=new Map}set(t,n){this._map.set(t,n)}get(t){return this._map.get(t)}has(t){return this._map.has(t)}}function RS(e=[]){return async function(t,n,r){const o=r.schemas[t];if(!o)throw new Error(`apigen/invoke: no schema found for operation "${t}"`);const s=()=>TS(r.fns,r.createClient,o,t,n.envelope,n.domainArgs);return e.reduceRight((i,a)=>()=>a(n,i),s)()}}const MS={"decimal.js":"Decimal"};function DS(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(MS).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${DS(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function LS(e={}){const t=e.level??"info",n=typeof e.destination=="string"&&e.destination.length>0,r=!n&&!!process.stderr.isTTY,o=e.format??(r?"pretty":"json"),s={level:t};if(o==="pretty")return s.transport={target:"pino-pretty",options:{colorize:!n,translateTime:"SYS:HH:MM:ss.l",ignore:"pid,hostname",...n?{destination:e.destination,mkdir:!0}:{destination:2}}},Ee(s);const i=n?Ee.destination({dest:e.destination,mkdir:!0,sync:!0}):Ee.destination(2);return Ee(s,i)}function Ff(e){return e?e.type==="array"?`${Ff(e.items)}[]`:e.enum?"enum":e.$ref?String(e.$ref).split("/").pop()||"object":e.anyOf||e.oneOf?"union":e.type??"object":"unknown"}function BS(e){var t;const n=(t=((e==null?void 0:e.input)??{}).properties)==null?void 0:t.data,r=(n==null?void 0:n.properties)??{},o=new Set((n==null?void 0:n.required)??[]),s=Object.entries(r).map(([a,c])=>({name:a,type:Ff(c),required:o.has(a)})),i=s.map(a=>`${a.name}${a.required?"":"?"}: ${a.type}`).join(", ");return{params:s,text:i}}const US=["invalid_argument","unauthenticated","permission_denied","not_found","internal"];class Vf extends Error{constructor(t,n,r){super(n),this.name="ApiError",this.code=t,this.details=r,Object.setPrototypeOf(this,new.target.prototype)}toJSON(){const t={code:this.code,message:this.message};return this.details!==void 0&&(t.details=this.details),t}}function FS(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&US.includes(e.code)&&typeof e.toJSON=="function"}function Lc(e,t,n=0){return e==="before-first-chunk"?{phase:e,error:t}:{phase:e,error:t,chunksDelivered:n}}const kr=new os({allErrors:!0});ss(kr);for(const e of[xi,Ti,Yo,Qo,"discriminator"])kr.addKeyword({keyword:e,valid:!0});kr.addFormat("decimal",/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);function VS(e){return e.map(t=>`${t.instancePath||"(root)"} ${t.message??"failed schema check"}`).join("; ")}function qS(e){return async function(t,n){const r=t.operation.id,o=e[r];if(o===void 0)return n();const s={data:t.domainArgs,...t.envelope},i=kr.compile(o.input);if(!i(s)){const a=i.errors??[];throw new Vf("invalid_argument",`Validation failed: ${VS(a)}`,a)}return n()}}async function KS(e){const t=[];try{for await(const n of e)t.push(n);return{ok:!0,chunks:t}}catch(n){const r=FS(n)?n:new Vf("internal",n instanceof Error?n.message:String(n));return t.length===0?{ok:!1,carrier:Lc("before-first-chunk",r)}:{ok:!1,carrier:Lc("after-first-chunk",r,t.length)}}}function GS(e){return e!==null&&typeof e=="object"&&Symbol.asyncIterator in e}class it extends Error{constructor(t,n){super(n),this.name="UnionCodecError",this.code=t}}function lo(e){const t=e.discriminator;if(t===null||typeof t!="object"||Array.isArray(t))return;const n=t;if(typeof n.propertyName!="string")return;const r=n.mapping;if(!(r===null||typeof r!="object"||Array.isArray(r)))return{propertyName:n.propertyName,mapping:r}}function qf(e,t){const n=e[Ti];if(typeof n=="string"){const r=t.registry.get(n);if(r)return r}return t.registry.resolve(e)}function zS(e,t,n){const r=qf(t,n);return r?r.encode(e,t,n):e}function WS(e,t,n){const r=qf(t,n);return r?r.decode(e,t,n):e}function HS(e){const{id:t,schema:n}=e;return{id:t,kind:"union",schema:n,matches(r){if(r[xi]==="union")return!0;const o=r.oneOf;return!Array.isArray(o)||o.length===0?!1:lo(r)!==void 0},encode(r,o,s){const i=lo(o);if(!i)throw new it("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:a,mapping:c}=i,u=r[a];if(u==null)throw new it("E_UNION_NO_DISCRIMINATOR",`[${t}] value at "${s.path}" is missing the discriminator property "${a}".`);const l=String(u),f=c[l];if(!f)throw new it("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${l}" at "${s.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`);const p=s.resolve(f);return zS(r,p,{...s,path:`${s.path}[${l}]`})},decode(r,o,s){if(r===null||typeof r!="object"||Array.isArray(r)){let d;throw r===null?d="null":Array.isArray(r)?d="array":d=typeof r,new it("E_UNION_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${s.path}", got ${d}.`)}const i=r,a=lo(o);if(!a)throw new it("E_UNION_NO_DISCRIMINATOR",`[${t}] schema node at "${s.path}" has no discriminator.propertyName; cannot dispatch union branch.`);const{propertyName:c,mapping:u}=a,l=i[c];if(l==null)throw new it("E_UNION_NO_DISCRIMINATOR",`[${t}] wire object at "${s.path}" is missing the discriminator property "${c}".`);const f=String(l),p=u[f];if(!p)throw new it("E_UNION_UNKNOWN_TAG",`[${t}] discriminator tag "${f}" on the wire at "${s.path}" is not in the mapping (known: ${Object.keys(u).join(", ")}).`);const h=s.resolve(p);return WS(r,h,{...s,path:`${s.path}[${f}]`})}}}const JS="x-apigen-instances";class Fn extends Error{constructor(t,n){super(n),this.name="NominalCodecError",this.code=t}}function Bc(e){const t=e.properties;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function YS(e){const t=e.required;return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}function Uc(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.encode(e,t,n)}return e}function QS(e,t,n){if(t){const r=n.registry.resolve(t);if(r)return r.decode(e,t,n)}return e}function ZS(e){const{id:t,schema:n,ctor:r}=e;return{id:t,kind:"nominal",schema:n,matches(o){return o[xi]==="nominal"?!0:o[Ti]===t},encode(o,s,i){if(o===null||typeof o!="object")return o;if(i.seen.has(o)){if(i.mode==="strict")throw new Fn("E_NOMINAL_CYCLE",`[${t}] cycle detected at "${i.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN §8.3); break the cycle or use 'lossy' mode.`);return null}i.seen.add(o);try{const a=Bc(s),c=typeof s[Qo]=="string"?s[Qo]:"toJSON",u=o[c];if(typeof u=="function"){const d=u.call(o);if(d!==null&&typeof d=="object"&&!Array.isArray(d)){const v={};for(const[m,y]of Object.entries(d))v[m]=Uc(y,a[m],{...i,path:`${i.path}/${m}`});return v}return d}const l={},f=Object.keys(a),p=o,h=f.length>0?f:Object.keys(p);for(const d of h){const v=p[d];v!==void 0&&(l[d]=Uc(v,a[d],{...i,path:`${i.path}/${d}`}))}return l}finally{i.seen.delete(o)}},decode(o,s,i){if(o===null||typeof o!="object"||Array.isArray(o)){let l;throw o===null?l="null":Array.isArray(o)?l="array":l=typeof o,new Fn("E_NOMINAL_INVALID_WIRE",`[${t}] expected a JSON object on the wire at "${i.path}", got ${l}.`)}const a=o;for(const l of YS(s))if(!(l in a))throw new Fn("E_NOMINAL_INVALID_WIRE",`[${t}] required field "${l}" missing on the wire at "${i.path}".`);if(s[JS]===!1)throw new Fn("E_NOMINAL_NONRECONSTRUCTABLE",`[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`);const c=Bc(s),u={};for(const[l,f]of Object.entries(a))u[l]=QS(f,c[l],{...i,path:`${i.path}/${l}`});if(r){const l=typeof s[Yo]=="string"?s[Yo]:"fromJSON",f=r[l];if(typeof f=="function")return f.call(r,u);const p=r;return new p(u)}return u}}}const XS=[Ci,Ri,Mi,Di,Li,Bi],eO={type:"object","x-apigen-logical":"nominal","x-apigen-codec":"ts.NominalSentinel"},Fc=ZS({id:"ts.NominalSentinel",schema:eO}),tO={oneOf:[],discriminator:{propertyName:"kind",mapping:{}},"x-apigen-logical":"union","x-apigen-codec":"ts.UnionSentinel"},Vc=HS({id:"ts.UnionSentinel",schema:tO});function nO(){const e=[...XS.map(t=>[t.id,t]),[Fc.id,Fc],[Vc.id,Vc]];return Object.freeze(new Map(e))}Object.freeze({host:"ts",logicalTypeVersion:ES,codecs:nO()});function qc(e,t,n){var r;const o=typeof((r=t==null?void 0:t.input)==null?void 0:r.description)=="string"?t.input.description:void 0,s=[n,o].filter(i=>typeof i=="string"&&i.length>0);return s.length>0?s.join(" — "):e}function Kf(e){if(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length===0)return{outputSchema:void 0,wrapped:!1};const t=e;return t.type==="object"?{outputSchema:t,wrapped:!1}:{outputSchema:{type:"object",properties:{result:t},required:["result"]},wrapped:!0}}function rO(e,t){return e?{result:t}:t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}const Kc=new Set(["string","number","boolean","integer"]);function oO(e){if(typeof e!="object"||e===null)return!1;const t=e;if(t.$ref!==void 0||t.oneOf||t.anyOf||t.allOf)return!1;const{type:n}=t;return typeof n=="string"?Kc.has(n):Array.isArray(n)?n.every(r=>Kc.has(r)||r==="null"):Array.isArray(t.enum)&&t.enum.length>0?t.enum.every(r=>["string","number","boolean"].includes(typeof r)):!1}function sO(e){if(!e||typeof e!="object")return!1;const t=e.properties;return t===void 0||typeof t!="object"||t===null?!1:Object.values(t).every(oO)}const iO={"decimal.js":"Decimal"};function aO(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(iO).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${aO(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function Gc(e){return e.words.join("-")}function zc(e){return e.words.map(dO).join("")}function Wc(e){return e.words.join("_")}function cO(e,t={}){var n,r;const o=[e.namespace,...e.path],s=e.safe||sO(e.input)?"GET":"POST",i=((r=(n=t.http)==null?void 0:n.verb)==null?void 0:r[e.id])??s,a="/"+o.map(h=>Gc(h)).join("/"),c=o.map(h=>Wc(h)).join("_"),u=o.map(h=>Wc(h)).slice(0,-1).join("."),l=zc(o[o.length-2]??o[0]),f=zc(o[o.length-1]),p=o.map(h=>Gc(h));return{http:{verb:i,route:a},mcp:{name:c},grpc:{package:u,service:l,method:f},cli:{path:p}}}function uO(e,t){return`x-${e}-${t}`}function lO(e,t){return`--${e}-${t}`}function fO(e,t){const n=r=>r.toUpperCase().replace(/-/g,"_");return e==="adhd"?`APIGEN_${n(t)}`:`APIGEN_${n(e)}_${n(t)}`}function dO(e){return e.length===0?e:e[0].toUpperCase()+e.slice(1)}function Gf(e){return e.anyOf??e.oneOf}function pO(e){if(!e)return!1;if(e.type==="array"||e.type==="object")return!0;const t=Gf(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="array"||r.type==="object")}return!1}function hO(e){if(!e)return!1;if(e.type==="boolean")return!0;const t=Gf(e);if(t){const n=t.filter(r=>r.type!=="null");return n.length>0&&n.every(r=>r.type==="boolean")}return!1}function mO(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function gO(e){var t,n;const r=(n=(t=e.input)==null?void 0:t.properties)==null?void 0:n.data,o=(r==null?void 0:r.properties)??{},s=(r==null?void 0:r.required)??[];return{props:o,required:s}}function Hc(e){return typeof e.handler=="function"}function yO(e){var t;const n=((t=e.input)==null?void 0:t.properties)??{},r=e["x-apigen-envelope"],o=[];for(const s of Object.keys(n)){if(s==="data")continue;const i=(r==null?void 0:r[s])??"adhd",a=uO(i,s);o.push({field:s,pluginId:i,httpHeader:a,mcpMetaKey:a,cliFlag:lO(i,s),envVar:fO(i,s)})}return o}function vO(e,t){const n=new Map,{props:r}=gO(e);for(const[o,s]of Object.entries(r)){let i="string";hO(s)?i="boolean":pO(s)&&(i="json"),n.set(mO(o),{camelKey:o,kind:"domain",valueKind:i})}for(const o of t){const s=o.cliFlag.replace(/^--/,"");n.set(s,{camelKey:o.field,kind:"envelope",valueKind:"string",envVar:o.envVar})}return n}function Jc(e){const{op:t,schema:n,transport:r,projection:o}=e,s=cO(t,o),i=n?yO(n):[],a=n?vO(n,i):new Map,c=n?BS(n).params:void 0,u={op:t,transport:r,http:s.http,mcp:s.mcp,cli:s.cli,grpc:s.grpc,params:c,envelope:i,cliFlags:a,streaming:t.streaming,isMount:Hc(t)};if(Hc(t)){const l=t.handler;u.mountHandler=async f=>l(f)}return u}function $O(e){const t=e.usePlugins;return Array.isArray(t)?t:[]}function wO(e){const t=e.useOptions;return t&&typeof t=="object"?t:{}}function bO(e){return async function(t,n){const r=Object.assign(t,{data:t.domainArgs});return await e.layer(r,n)}}function Yc(e,t){var n;const r=[];for(const o of t){const s=(n=o.capabilities)==null?void 0:n.layer;s&&r.push(bO(s))}return r.push(qS(e)),RS(r)}function EO(){const e=new Map;return{get:t=>e.get(t),set:(t,n)=>{e.set(t,n)}}}const SO={input:{type:"object",properties:{data:{type:"object",properties:{}}}},output:{}};async function Qc(e,t,n,r){const o={...n,operation:{id:e.op.id},ctx:new CS};if(e.isMount){const s=e.mountHandler;if(!s)throw new Error(`apigen-engine-runtime/dispatchForPlan: OpPlan for mount op "${e.op.id}" has isMount=true but no mountHandler`);const i={operation:e.op,data:n.domainArgs,envelope:n.envelope,ctx:EO(),transport:e.transport,signal:n.signal??new AbortController().signal},a={...r,fns:{[e.op.id]:()=>s(i)},schemas:{[e.op.id]:SO}};return t(e.op.id,o,a)}return t(e.op.id,o,r)}const OO={"decimal.js":"Decimal"};function NO(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(OO).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${NO(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function _O(e){return e.split(/[-_.]+/).flatMap(t=>t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").split("_").filter(Boolean)).map(t=>t.toLowerCase()).filter(Boolean)}const kO={"decimal.js":"Decimal"};function AO(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}Object.entries(kO).map(([e,t])=>({pattern:new RegExp(`import\\(["'][^"']*${AO(e)}[^"']*["']\\)\\.\\w+`,"g"),key:t}));function IO(e){return e.replace(/\.[^.]+$/,"").replace(/[._]+/g,"-")}function ts(e){return{raw:e,words:_O(e)}}function jO(e){return ts(IO(ho.basename(e)))}function PO(e,t,n){if(n){const o=n.find(s=>{var i;return s.kind==="action"&&s.namespace.raw===e.id&&((i=s.path[s.path.length-1])==null?void 0:i.raw)===t});if(!o)throw new Error(`@adhd/apigen-plugin-mcp: no Operation found for package "${e.id}" fn "${t}" in the supplied operations[] — every fn in pkg.schemas must correspond to a real extracted Operation (orchestrator.ts buildDescriptor Step 5 invariant). This indicates a correlation bug, not a naming gap.`);return o}const r=ts(t);return{id:`${e.id}/${t}`,host:"ts",namespace:ts(e.id),path:e.dropFileSegment?[r]:[jO(e.importPath),r],kind:"action",async:!1,streaming:!1,safe:!1,input:{},output:{},envelope:{},typeText:null}}const xO=["invalid_argument","unauthenticated","permission_denied","not_found","internal"];function TO(e){return typeof e=="object"&&e!==null&&e.name==="ApiError"&&xO.includes(e.code)&&typeof e.toJSON=="function"}async function CO(e){const t=await KS(e);if(t.ok){const o=t.chunks.map(s=>({type:"text",text:JSON.stringify(s)}));return o.push({type:"text",text:"[stream complete]"}),{content:o}}const{carrier:n}=t;if(n.phase==="before-first-chunk")return{content:[{type:"text",text:JSON.stringify(n.error.toJSON())}],isError:!0};const r={...n.error.toJSON(),chunksDelivered:n.chunksDelivered};return{content:[{type:"text",text:JSON.stringify(r)}],isError:!0}}class RO{constructor(){this.plans=new Map,this.dispatchers=new Map,this.schemasByOpId=new Map,this.toolMeta=new Map}bindSchema(t,n){this.schemasByOpId.set(t,n)}bindToolMeta(t,n){this.toolMeta.set(t,n)}registerRoute(t,n){this.plans.set(t.mcp.name,t),this.dispatchers.set(t.mcp.name,n)}getPlan(t){return this.plans.get(t)}getDispatch(t){return this.dispatchers.get(t)}listTools(){return[...this.plans.keys()].map(t=>{const n=this.toolMeta.get(t);return{name:t,description:(n==null?void 0:n.description)??t,inputSchema:(n==null?void 0:n.inputSchema)??{type:"object",properties:{}},...n!=null&&n.outputSchema?{outputSchema:n.outputSchema}:{}}})}readCall(t,n){const r={};for(const s of n.envelope){const i=t.meta[s.mcpMetaKey];i!==void 0&&(r[s.field]=i)}const o=t.args.data??{};return{envelope:r,domainArgs:o}}async writeResult(t,n,r){if(GS(n)){t.output=await CO(n);return}const o=this.schemasByOpId.get(r.op.id),{wrapped:s}=Kf(o==null?void 0:o.output),i=rO(s,n);t.output={content:[{type:"text",text:JSON.stringify(n)}],...i?{structuredContent:i}:{}}}writeError(t,n,r){throw TO(n)&&n.code,n}}function MO(e,t,n,r){var o;const s=[],i={host:n,operations:r};for(const a of e){const c=(o=a.capabilities)==null?void 0:o.mount;if(!c)continue;const u=c.operations(i,t[a.id]);for(const l of u)l.transports&&!l.transports.includes("mcp")||s.push(l)}return s}function DO(e,t){var n;const r=e.options.projection??{},o=e.options.toolDescriptions??{},s=$O(e.options),i=wO(e.options);for(const u of e.packages){if(!u.fns)throw new Error(`Package "${u.id}" is missing fns`);const l=u.fns,f=Object.entries(u.schemas).map(([m,y])=>({fnName:m,fnSchema:y,op:PO({id:u.id,importPath:u.importPath},m,e.operations)})),p={},h={};for(const{fnName:m,fnSchema:y,op:$}of f)p[$.id]=y,h[$.id]=l[m];const d=Yc(p,s),v={fns:h,createClient:u.createClient,schemas:p};for(const{fnName:m,fnSchema:y,op:$}of f){const S=Jc({op:$,schema:y,transport:"mcp",projection:r});t.bindSchema($.id,y);const{outputSchema:b}=Kf(y.output),N=qc(S.mcp.name,y,o[S.mcp.name]??o[m]);t.bindToolMeta(S.mcp.name,{description:N,inputSchema:y.input,outputSchema:b}),t.registerRoute(S,j=>Qc(S,d,j,v))}}const a=((n=e.packages[0])==null?void 0:n.id)??"ts",c=MO(s,i,a,e.operations??[]);if(c.length>0){const u=Yc({},s),l={fns:{},schemas:{}};for(const f of c){const p=Jc({op:f,transport:"mcp",projection:r}),h=qc(p.mcp.name,void 0,o[p.mcp.name]),d=f.input&&typeof f.input=="object"&&f.input.type==="object"?f.input:{type:"object",properties:{}};t.bindToolMeta(p.mcp.name,{description:h,inputSchema:d}),t.registerRoute(p,v=>Qc(p,u,v,l))}}}function fo(e,t){const n=new Np.Server({name:"apigen-mcp",version:"1.0.0"},{capabilities:{tools:{}}});return n.setRequestHandler(Xi.ListToolsRequestSchema,async()=>({tools:e.listTools()})),n.setRequestHandler(Xi.CallToolRequestSchema,async r=>{const{name:o,arguments:s={}}=r.params,i=e.getPlan(o),a=e.getDispatch(o);if(!i||!a)throw new Error(`Unknown tool: ${o}`);const c=s,u=c._meta??{},l={args:c,meta:u},f=Date.now();try{const p=await e.readCall(l,i),h=await a(p);return await e.writeResult(l,h,i),t.info({tool:o,ms:Date.now()-f},`→ ${o}`),l.output}catch(p){throw t.error({tool:o,ms:Date.now()-f,err:p},`✗ ${o}`),e.writeError(l,p,i),p}}),n}function Zc(e,t){return async(n,r)=>{try{await t(n,r)}catch(o){e.error({err:o},"mcp http transport handler error"),r.headersSent||r.writeHead(500),r.writableEnded||r.end("Internal Server Error")}}}async function LO(e){const t=e.options.transport??"stdio",n=e.options.port??3e3,r=e.options.host??"127.0.0.1",o=e.logger??LS();o.info(`mcp server starting (${t})`);const s=new RO;DO(e,s);const i=s.listTools().map(c=>c.name);o.info({tools:i},`${i.length} tools available`);for(const c of i){const u=s.getPlan(c),l=(u==null?void 0:u.params)??[],f=l.map(p=>`${p.name}${p.required?"":"?"}: ${p.type}`).join(", ");o.info({tool:c,args:{data:l}},`tool: ${c} args { data: {${f?` ${f} `:""}} }`)}if(t==="stdio"){const c=fo(s,o),u=new _p.StdioServerTransport;return await c.connect(u),o.info("stdio transport ready"),new Promise(l=>{e.signal&&e.signal.addEventListener("abort",()=>{o.info("mcp server shutting down"),l()})})}if(t==="sse"){const c=new Map,u=Zi.createServer(Zc(o,async(l,f)=>{const p=l.url??"";if(l.method==="GET"&&p==="/sse"){const h=fo(s,o),d=new kp.SSEServerTransport("/messages",f);c.set(d.sessionId,d),d.onclose=()=>c.delete(d.sessionId),await h.connect(d)}else if(l.method==="POST"&&p.startsWith("/messages")){const h=new URLSearchParams(p.split("?")[1]??"").get("sessionId"),d=h?c.get(h):void 0;if(!d){f.writeHead(404),f.end("Session not found");return}await d.handlePostMessage(l,f)}else f.writeHead(404),f.end("Not found")}));return u.listen(n,r,()=>{o.info({host:r,port:n},`listening on http://${r}:${n}`)}),new Promise(l=>{e.signal&&e.signal.addEventListener("abort",()=>{o.info("mcp server shutting down"),u.close(()=>l())})})}const a=Zi.createServer(Zc(o,async(c,u)=>{const l=fo(s,o),f=new Ap.StreamableHTTPServerTransport({sessionIdGenerator:void 0});await l.connect(f),await f.handleRequest(c,u)}));return a.listen(n,r,()=>{o.info({host:r,port:n},`listening on http://${r}:${n}`)}),new Promise(c=>{e.signal&&e.signal.addEventListener("abort",()=>{o.info("mcp server shutting down"),a.close(()=>c())})})}const BO={id:"mcp",run(e){return LO(e)}},zf=new Set(["FIXED","RESOLVED","DONE","SHIPPED","VERIFIED","REMOVED"]),Wf=new Set(["MITIGATED"]),Hf=new Set(["SUPERSEDED","INVALID","DUPLICATE","WONTFIX"]),Ui=new Set(["FIXED","RESOLVED","DONE","SHIPPED","VERIFIED","REMOVED","MITIGATED","SUPERSEDED","INVALID","DUPLICATE","WONTFIX"]);function Ce(e){return Ui.has(e)}function ur(e){return zf.has(e)||Wf.has(e)}function lr(e){return Hf.has(e)}class $e extends Error{constructor(t,n){super(`backlog item not found: ${t}::${n}`),this.name="BacklogItemNotFoundError"}}class Jf extends Error{constructor(t){super(`transition to terminal status "${t}" requires at least one citation (either already attached via addCitation or passed inline to transitionStatus/resolveItem) — per the global CLAUDE.md rule "No citation, no claim."`),this.name="CitationRequiredError"}}class Yf extends Error{constructor(t){super(`transition to terminal-dismissed status "${t}" requires a reason string`),this.name="ReasonRequiredError"}}class Qf extends Error{constructor(t,n){super(`item is claimed by "${t}" since ${n} (not stale) — cannot start work`),this.heldBy=t,this.heldSince=n,this.name="ClaimHeldError"}}class UO extends Error{constructor(t){super(`dependency cycle detected: ${t.join(" -> ")}`),this.cycle=t,this.name="DependencyCycleError"}}function FO(e,t){const n=t??D.join(Lt.homedir(),`.${e.orgNamespace}`);return D.join(n,e.project,e.namespace,"config.yaml")}function VO(e,t,n){const r=FO(e,n);let o={};if(K.existsSync(r))try{const a=ea.parse(K.readFileSync(r,"utf8"));a!==null&&typeof a=="object"&&!Array.isArray(a)&&(o=a)}catch{o={}}const s=o.migration&&typeof o.migration=="object"&&!Array.isArray(o.migration)?o.migration:{},i={...o,migration:{...s,phase:t}};return K.mkdirSync(D.dirname(r),{recursive:!0}),K.writeFileSync(r,ea.stringify(i),"utf8"),r}const ke="backlog-item",Xc="backlog-plan",eu="backlog-assignee",qO="adhd-backlog:";function KO(e){return au.createHash("sha256").update(e.trim().toLowerCase()).digest("hex")}function Zf(e){return e.replace(/[^\p{L}\p{N}_\s]/gu," ").trim().replace(/\s+/g," ")}function Ar(e){return e.split("-")[0]??e}function Ir(e){return e.replace(/-\d+$/,"")}function Fi(e,t,n,r){return`${n}
170
+
171
+ ${r}
172
+
173
+ <!-- ${qO}${e}::${t} -->`}function Vi(e,t){return`${e}::${t}`}function qi(e){switch(e){case"CRITICAL":return 10;case"HIGH":return 8;case"MEDIUM":return 5;case"LOW":return 2;default:return 1}}function Xf(e,t,n=[]){return[...new Set([ke,e,t,...n])]}function Ze(e){return e.tags.includes(ke)&&!e.isSuperseded}function ne(e){const t=e.metadata??{},n=t.humanId??"",r=t.kind??Ar(n),o=t.family??Ir(n),s=new Set([ke,r,o]);return{nodeId:e.id,humanId:n,kind:r,family:o,title:t.title??e.summary??"",body:t.body??"",status:t.status??"UNKNOWN",priority:t.priority,repo:t.repo??e.namespace,projectPath:t.projectPath,plan:t.plan,importedFrom:t.importedFrom,assignee:t.assignee,claimedBy:t.claimedBy,claimedAt:t.claimedAt,citations:t.citations??[],notes:t.notes??[],tags:e.tags.filter(i=>!s.has(i)),createdAt:t.createdAt??e.tCreated,updatedAt:t.updatedAt??t.createdAt??e.tCreated}}const GO=5,zO=20,WO=500;function HO(e){const t=e==null?void 0:e.code;return t==="SQLITE_BUSY"||t==="SQLITE_BUSY_TIMEOUT"||t==="SQLITE_BUSY_SNAPSHOT"}function JO(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,Math.max(0,Math.round(e)))}function ed(e,t={}){const n=t.maxAttempts??GO;for(let r=0;;r++)try{return e()}catch(o){if(!HO(o)||r>=n-1)throw o;const s=Math.min(WO,zO*2**r);JO(s*(.5+Math.random()*.5))}}function YO(e,t,n){const r=e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{family:n}});let o=0;for(const s of r){const i=s.metadata,a=/-(\d+)$/.exec((i==null?void 0:i.humanId)??"");a&&(o=Math.max(o,Number(a[1])))}return`${n}-${String(o+1).padStart(3,"0")}`}function QO(e,t,n){return e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{humanId:n}}).find(o=>{var s;return Ze(o)&&((s=o.metadata)==null?void 0:s.humanId)===n})??null}function td(e,t,n,r,o){return ed(()=>e.db.transaction(()=>{if(r){const i=QO(e,t,r);return o(r,i)}const s=YO(e,t,n);return o(s,null)}).immediate())}const nd="backlog-audit-event";function rd(e,t,n,r,o,s){const i=new Date().toISOString(),a={itemNodeId:t,kind:o,at:i,detail:s},c=`audit-event::${n}::${r}::${o}::${i}::${Math.random().toString(36).slice(2)}`,u=e.graph.writeNode(c,{kind:"generic",name:`audit-event::${n}::${r}::${i}`,tags:[nd],namespace:n,metadata:a});e.graph.writeEdge(u,t,"DERIVED_FROM")}function ZO(e,t){return e.graph.queryNodes({kind:"generic",tags:[nd],metadata:{itemNodeId:t}}).map(r=>r.metadata).filter(r=>r!==void 0&&r.itemNodeId===t).map(r=>({at:r.at,kind:r.kind,detail:r.detail})).sort((r,o)=>r.at.localeCompare(o.at))}const tu={CRITICAL:0,HIGH:1,MEDIUM:2,LOW:3};function nu(e){const t=[ke];e.kind&&t.push(e.kind),e.tags&&t.push(...e.tags);const n={};e.family&&(n.family=e.family),e.priority&&(n.priority=e.priority),e.plan&&(n.plan=e.plan),e.importedFrom&&(n.importedFrom=e.importedFrom),e.assignee&&(n.assignee=e.assignee),e.claimedBy&&(n.claimedBy=e.claimedBy),e.status&&e.status!=="open"&&e.status!=="closed"&&(n.status=e.status);const r={kind:"generic",tags:t,tagsMatchAll:!0};return e.repo!==void 0&&(r.namespace=e.repo),e.projectPath!==void 0&&(r.projectPath=e.projectPath),Object.keys(n).length>0&&(r.metadata=n),r}function XO(e,t){return t.status==="open"?e.filter(n=>!Ce(n.status)):t.status==="closed"?e.filter(n=>Ce(n.status)):e}function ru(e,t){return t.rootLevel?e.filter(n=>{const r=n.metadata;return!(r!=null&&r.projectPath)&&!(r!=null&&r.plan)}):e}function ou(e,t){return t.excludeArchived?e.filter(n=>{var r;return!((r=n.metadata)!=null&&r.archivedAt)}):e}function od(e,t={}){if(t.grep){const o=nu({...t}),s=Zf(t.grep);if(!s)return[];const i=e.graph.searchNodes(s,{limit:t.limit??1e3,filter:o});let a=ou(ru(i.filter(Ze),t),t);return t.offset&&(a=a.slice(t.offset)),a}const n=nu(t);t.limit!==void 0&&(n.limit=t.limit),t.offset!==void 0&&(n.offset=t.offset);const r=e.graph.queryNodes(n);return ou(ru(r.filter(Ze),t),t)}function nt(e,t={}){const r=od(e,t).map(ne);return XO(r,t)}function Ke(e,t,n){const r=Vi(t,n),s=e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{humanId:n}}).filter(Ze);return s.find(i=>i.name===r)??s[0]??null}function Zt(e,t){const n={};for(const r of e){const o=t(r);o&&(n[o]=(n[o]??0)+1)}return n}function eN(e,t={}){const n=nt(e,{repo:t.repo,projectPath:t.projectPath}),r=n.filter(s=>!Ce(s.status)),o=n.filter(s=>Ce(s.status));return{total:n.length,open:r.length,closed:o.length,byStatus:Zt(n,s=>s.status),byKind:Zt(n,s=>s.kind),byFamily:Zt(n,s=>s.family),byPriority:Zt(n,s=>s.priority),byRepo:t.repo===void 0?Zt(n,s=>s.repo):{}}}function tN(e,t={},n=20){const o=nt(e,{repo:t.repo,projectPath:t.projectPath,status:"open"}).filter(s=>s.priority!==void 0);return o.sort((s,i)=>{const a=tu[s.priority??""]??4,c=tu[i.priority??""]??4;return a-c||s.humanId.localeCompare(i.humanId)}),o.slice(0,n)}function sd(e,t){const n=e.graph.getEdges({src:t,rel:"DEPENDS_ON"}),r=[];for(const o of n){const s=e.graph.getNode(o.dst);s&&r.push(s)}return r}function nN(e,t,n){const r=Ke(e,t,n);return r?sd(e,r.id).filter(o=>!o.tInvalid).map(ne).filter(o=>!Ce(o.status)):[]}function rN(e,t={}){return nt(e,{repo:t.repo,projectPath:t.projectPath,status:"open"}).filter(r=>{if(r.claimedBy)return!1;const o=Ke(e,r.repo,r.humanId);return o?sd(e,o.id).filter(i=>!i.tInvalid).every(i=>Ce(ne(i).status)):!1})}function id(e,t={}){const n=nt(e,{repo:t.repo,projectPath:t.projectPath}),r=n.map(s=>({humanId:s.humanId,title:s.title,status:s.status})),o=[];for(const s of n){const i=Ke(e,s.repo,s.humanId);if(i)for(const a of["DEPENDS_ON","RELATES_TO","PART_OF"])for(const c of e.graph.getEdges({src:i.id,rel:a})){const u=e.graph.getNode(c.dst);if(!u||u.tInvalid)continue;const l=u.metadata;l!=null&&l.humanId&&o.push({from:s.humanId,to:l.humanId,rel:a})}}return{nodes:r,edges:o}}function oN(e,t={}){var c;const n=id(e,t),r=n.edges.filter(u=>u.rel==="DEPENDS_ON"),o=new Map;for(const u of n.nodes)o.set(u.humanId,new Set);for(const u of r)(c=o.get(u.from))==null||c.add(u.to);const s=new Set(n.nodes.map(u=>u.humanId)),i=[];let a=!0;for(;s.size>0&&a;){a=!1;for(const u of[...s].sort())[...o.get(u)??new Set].every(p=>!s.has(p))&&(i.push(u),s.delete(u),a=!0)}return s.size>0?{ok:!1,cycle:sN([...s],o)}:{ok:!0,order:i}}function sN(e,t){const n=new Set(e),r=new Set,o=[];function s(i){if(r.has(i)){const a=o.indexOf(i);return[...o.slice(a),i]}if(!n.has(i))return null;r.add(i),o.push(i);for(const a of t.get(i)??[]){const c=s(a);if(c)return c}return o.pop(),r.delete(i),null}for(const i of e){const a=s(i);if(a)return a}return e}function iN(e,t,n={}){const r=nt(e,{repo:n.repo,projectPath:n.projectPath}),o=t*6e4,s=Date.now();return r.filter(i=>!i.claimedBy||!i.claimedAt?!1:s-Date.parse(i.claimedAt)>=o)}function aN(e,t,n){var u,l,f,p;const r=Ke(e,t,n);if(!r)throw new $e(t,n);const o=ne(r),s=[{at:o.createdAt,kind:"created",detail:{title:o.title,repo:o.repo}}];for(const h of o.citations)s.push({at:o.updatedAt,kind:"citation",detail:{...h}});for(const h of o.notes)s.push({at:h.at,kind:"note",detail:{by:h.by,text:h.text}});s.push(...ZO(e,r.id)),s.sort((h,d)=>h.at.localeCompare(d.at));const i=e.graph.getSupersessionChain(r.id);let a;if(i.length>1){const h=i.findIndex(m=>m.id===r.id),d=h>0?((l=(u=i[h-1])==null?void 0:u.metadata)==null?void 0:l.humanId)??void 0:void 0,v=h>=0&&h<i.length-1?((p=(f=i[h+1])==null?void 0:f.metadata)==null?void 0:p.humanId)??void 0:void 0;a={},d&&(a.supersedes=d),v&&(a.supersededBy=v)}const c={humanId:o.humanId,history:s};return a&&(c.supersessionChain=a),c}class cN extends Error{constructor(t){super(`backlog item not found or invalidated: node ${t}`),this.nodeId=t,this.name="NotFoundError"}}function we(e,t,n){return ed(()=>e.db.transaction(()=>{const r=e.graph.getNode(t);if(!r||r.tInvalid)throw new cN(t);const o=r.metadata??{},s=n(o);return e.graph.touch(t,{metadata:s}),s}).immediate())}function uN(e,t,n){const r=new Map,o=Zf(n.title);if(o)for(const i of e.graph.searchNodes(o,{limit:10,filter:{tags:[ke],namespace:t}}))Ze(i)&&r.set(i.id,i);const s=n.dedupeScan;if(s!=null&&s.symbol)for(const i of e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{dedupeSymbol:s.symbol}}))Ze(i)&&r.set(i.id,i);if(s!=null&&s.path)for(const i of e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{dedupePath:s.path}}))Ze(i)&&r.set(i.id,i);if(s!=null&&s.errorText)for(const i of e.graph.queryNodes({kind:"generic",tags:[ke],namespace:t,metadata:{dedupeErrorText:s.errorText}}))Ze(i)&&r.set(i.id,i);return[...r.values()].map(ne)}function Ki(e,t){if(t.idOverride){const r=Ke(e,t.repo,t.idOverride);if(r){const o=ne(r);return{item:o,created:!1,duplicateCandidates:[o]}}}const n=t.force?[]:uN(e,t.repo,t);return n.length>0&&!t.force?{item:n[0],created:!1,duplicateCandidates:n}:td(e,t.repo,t.family,t.idOverride,(r,o)=>{var f,p,h;if(o){const d=ne(o);return{item:d,created:!1,duplicateCandidates:[d]}}const s=Ar(r),i=Ir(r),a=new Date().toISOString(),c={humanId:r,kind:s,family:i,title:t.title,body:t.body,status:"OPEN",repo:t.repo,citations:[],notes:[],createdAt:a,updatedAt:a};t.priority!==void 0&&(c.priority=t.priority),t.projectPath!==void 0&&(c.projectPath=t.projectPath),t.plan!==void 0&&(c.plan=t.plan),t.importedFrom!==void 0&&(c.importedFrom=t.importedFrom),((f=t.dedupeScan)==null?void 0:f.symbol)!==void 0&&(c.dedupeSymbol=t.dedupeScan.symbol),((p=t.dedupeScan)==null?void 0:p.path)!==void 0&&(c.dedupePath=t.dedupeScan.path),((h=t.dedupeScan)==null?void 0:h.errorText)!==void 0&&(c.dedupeErrorText=t.dedupeScan.errorText);const u=e.graph.writeNode(Fi(t.repo,r,t.title,t.body),{kind:"generic",name:Vi(t.repo,r),summary:t.title,tags:Xf(s,i,t.tags),namespace:t.repo,importance:qi(t.priority),confidence:"confirmed",...t.projectPath!==void 0?{projectPath:t.projectPath}:{},metadata:c}),l=e.graph.getNode(u);if(!l)throw new Error(`backlog: writeNode returned an id that does not resolve: ${u}`);return{item:ne(l),created:!0,duplicateCandidates:[]}})}function ad(e,t,n){const r=Ke(e,t,n);return r?ne(r):null}function cd(e,t,n){const r=Ke(e,t,n);if(!r)throw new $e(t,n);return r}function ud(e,t,n,r){const o=cd(e,t,n);let s="",i="";if(we(e,o.id,c=>{const u={...c,updatedAt:new Date().toISOString()};return r.title!==void 0&&(u.title=r.title),r.body!==void 0&&(u.body=r.body),r.projectPath!==void 0&&(u.projectPath=r.projectPath),r.importedFrom!==void 0&&(u.importedFrom=r.importedFrom),s=u.title,i=u.body,u}),r.title!==void 0||r.tags!==void 0||r.projectPath!==void 0){const c={};if(r.title!==void 0&&(c.summary=r.title),r.tags!==void 0){const u=Ar(n),l=Ir(n);c.tags=Xf(u,l,r.tags)}r.projectPath!==void 0&&(c.projectPath=r.projectPath),e.graph.touch(o.id,c)}if(r.title!==void 0||r.body!==void 0){const c=Fi(t,n,s,i);e.db.prepare("UPDATE node SET content = ?, content_hash = ? WHERE rowid = ? AND t_invalid IS NULL").run(c,KO(c),o.id)}const a=e.graph.getNode(o.id);if(!a)throw new $e(t,n);return ne(a)}function lN(e,t,n,r){const o=cd(e,t,n);e.graph.invalidate(o.id,r)}function Gi(e,t,n){const r=e.graph.getNode(t),o=r==null?void 0:r.metadata;o!=null&&o.repo&&(o!=null&&o.humanId)&&rd(e,t,o.repo,o.humanId,"claim",n)}const fN=30;class dN extends Error{constructor(t,n){super(`cannot release claim held by "${t}" as "${n}" without force`),this.heldBy=t,this.name="ClaimContentionError"}}function ld(e,t,n,r={}){const o=(r.staleAfterMin??fN)*6e4;let s;return we(e,t,i=>{const a=Date.now(),c=new Date(a).toISOString();return!i.claimedBy||i.claimedBy===n?(s={status:i.claimedBy?"renewed":"claimed",claimedBy:n,claimedAt:c},{...i,claimedBy:n,claimedAt:c,updatedAt:c}):(i.claimedAt?a-Date.parse(i.claimedAt):Number.POSITIVE_INFINITY)<=o&&!r.force?(s={status:"held",claimedBy:n,claimedAt:c,heldBy:i.claimedBy,...i.claimedAt!==void 0?{heldSince:i.claimedAt}:{}},i):(s={status:"reclaimed-stale",claimedBy:n,claimedAt:c,previousClaimant:i.claimedBy},{...i,claimedBy:n,claimedAt:c,updatedAt:c})}),s.status!=="held"&&Gi(e,t,{status:s.status,by:n}),s}function pN(e,t,n){let r;return we(e,t,o=>{const s=new Date().toISOString();return r={status:o.claimedBy?"renewed":"claimed",claimedBy:n,claimedAt:s},{...o,claimedBy:n,claimedAt:s,updatedAt:s}}),Gi(e,t,{status:r.status,by:n}),r}function hN(e,t,n,r={}){let o;return we(e,t,s=>{if(!s.claimedBy)return o={status:"release-noop"},s;if(s.claimedBy!==n&&!r.force)throw new dN(s.claimedBy,n);o={status:"released",wasClaimedBy:s.claimedBy};const a=new Date().toISOString(),c={...s,updatedAt:a};return delete c.claimedBy,delete c.claimedAt,c}),o.status!=="release-noop"&&Gi(e,t,{status:o.status,by:n,wasClaimedBy:o.wasClaimedBy}),o}function jr(e,t,n){const r=Ke(e,t,n);if(!r)throw new $e(t,n);return r}function $n(e,t,n,r,o){const s=jr(e,t,n);let i;we(e,s.id,c=>{i=c.status;const u=o.citations&&o.citations.length>0?[...c.citations,...o.citations]:c.citations;if(ur(r)&&u.length===0)throw new Jf(r);if(lr(r)&&!o.reason)throw new Yf(r);const l=new Date().toISOString(),f=[...c.notes];o.note&&f.push({by:o.by,at:l,text:o.note}),o.reason&&f.push({by:o.by,at:l,text:`[transition to ${r}] ${o.reason}`});const p={...c,status:r,citations:u,notes:f,updatedAt:l};return Ui.has(r)&&(delete p.claimedBy,delete p.claimedAt),p}),rd(e,s.id,t,n,"transition",{from:i,to:r,by:o.by,...o.reason?{reason:o.reason}:{}});const a=e.graph.getNode(s.id);if(!a)throw new $e(t,n);return ne(a)}function mN(e,t,n,r,o){return $n(e,t,n,r,o)}function gN(e,t,n,r){const o=jr(e,t,n),s=ld(e,o.id,r);if(s.status==="held")throw new Qf(s.heldBy??"unknown",s.heldSince??"unknown");return $n(e,t,n,"IN_PROGRESS",{by:r})}function yN(e,t,n,r){const o=jr(e,t,n);we(e,o.id,i=>({...i,citations:[...i.citations,r],updatedAt:new Date().toISOString()}));const s=e.graph.getNode(o.id);if(!s)throw new $e(t,n);return ne(s)}function vN(e,t,n,r,o){const s=jr(e,t,n);we(e,s.id,a=>{const c=new Date().toISOString();return{...a,notes:[...a.notes,{by:r,at:c,text:o}],updatedAt:c}});const i=e.graph.getNode(s.id);if(!i)throw new $e(t,n);return ne(i)}function $N(e,t,n={}){const r=new Set((n.exclude??[]).map(i=>i.toUpperCase())),o=nt(e,{repo:t.repo,projectPath:t.projectPath,status:"closed"}),s=[];for(const i of o){if(r.has(i.humanId.toUpperCase())||!Ce(i.status))continue;const a=new Date().toISOString();we(e,i.nodeId,u=>({...u,archivedAt:a,updatedAt:a}));const c=e.graph.getNode(i.nodeId);c&&s.push(ne(c))}return s}function ve(e,t,n){const r=Ke(e,t,n);if(!r)throw new $e(t,n);return r}function wN(e,t,n,r){const o=ve(e,t,n),s=ve(e,t,r);e.graph.writeEdge(o.id,s.id,"DEPENDS_ON")}function bN(e,t,n,r){const o=ve(e,t,n),s=ve(e,t,r);e.db.prepare("DELETE FROM edge WHERE src = ? AND dst = ? AND rel = 'DEPENDS_ON'").run(o.id,s.id)}function EN(e,t,n,r){const o=ve(e,t,n),s=ve(e,t,r);e.graph.writeEdge(o.id,s.id,"RELATES_TO")}function SN(e,t,n,r,o){const s=ve(e,t,n),i=new Date().toISOString();let a="";const c=td(e,t,r.family,r.idOverride,l=>{a=l;const f=Ar(a),p=Ir(a),h={humanId:a,kind:f,family:p,title:r.title,body:r.body,status:"OPEN",repo:t,citations:[],notes:[],createdAt:i,updatedAt:i};return r.priority!==void 0&&(h.priority=r.priority),r.projectPath!==void 0&&(h.projectPath=r.projectPath),r.plan!==void 0&&(h.plan=r.plan),e.graph.supersede(s.id,Fi(t,a,r.title,r.body),{kind:"generic",name:Vi(t,a),summary:r.title,tags:["backlog-item",f,p,...r.tags??[]],namespace:t,importance:qi(r.priority),confidence:"confirmed",...r.projectPath!==void 0?{projectPath:r.projectPath}:{},metadata:h})});we(e,s.id,l=>{const f=[...l.notes,{by:"system",at:i,text:`[superseded by ${a}] ${o}`}],p={...l,status:"SUPERSEDED",notes:f,updatedAt:i};return delete p.claimedBy,delete p.claimedAt,p}),e.graph.invalidate(s.id,o);const u=e.graph.getNode(c);if(!u)throw new Error(`backlog: supersede() returned an id that does not resolve: ${c}`);return ne(u)}function ON(e,t,n,r){const o=ve(e,t,n),s=[];for(const i of r){const a=Ki(e,{...i,repo:t});e.graph.writeEdge(a.item.nodeId,o.id,"PART_OF"),s.push(a.item)}return s}function NN(e,t,n,r,o){const s=ve(e,t,n),i=ve(e,t,r);we(e,i.id,c=>{const u=new Date().toISOString(),l={...c,status:"DUPLICATE",notes:[...c.notes,{by:"system",at:u,text:`[merged into ${n}] ${o}`}],updatedAt:u};return delete l.claimedBy,delete l.claimedAt,l}),e.graph.writeEdge(i.id,s.id,"SAME_AS"),e.graph.invalidate(i.id,o);const a=e.graph.getNode(s.id);if(!a)throw new $e(t,n);return ne(a)}function fd(e,t,n,r){const o=ve(e,t,n);we(e,o.id,i=>({...i,priority:r,updatedAt:new Date().toISOString()})),e.graph.touch(o.id,{importance:qi(r)});const s=e.graph.getNode(o.id);if(!s)throw new $e(t,n);return ne(s)}function _N(e,t,n){const r=`${t}::plan:${n}`,s=e.graph.queryNodes({kind:"generic",tags:[Xc],namespace:t,metadata:{planSlug:n}}).find(i=>i.name===r&&!i.isSuperseded);return s?s.id:e.graph.writeNode(`plan:${n}`,{kind:"generic",name:r,summary:n,tags:[Xc],namespace:t,metadata:{planSlug:n}})}function ns(e,t,n,r){const o=ve(e,t,n),s=_N(e,t,r);we(e,o.id,i=>({...i,plan:r,updatedAt:new Date().toISOString()})),e.graph.writeEdge(o.id,s,"MEMBER_OF")}function kN(e,t){const r=e.graph.queryNodes({kind:"entity",tags:[eu],metadata:{identity:t}}).find(o=>o.name===t&&!o.isSuperseded);return r?r.id:e.graph.writeNode(`assignee:${t}`,{kind:"entity",name:t,summary:t,tags:[eu],metadata:{identity:t}})}function AN(e,t,n,r,o){const s=ve(e,t,n),i=kN(e,r);we(e,s.id,c=>{const u=new Date().toISOString();return{...c,assignee:r,notes:[...c.notes,{by:o,at:u,text:`assigned to ${r}`}],updatedAt:u}}),e.graph.writeEdge(s.id,i,"ASSIGNED_TO");const a=e.graph.getNode(s.id);if(!a)throw new $e(t,n);return ne(a)}const su=/^(#{2,3})\s+([A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+)/,IN=["FIXED","RESOLVED","DONE","SHIPPED","VERIFIED","REMOVED","CLOSED"],jN=["MITIGATED"],PN=["INVALID","SUPERSEDED","DUPLICATE","WONTFIX"],xN=new Set([...IN,...jN,...PN]),TN=new Set(["OPEN","IN_PROGRESS","PARTIAL","OUTSTANDING","DEFERRED","BLOCKED","MIXED","UNKNOWN","FIXED","RESOLVED","DONE","SHIPPED","VERIFIED","REMOVED","MITIGATED","SUPERSEDED","INVALID","DUPLICATE","WONTFIX"]);function dd(e){const t=e.toUpperCase();return t==="IN-PROGRESS"?"IN_PROGRESS":t==="CLOSED"?"RESOLVED":TN.has(t)?t:"UNKNOWN"}function pd(e){var s;const t=(e??"").toLowerCase();if(!t.trim())return null;const n=i=>t.includes(i);if(n("outstanding"))return{label:"OUTSTANDING",open:!0};if(n("partially"))return{label:"PARTIAL",open:!0};if(n("in progress"))return{label:"IN-PROGRESS",open:!0};const r=n("shipped")&&"SHIPPED"||n("superseded")&&"SUPERSEDED"||n("invalid")&&"INVALID"||n("mitigated")&&"MITIGATED"||n("removed")&&!n("open")&&"REMOVED"||n("fixed")&&"FIXED"||n("resolved")&&"RESOLVED"||n("done")&&"DONE"||null,o=n("open")&&"OPEN"||(n("deferred")||n("defer"))&&"DEFERRED"||null;return r&&o?{label:"MIXED",open:!0}:r?{label:r,open:!1}:o?{label:o,open:!0}:n("downgraded")?{label:"OPEN",open:!0}:{label:((s=t.trim().split(/\s+/)[0])==null?void 0:s.toUpperCase().replace(/[^A-Z]/g,""))||"UNKNOWN",open:!0}}function hd(e,t){const n=t.match(/^\s*-?\s*\*\*Status:\*?\*?\s*([^\n]+)/im),r=n?pd(n[1]):null;if(r)return r;const o=e.toUpperCase();for(const s of["RESOLVED","FIXED","MITIGATED","DONE","CLOSED"])if(o.includes(s))return{label:s,open:!1};return{label:"UNKNOWN",open:!0}}function md(e,t){const r=`${e}
174
+ ${t}`.match(/\*{0,2}priority:?\*{0,2}\s*[:-]?\s*(CRITICAL|HIGH|MEDIUM|LOW)/i);return r?r[1].toUpperCase():/—\s*CRITICAL\b/i.test(e)||/\bCRITICAL\b/.test(e)?"CRITICAL":""}const CN=/^[A-Z][A-Z0-9_-]*$/;function RN(e){const t=e.trim().split(/\s+/)[0]??"";return CN.test(t)&&/[0-9_]/.test(t)}function gd(e){const t=e.split(`
175
+ `),n=[],r=[];let o=null;const s=()=>{if(!o)return;const i=o.bodyLines.join(`
176
+ `),a=hd(o.headerLine,i),c=md(o.headerLine,i),{bodyLines:u,...l}=o,f=!xN.has(a.label);n.push({...l,status:a.label,open:f,terminal:!f,priority:c,body:i.trim()}),o=null};return t.forEach((i,a)=>{const c=i.match(su),u=/^#{2,3}\s/.test(i);if(c&&/\d/.test(c[2])){s();const l=c[2],f=i.replace(su,"").replace(/^\s*[—–-]\s*/,"").trim(),p=l.split("-");o={id:l,kind:p[0]??l,family:l.replace(/-\d+[a-z]?$/i,""),title:f,level:c[1].length,line:a+1,headerLine:i,bodyLines:[]}}else if(u){const l=i.replace(/^#{2,3}\s+/,"");RN(l)&&r.push({line:a+1,headerLine:i}),s(),o=null}else o&&o.bodyLines.push(i)}),s(),{items:n,malformedHeaders:r}}function MN(e){return gd(e).items}function yd(e){return gd(e)}function DN(e){return`**Citations:** [${e.map(n=>{const r=n.lines?`${n.file}:${n.lines}`:n.file;return n.context?`${r} (${n.context})`:r}).join(", ")}]`}function LN(e){return e==="IN_PROGRESS"?"IN PROGRESS":e}function vd(e){const t=[];t.push(`### ${e.humanId} — ${e.title}`),t.push(""),t.push(`**Status:** ${LN(e.status)}`),e.priority&&t.push(`**Priority:** ${e.priority}`),e.assignee&&t.push(`**Assignee:** ${e.assignee}`),e.plan&&t.push(`**Plan:** ${e.plan}`),t.push(""),e.body&&t.push(e.body,""),e.citations.length>0&&t.push(DN(e.citations));for(const n of e.notes)t.push(`- Note (${n.by}, ${n.at}): ${n.text}`);return t.join(`
177
+ `).trimEnd()}function $d(e){return e.length===0?"":`${e.map(vd).join(`
178
+
179
+ `)}
180
+ `}function BN(e){return e.split(`
181
+ `).map(UN).join(`
182
+ `)}function UN(e){return/^###\s/.test(e)?`##${e}`:/^##\s/.test(e)?`##${e}`:e}function wd(e,t){let n=`### Archived — resolved/terminal backlog items relocated in batch (${t})
183
+
184
+ `;return n+="> Moved via `@adhd/backlog`'s `archiveResolved` (canonical terminal statuses: FIXED/RESOLVED/DONE/\n",n+=`> SHIPPED/VERIFIED/REMOVED/MITIGATED/SUPERSEDED/INVALID/DUPLICATE/WONTFIX). The graph node itself is
185
+ `,n+=`> NEVER deleted — this is a rendered snapshot; full history remains queryable via auditTrail.
186
+
187
+ `,n+=e.map(r=>BN(vd(r))).join(`
188
+
189
+ `),n+=`
190
+ `,n}function bd(e){return e.map(t=>{const n={humanId:t.id,title:t.title,body:t.body,status:dd(t.status)};return t.priority&&(t.priority==="CRITICAL"||t.priority==="HIGH"||t.priority==="MEDIUM"||t.priority==="LOW")&&(n.priority=t.priority),n})}function zi(e,t,n){const r=ad(e.store,t,n);if(!r)throw new $e(t,n);return r}async function Ed(e,t){return Ki(e.store,t)}async function Sd(e,t,n){return ad(e.store,t,n)}async function Od(e,t,n,r){return ud(e.store,t,n,r)}async function Nd(e,t){return nt(e.store,t??{})}async function _d(e,t,n,r){lN(e.store,t,n,r)}async function kd(e,t){return eN(e.store,t??{})}async function Ad(e,t,n){return tN(e.store,t??{},n??20)}async function Id(e,t){return rN(e.store,t??{})}async function jd(e,t,n){return nN(e.store,t,n)}async function Pd(e,t){return id(e.store,t??{})}async function xd(e,t){return oN(e.store,t??{})}async function Td(e,t,n){return iN(e.store,t,n??{})}async function Cd(e,t,n,r,o){const s=zi(e,t,n);return ld(e.store,s.nodeId,r,o??{})}async function Rd(e,t,n,r){const o=zi(e,t,n);return pN(e.store,o.nodeId,r)}async function Md(e,t,n,r,o){const s=zi(e,t,n);return hN(e.store,s.nodeId,r,o??{})}async function Dd(e,t,n,r,o){return AN(e.store,t,n,r,o)}async function Ld(e,t,n,r){return gN(e.store,t,n,r)}async function Bd(e,t,n,r,o){return $n(e.store,t,n,r,o)}async function Ud(e,t,n,r){return yN(e.store,t,n,r)}async function Fd(e,t,n,r,o){return vN(e.store,t,n,r,o)}async function Vd(e,t,n,r,o){return mN(e.store,t,n,r,o)}async function qd(e,t,n){const r=$N(e.store,t,n??{}),o=r.length>0?wd(r,new Date().toISOString().slice(0,10)):"";return{archivedCount:r.length,changelogMarkdown:o}}async function Kd(e,t,n,r){wN(e.store,t,n,r)}async function Gd(e,t,n,r){bN(e.store,t,n,r)}async function zd(e,t,n,r){EN(e.store,t,n,r)}async function Wd(e,t,n,r,o){return SN(e.store,t,n,r,o)}async function Hd(e,t,n,r){return ON(e.store,t,n,r)}async function Jd(e,t,n,r,o){return NN(e.store,t,n,r,o)}async function Yd(e,t,n,r){return fd(e.store,t,n,r)}async function Qd(e,t,n,r){ns(e.store,t,n,r)}async function Zd(e,t){const n=K.readFileSync(t.path,"utf8"),{items:r,malformedHeaders:o}=yd(n),s=bd(r),i=t.sourcePath??t.path,a={parsed:s.length,created:0,skippedDuplicates:0,updated:0,errors:[],malformedHeaders:o};if(t.dryRun)return a;for(const c of s)try{const u=Ki(e.store,{family:c.humanId.replace(/-\d+$/,""),idOverride:c.humanId,title:c.title,body:c.body,repo:t.repo,...t.projectPath!==void 0?{projectPath:t.projectPath}:{},...t.plan!==void 0?{plan:t.plan}:{},importedFrom:i,...c.priority!==void 0?{priority:c.priority}:{},force:!0});if(u.created&&t.plan!==void 0&&ns(e.store,t.repo,c.humanId,t.plan),u.created&&c.status!=="OPEN"&&$n(e.store,t.repo,c.humanId,c.status,{by:"system:importFromMarkdown",...ur(c.status)?{citations:[{file:t.path}]}:{},...lr(c.status)?{reason:`imported from markdown at status ${c.status}`}:{}}),u.created){a.created+=1;continue}a.skippedDuplicates+=1;const l=u.duplicateCandidates[0]??u.item;let f=!1;if(l.importedFrom===void 0||l.importedFrom===i){const h={};l.title!==c.title&&(h.title=c.title),l.body!==c.body&&(h.body=c.body),l.importedFrom===void 0&&(h.importedFrom=i),t.projectPath!==void 0&&l.projectPath!==t.projectPath&&(h.projectPath=t.projectPath),Object.keys(h).length>0&&(ud(e.store,t.repo,c.humanId,h),f=!0),c.priority!==void 0&&l.priority!==c.priority&&(fd(e.store,t.repo,c.humanId,c.priority),f=!0),l.status!==c.status&&($n(e.store,t.repo,c.humanId,c.status,{by:"system:importFromMarkdown",...ur(c.status)?{citations:[{file:t.path}]}:{},...lr(c.status)?{reason:`re-imported from markdown at status ${c.status}`}:{}}),f=!0)}t.plan!==void 0&&l.plan!==t.plan&&(ns(e.store,t.repo,c.humanId,t.plan),f=!0),f&&(a.updated+=1)}catch(u){a.errors.push({humanId:c.humanId,message:u instanceof Error?u.message:String(u)})}return a}async function Xd(e,t){let r=od(e.store,{...t,excludeArchived:!0}).map(ne);return(t==null?void 0:t.status)==="open"?r=r.filter(o=>!Ce(o.status)):(t==null?void 0:t.status)==="closed"&&(r=r.filter(o=>Ce(o.status))),$d(r)}async function ep(e,t){return nt(e.store,t??{})}async function tp(e,t,n){return aN(e.store,t,n)}const FN={"not-started":"not-started: BACKLOG.md is authoritative everywhere; the tool has not been adopted for this repo yet.","phase-1":"phase-1: seed import complete (or in progress) — BACKLOG.md remains authoritative; the graph is a read-only shadow copy.","phase-2":"phase-2: BACKLOG.md is still authoritative; the tool is shadow-running in parity-check mode (render vs. hand-edited markdown, non-blocking).","phase-3":"phase-3: the graph is authoritative. File/claim/transition/resolve via the backlog CLI/MCP — every BACKLOG.md is a generated projection, never hand-edited.","phase-4":"phase-4: phase-3 write path is live; the backlog-usage skill is published and distributed for agent discovery.","phase-5":"phase-5: the legacy tools/util/backlog.mjs parser has been deprecated/removed.",complete:"complete: migration fully done, including cross-repo rollout (Phase 6) where applicable."};async function np(e){const t=e.env.config.migration.phase;return rp(t)}function rp(e){const t=FN[e]??`unknown phase value: ${e}`;return{phase:e,description:t,toolIsAuthoritative:e==="phase-3"||e==="phase-4"||e==="phase-5"||e==="complete"}}async function op(e,t){const n=VO(e.env,t,e.adhdRoot);return{...rp(t),configPath:n}}const VN=Object.freeze(Object.defineProperty({__proto__:null,addCitation:Ud,addDependency:Kd,appendNote:Fd,archiveResolved:qd,assignItem:Dd,attachToPlan:Qd,auditTrail:tp,blockers:jd,claimItem:Cd,createItem:Ed,dependencyGraph:Pd,exportJson:ep,getItem:Sd,importFromMarkdown:Zd,linkRelated:zd,listItems:Nd,mergeItems:Jd,migrationStatus:np,readyItems:Id,releaseClaim:Md,removeDependency:Gd,renderToMarkdown:Xd,renewClaim:Rd,resolveItem:Vd,setMigrationPhase:op,setPriority:Yd,softDeleteItem:_d,splitItem:Hd,spotlight:Ad,staleClaims:Td,startWork:Ld,stats:kd,supersedeItem:Wd,topoOrder:xd,transitionStatus:Bd,updateItem:Od},Symbol.toStringTag,{value:"Module"}));function rs(e){if(!e.run)throw new Error(`@adhd/backlog: apigen plugin "${e.id}" declares no run() — cannot mount live`);return e.run}function sp(){if(!process.env.VITEST)return;const e=()=>{},t={info:e,error:e,debug:e,fatal:e,warn:e,trace:e};return t.child=()=>t,t}function ip(){return D.join(D.dirname(fr.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:Se&&Se.tagName.toUpperCase()==="SCRIPT"&&Se.src||new URL("index.js",document.baseURI).href)),"..","dist")}function iu(e){if(!e||typeof e!="object")return e;const t={},n=o=>{if(Array.isArray(o)){for(const i of o)n(i);return}if(!o||typeof o!="object")return;const s=o;for(const i of["definitions","$defs"]){const a=s[i];if(a&&typeof a=="object"&&!Array.isArray(a))for(const[c,u]of Object.entries(a))c in t||(t[c]=u)}for(const[i,a]of Object.entries(s))i==="definitions"||i==="$defs"||n(a)};if(n(e),n(t),Object.keys(t).length===0)return e;const r=(o,s)=>{if(Array.isArray(o))return o.map(u=>r(u,s));if(!o||typeof o!="object")return o;const i=o,a=i.$ref;if(typeof a=="string"){const u=a.replace(/^#\/(?:definitions|\$defs)\//,"");return s.has(u)||!(u in t)?{}:r(t[u],new Set([...s,u]))}const c={};for(const[u,l]of Object.entries(i))u==="definitions"||u==="$defs"||(c[u]=r(l,s));return c};return r(e,new Set)}async function qN(){const e=D.join(ip(),"client.d.ts");if(!K.existsSync(e))throw new Error(`@adhd/backlog: cannot mount — ${e} does not exist. Run "nx build backlog" first (extract() needs the built .d.ts for type information).`);return Mb({sourceFile:e,namespace:"backlog",dropFileSegment:!0})}async function Wi(e){const t=typeof e=="function"?e:()=>e,n=await qN(),r={schemas:Object.fromEntries(n.filter(s=>s.kind==="action").map(s=>{var i;return[((i=s.path[s.path.length-1])==null?void 0:i.raw)??"",{input:iu(s.input),output:iu(s.output),hasCtx:s.hasCtx,safe:s.safe}]}))};return{pkg:{id:"backlog",schemas:ub(r,[]),importPath:D.join(ip(),"client.js"),fns:VN,createClient:async()=>t()},operations:n}}async function ap(e){const t=wi({scope:e.scope,adhdRoot:e.adhdRoot,cwd:e.cwd});t.ensureDirs();const n=hs(t.files.db,t.config.db.busyTimeoutMs),r={store:n,env:t},{pkg:o,operations:s}=await Wi(r),i=sp(),a=[];(e.transport==="http"||e.transport==="both")&&a.push(rs(uS)({packages:[o],outputDir:"",options:{port:e.port??3300,host:e.host??"127.0.0.1",usePlugins:[wS]},signal:e.signal,operations:s,logger:i})),(e.transport==="mcp"||e.transport==="both")&&a.push(rs(BO)({packages:[o],outputDir:"",options:{transport:"stdio"},signal:e.signal,operations:s,logger:i}));try{await Promise.all(a)}finally{ms(n)}}const po=["claude","codex","opencode"],KN={claude:".claude",codex:".codex",opencode:".opencode"};function GN(e,t,n,r){if(t==="project")return D.join(n,KN[e],"skills");const o=r??Lt.homedir();if(e==="claude")return D.join(o,".claude","skills");if(e==="codex"){const s=r?D.join(o,".codex"):process.env.CODEX_HOME??D.join(o,".codex");return D.join(s,"skills")}return D.join(o,".config","opencode","skills")}function zN(){const e=D.dirname(fr.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:Se&&Se.tagName.toUpperCase()==="SCRIPT"&&Se.src||new URL("index.js",document.baseURI).href));return D.join(e,"..","skill","SKILL.md")}function WN(e){let t="all",n="user";for(let o=0;o<e.length;o++){const s=e[o];if(s==="--host")t=e[++o]??"all";else if(s==="--scope")n=e[++o]??"user";else throw new Error(`backlog install-skill: unknown argument "${s}" (expected --host/--scope)`)}if(n!=="user"&&n!=="project")throw new Error(`backlog install-skill: --scope must be "user" or "project", got "${n}"`);const r=t==="all"?[...po]:[t];for(const o of r)if(!po.includes(o))throw new Error(`backlog install-skill: --host must be one of ${po.join("|")}|all, got "${t}"`);return{hosts:r,scope:n}}function cp(e,t=process.cwd(),n){const{hosts:r,scope:o}=WN(e),s=zN();if(!K.existsSync(s))throw new Error(`backlog install-skill: packaged skill file not found at ${s} — was @adhd/backlog built/installed correctly?`);const i=K.readFileSync(s,"utf8"),a=D.join(D.dirname(fr.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:Se&&Se.tagName.toUpperCase()==="SCRIPT"&&Se.src||new URL("index.js",document.baseURI).href)),"..","package.json"),c=JSON.parse(K.readFileSync(a,"utf8")),u=[];for(const l of r){const f=D.join(GN(l,o,t,n),"backlog");K.mkdirSync(f,{recursive:!0});const p=D.join(f,"SKILL.md");K.writeFileSync(p,i,"utf8"),K.writeFileSync(D.join(f,"extension.json"),JSON.stringify({name:c.name,version:c.version,type:"skill",entrypoint:"SKILL.md"},null,2)+`
191
+ `,"utf8"),u.push({host:l,scope:o,path:p})}return u}async function up(e){const t=cp(e);console.log(JSON.stringify({installed:t}))}function HN(e){let t="mcp",n,r;for(let s=0;s<e.length;s++){const i=e[s];if(i==="--transport")t=e[++s];else if(i==="--port")n=Number(e[++s]);else if(i==="--host")r=e[++s];else throw new Error(`backlog serve: unknown argument "${i}" (expected --transport/--port/--host)`)}if(t!=="mcp"&&t!=="http"&&t!=="both")throw new Error(`backlog serve: --transport must be mcp|http|both, got "${t}"`);const o={transport:t};return n!==void 0&&(o.port=n),r!==void 0&&(o.host=r),o}async function lp(e,t={}){const n=HN(e),r=new AbortController;process.on("SIGTERM",()=>r.abort()),process.on("SIGINT",()=>r.abort()),await ap({...n,...t,signal:r.signal})}function fp(e){const t=e.find(n=>n.kind==="action");if(!t)throw new Error('@adhd/backlog: cli mount found zero "action" operations in client.ts — cannot derive a command prefix');return Xh(t).cli.path.slice(0,-1)}function dp(e,t){var r;return e.length===0?[...e]:(r=e[0])!=null&&r.startsWith("-")?[...e]:t.length>0&&t.every((o,s)=>e[s]===o)?[...e]:[...t,...e]}async function pp(e,t={}){const n=e??process.argv.slice(2);if(n[0]==="install-skill"){await up(n.slice(1));return}if(n[0]==="serve"){await lp(n.slice(1),t);return}let r;const o=()=>{if(!r){const s=wi({scope:t.scope,adhdRoot:t.adhdRoot,cwd:t.cwd});s.ensureDirs();const i=hs(s.files.db,s.config.db.busyTimeoutMs);r={store:i,ctx:{store:i,env:s}}}return r.ctx};try{const{pkg:s,operations:i}=await Wi(o),a=n,c=fp(i);await rs(Hh)({packages:[s],operations:i,outputDir:"",options:{argv:dp(a,c)},signal:t.signal??new AbortController().signal,logger:sp()})}finally{r&&ms(r.store)}}process.argv[1]&&(typeof document>"u"?require("url").pathToFileURL(__filename).href:Se&&Se.tagName.toUpperCase()==="SCRIPT"&&Se.src||new URL("index.js",document.baseURI).href)===fr.pathToFileURL(K.realpathSync(process.argv[1])).href&&pp().catch(e=>{console.error(e instanceof Error?e.stack??e.message:String(e)),process.exitCode=1});exports.BacklogItemNotFoundError=$e;exports.CitationRequiredError=Jf;exports.ClaimHeldError=Qf;exports.DependencyCycleError=UO;exports.ReasonRequiredError=Yf;exports.TERMINAL_DISMISSED_STATUSES=Hf;exports.TERMINAL_DONE_STATUSES=zf;exports.TERMINAL_STATUSES=Ui;exports.TERMINAL_WORKAROUND_STATUSES=Wf;exports.addCitation=Ud;exports.addDependency=Kd;exports.appendNote=Fd;exports.archiveResolved=qd;exports.assignItem=Dd;exports.attachToPlan=Qd;exports.auditTrail=tp;exports.backlogEnvironmentSpec=vf;exports.blockers=jd;exports.buildBacklogApigenPackage=Wi;exports.buildBacklogEnv=wi;exports.buildChangelogSection=wd;exports.claimItem=Cd;exports.classifyStatus=pd;exports.closeGraphBacklogStore=ms;exports.createItem=Ed;exports.dependencyGraph=Pd;exports.detectPriority=md;exports.detectStatus=hd;exports.exportJson=ep;exports.getItem=Sd;exports.importFromMarkdown=Zd;exports.installSkill=cp;exports.isTerminalStatus=Ce;exports.linkRelated=zd;exports.listItems=Nd;exports.mergeItems=Jd;exports.migrationStatus=np;exports.normalizeLegacyStatus=dd;exports.openGraphBacklogStore=hs;exports.parseBacklogMarkdown=MN;exports.parseBacklogMarkdownWithDiagnostics=yd;exports.prefixCommand=dp;exports.readyItems=Id;exports.releaseClaim=Md;exports.removeDependency=Gd;exports.renderItemsToMarkdown=$d;exports.renderToMarkdown=Xd;exports.renewClaim=Rd;exports.requiresCitation=ur;exports.requiresReason=lr;exports.resolveBacklogScope=$f;exports.resolveCommandPrefix=fp;exports.resolveItem=Vd;exports.runBacklogCli=pp;exports.runInstallSkillCommand=up;exports.runServeCommand=lp;exports.setMigrationPhase=op;exports.setPriority=Yd;exports.softDeleteItem=_d;exports.splitItem=Hd;exports.spotlight=Ad;exports.staleClaims=Td;exports.startBacklogServer=ap;exports.startWork=Ld;exports.stats=kd;exports.suggestClaimantIdentity=tb;exports.supersedeItem=Wd;exports.toImportItems=bd;exports.topoOrder=xd;exports.transitionStatus=Bd;exports.updateItem=Od;