gazesight 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -59,4 +59,4 @@ ${c}`:c:"",d=Function,m=`return (input) => {
|
|
|
59
59
|
${c}
|
|
60
60
|
}`,p;try{p=new d(...a,m)(...u)}catch(f){throw new Z(`this schema (generated code failed to evaluate: ${f.message})`)}return r?.debug&&(p.code=s),p.definite=o.definite,p}function A(e,r){for(let[o,t]of e.constants)if(t===r)return o;let i=`c${e.constantCounter++}`;return e.constants.set(i,r),i}function gt(e,r){return e.definite=!1,A(e,r)}function D(e){return`v${e.varCounter++}`}function t$(e,r){let i=e._zod.run({value:r,issues:[]},{});if(i&&typeof i.then=="function")return le;let o=i;return o.issues.length===0?o.value:le}function ie(e,r,i,o,t=!0){let n=e.content.length,a=r.constants.size,u=r.constantCounter,c=r.varCounter;try{return W(e,r,i,o,t)}catch(s){if(!(s instanceof Z)||!s.islandable)throw s;if(e.content.length=n,r.constants.size>a){let d=Array.from(r.constants.keys()).slice(a);for(let m of d)r.constants.delete(m)}return r.constantCounter=u,r.varCounter=c,r$(e,r,i,o)}}function r$(e,r,i,o){r.definite=!1;let t=A(r,i),n=A(r,t$),a=D(r);return e.write(`const ${a} = ${n}(${t}, ${o});`),e.write(`if (${a} === INVALID) return INVALID;`),a}var n$=new Set(["max_size","min_size","size_equals","max_length","min_length","length_equals"]);function i$(e,r,i,o){let t=i._zod.def.checks;if(!t||t.length===0)return o;let n=o;for(let a of t){let u=a._zod.def;if(u.when&&!n$.has(u.check))throw new Z('check with a custom "when" condition');switch(u.check){case"greater_than":o$(e,r,u,n);break;case"less_than":a$(e,r,u,n);break;case"multiple_of":u$(e,r,u,n);break;case"number_format":Ef(e,u,n);break;case"min_length":{let c=ft(u.minimum,"min_length"),s=Tc(e,r,n,`${n}.length >= ${c} && ${n}.length < ${u.minimum*2}`);e.write(`if (${s} < ${c}) return INVALID;`);break}case"max_length":{let c=ft(u.maximum,"max_length"),s=Tc(e,r,n,`${n}.length > ${c}`);e.write(`if (${s} > ${c}) return INVALID;`);break}case"length_equals":{let c=ft(u.length,"length_equals"),s=Tc(e,r,n,`${n}.length >= ${c} && ${n}.length <= ${u.length*2}`);e.write(`if (${s} !== ${c}) return INVALID;`);break}case"min_size":e.write(`if (${n}.size < ${ft(u.minimum,"min_size")}) return INVALID;`);break;case"max_size":e.write(`if (${n}.size > ${ft(u.maximum,"max_size")}) return INVALID;`);break;case"size_equals":e.write(`if (${n}.size !== ${ft(u.size,"size_equals")}) return INVALID;`);break;case"string_format":n=Cf(e,r,u,n);break;case"custom":n=f$(e,r,a,n);break;case"bigint_format":c$(e,u,n);break;case"mime_type":s$(e,r,u,n);break;case"property":d$(e,r,u,n);break;case"properties":l$(e,r,u,n);break;case"overwrite":{let c=D(r);m$(e,r,a,n,c),n=c;break}default:throw new Z(`check type ${u.check}`)}}return n}function Tc(e,r,i,o){let t=A(r,st),n=D(r);return e.write(`const ${n} = typeof ${i} === "string" && ${o} ? ${t}(${i}) : ${i}.length;`),n}function ft(e,r){if(typeof e!="number"||!Number.isFinite(e))throw new Z(`${r} bound of type ${typeof e}`);return`${e}`}function Uf(e,r){if(typeof r=="bigint")return`${r}n`;if(typeof r=="number"){if(Number.isNaN(r))throw new Z("comparison check with NaN bound");return`${r}`}if(r instanceof Date){if(Number.isNaN(r.getTime()))throw new Z("comparison check with Invalid Date bound");return A(e,r)}throw new Z(`comparison check bound of type ${typeof r}`)}function o$(e,r,i,o){let t=i.inclusive?"<":"<=";e.write(`if (${o} ${t} ${Uf(r,i.value)}) return INVALID;`)}function a$(e,r,i,o){let t=i.inclusive?">":">=";e.write(`if (${o} ${t} ${Uf(r,i.value)}) return INVALID;`)}function u$(e,r,i,o){if(typeof i.value=="bigint"){if(i.value===BigInt(0))throw new Z("multiple_of check with a zero divisor");e.write(`if (${o} % ${i.value}n !== 0n) return INVALID;`)}else{let t=A(r,br);e.write(`if (${t}(${o}, ${ft(i.value,"multiple_of")}) !== 0) return INVALID;`)}}function Ef(e,r,i){let o=r.format;switch(o){case"safeint":e.write(`if (!Number.isSafeInteger(${i})) return INVALID;`);break;case"int32":e.write(`if (!Number.isInteger(${i}) || ${i} < -2147483648 || ${i} > 2147483647) return INVALID;`);break;case"uint32":e.write(`if (!Number.isInteger(${i}) || ${i} < 0 || ${i} > 4294967295) return INVALID;`);break;case"float32":e.write(`if (!Number.isFinite(${i}) || ${i} < -3.4028234663852886e38 || ${i} > 3.4028234663852886e38) return INVALID;`);break;case"float64":e.write(`if (!Number.isFinite(${i})) return INVALID;`);break;default:throw new Z(`number format ${o}`)}}function c$(e,r,i){let o=r.format;if(o)switch(o){case"int64":e.write(`if (${i} < -9223372036854775808n || ${i} > 9223372036854775807n) return INVALID;`);break;case"uint64":e.write(`if (${i} < 0n || ${i} > 18446744073709551615n) return INVALID;`);break;default:throw new Z(`bigint format ${o}`)}}function s$(e,r,i,o){let t=i.mime;if(t&&t.length>0){let n=A(r,new Set(t));e.write(`if (!${n}.has(${o}.type)) return INVALID;`)}}function l$(e,r,i,o){if(i.when)throw new Z('check with a custom "when" condition');e.write(`if (${o} == null) return INVALID;`);let t=i.shape;for(let n of Reflect.ownKeys(t)){let a=typeof n=="symbol"?A(r,n):ce(n),u=D(r);e.write(`const ${u} = ${o}[${a}];`),ie(e,r,t[n],u,!1)}}function d$(e,r,i,o){let t=`${o}[${JSON.stringify(i.property)}]`;W(e,r,i.schema,t)}function m$(e,r,i,o,t){let n=i._zod.def.tx;if(!n)throw new Z("overwrite check without a transform function");if(vt(n))throw new Te("z.compile: async overwrite transforms are not supported");let a=A(r,n);e.write(`const ${t} = ${a}(${o});`)}function Oc(){throw new be}function Ac(e){this.issues.push(e)}function f$(e,r,i,o){let t=i._zod.def;if(t.fn){if(vt(t.fn))throw new Te("z.compile: async .refine() predicates are not supported");let n=gt(r,t.fn),a=A(r,Oc),u=D(r);return e.write(`const ${u} = ${n}(${o});`),e.write(`if (${u} instanceof Promise) ${a}();`),e.write(`if (!${u}) return INVALID;`),o}if(i._zod.check){if(vt(i._zod.check))throw new Te("z.compile: async .superRefine() / check functions are not supported");let n=i._zod.check,u=gt(r,s=>{let d={value:s,issues:[],addIssue:Ac};return n(d)instanceof Promise&&Oc(),d.issues.length===0?d.value:le}),c=D(r);return e.write(`const ${c} = ${u}(${o});`),e.write(`if (${c} === INVALID) return INVALID;`),c}throw new Z("custom check without a predicate or check function")}var p$=new Set(["cidrv4","cuid","cuid2","date","datetime","duration","e164","email","emoji","ends_with","guid","includes","ipv4","ksuid","lowercase","mac","nanoid","regex","starts_with","time","ulid","uppercase","uuid","xid"]);function Cf(e,r,i,o,t=!0){let n=i.format;if(n==="base64"){let s=A(r,Cr);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(n==="base64url"){let s=A(r,ci);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(n==="jwt"){let s=A(r,di),d=A(r,i.alg??null);return e.write(`if (!${s}(${o}, ${d})) return INVALID;`),o}if(n==="ipv6"){let s=A(r,Er);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(n==="cidrv6"){let s=A(r,ai);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(n==="credit_card"){let s=A(r,si);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(n==="iban"){let s=A(r,li);return e.write(`if (!${s}(${o})) return INVALID;`),o}let a=i;if(n==="url"||n==="httpurl"||a.normalize||a.hostname!==void 0||a.protocol!==void 0){let s=A(r,ni),d=A(r,i),m=D(r),p=D(r);if(e.write(`const ${m} = ${o}.trim();`),e.write(`const ${p} = ${s}(${m}, ${d});`),e.write(`if (typeof ${p} === "number") return INVALID;`),a.hostname!==void 0){let w=A(r,ii);e.write(`if (!${w}(${p}, ${d}.hostname)) return INVALID;`)}if(a.protocol!==void 0){let w=A(r,oi);e.write(`if (!${w}(${p}, ${d}.protocol)) return INVALID;`)}if(!t)return null;let f=D(r),h=a.normalize?`${p}.href`:`${A(r,Ur)}(${m})`;return e.write(`const ${f} = ${h};`),f}let u=i.fn;if(u){if(vt(u))throw new Z(`async string format ${n}`);let s=A(r,u);return e.write(`if (!${s}(${o})) return INVALID;`),o}if(p$.has(n)&&i.pattern){let s=A(r,i.pattern);return e.write(`${s}.lastIndex = 0;`),e.write(`if (!${s}.test(${o})) return INVALID;`),o}let c=i.format;switch(c){case"regex":throw new Z("regex format without a pattern");case"lowercase":e.write(`if (${o} !== ${o}.toLowerCase()) return INVALID;`);break;case"uppercase":e.write(`if (${o} !== ${o}.toUpperCase()) return INVALID;`);break;case"includes":e.write(`if (!${o}.includes(${ce(i.includes)})) return INVALID;`);break;case"starts_with":{let s=i.prefix;e.write(`if (${o}.slice(0, ${s.length}) !== ${ce(s)}) return INVALID;`);break}case"ends_with":{let s=i.suffix;e.write(`if (${o}.slice(-${s.length}) !== ${ce(s)}) return INVALID;`);break}default:throw new Z(`string format ${c}`)}return o}function W(e,r,i,o,t=!0){let n=i._zod.def,a=n.type;if(n.coerce)throw new Z(`coercion (z.coerce.${a}())`);let u=t||!!n.checks?.length,c;switch(a){case"string":c=g$(e,r,i,o,u);break;case"number":c=v$(e,i,o);break;case"boolean":c=h$(e,o);break;case"bigint":c=b$(e,i,o);break;case"symbol":c=$$(e,o);break;case"undefined":c=y$(e,o);break;case"null":c=_$(e,o);break;case"any":case"unknown":c=o;break;case"never":e.write("return INVALID;"),c=o;break;case"void":c=w$(e,o);break;case"nan":c=x$(e,o);break;case"date":c=k$(e,o);break;case"object":c=I$(e,r,i,o,u);break;case"optional":c=S$(e,r,i,o,u);break;case"nullable":c=T$(e,r,i,o,u);break;case"array":c=O$(e,r,i,o,u);break;case"literal":c=D$(e,r,i,o);break;case"enum":c=j$(e,r,i,o);break;case"readonly":{let s=jf(e,r,i,o),d=D(r);e.write(`const ${d} = Object.freeze(${s});`),c=d;break}case"success":jf(e,r,i,o),c="true";break;case"default":case"prefault":c=A$(e,r,i,o);break;case"nonoptional":c=N$(e,r,i,o);break;case"tuple":c=U$(e,r,i,o);break;case"union":c=E$(e,r,i,o);break;case"intersection":c=R$(e,r,i,o);break;case"record":c=L$(e,r,i,o);break;case"map":c=M$(e,r,i,o);break;case"set":c=F$(e,r,i,o);break;case"file":c=G$(e,o);break;case"template_literal":c=B$(e,r,i,o);break;case"lazy":c=J$(e,r,i,o);break;case"pipe":c=W$(e,r,i,o);break;case"custom":c=K$(e,r,i,o);break;case"transform":c=q$(e,r,i,o);break;case"catch":c=H$(e,r,i,o);break;default:throw new Z(`schema type ${a}`)}return c===null?null:i$(e,r,i,c)}function g$(e,r,i,o,t=!0){e.write(`if (typeof ${o} !== "string") return INVALID;`);let n=i._zod.def;return n.format===void 0?o:Cf(e,r,n,o,t)}function v$(e,r,i){e.write(`if (typeof ${i} !== "number" || !Number.isFinite(${i})) return INVALID;`);let o=r._zod.def;return o.check==="number_format"&&o.format&&Ef(e,{format:o.format},i),i}function h$(e,r){return e.write(`if (typeof ${r} !== "boolean") return INVALID;`),r}function b$(e,r,i){e.write(`if (typeof ${i} !== "bigint") return INVALID;`);let o=r._zod.def;if(o.format)switch(o.format){case"int64":e.write(`if (${i} < -9223372036854775808n || ${i} > 9223372036854775807n) return INVALID;`);break;case"uint64":e.write(`if (${i} < 0n || ${i} > 18446744073709551615n) return INVALID;`);break}return i}function $$(e,r){return e.write(`if (typeof ${r} !== "symbol") return INVALID;`),r}function y$(e,r){return e.write(`if (${r} !== undefined) return INVALID;`),r}function _$(e,r){return e.write(`if (${r} !== null) return INVALID;`),r}function w$(e,r){return e.write(`if (${r} !== undefined) return INVALID;`),r}function x$(e,r){return e.write(`if (typeof ${r} !== "number" || !Number.isNaN(${r})) return INVALID;`),r}function k$(e,r){return e.write(`if (!(${r} instanceof Date) || Number.isNaN(${r}.getTime())) return INVALID;`),r}function I$(e,r,i,o,t=!0){let n=i._zod.def;e.write(`if (typeof ${o} !== "object" || ${o} === null || Array.isArray(${o})) return INVALID;`);let a=n.shape,u=Object.keys(a),c=Object.getOwnPropertySymbols(a),s=c.length?[...u,...c]:u,d=S=>typeof S=="symbol"?A(r,S):ce(S),m=S=>typeof S=="symbol"?`[${d(S)}]`:ce(S),p=a;if(u.includes("__proto__"))throw new Z('object shape key "__proto__"');let f=new Map;for(let S of s){let j=p[S],O=d(S),U=D(r);if(e.write(`const ${U} = ${o}[${O}];`),j._zod.optin!==void 0){let T=D(r);e.write(`let ${T} = (() => {`),e.indented(F=>{let ae=ie(F,r,j,U);F.write(`return ${ae};`)}),e.write("})();"),j._zod.optout==="optional"?(e.write(`if (${T} === INVALID) {`),e.indented(F=>{F.write(`if (${O} in ${o}) return INVALID;`),F.write(`${T} = undefined;`)}),e.write("}")):e.write(`if (${T} === INVALID) return INVALID;`),f.set(S,T)}else{P$(j)&&e.write(`if (!(${O} in ${o})) return INVALID;`);let T=ie(e,r,j,U,t);T!==null&&f.set(S,T)}}let h=n.catchall,w="none";if(h){let S=h._zod.def.type;if(S==="never"){let j=u.map(O=>`k !== ${ce(O)}`).join(" && ")||"true";e.write(`for (const k in ${o}) {`),e.indented(O=>{O.write(`if (${j}) return INVALID;`)}),e.write("}")}else(S==="unknown"||S==="any")&&!h._zod.def.checks?.length?w="passthrough":w="schema"}let x=D(r),P=s.some(S=>Df(p[S])||Dc(p[S]));if(!t){if(w==="schema"){let S=u.length>0?A(r,new Set(u)):null;e.write(`for (const k in ${o}) {`),e.indented(j=>{j.write('if (k === "__proto__") continue;'),S&&j.write(`if (${S}.has(k)) continue;`);let O=D(r);j.write(`const ${O} = ${o}[k];`),ie(j,r,h,O,!1)}),e.write("}")}return null}if(P){e.write(`const ${x} = {};`);for(let S of s){let j=d(S),O=f.get(S);Dc(p[S])?e.write(`if (${j} in ${o}) ${x}[${j}] = ${O};`):Df(p[S])?e.write(`if (${O} !== undefined || ${j} in ${o}) ${x}[${j}] = ${O};`):e.write(`${x}[${j}] = ${O};`)}}else{let S=s.map(j=>`${m(j)}: ${f.get(j)}`).join(", ");e.write(`const ${x} = { ${S} };`)}if(w!=="none"){let S=u.length>0?A(r,new Set(u)):null;e.write(`for (const k in ${o}) {`),e.indented(j=>{if(j.write('if (k === "__proto__") continue;'),S&&j.write(`if (${S}.has(k)) continue;`),w==="passthrough")j.write(`${x}[k] = ${o}[k];`);else{let O=D(r);j.write(`const ${O} = ${o}[k];`);let U=ie(j,r,h,O);j.write(`${x}[k] = ${U};`)}}),e.write("}")}return x}function S$(e,r,i,o,t=!0){let n=i._zod.def;if(z$(i))return W(e,r,n.innerType,o,t);if(n.innerType._zod.optin==="defaulted"){let u=D(r),c=D(r);return e.write(`let ${u};`),e.write(`if (${o} === undefined) {`),e.indented(s=>{s.write(`const ${c} = (() => {`),s.indented(d=>{let m=W(d,r,n.innerType,o);d.write(`return ${m};`)}),s.write("})();"),s.write(`if (${c} !== INVALID) ${u} = ${c};`)}),e.write("} else {"),e.indented(s=>{let d=W(s,r,n.innerType,o);s.write(`${u} = ${d};`)}),e.write("}"),u}let a=t?D(r):null;return a&&e.write(`let ${a};`),e.write(`if (${o} !== undefined) {`),e.indented(u=>{let c=W(u,r,n.innerType,o,t);a&&c!==null&&u.write(`${a} = ${c};`)}),e.write("}"),a}function z$(e){return e._zod.traits?.has("$ZodExactOptional")===!0}function P$(e){return e._zod.optin===void 0&&pt(e)}function pt(e){if(e._zod.def.coerce)return!0;let r=e._zod.def;switch(r.type){case"any":case"unknown":case"undefined":case"void":case"default":case"prefault":case"transform":case"custom":case"lazy":return!0;case"string":case"number":case"boolean":case"bigint":case"symbol":case"null":case"never":case"nan":case"date":case"object":case"array":case"tuple":case"record":case"map":case"set":case"file":case"template_literal":return!1;case"nonoptional":return r.innerType?pt(r.innerType):!1;case"literal":return!!r.values?.includes(void 0);case"enum":return!!e._zod.values?.has(void 0);case"optional":case"nullable":case"readonly":case"success":return r.innerType?pt(r.innerType):!0;case"catch":return!0;case"union":return r.options?r.options.some(pt):!0;case"intersection":return!r.left||!r.right?!0:pt(r.left)&&pt(r.right);case"pipe":return r.in?pt(r.in):!0;default:return!0}}function Dc(e){return e._zod.optin==="optional"&&e._zod.optout==="optional"}function Df(e){return(e._zod.optin!=="defaulted"||e._zod.optout==="optional")&&Lt(e)}function Lt(e){let r=e._zod.def;switch(r.type){case"string":case"number":case"boolean":case"bigint":case"symbol":case"null":case"nan":case"date":case"object":case"array":case"tuple":case"record":case"map":case"set":case"file":case"template_literal":case"never":case"success":return!1;case"literal":return!!r.values?.includes(void 0);case"enum":return!!e._zod.values?.has(void 0);case"optional":return!0;case"nullable":case"readonly":case"nonoptional":return r.innerType?Lt(r.innerType):!0;case"union":return r.options?r.options.some(Lt):!0;case"intersection":return!r.left||!r.right||Lt(r.left)||Lt(r.right);case"pipe":return r.out?Lt(r.out):!0;default:return!0}}function T$(e,r,i,o,t=!0){let n=i._zod.def,a=t?D(r):null;return a&&e.write(`let ${a} = null;`),e.write(`if (${o} !== null) {`),e.indented(u=>{let c=W(u,r,n.innerType,o,t);a&&c!==null&&u.write(`${a} = ${c};`)}),e.write("}"),a}function O$(e,r,i,o,t=!0){let n=i._zod.def;e.write(`if (!Array.isArray(${o})) return INVALID;`);let a=t?D(r):null,u=D(r),c=D(r);return a&&e.write(`const ${a} = new Array(${o}.length);`),e.write(`for (let ${u} = 0; ${u} < ${o}.length; ${u}++) {`),e.indented(s=>{s.write(`const ${c} = ${o}[${u}];`);let d=ie(s,r,n.element,c,t);a&&d!==null&&s.write(`${a}[${u}] = ${d};`)}),e.write("}"),a}function D$(e,r,i,o){let n=i._zod.def.values;if(n.length!==1){let u=A(r,new Set(n));return e.write(`if (!${u}.has(${o})) return INVALID;`),o}let a=n[0];if(typeof a=="number"&&Number.isNaN(a)){let u=A(r,new Set(n));return e.write(`if (!${u}.has(${o})) return INVALID;`),o}if(typeof a=="string")e.write(`if (${o} !== ${ce(a)}) return INVALID;`);else if(typeof a=="number"||typeof a=="boolean")e.write(`if (${o} !== ${a}) return INVALID;`);else if(a===null)e.write(`if (${o} !== null) return INVALID;`);else if(a===void 0)e.write(`if (${o} !== undefined) return INVALID;`);else if(typeof a=="bigint")e.write(`if (${o} !== ${a}n) return INVALID;`);else throw new Z(`literal type ${typeof a}`);return o}function j$(e,r,i,o){let t=i._zod.values;if(!t)throw new Z("enum schema without enumerated values");let n=A(r,t);return e.write(`if (!${n}.has(${o})) return INVALID;`),o}function jf(e,r,i,o){let t=i._zod.def;return W(e,r,t.innerType,o)}function A$(e,r,i,o){let t=i._zod.def,a=Object.getOwnPropertyDescriptor(i._zod.def,"defaultValue")?()=>i._zod.def.defaultValue:void 0;if(i._zod.def.type==="prefault"){if(!a)return W(e,r,t.innerType,o);let c=A(r,a),s=D(r);return e.write(`let ${s} = ${o};`),e.write(`if (${o} === undefined) ${s} = ${c}();`),W(e,r,t.innerType,s)}let u=D(r);if(a){let c=A(r,a),s=A(r,$r);e.write(`let ${u};`),e.write(`if (${o} === undefined) {`),e.indented(d=>{d.write(`${u} = ${s}(${c}());`)}),e.write("} else {"),e.indented(d=>{let m=W(d,r,t.innerType,o);d.write(`${u} = ${m} === undefined ? ${s}(${c}()) : ${m};`)}),e.write("}")}else e.write(`let ${u};`),e.write(`if (${o} !== undefined) {`),e.indented(c=>{let s=W(c,r,t.innerType,o);c.write(`${u} = ${s};`)}),e.write("}");return u}function N$(e,r,i,o){let t=i._zod.def,n=W(e,r,t.innerType,o),a=D(r);return e.write(`const ${a} = ${n};`),e.write(`if (${a} === undefined) return INVALID;`),a}function U$(e,r,i,o){let t=i._zod.def,n=t.items,a=t.rest;e.write(`if (!Array.isArray(${o})) return INVALID;`);let u=Af(n,"optin"),c=Af(n,"optout");a?e.write(`if (${o}.length < ${u}) return INVALID;`):e.write(`if (${o}.length < ${u} || ${o}.length > ${n.length}) return INVALID;`);let s=D(r);e.write(`const ${s} = [];`);for(let d=0;d<n.length;d++){let m=n[d];if(d>=c)e.write(`if (${s}.length === ${d}) {`),e.indented(p=>{p.write(`if (${d} < ${o}.length) {`),p.indented(f=>{let h=D(r);f.write(`const ${h} = ${o}[${d}];`);let w=ie(f,r,m,h);f.write(`${s}[${d}] = ${w};`)}),p.write("} else {"),p.indented(f=>{if(Dc(m)){f.write(`${s}.length = ${d};`);return}let h=D(r),w=D(r);f.write(`const ${h} = undefined;`),f.write(`const ${w} = (() => {`),f.indented(x=>{let P=ie(x,r,m,h);x.write(`return ${P};`)}),f.write("})();"),f.write(`if (${w} === INVALID || ${w} === undefined) ${s}.length = ${d};`),f.write(`else ${s}[${d}] = ${w};`)}),p.write("}")}),e.write("}");else{let p=D(r);e.write(`const ${p} = ${o}[${d}];`);let f=ie(e,r,m,p);e.write(`${s}[${d}] = ${f};`)}}if(a){let d=D(r),m=D(r);e.write(`for (let ${d} = ${n.length}; ${d} < ${o}.length; ${d}++) {`),e.indented(p=>{p.write(`const ${m} = ${o}[${d}];`);let f=ie(p,r,a,m);p.write(`${s}[${d}] = ${f};`)}),e.write("}")}return s}function Af(e,r){for(let i=e.length-1;i>=0;i--)if(!(r==="optin"?e[i]._zod.optin!==void 0:e[i]._zod.optout==="optional"))return i+1;return 0}function E$(e,r,i,o){let t=i._zod.def,n=t.options;if(t.discriminator)return C$(e,r,t,o);if(t.inclusive===!1)throw new Z("exclusive unions (z.xor)");if(n.length===0)return e.write("return INVALID;"),o;if(n.length===1)return W(e,r,n[0],o);if(n.every(c=>c._zod.def.type==="literal"&&!c._zod.def.checks?.length)){let c=new Set(n.flatMap(d=>d._zod.def.values)),s=A(r,c);return e.write(`if (!${s}.has(${o})) return INVALID;`),o}let u=D(r);e.write(`let ${u};`);for(let c=0;c<n.length;c++){let s=n[c];c===0?e.write(`${u} = (() => {`):e.write(`if (${u} === INVALID) ${u} = (() => {`),e.indented(d=>{let m=W(d,r,s,o);d.write(`return ${m};`)}),e.write("})();")}return e.write(`if (${u} === INVALID) return INVALID;`),u}function C$(e,r,i,o){if(i.unionFallback)throw new Z("discriminated union with unionFallback");if(i.options.length===0)return e.write("return INVALID;"),o;let t=D(r),n=D(r);e.write(`const ${t} = ${o}?.[${ce(i.discriminator)}];`),e.write(`let ${n};`);let a=!0,u=new Set;for(let c of i.options){let s=c._zod.propValues?.[i.discriminator];if(!s||s.size===0)throw new Z("discriminated union option without static discriminator values");for(let p of s){if(u.has(p))throw new Z(`duplicate discriminator value ${String(p)}`);u.add(p)}let d=Array.from(s,p=>Z$(r,t,p)),m=a?"if":"else if";e.write(`${m} (${d.join(" || ")}) {`),e.indented(p=>{let f=W(p,r,c,o);p.write(`${n} = ${f};`)}),e.write("}"),a=!1}return e.write("else { return INVALID; }"),n}function Z$(e,r,i){if(typeof i=="string")return`${r} === ${ce(i)}`;if(typeof i=="number")return Number.isNaN(i)?`Number.isNaN(${r})`:`${r} === ${i}`;if(typeof i=="boolean")return`${r} === ${i}`;if(i===null)return`${r} === null`;if(i===void 0)return`${r} === undefined`;if(typeof i=="bigint")return`${r} === ${i}n`;if(typeof i=="symbol"){let o=A(e,i);return`${r} === ${o}`}throw new Z(`literal discriminator value ${String(i)}`)}function R$(e,r,i,o){let t=i._zod.def;r.definite=!1;let n=ie(e,r,t.left,o),a=ie(e,r,t.right,o),u=A(r,Ct),c=D(r);return e.write(`const ${c} = ${u}(${n}, ${a});`),e.write(`if (!${c}.valid) return INVALID;`),`${c}.data`}function L$(e,r,i,o){let t=i._zod.def,n=A(r,ke);e.write(`if (!${n}(${o})) return INVALID;`);let a=D(r),u=D(r),c=D(r);e.write(`const ${a} = {};`);let s=t,d=s.partial?void 0:t.keyType._zod.values;if(d){let f=[];for(let w of d){if(!(typeof w=="string"||typeof w=="number"||typeof w=="symbol"))throw new Z(`record key value ${String(w)}`);let x=typeof w=="number"?w.toString():w;if(x==="__proto__")throw new Z('record key "__proto__"');f.push(x);let P=A(r,w),S=W(e,r,t.keyType,P),j=D(r);e.write(`const ${j} = ${o}[${V$(r,x)}];`);let O=ie(e,r,t.valueType,j);e.write(`${a}[${S}] = ${O};`)}let h=A(r,new Set(f));return e.write(`for (const ${u} in ${o}) {`),e.indented(w=>{w.write(`if (${h}.has(${u})) continue;`),s.mode==="loose"?w.write(`if (${u} !== "__proto__") ${a}[${u}] = ${o}[${u}];`):w.write("return INVALID;")}),e.write("}"),a}let m=t.keyType._zod.def;if(!(m.type==="string"&&m.format===void 0&&!m.coerce&&(m.checks?.length??0)===0)){let f=t.mode==="loose",h=Ti(t.keyType);h.definite===!1&&(r.definite=!1);let w=A(r,h),x=A(r,Fe),P=D(r);return Nf(e,r,o,u,S=>{S.write(`let ${P} = ${w}(${u});`),S.write(`if (${P} === INVALID && typeof ${u} === "string" && ${x}.test(${u})) ${P} = ${w}(Number(${u}));`),f?S.write(`if (${P} === INVALID) { ${a}[${u}] = ${o}[${u}]; continue; }`):S.write(`if (${P} === INVALID) return INVALID;`),S.write(`if (${P} === "__proto__") continue;`);let j=D(r);S.write(`const ${j} = ${o}[${u}];`);let O=ie(S,r,t.valueType,j);S.write(`${a}[${P}] = ${O};`)}),a}return Nf(e,r,o,u,f=>{f.write(`const ${c} = ${o}[${u}];`);let h=ie(f,r,t.valueType,c);f.write(`${a}[${u}] = ${h};`)},"return INVALID;"),a}function Nf(e,r,i,o,t,n){let a=A(r,Object.prototype.propertyIsEnumerable),u=D(r),c=D(r),s=D(r);e.write(`const ${u} = Object.getOwnPropertySymbols(${i});`),e.write(`const ${c} = Object.getOwnPropertyNames(${i});`),e.write(`for (let ${s} = 0; ${s} < ${c}.length; ${s}++) {`),e.indented(d=>{d.write(`const ${o} = ${c}[${s}];`),d.write(`if (${o} === "__proto__" || !${a}.call(${i}, ${o})) continue;`),t(d)}),e.write("}"),e.write(`for (let ${s} = 0; ${s} < ${u}.length; ${s}++) {`),e.indented(d=>{d.write(`const ${o} = ${u}[${s}];`),d.write(`if (!${a}.call(${i}, ${o})) continue;`),n?d.write(n):t(d)}),e.write("}")}function V$(e,r){return typeof r=="string"?ce(r):A(e,r)}function M$(e,r,i,o){let t=i._zod.def;e.write(`if (!(${o} instanceof Map)) return INVALID;`);let n=D(r),a=D(r),u=D(r);return e.write(`const ${n} = new Map();`),e.write(`for (const [${a}, ${u}] of ${o}) {`),e.indented(c=>{let s=W(c,r,t.keyType,a),d=W(c,r,t.valueType,u);c.write(`${n}.set(${s}, ${d});`)}),e.write("}"),n}function F$(e,r,i,o){let t=i._zod.def;e.write(`if (!(${o} instanceof Set)) return INVALID;`);let n=D(r),a=D(r);return e.write(`const ${n} = new Set();`),e.write(`for (const ${a} of ${o}) {`),e.indented(u=>{let c=W(u,r,t.valueType,a);u.write(`${n}.add(${c});`)}),e.write("}"),n}function G$(e,r){return e.write(`if (!(${r} instanceof File)) return INVALID;`),r}function B$(e,r,i,o){e.write(`if (typeof ${o} !== "string") return INVALID;`);let t=i._zod.pattern;if(t){let n=A(r,t);e.write(`${n}.lastIndex = 0;`),e.write(`if (!${n}.test(${o})) return INVALID;`)}return o}function J$(e,r,i,o){let t=i._zod.def,n=gt(r,t.getter),a=A(r,{parser:null});e.write(`if (!${a}.parser) {`),e.indented(c=>{c.write(`const inner = ${n}();`),c.write(`${a}.parser = function(input) {`),c.indented(s=>{s.write("const result = inner._zod.run({ value: input, issues: [] }, {});"),s.write("return result.issues.length === 0 ? result.value : INVALID;")}),c.write("};")}),e.write("}");let u=D(r);return e.write(`const ${u} = ${a}.parser(${o});`),e.write(`if (${u} === INVALID) return INVALID;`),u}function W$(e,r,i,o){let t=i._zod.def,n=W(e,r,t.in,o);if(t.transform){if(vt(t.transform))throw new Te("z.compile: async transforms in pipes are not supported");let a=t.transform,c=gt(r,d=>{let m={value:d,issues:[],addIssue:Ac},p=a(d,m);return p instanceof Promise?le:m.issues.length===0?p:le}),s=D(r);return e.write(`const ${s} = ${c}(${n});`),e.write(`if (${s} === INVALID) return INVALID;`),W(e,r,t.out,s)}else return W(e,r,t.out,n)}function vt(e){return typeof e=="function"&&(e.constructor.name==="AsyncFunction"||e[Symbol.toStringTag]==="AsyncFunction")}function K$(e,r,i,o){let t=i._zod.def;if(t.fn){if(vt(t.fn))throw new Te("z.compile: async custom predicates are not supported");let n=gt(r,t.fn),a=A(r,Oc),u=D(r);e.write(`const ${u} = ${n}(${o});`),e.write(`if (${u} instanceof Promise) ${a}();`),e.write(`if (!${u}) return INVALID;`)}else throw new Z("custom schema without a predicate function");return o}function X$(e,r,i){let o=e._zod.run({value:i,issues:[]},{});if(o&&typeof o.then=="function")return le;let t=o;return t.issues.length===0?t.value:r()}function H$(e,r,i,o){let t=i._zod.def;if(!t.catchValue[Nn])throw new Z("catch with a callback (only a constant catch value compiles)",!1);let n=D(r);e.write(`let ${n} = (() => {`),e.indented(s=>{let d=ie(s,r,t.innerType,o);s.write(`return ${d};`)}),e.write("})();");let a=A(r,t.innerType),u=gt(r,t.catchValue),c=A(r,X$);return e.write(`if (${n} === INVALID) {`),e.indented(s=>{s.write(`${n} = ${c}(${a}, ${u}, ${o});`),s.write(`if (${n} === INVALID) return INVALID;`)}),e.write("}"),n}function q$(e,r,i,o){let t=i._zod.def;if(t.transform){if(vt(t.transform))throw new Te("z.compile: async transforms are not supported");let n=t.transform,u=gt(r,s=>{let d={value:s,issues:[],addIssue:Ac},m=n(s,d);return m instanceof Promise?le:d.issues.length===0?m:le}),c=D(r);return e.write(`const ${c} = ${u}(${o});`),e.write(`if (${c} === INVALID) return INVALID;`),c}return o}function Oi(e){return e.checks&&(e.checks=[...e.checks]),e}function Nc(e,r){return new e(Oi({type:"string",...I(r)}))}function Uc(e,r){return new e(Oi({type:"string",coerce:!0,...I(r)}))}function Di(e,r){return new e({type:"string",format:"email",check:"string_format",abort:!1,...I(r)})}function ji(e,r){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...I(r)})}function Ai(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...I(r)})}function Ni(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...I(r)})}function Ui(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...I(r)})}function Ei(e,r){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...I(r)})}function Kr(e,r){return new e({type:"string",format:"url",check:"string_format",abort:!1,...I(r)})}function Ci(e,r){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...I(r)})}function Zi(e,r){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...I(r)})}function Ri(e,r){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...I(r)})}function Li(e,r){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...I(r)})}function Vi(e,r){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...I(r)})}function Mi(e,r){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...I(r)})}function Fi(e,r){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...I(r)})}function Gi(e,r){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...I(r)})}function Bi(e,r){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...I(r)})}function Ec(e,r){return new e({type:"string",format:"mac",check:"string_format",abort:!1,...I(r)})}function Ji(e,r){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...I(r)})}function Wi(e,r){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...I(r)})}function Ki(e,r){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...I(r)})}function Xi(e,r){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...I(r)})}function Hi(e,r){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...I(r)})}function Cc(e,r){return new e({type:"string",format:"credit_card",check:"string_format",abort:!1,...I(r)})}function Zc(e,r){return new e({type:"string",format:"iban",check:"string_format",abort:!1,...I(r)})}function qi(e,r){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...I(r)})}var Rc={Any:null,Minute:-1,Second:0,Millisecond:3,Microsecond:6};function Xr(e,r){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...I(r)})}function Hr(e,r){return new e({type:"string",format:"date",check:"string_format",...I(r)})}function qr(e,r){return new e({type:"string",format:"time",check:"string_format",precision:null,...I(r)})}function Yr(e,r){return new e({type:"string",format:"duration",check:"string_format",...I(r)})}function Lc(e,r){return new e(Oi({type:"number",checks:[],...I(r)}))}function Vc(e,r){return new e(Oi({type:"number",coerce:!0,checks:[],...I(r)}))}function Mc(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...I(r)})}function Fc(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"float32",...I(r)})}function Gc(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"float64",...I(r)})}function Bc(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"int32",...I(r)})}function Jc(e,r){return new e({type:"number",check:"number_format",abort:!1,format:"uint32",...I(r)})}function Wc(e,r){return new e({type:"boolean",...I(r)})}function Kc(e,r){return new e({type:"boolean",coerce:!0,...I(r)})}function Xc(e,r){return new e({type:"bigint",...I(r)})}function Hc(e,r){return new e({type:"bigint",coerce:!0,...I(r)})}function qc(e,r){return new e({type:"bigint",check:"bigint_format",abort:!1,format:"int64",...I(r)})}function Yc(e,r){return new e({type:"bigint",check:"bigint_format",abort:!1,format:"uint64",...I(r)})}function Qc(e,r){return new e({type:"symbol",...I(r)})}function es(e,r){return new e({type:"undefined",...I(r)})}function ts(e,r){return new e({type:"null",...I(r)})}function rs(e){return new e({type:"any"})}function ns(e){return new e({type:"unknown"})}function is(e,r){return new e({type:"never",...I(r)})}function os(e,r){return new e({type:"void",...I(r)})}function as(e,r){return new e({type:"date",...I(r)})}function us(e,r){return new e({type:"date",coerce:!0,...I(r)})}function cs(e,r){return new e({type:"nan",...I(r)})}function Ae(e,r){return new Hn({check:"less_than",...I(r),value:e,inclusive:!1})}function we(e,r){return new Hn({check:"less_than",...I(r),value:e,inclusive:!0})}function Ne(e,r){return new qn({check:"greater_than",...I(r),value:e,inclusive:!1})}function xe(e,r){return new qn({check:"greater_than",...I(r),value:e,inclusive:!0})}function Yi(e){return Ne(0,e)}function Qi(e){return Ae(0,e)}function eo(e){return we(0,e)}function to(e){return xe(0,e)}function qe(e,r){return new Ja({check:"multiple_of",...I(r),value:e})}function Ye(e,r){return new Xa({check:"max_size",...I(r),maximum:e})}function Ue(e,r){return new Ha({check:"min_size",...I(r),minimum:e})}function ht(e,r){return new qa({check:"size_equals",...I(r),size:e})}function bt(e,r){return new Ya({check:"max_length",...I(r),maximum:e})}function Ge(e,r){return new Qa({check:"min_length",...I(r),minimum:e})}function $t(e,r){return new eu({check:"length_equals",...I(r),length:e})}function Vt(e,r){return new tu({check:"string_format",format:"regex",...I(r),pattern:e})}function Mt(e){return new ru({check:"string_format",format:"lowercase",...I(e)})}function Ft(e){return new nu({check:"string_format",format:"uppercase",...I(e)})}function Gt(e,r){return new iu({check:"string_format",format:"includes",...I(r),includes:e})}function Bt(e,r){return new ou({check:"string_format",format:"starts_with",...I(r),prefix:e})}function Jt(e,r){return new au({check:"string_format",format:"ends_with",...I(r),suffix:e})}function ro(e,r,i){return new uu({check:"property",property:e,schema:r,...I(i)})}function Wt(e,r){return new cu({check:"properties",shape:e,...I(r)})}function Kt(e,r){return new su({check:"mime_type",mime:e,...I(r)})}function Oe(e){return new lu({check:"overwrite",tx:e})}function Xt(e){return Oe(r=>r.normalize(e))}function Ht(){return Oe(e=>e.trim())}function qt(){return Oe(e=>e.toLowerCase())}function Yt(){return Oe(e=>e.toUpperCase())}function Qt(){return Oe(e=>Ko(e))}function ss(e,r,i){return new e({type:"array",element:r,...I(i)})}function Y$(e,r,i){return new e({type:"union",options:r,...I(i)})}function Q$(e,r,i){return new e({type:"union",options:r,inclusive:!1,...I(i)})}function ey(e,r,i,o){return new e({type:"union",options:i,discriminator:r,...I(o)})}function ty(e,r,i){return new e({type:"intersection",left:r,right:i})}function ry(e,r,i,o){let t=i instanceof N,n=t?o:i,a=t?i:null;return new e({type:"tuple",items:r,rest:a,...I(n)})}function ny(e,r,i,o){return new e({type:"record",keyType:r,valueType:i,...I(o)})}function iy(e,r,i,o){return new e({type:"map",keyType:r,valueType:i,...I(o)})}function oy(e,r,i){return new e({type:"set",valueType:r,...I(i)})}function ay(e,r,i){let o=Array.isArray(r)?Object.fromEntries(r.map(t=>[t,t])):r;return new e({type:"enum",entries:o,...I(i)})}function uy(e,r,i){return new e({type:"enum",entries:r,...I(i)})}function cy(e,r,i){return new e({type:"literal",values:Array.isArray(r)?r:[r],...I(i)})}function ls(e,r){return new e({type:"file",...I(r)})}function sy(e,r){return new e({type:"transform",transform:r})}function ly(e,r){return new e({type:"optional",innerType:r})}function dy(e,r){return new e({type:"nullable",innerType:r})}function my(e,r,i){return new e({type:"default",innerType:r,get defaultValue(){return typeof i=="function"?i():$r(i)}})}function fy(e,r,i){return new e({type:"nonoptional",innerType:r,...I(i)})}function py(e,r){return new e({type:"success",innerType:r})}function gy(e,r,i){return new e({type:"catch",innerType:r,catchValue:typeof i=="function"?i:ea(i)})}function vy(e,r,i){return new e({type:"pipe",in:r,out:i})}function hy(e,r){return new e({type:"readonly",innerType:r})}function by(e,r,i){return new e({type:"template_literal",parts:r,...I(i)})}function $y(e,r){return new e({type:"lazy",getter:r})}function yy(e,r){return new e({type:"promise",innerType:r})}function ds(e,r,i){let o=I(i);return o.abort??(o.abort=!0),new e({type:"custom",check:"custom",fn:r,...o})}function ms(e,r,i){return new e({type:"custom",check:"custom",fn:r,...I(i)})}function fs(e,r){let i=Zf(o=>(o.addIssue=t=>{if(typeof t=="string")o.issues.push(Dt(t,o.value,i._zod.def));else{let n=t;n.fatal&&(n.continue=!1),n.code??(n.code="custom"),"input"in n||(n.input=o.value),n.inst??(n.inst=i),n.continue??(n.continue=!i._zod.def.abort),o.issues.push(Dt(n))}},e(o.value,o)),r);return i}function Zf(e,r){let i=new B({check:"custom",...I(r)});return i._zod.check=e,i}function ps(e){let r=new B({check:"describe"});return r._zod.onattach=[i=>{let o=ne.get(i)??{};ne.add(i,{...o,description:e})}],r._zod.check=()=>{},r}function gs(e){let r=new B({check:"meta"});return r._zod.onattach=[i=>{let o=ne.get(i)??{};ne.add(i,{...o,...e})}],r._zod.check=()=>{},r}function vs(e,r){let i=I(r),o=i.truthy??["true","1","yes","on","y","enabled"],t=i.falsy??["false","0","no","off","n","disabled"];i.case!=="sensitive"&&(o=o.map(f=>typeof f=="string"?f.toLowerCase():f),t=t.map(f=>typeof f=="string"?f.toLowerCase():f));let n=new Set(o),a=new Set(t),u=e.Codec??Vr,c=e.Boolean??Rr,s=e.String??mt,d=new s({type:"string",error:i.error}),m=new c({type:"boolean",error:i.error}),p=new u({type:"pipe",in:d,out:m,transform:((f,h)=>{let w=f;return i.case!=="sensitive"&&(w=w.toLowerCase()),n.has(w)?!0:a.has(w)?!1:(h.issues.push({code:"invalid_value",expected:"stringbool",values:[...n,...a],input:h.value,inst:p,continue:!1}),{})}),reverseTransform:((f,h)=>f===!0?o[0]||"true":t[0]||"false"),error:i.error});return p._zod.bag.truthy=o,p._zod.bag.falsy=t,p._zod.bag.case=i.case??"insensitive",p}function yt(e,r,i,o={}){let t=I(o),n={check:"string_format",type:"string",format:r,fn:typeof i=="function"?i:u=>i.test(u),...t};return i instanceof RegExp&&(n.pattern=i),new e(n)}function Qr(e,...r){for(let i of r)for(let o of Reflect.ownKeys(i))Object.prototype.propertyIsEnumerable.call(i,o)&&re(e,o,i[o]);return e}function Qe(e){let r=e?.target??"draft-2020-12";return r==="draft-4"&&(r="draft-04"),r==="draft-7"&&(r="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??ne,target:r,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??"ref",reused:e?.reused??"inline",intersections:[],deferred:[],external:e?.external??void 0}}function q(e,r,i,o,t){let n=typeof r.unrepresentable=="function"?r.unrepresentable({zodSchema:e,path:o.path,message:t}):r.unrepresentable;if(n==="any")return!1;if(n===void 0||n==="throw")throw new Error(t);return Object.assign(i,n),!0}function V(e,r,i={path:[],schemaPath:[]}){var o;let t=e._zod.def,n=r.seen.get(e);if(n)return n.count++,i.schemaPath.includes(e)&&(n.cycle=i.path),n.schema;let a={schema:{},count:1,cycle:void 0,path:i.path};r.seen.set(e,a),r.sharedDefsExtractedFor=void 0,r.sharedEmitDoneFor=void 0;let u=e._zod.toJSONSchema?.();if(u)a.schema=u;else{let d={...i,schemaPath:[...i.schemaPath,e],path:i.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(r,a.schema,d);else{let p=a.schema,f=r.processors[t.type];if(!f)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${t.type}`);f(e,r,p,d)}let m=e._zod.parent;m&&(a.ref||(a.ref=m),V(m,r,d),r.seen.get(m).isParent=!0)}let c=r.metadataRegistry.get(e);return c&&Qr(a.schema,c),r.io==="input"&&de(e)&&(delete a.schema.examples,delete a.schema.default),r.io==="input"&&"_prefault"in a.schema&&((o=a.schema).default??(o.default=a.schema._prefault)),delete a.schema._prefault,r.seen.get(e).schema}function Rf(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function et(e,r){let i=e.seen.get(r);if(!i)throw new Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let o=new Map;for(let a of e.seen.entries()){let u=e.metadataRegistry.get(a[0])?.id;if(u){let c=o.get(u);if(c&&c!==a[0])throw new Error(`Duplicate schema id "${u}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(u,a[0])}}let t=a=>{let u=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let m=e.external.registry.get(a[0])?.id,p=e.external.uri??(h=>h);if(m)return{ref:p(m)};let f=a[1].defId??a[1].schema.id??`schema${e.counter++}`;return a[1].defId=f,{defId:f,ref:`${p("__shared")}#/${u}/${Rf(f)}`}}let c="#",s=`${c}/${u}/`;if(a[1]===i&&!a[1].schema.id)return{ref:c};let d=a[1].schema.id??`__schema${e.counter++}`;return{defId:d,ref:s+Rf(d)}},n=a=>{if(a[1].schema.$ref)return;let u=a[1],{ref:c,defId:s}=t(a);u.def={...u.schema},s&&(u.defId=s);let d=u.schema;for(let m in d)delete d[m];d.$ref=c};if(e.cycles==="throw")for(let a of e.seen.entries()){let u=a[1];if(u.cycle)throw new Error(`Cycle detected: #/${u.cycle?.join("/")}/<root>
|
|
61
61
|
|
|
62
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let u=a[1];if(r===a[0]){n(a);continue}if(e.external){let s=e.external.registry.get(a[0])?.id;if(r!==a[0]&&s){n(a);continue}}if(e.metadataRegistry.get(a[0])?.id){n(a);continue}if(u.cycle){n(a);continue}u.count>1&&e.reused==="ref"&&n(a)}e.external&&(e.sharedDefsExtractedFor=e.external)}function Mf(e){let r=e.anyOf;if(!Array.isArray(r)||r.length===0||e.type!==void 0)return;let i=[];for(let o of r){if(!o||typeof o!="object")return;Mf(o);let t=Object.keys(o);if(t.length!==1||t[0]!=="type")return;let n=o.type;for(let a of Array.isArray(n)?n:[n]){if(typeof a!="string")return;i.includes(a)||i.push(a)}}delete e.anyOf,e.type=i.length===1?i[0]:i}var Ff=new Set(["type","properties","required","additionalProperties"]),Lf=["oneOf","anyOf"];function Vf(e){let r=e.additionalProperties;return r===void 0||r===!1||typeof r!="object"||r===null?null:Object.keys(r).length?r:null}function hs(e){let r=[];for(let n of e){if(typeof n!="object"||n.type!=="object")return null;for(let a in n)if(!Ff.has(a))return null;r.push(n)}let i={},o=new Set;for(let n of r){for(let a in n.properties){if(Object.prototype.hasOwnProperty.call(i,a))continue;let u=[];for(let s of r){let d=s.properties?.[a]??Vf(s);d!=null&&(u.some(m=>JSON.stringify(m)===JSON.stringify(d))||u.push(d))}let c=u.length===1?u[0]:hs(u)??{allOf:u};re(i,a,c)}for(let a of n.required??[])o.add(a)}let t={type:"object",properties:i};if(o.size&&(t.required=[...o]),r.every(n=>n.additionalProperties===!1))t.additionalProperties=!1;else{let n=[];for(let a of r){let u=Vf(a);u&&!n.some(c=>JSON.stringify(c)===JSON.stringify(u))&&n.push(u)}n.length===1?t.additionalProperties=n[0]:n.length>1&&(t.additionalProperties={allOf:n})}return t}function _y(e){let r=e.allOf;if(!Array.isArray(r)||r.length<2)return;for(let t of Ff)if(t in e)return;let i=r.filter(t=>Lf.some(n=>Array.isArray(t[n]))),o=null;if(!i.length)o=hs(r);else{let t=i[0],n=Lf.find(c=>Array.isArray(t[c]));if(Object.keys(t).length!==1)return;let a=r.filter(c=>c!==t),u=t[n].map(c=>hs([...a,c]));if(u.some(c=>!c))return;o={[n]:u}}o&&(delete e.allOf,Qr(e,o))}function tt(e,r){let i=e.seen.get(r);if(!i)throw new Error("Unprocessed schema. This is a bug in Zod.");let o=u=>{let c=e.seen.get(u);if(c.ref===null)return;let s=c.def??c.schema,d={...s},m=c.ref;if(c.ref=null,m){o(m);let f=e.seen.get(m),h=f.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(s.allOf=s.allOf??[],s.allOf.push(h)):Qr(s,h),Qr(s,d),u._zod.parent===m)for(let x in s)x==="$ref"||x==="allOf"||x in d||delete s[x];if(h.$ref&&f.def)for(let x in s)x==="$ref"||x==="allOf"||x in f.def&&JSON.stringify(s[x])===JSON.stringify(f.def[x])&&delete s[x]}let p=u._zod.parent;if(p&&p!==m){o(p);let f=e.seen.get(p);if(f?.schema.$ref&&(s.$ref=f.schema.$ref,f.def))for(let h in s)h==="$ref"||h==="allOf"||h in f.def&&JSON.stringify(s[h])===JSON.stringify(f.def[h])&&delete s[h]}e.override({zodSchema:u,jsonSchema:s,path:c.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let u of[...e.seen.entries()].reverse())o(u[0]);if(e.target!=="openapi-3.0")for(let u of e.seen.entries())Mf(u[1].def??u[1].schema);for(let u of e.deferred)u();if(e.intersections.length){let u=new Map;for(let c of e.seen.values())for(let s of[c.schema,c.def]){let d=s?.allOf;if(!Array.isArray(d))continue;let m=u.get(d);m?m.push(s):u.set(d,[s])}for(let c of e.intersections)for(let s of u.get(c)??[])_y(s)}}let t={};if(e.target==="draft-2020-12"?t.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?t.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?t.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){let u=e.external.registry.get(r)?.id;if(!u)throw new Error("Schema is missing an `id` property");t.$id=e.external.uri(u)}Qr(t,i.defId?i.schema:i.def??i.schema);let n=e.metadataRegistry.get(r)?.id;n!==void 0&&t.id===n&&delete t.id;let a=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let u of e.seen.entries()){let c=u[1];c.def&&c.defId&&(c.def.id===c.defId&&delete c.def.id,re(a,c.defId,c.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(a).length>0&&(e.target==="draft-2020-12"?t.$defs=a:t.definitions=a);try{let u=JSON.parse(JSON.stringify(t));return Object.defineProperty(u,"~standard",{value:{...r["~standard"],jsonSchema:{input:er(r,"input",e.processors),output:er(r,"output",e.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function de(e,r){let i=r??{seen:new Set};if(i.seen.has(e))return!1;i.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return de(o.element,i);if(o.type==="set")return de(o.valueType,i);if(o.type==="lazy")return de(o.getter(),i);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return de(o.innerType,i);if(o.type==="intersection")return de(o.left,i)||de(o.right,i);if(o.type==="record"||o.type==="map")return de(o.keyType,i)||de(o.valueType,i);if(o.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:de(o.in,i)||de(o.out,i);if(o.type==="object"){for(let t in o.shape)if(de(o.shape[t],i))return!0;return!1}if(o.type==="union"){for(let t of o.options)if(de(t,i))return!0;return!1}if(o.type==="tuple"){for(let t of o.items)if(de(t,i))return!0;return!!(o.rest&&de(o.rest,i))}return!1}var bs=(e,r={})=>i=>{let o=Qe({...i,processors:r});return V(e,o),et(o,e),tt(o,e)},er=(e,r,i={})=>o=>{let{libraryOptions:t,target:n}=o??{},a=Qe({...t??{},target:n,io:r,processors:i});return V(e,a),et(a,e),tt(a,e)};var tr=(e,r,i)=>{(e[r]===void 0||i>e[r])&&(e[r]=i)},rr=(e,r,i)=>{(e[r]===void 0||i<e[r])&&(e[r]=i)},Gf=(e,r)=>{tr(e,"minimum",r),rr(e,"maximum",r)},Kf=(e,r)=>{e.multipleOf??(e.multipleOf=[]),e.multipleOf.includes(r)||e.multipleOf.push(r)},Xf=(e,r)=>{e.patterns??(e.patterns=new Set),e.patterns.add(r)},Hf=(e,r)=>{e.mime=e.mime?e.mime.filter(i=>r.includes(i)):[...r]},qf=(e,r)=>{e.format=r,r.includes("int")&&(e.isInt=!0)},Bf=(e,r)=>tr(e,"minimum",r.minimum),Jf=(e,r)=>rr(e,"maximum",r.maximum),Wf=e=>(r,i)=>{qf(r,i.format);let[o,t]=e[i.format];tr(r,"minimum",o),rr(r,"maximum",t)},wy={greater_than:(e,r)=>tr(e,r.inclusive?"minimum":"exclusiveMinimum",r.value),less_than:(e,r)=>rr(e,r.inclusive?"maximum":"exclusiveMaximum",r.value),multiple_of:(e,r)=>Kf(e,r.value),number_format:Wf(_r),bigint_format:Wf(wr),min_length:Bf,max_length:Jf,length_equals:(e,r)=>Gf(e,r.length),min_size:Bf,max_size:Jf,size_equals:(e,r)=>Gf(e,r.size),string_format:(e,r)=>{qf(e,r.format),r.pattern&&Xf(e,r.pattern),(r.format==="base64"||r.format==="base64url")&&(e.contentEncoding=r.format),(r.local||r.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,r)=>Hf(e,r.mime)};function Y(e){let r={},i=e._zod.def,o=e._zod.traits.has("$ZodCheck")?[e,...i.checks??[]]:i.checks??[];for(let n of o)wy[n._zod.def.check]?.(r,n._zod.def);let t=e._zod.bag;t.minimum!==void 0&&tr(r,"minimum",t.minimum),t.exclusiveMinimum!==void 0&&tr(r,"exclusiveMinimum",t.exclusiveMinimum),t.maximum!==void 0&&rr(r,"maximum",t.maximum),t.exclusiveMaximum!==void 0&&rr(r,"exclusiveMaximum",t.exclusiveMaximum),t.multipleOf!==void 0&&Kf(r,t.multipleOf),t.format!==void 0&&(r.format??(r.format=t.format),t.format.includes("int")&&(r.isInt=!0)),t.mime&&Hf(r,t.mime);for(let n of t.patterns??[])Xf(r,n);return r}var xy={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},ky=new Map([[ui,Sa],[Zr,za]]),Yf=e=>ky.get(e)??e,_s=(e,r,i,o)=>{let t=i;t.type="string";let{minimum:n,maximum:a,format:u,patterns:c,contentEncoding:s,laxFormat:d}=Y(e);if(typeof n=="number"&&(t.minLength=n),typeof a=="number"&&(t.maxLength=a),u&&(t.format=xy[u]??u,t.format===""&&delete t.format,(u==="time"||d)&&delete t.format),s&&(t.contentEncoding=s),c&&c.size>0){let m=[...c].map(Yf);m.length===1?t.pattern=m[0].source:m.length>1&&(t.allOf=[...m.map(p=>({...r.target==="draft-07"||r.target==="draft-04"||r.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))])}},ws=(e,r,i,o)=>{let t=i,{minimum:n,maximum:a,multipleOf:u,exclusiveMaximum:c,exclusiveMinimum:s,isInt:d}=Y(e);t.type=d?"integer":"number";let m=typeof s=="number"&&s>=(n??Number.NEGATIVE_INFINITY),p=typeof c=="number"&&c<=(a??Number.POSITIVE_INFINITY),f=r.target==="draft-04"||r.target==="openapi-3.0";if(m?f?(t.minimum=s,t.exclusiveMinimum=!0):t.exclusiveMinimum=s:typeof n=="number"&&(t.minimum=n),p?f?(t.maximum=c,t.exclusiveMaximum=!0):t.exclusiveMaximum=c:typeof a=="number"&&(t.maximum=a),u){let h=new Set;for(let P of u)Number.isFinite(P)&&P!==0?h.add(Math.abs(P)):q(e,r,t,o,`A multipleOf divisor of ${P} cannot be represented in JSON Schema`);let[w,...x]=h;w!==void 0&&(t.multipleOf=w),x.length&&(t.allOf=[...t.allOf??[],...x.map(P=>({multipleOf:P}))])}},xs=(e,r,i,o)=>{i.type="boolean"},ks=(e,r,i,o)=>{q(e,r,i,o,"BigInt cannot be represented in JSON Schema")},Is=(e,r,i,o)=>{q(e,r,i,o,"Symbols cannot be represented in JSON Schema")},Ss=(e,r,i,o)=>{r.target==="openapi-3.0"?(i.type="string",i.nullable=!0,i.enum=[null]):i.type="null"},zs=(e,r,i,o)=>{q(e,r,i,o,"Undefined cannot be represented in JSON Schema")},Ps=(e,r,i,o)=>{q(e,r,i,o,"Void cannot be represented in JSON Schema")},Ts=(e,r,i,o)=>{i.not={}},Os=(e,r,i,o)=>{},Ds=(e,r,i,o)=>{},js=(e,r,i,o)=>{q(e,r,i,o,"Date cannot be represented in JSON Schema")},As=(e,r,i,o)=>{let t=e._zod.def,n=zt(t.entries);if(n.length===0){i.not={};return}n.every(a=>typeof a=="number")&&(i.type="number"),n.every(a=>typeof a=="string")&&(i.type="string"),i.enum=n},Ns=(e,r,i,o)=>{let t=e._zod.def;if(t.values.length===0){i.not={};return}let n=[];for(let a of t.values)if(a===void 0){if(q(e,r,i,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof a=="bigint"){if(q(e,r,i,o,"BigInt literals cannot be represented in JSON Schema"))return;n.push(Number(a))}else n.push(a);if(n.length!==0)if(n.length===1){let a=n[0];i.type=a===null?"null":typeof a,r.target==="draft-04"||r.target==="openapi-3.0"?i.enum=[a]:i.const=a}else n.every(a=>typeof a=="number")&&(i.type="number"),n.every(a=>typeof a=="string")&&(i.type="string"),n.every(a=>typeof a=="boolean")&&(i.type="boolean"),n.every(a=>a===null)&&(i.type="null"),i.enum=n},Us=(e,r,i,o)=>{q(e,r,i,o,"NaN cannot be represented in JSON Schema")},Es=(e,r,i,o)=>{let t=i,n=e._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");t.type="string",t.pattern=n.source},Cs=(e,r,i,o)=>{let t=i;t.type="string",t.format="binary",t.contentEncoding="binary";let{minimum:n,maximum:a,mime:u}=Y(e);n!==void 0&&(t.minLength=n),a!==void 0&&(t.maxLength=a),u&&(u.length===0?t.not={}:u.length===1?t.contentMediaType=u[0]:t.anyOf=u.map(c=>({contentMediaType:c})))},Zs=(e,r,i,o)=>{i.type="boolean"},Rs=(e,r,i,o)=>{q(e,r,i,o,"Custom types cannot be represented in JSON Schema")},Ls=(e,r,i,o)=>{q(e,r,i,o,"Function types cannot be represented in JSON Schema")},Vs=(e,r,i,o)=>{q(e,r,i,o,"Transforms cannot be represented in JSON Schema")},Ms=(e,r,i,o)=>{q(e,r,i,o,"Map cannot be represented in JSON Schema")},Fs=(e,r,i,o)=>{q(e,r,i,o,"Set cannot be represented in JSON Schema")},Gs=(e,r,i,o)=>{let t=i,n=e._zod.def,{minimum:a,maximum:u}=Y(e);typeof a=="number"&&(t.minItems=a),typeof u=="number"&&(t.maxItems=u),t.type="array",t.items=V(n.element,r,{...o,path:[...o.path,"items"]})};function en(e){let r=e._zod.def;return r.type==="pipe"&&r.in._zod.traits.has("$ZodTransform")?en(r.out):r.type==="catch"?en(r.innerType):e._zod.optin}var Bs=(e,r,i,o)=>{let t=i,n=e._zod.def,a=n.shape;if(Object.getOwnPropertySymbols(a).length&&q(e,r,t,o,"Symbol keys cannot be represented in JSON Schema"))return;t.type="object",t.properties={};for(let s in a)re(t.properties,s,V(a[s],r,{...o,path:[...o.path,"properties",s]}));let c=[];for(let s of Object.keys(a)){let d=n.shape[s];(r.io==="input"?en(d)===void 0:d._zod.optout===void 0)&&c.push(s)}c.length>0&&(t.required=c),n.catchall?._zod.def.type==="never"?t.additionalProperties=!1:n.catchall?n.catchall&&(t.additionalProperties=V(n.catchall,r,{...o,path:[...o.path,"additionalProperties"]})):r.io==="output"&&(t.additionalProperties=!1)},io=(e,r,i,o)=>{let t=e._zod.def,n=t.inclusive===!1,a=t.options.map((u,c)=>V(u,r,{...o,path:[...o.path,n?"oneOf":"anyOf",c]}));n?i.oneOf=a:i.anyOf=a},Js=(e,r,i,o)=>{let t=e._zod.def,n=V(t.left,r,{...o,path:[...o.path,"allOf",0]}),a=V(t.right,r,{...o,path:[...o.path,"allOf",1]}),u=s=>"allOf"in s&&Object.keys(s).length===1,c=[...u(n)?n.allOf:[n],...u(a)?a.allOf:[a]];i.allOf=c,r.intersections.push(c)},Ws=(e,r,i,o)=>{let t=i,n=e._zod.def;t.type="array";let a=r.target==="draft-2020-12"?"prefixItems":"items",u=r.target==="draft-2020-12"||r.target==="openapi-3.0"?"items":"additionalItems",c=n.items.map((w,x)=>V(w,r,{...o,path:[...o.path,a,x]})),s=n.rest?V(n.rest,r,{...o,path:[...o.path,u,...r.target==="openapi-3.0"?[n.items.length]:[]]}):null,d=n.items.length;for(;d>0;){let w=n.items[d-1];if(!(r.io==="input"?en(w)!==void 0:w._zod.optout==="optional"))break;d--}let m=n.items.length,p=!n.rest;r.target==="draft-2020-12"?(t.prefixItems=c,p?t.items=!1:s&&(t.items=s),d>0&&(t.minItems=d),p&&(t.maxItems=m)):r.target==="openapi-3.0"?(t.items={anyOf:c},s&&t.items.anyOf.push(s),d>0&&(t.minItems=d),p&&(t.maxItems=m)):(t.items=c,p?t.additionalItems=!1:s&&(t.additionalItems=s),d>0&&(t.minItems=d),p&&(t.maxItems=m));let{minimum:f,maximum:h}=Y(e);typeof f=="number"&&(t.minItems=f),typeof h=="number"&&(t.maxItems=h)};function $s(e,r,i){if(r.$ref){if(i.has(r))return r;i.add(r);let h=e.get(r)?.def;if(!h)return r;let w=$s(e,h,i);return w===h?r:w}for(let h of["anyOf","oneOf"]){let w=r[h];if(!Array.isArray(w))continue;let x=w.map(P=>$s(e,P,i));x.some((P,S)=>P!==w[S])&&(r={...r,[h]:x})}let o=Array.isArray(r.type)?r.type:[r.type],t=!o.includes("string")&&o.some(h=>h==="number"||h==="integer"),n=r.enum??(r.const!==void 0?[r.const]:void 0);if(!t&&!n?.some(h=>typeof h=="number"))return r;let{minimum:a,maximum:u,exclusiveMinimum:c,exclusiveMaximum:s,multipleOf:d,format:m,id:p,...f}=r;return f.enum?f.enum=f.enum.map(h=>typeof h=="number"?String(h):h):typeof f.const=="number"&&(f.const=String(f.const)),t&&(f.type="string",n||(f.pattern=(o.includes("number")?Fe:Dr).source)),f}var ys=new WeakMap;function Iy(e){let r=new Map;for(let o of e.seen.values())o.def&&!r.has(o.schema)&&r.set(o.schema,o);let i=new Map;for(let o of ys.get(e)??[]){let t=e.seen.get(o),n=(t?.def??t?.schema)?.propertyNames;if(!n||n===!0||i.has(n))continue;let a=$s(r,n,new Set);a!==n&&i.set(n,a)}if(i.size)for(let o of e.seen.values())for(let t of[o.schema,o.def]){let n=t&&i.get(t.propertyNames);n&&(t.propertyNames=n)}}var Ks=(e,r,i,o)=>{let t=i,n=e._zod.def;t.type="object";let a=n.keyType,u=Y(a).patterns;if(n.mode==="loose"&&u&&u.size>0){let d=V(n.valueType,r,{...o,path:[...o.path,"patternProperties","*"]});t.patternProperties={};for(let m of u)re(t.patternProperties,Yf(m).source,d)}else{if(r.target==="draft-07"||r.target==="draft-2020-12"){t.propertyNames=V(n.keyType,r,{...o,path:[...o.path,"propertyNames"]});let d=ys.get(r);d||(d=[],ys.set(r,d),r.deferred.push(()=>Iy(r))),d.push(e)}t.additionalProperties=V(n.valueType,r,{...o,path:[...o.path,"additionalProperties"]})}let c=a._zod.values,s=r.io==="input"&&en(n.valueType)!==void 0;if(c&&!n.partial&&!s){let d=[...c].filter(m=>typeof m=="string"||typeof m=="number");d.length>0&&(t.required=d.map(String))}},Xs=(e,r,i,o)=>{let t=e._zod.def,n=V(t.innerType,r,o),a=r.seen.get(e);r.target==="openapi-3.0"?(a.ref=t.innerType,i.nullable=!0):i.anyOf=[n,{type:"null"}]},Hs=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},qs=Symbol();function Qf(e,r,i,o,t){let n=!1,a=JSON.stringify(e,(u,c)=>typeof c!="bigint"?c:(n=!0,null));return n?(q(r,i,o,t,"BigInt defaults cannot be represented in JSON Schema"),qs):JSON.parse(a)}var Ys=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType;let a=Qf(t.defaultValue,e,r,i,o);a!==qs&&(i.default=a)},Qs=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);if(n.ref=t.innerType,r.io!=="input")return;let a=Qf(t.defaultValue,e,r,i,o);a!==qs&&(i._prefault=a)},el=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType;let a;try{a=t.catchValue(void 0)}catch{q(e,r,i,o,"Dynamic catch values are not supported in JSON Schema");return}i.default=a},tl=(e,r,i,o)=>{let t=e._zod.def,n=t.in._zod.traits.has("$ZodTransform"),a=r.io==="input"?n?t.out:t.in:t.out;V(a,r,o);let u=r.seen.get(e);u.ref=a},rl=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType,i.readOnly=!0},nl=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},oo=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},il=(e,r,i,o)=>{let t=e._zod.innerType;V(t,r,o);let n=r.seen.get(e);n.ref=t},no={string:_s,number:ws,boolean:xs,bigint:ks,symbol:Is,null:Ss,undefined:zs,void:Ps,never:Ts,any:Os,unknown:Ds,date:js,enum:As,literal:Ns,nan:Us,template_literal:Es,file:Cs,success:Zs,custom:Rs,function:Ls,transform:Vs,map:Ms,set:Fs,array:Gs,object:Bs,union:io,intersection:Js,tuple:Ws,record:Ks,nullable:Xs,nonoptional:Hs,default:Ys,prefault:Qs,catch:el,pipe:tl,readonly:rl,promise:nl,optional:oo,lazy:il};function ao(e,r){if("_idmap"in e){let o=e,t=Qe({...r,processors:no}),n={};for(let c of o._idmap.entries()){let[s,d]=c;V(d,t)}let a={},u={registry:o,uri:r?.uri,defs:n};t.external=u;for(let c of o._idmap.entries()){let[s,d]=c;et(t,d),re(a,s,tt(t,d))}if(Object.keys(n).length>0){let c=t.target==="draft-2020-12"?"$defs":"definitions";a.__shared={[c]:n}}return{schemas:a}}let i=Qe({...r,processors:no});return V(e,i),et(i,e),tt(i,e)}var uo=class{get metadataRegistry(){return this.ctx.metadataRegistry}get target(){return this.ctx.target}get unrepresentable(){return this.ctx.unrepresentable}get override(){return this.ctx.override}get io(){return this.ctx.io}get counter(){return this.ctx.counter}set counter(r){this.ctx.counter=r}get seen(){return this.ctx.seen}constructor(r){let i=r?.target??"draft-2020-12";i==="draft-4"&&(i="draft-04"),i==="draft-7"&&(i="draft-07"),this.ctx=Qe({processors:no,target:i,...r?.metadata&&{metadata:r.metadata},...r?.unrepresentable&&{unrepresentable:r.unrepresentable},...r?.override&&{override:r.override},...r?.io&&{io:r.io}})}process(r,i={path:[],schemaPath:[]}){return V(r,this.ctx,i)}emit(r,i){i&&(i.cycles&&(this.ctx.cycles=i.cycles),i.reused&&(this.ctx.reused=i.reused),i.external&&(this.ctx.external=i.external)),this.ctx.sharedDefsExtractedFor=void 0,this.ctx.sharedEmitDoneFor=void 0,et(this.ctx,r);let o=tt(this.ctx,r),{"~standard":t,...n}=o;return n}};var ep={};var lr={};Le(lr,{ZodAny:()=>Sl,ZodArray:()=>Ol,ZodBase64:()=>zo,ZodBase64URL:()=>Po,ZodBigInt:()=>cr,ZodBigIntFormat:()=>Do,ZodBoolean:()=>ur,ZodCIDRv4:()=>Io,ZodCIDRv6:()=>So,ZodCUID:()=>bo,ZodCUID2:()=>$o,ZodCatch:()=>ql,ZodCodec:()=>dn,ZodCreditCard:()=>bl,ZodCustom:()=>mn,ZodCustomStringFormat:()=>kt,ZodDate:()=>on,ZodDefault:()=>Bl,ZodDiscriminatedUnion:()=>jl,ZodE164:()=>To,ZodEmail:()=>po,ZodEmoji:()=>vo,ZodEnum:()=>ir,ZodExactOptional:()=>Uo,ZodFile:()=>Vl,ZodFunction:()=>ud,ZodGUID:()=>go,ZodIBAN:()=>$l,ZodIPv4:()=>xo,ZodIPv6:()=>ko,ZodISODate:()=>nt,ZodISODateTime:()=>rt,ZodISODuration:()=>ot,ZodISOTime:()=>it,ZodInstanceOf:()=>ld,ZodIntersection:()=>Al,ZodJWT:()=>Oo,ZodKSUID:()=>wo,ZodLazy:()=>id,ZodLiteral:()=>Ll,ZodMAC:()=>hl,ZodMap:()=>Zl,ZodNaN:()=>Ql,ZodNanoID:()=>ho,ZodNever:()=>Pl,ZodNonOptional:()=>Eo,ZodNull:()=>kl,ZodNullable:()=>Gl,ZodNumber:()=>ar,ZodNumberFormat:()=>It,ZodObject:()=>un,ZodOptional:()=>sn,ZodPipe:()=>ln,ZodPrefault:()=>Wl,ZodPreprocess:()=>ed,ZodPromise:()=>ad,ZodReadonly:()=>td,ZodRecord:()=>nr,ZodSet:()=>Rl,ZodString:()=>or,ZodStringFormat:()=>G,ZodSuccess:()=>Hl,ZodSymbol:()=>wl,ZodTemplateLiteral:()=>nd,ZodTransform:()=>Ml,ZodTuple:()=>Ul,ZodType:()=>E,ZodULID:()=>yo,ZodURL:()=>nn,ZodUUID:()=>Ee,ZodUndefined:()=>xl,ZodUnion:()=>cn,ZodUnknown:()=>zl,ZodVoid:()=>Tl,ZodXID:()=>_o,ZodXor:()=>Dl,_ZodString:()=>fo,_default:()=>Jl,_function:()=>mg,any:()=>Fp,array:()=>an,base64:()=>xp,base64url:()=>kp,bigint:()=>Zp,boolean:()=>_l,catch:()=>Yl,check:()=>fg,cidrv4:()=>_p,cidrv6:()=>wp,codec:()=>cg,creditCard:()=>Sp,cuid:()=>fp,cuid2:()=>pp,currencyCode:()=>jp,custom:()=>pg,date:()=>Bp,describe:()=>gg,discriminatedUnion:()=>qp,e164:()=>Ip,email:()=>np,emoji:()=>dp,enum:()=>Ao,exactOptional:()=>Fl,file:()=>ig,float32:()=>Np,float64:()=>Up,function:()=>mg,guid:()=>ip,hash:()=>Ap,hex:()=>Dp,hostname:()=>Op,httpUrl:()=>lp,iban:()=>zp,instanceof:()=>hg,int:()=>lo,int32:()=>Ep,int64:()=>Rp,intersection:()=>Nl,invertCodec:()=>sg,ipv4:()=>bp,ipv6:()=>yp,json:()=>$g,jwt:()=>Pp,keyof:()=>Jp,ksuid:()=>hp,lazy:()=>od,literal:()=>ng,looseObject:()=>Xp,looseRecord:()=>Qp,mac:()=>$p,map:()=>eg,meta:()=>vg,nan:()=>ug,nanoid:()=>mp,nativeEnum:()=>rg,never:()=>jo,nonoptional:()=>Xl,null:()=>Il,nullable:()=>rn,nullish:()=>og,number:()=>yl,object:()=>Wp,optional:()=>wt,partialRecord:()=>Yp,pipe:()=>mo,prefault:()=>Kl,preprocess:()=>yg,promise:()=>dg,readonly:()=>rd,record:()=>Cl,refine:()=>cd,set:()=>tg,strictObject:()=>Kp,string:()=>tn,stringFormat:()=>Tp,stringbool:()=>bg,success:()=>ag,superRefine:()=>sd,symbol:()=>Vp,templateLiteral:()=>lg,transform:()=>No,tuple:()=>El,uint32:()=>Cp,uint64:()=>Lp,ulid:()=>gp,undefined:()=>Mp,union:()=>sr,unknown:()=>_t,url:()=>sp,uuid:()=>op,uuidv4:()=>ap,uuidv6:()=>up,uuidv7:()=>cp,void:()=>Gp,xid:()=>vp,xor:()=>Hp});var co={};Le(co,{endsWith:()=>Jt,gt:()=>Ne,gte:()=>xe,includes:()=>Gt,length:()=>$t,lowercase:()=>Mt,lt:()=>Ae,lte:()=>we,maxLength:()=>bt,maxSize:()=>Ye,mime:()=>Kt,minLength:()=>Ge,minSize:()=>Ue,multipleOf:()=>qe,negative:()=>Qi,nonnegative:()=>to,nonpositive:()=>eo,normalize:()=>Xt,overwrite:()=>Oe,positive:()=>Yi,properties:()=>Wt,property:()=>ro,regex:()=>Vt,size:()=>ht,slugify:()=>Qt,startsWith:()=>Bt,toLowerCase:()=>qt,toUpperCase:()=>Yt,trim:()=>Ht,uppercase:()=>Ft});var tp=new WeakSet([Object.prototype,Error.prototype]);function so(e,r,i){Object.defineProperty(e,r,{configurable:!0,enumerable:!1,get(){let o=i(this);return Object.defineProperty(this,r,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,r,{value:o,configurable:!0,writable:!0})}})}var rp=(e,r)=>{aa.init(e,r),e.name="ZodError";let i=Object.getPrototypeOf(e);tp.has(i)||(tp.add(i),so(i,"format",o=>t=>zr(o,t)),so(i,"flatten",o=>t=>Sr(o,t)),so(i,"addIssue",o=>t=>{o.issues.push(t),o.message=JSON.stringify(o.issues,Pt,2)}),so(i,"addIssues",o=>t=>{o.issues.push(...t),o.message=JSON.stringify(o.issues,Pt,2)}),Object.defineProperty(i,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},zy=g("ZodError",rp),ye=g("ZodError",rp,void 0,{Parent:Error});var ol=jt(ye),al=At(ye),ul=Nt(ye),cl=Ut(ye),sl=Zn(ye),ll=Rn(ye),dl=Ln(ye),ml=Vn(ye),fl=Mn(ye),pl=Fn(ye),gl=Gn(ye),vl=Bn(ye);function Ty(){ee.localeError||K(xi())}function xt(){ee.memoizer||K({memoizer:Br()})}var E=g("ZodType",(e,r)=>(Ty(),N.init(e,r),e.def=r,e.type=r.type,e),{check(...e){let r=this.def;return this.clone(b.mergeDefs(r,{checks:[...r.checks??[],...e.map(i=>typeof i=="function"?{_zod:{check:i,def:{check:"custom"},onattach:[]}}:i)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,r){return R(this,e,r)},brand(){return this},register(e,r){return e.add(this,r),this},refine(e,r){return this.check(cd(e,r))},superRefine(e,r){return this.check(sd(e,r))},overwrite(e){return this.check(Oe(e))},optional(){return wt(this)},exactOptional(){return Fl(this)},nullable(){return rn(this)},nullish(){return wt(rn(this))},nonoptional(e){return Xl(this,e)},array(){return an(this)},or(e){return sr([this,e])},and(e){return Nl(this,e)},transform(e){return mo(this,No(e))},default(e){return Jl(this,e)},prefault(e){return Kl(this,e)},catch(e){return Yl(this,e)},pipe(e){return mo(this,e)},readonly(){return rd(this)},describe(e){let r=this.clone();return ne.add(r,{description:e}),r},meta(...e){if(e.length===0)return ne.get(this);let r=this.clone();return ne.add(r,e[0]),r},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...r){return r.length===0?e(this):e(this,...r)},get"~standard"(){return b.hide(this,"~standard",{...ri(this),jsonSchema:{input:er(this,"input"),output:er(this,"output")}})},set"~standard"(e){b.own(this,"~standard",e)},parse:function e(r,i){return ol(this,r,i,{callee:e})},parseAsync:async function e(r,i){return await al(this,r,i,{callee:e})},safeParse(e,r){return ul(this,e,r)},async safeParseAsync(e,r){return cl(this,e,r)},get spa(){return this?.safeParseAsync},set spa(e){b.own(this,"spa",e)},validate(e,r){return Pr(this,e,r)},validateAsync(e,r){return Tr(this,e,r)},encode:function e(r,i){return sl(this,r,i,{callee:e})},decode:function e(r,i){return ll(this,r,i,{callee:e})},encodeAsync:async function e(r,i){return await dl(this,r,i,{callee:e})},decodeAsync:async function e(r,i){return await ml(this,r,i,{callee:e})},safeEncode(e,r){return fl(this,e,r)},safeDecode(e,r){return pl(this,e,r)},async safeEncodeAsync(e,r){return gl(this,e,r)},async safeDecodeAsync(e,r){return vl(this,e,r)},toJSONSchema(e){return bs(this,{})(e)},get description(){return ne.get(this)?.description},get _def(){return this._zod.def}}),fo=g("_ZodString",(e,r)=>{mt.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>_s(e,i,o,t)},b.derived({format:e=>Y(e).format??null,minLength:e=>Y(e).minimum??null,maxLength:e=>Y(e).maximum??null},{regex(...e){return this.check(Vt(...e))},includes(...e){return this.check(Gt(...e))},startsWith(...e){return this.check(Bt(...e))},endsWith(...e){return this.check(Jt(...e))},min(...e){return this.check(Ge(...e))},max(...e){return this.check(bt(...e))},length(...e){return this.check($t(...e))},nonempty(...e){return this.check(Ge(1,...e))},lowercase(e){return this.check(Mt(e))},uppercase(e){return this.check(Ft(e))},trim(){return this.check(Ht())},normalize(...e){return this.check(Xt(...e))},toLowerCase(){return this.check(qt())},toUpperCase(){return this.check(Yt())},slugify(){return this.check(Qt())}})),or=g("ZodString",(e,r)=>{mt.init(e,r),fo.init(e,r)},{email(e){return this.check(Di(po,e))},url(e){return this.check(Kr(nn,e))},jwt(e){return this.check(qi(Oo,e))},emoji(e){return this.check(Ci(vo,e))},guid(e){return this.check(ji(go,e))},uuid(e){return this.check(Ai(Ee,e))},uuidv4(e){return this.check(Ni(Ee,e))},uuidv6(e){return this.check(Ui(Ee,e))},uuidv7(e){return this.check(Ei(Ee,e))},nanoid(e){return this.check(Zi(ho,e))},cuid(e){return this.check(Ri(bo,e))},cuid2(e){return this.check(Li($o,e))},ulid(e){return this.check(Vi(yo,e))},base64(e){return this.check(Ki(zo,e))},base64url(e){return this.check(Xi(Po,e))},xid(e){return this.check(Mi(_o,e))},ksuid(e){return this.check(Fi(wo,e))},ipv4(e){return this.check(Gi(xo,e))},ipv6(e){return this.check(Bi(ko,e))},cidrv4(e){return this.check(Ji(Io,e))},cidrv6(e){return this.check(Wi(So,e))},e164(e){return this.check(Hi(To,e))},datetime(e){return this.check(Xr(rt,e))},date(e){return this.check(Hr(nt,e))},time(e){return this.check(qr(it,e))},duration(e){return this.check(Yr(ot,e))}});function tn(e){return Nc(or,e)}var G=g("ZodStringFormat",(e,r)=>{L.init(e,r),fo.init(e,r)}),rt=g("ZodISODateTime",(e,r)=>{Su.init(e,r),G.init(e,r)}),nt=g("ZodISODate",(e,r)=>{zu.init(e,r),G.init(e,r)}),it=g("ZodISOTime",(e,r)=>{Pu.init(e,r),G.init(e,r)}),ot=g("ZodISODuration",(e,r)=>{Tu.init(e,r),G.init(e,r)}),po=g("ZodEmail",(e,r)=>{gu.init(e,r),G.init(e,r)});function np(e){return Di(po,e)}var go=g("ZodGUID",(e,r)=>{fu.init(e,r),G.init(e,r)});function ip(e){return ji(go,e)}var Ee=g("ZodUUID",(e,r)=>{pu.init(e,r),G.init(e,r)});function op(e){return Ai(Ee,e)}function ap(e){return Ni(Ee,e)}function up(e){return Ui(Ee,e)}function cp(e){return Ei(Ee,e)}var nn=g("ZodURL",(e,r)=>{bu.init(e,r),G.init(e,r)});function sp(e){return Kr(nn,e)}function lp(e){return Kr(nn,{protocol:Or,hostname:Ta,...b.normalizeParams(e)})}var vo=g("ZodEmoji",(e,r)=>{$u.init(e,r),G.init(e,r)});function dp(e){return Ci(vo,e)}var ho=g("ZodNanoID",(e,r)=>{yu.init(e,r),G.init(e,r)});function mp(e){return Zi(ho,e)}var bo=g("ZodCUID",(e,r)=>{_u.init(e,r),G.init(e,r)});function fp(e){return Ri(bo,e)}var $o=g("ZodCUID2",(e,r)=>{wu.init(e,r),G.init(e,r)});function pp(e){return Li($o,e)}var yo=g("ZodULID",(e,r)=>{xu.init(e,r),G.init(e,r)});function gp(e){return Vi(yo,e)}var _o=g("ZodXID",(e,r)=>{ku.init(e,r),G.init(e,r)});function vp(e){return Mi(_o,e)}var wo=g("ZodKSUID",(e,r)=>{Iu.init(e,r),G.init(e,r)});function hp(e){return Fi(wo,e)}var xo=g("ZodIPv4",(e,r)=>{Ou.init(e,r),G.init(e,r)});function bp(e){return Gi(xo,e)}var hl=g("ZodMAC",(e,r)=>{ju.init(e,r),G.init(e,r)});function $p(e){return Ec(hl,e)}var ko=g("ZodIPv6",(e,r)=>{Du.init(e,r),G.init(e,r)});function yp(e){return Bi(ko,e)}var Io=g("ZodCIDRv4",(e,r)=>{Au.init(e,r),G.init(e,r)});function _p(e){return Ji(Io,e)}var So=g("ZodCIDRv6",(e,r)=>{Nu.init(e,r),G.init(e,r)});function wp(e){return Wi(So,e)}var zo=g("ZodBase64",(e,r)=>{Uu.init(e,r),G.init(e,r)});function xp(e){return Ki(zo,e)}var Po=g("ZodBase64URL",(e,r)=>{Eu.init(e,r),G.init(e,r)});function kp(e){return Xi(Po,e)}var To=g("ZodE164",(e,r)=>{Cu.init(e,r),G.init(e,r)});function Ip(e){return Hi(To,e)}var bl=g("ZodCreditCard",(e,r)=>{Zu.init(e,r),G.init(e,r)});function Sp(e){return Cc(bl,e)}var $l=g("ZodIBAN",(e,r)=>{Ru.init(e,r),G.init(e,r)});function zp(e){return Zc($l,e)}var Oo=g("ZodJWT",(e,r)=>{Lu.init(e,r),G.init(e,r)});function Pp(e){return qi(Oo,e)}var kt=g("ZodCustomStringFormat",(e,r)=>{Vu.init(e,r),G.init(e,r)});function Tp(e,r,i={}){return yt(kt,e,r,i)}function Op(e){return yt(kt,"hostname",Pa,e)}function Dp(e){return yt(kt,"hex",Fa,e)}function jp(e){return yt(kt,"currency_code",Da,e)}function Ap(e,r){let i=r?.enc??"hex",o=`${e}_${i}`,t=Se[o];if(!t)throw new Error(`Unrecognized hash format: ${o}`);return yt(kt,o,t,r)}var ar=g("ZodNumber",(e,r)=>{mi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>ws(e,i,o,t),e.isFinite=!0},b.derived({minValue:e=>{let{minimum:r,exclusiveMinimum:i}=Y(e);return Math.max(r??Number.NEGATIVE_INFINITY,i??Number.NEGATIVE_INFINITY)},maxValue:e=>{let{maximum:r,exclusiveMaximum:i}=Y(e);return Math.min(r??Number.POSITIVE_INFINITY,i??Number.POSITIVE_INFINITY)},isInt:e=>{let{isInt:r,multipleOf:i}=Y(e);return!!r||!!i?.some(Number.isSafeInteger)},format:e=>Y(e).format??null},{gt(e,r){return this.check(Ne(e,r))},gte(e,r){return this.check(xe(e,r))},min(e,r){return this.check(xe(e,r))},lt(e,r){return this.check(Ae(e,r))},lte(e,r){return this.check(we(e,r))},max(e,r){return this.check(we(e,r))},int(e){return this.check(lo(e))},safe(e){return this.check(lo(e))},positive(e){return this.check(Ne(0,e))},nonnegative(e){return this.check(xe(0,e))},negative(e){return this.check(Ae(0,e))},nonpositive(e){return this.check(we(0,e))},multipleOf(e,r){return this.check(qe(e,r))},step(e,r){return this.check(qe(e,r))},finite(){return this}}));function yl(e){return Lc(ar,e)}var It=g("ZodNumberFormat",(e,r)=>{Mu.init(e,r),ar.init(e,r)});function lo(e){return Mc(It,e)}function Np(e){return Fc(It,e)}function Up(e){return Gc(It,e)}function Ep(e){return Bc(It,e)}function Cp(e){return Jc(It,e)}var ur=g("ZodBoolean",(e,r)=>{Rr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>xs(e,i,o,t)});function _l(e){return Wc(ur,e)}var cr=g("ZodBigInt",(e,r)=>{fi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>ks(e,i,o,t)},b.derived({minValue:e=>Y(e).minimum??null,maxValue:e=>Y(e).maximum??null,format:e=>Y(e).format??null},{gte(e,r){return this.check(xe(e,r))},min(e,r){return this.check(xe(e,r))},gt(e,r){return this.check(Ne(e,r))},lt(e,r){return this.check(Ae(e,r))},lte(e,r){return this.check(we(e,r))},max(e,r){return this.check(we(e,r))},positive(e){return this.check(Ne(BigInt(0),e))},negative(e){return this.check(Ae(BigInt(0),e))},nonpositive(e){return this.check(we(BigInt(0),e))},nonnegative(e){return this.check(xe(BigInt(0),e))},multipleOf(e,r){return this.check(qe(e,r))}}));function Zp(e){return Xc(cr,e)}var Do=g("ZodBigIntFormat",(e,r)=>{Fu.init(e,r),cr.init(e,r)});function Rp(e){return qc(Do,e)}function Lp(e){return Yc(Do,e)}var wl=g("ZodSymbol",(e,r)=>{Gu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Is(e,i,o,t)});function Vp(e){return Qc(wl,e)}var xl=g("ZodUndefined",(e,r)=>{Bu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>zs(e,i,o,t)});function Mp(e){return es(xl,e)}var kl=g("ZodNull",(e,r)=>{Ju.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ss(e,i,o,t)});function Il(e){return ts(kl,e)}var Sl=g("ZodAny",(e,r)=>{Wu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Os(e,i,o,t)});function Fp(){return rs(Sl)}var zl=g("ZodUnknown",(e,r)=>{Ku.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ds(e,i,o,t)});function _t(){return ns(zl)}var Pl=g("ZodNever",(e,r)=>{Xu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ts(e,i,o,t)});function jo(e){return is(Pl,e)}var Tl=g("ZodVoid",(e,r)=>{Hu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ps(e,i,o,t)});function Gp(e){return os(Tl,e)}var on=g("ZodDate",(e,r)=>{qu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>js(e,i,o,t),e.min=(i,o)=>e.check(xe(i,o)),e.max=(i,o)=>e.check(we(i,o))},b.derived({minDate:e=>{let{minimum:r}=Y(e);return r?new Date(r):null},maxDate:e=>{let{maximum:r}=Y(e);return r?new Date(r):null}},{}));function Bp(e){return as(on,e)}var Ol=g("ZodArray",(e,r)=>{xt(),Yu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Gs(e,i,o,t),e.element=r.element},{min(e,r){return this.check(Ge(e,r))},nonempty(e){return this.check(Ge(1,e))},max(e,r){return this.check(bt(e,r))},length(e,r){return this.check($t(e,r))},unwrap(){return this.element}});function an(e,r){return ss(Ol,e,r)}function Jp(e){let r=e._zod.def.shape;return Ao(Object.keys(r))}var un=g("ZodObject",(e,r)=>{xt(),Qu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Bs(e,i,o,t),b.installLazyProp(e,"shape",i=>i._zod.def.shape,!1)},{keyof(){return Ao(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(b.mergeDefs(this._zod.def,{catchall:e}))},passthrough(){return this.clone(b.mergeDefs(this._zod.def,{catchall:_t()}))},loose(){return this.clone(b.mergeDefs(this._zod.def,{catchall:_t()}))},strict(){return this.clone(b.mergeDefs(this._zod.def,{catchall:jo()}))},strip(){return this.clone(b.mergeDefs(this._zod.def,{catchall:void 0}))},extend(e){return b.extend(this,e)},safeExtend(e){return b.safeExtend(this,e)},merge(e){return b.merge(this,e)},pick(e){return b.pick(this,e)},omit(e){return b.omit(this,e)},partial(...e){return b.partial(sn,this,e[0])},exactPartial(...e){return b.partial(Uo,this,e[0],"exactPartial")},required(...e){return b.required(Eo,this,e[0])}});function Wp(e,r){let i={type:"object",shape:e??{},...b.normalizeParams(r)};return new un(i)}function Kp(e,r){return new un({type:"object",shape:e,catchall:jo(),...b.normalizeParams(r)})}function Xp(e,r){return new un({type:"object",shape:e,catchall:_t(),...b.normalizeParams(r)})}var cn=g("ZodUnion",(e,r)=>{Lr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>io(e,i,o,t),e.options=r.options});function sr(e,r){return new cn({type:"union",options:e,...b.normalizeParams(r)})}var Dl=g("ZodXor",(e,r)=>{cn.init(e,r),ec.init(e,r),e._zod.processJSONSchema=(i,o,t)=>io(e,i,o,t),e.options=r.options});function Hp(e,r){return new Dl({type:"union",options:e,inclusive:!1,...b.normalizeParams(r)})}var jl=g("ZodDiscriminatedUnion",(e,r)=>{cn.init(e,r),rc.init(e,r)});function qp(e,r,i){return new jl({type:"union",options:r,discriminator:e,...b.normalizeParams(i)})}var Al=g("ZodIntersection",(e,r)=>{nc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Js(e,i,o,t)});function Nl(e,r){return new Al({type:"intersection",left:e,right:r})}var Ul=g("ZodTuple",(e,r)=>{xt(),pi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ws(e,i,o,t)},{rest(e){return this.clone({...this._zod.def,rest:e})},partial(){let e=this._zod.def;if(e.checks?.length)throw new Error(".partial() cannot be used on tuple schemas containing refinements");return this.clone({...e,items:e.items.map(r=>new sn({type:"optional",innerType:r}))})}});function El(e,r,i){let o=r instanceof N,t=o?i:r,n=o?r:null;return new Ul({type:"tuple",items:e,rest:n,...b.normalizeParams(t)})}var nr=g("ZodRecord",(e,r)=>{xt(),ic.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ks(e,i,o,t),e.keyType=r.keyType,e.valueType=r.valueType});function Cl(e,r,i){return!r||!r._zod?new nr({type:"record",keyType:tn(),valueType:e,...b.normalizeParams(r)}):new nr({type:"record",keyType:e,valueType:r,...b.normalizeParams(i)})}function Yp(e,r,i){return new nr({type:"record",keyType:e,valueType:r,...b.normalizeParams(i),partial:!0})}function Qp(e,r,i){return new nr({type:"record",keyType:e,valueType:r,mode:"loose",...b.normalizeParams(i)})}var Zl=g("ZodMap",(e,r)=>{xt(),oc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ms(e,i,o,t),e.keyType=r.keyType,e.valueType=r.valueType,e.min=(...i)=>e.check(Ue(...i)),e.nonempty=i=>e.check(Ue(1,i)),e.max=(...i)=>e.check(Ye(...i)),e.size=(...i)=>e.check(ht(...i))});function eg(e,r,i){return new Zl({type:"map",keyType:e,valueType:r,...b.normalizeParams(i)})}var Rl=g("ZodSet",(e,r)=>{xt(),ac.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Fs(e,i,o,t),e.min=(...i)=>e.check(Ue(...i)),e.nonempty=i=>e.check(Ue(1,i)),e.max=(...i)=>e.check(Ye(...i)),e.size=(...i)=>e.check(ht(...i))});function tg(e,r){return new Rl({type:"set",valueType:e,...b.normalizeParams(r)})}var ir=g("ZodEnum",(e,r)=>{uc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(o,t,n)=>As(e,o,t,n),e.enum=r.entries,e.options=[...e._zod.values];let i=new Set(Object.keys(r.entries));e.extract=(o,t)=>{let n={};for(let a of o)if(i.has(a))n[a]=r.entries[a];else throw new Error(`Key ${a} not found in enum`);return new ir({...r,checks:[],...b.normalizeParams(t),entries:n})},e.exclude=(o,t)=>{let n={...r.entries};for(let a of o)if(i.has(a))delete n[a];else throw new Error(`Key ${a} not found in enum`);return new ir({...r,checks:[],...b.normalizeParams(t),entries:n})}});function Ao(e,r){let i=Array.isArray(e)?Object.fromEntries(e.map(o=>[o,o])):e;return new ir({type:"enum",entries:i,...b.normalizeParams(r)})}function rg(e,r){return new ir({type:"enum",entries:e,...b.normalizeParams(r)})}var Ll=g("ZodLiteral",(e,r)=>{cc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ns(e,i,o,t),e.values=new Set(r.values),Object.defineProperty(e,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function ng(e,r){return new Ll({type:"literal",values:Array.isArray(e)?e:[e],...b.normalizeParams(r)})}var Vl=g("ZodFile",(e,r)=>{sc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Cs(e,i,o,t),e.min=(i,o)=>e.check(Ue(i,o)),e.max=(i,o)=>e.check(Ye(i,o)),e.mime=(i,o)=>e.check(Kt(Array.isArray(i)?i:[i],o))});function ig(e){return ls(Vl,e)}var Ml=g("ZodTransform",(e,r)=>{xt(),lc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Vs(e,i,o,t),e._zod.parse=(i,o)=>{if(o.direction==="backward")throw new He(e.constructor.name);i.addIssue=n=>{if(typeof n=="string")i.issues.push(b.issue(n,i.value,r));else{let a=n;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),"input"in a||(a.input=i.value),a.inst??(a.inst=e),i.issues.push(b.issue(a))}};let t=r.transform(i.value,i);return t instanceof Promise?t.then(n=>(i.value=n,i)):(i.value=t,i)}});function No(e){return new Ml({type:"transform",transform:e})}var sn=g("ZodOptional",(e,r)=>{gi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>oo(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function wt(e){return new sn({type:"optional",innerType:e})}var Uo=g("ZodExactOptional",(e,r)=>{dc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>oo(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Fl(e){return new Uo({type:"optional",innerType:e})}var Gl=g("ZodNullable",(e,r)=>{mc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Xs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function rn(e){return new Gl({type:"nullable",innerType:e})}function og(e){return wt(rn(e))}var Bl=g("ZodDefault",(e,r)=>{fc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ys(e,i,o,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Jl(e,r){return new Bl({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():b.shallowClone(r)}})}var Wl=g("ZodPrefault",(e,r)=>{pc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Qs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Kl(e,r){return new Wl({type:"prefault",innerType:e,get defaultValue(){return typeof r=="function"?r():b.shallowClone(r)}})}var Eo=g("ZodNonOptional",(e,r)=>{gc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Hs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Xl(e,r){return new Eo({type:"nonoptional",innerType:e,...b.normalizeParams(r)})}var Hl=g("ZodSuccess",(e,r)=>{vc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Zs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function ag(e){return new Hl({type:"success",innerType:e})}var ql=g("ZodCatch",(e,r)=>{hc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>el(e,i,o,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Yl(e,r){return new ql({type:"catch",innerType:e,catchValue:typeof r=="function"?r:b.constantCatch(r)})}var Ql=g("ZodNaN",(e,r)=>{bc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Us(e,i,o,t)});function ug(e){return cs(Ql,e)}var ln=g("ZodPipe",(e,r)=>{vi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>tl(e,i,o,t),e.in=r.in,e.out=r.out});function mo(e,r){return new ln({type:"pipe",in:e,out:r})}var dn=g("ZodCodec",(e,r)=>{ln.init(e,r),Vr.init(e,r)});function cg(e,r,i){return new dn({type:"pipe",in:e,out:r,transform:i.decode,reverseTransform:i.encode})}function sg(e){let r=e._zod.def;return new dn({type:"pipe",in:r.out,out:r.in,transform:r.reverseTransform,reverseTransform:r.transform})}var ed=g("ZodPreprocess",(e,r)=>{ln.init(e,r),$c.init(e,r)}),td=g("ZodReadonly",(e,r)=>{yc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>rl(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function rd(e){return new td({type:"readonly",innerType:e})}var nd=g("ZodTemplateLiteral",(e,r)=>{_c.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Es(e,i,o,t)});function lg(e,r){return new nd({type:"template_literal",parts:e,...b.normalizeParams(r)})}var id=g("ZodLazy",(e,r)=>{Mr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>il(e,i,o,t),e.unwrap=()=>e._zod.def.getter()});function od(e){return new id({type:"lazy",getter:e})}var ad=g("ZodPromise",(e,r)=>{xc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>nl(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function dg(e){return new ad({type:"promise",innerType:e})}var ud=g("ZodFunction",(e,r)=>{wc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ls(e,i,o,t)});function mg(e){return new ud({type:"function",input:Array.isArray(e?.input)?El(e?.input):e?.input??an(_t()),output:e?.output??_t()})}var mn=g("ZodCustom",(e,r)=>{kc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Rs(e,i,o,t)});function fg(e){let r=new B({check:"custom"});return r._zod.check=e,r}function pg(e,r){return ds(mn,e??(()=>!0),r)}function cd(e,r={}){return ms(mn,e,r)}function sd(e,r){return fs(e,r)}var gg=ps,vg=gs,ld=g("ZodInstanceOf",(e,r)=>{mn.init(e,r)},{properties(e,r){return this.check(Wt(e,r))}});function hg(e,r={}){let i=new ld({type:"custom",check:"custom",fn:o=>o instanceof e,abort:!0,...b.normalizeParams(r)});return i._zod.bag.Class=e,i._zod.check=o=>{o.value instanceof e||o.issues.push({code:"invalid_type",expected:e.name,input:o.value,inst:i,path:[...i._zod.def.path??[]]})},i}var bg=(...e)=>vs({Codec:dn,Boolean:ur,String:or},...e);function $g(e){let r=od(()=>sr([tn(e),yl(),_l(),Il(),an(r),Cl(tn(),r)]));return r}function yg(e,r){return new ed({type:"pipe",in:No(e),out:r})}var Oy={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"};function Dy(e){K({customError:e})}function jy(){return K().customError}var dd;dd||(dd={});var fn={};Le(fn,{ZodISODate:()=>nt,ZodISODateTime:()=>rt,ZodISODuration:()=>ot,ZodISOTime:()=>it,date:()=>Ny,datetime:()=>Ay,duration:()=>Ey,time:()=>Uy});function Ay(e){return Xr(rt,e)}function Ny(e){return Hr(nt,e)}function Uy(e){return qr(it,e)}function Ey(e){return Yr(ot,e)}var z={...lr,...co,iso:fn},Cy=new Set(["$schema","$ref","$defs","definitions","$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor","type","enum","const","anyOf","oneOf","allOf","not","properties","required","additionalProperties","patternProperties","propertyNames","minProperties","maxProperties","items","prefixItems","additionalItems","minItems","maxItems","uniqueItems","contains","minContains","maxContains","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","description","default","contentEncoding","contentMediaType","contentSchema","unevaluatedItems","unevaluatedProperties","if","then","else","dependentSchemas","dependentRequired","nullable","readOnly"]);function Zy(e,r){let i=e.$schema;return i==="https://json-schema.org/draft/2020-12/schema"?"draft-2020-12":i==="http://json-schema.org/draft-07/schema#"?"draft-7":i==="http://json-schema.org/draft-04/schema#"?"draft-4":r??"draft-2020-12"}function _g(e,r){return e.map((i,o)=>o<r?i:i.optional())}function Ry(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Ly(e,r){if(!e.startsWith("#"))throw new Error("External $ref is not supported, only local refs (#/...) are allowed");let i=e.slice(1).split("/").filter(Boolean);if(i.length===0)return r.rootSchema;let o=r.version==="draft-2020-12"?"$defs":"definitions";if(i[0]===o){let t=i[1]===void 0?void 0:Ry(i[1]);if(!t||!r.defs[t])throw new Error(`Reference not found: ${e}`);return r.defs[t]}throw new Error(`Reference not found: ${e}`)}function Vy(e,r){return z.transform(o=>o).check(o=>{let t=o.value;if(typeof t!="object"||t===null||Array.isArray(t))return;let n=Object.getOwnPropertyNames(t);if(r.minProperties!==void 0&&n.length<r.minProperties&&o.issues.push({origin:"object",code:"too_small",minimum:r.minProperties,inclusive:!0,message:`Too small: expected object to have >=${r.minProperties} properties`,input:t,inst:e,continue:!0}),r.maxProperties!==void 0&&n.length>r.maxProperties&&o.issues.push({origin:"object",code:"too_big",maximum:r.maxProperties,inclusive:!0,message:`Too big: expected object to have <=${r.maxProperties} properties`,input:t,inst:e,continue:!0}),r.keySchema)for(let a of n){let u=r.keySchema.safeParse(a);u.success||o.issues.push({code:"invalid_key",origin:"record",issues:u.error.issues,input:a,path:[a],continue:!0})}}).pipe(e)}function md(e,r){if(e===null)return"z";let i=typeof e;if(i!=="object"){if(i==="number"&&Number.isNaN(e))return null;let o=String(e);return`${i[0]}${o.length}:${o}`}if(r.has(e))return null;r.add(e);try{if(Array.isArray(e)){let n=[];for(let a of e){let u=md(a,r);if(u===null)return null;n.push(u)}return`a${n.length}:[${n.join(",")}]`}let o=Object.keys(e).sort(),t=[];for(let n of o){let a=md(e[n],r);if(a===null)return null;t.push(`${n.length}:${n}=${a}`)}return`o${t.length}:{${t.join(",")}}`}finally{r.delete(e)}}var My=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),Fy=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function pn(e){return typeof e!="object"||e===null?!1:Array.isArray(e)?e.some(pn):typeof e.$ref=="string"?!0:Object.entries(e).some(([r,i])=>My.has(r)?pn(i):!Fy.has(r)||typeof i!="object"||i===null?!1:Object.values(i).some(pn))}function wg(e){return e===1?"element":"elements"}function Gy(e,r){return z.transform(o=>o).check(o=>{let t=o.value;if(Array.isArray(t)){if(r.uniqueItems===!0){let n=new Map;for(let a=0;a<t.length;a++){let u=md(t[a],new Set);if(u===null)continue;let c=n.get(u);if(c===void 0){n.set(u,a);continue}o.issues.push({code:"custom",message:`Array items must be unique: element at index ${a} duplicates the one at index ${c}`,input:t,path:[a],continue:!0})}}if(r.containsSchema){let n=r.minContains??1,a=r.maxContains!==void 0?r.maxContains+1:Number.POSITIVE_INFINITY,u=0;for(let c of t)if(r.containsSchema.safeParse(c).success&&++u>=a)break;u<n&&o.issues.push({code:"custom",message:`Array must contain at least ${n} matching ${wg(n)}; found ${u}`,input:t,continue:!0}),r.maxContains!==void 0&&u>r.maxContains&&o.issues.push({code:"custom",message:`Array must contain at most ${r.maxContains} matching ${wg(r.maxContains)}`,input:t,continue:!0})}}}).pipe(e)}function xg(e,r){if(e!==!1)return e===void 0||e===!0?z.any():me(e,r)}var By=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function kg(e,r){if(e.not!==void 0){if(typeof e.not=="object"&&Object.keys(e.not).length===0)return z.never();throw new Error("not is not supported in Zod (except { not: {} } for never)")}if(e.unevaluatedItems!==void 0)throw new Error("unevaluatedItems is not supported");if(e.unevaluatedProperties!==void 0)throw new Error("unevaluatedProperties is not supported");if(e.if!==void 0||e.then!==void 0||e.else!==void 0)throw new Error("Conditional schemas (if/then/else) are not supported");if(e.dependentSchemas!==void 0||e.dependentRequired!==void 0)throw new Error("dependentSchemas and dependentRequired are not supported");if(e.$ref){let t=e.$ref;if(r.refs.has(t))return r.refs.get(t);if(r.processing.has(t))return z.lazy(()=>{if(!r.refs.has(t))throw new Error(`Circular reference not resolved: ${t}`);return r.refs.get(t)});r.processing.add(t);let n=Ly(t,r),a=me(n,r);return r.refs.set(t,a),r.processing.delete(t),a}if(e.enum!==void 0){let t=e.enum;if(r.version==="openapi-3.0"&&e.nullable===!0&&t.length===1&&t[0]===null)return z.null();if(t.length===0)return z.never();if(t.length===1)return z.literal(t[0]);if(t.every(a=>typeof a=="string"))return z.enum(t);let n=t.map(a=>z.literal(a));return n.length<2?n[0]:z.union([n[0],n[1],...n.slice(2)])}if(e.const!==void 0)return z.literal(e.const);let i=e.type;if(Array.isArray(i)){let t=i.map(n=>{let a={...e,type:n};return kg(a,r)});return t.length===0?z.never():t.length===1?t[0]:z.union(t)}if(!i)return z.any();let o;switch(i){case"string":{let t=z.string();if(e.format){let n=e.format;n==="email"?t=t.check(z.email()):n==="uri"||n==="uri-reference"?t=t.check(z.url()):n==="uuid"||n==="guid"?t=t.check(z.uuid()):n==="date-time"?t=t.check(z.iso.datetime({offset:!0})):n==="date"?t=t.check(z.iso.date()):n==="time"?t=t.check(z.regex(By)):n==="duration"?t=t.check(z.iso.duration()):n==="hostname"?t=t.check(z.hostname()):n==="ipv4"?t=t.check(z.ipv4()):n==="ipv6"?t=t.check(z.ipv6()):n==="mac"?t=t.check(z.mac()):n==="cidr"?t=t.check(z.cidrv4()):n==="cidr-v6"?t=t.check(z.cidrv6()):n==="base64"?t=t.check(z.base64()):n==="base64url"?t=t.check(z.base64url()):n==="e164"?t=t.check(z.e164()):n==="credit_card"?t=t.check(z.creditCard()):n==="iban"?t=t.check(z.iban()):n==="jwt"?t=t.check(z.jwt()):n==="emoji"?t=t.check(z.emoji()):n==="nanoid"?t=t.check(z.nanoid()):n==="cuid"?t=t.check(z.cuid()):n==="cuid2"?t=t.check(z.cuid2()):n==="ulid"?t=t.check(z.ulid()):n==="xid"?t=t.check(z.xid()):n==="ksuid"&&(t=t.check(z.ksuid()))}typeof e.minLength=="number"&&(t=t.min(e.minLength)),typeof e.maxLength=="number"&&(t=t.max(e.maxLength)),e.pattern&&(t=t.regex(new RegExp(e.pattern))),o=t;break}case"number":case"integer":{let t=i==="integer"?z.number().int():z.number();typeof e.minimum=="number"&&e.exclusiveMinimum!==!0&&(t=t.min(e.minimum)),typeof e.maximum=="number"&&e.exclusiveMaximum!==!0&&(t=t.max(e.maximum)),typeof e.exclusiveMinimum=="number"?t=t.gt(e.exclusiveMinimum):e.exclusiveMinimum===!0&&typeof e.minimum=="number"&&(t=t.gt(e.minimum)),typeof e.exclusiveMaximum=="number"?t=t.lt(e.exclusiveMaximum):e.exclusiveMaximum===!0&&typeof e.maximum=="number"&&(t=t.lt(e.maximum)),typeof e.multipleOf=="number"&&(t=t.multipleOf(e.multipleOf)),o=t;break}case"boolean":{o=z.boolean();break}case"null":{o=z.null();break}case"object":{let t={},n=e.properties||{},a=new Set(e.required||[]),u=typeof e.additionalProperties=="object"?me(e.additionalProperties,r):void 0;for(let[m,p]of Object.entries(n)){let f=me(p,r);re(t,m,a.has(m)?f:f.optional())}if(e.patternProperties){let m=e.patternProperties,p=Object.keys(m),f=[];for(let w of p){let x=me(m[w],r),P=z.string().regex(new RegExp(w));f.push(z.looseRecord(P,x))}let h=[];if(Object.keys(t).length>0&&h.push(z.object(t).passthrough()),h.push(...f),h.length===0)o=z.object({}).passthrough();else if(h.length===1)o=h[0];else{let w=z.intersection(h[0],h[1]);for(let x=2;x<h.length;x++)w=z.intersection(w,h[x]);o=w}if(e.additionalProperties===!1){let w=Object.keys(t),x=p.map(S=>new RegExp(S)),P=o;o=o.check(S=>{if(!ke(S.value))return;let j=[];for(let O of Object.keys(S.value))w.includes(O)||x.some(U=>U.test(O))||j.push(O);j.length&&S.issues.push({code:"unrecognized_keys",keys:j,input:S.value,inst:P})})}}else{let m=z.object(t);e.additionalProperties===!1?o=m.strict():u?o=m.catchall(u):o=m.passthrough()}let c=e.propertyNames!==void 0&&e.propertyNames!==!0,s=typeof e.minProperties=="number"?e.minProperties:void 0,d=typeof e.maxProperties=="number"?e.maxProperties:void 0;if(c||s!==void 0||d!==void 0){let m;if(c){let p=typeof e.propertyNames=="object"&&e.propertyNames.type===void 0?{type:"string",...e.propertyNames}:e.propertyNames;m=me(p,r)}o=Vy(o,{keySchema:m,minProperties:s,maxProperties:d})}break}case"array":{let t=e.prefixItems,n=e.items;if(t&&Array.isArray(t)){let a=typeof e.minItems=="number"?e.minItems:0,u=t.map(m=>me(m,r)),c=_g(u,a),s=Array.isArray(n)?void 0:xg(n,r),d=z.tuple(c);o=s?d.rest(s):d,typeof e.minItems=="number"&&(o=o.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(o=o.check(z.maxLength(e.maxItems)))}else if(Array.isArray(n)){let a=typeof e.minItems=="number"?e.minItems:0,u=n.map(m=>me(m,r)),c=_g(u,a),s=xg(e.additionalItems,r),d=z.tuple(c);o=s?d.rest(s):d,typeof e.minItems=="number"&&(o=o.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(o=o.check(z.maxLength(e.maxItems)))}else if(n!==void 0){let a=me(n,r),u=z.array(a);typeof e.minItems=="number"&&(u=u.min(e.minItems)),typeof e.maxItems=="number"&&(u=u.max(e.maxItems)),o=u}else o=z.array(z.any());(e.uniqueItems===!0||e.contains!==void 0)&&(o=Gy(o,{uniqueItems:e.uniqueItems===!0,containsSchema:e.contains!==void 0?me(e.contains,r):void 0,minContains:typeof e.minContains=="number"?e.minContains:void 0,maxContains:typeof e.maxContains=="number"?e.maxContains:void 0}));break}default:throw new Error(`Unsupported type: ${i}`)}return o}function me(e,r){if(typeof e=="boolean")return e?z.any():z.never();let i=kg(e,r),o=e.type||e.enum!==void 0||e.const!==void 0;if(e.anyOf&&Array.isArray(e.anyOf)){let u=e.anyOf.map(s=>me(s,r)),c=z.union(u);i=o?z.intersection(i,c):c}if(e.oneOf&&Array.isArray(e.oneOf)){let u=e.oneOf.map(s=>me(s,r)),c=z.xor(u);i=o?z.intersection(i,c):c}if(e.allOf&&Array.isArray(e.allOf))if(e.allOf.length===0)i=o?i:z.any();else{let u=o?i:me(e.allOf[0],r),c=o?0:1;for(let s=c;s<e.allOf.length;s++)u=z.intersection(u,me(e.allOf[s],r));i=u}e.nullable===!0&&r.version==="openapi-3.0"&&(i=z.nullable(i)),e.readOnly===!0&&(i=z.readonly(i)),e.default!==void 0&&(i=i.default(e.default));let t={},n=["$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor"];for(let u of n)u in e&&(t[u]=e[u]);let a=["contentEncoding","contentMediaType","contentSchema"];for(let u of a)u in e&&(t[u]=e[u]);if(e.type==="object"&&e.$ref===void 0){e.propertyNames!==void 0&&!pn(e.propertyNames)&&(t.propertyNames=e.propertyNames);for(let u of["minProperties","maxProperties"])e[u]!==void 0&&(t[u]=e[u])}if(e.type==="array"&&e.$ref===void 0){e.contains!==void 0&&!pn(e.contains)&&(t.contains=e.contains);for(let u of["uniqueItems","minContains","maxContains"])e[u]!==void 0&&(t[u]=e[u])}for(let u of Object.keys(e))Cy.has(u)||re(t,u,e[u]);return Object.keys(t).length>0&&r.registry.add(i,t),e.description&&(i=i.describe(e.description)),i}function Ig(e,r){if(typeof e=="boolean")return e?z.any():z.never();let i;try{i=JSON.parse(JSON.stringify(e))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}let o=Zy(i,r?.defaultTarget),t=i.$defs||i.definitions||{},n={version:o,defs:t,refs:new Map,processing:new Set,rootSchema:i,registry:r?.registry??ne};return me(i,n)}var Sg=Symbol("z.visit/resolving");function gn(e,r){let i=typeof r=="function"?r:(a,u)=>{let c=r[a._zod.def.type];return c?c(a,u):a},o=new Map;function t(a){let u=o.get(a);if(u===Sg)return new Mr({type:"lazy",getter:()=>o.get(a)});if(u!==void 0)return u;o.set(a,Sg);let c=n(a),s=i(c,c!==a);return o.set(a,s),s}function n(a){let u=a._zod.def,c=u.type;switch(c){case"object":{let s=u.shape,d=Object.keys(s),m=!1,p={};for(let h of d){let w=t(s[h]);w!==s[h]&&(m=!0),p[h]=w}let f=u.catchall;return u.catchall&&(f=t(u.catchall),f!==u.catchall&&(m=!0)),m?R(a,{...u,shape:p,catchall:f}):a}case"array":{let s=t(u.element);return s===u.element?a:R(a,{...u,element:s})}case"tuple":{let s=u.items,d=!1,m=[];for(let f of s){let h=t(f);h!==f&&(d=!0),m.push(h)}let p=u.rest;return u.rest&&(p=t(u.rest),p!==u.rest&&(d=!0)),d?R(a,{...u,items:m,rest:p}):a}case"record":case"map":{let s=t(u.keyType),d=t(u.valueType);return s===u.keyType&&d===u.valueType?a:R(a,{...u,keyType:s,valueType:d})}case"set":{let s=t(u.valueType);return s===u.valueType?a:R(a,{...u,valueType:s})}case"union":{let s=u.options,d=!1,m=[];for(let p of s){let f=t(p);f!==p&&(d=!0),m.push(f)}return d?R(a,{...u,options:m}):a}case"intersection":{let s=t(u.left),d=t(u.right);return s===u.left&&d===u.right?a:R(a,{...u,left:s,right:d})}case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":{let s=t(u.innerType);return s===u.innerType?a:R(a,{...u,innerType:s})}case"pipe":{let s=t(u.in),d=t(u.out);return s===u.in&&d===u.out?a:R(a,{...u,in:s,out:d})}case"function":{let s=t(u.input),d=t(u.output);return s===u.input&&d===u.output?a:R(a,{...u,input:s,output:d})}case"lazy":{let s=u.getter,{_cachedInner:d,...m}=u;return R(a,{...m,getter:()=>t(s())})}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":return a;default:return a}}return t(e)}function zg(e){return gn(e,{object:r=>r.partial(),union:r=>{let i=r._zod.def;return i.discriminator===void 0?r:sr(i.options)}})}function Jy(e,r){if(!r?.length)return e;let i=e._zod.def;return R(e,Pe(i,{checks:[...i.checks??[],...r]}),{parent:!0})}function Pg(e){return Jy(e.out,e.checks)}function Wy(e){return e.in._zod.traits.has("$ZodTransform")?Pg(e):e.in}function Tg(e){return gn(e,{pipe:r=>Wy(r._zod.def),default:(r,i)=>i?wt(r._zod.def.innerType):r,catch:(r,i)=>i?r._zod.def.innerType:r})}function Og(e){return gn(e,{pipe:r=>Pg(r._zod.def),prefault:(r,i)=>i?r._zod.def.innerType:r})}var fd={};Le(fd,{bigint:()=>qy,boolean:()=>Hy,date:()=>Yy,number:()=>Xy,string:()=>Ky});function Ky(e){return Uc(or,e)}function Xy(e){return Vc(ar,e)}function Hy(e){return Kc(ur,e)}function qy(e){return Hc(cr,e)}function Yy(e){return us(on,e)}var fe=l.strictObject({tabId:l.number().int().nonnegative().optional()}),pd=l.strictObject({stable:l.boolean(),stabilityWaitMs:l.number().finite().nonnegative(),lastMutationAgoMs:l.number().finite().nonnegative(),fontsReady:l.boolean(),pendingImages:l.number().int().nonnegative().max(1e6),timeoutReached:l.boolean()}),Dg=fe.extend({maxEntries:l.number().int().min(1).max(100).default(50),reset:l.boolean().default(!0)}),Qy=fe.extend({selector:l.string().min(1).max(2048),durationMs:l.number().int().min(500).max(3e4).default(3e3)}),xI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),highlighted:l.boolean()}),hn=l.strictObject({level:l.enum(["warn","error"]),message:l.string().max(512),timestamp:l.number().finite().nonnegative()}),gd=l.strictObject({url:l.url().max(1024),method:l.string().max(16),resourceType:l.string().max(32),status:l.number().int().min(100).max(599).optional(),error:l.string().max(128).optional(),timestamp:l.number().finite().nonnegative()}),kI=l.strictObject({tabId:l.number().int().nonnegative(),entries:l.array(hn).max(100),dropped:l.number().int().nonnegative(),forwardingDropped:l.number().int().nonnegative()}),II=l.strictObject({tabId:l.number().int().nonnegative(),entries:l.array(gd).max(100),dropped:l.number().int().nonnegative()}),vd=l.strictObject({url:l.url(),title:l.string().max(160),readyState:l.enum(["loading","interactive","complete"]),viewport:l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive()}),scroll:l.strictObject({x:l.number().finite(),y:l.number().finite()}),stabilityPending:l.boolean(),consoleInstrumentationActive:l.boolean(),consoleForwardingDropped:l.number().int().nonnegative()}),SI=vd.extend({tabId:l.number().int().nonnegative(),targetState:l.enum(["authorized","reauthorization_required","none"]),runtimeErrorCount:l.number().int().nonnegative(),consoleEntryCount:l.number().int().nonnegative(),networkFailureCount:l.number().int().nonnegative()}),bn=l.enum(["click","type","press_key","hover","scroll","select","focus"]),vn=fe.extend({selector:l.string().min(1).max(2048)}),e_=vn.extend({text:l.string().max(4096),clear:l.boolean().default(!0)}),t_=fe.extend({selector:l.string().min(1).max(2048).optional(),key:l.string().max(12).refine(e=>e.length===1||["Enter","Escape","Tab","Backspace","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(e)),shift:l.boolean().default(!1)}),r_=fe.extend({selector:l.string().min(1).max(2048).optional(),x:l.number().finite().min(-1e6).max(1e6).default(0),y:l.number().finite().min(-1e6).max(1e6).default(0),mode:l.enum(["by","to"]).default("by")}),n_=vn.extend({value:l.string().max(4096)}),zI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),action:bn,inputSource:l.literal("dom"),completed:l.literal(!0),scroll:l.strictObject({x:l.number().finite(),y:l.number().finite()}).optional()}),Ce=fe.extend({url:l.url().optional(),format:l.enum(["png","jpeg"]).default("jpeg"),quality:l.number().int().min(0).max(100).default(85),waitForStable:l.boolean().default(!1),includeOverlay:l.boolean().optional(),stableWindowMs:l.number().int().min(20).max(1e3).default(100),maxWaitMs:l.number().int().min(50).max(5e3).default(2e3)}),i_=fe.extend({bypassCache:l.boolean().default(!1)}),o_=Ce.extend({x:l.number().finite().nonnegative(),y:l.number().finite().nonnegative(),width:l.number().finite().positive().max(32768),height:l.number().finite().positive().max(32768)}),a_=Ce.extend({selector:l.string().min(1).max(2048),padding:l.number().finite().min(0).max(1e3).default(0)}),u_=Ce.extend({maxPixels:l.number().int().min(1).max(32e6).default(16e6),maxSegments:l.number().int().min(1).max(64).default(32),timeoutMs:l.number().int().min(500).max(8e3).default(7e3)}),c_=fe.extend({url:l.url()}),PI=l.strictObject({baseline:l.uuid().optional().describe("A prior PNG imageReference from this session. Omit and use referenceImagePath instead to diff against an external design reference."),referenceImagePath:l.string().min(1).max(4096).optional().describe("Path (relative to the MCP server's working directory, or absolute) to a local PNG design reference to diff the live capture against. Exactly one of baseline/referenceImagePath is required."),current:l.uuid().optional(),tabId:l.number().int().nonnegative().optional().describe("Only used with referenceImagePath when current is omitted, to select which tab to capture. Ignored otherwise (baseline's own tab is used)."),threshold:l.number().finite().min(0).max(1).default(.1),checkpoint:l.string().min(1).max(200).regex(/^[A-Za-z0-9_-]+$/).optional().describe("Visual Convergence best-so-far tracking id (e.g. 'hero-desktop'). Only meaningful together with referenceImagePath: persists the best-known result locally and objectively reports isBest/regressed on every call, independent of the agent's own assessment.")}),jg=l.enum(["mobile-small","mobile","tablet","desktop","desktop-wide"]),s_=fe.extend({profile:jg.optional(),width:l.number().int().min(200).max(8192).optional(),height:l.number().int().min(200).max(8192).optional(),dedicatedPreview:l.boolean().default(!0),close:l.boolean().optional().describe("Close the current dedicated preview window instead of creating or resizing one. Width/height/profile are ignored when true. Idempotent: has no effect if no preview is open.")}),TI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),windowId:l.number().int().nonnegative(),width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive(),zoom:l.number().finite().positive(),outerWidth:l.number().int().positive(),outerHeight:l.number().int().positive(),dedicatedPreview:l.boolean(),sourceTabId:l.number().int().nonnegative().optional(),requested:l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),profile:jg.optional()}).optional(),exact:l.boolean().optional(),attempts:l.number().int().min(0).max(3).optional(),requiresTargetSelection:l.boolean().optional(),sourceWindowUnchanged:l.boolean().optional(),previewClosed:l.boolean().optional().describe("Present when close:true was requested. True if a dedicated preview window was actually open and closed; false if there was none to close.")}),Ag=fe.extend({selector:l.string().min(1).max(2048).optional(),depth:l.number().int().min(0).max(8).default(3),maxNodes:l.number().int().min(1).max(300).default(100),textLength:l.number().int().min(0).max(300).default(160),maxBytes:l.number().int().min(2048).max(65536).default(32768)}),l_=Ag.extend({selector:l.string().min(1).max(2048)}),d_=fe.extend({maxRegions:l.number().int().min(1).max(100).default(50),reset:l.boolean().default(!0)}),m_=l.enum(["highlight","clear_highlight","capture_region","capture_element","capture_full_page","get_dom","get_element","get_changed_regions","get_viewport","set_viewport",...bn.options,"get_console","get_network_failures","get_page_status"]),Ng=l.strictObject({x:l.number().finite(),y:l.number().finite(),width:l.number().finite().nonnegative(),height:l.number().finite().nonnegative()}),f_=l.strictObject({index:l.number().int().nonnegative(),parent:l.number().int().nonnegative().optional(),depth:l.number().int().min(0).max(8),tag:l.string().max(80),id:l.string().max(160).optional(),classes:l.array(l.string().max(80)).max(6).optional(),role:l.string().max(80).optional(),text:l.string().max(300).optional(),ariaLabel:l.string().max(300).optional(),name:l.string().max(160).optional(),type:l.string().max(80).optional(),href:l.string().max(1024).optional(),bounds:Ng,visible:l.boolean(),redacted:l.boolean().optional(),disabled:l.boolean().optional(),checked:l.boolean().optional(),selected:l.boolean().optional()}),OI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),nodes:l.array(f_).max(300),truncated:l.boolean(),payloadBytes:l.number().int().max(65536)}),DI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),regions:l.array(Ng.extend({reason:l.enum(["mutation","resize","attribute","text"]),selector:l.string().max(240).optional()})).max(100),trackingStarted:l.boolean(),dropped:l.number().int().nonnegative(),coverage:l.literal("potential-dom-and-layout-changes")}),hd=l.strictObject({type:l.enum(["error","unhandledrejection","console-error"]),message:l.string().max(4096),source:l.string().max(2048).optional(),line:l.number().int().nonnegative().optional(),column:l.number().int().nonnegative().optional(),timestamp:l.number().nonnegative()}),Ug=l.strictObject({extensionVersion:l.string().max(80).optional(),extensionId:l.string().min(1).max(256).optional(),capabilities:l.array(m_).max(20).optional(),selectedTab:l.number().int().nonnegative().nullable(),url:l.string().max(2048).nullable(),targetState:l.enum(["none","authorized","reauthorization_required"]).optional(),browser:l.strictObject({name:l.enum(["firefox","chrome"]),version:l.string().max(80)}).optional(),backgroundCapture:l.strictObject({enabled:l.boolean(),permissionGranted:l.boolean()}).optional()}),Eg=l.discriminatedUnion("type",[l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("highlight"),payload:Qy}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("clear_highlight"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_console"),payload:Dg}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_network_failures"),payload:Dg}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_page_status"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("click"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("type"),payload:e_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("press_key"),payload:t_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("hover"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("scroll"),payload:r_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("select"),payload:n_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("focus"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_viewport"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("set_viewport"),payload:s_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_dom"),payload:Ag}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_element"),payload:l_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_changed_regions"),payload:d_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_region"),payload:o_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_element"),payload:a_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_full_page"),payload:u_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture"),payload:Ce}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("reload"),payload:i_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("navigate"),payload:c_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_errors"),payload:fe})]),jI=l.discriminatedUnion("ok",[l.strictObject({id:l.uuid(),version:l.literal(1),ok:l.literal(!0),result:l.unknown()}),l.strictObject({id:l.uuid(),version:l.literal(1),ok:l.literal(!1),error:l.strictObject({code:l.string().max(80),message:l.string().max(4096),stability:pd.optional()})})]),AI=l.strictObject({version:l.literal(1),type:l.literal("hello"),token:l.string().regex(/^[a-f0-9]{64}$/),state:Ug}),NI=l.strictObject({version:l.literal(1),type:l.literal("state"),state:Ug}),Cg=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),width:l.number().int().positive(),height:l.number().int().positive(),format:l.enum(["png","jpeg"]),captureMs:l.number().nonnegative(),processingMs:l.number().nonnegative().optional(),totalMs:l.number().nonnegative().optional(),segments:l.number().int().positive().max(64).optional(),scrollRestored:l.boolean().optional(),stabilityWaitMs:l.number().nonnegative().optional(),extensionTotalMs:l.number().nonnegative().optional(),renderAppearsStable:l.boolean().optional(),stable:l.boolean().optional(),lastMutationAgoMs:l.number().finite().nonnegative().optional(),fontsReady:l.boolean().optional(),pendingImages:l.number().int().nonnegative().optional(),timeoutReached:l.boolean().optional(),dataUrl:l.string().max(16*1024*1024)}),UI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url()}),EI=l.strictObject({tabId:l.number().int().nonnegative(),errors:l.array(hd).max(200)}),k=class extends Error{constructor(i,o,t){super(o);this.code=i;this.stability=t}};function Je(e,r=[]){let i=new URL(e);if(!["http:","https:"].includes(i.protocol)||i.username||i.password||!["localhost","127.0.0.1","[::1]"].includes(i.hostname)&&!r.includes(i.origin))throw new k("GS_URL_NOT_ALLOWED","Use a localhost URL or explicitly authorize this origin in both server and extension settings.")}function bd(e){let r=typeof e=="object"&&e!==null&&"message"in e?e.message:e;return String(r).slice(0,512)}function Zg(e,r){return e instanceof k?e:new k(r==="capture"?"GS_CAPTURE_FAILED":"GS_OPERATION_FAILED",`Firefox ${r}: ${bd(e)}`)}var Co=class{constructor(r,i,o,t,n,a){this.port=r;this.token=i;this.state=o;this.handler=t;this.status=n;this.keepaliveMs=a}socket;timer;keepalive;delay=250;stopped=!1;paired=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,clearTimeout(this.timer),clearInterval(this.keepalive),this.socket?.close(),this.status(!1)}async publish(){this.paired&&this.socket?.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify({version:1,type:"state",state:await this.state()}))}async connect(){if(this.stopped)return;let r=new WebSocket(`ws://127.0.0.1:${this.port}`);this.socket=r,this.paired=!1;let i=setTimeout(()=>r.close(),4e3);r.onopen=()=>{this.state().then(t=>{r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({version:1,type:"hello",token:this.token,state:t}))})};let o=Promise.resolve();r.onmessage=t=>{o=o.then(async()=>{try{if(typeof t.data!="string"||t.data.length>32768)throw new Error("Invalid message");let n=JSON.parse(t.data);if(!this.paired){if(JSON.stringify(n)!==JSON.stringify({version:1,type:"paired"}))throw new Error("Pairing failed");this.paired=!0,clearTimeout(i),this.delay=250,this.status(!0),this.keepaliveMs&&(this.keepalive=setInterval(()=>{this.publish().catch(()=>{})},this.keepaliveMs));return}let a=Eg.parse(n),u;try{u={id:a.id,version:1,ok:!0,result:await this.handler(a)}}catch(c){let s=Zg(c,a.type);u={id:a.id,version:1,ok:!1,error:{code:s.code,message:s.message,...s.stability?{stability:s.stability}:{}}}}r.readyState===WebSocket.OPEN&&r.send(JSON.stringify(u))}catch{r.close(1008,"Invalid message")}})},r.onerror=()=>r.close(),r.onclose=()=>{clearTimeout(i),clearInterval(this.keepalive),this.paired=!1,this.stopped||this.status(!1),this.stopped||(this.timer=setTimeout(()=>void this.connect(),this.delay),this.delay=Math.min(this.delay*2,5e3))}}};var Zo=class{selectedTab=null;selectedOrigin=null;state="none";generation=0;choose(r,i){this.selectedTab=r,this.selectedOrigin=i?new URL(i).origin:null,this.state="authorized",this.generation++}reauthorize(r){r===this.selectedTab&&(this.state="reauthorization_required",this.generation++)}refresh(r){r===this.selectedTab&&this.generation++}resume(r){r===this.selectedTab&&this.state==="reauthorization_required"&&(this.state="authorized")}assertAuthorized(r){if(r!==this.selectedTab)throw new k("GS_TARGET_MISMATCH","The requested tab is not the target explicitly selected in GazeSight.");if(this.state!=="authorized")throw new k("GS_REAUTHORIZE_TARGET","Click the GazeSight extension icon or use the configured selection shortcut (default Ctrl+Shift+Y) in the target tab to grant Firefox permission for this document.")}assertAuthorizedUrl(r,i){if(this.assertAuthorized(r),this.selectedOrigin!==null&&new URL(i).origin!==this.selectedOrigin)throw new k("GS_REAUTHORIZE_TARGET","The target moved to a different origin. Select it again before GazeSight accesses it.")}isSelectedOrigin(r){try{return this.selectedOrigin!==null&&new URL(r).origin===this.selectedOrigin}catch{return!1}}remove(r){this.selectedTab===r&&(this.selectedTab=null,this.selectedOrigin=null,this.state="none",this.generation++)}resolve(r){let i=r??this.selectedTab;if(i===null)throw new k("GS_NO_TARGET_TAB","Open your preview page in Firefox and click the GazeSight icon.");return i}};async function $d(e){try{return await e()}catch(r){throw p_(r)}}function p_(e){let r=bd(e),i=/activeTab|<all_urls>|permission/i.test(r);return new k(i?"GS_PERMISSION_DENIED":"GS_CAPTURE_FAILED",`Firefox captureVisibleTab: ${r}${i?" Click the GazeSight icon or use the configured selection shortcut (default Ctrl+Shift+Y) in the selected tab to grant activeTab again.":""}`)}var $n=class{constructor(r,i,o){this.nativeCapture=r;this.contentOperation=i;this.services=o}capture(r){return this.nativeCapture(r)}executeContentOperation(r){return this.contentOperation(r)}getTarget(r){return browser.tabs.get(r)}async reload(r,i){await browser.tabs.reload(r,{bypassCache:i})}async navigate(r,i){await browser.tabs.update(r,{url:i})}getViewport(r){return this.services.getViewport(r)}resizePreview(...r){return this.services.resizePreview(...r)}getDiagnostics(r){return this.services.getDiagnostics(r)}};var Rg=l.discriminatedUnion("op",[l.strictObject({op:l.literal("metrics")}),l.strictObject({op:l.literal("begin")}),l.strictObject({op:l.literal("restore"),lease:l.uuid()}),l.strictObject({op:l.literal("scroll"),lease:l.uuid(),x:l.number().finite().nonnegative(),y:l.number().finite().nonnegative()}),l.strictObject({op:l.literal("element"),lease:l.uuid(),selector:l.string().min(1).max(2048),padding:l.number().min(0).max(1e3)})]);async function yd(e,r,i,o,t,n,a=()=>performance.now()){e.assertAuthorized(r);let u=a()+5e3;e.reauthorize(r);let c=e.generation,s=()=>{if(a()>=u)throw new k("GS_TIMEOUT","Navigation preparation exceeded its bounded deadline; no navigation was issued.");if(e.selectedTab!==r||e.generation!==c||e.state!=="reauthorization_required")throw new k("GS_TARGET_CHANGED","The target changed before navigation; no navigation was issued.")};await o(),s();let d=await t();if(s(),d!==i)throw new k("GS_TARGET_CHANGED","The document changed before navigation; no navigation was issued.");await n()}function _d(e,r,i){if(![e.x,e.y,e.width,e.height,r.width,r.height,i.width,i.height].every(Number.isFinite)||r.width<=0||r.height<=0||e.width<=0||e.height<=0||e.x<0||e.y<0||e.x+e.width>r.width+.5||e.y+e.height>r.height+.5)throw new k("GS_REGION_OUT_OF_VIEWPORT","The complete region must fit inside the current CSS viewport.");let o=i.width/r.width,t=i.height/r.height,n=Math.floor(e.x*o),a=Math.floor(e.y*t);return{x:n,y:a,width:Math.min(i.width,Math.ceil((e.x+e.width)*o))-n,height:Math.min(i.height,Math.ceil((e.y+e.height)*t))-a}}function Lg(e,r,i,o,t,n=0){if(![e,r,i,o].every(u=>Number.isFinite(u)&&u>0)||e>32768||r>32768)throw new k("GS_CAPTURE_LIMIT","Page dimensions exceed the capture limits.");if(i=e>i?Math.max(1,i-n*2):i,o=r>o?Math.max(1,o-n*2):o,Math.ceil(e/i)*Math.ceil(r/o)>t)throw new k("GS_CAPTURE_LIMIT","Page requires too many capture segments.");let a=[];for(let u=0;u<r;u+=o)for(let c=0;c<e;c+=i)a.push({x:c,y:u,width:Math.min(i,e-c),height:Math.min(o,r-u)});return a}var dr=l.object({width:l.number().finite().positive(),height:l.number().finite().positive(),pageWidth:l.number().finite().positive(),pageHeight:l.number().finite().positive(),x:l.number().finite(),y:l.number().finite(),devicePixelRatio:l.number().finite().positive()}),Vg=dr.extend({lease:l.uuid()}),Mg=dr.extend({rect:l.object({x:l.number(),y:l.number(),width:l.number().positive(),height:l.number().positive()})});async function Fg(e,r,i){let o=performance.now(),t=r.payload,n=o+(r.type==="capture_full_page"?r.payload.timeoutMs:7e3);async function a(O){let U=n-performance.now();if(U<=0)throw new k("GS_TIMEOUT","Capture suite deadline reached.");let T;try{return await Promise.race([O(),new Promise((F,ae)=>{T=setTimeout(()=>ae(new k("GS_TIMEOUT","Capture suite deadline reached.")),U)})])}finally{clearTimeout(T)}}let u=O=>a(()=>e.executeContentOperation(O)),c=Ce.parse({tabId:t.tabId,url:t.url,format:t.format,quality:t.quality,waitForStable:t.waitForStable,stableWindowMs:t.stableWindowMs,maxWaitMs:t.maxWaitMs,includeOverlay:t.includeOverlay}),s=0,d=0,m=0,p=0,f,h=!0,w,x,P;async function S(){let O=Cg.parse(await a(()=>e.capture(c)));if(s+=O.captureMs,p+=O.stabilityWaitMs??0,m++,w??=O,!new RegExp(`^data:image/${O.format};base64,[A-Za-z0-9+/]+={0,2}$`).test(O.dataUrl))throw new k("GS_CAPTURE_FAILED","Native capture returned an invalid image data URL.");let U=performance.now(),T=await a(async()=>{let F=await createImageBitmap(await(await fetch(O.dataUrl)).blob());if(performance.now()>n)throw F.close(),new k("GS_TIMEOUT","Image decoding exceeded the capture deadline.");return F});return d+=performance.now()-U,T}function j(O,U,T=16e6){if(!Number.isFinite(O*U)||O<1||U<1||O>32768||U>32768||O*U>T)throw new k("GS_CAPTURE_LIMIT","Output image exceeds the pixel/memory limit.");return x=i.createSurface(O,U),x}try{if(r.type==="capture_full_page"){let T=Vg.parse(await u({op:"begin"}));f=T.lease;let F=Lg(T.pageWidth,T.pageHeight,T.width,T.height,r.payload.maxSegments,1),ae,_e=0,ge=0;for(let J of F){let ue=dr.parse(await u({op:"scroll",lease:f,x:Math.max(0,J.x-1),y:Math.max(0,J.y-1)}));if(ue.pageWidth!==T.pageWidth||ue.pageHeight!==T.pageHeight||ue.width!==T.width||ue.height!==T.height)throw new k("GS_PAGE_CHANGED","Page dimensions changed during capture; infinite or dynamic pages are not stitched.");let Re=await S();try{let cv=performance.now();if(ae||(_e=Re.width/ue.width,ge=Re.height/ue.height,ae=j(Math.ceil(T.pageWidth*_e),Math.ceil(T.pageHeight*ge),r.payload.maxPixels)),Math.abs(Re.width/ue.width-_e)>.001||Math.abs(Re.height/ue.height-ge)>.001)throw new k("GS_TARGET_CHANGED","Capture scale changed during stitching.");let Tn=_d({x:J.x-ue.x,y:J.y-ue.y,width:J.width,height:J.height},ue,Re),Od=Math.floor(J.x*_e),Dd=Math.floor(J.y*ge),sv=Math.ceil((J.x+J.width)*_e)-Od,lv=Math.ceil((J.y+J.height)*ge)-Dd;ae.drawImage(Re,Tn.x,Tn.y,Tn.width,Tn.height,Od,Dd,sv,lv),d+=performance.now()-cv}finally{Re.close()}let Pn=dr.parse(await u({op:"metrics"}));if(Pn.pageWidth!==T.pageWidth||Pn.pageHeight!==T.pageHeight||Math.abs(Pn.x-ue.x)>.5||Math.abs(Pn.y-ue.y)>.5)throw new k("GS_PAGE_CHANGED","Page size or scroll changed during native capture.")}}else{let T,F;if(r.type==="capture_element"){f=Vg.parse(await u({op:"begin"})).lease;let J=Mg.parse(await u({op:"element",lease:f,selector:r.payload.selector,padding:r.payload.padding}));T=J,F=J.rect}else T=dr.parse(await u({op:"metrics"})),F=r.payload;let ae=await S();try{let ge=performance.now(),J=_d(F,T,ae);j(J.width,J.height).drawImage(ae,J.x,J.y,J.width,J.height,0,0,J.width,J.height),d+=performance.now()-ge}finally{ae.close()}let _e=dr.parse(await u({op:"metrics"}));if(T.width!==_e.width||T.height!==_e.height||T.x!==_e.x||T.y!==_e.y)throw new k("GS_TARGET_CHANGED","Viewport or scroll changed during capture.");if(r.type==="capture_element"){let ge=Mg.parse(await u({op:"element",lease:f,selector:r.payload.selector,padding:r.payload.padding}));if(JSON.stringify(ge.rect)!==JSON.stringify(F))throw new k("GS_PAGE_CHANGED","Element geometry changed during capture.")}}if(!x||!w)throw new k("GS_CAPTURE_FAILED","No capture segments produced.");let O=performance.now(),U=await x.encode(t.format,t.quality);if(d+=performance.now()-O,U.length>16*1024*1024)throw new k("GS_CAPTURE_LIMIT","Encoded image exceeds the bridge payload limit.");if(performance.now()>n)throw new k("GS_TIMEOUT","Local image processing exceeded the capture deadline.");return P={...w,width:x.width,height:x.height,dataUrl:U,segments:m,captureMs:s,processingMs:d,stabilityWaitMs:p,extensionTotalMs:performance.now()-o,totalMs:performance.now()-o,scrollRestored:h},P}finally{if(f){let O;try{if(h=l.object({scrollRestored:l.boolean()}).parse(await Promise.race([e.executeContentOperation({op:"restore",lease:f}),new Promise((T,F)=>{O=setTimeout(()=>F(new k("GS_SCROLL_RESTORE_FAILED","Scroll restoration timed out; content watchdog remains active.")),500)})])).scrollRestored,!h)throw new k("GS_SCROLL_RESTORE_FAILED","The original scroll position could not be restored.")}finally{clearTimeout(O)}}x&&x.dispose(),P&&Object.assign(P,{scrollRestored:h,totalMs:performance.now()-o,extensionTotalMs:performance.now()-o})}}var Ro=class{createSurface(r,i){let o=document.createElement("canvas");o.width=r,o.height=i;let t=o.getContext("2d");if(!t)throw new k("GS_CAPTURE_FAILED","Unable to allocate local image processing surface.");return{width:r,height:i,drawImage:(n,a,u,c,s,d,m,p,f)=>t.drawImage(n,a,u,c,s,d,m,p,f),encode:async(n,a)=>o.toDataURL(`image/${n}`,a/100),dispose:()=>{o.width=0,o.height=0}}}};var g_={"mobile-small":{width:320,height:568},mobile:{width:390,height:844},tablet:{width:768,height:1024},desktop:{width:1440,height:900},"desktop-wide":{width:1920,height:1080}},hS=l.strictObject({op:l.literal("measure")}),v_=l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive()});function h_(e){let r=e.profile?g_[e.profile]:void 0,i=e.width??r?.width,o=e.height??r?.height;if(!i||!o)throw new k("GS_INVALID_VIEWPORT","Provide a profile or both width and height in CSS pixels.");return{width:i,height:o,...e.profile?{profile:e.profile}:{}}}function b_(e,r,i,o){if(!i.width||!i.height||!Number.isFinite(o)||o<=0)throw new k("GS_VIEWPORT_FAILED","Window dimensions or zoom are unavailable.");return{width:Math.max(200,Math.min(8192,Math.round(i.width+(e.width-r.width)*o))),height:Math.max(200,Math.min(8192,Math.round(i.height+(e.height-r.height)*o)))}}function $_(e,r){return["width","height","left","top","state"].every(i=>e[i]===r[i])}function Gg(e,r){if(e.tabs?.length!==1||e.tabs[0].id!==r)throw new k("GS_PREVIEW_IN_USE","The preview now contains other tabs; GazeSight will not resize it.")}function y_(e){if(e.cookieStoreId&&e.cookieStoreId!=="firefox-default"&&e.cookieStoreId!=="firefox-private")throw new k("GS_PREVIEW_CONTEXT_UNSUPPORTED","A dedicated preview cannot preserve this Firefox container without additional permissions. Use the selected window explicitly instead.");return{incognito:!!(e.incognito||e.cookieStoreId==="firefox-private")}}var Lo=class{preview;async get(r){let i=wd(r),o=await browser.tabs.sendMessage(r.id,{type:"gazesight-viewport-content",operation:{op:"measure"}},{frameId:0});if(!o?.ok)throw new k("GS_VIEWPORT_FAILED","Viewport measurement unavailable; select the target again.");let t=v_.parse(o.value),n=await browser.windows.get(i),a=await browser.tabs.getZoom(r.id);return{tabId:r.id,url:r.url,windowId:i,...t,zoom:a,outerWidth:n.width,outerHeight:n.height,dedicatedPreview:!!(this.preview&&this.preview.tabId===r.id),...this.preview&&this.preview.tabId===r.id?{sourceTabId:this.preview.sourceTabId}:{}}}async close(r,i){await i();let o=!!this.preview;if(this.preview){let n=this.preview.windowId;this.preview=void 0,await browser.windows.remove(n).catch(()=>{})}return{...await this.get(r),previewClosed:o}}async set(r,i,o){if(i.close)return this.close(r,o);let t=h_(i),n=wd(r),a=i.dedicatedPreview&&this.preview&&this.preview.tabId===r.id?this.preview.sourceWindowId:n,u=await browser.windows.get(a).catch(()=>{}),c=r,s=!1,d=!1;if(i.dedicatedPreview){if(this.preview){let x=await browser.windows.get(this.preview.windowId,{populate:!0}).catch(()=>{});if(!x)this.preview=void 0;else{if(Gg(x,this.preview.tabId),r.id!==this.preview.tabId&&(r.id!==this.preview.sourceTabId||r.cookieStoreId!==this.preview.cookieStoreId))throw new k("GS_PREVIEW_IN_USE","An existing preview belongs to another source. Close that preview before creating a different one.");if(c=await browser.tabs.get(this.preview.tabId),r.id===this.preview.sourceTabId&&r.url!==this.preview.url&&(await o(),await browser.tabs.update(this.preview.tabId,{url:r.url}),this.preview.url=r.url,d=!0),t.width<500&&r.id===this.preview.tabId&&x.type!=="popup"){await o();let P={...this.preview},S=await browser.windows.create({tabId:P.tabId,type:"popup",focused:!0,width:Math.min(8192,t.width+32),height:Math.min(8192,t.height+120),titlePreface:"GazeSight Preview | "});if(S.id===void 0)throw new k("GS_VIEWPORT_FAILED","Firefox did not return the compact preview window.");this.preview={...P,windowId:S.id},c=await browser.tabs.get(P.tabId),s=!0}}}if(!this.preview){let x=y_(r);await o();let P=await browser.windows.create({url:r.url,type:t.width<500?"popup":"normal",focused:!0,width:Math.min(8192,t.width+32),height:Math.min(8192,t.height+120),...x,titlePreface:"GazeSight Preview | "}),S=P.tabs?.[0];if(P.id===void 0||S?.id===void 0)throw new k("GS_VIEWPORT_FAILED","Firefox did not return a preview tab.");this.preview={windowId:P.id,tabId:S.id,sourceTabId:r.id,sourceWindowId:n,cookieStoreId:r.cookieStoreId,url:r.url},c=S,d=!0}}let m,p,f;for(let x=0;x<20;x++){await o();let P=await browser.tabs.get(c.id);if(P.status==="complete"&&P.url!==r.url)throw new k("GS_TARGET_CHANGED","The preview navigated away from its source URL.");if(c=P,c.status==="complete"){if(d){try{await browser.tabs.executeScript?.(c.id,{file:"content.js",runAt:"document_start"})}catch(S){p=S}d=!1}try{m=await this.get(c);break}catch(S){f=S}}await new Promise(S=>setTimeout(S,100))}if(!m){let x=p??f;throw new k("GS_VIEWPORT_FAILED","Preview created but its measured viewport is unavailable."+(x?` ${p?"Injection":"Measurement"} error: ${String(x?.message??x)}`:""))}let h=0;for(;h<3&&(m.width!==t.width||m.height!==t.height);h++){await o();let x=wd(c),P=await browser.windows.get(x,{populate:!0});i.dedicatedPreview&&Gg(P,c.id);let S=b_(t,m,P,m.zoom);await browser.windows.update(x,{state:"normal"}),await o(),await browser.windows.update(x,S),await new Promise(O=>setTimeout(O,150)),await o();let j=await browser.tabs.get(c.id);if(j.url!==r.url)throw new k("GS_TARGET_CHANGED","The preview navigated during resize.");m=await this.get(j)}let w=await browser.windows.get(a).catch(()=>{});return{...m,movedToCompact:s,requested:t,exact:m.width===t.width&&m.height===t.height,attempts:h,...u&&w?{sourceWindowUnchanged:$_(u,w)}:{}}}removeWindow(r){this.preview?.windowId===r&&(this.preview=void 0)}previewSourceTabId(r){return this.preview&&this.preview.tabId===r?this.preview.sourceTabId:void 0}currentPreviewTabId(){return this.preview?.tabId}clear(){this.preview=void 0}};function wd(e){if(e.id===void 0||e.windowId===void 0||!e.url)throw new k("GS_VIEWPORT_FAILED","Firefox tab identity or window is unavailable.");return e.windowId}var __="gazesight-select-target";async function Bg(e,r){if(e!==__)return;let i=r??(await browser.tabs.query({active:!0,lastFocusedWindow:!0}))[0];if(!(i?.id===void 0||i.active!==!0))return i}function Ze(e,r){return e.slice(0,4096).replace(/https?:\/\/[^\s"'<>]+/gi,i=>{try{let o=new URL(i);return o.origin+o.pathname}catch{return"[redacted URL]"}}).replace(/(?:bearer\s+)[\w.+/=-]+/gi,"[redacted]").replace(/\beyJ[\w-]+\.[\w-]+(?:\.[\w-]+)?/g,"[redacted]").replace(/\b[a-zA-Z0-9_+/-]{24,}={0,2}\b/g,"[redacted]").replace(/((?:password|passwd|token|secret|credential|api[-_]?key|authorization)["']?\s*[:=]\s*["']?)[^\s,;"']+/gi,"$1[redacted]").replace(/\s+/g," ").trim().slice(0,r)}function yn(e,r){try{let i=new URL(e,r);return["http:","https:"].includes(i.protocol)?(i.origin+i.pathname.split("/").map(o=>Ze(o,200)).join("/")).slice(0,1024):void 0}catch{return}}var kS=l.strictObject({op:l.enum(["status","stop"])}),IS=l.discriminatedUnion("type",[l.strictObject({namespace:l.literal("gazesight-console"),type:l.literal("entry"),entry:hn}),l.strictObject({namespace:l.literal("gazesight-console"),type:l.enum(["ready","stopped"])})]),_n=class{entries=[];dropped=0;get count(){return this.entries.length}push(r){this.entries.length===100&&(this.entries.shift(),this.dropped++),this.entries.push(r)}clear(){this.entries=[],this.dropped=0}read(r,i){let o=Math.max(1,Math.min(100,Math.floor(r))),t={entries:this.entries.slice(-o),dropped:this.dropped+Math.max(0,this.entries.length-o)};return i&&this.clear(),t}};function Jg(e){if(!e.error&&!(e.statusCode!==void 0&&e.statusCode>=400&&e.statusCode<=599))return;let r=yn(e.url,e.url);if(r)return gd.parse({url:r,method:Ze(e.method,16),resourceType:Ze(e.type,32),timestamp:e.timeStamp,...e.statusCode!==void 0?{status:e.statusCode}:{},...e.error?{error:/^NS_ERROR_[A-Z_]{1,96}$/.test(e.error)?e.error:Ze(e.error,128)}:{}})}var Wg=l.strictObject({type:l.literal("gazesight-ui"),action:l.enum(["status","select","disconnect","fast","stable","diagnostics","background-enable","background-denied","background-disable","continuous-enable","continuous-denied","continuous-disable"])});function Kg(e,r,i,o){return e?r==="none"?"WAIT":r==="reauthorization_required"?"AUTH":i?"WAIT":o?"ERR":"ON":"OFF"}function xd(e,r,i,o=!1){if(e.id!==r||!o&&e.tab||!e.url)return!1;try{let t=new URL(e.url),n=new URL(i);return t.origin===n.origin&&t.pathname===n.pathname}catch{return!1}}var Xg="0.5.2";async function Hg(e){if(e.tabId!==e.targetTabId)throw new k("GS_TARGET_MISMATCH","The requested tab is not the target explicitly selected in GazeSight.");let r=e.backgroundMode==="enabled"&&e.permissionGranted,i=await e.currentTarget();if(i.id!==e.tabId||i.url!==e.url||e.currentGeneration()!==e.generation)throw new k("GS_TARGET_CHANGED","The target changed before capture.");if(!r&&!i.active)throw new k("GS_CAPTURE_FAILED","Bring the authorized target tab to the front.");let o=await(r?e.background():e.foreground()),t=await e.currentTarget();if(t.id!==e.tabId||t.url!==e.url||e.currentGeneration()!==e.generation)throw new k("GS_TARGET_CHANGED","The target changed during capture.");if(!r&&!t.active)throw new k("GS_CAPTURE_FAILED","The active tab changed during capture.");return o}function wn(e){return String(e).padStart(2,"0")}function w_(e=new Date){return`GazeSight/gazesight-${e.getFullYear()}-${wn(e.getMonth()+1)}-${wn(e.getDate())}_${wn(e.getHours())}-${wn(e.getMinutes())}-${wn(e.getSeconds())}.png`}var Vo=class{busy=!1;async run(r){if(this.busy)throw new k("GS_CAPTURE_BUSY","A manual screenshot is already in progress.");this.busy=!0;try{if(!await r.permissionGranted())throw new k("GS_PERMISSION_DENIED","Download permission required.");let i=await r.capture();if(i.format!=="png"||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(i.dataUrl))throw new k("GS_CAPTURE_FAILED","Capture failed to produce a PNG image.");let o=w_(r.now),t;try{if(t=await r.download({url:i.dataUrl,filename:o,saveAs:!1,conflictAction:"uniquify"}),!await r.waitForCompletion(t))throw new Error("interrupted")}catch{throw new k("GS_DOWNLOAD_FAILED","Download failed.")}return{filename:o,downloadId:t}}finally{this.busy=!1}}};function kd(e,r,i,o){if(!i.enabled||!i.hostPermissionGranted)return!1;let t=o(e);return t!==void 0&&t===r.selectedTab&&r.state==="authorized"}function qg(e,r,i,o,t){return kd(e,i,o,t)&&i.isSelectedOrigin(r)}function Yg(e,r){if(r===null)return!1;try{return new URL(e).origin===r}catch{return!1}}var _=new Zo,fr=new Lo,x_=new Ro,ze=new Map,pr=new _n,gr=new _n,X,We=[],je=!1,mr=null,kn=!1,Sd=!1,In=!1,oe="disabled",M=!1,te=!1,k_=new Vo;function ev(e){return kd(e,_,{enabled:te,hostPermissionGranted:M},r=>fr.previewSourceTabId(r))}function I_(e,r){return qg(e,r,_,{enabled:te,hostPermissionGranted:M},i=>fr.previewSourceTabId(i))}function Q(e){ev(e)||_.assertAuthorized(e)}function tv(e,r){I_(e,r)||_.assertAuthorizedUrl(e,r)}function S_(e){return e===_.selectedTab?_.state==="authorized":ev(e)}async function z_(e){let r=Date.now()+15e3;for(;Date.now()<r;){let[i]=await browser.downloads.search({id:e});if(i?.state==="complete")return!0;if(i?.state==="interrupted")return!1;await new Promise(o=>setTimeout(o,100))}return!1}var rv,nv,iv={getViewport:e=>fr.get(e),resizePreview:(...e)=>fr.set(...e),getDiagnostics:T_},H=new $n(async e=>{let r=_.resolve(e.tabId);Q(r);let i=_.generation,o=await H.getTarget(r);if(tv(r,o.url??""),i!==_.generation)throw new k("GS_TARGET_CHANGED","The target changed before native capture.");Je(o.url??"",We);let t=o.windowId;if(t===void 0)throw new k("GS_CAPTURE_FAILED","The authorized target window is unavailable.");return Hg({tabId:r,targetTabId:r,generation:i,currentGeneration:()=>_.generation,url:o.url??"",currentTarget:()=>H.getTarget(r),backgroundMode:oe,permissionGranted:M,foreground:()=>$d(()=>browser.tabs.captureVisibleTab(t,{format:e.format,quality:e.quality})),background:()=>$d(()=>browser.tabs.captureTab(r,{format:e.format,quality:e.quality}))})},async e=>{let r=_.resolve();Q(r);let i=await browser.tabs.sendMessage(r,{type:"gazesight-capture-content",operation:Rg.parse(e)},{frameId:0});if(!i?.ok)throw new k("GS_CAPTURE_FAILED","Fixed content operation failed.");return i.value},iv);async function P_(){let e=await browser.runtime.getBrowserInfo(),r={extensionVersion:Xg,extensionId:browser.runtime.id,capabilities:["highlight","clear_highlight","capture_region","capture_element","capture_full_page","get_dom","get_element","get_changed_regions","get_viewport","set_viewport",...bn.options,"get_console","get_network_failures","get_page_status"],targetState:_.state,browser:{name:"firefox",version:e.version},backgroundCapture:{enabled:oe==="enabled",permissionGranted:M}};if(_.selectedTab===null)return{selectedTab:null,url:null,...r};try{let i=await H.getTarget(_.selectedTab);return{selectedTab:_.selectedTab,url:i.url??null,...r}}catch{return _.remove(_.selectedTab),{selectedTab:null,url:null,...r,targetState:_.state}}}var Id=Promise.resolve(),xn;function pe(){let e={text:Kg(je,_.state,Sd,In),color:je&&_.state==="authorized"?"#15734b":"#8c5321",title:_.state==="reauthorization_required"?"GazeSight: click in the target tab to reauthorize this document":"GazeSight: use this tab"};return Id=Id.catch(()=>{}).then(async()=>{try{let r=await Promise.allSettled([xn?.text!==e.text?Promise.resolve().then(()=>browser.browserAction.setBadgeText({text:e.text})):void 0,xn?.color!==e.color?Promise.resolve().then(()=>browser.browserAction.setBadgeBackgroundColor({color:e.color})):void 0,xn?.title!==e.title?Promise.resolve().then(()=>browser.browserAction.setTitle({title:e.title})):void 0]);for(let i of r)if(i.status==="rejected")throw i.reason;xn=e}catch(r){throw xn=void 0,r}}),Id}async function Mo(e){await browser.tabs.executeScript(e,{file:"content.js",runAt:"document_start"}).catch(()=>{}),je&&_.selectedTab===e&&_.state==="authorized"&&(await browser.scripting.executeScript({target:{tabId:e,frameIds:[0]},files:["diagnostics-page.js"],world:"MAIN",injectImmediately:!0}).catch(()=>{}),!je||_.selectedTab!==e||_.state!=="authorized"?await Fo(e):await at(e))}async function T_(e){let r=await browser.tabs.sendMessage(e,{type:"gazesight-diagnostics-content",operation:{op:"status"}},{frameId:0});if(!r?.ok)throw new k("GS_DIAGNOSTICS_UNAVAILABLE","Select the target again to initialize diagnostics.");return vd.parse(r.value)}async function Fo(e){await Sn(e,{op:"clear"}).catch(()=>{}),await vr(e,{op:"set",state:"none"}),mr===e&&(mr=null),await browser.tabs.sendMessage(e,{type:"gazesight-diagnostics-content",operation:{op:"stop"}},{frameId:0}).catch(()=>{})}async function Sn(e,r){let i=await browser.tabs.sendMessage(e,{type:"gazesight-overlay-content",operation:r},{frameId:0});if(!i?.ok)throw new k(i?.code??"GS_HIGHLIGHT_UNAVAILABLE","The overlay operation was refused or unavailable.");return i.value===!0}function O_(e){return e?oe==="enabled"&&M?"background":"authorized":"none"}async function vr(e,r){await browser.tabs.sendMessage(e,{type:"gazesight-target-indicator-content",operation:r}).catch(()=>{})}async function at(e){await vr(e,{op:"set",state:O_(_.state==="authorized"&&_.selectedTab===e)})}function zn(){pr.clear(),gr.clear()}function ov(e){if(!(!je||_.state!=="authorized"||e.tabId!==_.selectedTab||!_.isSelectedOrigin(e.url)))try{Je(e.url,We);let r=Jg(e);r&&gr.push(r)}catch{}}browser.webRequest.onCompleted.addListener(ov,{urls:["http://*/*","https://*/*"]});browser.webRequest.onErrorOccurred.addListener(ov,{urls:["http://*/*","https://*/*"]});async function D_(e){let r=e.payload.tabId;if(r===void 0&&e.type.startsWith("capture")&&"url"in e.payload&&e.payload.url){let o=e.payload.url,t=(await browser.tabs.query({})).filter(n=>n.url===o);if(t.length!==1)throw new k("GS_TAB_NOT_FOUND","Provide a tabId or a URL matching exactly one open Firefox tab.");r=t[0].id}r=_.resolve(r),Q(r);let i;try{i=await H.getTarget(r)}catch{throw new k("GS_TAB_NOT_FOUND","The Firefox tab was closed. Select a new target.")}return Je(i.url??"",We),tv(r,i.url??""),i}async function av(e){let r=await D_(e),i=r.id;if(e.type==="highlight"||e.type==="clear_highlight"){if(Q(i),kn)throw new k("GS_CAPTURE_BUSY","Wait for the current capture before changing its overlay.");let o=_.generation,t=await Sn(i,e.type==="highlight"?{op:"show",options:e.payload}:{op:"clear"}),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw await Sn(i,{op:"clear"}).catch(()=>{}),new k("GS_TARGET_CHANGED","The target changed while highlighting.");return Q(i),mr=t?i:null,{tabId:i,url:n.url,highlighted:t}}if(e.type==="get_console"||e.type==="get_network_failures"||e.type==="get_page_status"){Q(i);let o=_.generation,t=e.type==="get_network_failures"?void 0:await H.getDiagnostics(i),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The target document changed during diagnostics.");return Q(i),e.type==="get_console"?{tabId:i,...pr.read(e.payload.maxEntries,e.payload.reset),forwardingDropped:t.consoleForwardingDropped}:e.type==="get_network_failures"?{tabId:i,...gr.read(e.payload.maxEntries,e.payload.reset)}:{...t,tabId:i,targetState:_.state,runtimeErrorCount:ze.get(i)?.length??0,consoleEntryCount:pr.count,networkFailureCount:gr.count}}if(bn.safeParse(e.type).success){Q(i);let o=_.generation,t=await browser.tabs.sendMessage(i,{type:"gazesight-interaction-content",operation:{type:e.type,options:e.payload}},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","Interaction content unavailable; select the target again.")}),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The document changed during interaction; the action may already have occurred. Inspect before retrying.");if(Q(i),!t?.ok)throw new k(typeof t?.code=="string"&&t.code.startsWith("GS_")?t.code:"GS_INTERACTION_FAILED","The DOM interaction was refused or failed.");return{tabId:i,url:n.url,action:e.type,inputSource:"dom",completed:!0,...t.value}}if(e.type==="get_viewport"||e.type==="set_viewport"){Q(i);let o=_.generation,t=async()=>{Q(i);let c=await H.getTarget(i);if(_.generation!==o||c.url!==r.url)throw new k("GS_TARGET_CHANGED","The selected source changed during viewport operation.")},n=e.type==="get_viewport"?await H.getViewport(r):await H.resizePreview(r,e.payload,t);await t(),Je(n.url,We);let{movedToCompact:a,...u}={movedToCompact:!1,...n};return a&&(te&&M?_.refresh(n.tabId):_.reauthorize(n.tabId),await pe(),await X?.publish()),{...u,requiresTargetSelection:!S_(n.tabId)}}if(e.type==="get_dom"||e.type==="get_element"||e.type==="get_changed_regions"){Q(i);let o=_.generation,t=await browser.tabs.sendMessage(i,{type:"gazesight-dom-content",operation:{type:e.type,options:{...e.payload,tabId:i}}},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","DOM content script unavailable; reauthorize the target.")});Q(i);let n=await H.getTarget(i);if(_.generation!==o||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The target changed during inspection.");if(!t?.ok)throw new k(typeof t?.code=="string"&&t.code.startsWith("GS_")?t.code:"GS_DOM_FAILED","The fixed DOM inspection operation failed.");return t.value}if(e.type==="capture_region"||e.type==="capture_element"||e.type==="capture_full_page"){Q(i);let o=_.generation;async function t(){Q(i);let a=await H.getTarget(i);if(o!==_.generation||a.url!==r.url||(oe!=="enabled"||!M)&&!a.active)throw new k("GS_TARGET_CHANGED","The authorized active target changed during capture.")}let n=new $n(async a=>(await t(),av({id:e.id,version:1,type:"capture",payload:Ce.parse({...a,tabId:i})})),async a=>{await t();let u=await browser.tabs.sendMessage(i,{type:"gazesight-capture-content",operation:a},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","Capture content script unavailable; reauthorize the target.")});if(await t(),!u?.ok)throw new k(typeof u?.code=="string"&&u.code.startsWith("GS_")?u.code:"GS_CAPTURE_FAILED","The fixed content capture operation failed.");return u.value},iv);return Fg(n,e,x_)}if(e.type==="capture"){Q(i);let o=performance.now(),t=_.generation;if((oe!=="enabled"||!M)&&!r.active)throw new k("GS_CAPTURE_FAILED","Bring the selected GazeSight tab to the front in its Firefox window before capturing.");let n=0,a;if(e.payload.waitForStable){let h=await browser.tabs.sendMessage(i,{type:"gazesight-wait-stable",options:e.payload},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","The target document closed or navigated, or its content script is unavailable. Click the GazeSight icon in the target tab.")});if(!h?.ok)throw new k(h?.code==="GS_TARGET_CHANGED"?"GS_TARGET_CHANGED":"GS_RENDER_NOT_STABLE","The render did not appear stable before maxWaitMs. Retry after updates settle.",h?.stability?pd.parse(h.stability):void 0);n=h.stabilityWaitMs,a={lastMutationAgoMs:h.lastMutationAgoMs,fontsReady:h.fontsReady,pendingImages:h.pendingImages,timeoutReached:h.timeoutReached}}if(t!==_.generation)throw new k("GS_TARGET_CHANGED","The target document changed during capture preparation.");let u=performance.now(),c=await H.capture(e.payload).then(h=>{if(typeof h!="string")throw new k("GS_CAPTURE_FAILED","Invalid native capture result.");return h}).catch(async h=>{throw h instanceof k&&h.code==="GS_PERMISSION_DENIED"?(_.reauthorize(i),await pe(),await X?.publish(),new k("GS_REAUTHORIZE_TARGET","Firefox requires permission again. Click the GazeSight extension icon in the target tab.")):h}),s=performance.now()-u,d=oe==="enabled"&&M?[await H.getTarget(i)]:await browser.tabs.query({active:!0,windowId:r.windowId});if(t!==_.generation)throw new k("GS_TARGET_CHANGED","The target document changed during native capture. Click the GazeSight icon in the target tab again.");if(d[0]?.id!==i||d[0]?.url!==r.url)throw new k("GS_CAPTURE_FAILED","The active tab changed during capture. Retry with the preview tab active.");let m=await createImageBitmap(await(await fetch(c)).blob()),p=m.width,f=m.height;return m.close(),{tabId:i,url:r.url,width:p,height:f,format:e.payload.format,captureMs:s,stabilityWaitMs:n,extensionTotalMs:performance.now()-o,renderAppearsStable:e.payload.waitForStable,stable:e.payload.waitForStable,...a,dataUrl:c}}if(e.type==="get_errors"){Q(i);let o=ze.get(i)??[];return ze.set(i,[]),{tabId:i,errors:o}}if(e.type==="reload")return await yd(_,i,r.url,async()=>{await pe(),await X?.publish()},async()=>(await H.getTarget(i)).url??"",()=>H.reload(i,e.payload.bypassCache)),await Qg(i),{tabId:i,url:r.url};if(e.type!=="navigate")throw new k("GS_INVALID_MESSAGE","Unsupported operation.");return Je(e.payload.url,We),await yd(_,i,r.url,async()=>{await pe(),await X?.publish()},async()=>(await H.getTarget(i)).url??"",()=>H.navigate(i,e.payload.url)),await Qg(i),{tabId:i,url:e.payload.url}}async function Qg(e){if(!(te&&M))return;let r=Date.now()+5e3;for(;Date.now()<r;){if(_.selectedTab!==e||_.state==="none"||_.state==="authorized")return;let i=await browser.tabs.get(e).catch(()=>{});if(i?.status==="complete"&&_.isSelectedOrigin(i.url??"")){_.resume(e),await at(e),await pe(),await X?.publish();return}await new Promise(o=>setTimeout(o,100))}}async function j_(){let e=await browser.storage.local.get(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),r=typeof e.continuousAuthPrimaryTabId=="number"?e.continuousAuthPrimaryTabId:null,i=typeof e.continuousAuthOrigin=="string"?e.continuousAuthOrigin:null;if(!(r===null||i===null))try{let o=await browser.tabs.get(r);if(!o.url||!Yg(o.url,i))throw new k("GS_TARGET_CHANGED","Stale persisted target.");Je(o.url,We),_.choose(r,o.url),await Mo(r),await pe()}catch{await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"])}}async function uv(){X?.stop();let e=await browser.storage.local.get(["port","token","allowedOrigins","backgroundCaptureEnabled","continuousAuthorizationEnabled"]);if(M=await browser.permissions.contains({origins:["<all_urls>"]}),oe=e.backgroundCaptureEnabled===!0&&M?"enabled":"disabled",e.backgroundCaptureEnabled===!0&&!M&&await browser.storage.local.set({backgroundCaptureEnabled:!1}),te=e.continuousAuthorizationEnabled===!0&&M,e.continuousAuthorizationEnabled===!0&&!M&&await browser.storage.local.set({continuousAuthorizationEnabled:!1}),We=Array.isArray(e.allowedOrigins)?e.allowedOrigins:[],te&&_.selectedTab===null&&await j_(),typeof e.token!="string"||!/^[a-f0-9]{64}$/.test(e.token))return;let r=Number(e.port??32147);!Number.isInteger(r)||r<1024||r>65535||(X=new Co(r,e.token,P_,zd,i=>{je=i,!i&&_.selectedTab!==null&&(Pd(_.selectedTab),Fo(_.selectedTab)),i&&_.state==="authorized"&&_.selectedTab!==null&&Mo(_.selectedTab),pe()}),X.start())}async function zd(e){let r=e.type==="capture"||e.type.startsWith("capture_"),i=!1,o=mr;if(r&&o!==null){if(kn)throw new k("GS_CAPTURE_BUSY","Wait for the current overlay capture to complete.");Q(_.resolve(e.payload.tabId)),kn=!0;try{(!("includeOverlay"in e.payload)||e.payload.includeOverlay!==!0)&&(i=await Sn(o,{op:"suspend"}),i||(mr=null))}catch(a){throw kn=!1,a}}let t=r&&_.state==="authorized"?_.selectedTab:null;t!==null&&await vr(t,{op:"suspend"});let n;r&&(Sd=!0,n=setTimeout(()=>{pe().catch(()=>{})},120));try{let a=await av(e);if(In=!1,r){let u=a;rv={mode:e.payload&&"waitForStable"in e.payload&&e.payload.waitForStable?"STABLE":"FAST",width:u.width,height:u.height,time:new Date().toISOString()}}return a}catch(a){throw In=!0,nv={code:a instanceof k?a.code:"GS_OPERATION_FAILED",message:Ze(a instanceof Error?a.message:"Operation failed",512),time:new Date().toISOString()},a}finally{t!==null&&await vr(t,{op:"resume"}),i&&o!==null&&(await Sn(o,{op:"resume"}).catch(()=>!1)||(mr=null)),r&&o!==null&&(kn=!1),n!==void 0&&clearTimeout(n),r&&(Sd=!1),pe().catch(()=>{})}}async function De(){let e,r;if(_.selectedTab!==null){let i=await browser.tabs.get(_.selectedTab).catch(()=>{});e=i?.url?yn(i.url,i.url):void 0,je&&_.state==="authorized"&&(r=(await H.getDiagnostics(_.selectedTab).catch(()=>{}))?.viewport)}return{connected:je,paired:je,targetState:_.state,url:e,viewport:r,lastCapture:rv,lastError:nv,backgroundMode:oe,backgroundCapture:{enabled:oe==="enabled",permissionGranted:M},continuousAuthorization:{enabled:te,permissionGranted:M,authorizedOrigin:te&&_.state==="authorized"?_.selectedOrigin:null},consoleCount:pr.count,networkCount:gr.count,runtimeErrorCount:_.selectedTab===null?0:ze.get(_.selectedTab)?.length??0}}async function A_(e){if(e==="status")return De();if(e==="background-enable")return oe="requesting",M=await browser.permissions.contains({origins:["<all_urls>"]}),oe=M?"enabled":"permission_denied",await browser.storage.local.set({backgroundCaptureEnabled:M}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="background-denied")return oe="permission_denied",M=!1,await browser.storage.local.set({backgroundCaptureEnabled:!1}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="background-disable")return oe="disabled",await browser.storage.local.set({backgroundCaptureEnabled:!1}),te||await browser.permissions.remove({origins:["<all_urls>"]}),M=await browser.permissions.contains({origins:["<all_urls>"]}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="continuous-enable")return te=!1,M=await browser.permissions.contains({origins:["<all_urls>"]}),te=M,await browser.storage.local.set({continuousAuthorizationEnabled:M}),te&&_.state==="authorized"&&_.selectedTab!==null&&_.selectedOrigin!==null&&await browser.storage.local.set({continuousAuthPrimaryTabId:_.selectedTab,continuousAuthOrigin:_.selectedOrigin}),await X?.publish(),De();if(e==="continuous-denied")return te=!1,await browser.storage.local.set({continuousAuthorizationEnabled:!1}),await X?.publish(),De();if(e==="continuous-disable")return te=!1,await browser.storage.local.set({continuousAuthorizationEnabled:!1}),await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),oe!=="enabled"&&await browser.permissions.remove({origins:["<all_urls>"]}),M=await browser.permissions.contains({origins:["<all_urls>"]}),await X?.publish(),De();if(e==="disconnect"){let i=_.selectedTab;return i!==null&&(await Pd(i),await Fo(i),_.remove(i)),zn(),ze.clear(),In=!1,await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),fr.clear(),await pe(),await X?.publish(),De()}if(e==="select"){let[i]=await browser.tabs.query({active:!0,lastFocusedWindow:!0});if(!i?.id)throw new k("GS_NO_TARGET_TAB","Activate your preview page before using this tab.");if(Je(i.url??"",We),!await Td(i))throw new k("GS_TARGET_SELECTION_FAILED","Selection failed. Check the allowed origin and settings.");return De()}if(!je)throw new k("GS_NOT_CONNECTED","Start the GazeSight MCP server and check pairing in settings.");let r=_.resolve();return Q(r),e==="diagnostics"?{status:await De(),console:pr.read(10,!1),network:gr.read(10,!1),runtimeErrors:(ze.get(r)??[]).slice(-10)}:e==="fast"?k_.run({permissionGranted:()=>browser.permissions.contains({permissions:["downloads"]}),capture:async()=>await zd({id:crypto.randomUUID(),version:1,type:"capture",payload:Ce.parse({tabId:r,format:"png",waitForStable:!1})}),download:async i=>{let o=await(await fetch(i.url)).blob(),t=URL.createObjectURL(o);try{return await browser.downloads.download({...i,url:t})}finally{setTimeout(()=>URL.revokeObjectURL(t),3e4)}},waitForCompletion:z_}):(await zd({id:crypto.randomUUID(),version:1,type:"capture",payload:Ce.parse({tabId:r,waitForStable:!0})}),De())}async function Pd(e){await browser.tabs.sendMessage(e,{type:"gazesight-dom-content",operation:{type:"stop_tracking"}},{frameId:0}).catch(()=>{})}async function Td(e){try{return Je(e.url??"",We),_.selectedTab!==null&&(await Pd(_.selectedTab),await Fo(_.selectedTab)),zn(),ze.clear(),_.choose(e.id,e.url),In=!1,te&&_.selectedOrigin!==null&&await browser.storage.local.set({continuousAuthPrimaryTabId:e.id,continuousAuthOrigin:_.selectedOrigin}),await Mo(e.id),await pe(),await X?.publish(),!0}catch{return await browser.runtime.openOptionsPage(),!1}}browser.browserAction.onClicked.addListener(Td);browser.commands.onCommand.addListener(async(e,r)=>{try{let i=await Bg(e,r);i&&await Td(i)}catch{await browser.runtime.openOptionsPage()}});browser.tabs.onRemoved.addListener(e=>{e===_.selectedTab&&(zn(),browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"])),_.remove(e),ze.delete(e),pe(),X?.publish()});browser.windows.onRemoved.addListener(e=>fr.removeWindow(e));browser.tabs.onUpdated.addListener((e,r)=>{if(e===_.selectedTab){if(r.url&&!_.isSelectedOrigin(r.url)){zn(),ze.delete(e),_.reauthorize(e),vr(e,{op:"set",state:"none"}),pe(),X?.publish();return}r.status==="loading"&&(zn(),ze.delete(e),(oe==="enabled"||te)&&M?_.refresh(e):(_.reauthorize(e),vr(e,{op:"set",state:"none"})),pe()),r.status==="complete"&&(te&&M&&browser.tabs.get(e).then(i=>{_.selectedTab===e&&_.state==="reauthorization_required"&&_.isSelectedOrigin(i.url??"")&&(_.resume(e),at(e),pe(),X?.publish())}).catch(()=>{}),Mo(e)),X?.publish()}});browser.runtime.onMessage.addListener((e,r)=>{if(r.id===browser.runtime.id){if(e?.type==="gazesight-ui"){if(!xd(r,browser.runtime.id,browser.runtime.getURL("popup.html"))&&!xd(r,browser.runtime.id,browser.runtime.getURL("permission.html"),!0))return;let i=Wg.safeParse(e);return i.success?A_(i.data.action).then(o=>({ok:!0,value:o}),o=>({ok:!1,error:Ze(o instanceof Error?o.message:"GS_OPERATION_FAILED",512)})):Promise.resolve({ok:!1,error:"GS_INVALID_MESSAGE"})}if(!(!je||_.state!=="authorized"||r.tab?.id!==_.selectedTab||!_.isSelectedOrigin(r.tab?.url??"")||r.frameId!==0)){if(e?.type==="console-diagnostic"){let i=hn.safeParse(e.entry);i.success&&pr.push({...i.data,message:Ze(i.data.message,512)});return}if(e?.type==="runtime-error"&&r.tab?.id!==void 0&&r.frameId===0){let i=hd.safeParse(e.error);if(i.success&&r.tab.id===_.selectedTab){let o=ze.get(r.tab.id)??[];o.push({...i.data,message:Ze(i.data.message,4096),source:i.data.source?yn(i.data.source,r.tab.url??i.data.source):void 0}),ze.set(r.tab.id,o.slice(-200))}}}}});browser.storage.onChanged.addListener((e,r)=>{r==="local"&&["port","token","allowedOrigins"].some(i=>i in e)&&uv()});browser.permissions.onRemoved.addListener(e=>{e.origins?.includes("<all_urls>")&&(M=!1,oe="disabled",te=!1,browser.storage.local.set({backgroundCaptureEnabled:!1,continuousAuthorizationEnabled:!1}),browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),_.state==="authorized"&&_.selectedTab!==null&&at(_.selectedTab),X?.publish())});browser.permissions.onAdded.addListener(e=>{e.origins?.includes("<all_urls>")&&(M=!0,_.state==="authorized"&&_.selectedTab!==null&&at(_.selectedTab),X?.publish())});uv();})();
|
|
62
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let a of e.seen.entries()){let u=a[1];if(r===a[0]){n(a);continue}if(e.external){let s=e.external.registry.get(a[0])?.id;if(r!==a[0]&&s){n(a);continue}}if(e.metadataRegistry.get(a[0])?.id){n(a);continue}if(u.cycle){n(a);continue}u.count>1&&e.reused==="ref"&&n(a)}e.external&&(e.sharedDefsExtractedFor=e.external)}function Mf(e){let r=e.anyOf;if(!Array.isArray(r)||r.length===0||e.type!==void 0)return;let i=[];for(let o of r){if(!o||typeof o!="object")return;Mf(o);let t=Object.keys(o);if(t.length!==1||t[0]!=="type")return;let n=o.type;for(let a of Array.isArray(n)?n:[n]){if(typeof a!="string")return;i.includes(a)||i.push(a)}}delete e.anyOf,e.type=i.length===1?i[0]:i}var Ff=new Set(["type","properties","required","additionalProperties"]),Lf=["oneOf","anyOf"];function Vf(e){let r=e.additionalProperties;return r===void 0||r===!1||typeof r!="object"||r===null?null:Object.keys(r).length?r:null}function hs(e){let r=[];for(let n of e){if(typeof n!="object"||n.type!=="object")return null;for(let a in n)if(!Ff.has(a))return null;r.push(n)}let i={},o=new Set;for(let n of r){for(let a in n.properties){if(Object.prototype.hasOwnProperty.call(i,a))continue;let u=[];for(let s of r){let d=s.properties?.[a]??Vf(s);d!=null&&(u.some(m=>JSON.stringify(m)===JSON.stringify(d))||u.push(d))}let c=u.length===1?u[0]:hs(u)??{allOf:u};re(i,a,c)}for(let a of n.required??[])o.add(a)}let t={type:"object",properties:i};if(o.size&&(t.required=[...o]),r.every(n=>n.additionalProperties===!1))t.additionalProperties=!1;else{let n=[];for(let a of r){let u=Vf(a);u&&!n.some(c=>JSON.stringify(c)===JSON.stringify(u))&&n.push(u)}n.length===1?t.additionalProperties=n[0]:n.length>1&&(t.additionalProperties={allOf:n})}return t}function _y(e){let r=e.allOf;if(!Array.isArray(r)||r.length<2)return;for(let t of Ff)if(t in e)return;let i=r.filter(t=>Lf.some(n=>Array.isArray(t[n]))),o=null;if(!i.length)o=hs(r);else{let t=i[0],n=Lf.find(c=>Array.isArray(t[c]));if(Object.keys(t).length!==1)return;let a=r.filter(c=>c!==t),u=t[n].map(c=>hs([...a,c]));if(u.some(c=>!c))return;o={[n]:u}}o&&(delete e.allOf,Qr(e,o))}function tt(e,r){let i=e.seen.get(r);if(!i)throw new Error("Unprocessed schema. This is a bug in Zod.");let o=u=>{let c=e.seen.get(u);if(c.ref===null)return;let s=c.def??c.schema,d={...s},m=c.ref;if(c.ref=null,m){o(m);let f=e.seen.get(m),h=f.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(s.allOf=s.allOf??[],s.allOf.push(h)):Qr(s,h),Qr(s,d),u._zod.parent===m)for(let x in s)x==="$ref"||x==="allOf"||x in d||delete s[x];if(h.$ref&&f.def)for(let x in s)x==="$ref"||x==="allOf"||x in f.def&&JSON.stringify(s[x])===JSON.stringify(f.def[x])&&delete s[x]}let p=u._zod.parent;if(p&&p!==m){o(p);let f=e.seen.get(p);if(f?.schema.$ref&&(s.$ref=f.schema.$ref,f.def))for(let h in s)h==="$ref"||h==="allOf"||h in f.def&&JSON.stringify(s[h])===JSON.stringify(f.def[h])&&delete s[h]}e.override({zodSchema:u,jsonSchema:s,path:c.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let u of[...e.seen.entries()].reverse())o(u[0]);if(e.target!=="openapi-3.0")for(let u of e.seen.entries())Mf(u[1].def??u[1].schema);for(let u of e.deferred)u();if(e.intersections.length){let u=new Map;for(let c of e.seen.values())for(let s of[c.schema,c.def]){let d=s?.allOf;if(!Array.isArray(d))continue;let m=u.get(d);m?m.push(s):u.set(d,[s])}for(let c of e.intersections)for(let s of u.get(c)??[])_y(s)}}let t={};if(e.target==="draft-2020-12"?t.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?t.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?t.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){let u=e.external.registry.get(r)?.id;if(!u)throw new Error("Schema is missing an `id` property");t.$id=e.external.uri(u)}Qr(t,i.defId?i.schema:i.def??i.schema);let n=e.metadataRegistry.get(r)?.id;n!==void 0&&t.id===n&&delete t.id;let a=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let u of e.seen.entries()){let c=u[1];c.def&&c.defId&&(c.def.id===c.defId&&delete c.def.id,re(a,c.defId,c.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(a).length>0&&(e.target==="draft-2020-12"?t.$defs=a:t.definitions=a);try{let u=JSON.parse(JSON.stringify(t));return Object.defineProperty(u,"~standard",{value:{...r["~standard"],jsonSchema:{input:er(r,"input",e.processors),output:er(r,"output",e.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function de(e,r){let i=r??{seen:new Set};if(i.seen.has(e))return!1;i.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return de(o.element,i);if(o.type==="set")return de(o.valueType,i);if(o.type==="lazy")return de(o.getter(),i);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return de(o.innerType,i);if(o.type==="intersection")return de(o.left,i)||de(o.right,i);if(o.type==="record"||o.type==="map")return de(o.keyType,i)||de(o.valueType,i);if(o.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:de(o.in,i)||de(o.out,i);if(o.type==="object"){for(let t in o.shape)if(de(o.shape[t],i))return!0;return!1}if(o.type==="union"){for(let t of o.options)if(de(t,i))return!0;return!1}if(o.type==="tuple"){for(let t of o.items)if(de(t,i))return!0;return!!(o.rest&&de(o.rest,i))}return!1}var bs=(e,r={})=>i=>{let o=Qe({...i,processors:r});return V(e,o),et(o,e),tt(o,e)},er=(e,r,i={})=>o=>{let{libraryOptions:t,target:n}=o??{},a=Qe({...t??{},target:n,io:r,processors:i});return V(e,a),et(a,e),tt(a,e)};var tr=(e,r,i)=>{(e[r]===void 0||i>e[r])&&(e[r]=i)},rr=(e,r,i)=>{(e[r]===void 0||i<e[r])&&(e[r]=i)},Gf=(e,r)=>{tr(e,"minimum",r),rr(e,"maximum",r)},Kf=(e,r)=>{e.multipleOf??(e.multipleOf=[]),e.multipleOf.includes(r)||e.multipleOf.push(r)},Xf=(e,r)=>{e.patterns??(e.patterns=new Set),e.patterns.add(r)},Hf=(e,r)=>{e.mime=e.mime?e.mime.filter(i=>r.includes(i)):[...r]},qf=(e,r)=>{e.format=r,r.includes("int")&&(e.isInt=!0)},Bf=(e,r)=>tr(e,"minimum",r.minimum),Jf=(e,r)=>rr(e,"maximum",r.maximum),Wf=e=>(r,i)=>{qf(r,i.format);let[o,t]=e[i.format];tr(r,"minimum",o),rr(r,"maximum",t)},wy={greater_than:(e,r)=>tr(e,r.inclusive?"minimum":"exclusiveMinimum",r.value),less_than:(e,r)=>rr(e,r.inclusive?"maximum":"exclusiveMaximum",r.value),multiple_of:(e,r)=>Kf(e,r.value),number_format:Wf(_r),bigint_format:Wf(wr),min_length:Bf,max_length:Jf,length_equals:(e,r)=>Gf(e,r.length),min_size:Bf,max_size:Jf,size_equals:(e,r)=>Gf(e,r.size),string_format:(e,r)=>{qf(e,r.format),r.pattern&&Xf(e,r.pattern),(r.format==="base64"||r.format==="base64url")&&(e.contentEncoding=r.format),(r.local||r.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,r)=>Hf(e,r.mime)};function Y(e){let r={},i=e._zod.def,o=e._zod.traits.has("$ZodCheck")?[e,...i.checks??[]]:i.checks??[];for(let n of o)wy[n._zod.def.check]?.(r,n._zod.def);let t=e._zod.bag;t.minimum!==void 0&&tr(r,"minimum",t.minimum),t.exclusiveMinimum!==void 0&&tr(r,"exclusiveMinimum",t.exclusiveMinimum),t.maximum!==void 0&&rr(r,"maximum",t.maximum),t.exclusiveMaximum!==void 0&&rr(r,"exclusiveMaximum",t.exclusiveMaximum),t.multipleOf!==void 0&&Kf(r,t.multipleOf),t.format!==void 0&&(r.format??(r.format=t.format),t.format.includes("int")&&(r.isInt=!0)),t.mime&&Hf(r,t.mime);for(let n of t.patterns??[])Xf(r,n);return r}var xy={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},ky=new Map([[ui,Sa],[Zr,za]]),Yf=e=>ky.get(e)??e,_s=(e,r,i,o)=>{let t=i;t.type="string";let{minimum:n,maximum:a,format:u,patterns:c,contentEncoding:s,laxFormat:d}=Y(e);if(typeof n=="number"&&(t.minLength=n),typeof a=="number"&&(t.maxLength=a),u&&(t.format=xy[u]??u,t.format===""&&delete t.format,(u==="time"||d)&&delete t.format),s&&(t.contentEncoding=s),c&&c.size>0){let m=[...c].map(Yf);m.length===1?t.pattern=m[0].source:m.length>1&&(t.allOf=[...m.map(p=>({...r.target==="draft-07"||r.target==="draft-04"||r.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))])}},ws=(e,r,i,o)=>{let t=i,{minimum:n,maximum:a,multipleOf:u,exclusiveMaximum:c,exclusiveMinimum:s,isInt:d}=Y(e);t.type=d?"integer":"number";let m=typeof s=="number"&&s>=(n??Number.NEGATIVE_INFINITY),p=typeof c=="number"&&c<=(a??Number.POSITIVE_INFINITY),f=r.target==="draft-04"||r.target==="openapi-3.0";if(m?f?(t.minimum=s,t.exclusiveMinimum=!0):t.exclusiveMinimum=s:typeof n=="number"&&(t.minimum=n),p?f?(t.maximum=c,t.exclusiveMaximum=!0):t.exclusiveMaximum=c:typeof a=="number"&&(t.maximum=a),u){let h=new Set;for(let P of u)Number.isFinite(P)&&P!==0?h.add(Math.abs(P)):q(e,r,t,o,`A multipleOf divisor of ${P} cannot be represented in JSON Schema`);let[w,...x]=h;w!==void 0&&(t.multipleOf=w),x.length&&(t.allOf=[...t.allOf??[],...x.map(P=>({multipleOf:P}))])}},xs=(e,r,i,o)=>{i.type="boolean"},ks=(e,r,i,o)=>{q(e,r,i,o,"BigInt cannot be represented in JSON Schema")},Is=(e,r,i,o)=>{q(e,r,i,o,"Symbols cannot be represented in JSON Schema")},Ss=(e,r,i,o)=>{r.target==="openapi-3.0"?(i.type="string",i.nullable=!0,i.enum=[null]):i.type="null"},zs=(e,r,i,o)=>{q(e,r,i,o,"Undefined cannot be represented in JSON Schema")},Ps=(e,r,i,o)=>{q(e,r,i,o,"Void cannot be represented in JSON Schema")},Ts=(e,r,i,o)=>{i.not={}},Os=(e,r,i,o)=>{},Ds=(e,r,i,o)=>{},js=(e,r,i,o)=>{q(e,r,i,o,"Date cannot be represented in JSON Schema")},As=(e,r,i,o)=>{let t=e._zod.def,n=zt(t.entries);if(n.length===0){i.not={};return}n.every(a=>typeof a=="number")&&(i.type="number"),n.every(a=>typeof a=="string")&&(i.type="string"),i.enum=n},Ns=(e,r,i,o)=>{let t=e._zod.def;if(t.values.length===0){i.not={};return}let n=[];for(let a of t.values)if(a===void 0){if(q(e,r,i,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof a=="bigint"){if(q(e,r,i,o,"BigInt literals cannot be represented in JSON Schema"))return;n.push(Number(a))}else n.push(a);if(n.length!==0)if(n.length===1){let a=n[0];i.type=a===null?"null":typeof a,r.target==="draft-04"||r.target==="openapi-3.0"?i.enum=[a]:i.const=a}else n.every(a=>typeof a=="number")&&(i.type="number"),n.every(a=>typeof a=="string")&&(i.type="string"),n.every(a=>typeof a=="boolean")&&(i.type="boolean"),n.every(a=>a===null)&&(i.type="null"),i.enum=n},Us=(e,r,i,o)=>{q(e,r,i,o,"NaN cannot be represented in JSON Schema")},Es=(e,r,i,o)=>{let t=i,n=e._zod.pattern;if(!n)throw new Error("Pattern not found in template literal");t.type="string",t.pattern=n.source},Cs=(e,r,i,o)=>{let t=i;t.type="string",t.format="binary",t.contentEncoding="binary";let{minimum:n,maximum:a,mime:u}=Y(e);n!==void 0&&(t.minLength=n),a!==void 0&&(t.maxLength=a),u&&(u.length===0?t.not={}:u.length===1?t.contentMediaType=u[0]:t.anyOf=u.map(c=>({contentMediaType:c})))},Zs=(e,r,i,o)=>{i.type="boolean"},Rs=(e,r,i,o)=>{q(e,r,i,o,"Custom types cannot be represented in JSON Schema")},Ls=(e,r,i,o)=>{q(e,r,i,o,"Function types cannot be represented in JSON Schema")},Vs=(e,r,i,o)=>{q(e,r,i,o,"Transforms cannot be represented in JSON Schema")},Ms=(e,r,i,o)=>{q(e,r,i,o,"Map cannot be represented in JSON Schema")},Fs=(e,r,i,o)=>{q(e,r,i,o,"Set cannot be represented in JSON Schema")},Gs=(e,r,i,o)=>{let t=i,n=e._zod.def,{minimum:a,maximum:u}=Y(e);typeof a=="number"&&(t.minItems=a),typeof u=="number"&&(t.maxItems=u),t.type="array",t.items=V(n.element,r,{...o,path:[...o.path,"items"]})};function en(e){let r=e._zod.def;return r.type==="pipe"&&r.in._zod.traits.has("$ZodTransform")?en(r.out):r.type==="catch"?en(r.innerType):e._zod.optin}var Bs=(e,r,i,o)=>{let t=i,n=e._zod.def,a=n.shape;if(Object.getOwnPropertySymbols(a).length&&q(e,r,t,o,"Symbol keys cannot be represented in JSON Schema"))return;t.type="object",t.properties={};for(let s in a)re(t.properties,s,V(a[s],r,{...o,path:[...o.path,"properties",s]}));let c=[];for(let s of Object.keys(a)){let d=n.shape[s];(r.io==="input"?en(d)===void 0:d._zod.optout===void 0)&&c.push(s)}c.length>0&&(t.required=c),n.catchall?._zod.def.type==="never"?t.additionalProperties=!1:n.catchall?n.catchall&&(t.additionalProperties=V(n.catchall,r,{...o,path:[...o.path,"additionalProperties"]})):r.io==="output"&&(t.additionalProperties=!1)},io=(e,r,i,o)=>{let t=e._zod.def,n=t.inclusive===!1,a=t.options.map((u,c)=>V(u,r,{...o,path:[...o.path,n?"oneOf":"anyOf",c]}));n?i.oneOf=a:i.anyOf=a},Js=(e,r,i,o)=>{let t=e._zod.def,n=V(t.left,r,{...o,path:[...o.path,"allOf",0]}),a=V(t.right,r,{...o,path:[...o.path,"allOf",1]}),u=s=>"allOf"in s&&Object.keys(s).length===1,c=[...u(n)?n.allOf:[n],...u(a)?a.allOf:[a]];i.allOf=c,r.intersections.push(c)},Ws=(e,r,i,o)=>{let t=i,n=e._zod.def;t.type="array";let a=r.target==="draft-2020-12"?"prefixItems":"items",u=r.target==="draft-2020-12"||r.target==="openapi-3.0"?"items":"additionalItems",c=n.items.map((w,x)=>V(w,r,{...o,path:[...o.path,a,x]})),s=n.rest?V(n.rest,r,{...o,path:[...o.path,u,...r.target==="openapi-3.0"?[n.items.length]:[]]}):null,d=n.items.length;for(;d>0;){let w=n.items[d-1];if(!(r.io==="input"?en(w)!==void 0:w._zod.optout==="optional"))break;d--}let m=n.items.length,p=!n.rest;r.target==="draft-2020-12"?(t.prefixItems=c,p?t.items=!1:s&&(t.items=s),d>0&&(t.minItems=d),p&&(t.maxItems=m)):r.target==="openapi-3.0"?(t.items={anyOf:c},s&&t.items.anyOf.push(s),d>0&&(t.minItems=d),p&&(t.maxItems=m)):(t.items=c,p?t.additionalItems=!1:s&&(t.additionalItems=s),d>0&&(t.minItems=d),p&&(t.maxItems=m));let{minimum:f,maximum:h}=Y(e);typeof f=="number"&&(t.minItems=f),typeof h=="number"&&(t.maxItems=h)};function $s(e,r,i){if(r.$ref){if(i.has(r))return r;i.add(r);let h=e.get(r)?.def;if(!h)return r;let w=$s(e,h,i);return w===h?r:w}for(let h of["anyOf","oneOf"]){let w=r[h];if(!Array.isArray(w))continue;let x=w.map(P=>$s(e,P,i));x.some((P,S)=>P!==w[S])&&(r={...r,[h]:x})}let o=Array.isArray(r.type)?r.type:[r.type],t=!o.includes("string")&&o.some(h=>h==="number"||h==="integer"),n=r.enum??(r.const!==void 0?[r.const]:void 0);if(!t&&!n?.some(h=>typeof h=="number"))return r;let{minimum:a,maximum:u,exclusiveMinimum:c,exclusiveMaximum:s,multipleOf:d,format:m,id:p,...f}=r;return f.enum?f.enum=f.enum.map(h=>typeof h=="number"?String(h):h):typeof f.const=="number"&&(f.const=String(f.const)),t&&(f.type="string",n||(f.pattern=(o.includes("number")?Fe:Dr).source)),f}var ys=new WeakMap;function Iy(e){let r=new Map;for(let o of e.seen.values())o.def&&!r.has(o.schema)&&r.set(o.schema,o);let i=new Map;for(let o of ys.get(e)??[]){let t=e.seen.get(o),n=(t?.def??t?.schema)?.propertyNames;if(!n||n===!0||i.has(n))continue;let a=$s(r,n,new Set);a!==n&&i.set(n,a)}if(i.size)for(let o of e.seen.values())for(let t of[o.schema,o.def]){let n=t&&i.get(t.propertyNames);n&&(t.propertyNames=n)}}var Ks=(e,r,i,o)=>{let t=i,n=e._zod.def;t.type="object";let a=n.keyType,u=Y(a).patterns;if(n.mode==="loose"&&u&&u.size>0){let d=V(n.valueType,r,{...o,path:[...o.path,"patternProperties","*"]});t.patternProperties={};for(let m of u)re(t.patternProperties,Yf(m).source,d)}else{if(r.target==="draft-07"||r.target==="draft-2020-12"){t.propertyNames=V(n.keyType,r,{...o,path:[...o.path,"propertyNames"]});let d=ys.get(r);d||(d=[],ys.set(r,d),r.deferred.push(()=>Iy(r))),d.push(e)}t.additionalProperties=V(n.valueType,r,{...o,path:[...o.path,"additionalProperties"]})}let c=a._zod.values,s=r.io==="input"&&en(n.valueType)!==void 0;if(c&&!n.partial&&!s){let d=[...c].filter(m=>typeof m=="string"||typeof m=="number");d.length>0&&(t.required=d.map(String))}},Xs=(e,r,i,o)=>{let t=e._zod.def,n=V(t.innerType,r,o),a=r.seen.get(e);r.target==="openapi-3.0"?(a.ref=t.innerType,i.nullable=!0):i.anyOf=[n,{type:"null"}]},Hs=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},qs=Symbol();function Qf(e,r,i,o,t){let n=!1,a=JSON.stringify(e,(u,c)=>typeof c!="bigint"?c:(n=!0,null));return n?(q(r,i,o,t,"BigInt defaults cannot be represented in JSON Schema"),qs):JSON.parse(a)}var Ys=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType;let a=Qf(t.defaultValue,e,r,i,o);a!==qs&&(i.default=a)},Qs=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);if(n.ref=t.innerType,r.io!=="input")return;let a=Qf(t.defaultValue,e,r,i,o);a!==qs&&(i._prefault=a)},el=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType;let a;try{a=t.catchValue(void 0)}catch{q(e,r,i,o,"Dynamic catch values are not supported in JSON Schema");return}i.default=a},tl=(e,r,i,o)=>{let t=e._zod.def,n=t.in._zod.traits.has("$ZodTransform"),a=r.io==="input"?n?t.out:t.in:t.out;V(a,r,o);let u=r.seen.get(e);u.ref=a},rl=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType,i.readOnly=!0},nl=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},oo=(e,r,i,o)=>{let t=e._zod.def;V(t.innerType,r,o);let n=r.seen.get(e);n.ref=t.innerType},il=(e,r,i,o)=>{let t=e._zod.innerType;V(t,r,o);let n=r.seen.get(e);n.ref=t},no={string:_s,number:ws,boolean:xs,bigint:ks,symbol:Is,null:Ss,undefined:zs,void:Ps,never:Ts,any:Os,unknown:Ds,date:js,enum:As,literal:Ns,nan:Us,template_literal:Es,file:Cs,success:Zs,custom:Rs,function:Ls,transform:Vs,map:Ms,set:Fs,array:Gs,object:Bs,union:io,intersection:Js,tuple:Ws,record:Ks,nullable:Xs,nonoptional:Hs,default:Ys,prefault:Qs,catch:el,pipe:tl,readonly:rl,promise:nl,optional:oo,lazy:il};function ao(e,r){if("_idmap"in e){let o=e,t=Qe({...r,processors:no}),n={};for(let c of o._idmap.entries()){let[s,d]=c;V(d,t)}let a={},u={registry:o,uri:r?.uri,defs:n};t.external=u;for(let c of o._idmap.entries()){let[s,d]=c;et(t,d),re(a,s,tt(t,d))}if(Object.keys(n).length>0){let c=t.target==="draft-2020-12"?"$defs":"definitions";a.__shared={[c]:n}}return{schemas:a}}let i=Qe({...r,processors:no});return V(e,i),et(i,e),tt(i,e)}var uo=class{get metadataRegistry(){return this.ctx.metadataRegistry}get target(){return this.ctx.target}get unrepresentable(){return this.ctx.unrepresentable}get override(){return this.ctx.override}get io(){return this.ctx.io}get counter(){return this.ctx.counter}set counter(r){this.ctx.counter=r}get seen(){return this.ctx.seen}constructor(r){let i=r?.target??"draft-2020-12";i==="draft-4"&&(i="draft-04"),i==="draft-7"&&(i="draft-07"),this.ctx=Qe({processors:no,target:i,...r?.metadata&&{metadata:r.metadata},...r?.unrepresentable&&{unrepresentable:r.unrepresentable},...r?.override&&{override:r.override},...r?.io&&{io:r.io}})}process(r,i={path:[],schemaPath:[]}){return V(r,this.ctx,i)}emit(r,i){i&&(i.cycles&&(this.ctx.cycles=i.cycles),i.reused&&(this.ctx.reused=i.reused),i.external&&(this.ctx.external=i.external)),this.ctx.sharedDefsExtractedFor=void 0,this.ctx.sharedEmitDoneFor=void 0,et(this.ctx,r);let o=tt(this.ctx,r),{"~standard":t,...n}=o;return n}};var ep={};var lr={};Le(lr,{ZodAny:()=>Sl,ZodArray:()=>Ol,ZodBase64:()=>zo,ZodBase64URL:()=>Po,ZodBigInt:()=>cr,ZodBigIntFormat:()=>Do,ZodBoolean:()=>ur,ZodCIDRv4:()=>Io,ZodCIDRv6:()=>So,ZodCUID:()=>bo,ZodCUID2:()=>$o,ZodCatch:()=>ql,ZodCodec:()=>dn,ZodCreditCard:()=>bl,ZodCustom:()=>mn,ZodCustomStringFormat:()=>kt,ZodDate:()=>on,ZodDefault:()=>Bl,ZodDiscriminatedUnion:()=>jl,ZodE164:()=>To,ZodEmail:()=>po,ZodEmoji:()=>vo,ZodEnum:()=>ir,ZodExactOptional:()=>Uo,ZodFile:()=>Vl,ZodFunction:()=>ud,ZodGUID:()=>go,ZodIBAN:()=>$l,ZodIPv4:()=>xo,ZodIPv6:()=>ko,ZodISODate:()=>nt,ZodISODateTime:()=>rt,ZodISODuration:()=>ot,ZodISOTime:()=>it,ZodInstanceOf:()=>ld,ZodIntersection:()=>Al,ZodJWT:()=>Oo,ZodKSUID:()=>wo,ZodLazy:()=>id,ZodLiteral:()=>Ll,ZodMAC:()=>hl,ZodMap:()=>Zl,ZodNaN:()=>Ql,ZodNanoID:()=>ho,ZodNever:()=>Pl,ZodNonOptional:()=>Eo,ZodNull:()=>kl,ZodNullable:()=>Gl,ZodNumber:()=>ar,ZodNumberFormat:()=>It,ZodObject:()=>un,ZodOptional:()=>sn,ZodPipe:()=>ln,ZodPrefault:()=>Wl,ZodPreprocess:()=>ed,ZodPromise:()=>ad,ZodReadonly:()=>td,ZodRecord:()=>nr,ZodSet:()=>Rl,ZodString:()=>or,ZodStringFormat:()=>G,ZodSuccess:()=>Hl,ZodSymbol:()=>wl,ZodTemplateLiteral:()=>nd,ZodTransform:()=>Ml,ZodTuple:()=>Ul,ZodType:()=>E,ZodULID:()=>yo,ZodURL:()=>nn,ZodUUID:()=>Ee,ZodUndefined:()=>xl,ZodUnion:()=>cn,ZodUnknown:()=>zl,ZodVoid:()=>Tl,ZodXID:()=>_o,ZodXor:()=>Dl,_ZodString:()=>fo,_default:()=>Jl,_function:()=>mg,any:()=>Fp,array:()=>an,base64:()=>xp,base64url:()=>kp,bigint:()=>Zp,boolean:()=>_l,catch:()=>Yl,check:()=>fg,cidrv4:()=>_p,cidrv6:()=>wp,codec:()=>cg,creditCard:()=>Sp,cuid:()=>fp,cuid2:()=>pp,currencyCode:()=>jp,custom:()=>pg,date:()=>Bp,describe:()=>gg,discriminatedUnion:()=>qp,e164:()=>Ip,email:()=>np,emoji:()=>dp,enum:()=>Ao,exactOptional:()=>Fl,file:()=>ig,float32:()=>Np,float64:()=>Up,function:()=>mg,guid:()=>ip,hash:()=>Ap,hex:()=>Dp,hostname:()=>Op,httpUrl:()=>lp,iban:()=>zp,instanceof:()=>hg,int:()=>lo,int32:()=>Ep,int64:()=>Rp,intersection:()=>Nl,invertCodec:()=>sg,ipv4:()=>bp,ipv6:()=>yp,json:()=>$g,jwt:()=>Pp,keyof:()=>Jp,ksuid:()=>hp,lazy:()=>od,literal:()=>ng,looseObject:()=>Xp,looseRecord:()=>Qp,mac:()=>$p,map:()=>eg,meta:()=>vg,nan:()=>ug,nanoid:()=>mp,nativeEnum:()=>rg,never:()=>jo,nonoptional:()=>Xl,null:()=>Il,nullable:()=>rn,nullish:()=>og,number:()=>yl,object:()=>Wp,optional:()=>wt,partialRecord:()=>Yp,pipe:()=>mo,prefault:()=>Kl,preprocess:()=>yg,promise:()=>dg,readonly:()=>rd,record:()=>Cl,refine:()=>cd,set:()=>tg,strictObject:()=>Kp,string:()=>tn,stringFormat:()=>Tp,stringbool:()=>bg,success:()=>ag,superRefine:()=>sd,symbol:()=>Vp,templateLiteral:()=>lg,transform:()=>No,tuple:()=>El,uint32:()=>Cp,uint64:()=>Lp,ulid:()=>gp,undefined:()=>Mp,union:()=>sr,unknown:()=>_t,url:()=>sp,uuid:()=>op,uuidv4:()=>ap,uuidv6:()=>up,uuidv7:()=>cp,void:()=>Gp,xid:()=>vp,xor:()=>Hp});var co={};Le(co,{endsWith:()=>Jt,gt:()=>Ne,gte:()=>xe,includes:()=>Gt,length:()=>$t,lowercase:()=>Mt,lt:()=>Ae,lte:()=>we,maxLength:()=>bt,maxSize:()=>Ye,mime:()=>Kt,minLength:()=>Ge,minSize:()=>Ue,multipleOf:()=>qe,negative:()=>Qi,nonnegative:()=>to,nonpositive:()=>eo,normalize:()=>Xt,overwrite:()=>Oe,positive:()=>Yi,properties:()=>Wt,property:()=>ro,regex:()=>Vt,size:()=>ht,slugify:()=>Qt,startsWith:()=>Bt,toLowerCase:()=>qt,toUpperCase:()=>Yt,trim:()=>Ht,uppercase:()=>Ft});var tp=new WeakSet([Object.prototype,Error.prototype]);function so(e,r,i){Object.defineProperty(e,r,{configurable:!0,enumerable:!1,get(){let o=i(this);return Object.defineProperty(this,r,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,r,{value:o,configurable:!0,writable:!0})}})}var rp=(e,r)=>{aa.init(e,r),e.name="ZodError";let i=Object.getPrototypeOf(e);tp.has(i)||(tp.add(i),so(i,"format",o=>t=>zr(o,t)),so(i,"flatten",o=>t=>Sr(o,t)),so(i,"addIssue",o=>t=>{o.issues.push(t),o.message=JSON.stringify(o.issues,Pt,2)}),so(i,"addIssues",o=>t=>{o.issues.push(...t),o.message=JSON.stringify(o.issues,Pt,2)}),Object.defineProperty(i,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},zy=g("ZodError",rp),ye=g("ZodError",rp,void 0,{Parent:Error});var ol=jt(ye),al=At(ye),ul=Nt(ye),cl=Ut(ye),sl=Zn(ye),ll=Rn(ye),dl=Ln(ye),ml=Vn(ye),fl=Mn(ye),pl=Fn(ye),gl=Gn(ye),vl=Bn(ye);function Ty(){ee.localeError||K(xi())}function xt(){ee.memoizer||K({memoizer:Br()})}var E=g("ZodType",(e,r)=>(Ty(),N.init(e,r),e.def=r,e.type=r.type,e),{check(...e){let r=this.def;return this.clone(b.mergeDefs(r,{checks:[...r.checks??[],...e.map(i=>typeof i=="function"?{_zod:{check:i,def:{check:"custom"},onattach:[]}}:i)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,r){return R(this,e,r)},brand(){return this},register(e,r){return e.add(this,r),this},refine(e,r){return this.check(cd(e,r))},superRefine(e,r){return this.check(sd(e,r))},overwrite(e){return this.check(Oe(e))},optional(){return wt(this)},exactOptional(){return Fl(this)},nullable(){return rn(this)},nullish(){return wt(rn(this))},nonoptional(e){return Xl(this,e)},array(){return an(this)},or(e){return sr([this,e])},and(e){return Nl(this,e)},transform(e){return mo(this,No(e))},default(e){return Jl(this,e)},prefault(e){return Kl(this,e)},catch(e){return Yl(this,e)},pipe(e){return mo(this,e)},readonly(){return rd(this)},describe(e){let r=this.clone();return ne.add(r,{description:e}),r},meta(...e){if(e.length===0)return ne.get(this);let r=this.clone();return ne.add(r,e[0]),r},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...r){return r.length===0?e(this):e(this,...r)},get"~standard"(){return b.hide(this,"~standard",{...ri(this),jsonSchema:{input:er(this,"input"),output:er(this,"output")}})},set"~standard"(e){b.own(this,"~standard",e)},parse:function e(r,i){return ol(this,r,i,{callee:e})},parseAsync:async function e(r,i){return await al(this,r,i,{callee:e})},safeParse(e,r){return ul(this,e,r)},async safeParseAsync(e,r){return cl(this,e,r)},get spa(){return this?.safeParseAsync},set spa(e){b.own(this,"spa",e)},validate(e,r){return Pr(this,e,r)},validateAsync(e,r){return Tr(this,e,r)},encode:function e(r,i){return sl(this,r,i,{callee:e})},decode:function e(r,i){return ll(this,r,i,{callee:e})},encodeAsync:async function e(r,i){return await dl(this,r,i,{callee:e})},decodeAsync:async function e(r,i){return await ml(this,r,i,{callee:e})},safeEncode(e,r){return fl(this,e,r)},safeDecode(e,r){return pl(this,e,r)},async safeEncodeAsync(e,r){return gl(this,e,r)},async safeDecodeAsync(e,r){return vl(this,e,r)},toJSONSchema(e){return bs(this,{})(e)},get description(){return ne.get(this)?.description},get _def(){return this._zod.def}}),fo=g("_ZodString",(e,r)=>{mt.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>_s(e,i,o,t)},b.derived({format:e=>Y(e).format??null,minLength:e=>Y(e).minimum??null,maxLength:e=>Y(e).maximum??null},{regex(...e){return this.check(Vt(...e))},includes(...e){return this.check(Gt(...e))},startsWith(...e){return this.check(Bt(...e))},endsWith(...e){return this.check(Jt(...e))},min(...e){return this.check(Ge(...e))},max(...e){return this.check(bt(...e))},length(...e){return this.check($t(...e))},nonempty(...e){return this.check(Ge(1,...e))},lowercase(e){return this.check(Mt(e))},uppercase(e){return this.check(Ft(e))},trim(){return this.check(Ht())},normalize(...e){return this.check(Xt(...e))},toLowerCase(){return this.check(qt())},toUpperCase(){return this.check(Yt())},slugify(){return this.check(Qt())}})),or=g("ZodString",(e,r)=>{mt.init(e,r),fo.init(e,r)},{email(e){return this.check(Di(po,e))},url(e){return this.check(Kr(nn,e))},jwt(e){return this.check(qi(Oo,e))},emoji(e){return this.check(Ci(vo,e))},guid(e){return this.check(ji(go,e))},uuid(e){return this.check(Ai(Ee,e))},uuidv4(e){return this.check(Ni(Ee,e))},uuidv6(e){return this.check(Ui(Ee,e))},uuidv7(e){return this.check(Ei(Ee,e))},nanoid(e){return this.check(Zi(ho,e))},cuid(e){return this.check(Ri(bo,e))},cuid2(e){return this.check(Li($o,e))},ulid(e){return this.check(Vi(yo,e))},base64(e){return this.check(Ki(zo,e))},base64url(e){return this.check(Xi(Po,e))},xid(e){return this.check(Mi(_o,e))},ksuid(e){return this.check(Fi(wo,e))},ipv4(e){return this.check(Gi(xo,e))},ipv6(e){return this.check(Bi(ko,e))},cidrv4(e){return this.check(Ji(Io,e))},cidrv6(e){return this.check(Wi(So,e))},e164(e){return this.check(Hi(To,e))},datetime(e){return this.check(Xr(rt,e))},date(e){return this.check(Hr(nt,e))},time(e){return this.check(qr(it,e))},duration(e){return this.check(Yr(ot,e))}});function tn(e){return Nc(or,e)}var G=g("ZodStringFormat",(e,r)=>{L.init(e,r),fo.init(e,r)}),rt=g("ZodISODateTime",(e,r)=>{Su.init(e,r),G.init(e,r)}),nt=g("ZodISODate",(e,r)=>{zu.init(e,r),G.init(e,r)}),it=g("ZodISOTime",(e,r)=>{Pu.init(e,r),G.init(e,r)}),ot=g("ZodISODuration",(e,r)=>{Tu.init(e,r),G.init(e,r)}),po=g("ZodEmail",(e,r)=>{gu.init(e,r),G.init(e,r)});function np(e){return Di(po,e)}var go=g("ZodGUID",(e,r)=>{fu.init(e,r),G.init(e,r)});function ip(e){return ji(go,e)}var Ee=g("ZodUUID",(e,r)=>{pu.init(e,r),G.init(e,r)});function op(e){return Ai(Ee,e)}function ap(e){return Ni(Ee,e)}function up(e){return Ui(Ee,e)}function cp(e){return Ei(Ee,e)}var nn=g("ZodURL",(e,r)=>{bu.init(e,r),G.init(e,r)});function sp(e){return Kr(nn,e)}function lp(e){return Kr(nn,{protocol:Or,hostname:Ta,...b.normalizeParams(e)})}var vo=g("ZodEmoji",(e,r)=>{$u.init(e,r),G.init(e,r)});function dp(e){return Ci(vo,e)}var ho=g("ZodNanoID",(e,r)=>{yu.init(e,r),G.init(e,r)});function mp(e){return Zi(ho,e)}var bo=g("ZodCUID",(e,r)=>{_u.init(e,r),G.init(e,r)});function fp(e){return Ri(bo,e)}var $o=g("ZodCUID2",(e,r)=>{wu.init(e,r),G.init(e,r)});function pp(e){return Li($o,e)}var yo=g("ZodULID",(e,r)=>{xu.init(e,r),G.init(e,r)});function gp(e){return Vi(yo,e)}var _o=g("ZodXID",(e,r)=>{ku.init(e,r),G.init(e,r)});function vp(e){return Mi(_o,e)}var wo=g("ZodKSUID",(e,r)=>{Iu.init(e,r),G.init(e,r)});function hp(e){return Fi(wo,e)}var xo=g("ZodIPv4",(e,r)=>{Ou.init(e,r),G.init(e,r)});function bp(e){return Gi(xo,e)}var hl=g("ZodMAC",(e,r)=>{ju.init(e,r),G.init(e,r)});function $p(e){return Ec(hl,e)}var ko=g("ZodIPv6",(e,r)=>{Du.init(e,r),G.init(e,r)});function yp(e){return Bi(ko,e)}var Io=g("ZodCIDRv4",(e,r)=>{Au.init(e,r),G.init(e,r)});function _p(e){return Ji(Io,e)}var So=g("ZodCIDRv6",(e,r)=>{Nu.init(e,r),G.init(e,r)});function wp(e){return Wi(So,e)}var zo=g("ZodBase64",(e,r)=>{Uu.init(e,r),G.init(e,r)});function xp(e){return Ki(zo,e)}var Po=g("ZodBase64URL",(e,r)=>{Eu.init(e,r),G.init(e,r)});function kp(e){return Xi(Po,e)}var To=g("ZodE164",(e,r)=>{Cu.init(e,r),G.init(e,r)});function Ip(e){return Hi(To,e)}var bl=g("ZodCreditCard",(e,r)=>{Zu.init(e,r),G.init(e,r)});function Sp(e){return Cc(bl,e)}var $l=g("ZodIBAN",(e,r)=>{Ru.init(e,r),G.init(e,r)});function zp(e){return Zc($l,e)}var Oo=g("ZodJWT",(e,r)=>{Lu.init(e,r),G.init(e,r)});function Pp(e){return qi(Oo,e)}var kt=g("ZodCustomStringFormat",(e,r)=>{Vu.init(e,r),G.init(e,r)});function Tp(e,r,i={}){return yt(kt,e,r,i)}function Op(e){return yt(kt,"hostname",Pa,e)}function Dp(e){return yt(kt,"hex",Fa,e)}function jp(e){return yt(kt,"currency_code",Da,e)}function Ap(e,r){let i=r?.enc??"hex",o=`${e}_${i}`,t=Se[o];if(!t)throw new Error(`Unrecognized hash format: ${o}`);return yt(kt,o,t,r)}var ar=g("ZodNumber",(e,r)=>{mi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>ws(e,i,o,t),e.isFinite=!0},b.derived({minValue:e=>{let{minimum:r,exclusiveMinimum:i}=Y(e);return Math.max(r??Number.NEGATIVE_INFINITY,i??Number.NEGATIVE_INFINITY)},maxValue:e=>{let{maximum:r,exclusiveMaximum:i}=Y(e);return Math.min(r??Number.POSITIVE_INFINITY,i??Number.POSITIVE_INFINITY)},isInt:e=>{let{isInt:r,multipleOf:i}=Y(e);return!!r||!!i?.some(Number.isSafeInteger)},format:e=>Y(e).format??null},{gt(e,r){return this.check(Ne(e,r))},gte(e,r){return this.check(xe(e,r))},min(e,r){return this.check(xe(e,r))},lt(e,r){return this.check(Ae(e,r))},lte(e,r){return this.check(we(e,r))},max(e,r){return this.check(we(e,r))},int(e){return this.check(lo(e))},safe(e){return this.check(lo(e))},positive(e){return this.check(Ne(0,e))},nonnegative(e){return this.check(xe(0,e))},negative(e){return this.check(Ae(0,e))},nonpositive(e){return this.check(we(0,e))},multipleOf(e,r){return this.check(qe(e,r))},step(e,r){return this.check(qe(e,r))},finite(){return this}}));function yl(e){return Lc(ar,e)}var It=g("ZodNumberFormat",(e,r)=>{Mu.init(e,r),ar.init(e,r)});function lo(e){return Mc(It,e)}function Np(e){return Fc(It,e)}function Up(e){return Gc(It,e)}function Ep(e){return Bc(It,e)}function Cp(e){return Jc(It,e)}var ur=g("ZodBoolean",(e,r)=>{Rr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>xs(e,i,o,t)});function _l(e){return Wc(ur,e)}var cr=g("ZodBigInt",(e,r)=>{fi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>ks(e,i,o,t)},b.derived({minValue:e=>Y(e).minimum??null,maxValue:e=>Y(e).maximum??null,format:e=>Y(e).format??null},{gte(e,r){return this.check(xe(e,r))},min(e,r){return this.check(xe(e,r))},gt(e,r){return this.check(Ne(e,r))},lt(e,r){return this.check(Ae(e,r))},lte(e,r){return this.check(we(e,r))},max(e,r){return this.check(we(e,r))},positive(e){return this.check(Ne(BigInt(0),e))},negative(e){return this.check(Ae(BigInt(0),e))},nonpositive(e){return this.check(we(BigInt(0),e))},nonnegative(e){return this.check(xe(BigInt(0),e))},multipleOf(e,r){return this.check(qe(e,r))}}));function Zp(e){return Xc(cr,e)}var Do=g("ZodBigIntFormat",(e,r)=>{Fu.init(e,r),cr.init(e,r)});function Rp(e){return qc(Do,e)}function Lp(e){return Yc(Do,e)}var wl=g("ZodSymbol",(e,r)=>{Gu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Is(e,i,o,t)});function Vp(e){return Qc(wl,e)}var xl=g("ZodUndefined",(e,r)=>{Bu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>zs(e,i,o,t)});function Mp(e){return es(xl,e)}var kl=g("ZodNull",(e,r)=>{Ju.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ss(e,i,o,t)});function Il(e){return ts(kl,e)}var Sl=g("ZodAny",(e,r)=>{Wu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Os(e,i,o,t)});function Fp(){return rs(Sl)}var zl=g("ZodUnknown",(e,r)=>{Ku.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ds(e,i,o,t)});function _t(){return ns(zl)}var Pl=g("ZodNever",(e,r)=>{Xu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ts(e,i,o,t)});function jo(e){return is(Pl,e)}var Tl=g("ZodVoid",(e,r)=>{Hu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ps(e,i,o,t)});function Gp(e){return os(Tl,e)}var on=g("ZodDate",(e,r)=>{qu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>js(e,i,o,t),e.min=(i,o)=>e.check(xe(i,o)),e.max=(i,o)=>e.check(we(i,o))},b.derived({minDate:e=>{let{minimum:r}=Y(e);return r?new Date(r):null},maxDate:e=>{let{maximum:r}=Y(e);return r?new Date(r):null}},{}));function Bp(e){return as(on,e)}var Ol=g("ZodArray",(e,r)=>{xt(),Yu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Gs(e,i,o,t),e.element=r.element},{min(e,r){return this.check(Ge(e,r))},nonempty(e){return this.check(Ge(1,e))},max(e,r){return this.check(bt(e,r))},length(e,r){return this.check($t(e,r))},unwrap(){return this.element}});function an(e,r){return ss(Ol,e,r)}function Jp(e){let r=e._zod.def.shape;return Ao(Object.keys(r))}var un=g("ZodObject",(e,r)=>{xt(),Qu.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Bs(e,i,o,t),b.installLazyProp(e,"shape",i=>i._zod.def.shape,!1)},{keyof(){return Ao(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(b.mergeDefs(this._zod.def,{catchall:e}))},passthrough(){return this.clone(b.mergeDefs(this._zod.def,{catchall:_t()}))},loose(){return this.clone(b.mergeDefs(this._zod.def,{catchall:_t()}))},strict(){return this.clone(b.mergeDefs(this._zod.def,{catchall:jo()}))},strip(){return this.clone(b.mergeDefs(this._zod.def,{catchall:void 0}))},extend(e){return b.extend(this,e)},safeExtend(e){return b.safeExtend(this,e)},merge(e){return b.merge(this,e)},pick(e){return b.pick(this,e)},omit(e){return b.omit(this,e)},partial(...e){return b.partial(sn,this,e[0])},exactPartial(...e){return b.partial(Uo,this,e[0],"exactPartial")},required(...e){return b.required(Eo,this,e[0])}});function Wp(e,r){let i={type:"object",shape:e??{},...b.normalizeParams(r)};return new un(i)}function Kp(e,r){return new un({type:"object",shape:e,catchall:jo(),...b.normalizeParams(r)})}function Xp(e,r){return new un({type:"object",shape:e,catchall:_t(),...b.normalizeParams(r)})}var cn=g("ZodUnion",(e,r)=>{Lr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>io(e,i,o,t),e.options=r.options});function sr(e,r){return new cn({type:"union",options:e,...b.normalizeParams(r)})}var Dl=g("ZodXor",(e,r)=>{cn.init(e,r),ec.init(e,r),e._zod.processJSONSchema=(i,o,t)=>io(e,i,o,t),e.options=r.options});function Hp(e,r){return new Dl({type:"union",options:e,inclusive:!1,...b.normalizeParams(r)})}var jl=g("ZodDiscriminatedUnion",(e,r)=>{cn.init(e,r),rc.init(e,r)});function qp(e,r,i){return new jl({type:"union",options:r,discriminator:e,...b.normalizeParams(i)})}var Al=g("ZodIntersection",(e,r)=>{nc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Js(e,i,o,t)});function Nl(e,r){return new Al({type:"intersection",left:e,right:r})}var Ul=g("ZodTuple",(e,r)=>{xt(),pi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ws(e,i,o,t)},{rest(e){return this.clone({...this._zod.def,rest:e})},partial(){let e=this._zod.def;if(e.checks?.length)throw new Error(".partial() cannot be used on tuple schemas containing refinements");return this.clone({...e,items:e.items.map(r=>new sn({type:"optional",innerType:r}))})}});function El(e,r,i){let o=r instanceof N,t=o?i:r,n=o?r:null;return new Ul({type:"tuple",items:e,rest:n,...b.normalizeParams(t)})}var nr=g("ZodRecord",(e,r)=>{xt(),ic.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ks(e,i,o,t),e.keyType=r.keyType,e.valueType=r.valueType});function Cl(e,r,i){return!r||!r._zod?new nr({type:"record",keyType:tn(),valueType:e,...b.normalizeParams(r)}):new nr({type:"record",keyType:e,valueType:r,...b.normalizeParams(i)})}function Yp(e,r,i){return new nr({type:"record",keyType:e,valueType:r,...b.normalizeParams(i),partial:!0})}function Qp(e,r,i){return new nr({type:"record",keyType:e,valueType:r,mode:"loose",...b.normalizeParams(i)})}var Zl=g("ZodMap",(e,r)=>{xt(),oc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ms(e,i,o,t),e.keyType=r.keyType,e.valueType=r.valueType,e.min=(...i)=>e.check(Ue(...i)),e.nonempty=i=>e.check(Ue(1,i)),e.max=(...i)=>e.check(Ye(...i)),e.size=(...i)=>e.check(ht(...i))});function eg(e,r,i){return new Zl({type:"map",keyType:e,valueType:r,...b.normalizeParams(i)})}var Rl=g("ZodSet",(e,r)=>{xt(),ac.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Fs(e,i,o,t),e.min=(...i)=>e.check(Ue(...i)),e.nonempty=i=>e.check(Ue(1,i)),e.max=(...i)=>e.check(Ye(...i)),e.size=(...i)=>e.check(ht(...i))});function tg(e,r){return new Rl({type:"set",valueType:e,...b.normalizeParams(r)})}var ir=g("ZodEnum",(e,r)=>{uc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(o,t,n)=>As(e,o,t,n),e.enum=r.entries,e.options=[...e._zod.values];let i=new Set(Object.keys(r.entries));e.extract=(o,t)=>{let n={};for(let a of o)if(i.has(a))n[a]=r.entries[a];else throw new Error(`Key ${a} not found in enum`);return new ir({...r,checks:[],...b.normalizeParams(t),entries:n})},e.exclude=(o,t)=>{let n={...r.entries};for(let a of o)if(i.has(a))delete n[a];else throw new Error(`Key ${a} not found in enum`);return new ir({...r,checks:[],...b.normalizeParams(t),entries:n})}});function Ao(e,r){let i=Array.isArray(e)?Object.fromEntries(e.map(o=>[o,o])):e;return new ir({type:"enum",entries:i,...b.normalizeParams(r)})}function rg(e,r){return new ir({type:"enum",entries:e,...b.normalizeParams(r)})}var Ll=g("ZodLiteral",(e,r)=>{cc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ns(e,i,o,t),e.values=new Set(r.values),Object.defineProperty(e,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function ng(e,r){return new Ll({type:"literal",values:Array.isArray(e)?e:[e],...b.normalizeParams(r)})}var Vl=g("ZodFile",(e,r)=>{sc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Cs(e,i,o,t),e.min=(i,o)=>e.check(Ue(i,o)),e.max=(i,o)=>e.check(Ye(i,o)),e.mime=(i,o)=>e.check(Kt(Array.isArray(i)?i:[i],o))});function ig(e){return ls(Vl,e)}var Ml=g("ZodTransform",(e,r)=>{xt(),lc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Vs(e,i,o,t),e._zod.parse=(i,o)=>{if(o.direction==="backward")throw new He(e.constructor.name);i.addIssue=n=>{if(typeof n=="string")i.issues.push(b.issue(n,i.value,r));else{let a=n;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),"input"in a||(a.input=i.value),a.inst??(a.inst=e),i.issues.push(b.issue(a))}};let t=r.transform(i.value,i);return t instanceof Promise?t.then(n=>(i.value=n,i)):(i.value=t,i)}});function No(e){return new Ml({type:"transform",transform:e})}var sn=g("ZodOptional",(e,r)=>{gi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>oo(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function wt(e){return new sn({type:"optional",innerType:e})}var Uo=g("ZodExactOptional",(e,r)=>{dc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>oo(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Fl(e){return new Uo({type:"optional",innerType:e})}var Gl=g("ZodNullable",(e,r)=>{mc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Xs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function rn(e){return new Gl({type:"nullable",innerType:e})}function og(e){return wt(rn(e))}var Bl=g("ZodDefault",(e,r)=>{fc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ys(e,i,o,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Jl(e,r){return new Bl({type:"default",innerType:e,get defaultValue(){return typeof r=="function"?r():b.shallowClone(r)}})}var Wl=g("ZodPrefault",(e,r)=>{pc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Qs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Kl(e,r){return new Wl({type:"prefault",innerType:e,get defaultValue(){return typeof r=="function"?r():b.shallowClone(r)}})}var Eo=g("ZodNonOptional",(e,r)=>{gc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Hs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function Xl(e,r){return new Eo({type:"nonoptional",innerType:e,...b.normalizeParams(r)})}var Hl=g("ZodSuccess",(e,r)=>{vc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Zs(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function ag(e){return new Hl({type:"success",innerType:e})}var ql=g("ZodCatch",(e,r)=>{hc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>el(e,i,o,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Yl(e,r){return new ql({type:"catch",innerType:e,catchValue:typeof r=="function"?r:b.constantCatch(r)})}var Ql=g("ZodNaN",(e,r)=>{bc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Us(e,i,o,t)});function ug(e){return cs(Ql,e)}var ln=g("ZodPipe",(e,r)=>{vi.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>tl(e,i,o,t),e.in=r.in,e.out=r.out});function mo(e,r){return new ln({type:"pipe",in:e,out:r})}var dn=g("ZodCodec",(e,r)=>{ln.init(e,r),Vr.init(e,r)});function cg(e,r,i){return new dn({type:"pipe",in:e,out:r,transform:i.decode,reverseTransform:i.encode})}function sg(e){let r=e._zod.def;return new dn({type:"pipe",in:r.out,out:r.in,transform:r.reverseTransform,reverseTransform:r.transform})}var ed=g("ZodPreprocess",(e,r)=>{ln.init(e,r),$c.init(e,r)}),td=g("ZodReadonly",(e,r)=>{yc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>rl(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function rd(e){return new td({type:"readonly",innerType:e})}var nd=g("ZodTemplateLiteral",(e,r)=>{_c.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Es(e,i,o,t)});function lg(e,r){return new nd({type:"template_literal",parts:e,...b.normalizeParams(r)})}var id=g("ZodLazy",(e,r)=>{Mr.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>il(e,i,o,t),e.unwrap=()=>e._zod.def.getter()});function od(e){return new id({type:"lazy",getter:e})}var ad=g("ZodPromise",(e,r)=>{xc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>nl(e,i,o,t),e.unwrap=()=>e._zod.def.innerType});function dg(e){return new ad({type:"promise",innerType:e})}var ud=g("ZodFunction",(e,r)=>{wc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Ls(e,i,o,t)});function mg(e){return new ud({type:"function",input:Array.isArray(e?.input)?El(e?.input):e?.input??an(_t()),output:e?.output??_t()})}var mn=g("ZodCustom",(e,r)=>{kc.init(e,r),E.init(e,r),e._zod.processJSONSchema=(i,o,t)=>Rs(e,i,o,t)});function fg(e){let r=new B({check:"custom"});return r._zod.check=e,r}function pg(e,r){return ds(mn,e??(()=>!0),r)}function cd(e,r={}){return ms(mn,e,r)}function sd(e,r){return fs(e,r)}var gg=ps,vg=gs,ld=g("ZodInstanceOf",(e,r)=>{mn.init(e,r)},{properties(e,r){return this.check(Wt(e,r))}});function hg(e,r={}){let i=new ld({type:"custom",check:"custom",fn:o=>o instanceof e,abort:!0,...b.normalizeParams(r)});return i._zod.bag.Class=e,i._zod.check=o=>{o.value instanceof e||o.issues.push({code:"invalid_type",expected:e.name,input:o.value,inst:i,path:[...i._zod.def.path??[]]})},i}var bg=(...e)=>vs({Codec:dn,Boolean:ur,String:or},...e);function $g(e){let r=od(()=>sr([tn(e),yl(),_l(),Il(),an(r),Cl(tn(),r)]));return r}function yg(e,r){return new ed({type:"pipe",in:No(e),out:r})}var Oy={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"};function Dy(e){K({customError:e})}function jy(){return K().customError}var dd;dd||(dd={});var fn={};Le(fn,{ZodISODate:()=>nt,ZodISODateTime:()=>rt,ZodISODuration:()=>ot,ZodISOTime:()=>it,date:()=>Ny,datetime:()=>Ay,duration:()=>Ey,time:()=>Uy});function Ay(e){return Xr(rt,e)}function Ny(e){return Hr(nt,e)}function Uy(e){return qr(it,e)}function Ey(e){return Yr(ot,e)}var z={...lr,...co,iso:fn},Cy=new Set(["$schema","$ref","$defs","definitions","$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor","type","enum","const","anyOf","oneOf","allOf","not","properties","required","additionalProperties","patternProperties","propertyNames","minProperties","maxProperties","items","prefixItems","additionalItems","minItems","maxItems","uniqueItems","contains","minContains","maxContains","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","description","default","contentEncoding","contentMediaType","contentSchema","unevaluatedItems","unevaluatedProperties","if","then","else","dependentSchemas","dependentRequired","nullable","readOnly"]);function Zy(e,r){let i=e.$schema;return i==="https://json-schema.org/draft/2020-12/schema"?"draft-2020-12":i==="http://json-schema.org/draft-07/schema#"?"draft-7":i==="http://json-schema.org/draft-04/schema#"?"draft-4":r??"draft-2020-12"}function _g(e,r){return e.map((i,o)=>o<r?i:i.optional())}function Ry(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Ly(e,r){if(!e.startsWith("#"))throw new Error("External $ref is not supported, only local refs (#/...) are allowed");let i=e.slice(1).split("/").filter(Boolean);if(i.length===0)return r.rootSchema;let o=r.version==="draft-2020-12"?"$defs":"definitions";if(i[0]===o){let t=i[1]===void 0?void 0:Ry(i[1]);if(!t||!r.defs[t])throw new Error(`Reference not found: ${e}`);return r.defs[t]}throw new Error(`Reference not found: ${e}`)}function Vy(e,r){return z.transform(o=>o).check(o=>{let t=o.value;if(typeof t!="object"||t===null||Array.isArray(t))return;let n=Object.getOwnPropertyNames(t);if(r.minProperties!==void 0&&n.length<r.minProperties&&o.issues.push({origin:"object",code:"too_small",minimum:r.minProperties,inclusive:!0,message:`Too small: expected object to have >=${r.minProperties} properties`,input:t,inst:e,continue:!0}),r.maxProperties!==void 0&&n.length>r.maxProperties&&o.issues.push({origin:"object",code:"too_big",maximum:r.maxProperties,inclusive:!0,message:`Too big: expected object to have <=${r.maxProperties} properties`,input:t,inst:e,continue:!0}),r.keySchema)for(let a of n){let u=r.keySchema.safeParse(a);u.success||o.issues.push({code:"invalid_key",origin:"record",issues:u.error.issues,input:a,path:[a],continue:!0})}}).pipe(e)}function md(e,r){if(e===null)return"z";let i=typeof e;if(i!=="object"){if(i==="number"&&Number.isNaN(e))return null;let o=String(e);return`${i[0]}${o.length}:${o}`}if(r.has(e))return null;r.add(e);try{if(Array.isArray(e)){let n=[];for(let a of e){let u=md(a,r);if(u===null)return null;n.push(u)}return`a${n.length}:[${n.join(",")}]`}let o=Object.keys(e).sort(),t=[];for(let n of o){let a=md(e[n],r);if(a===null)return null;t.push(`${n.length}:${n}=${a}`)}return`o${t.length}:{${t.join(",")}}`}finally{r.delete(e)}}var My=new Set(["items","prefixItems","additionalItems","additionalProperties","contains","propertyNames","not","if","then","else","allOf","anyOf","oneOf","unevaluatedItems","unevaluatedProperties","contentSchema"]),Fy=new Set(["properties","patternProperties","dependentSchemas","dependencies","$defs","definitions"]);function pn(e){return typeof e!="object"||e===null?!1:Array.isArray(e)?e.some(pn):typeof e.$ref=="string"?!0:Object.entries(e).some(([r,i])=>My.has(r)?pn(i):!Fy.has(r)||typeof i!="object"||i===null?!1:Object.values(i).some(pn))}function wg(e){return e===1?"element":"elements"}function Gy(e,r){return z.transform(o=>o).check(o=>{let t=o.value;if(Array.isArray(t)){if(r.uniqueItems===!0){let n=new Map;for(let a=0;a<t.length;a++){let u=md(t[a],new Set);if(u===null)continue;let c=n.get(u);if(c===void 0){n.set(u,a);continue}o.issues.push({code:"custom",message:`Array items must be unique: element at index ${a} duplicates the one at index ${c}`,input:t,path:[a],continue:!0})}}if(r.containsSchema){let n=r.minContains??1,a=r.maxContains!==void 0?r.maxContains+1:Number.POSITIVE_INFINITY,u=0;for(let c of t)if(r.containsSchema.safeParse(c).success&&++u>=a)break;u<n&&o.issues.push({code:"custom",message:`Array must contain at least ${n} matching ${wg(n)}; found ${u}`,input:t,continue:!0}),r.maxContains!==void 0&&u>r.maxContains&&o.issues.push({code:"custom",message:`Array must contain at most ${r.maxContains} matching ${wg(r.maxContains)}`,input:t,continue:!0})}}}).pipe(e)}function xg(e,r){if(e!==!1)return e===void 0||e===!0?z.any():me(e,r)}var By=/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;function kg(e,r){if(e.not!==void 0){if(typeof e.not=="object"&&Object.keys(e.not).length===0)return z.never();throw new Error("not is not supported in Zod (except { not: {} } for never)")}if(e.unevaluatedItems!==void 0)throw new Error("unevaluatedItems is not supported");if(e.unevaluatedProperties!==void 0)throw new Error("unevaluatedProperties is not supported");if(e.if!==void 0||e.then!==void 0||e.else!==void 0)throw new Error("Conditional schemas (if/then/else) are not supported");if(e.dependentSchemas!==void 0||e.dependentRequired!==void 0)throw new Error("dependentSchemas and dependentRequired are not supported");if(e.$ref){let t=e.$ref;if(r.refs.has(t))return r.refs.get(t);if(r.processing.has(t))return z.lazy(()=>{if(!r.refs.has(t))throw new Error(`Circular reference not resolved: ${t}`);return r.refs.get(t)});r.processing.add(t);let n=Ly(t,r),a=me(n,r);return r.refs.set(t,a),r.processing.delete(t),a}if(e.enum!==void 0){let t=e.enum;if(r.version==="openapi-3.0"&&e.nullable===!0&&t.length===1&&t[0]===null)return z.null();if(t.length===0)return z.never();if(t.length===1)return z.literal(t[0]);if(t.every(a=>typeof a=="string"))return z.enum(t);let n=t.map(a=>z.literal(a));return n.length<2?n[0]:z.union([n[0],n[1],...n.slice(2)])}if(e.const!==void 0)return z.literal(e.const);let i=e.type;if(Array.isArray(i)){let t=i.map(n=>{let a={...e,type:n};return kg(a,r)});return t.length===0?z.never():t.length===1?t[0]:z.union(t)}if(!i)return z.any();let o;switch(i){case"string":{let t=z.string();if(e.format){let n=e.format;n==="email"?t=t.check(z.email()):n==="uri"||n==="uri-reference"?t=t.check(z.url()):n==="uuid"||n==="guid"?t=t.check(z.uuid()):n==="date-time"?t=t.check(z.iso.datetime({offset:!0})):n==="date"?t=t.check(z.iso.date()):n==="time"?t=t.check(z.regex(By)):n==="duration"?t=t.check(z.iso.duration()):n==="hostname"?t=t.check(z.hostname()):n==="ipv4"?t=t.check(z.ipv4()):n==="ipv6"?t=t.check(z.ipv6()):n==="mac"?t=t.check(z.mac()):n==="cidr"?t=t.check(z.cidrv4()):n==="cidr-v6"?t=t.check(z.cidrv6()):n==="base64"?t=t.check(z.base64()):n==="base64url"?t=t.check(z.base64url()):n==="e164"?t=t.check(z.e164()):n==="credit_card"?t=t.check(z.creditCard()):n==="iban"?t=t.check(z.iban()):n==="jwt"?t=t.check(z.jwt()):n==="emoji"?t=t.check(z.emoji()):n==="nanoid"?t=t.check(z.nanoid()):n==="cuid"?t=t.check(z.cuid()):n==="cuid2"?t=t.check(z.cuid2()):n==="ulid"?t=t.check(z.ulid()):n==="xid"?t=t.check(z.xid()):n==="ksuid"&&(t=t.check(z.ksuid()))}typeof e.minLength=="number"&&(t=t.min(e.minLength)),typeof e.maxLength=="number"&&(t=t.max(e.maxLength)),e.pattern&&(t=t.regex(new RegExp(e.pattern))),o=t;break}case"number":case"integer":{let t=i==="integer"?z.number().int():z.number();typeof e.minimum=="number"&&e.exclusiveMinimum!==!0&&(t=t.min(e.minimum)),typeof e.maximum=="number"&&e.exclusiveMaximum!==!0&&(t=t.max(e.maximum)),typeof e.exclusiveMinimum=="number"?t=t.gt(e.exclusiveMinimum):e.exclusiveMinimum===!0&&typeof e.minimum=="number"&&(t=t.gt(e.minimum)),typeof e.exclusiveMaximum=="number"?t=t.lt(e.exclusiveMaximum):e.exclusiveMaximum===!0&&typeof e.maximum=="number"&&(t=t.lt(e.maximum)),typeof e.multipleOf=="number"&&(t=t.multipleOf(e.multipleOf)),o=t;break}case"boolean":{o=z.boolean();break}case"null":{o=z.null();break}case"object":{let t={},n=e.properties||{},a=new Set(e.required||[]),u=typeof e.additionalProperties=="object"?me(e.additionalProperties,r):void 0;for(let[m,p]of Object.entries(n)){let f=me(p,r);re(t,m,a.has(m)?f:f.optional())}if(e.patternProperties){let m=e.patternProperties,p=Object.keys(m),f=[];for(let w of p){let x=me(m[w],r),P=z.string().regex(new RegExp(w));f.push(z.looseRecord(P,x))}let h=[];if(Object.keys(t).length>0&&h.push(z.object(t).passthrough()),h.push(...f),h.length===0)o=z.object({}).passthrough();else if(h.length===1)o=h[0];else{let w=z.intersection(h[0],h[1]);for(let x=2;x<h.length;x++)w=z.intersection(w,h[x]);o=w}if(e.additionalProperties===!1){let w=Object.keys(t),x=p.map(S=>new RegExp(S)),P=o;o=o.check(S=>{if(!ke(S.value))return;let j=[];for(let O of Object.keys(S.value))w.includes(O)||x.some(U=>U.test(O))||j.push(O);j.length&&S.issues.push({code:"unrecognized_keys",keys:j,input:S.value,inst:P})})}}else{let m=z.object(t);e.additionalProperties===!1?o=m.strict():u?o=m.catchall(u):o=m.passthrough()}let c=e.propertyNames!==void 0&&e.propertyNames!==!0,s=typeof e.minProperties=="number"?e.minProperties:void 0,d=typeof e.maxProperties=="number"?e.maxProperties:void 0;if(c||s!==void 0||d!==void 0){let m;if(c){let p=typeof e.propertyNames=="object"&&e.propertyNames.type===void 0?{type:"string",...e.propertyNames}:e.propertyNames;m=me(p,r)}o=Vy(o,{keySchema:m,minProperties:s,maxProperties:d})}break}case"array":{let t=e.prefixItems,n=e.items;if(t&&Array.isArray(t)){let a=typeof e.minItems=="number"?e.minItems:0,u=t.map(m=>me(m,r)),c=_g(u,a),s=Array.isArray(n)?void 0:xg(n,r),d=z.tuple(c);o=s?d.rest(s):d,typeof e.minItems=="number"&&(o=o.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(o=o.check(z.maxLength(e.maxItems)))}else if(Array.isArray(n)){let a=typeof e.minItems=="number"?e.minItems:0,u=n.map(m=>me(m,r)),c=_g(u,a),s=xg(e.additionalItems,r),d=z.tuple(c);o=s?d.rest(s):d,typeof e.minItems=="number"&&(o=o.check(z.minLength(e.minItems))),typeof e.maxItems=="number"&&(o=o.check(z.maxLength(e.maxItems)))}else if(n!==void 0){let a=me(n,r),u=z.array(a);typeof e.minItems=="number"&&(u=u.min(e.minItems)),typeof e.maxItems=="number"&&(u=u.max(e.maxItems)),o=u}else o=z.array(z.any());(e.uniqueItems===!0||e.contains!==void 0)&&(o=Gy(o,{uniqueItems:e.uniqueItems===!0,containsSchema:e.contains!==void 0?me(e.contains,r):void 0,minContains:typeof e.minContains=="number"?e.minContains:void 0,maxContains:typeof e.maxContains=="number"?e.maxContains:void 0}));break}default:throw new Error(`Unsupported type: ${i}`)}return o}function me(e,r){if(typeof e=="boolean")return e?z.any():z.never();let i=kg(e,r),o=e.type||e.enum!==void 0||e.const!==void 0;if(e.anyOf&&Array.isArray(e.anyOf)){let u=e.anyOf.map(s=>me(s,r)),c=z.union(u);i=o?z.intersection(i,c):c}if(e.oneOf&&Array.isArray(e.oneOf)){let u=e.oneOf.map(s=>me(s,r)),c=z.xor(u);i=o?z.intersection(i,c):c}if(e.allOf&&Array.isArray(e.allOf))if(e.allOf.length===0)i=o?i:z.any();else{let u=o?i:me(e.allOf[0],r),c=o?0:1;for(let s=c;s<e.allOf.length;s++)u=z.intersection(u,me(e.allOf[s],r));i=u}e.nullable===!0&&r.version==="openapi-3.0"&&(i=z.nullable(i)),e.readOnly===!0&&(i=z.readonly(i)),e.default!==void 0&&(i=i.default(e.default));let t={},n=["$id","id","$comment","$anchor","$vocabulary","$dynamicRef","$dynamicAnchor"];for(let u of n)u in e&&(t[u]=e[u]);let a=["contentEncoding","contentMediaType","contentSchema"];for(let u of a)u in e&&(t[u]=e[u]);if(e.type==="object"&&e.$ref===void 0){e.propertyNames!==void 0&&!pn(e.propertyNames)&&(t.propertyNames=e.propertyNames);for(let u of["minProperties","maxProperties"])e[u]!==void 0&&(t[u]=e[u])}if(e.type==="array"&&e.$ref===void 0){e.contains!==void 0&&!pn(e.contains)&&(t.contains=e.contains);for(let u of["uniqueItems","minContains","maxContains"])e[u]!==void 0&&(t[u]=e[u])}for(let u of Object.keys(e))Cy.has(u)||re(t,u,e[u]);return Object.keys(t).length>0&&r.registry.add(i,t),e.description&&(i=i.describe(e.description)),i}function Ig(e,r){if(typeof e=="boolean")return e?z.any():z.never();let i;try{i=JSON.parse(JSON.stringify(e))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}let o=Zy(i,r?.defaultTarget),t=i.$defs||i.definitions||{},n={version:o,defs:t,refs:new Map,processing:new Set,rootSchema:i,registry:r?.registry??ne};return me(i,n)}var Sg=Symbol("z.visit/resolving");function gn(e,r){let i=typeof r=="function"?r:(a,u)=>{let c=r[a._zod.def.type];return c?c(a,u):a},o=new Map;function t(a){let u=o.get(a);if(u===Sg)return new Mr({type:"lazy",getter:()=>o.get(a)});if(u!==void 0)return u;o.set(a,Sg);let c=n(a),s=i(c,c!==a);return o.set(a,s),s}function n(a){let u=a._zod.def,c=u.type;switch(c){case"object":{let s=u.shape,d=Object.keys(s),m=!1,p={};for(let h of d){let w=t(s[h]);w!==s[h]&&(m=!0),p[h]=w}let f=u.catchall;return u.catchall&&(f=t(u.catchall),f!==u.catchall&&(m=!0)),m?R(a,{...u,shape:p,catchall:f}):a}case"array":{let s=t(u.element);return s===u.element?a:R(a,{...u,element:s})}case"tuple":{let s=u.items,d=!1,m=[];for(let f of s){let h=t(f);h!==f&&(d=!0),m.push(h)}let p=u.rest;return u.rest&&(p=t(u.rest),p!==u.rest&&(d=!0)),d?R(a,{...u,items:m,rest:p}):a}case"record":case"map":{let s=t(u.keyType),d=t(u.valueType);return s===u.keyType&&d===u.valueType?a:R(a,{...u,keyType:s,valueType:d})}case"set":{let s=t(u.valueType);return s===u.valueType?a:R(a,{...u,valueType:s})}case"union":{let s=u.options,d=!1,m=[];for(let p of s){let f=t(p);f!==p&&(d=!0),m.push(f)}return d?R(a,{...u,options:m}):a}case"intersection":{let s=t(u.left),d=t(u.right);return s===u.left&&d===u.right?a:R(a,{...u,left:s,right:d})}case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":{let s=t(u.innerType);return s===u.innerType?a:R(a,{...u,innerType:s})}case"pipe":{let s=t(u.in),d=t(u.out);return s===u.in&&d===u.out?a:R(a,{...u,in:s,out:d})}case"function":{let s=t(u.input),d=t(u.output);return s===u.input&&d===u.output?a:R(a,{...u,input:s,output:d})}case"lazy":{let s=u.getter,{_cachedInner:d,...m}=u;return R(a,{...m,getter:()=>t(s())})}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":return a;default:return a}}return t(e)}function zg(e){return gn(e,{object:r=>r.partial(),union:r=>{let i=r._zod.def;return i.discriminator===void 0?r:sr(i.options)}})}function Jy(e,r){if(!r?.length)return e;let i=e._zod.def;return R(e,Pe(i,{checks:[...i.checks??[],...r]}),{parent:!0})}function Pg(e){return Jy(e.out,e.checks)}function Wy(e){return e.in._zod.traits.has("$ZodTransform")?Pg(e):e.in}function Tg(e){return gn(e,{pipe:r=>Wy(r._zod.def),default:(r,i)=>i?wt(r._zod.def.innerType):r,catch:(r,i)=>i?r._zod.def.innerType:r})}function Og(e){return gn(e,{pipe:r=>Pg(r._zod.def),prefault:(r,i)=>i?r._zod.def.innerType:r})}var fd={};Le(fd,{bigint:()=>qy,boolean:()=>Hy,date:()=>Yy,number:()=>Xy,string:()=>Ky});function Ky(e){return Uc(or,e)}function Xy(e){return Vc(ar,e)}function Hy(e){return Kc(ur,e)}function qy(e){return Hc(cr,e)}function Yy(e){return us(on,e)}var fe=l.strictObject({tabId:l.number().int().nonnegative().optional()}),pd=l.strictObject({stable:l.boolean(),stabilityWaitMs:l.number().finite().nonnegative(),lastMutationAgoMs:l.number().finite().nonnegative(),fontsReady:l.boolean(),pendingImages:l.number().int().nonnegative().max(1e6),timeoutReached:l.boolean()}),Dg=fe.extend({maxEntries:l.number().int().min(1).max(100).default(50),reset:l.boolean().default(!0)}),Qy=fe.extend({selector:l.string().min(1).max(2048),durationMs:l.number().int().min(500).max(3e4).default(3e3)}),xI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),highlighted:l.boolean()}),hn=l.strictObject({level:l.enum(["warn","error"]),message:l.string().max(512),timestamp:l.number().finite().nonnegative()}),gd=l.strictObject({url:l.url().max(1024),method:l.string().max(16),resourceType:l.string().max(32),status:l.number().int().min(100).max(599).optional(),error:l.string().max(128).optional(),timestamp:l.number().finite().nonnegative()}),kI=l.strictObject({tabId:l.number().int().nonnegative(),entries:l.array(hn).max(100),dropped:l.number().int().nonnegative(),forwardingDropped:l.number().int().nonnegative()}),II=l.strictObject({tabId:l.number().int().nonnegative(),entries:l.array(gd).max(100),dropped:l.number().int().nonnegative()}),vd=l.strictObject({url:l.url(),title:l.string().max(160),readyState:l.enum(["loading","interactive","complete"]),viewport:l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive()}),scroll:l.strictObject({x:l.number().finite(),y:l.number().finite()}),stabilityPending:l.boolean(),consoleInstrumentationActive:l.boolean(),consoleForwardingDropped:l.number().int().nonnegative()}),SI=vd.extend({tabId:l.number().int().nonnegative(),targetState:l.enum(["authorized","reauthorization_required","none"]),runtimeErrorCount:l.number().int().nonnegative(),consoleEntryCount:l.number().int().nonnegative(),networkFailureCount:l.number().int().nonnegative()}),bn=l.enum(["click","type","press_key","hover","scroll","select","focus"]),vn=fe.extend({selector:l.string().min(1).max(2048)}),e_=vn.extend({text:l.string().max(4096),clear:l.boolean().default(!0)}),t_=fe.extend({selector:l.string().min(1).max(2048).optional(),key:l.string().max(12).refine(e=>e.length===1||["Enter","Escape","Tab","Backspace","Delete","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"].includes(e)),shift:l.boolean().default(!1)}),r_=fe.extend({selector:l.string().min(1).max(2048).optional(),x:l.number().finite().min(-1e6).max(1e6).default(0),y:l.number().finite().min(-1e6).max(1e6).default(0),mode:l.enum(["by","to"]).default("by")}),n_=vn.extend({value:l.string().max(4096)}),zI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),action:bn,inputSource:l.literal("dom"),completed:l.literal(!0),scroll:l.strictObject({x:l.number().finite(),y:l.number().finite()}).optional()}),Ce=fe.extend({url:l.url().optional(),format:l.enum(["png","jpeg"]).default("jpeg"),quality:l.number().int().min(0).max(100).default(85),waitForStable:l.boolean().default(!1),includeOverlay:l.boolean().optional(),stableWindowMs:l.number().int().min(20).max(1e3).default(100),maxWaitMs:l.number().int().min(50).max(5e3).default(2e3)}),i_=fe.extend({bypassCache:l.boolean().default(!1)}),o_=Ce.extend({x:l.number().finite().nonnegative(),y:l.number().finite().nonnegative(),width:l.number().finite().positive().max(32768),height:l.number().finite().positive().max(32768)}),a_=Ce.extend({selector:l.string().min(1).max(2048),padding:l.number().finite().min(0).max(1e3).default(0)}),u_=Ce.extend({maxPixels:l.number().int().min(1).max(32e6).default(16e6),maxSegments:l.number().int().min(1).max(64).default(32),timeoutMs:l.number().int().min(500).max(8e3).default(7e3)}),c_=fe.extend({url:l.url()}),PI=l.strictObject({baseline:l.uuid().optional().describe("A prior PNG imageReference from this session. Omit and use referenceImagePath instead to diff against an external design reference."),referenceImagePath:l.string().min(1).max(4096).optional().describe("Path (relative to the MCP server's working directory, or absolute) to a local PNG design reference to diff the live capture against. Exactly one of baseline/referenceImagePath is required."),current:l.uuid().optional(),tabId:l.number().int().nonnegative().optional().describe("Only used with referenceImagePath when current is omitted, to select which tab to capture. Ignored otherwise (baseline's own tab is used)."),threshold:l.number().finite().min(0).max(1).default(.1),checkpoint:l.string().min(1).max(200).regex(/^[A-Za-z0-9_-]+$/).optional().describe("Visual Convergence best-so-far tracking id (e.g. 'hero-desktop'). Only meaningful together with referenceImagePath: persists the best-known result locally and objectively reports isBest/regressed on every call, independent of the agent's own assessment.")}),jg=l.enum(["mobile-small","mobile","tablet","desktop","desktop-wide"]),s_=fe.extend({profile:jg.optional(),width:l.number().int().min(200).max(8192).optional(),height:l.number().int().min(200).max(8192).optional(),dedicatedPreview:l.boolean().default(!0),close:l.boolean().optional().describe("Close the current dedicated preview window instead of creating or resizing one. Width/height/profile are ignored when true. Idempotent: has no effect if no preview is open.")}),TI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),windowId:l.number().int().nonnegative(),width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive(),zoom:l.number().finite().positive(),outerWidth:l.number().int().positive(),outerHeight:l.number().int().positive(),dedicatedPreview:l.boolean(),sourceTabId:l.number().int().nonnegative().optional(),requested:l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),profile:jg.optional()}).optional(),exact:l.boolean().optional(),attempts:l.number().int().min(0).max(3).optional(),requiresTargetSelection:l.boolean().optional(),sourceWindowUnchanged:l.boolean().optional(),previewClosed:l.boolean().optional().describe("Present when close:true was requested. True if a dedicated preview window was actually open and closed; false if there was none to close.")}),Ag=fe.extend({selector:l.string().min(1).max(2048).optional(),depth:l.number().int().min(0).max(8).default(3),maxNodes:l.number().int().min(1).max(300).default(100),textLength:l.number().int().min(0).max(300).default(160),maxBytes:l.number().int().min(2048).max(65536).default(32768)}),l_=Ag.extend({selector:l.string().min(1).max(2048)}),d_=fe.extend({maxRegions:l.number().int().min(1).max(100).default(50),reset:l.boolean().default(!0)}),m_=l.enum(["highlight","clear_highlight","capture_region","capture_element","capture_full_page","get_dom","get_element","get_changed_regions","get_viewport","set_viewport",...bn.options,"get_console","get_network_failures","get_page_status"]),Ng=l.strictObject({x:l.number().finite(),y:l.number().finite(),width:l.number().finite().nonnegative(),height:l.number().finite().nonnegative()}),f_=l.strictObject({index:l.number().int().nonnegative(),parent:l.number().int().nonnegative().optional(),depth:l.number().int().min(0).max(8),tag:l.string().max(80),id:l.string().max(160).optional(),classes:l.array(l.string().max(80)).max(6).optional(),role:l.string().max(80).optional(),text:l.string().max(300).optional(),ariaLabel:l.string().max(300).optional(),name:l.string().max(160).optional(),type:l.string().max(80).optional(),href:l.string().max(1024).optional(),bounds:Ng,visible:l.boolean(),redacted:l.boolean().optional(),disabled:l.boolean().optional(),checked:l.boolean().optional(),selected:l.boolean().optional()}),OI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),nodes:l.array(f_).max(300),truncated:l.boolean(),payloadBytes:l.number().int().max(65536)}),DI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),regions:l.array(Ng.extend({reason:l.enum(["mutation","resize","attribute","text"]),selector:l.string().max(240).optional()})).max(100),trackingStarted:l.boolean(),dropped:l.number().int().nonnegative(),coverage:l.literal("potential-dom-and-layout-changes")}),hd=l.strictObject({type:l.enum(["error","unhandledrejection","console-error"]),message:l.string().max(4096),source:l.string().max(2048).optional(),line:l.number().int().nonnegative().optional(),column:l.number().int().nonnegative().optional(),timestamp:l.number().nonnegative()}),Ug=l.strictObject({extensionVersion:l.string().max(80).optional(),extensionId:l.string().min(1).max(256).optional(),capabilities:l.array(m_).max(20).optional(),selectedTab:l.number().int().nonnegative().nullable(),url:l.string().max(2048).nullable(),targetState:l.enum(["none","authorized","reauthorization_required"]).optional(),browser:l.strictObject({name:l.enum(["firefox","chrome"]),version:l.string().max(80)}).optional(),backgroundCapture:l.strictObject({enabled:l.boolean(),permissionGranted:l.boolean()}).optional()}),Eg=l.discriminatedUnion("type",[l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("highlight"),payload:Qy}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("clear_highlight"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_console"),payload:Dg}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_network_failures"),payload:Dg}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_page_status"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("click"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("type"),payload:e_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("press_key"),payload:t_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("hover"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("scroll"),payload:r_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("select"),payload:n_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("focus"),payload:vn}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_viewport"),payload:fe}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("set_viewport"),payload:s_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_dom"),payload:Ag}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_element"),payload:l_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_changed_regions"),payload:d_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_region"),payload:o_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_element"),payload:a_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture_full_page"),payload:u_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("capture"),payload:Ce}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("reload"),payload:i_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("navigate"),payload:c_}),l.strictObject({id:l.uuid(),version:l.literal(1),type:l.literal("get_errors"),payload:fe})]),jI=l.discriminatedUnion("ok",[l.strictObject({id:l.uuid(),version:l.literal(1),ok:l.literal(!0),result:l.unknown()}),l.strictObject({id:l.uuid(),version:l.literal(1),ok:l.literal(!1),error:l.strictObject({code:l.string().max(80),message:l.string().max(4096),stability:pd.optional()})})]),AI=l.strictObject({version:l.literal(1),type:l.literal("hello"),token:l.string().regex(/^[a-f0-9]{64}$/),state:Ug}),NI=l.strictObject({version:l.literal(1),type:l.literal("state"),state:Ug}),Cg=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url(),width:l.number().int().positive(),height:l.number().int().positive(),format:l.enum(["png","jpeg"]),captureMs:l.number().nonnegative(),processingMs:l.number().nonnegative().optional(),totalMs:l.number().nonnegative().optional(),segments:l.number().int().positive().max(64).optional(),scrollRestored:l.boolean().optional(),stabilityWaitMs:l.number().nonnegative().optional(),extensionTotalMs:l.number().nonnegative().optional(),renderAppearsStable:l.boolean().optional(),stable:l.boolean().optional(),lastMutationAgoMs:l.number().finite().nonnegative().optional(),fontsReady:l.boolean().optional(),pendingImages:l.number().int().nonnegative().optional(),timeoutReached:l.boolean().optional(),dataUrl:l.string().max(16*1024*1024)}),UI=l.strictObject({tabId:l.number().int().nonnegative(),url:l.url()}),EI=l.strictObject({tabId:l.number().int().nonnegative(),errors:l.array(hd).max(200)}),k=class extends Error{constructor(i,o,t){super(o);this.code=i;this.stability=t}};function Je(e,r=[]){let i=new URL(e);if(!["http:","https:"].includes(i.protocol)||i.username||i.password||!["localhost","127.0.0.1","[::1]"].includes(i.hostname)&&!r.includes(i.origin))throw new k("GS_URL_NOT_ALLOWED","Use a localhost URL or explicitly authorize this origin in both server and extension settings.")}function bd(e){let r=typeof e=="object"&&e!==null&&"message"in e?e.message:e;return String(r).slice(0,512)}function Zg(e,r){return e instanceof k?e:new k(r==="capture"?"GS_CAPTURE_FAILED":"GS_OPERATION_FAILED",`Firefox ${r}: ${bd(e)}`)}var Co=class{constructor(r,i,o,t,n,a){this.port=r;this.token=i;this.state=o;this.handler=t;this.status=n;this.keepaliveMs=a}socket;timer;keepalive;delay=250;stopped=!1;paired=!1;start(){this.stopped=!1,this.connect()}stop(){this.stopped=!0,clearTimeout(this.timer),clearInterval(this.keepalive),this.socket?.close(),this.status(!1)}async publish(){this.paired&&this.socket?.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify({version:1,type:"state",state:await this.state()}))}async connect(){if(this.stopped)return;let r=new WebSocket(`ws://127.0.0.1:${this.port}`);this.socket=r,this.paired=!1;let i=setTimeout(()=>r.close(),4e3);r.onopen=()=>{this.state().then(t=>{r.readyState===WebSocket.OPEN&&r.send(JSON.stringify({version:1,type:"hello",token:this.token,state:t}))})};let o=Promise.resolve();r.onmessage=t=>{o=o.then(async()=>{try{if(typeof t.data!="string"||t.data.length>32768)throw new Error("Invalid message");let n=JSON.parse(t.data);if(!this.paired){if(JSON.stringify(n)!==JSON.stringify({version:1,type:"paired"}))throw new Error("Pairing failed");this.paired=!0,clearTimeout(i),this.delay=250,this.status(!0),this.keepaliveMs&&(this.keepalive=setInterval(()=>{this.publish().catch(()=>{})},this.keepaliveMs));return}let a=Eg.parse(n),u;try{u={id:a.id,version:1,ok:!0,result:await this.handler(a)}}catch(c){let s=Zg(c,a.type);u={id:a.id,version:1,ok:!1,error:{code:s.code,message:s.message,...s.stability?{stability:s.stability}:{}}}}r.readyState===WebSocket.OPEN&&r.send(JSON.stringify(u))}catch{r.close(1008,"Invalid message")}})},r.onerror=()=>r.close(),r.onclose=()=>{clearTimeout(i),clearInterval(this.keepalive),this.paired=!1,this.stopped||this.status(!1),this.stopped||(this.timer=setTimeout(()=>void this.connect(),this.delay),this.delay=Math.min(this.delay*2,5e3))}}};var Zo=class{selectedTab=null;selectedOrigin=null;state="none";generation=0;choose(r,i){this.selectedTab=r,this.selectedOrigin=i?new URL(i).origin:null,this.state="authorized",this.generation++}reauthorize(r){r===this.selectedTab&&(this.state="reauthorization_required",this.generation++)}refresh(r){r===this.selectedTab&&this.generation++}resume(r){r===this.selectedTab&&this.state==="reauthorization_required"&&(this.state="authorized")}assertAuthorized(r){if(r!==this.selectedTab)throw new k("GS_TARGET_MISMATCH","The requested tab is not the target explicitly selected in GazeSight.");if(this.state!=="authorized")throw new k("GS_REAUTHORIZE_TARGET","Click the GazeSight extension icon or use the configured selection shortcut (default Ctrl+Shift+Y) in the target tab to grant Firefox permission for this document.")}assertAuthorizedUrl(r,i){if(this.assertAuthorized(r),this.selectedOrigin!==null&&new URL(i).origin!==this.selectedOrigin)throw new k("GS_REAUTHORIZE_TARGET","The target moved to a different origin. Select it again before GazeSight accesses it.")}isSelectedOrigin(r){try{return this.selectedOrigin!==null&&new URL(r).origin===this.selectedOrigin}catch{return!1}}remove(r){this.selectedTab===r&&(this.selectedTab=null,this.selectedOrigin=null,this.state="none",this.generation++)}resolve(r){let i=r??this.selectedTab;if(i===null)throw new k("GS_NO_TARGET_TAB","Open your preview page in Firefox and click the GazeSight icon.");return i}};async function $d(e){try{return await e()}catch(r){throw p_(r)}}function p_(e){let r=bd(e),i=/activeTab|<all_urls>|permission/i.test(r);return new k(i?"GS_PERMISSION_DENIED":"GS_CAPTURE_FAILED",`Firefox captureVisibleTab: ${r}${i?" Click the GazeSight icon or use the configured selection shortcut (default Ctrl+Shift+Y) in the selected tab to grant activeTab again.":""}`)}var $n=class{constructor(r,i,o){this.nativeCapture=r;this.contentOperation=i;this.services=o}capture(r){return this.nativeCapture(r)}executeContentOperation(r){return this.contentOperation(r)}getTarget(r){return browser.tabs.get(r)}async reload(r,i){await browser.tabs.reload(r,{bypassCache:i})}async navigate(r,i){await browser.tabs.update(r,{url:i})}getViewport(r){return this.services.getViewport(r)}resizePreview(...r){return this.services.resizePreview(...r)}getDiagnostics(r){return this.services.getDiagnostics(r)}};var Rg=l.discriminatedUnion("op",[l.strictObject({op:l.literal("metrics")}),l.strictObject({op:l.literal("begin")}),l.strictObject({op:l.literal("restore"),lease:l.uuid()}),l.strictObject({op:l.literal("scroll"),lease:l.uuid(),x:l.number().finite().nonnegative(),y:l.number().finite().nonnegative()}),l.strictObject({op:l.literal("element"),lease:l.uuid(),selector:l.string().min(1).max(2048),padding:l.number().min(0).max(1e3)})]);async function yd(e,r,i,o,t,n,a=()=>performance.now()){e.assertAuthorized(r);let u=a()+5e3;e.reauthorize(r);let c=e.generation,s=()=>{if(a()>=u)throw new k("GS_TIMEOUT","Navigation preparation exceeded its bounded deadline; no navigation was issued.");if(e.selectedTab!==r||e.generation!==c||e.state!=="reauthorization_required")throw new k("GS_TARGET_CHANGED","The target changed before navigation; no navigation was issued.")};await o(),s();let d=await t();if(s(),d!==i)throw new k("GS_TARGET_CHANGED","The document changed before navigation; no navigation was issued.");await n()}function _d(e,r,i){if(![e.x,e.y,e.width,e.height,r.width,r.height,i.width,i.height].every(Number.isFinite)||r.width<=0||r.height<=0||e.width<=0||e.height<=0||e.x<0||e.y<0||e.x+e.width>r.width+.5||e.y+e.height>r.height+.5)throw new k("GS_REGION_OUT_OF_VIEWPORT","The complete region must fit inside the current CSS viewport.");let o=i.width/r.width,t=i.height/r.height,n=Math.floor(e.x*o),a=Math.floor(e.y*t);return{x:n,y:a,width:Math.min(i.width,Math.ceil((e.x+e.width)*o))-n,height:Math.min(i.height,Math.ceil((e.y+e.height)*t))-a}}function Lg(e,r,i,o,t,n=0){if(![e,r,i,o].every(u=>Number.isFinite(u)&&u>0)||e>32768||r>32768)throw new k("GS_CAPTURE_LIMIT","Page dimensions exceed the capture limits.");if(i=e>i?Math.max(1,i-n*2):i,o=r>o?Math.max(1,o-n*2):o,Math.ceil(e/i)*Math.ceil(r/o)>t)throw new k("GS_CAPTURE_LIMIT","Page requires too many capture segments.");let a=[];for(let u=0;u<r;u+=o)for(let c=0;c<e;c+=i)a.push({x:c,y:u,width:Math.min(i,e-c),height:Math.min(o,r-u)});return a}var dr=l.object({width:l.number().finite().positive(),height:l.number().finite().positive(),pageWidth:l.number().finite().positive(),pageHeight:l.number().finite().positive(),x:l.number().finite(),y:l.number().finite(),devicePixelRatio:l.number().finite().positive()}),Vg=dr.extend({lease:l.uuid()}),Mg=dr.extend({rect:l.object({x:l.number(),y:l.number(),width:l.number().positive(),height:l.number().positive()})});async function Fg(e,r,i){let o=performance.now(),t=r.payload,n=o+(r.type==="capture_full_page"?r.payload.timeoutMs:7e3);async function a(O){let U=n-performance.now();if(U<=0)throw new k("GS_TIMEOUT","Capture suite deadline reached.");let T;try{return await Promise.race([O(),new Promise((F,ae)=>{T=setTimeout(()=>ae(new k("GS_TIMEOUT","Capture suite deadline reached.")),U)})])}finally{clearTimeout(T)}}let u=O=>a(()=>e.executeContentOperation(O)),c=Ce.parse({tabId:t.tabId,url:t.url,format:t.format,quality:t.quality,waitForStable:t.waitForStable,stableWindowMs:t.stableWindowMs,maxWaitMs:t.maxWaitMs,includeOverlay:t.includeOverlay}),s=0,d=0,m=0,p=0,f,h=!0,w,x,P;async function S(){let O=Cg.parse(await a(()=>e.capture(c)));if(s+=O.captureMs,p+=O.stabilityWaitMs??0,m++,w??=O,!new RegExp(`^data:image/${O.format};base64,[A-Za-z0-9+/]+={0,2}$`).test(O.dataUrl))throw new k("GS_CAPTURE_FAILED","Native capture returned an invalid image data URL.");let U=performance.now(),T=await a(async()=>{let F=await createImageBitmap(await(await fetch(O.dataUrl)).blob());if(performance.now()>n)throw F.close(),new k("GS_TIMEOUT","Image decoding exceeded the capture deadline.");return F});return d+=performance.now()-U,T}function j(O,U,T=16e6){if(!Number.isFinite(O*U)||O<1||U<1||O>32768||U>32768||O*U>T)throw new k("GS_CAPTURE_LIMIT","Output image exceeds the pixel/memory limit.");return x=i.createSurface(O,U),x}try{if(r.type==="capture_full_page"){let T=Vg.parse(await u({op:"begin"}));f=T.lease;let F=Lg(T.pageWidth,T.pageHeight,T.width,T.height,r.payload.maxSegments,1),ae,_e=0,ge=0;for(let J of F){let ue=dr.parse(await u({op:"scroll",lease:f,x:Math.max(0,J.x-1),y:Math.max(0,J.y-1)}));if(ue.pageWidth!==T.pageWidth||ue.pageHeight!==T.pageHeight||ue.width!==T.width||ue.height!==T.height)throw new k("GS_PAGE_CHANGED","Page dimensions changed during capture; infinite or dynamic pages are not stitched.");let Re=await S();try{let cv=performance.now();if(ae||(_e=Re.width/ue.width,ge=Re.height/ue.height,ae=j(Math.ceil(T.pageWidth*_e),Math.ceil(T.pageHeight*ge),r.payload.maxPixels)),Math.abs(Re.width/ue.width-_e)>.001||Math.abs(Re.height/ue.height-ge)>.001)throw new k("GS_TARGET_CHANGED","Capture scale changed during stitching.");let Tn=_d({x:J.x-ue.x,y:J.y-ue.y,width:J.width,height:J.height},ue,Re),Od=Math.floor(J.x*_e),Dd=Math.floor(J.y*ge),sv=Math.ceil((J.x+J.width)*_e)-Od,lv=Math.ceil((J.y+J.height)*ge)-Dd;ae.drawImage(Re,Tn.x,Tn.y,Tn.width,Tn.height,Od,Dd,sv,lv),d+=performance.now()-cv}finally{Re.close()}let Pn=dr.parse(await u({op:"metrics"}));if(Pn.pageWidth!==T.pageWidth||Pn.pageHeight!==T.pageHeight||Math.abs(Pn.x-ue.x)>.5||Math.abs(Pn.y-ue.y)>.5)throw new k("GS_PAGE_CHANGED","Page size or scroll changed during native capture.")}}else{let T,F;if(r.type==="capture_element"){f=Vg.parse(await u({op:"begin"})).lease;let J=Mg.parse(await u({op:"element",lease:f,selector:r.payload.selector,padding:r.payload.padding}));T=J,F=J.rect}else T=dr.parse(await u({op:"metrics"})),F=r.payload;let ae=await S();try{let ge=performance.now(),J=_d(F,T,ae);j(J.width,J.height).drawImage(ae,J.x,J.y,J.width,J.height,0,0,J.width,J.height),d+=performance.now()-ge}finally{ae.close()}let _e=dr.parse(await u({op:"metrics"}));if(T.width!==_e.width||T.height!==_e.height||T.x!==_e.x||T.y!==_e.y)throw new k("GS_TARGET_CHANGED","Viewport or scroll changed during capture.");if(r.type==="capture_element"){let ge=Mg.parse(await u({op:"element",lease:f,selector:r.payload.selector,padding:r.payload.padding}));if(JSON.stringify(ge.rect)!==JSON.stringify(F))throw new k("GS_PAGE_CHANGED","Element geometry changed during capture.")}}if(!x||!w)throw new k("GS_CAPTURE_FAILED","No capture segments produced.");let O=performance.now(),U=await x.encode(t.format,t.quality);if(d+=performance.now()-O,U.length>16*1024*1024)throw new k("GS_CAPTURE_LIMIT","Encoded image exceeds the bridge payload limit.");if(performance.now()>n)throw new k("GS_TIMEOUT","Local image processing exceeded the capture deadline.");return P={...w,width:x.width,height:x.height,dataUrl:U,segments:m,captureMs:s,processingMs:d,stabilityWaitMs:p,extensionTotalMs:performance.now()-o,totalMs:performance.now()-o,scrollRestored:h},P}finally{if(f){let O;try{if(h=l.object({scrollRestored:l.boolean()}).parse(await Promise.race([e.executeContentOperation({op:"restore",lease:f}),new Promise((T,F)=>{O=setTimeout(()=>F(new k("GS_SCROLL_RESTORE_FAILED","Scroll restoration timed out; content watchdog remains active.")),500)})])).scrollRestored,!h)throw new k("GS_SCROLL_RESTORE_FAILED","The original scroll position could not be restored.")}finally{clearTimeout(O)}}x&&x.dispose(),P&&Object.assign(P,{scrollRestored:h,totalMs:performance.now()-o,extensionTotalMs:performance.now()-o})}}var Ro=class{createSurface(r,i){let o=document.createElement("canvas");o.width=r,o.height=i;let t=o.getContext("2d");if(!t)throw new k("GS_CAPTURE_FAILED","Unable to allocate local image processing surface.");return{width:r,height:i,drawImage:(n,a,u,c,s,d,m,p,f)=>t.drawImage(n,a,u,c,s,d,m,p,f),encode:async(n,a)=>o.toDataURL(`image/${n}`,a/100),dispose:()=>{o.width=0,o.height=0}}}};var g_={"mobile-small":{width:320,height:568},mobile:{width:390,height:844},tablet:{width:768,height:1024},desktop:{width:1440,height:900},"desktop-wide":{width:1920,height:1080}},hS=l.strictObject({op:l.literal("measure")}),v_=l.strictObject({width:l.number().int().positive(),height:l.number().int().positive(),devicePixelRatio:l.number().finite().positive()});function h_(e){let r=e.profile?g_[e.profile]:void 0,i=e.width??r?.width,o=e.height??r?.height;if(!i||!o)throw new k("GS_INVALID_VIEWPORT","Provide a profile or both width and height in CSS pixels.");return{width:i,height:o,...e.profile?{profile:e.profile}:{}}}function b_(e,r,i,o){if(!i.width||!i.height||!Number.isFinite(o)||o<=0)throw new k("GS_VIEWPORT_FAILED","Window dimensions or zoom are unavailable.");return{width:Math.max(200,Math.min(8192,Math.round(i.width+(e.width-r.width)*o))),height:Math.max(200,Math.min(8192,Math.round(i.height+(e.height-r.height)*o)))}}function $_(e,r){return["width","height","left","top","state"].every(i=>e[i]===r[i])}function Gg(e,r){if(e.tabs?.length!==1||e.tabs[0].id!==r)throw new k("GS_PREVIEW_IN_USE","The preview now contains other tabs; GazeSight will not resize it.")}function y_(e){if(e.cookieStoreId&&e.cookieStoreId!=="firefox-default"&&e.cookieStoreId!=="firefox-private")throw new k("GS_PREVIEW_CONTEXT_UNSUPPORTED","A dedicated preview cannot preserve this Firefox container without additional permissions. Use the selected window explicitly instead.");return{incognito:!!(e.incognito||e.cookieStoreId==="firefox-private")}}var Lo=class{preview;async get(r){let i=wd(r),o=await browser.tabs.sendMessage(r.id,{type:"gazesight-viewport-content",operation:{op:"measure"}},{frameId:0});if(!o?.ok)throw new k("GS_VIEWPORT_FAILED","Viewport measurement unavailable; select the target again.");let t=v_.parse(o.value),n=await browser.windows.get(i),a=await browser.tabs.getZoom(r.id);return{tabId:r.id,url:r.url,windowId:i,...t,zoom:a,outerWidth:n.width,outerHeight:n.height,dedicatedPreview:!!(this.preview&&this.preview.tabId===r.id),...this.preview&&this.preview.tabId===r.id?{sourceTabId:this.preview.sourceTabId}:{}}}async close(r,i){await i();let o=!!this.preview;if(this.preview){let n=this.preview.windowId;this.preview=void 0,await browser.windows.remove(n).catch(()=>{})}return{...await this.get(r),previewClosed:o}}async set(r,i,o){if(i.close)return this.close(r,o);let t=h_(i),n=wd(r),a=i.dedicatedPreview&&this.preview&&this.preview.tabId===r.id?this.preview.sourceWindowId:n,u=await browser.windows.get(a).catch(()=>{}),c=r,s=!1,d=!1;if(i.dedicatedPreview){if(this.preview){let x=await browser.windows.get(this.preview.windowId,{populate:!0}).catch(()=>{});if(!x)this.preview=void 0;else{if(Gg(x,this.preview.tabId),r.id!==this.preview.tabId&&(r.id!==this.preview.sourceTabId||r.cookieStoreId!==this.preview.cookieStoreId))throw new k("GS_PREVIEW_IN_USE","An existing preview belongs to another source. Close that preview before creating a different one.");if(c=await browser.tabs.get(this.preview.tabId),r.id===this.preview.sourceTabId&&r.url!==this.preview.url&&(await o(),await browser.tabs.update(this.preview.tabId,{url:r.url}),this.preview.url=r.url,d=!0),t.width<500&&r.id===this.preview.tabId&&x.type!=="popup"){await o();let P={...this.preview},S=await browser.windows.create({tabId:P.tabId,type:"popup",focused:!0,width:Math.min(8192,t.width+32),height:Math.min(8192,t.height+120),titlePreface:"GazeSight Preview | "});if(S.id===void 0)throw new k("GS_VIEWPORT_FAILED","Firefox did not return the compact preview window.");this.preview={...P,windowId:S.id},c=await browser.tabs.get(P.tabId),s=!0}}}if(!this.preview){let x=y_(r);await o();let P=await browser.windows.create({url:r.url,type:t.width<500?"popup":"normal",focused:!0,width:Math.min(8192,t.width+32),height:Math.min(8192,t.height+120),...x,titlePreface:"GazeSight Preview | "}),S=P.tabs?.[0];if(P.id===void 0||S?.id===void 0)throw new k("GS_VIEWPORT_FAILED","Firefox did not return a preview tab.");this.preview={windowId:P.id,tabId:S.id,sourceTabId:r.id,sourceWindowId:n,cookieStoreId:r.cookieStoreId,url:r.url},c=S,d=!0}}let m,p,f;for(let x=0;x<20;x++){await o();let P=await browser.tabs.get(c.id);if(P.status==="complete"&&P.url!==r.url)throw new k("GS_TARGET_CHANGED","The preview navigated away from its source URL.");if(c=P,c.status==="complete"){if(d){try{await browser.tabs.executeScript?.(c.id,{file:"content.js",runAt:"document_start"})}catch(S){p=S}d=!1}try{m=await this.get(c);break}catch(S){f=S}}await new Promise(S=>setTimeout(S,100))}if(!m){let x=p??f;throw new k("GS_VIEWPORT_FAILED","Preview created but its measured viewport is unavailable."+(x?` ${p?"Injection":"Measurement"} error: ${String(x?.message??x)}`:""))}let h=0;for(;h<3&&(m.width!==t.width||m.height!==t.height);h++){await o();let x=wd(c),P=await browser.windows.get(x,{populate:!0});i.dedicatedPreview&&Gg(P,c.id);let S=b_(t,m,P,m.zoom);await browser.windows.update(x,{state:"normal"}),await o(),await browser.windows.update(x,S),await new Promise(O=>setTimeout(O,150)),await o();let j=await browser.tabs.get(c.id);if(j.url!==r.url)throw new k("GS_TARGET_CHANGED","The preview navigated during resize.");m=await this.get(j)}let w=await browser.windows.get(a).catch(()=>{});return{...m,movedToCompact:s,requested:t,exact:m.width===t.width&&m.height===t.height,attempts:h,...u&&w?{sourceWindowUnchanged:$_(u,w)}:{}}}removeWindow(r){this.preview?.windowId===r&&(this.preview=void 0)}previewSourceTabId(r){return this.preview&&this.preview.tabId===r?this.preview.sourceTabId:void 0}currentPreviewTabId(){return this.preview?.tabId}clear(){this.preview=void 0}};function wd(e){if(e.id===void 0||e.windowId===void 0||!e.url)throw new k("GS_VIEWPORT_FAILED","Firefox tab identity or window is unavailable.");return e.windowId}var __="gazesight-select-target";async function Bg(e,r){if(e!==__)return;let i=r??(await browser.tabs.query({active:!0,lastFocusedWindow:!0}))[0];if(!(i?.id===void 0||i.active!==!0))return i}function Ze(e,r){return e.slice(0,4096).replace(/https?:\/\/[^\s"'<>]+/gi,i=>{try{let o=new URL(i);return o.origin+o.pathname}catch{return"[redacted URL]"}}).replace(/(?:bearer\s+)[\w.+/=-]+/gi,"[redacted]").replace(/\beyJ[\w-]+\.[\w-]+(?:\.[\w-]+)?/g,"[redacted]").replace(/\b[a-zA-Z0-9_+/-]{24,}={0,2}\b/g,"[redacted]").replace(/((?:password|passwd|token|secret|credential|api[-_]?key|authorization)["']?\s*[:=]\s*["']?)[^\s,;"']+/gi,"$1[redacted]").replace(/\s+/g," ").trim().slice(0,r)}function yn(e,r){try{let i=new URL(e,r);return["http:","https:"].includes(i.protocol)?(i.origin+i.pathname.split("/").map(o=>Ze(o,200)).join("/")).slice(0,1024):void 0}catch{return}}var kS=l.strictObject({op:l.enum(["status","stop"])}),IS=l.discriminatedUnion("type",[l.strictObject({namespace:l.literal("gazesight-console"),type:l.literal("entry"),entry:hn}),l.strictObject({namespace:l.literal("gazesight-console"),type:l.enum(["ready","stopped"])})]),_n=class{entries=[];dropped=0;get count(){return this.entries.length}push(r){this.entries.length===100&&(this.entries.shift(),this.dropped++),this.entries.push(r)}clear(){this.entries=[],this.dropped=0}read(r,i){let o=Math.max(1,Math.min(100,Math.floor(r))),t={entries:this.entries.slice(-o),dropped:this.dropped+Math.max(0,this.entries.length-o)};return i&&this.clear(),t}};function Jg(e){if(!e.error&&!(e.statusCode!==void 0&&e.statusCode>=400&&e.statusCode<=599))return;let r=yn(e.url,e.url);if(r)return gd.parse({url:r,method:Ze(e.method,16),resourceType:Ze(e.type,32),timestamp:e.timeStamp,...e.statusCode!==void 0?{status:e.statusCode}:{},...e.error?{error:/^NS_ERROR_[A-Z_]{1,96}$/.test(e.error)?e.error:Ze(e.error,128)}:{}})}var Wg=l.strictObject({type:l.literal("gazesight-ui"),action:l.enum(["status","select","disconnect","fast","stable","diagnostics","background-enable","background-denied","background-disable","continuous-enable","continuous-denied","continuous-disable"])});function Kg(e,r,i,o){return e?r==="none"?"WAIT":r==="reauthorization_required"?"AUTH":i?"WAIT":o?"ERR":"ON":"OFF"}function xd(e,r,i,o=!1){if(e.id!==r||!o&&e.tab||!e.url)return!1;try{let t=new URL(e.url),n=new URL(i);return t.origin===n.origin&&t.pathname===n.pathname}catch{return!1}}var Xg="0.5.3";async function Hg(e){if(e.tabId!==e.targetTabId)throw new k("GS_TARGET_MISMATCH","The requested tab is not the target explicitly selected in GazeSight.");let r=e.backgroundMode==="enabled"&&e.permissionGranted,i=await e.currentTarget();if(i.id!==e.tabId||i.url!==e.url||e.currentGeneration()!==e.generation)throw new k("GS_TARGET_CHANGED","The target changed before capture.");if(!r&&!i.active)throw new k("GS_CAPTURE_FAILED","Bring the authorized target tab to the front.");let o=await(r?e.background():e.foreground()),t=await e.currentTarget();if(t.id!==e.tabId||t.url!==e.url||e.currentGeneration()!==e.generation)throw new k("GS_TARGET_CHANGED","The target changed during capture.");if(!r&&!t.active)throw new k("GS_CAPTURE_FAILED","The active tab changed during capture.");return o}function wn(e){return String(e).padStart(2,"0")}function w_(e=new Date){return`GazeSight/gazesight-${e.getFullYear()}-${wn(e.getMonth()+1)}-${wn(e.getDate())}_${wn(e.getHours())}-${wn(e.getMinutes())}-${wn(e.getSeconds())}.png`}var Vo=class{busy=!1;async run(r){if(this.busy)throw new k("GS_CAPTURE_BUSY","A manual screenshot is already in progress.");this.busy=!0;try{if(!await r.permissionGranted())throw new k("GS_PERMISSION_DENIED","Download permission required.");let i=await r.capture();if(i.format!=="png"||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(i.dataUrl))throw new k("GS_CAPTURE_FAILED","Capture failed to produce a PNG image.");let o=w_(r.now),t;try{if(t=await r.download({url:i.dataUrl,filename:o,saveAs:!1,conflictAction:"uniquify"}),!await r.waitForCompletion(t))throw new Error("interrupted")}catch{throw new k("GS_DOWNLOAD_FAILED","Download failed.")}return{filename:o,downloadId:t}}finally{this.busy=!1}}};function kd(e,r,i,o){if(!i.enabled||!i.hostPermissionGranted)return!1;let t=o(e);return t!==void 0&&t===r.selectedTab&&r.state==="authorized"}function qg(e,r,i,o,t){return kd(e,i,o,t)&&i.isSelectedOrigin(r)}function Yg(e,r){if(r===null)return!1;try{return new URL(e).origin===r}catch{return!1}}var _=new Zo,fr=new Lo,x_=new Ro,ze=new Map,pr=new _n,gr=new _n,X,We=[],je=!1,mr=null,kn=!1,Sd=!1,In=!1,oe="disabled",M=!1,te=!1,k_=new Vo;function ev(e){return kd(e,_,{enabled:te,hostPermissionGranted:M},r=>fr.previewSourceTabId(r))}function I_(e,r){return qg(e,r,_,{enabled:te,hostPermissionGranted:M},i=>fr.previewSourceTabId(i))}function Q(e){ev(e)||_.assertAuthorized(e)}function tv(e,r){I_(e,r)||_.assertAuthorizedUrl(e,r)}function S_(e){return e===_.selectedTab?_.state==="authorized":ev(e)}async function z_(e){let r=Date.now()+15e3;for(;Date.now()<r;){let[i]=await browser.downloads.search({id:e});if(i?.state==="complete")return!0;if(i?.state==="interrupted")return!1;await new Promise(o=>setTimeout(o,100))}return!1}var rv,nv,iv={getViewport:e=>fr.get(e),resizePreview:(...e)=>fr.set(...e),getDiagnostics:T_},H=new $n(async e=>{let r=_.resolve(e.tabId);Q(r);let i=_.generation,o=await H.getTarget(r);if(tv(r,o.url??""),i!==_.generation)throw new k("GS_TARGET_CHANGED","The target changed before native capture.");Je(o.url??"",We);let t=o.windowId;if(t===void 0)throw new k("GS_CAPTURE_FAILED","The authorized target window is unavailable.");return Hg({tabId:r,targetTabId:r,generation:i,currentGeneration:()=>_.generation,url:o.url??"",currentTarget:()=>H.getTarget(r),backgroundMode:oe,permissionGranted:M,foreground:()=>$d(()=>browser.tabs.captureVisibleTab(t,{format:e.format,quality:e.quality})),background:()=>$d(()=>browser.tabs.captureTab(r,{format:e.format,quality:e.quality}))})},async e=>{let r=_.resolve();Q(r);let i=await browser.tabs.sendMessage(r,{type:"gazesight-capture-content",operation:Rg.parse(e)},{frameId:0});if(!i?.ok)throw new k("GS_CAPTURE_FAILED","Fixed content operation failed.");return i.value},iv);async function P_(){let e=await browser.runtime.getBrowserInfo(),r={extensionVersion:Xg,extensionId:browser.runtime.id,capabilities:["highlight","clear_highlight","capture_region","capture_element","capture_full_page","get_dom","get_element","get_changed_regions","get_viewport","set_viewport",...bn.options,"get_console","get_network_failures","get_page_status"],targetState:_.state,browser:{name:"firefox",version:e.version},backgroundCapture:{enabled:oe==="enabled",permissionGranted:M}};if(_.selectedTab===null)return{selectedTab:null,url:null,...r};try{let i=await H.getTarget(_.selectedTab);return{selectedTab:_.selectedTab,url:i.url??null,...r}}catch{return _.remove(_.selectedTab),{selectedTab:null,url:null,...r,targetState:_.state}}}var Id=Promise.resolve(),xn;function pe(){let e={text:Kg(je,_.state,Sd,In),color:je&&_.state==="authorized"?"#15734b":"#8c5321",title:_.state==="reauthorization_required"?"GazeSight: click in the target tab to reauthorize this document":"GazeSight: use this tab"};return Id=Id.catch(()=>{}).then(async()=>{try{let r=await Promise.allSettled([xn?.text!==e.text?Promise.resolve().then(()=>browser.browserAction.setBadgeText({text:e.text})):void 0,xn?.color!==e.color?Promise.resolve().then(()=>browser.browserAction.setBadgeBackgroundColor({color:e.color})):void 0,xn?.title!==e.title?Promise.resolve().then(()=>browser.browserAction.setTitle({title:e.title})):void 0]);for(let i of r)if(i.status==="rejected")throw i.reason;xn=e}catch(r){throw xn=void 0,r}}),Id}async function Mo(e){await browser.tabs.executeScript(e,{file:"content.js",runAt:"document_start"}).catch(()=>{}),je&&_.selectedTab===e&&_.state==="authorized"&&(await browser.scripting.executeScript({target:{tabId:e,frameIds:[0]},files:["diagnostics-page.js"],world:"MAIN",injectImmediately:!0}).catch(()=>{}),!je||_.selectedTab!==e||_.state!=="authorized"?await Fo(e):await at(e))}async function T_(e){let r=await browser.tabs.sendMessage(e,{type:"gazesight-diagnostics-content",operation:{op:"status"}},{frameId:0});if(!r?.ok)throw new k("GS_DIAGNOSTICS_UNAVAILABLE","Select the target again to initialize diagnostics.");return vd.parse(r.value)}async function Fo(e){await Sn(e,{op:"clear"}).catch(()=>{}),await vr(e,{op:"set",state:"none"}),mr===e&&(mr=null),await browser.tabs.sendMessage(e,{type:"gazesight-diagnostics-content",operation:{op:"stop"}},{frameId:0}).catch(()=>{})}async function Sn(e,r){let i=await browser.tabs.sendMessage(e,{type:"gazesight-overlay-content",operation:r},{frameId:0});if(!i?.ok)throw new k(i?.code??"GS_HIGHLIGHT_UNAVAILABLE","The overlay operation was refused or unavailable.");return i.value===!0}function O_(e){return e?oe==="enabled"&&M?"background":"authorized":"none"}async function vr(e,r){await browser.tabs.sendMessage(e,{type:"gazesight-target-indicator-content",operation:r}).catch(()=>{})}async function at(e){await vr(e,{op:"set",state:O_(_.state==="authorized"&&_.selectedTab===e)})}function zn(){pr.clear(),gr.clear()}function ov(e){if(!(!je||_.state!=="authorized"||e.tabId!==_.selectedTab||!_.isSelectedOrigin(e.url)))try{Je(e.url,We);let r=Jg(e);r&&gr.push(r)}catch{}}browser.webRequest.onCompleted.addListener(ov,{urls:["http://*/*","https://*/*"]});browser.webRequest.onErrorOccurred.addListener(ov,{urls:["http://*/*","https://*/*"]});async function D_(e){let r=e.payload.tabId;if(r===void 0&&e.type.startsWith("capture")&&"url"in e.payload&&e.payload.url){let o=e.payload.url,t=(await browser.tabs.query({})).filter(n=>n.url===o);if(t.length!==1)throw new k("GS_TAB_NOT_FOUND","Provide a tabId or a URL matching exactly one open Firefox tab.");r=t[0].id}r=_.resolve(r),Q(r);let i;try{i=await H.getTarget(r)}catch{throw new k("GS_TAB_NOT_FOUND","The Firefox tab was closed. Select a new target.")}return Je(i.url??"",We),tv(r,i.url??""),i}async function av(e){let r=await D_(e),i=r.id;if(e.type==="highlight"||e.type==="clear_highlight"){if(Q(i),kn)throw new k("GS_CAPTURE_BUSY","Wait for the current capture before changing its overlay.");let o=_.generation,t=await Sn(i,e.type==="highlight"?{op:"show",options:e.payload}:{op:"clear"}),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw await Sn(i,{op:"clear"}).catch(()=>{}),new k("GS_TARGET_CHANGED","The target changed while highlighting.");return Q(i),mr=t?i:null,{tabId:i,url:n.url,highlighted:t}}if(e.type==="get_console"||e.type==="get_network_failures"||e.type==="get_page_status"){Q(i);let o=_.generation,t=e.type==="get_network_failures"?void 0:await H.getDiagnostics(i),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The target document changed during diagnostics.");return Q(i),e.type==="get_console"?{tabId:i,...pr.read(e.payload.maxEntries,e.payload.reset),forwardingDropped:t.consoleForwardingDropped}:e.type==="get_network_failures"?{tabId:i,...gr.read(e.payload.maxEntries,e.payload.reset)}:{...t,tabId:i,targetState:_.state,runtimeErrorCount:ze.get(i)?.length??0,consoleEntryCount:pr.count,networkFailureCount:gr.count}}if(bn.safeParse(e.type).success){Q(i);let o=_.generation,t=await browser.tabs.sendMessage(i,{type:"gazesight-interaction-content",operation:{type:e.type,options:e.payload}},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","Interaction content unavailable; select the target again.")}),n=await H.getTarget(i);if(o!==_.generation||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The document changed during interaction; the action may already have occurred. Inspect before retrying.");if(Q(i),!t?.ok)throw new k(typeof t?.code=="string"&&t.code.startsWith("GS_")?t.code:"GS_INTERACTION_FAILED","The DOM interaction was refused or failed.");return{tabId:i,url:n.url,action:e.type,inputSource:"dom",completed:!0,...t.value}}if(e.type==="get_viewport"||e.type==="set_viewport"){Q(i);let o=_.generation,t=async()=>{Q(i);let c=await H.getTarget(i);if(_.generation!==o||c.url!==r.url)throw new k("GS_TARGET_CHANGED","The selected source changed during viewport operation.")},n=e.type==="get_viewport"?await H.getViewport(r):await H.resizePreview(r,e.payload,t);await t(),Je(n.url,We);let{movedToCompact:a,...u}={movedToCompact:!1,...n};return a&&(te&&M?_.refresh(n.tabId):_.reauthorize(n.tabId),await pe(),await X?.publish()),{...u,requiresTargetSelection:!S_(n.tabId)}}if(e.type==="get_dom"||e.type==="get_element"||e.type==="get_changed_regions"){Q(i);let o=_.generation,t=await browser.tabs.sendMessage(i,{type:"gazesight-dom-content",operation:{type:e.type,options:{...e.payload,tabId:i}}},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","DOM content script unavailable; reauthorize the target.")});Q(i);let n=await H.getTarget(i);if(_.generation!==o||n.url!==r.url)throw new k("GS_TARGET_CHANGED","The target changed during inspection.");if(!t?.ok)throw new k(typeof t?.code=="string"&&t.code.startsWith("GS_")?t.code:"GS_DOM_FAILED","The fixed DOM inspection operation failed.");return t.value}if(e.type==="capture_region"||e.type==="capture_element"||e.type==="capture_full_page"){Q(i);let o=_.generation;async function t(){Q(i);let a=await H.getTarget(i);if(o!==_.generation||a.url!==r.url||(oe!=="enabled"||!M)&&!a.active)throw new k("GS_TARGET_CHANGED","The authorized active target changed during capture.")}let n=new $n(async a=>(await t(),av({id:e.id,version:1,type:"capture",payload:Ce.parse({...a,tabId:i})})),async a=>{await t();let u=await browser.tabs.sendMessage(i,{type:"gazesight-capture-content",operation:a},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","Capture content script unavailable; reauthorize the target.")});if(await t(),!u?.ok)throw new k(typeof u?.code=="string"&&u.code.startsWith("GS_")?u.code:"GS_CAPTURE_FAILED","The fixed content capture operation failed.");return u.value},iv);return Fg(n,e,x_)}if(e.type==="capture"){Q(i);let o=performance.now(),t=_.generation;if((oe!=="enabled"||!M)&&!r.active)throw new k("GS_CAPTURE_FAILED","Bring the selected GazeSight tab to the front in its Firefox window before capturing.");let n=0,a;if(e.payload.waitForStable){let h=await browser.tabs.sendMessage(i,{type:"gazesight-wait-stable",options:e.payload},{frameId:0}).catch(()=>{throw new k("GS_TARGET_CHANGED","The target document closed or navigated, or its content script is unavailable. Click the GazeSight icon in the target tab.")});if(!h?.ok)throw new k(h?.code==="GS_TARGET_CHANGED"?"GS_TARGET_CHANGED":"GS_RENDER_NOT_STABLE","The render did not appear stable before maxWaitMs. Retry after updates settle.",h?.stability?pd.parse(h.stability):void 0);n=h.stabilityWaitMs,a={lastMutationAgoMs:h.lastMutationAgoMs,fontsReady:h.fontsReady,pendingImages:h.pendingImages,timeoutReached:h.timeoutReached}}if(t!==_.generation)throw new k("GS_TARGET_CHANGED","The target document changed during capture preparation.");let u=performance.now(),c=await H.capture(e.payload).then(h=>{if(typeof h!="string")throw new k("GS_CAPTURE_FAILED","Invalid native capture result.");return h}).catch(async h=>{throw h instanceof k&&h.code==="GS_PERMISSION_DENIED"?(_.reauthorize(i),await pe(),await X?.publish(),new k("GS_REAUTHORIZE_TARGET","Firefox requires permission again. Click the GazeSight extension icon in the target tab.")):h}),s=performance.now()-u,d=oe==="enabled"&&M?[await H.getTarget(i)]:await browser.tabs.query({active:!0,windowId:r.windowId});if(t!==_.generation)throw new k("GS_TARGET_CHANGED","The target document changed during native capture. Click the GazeSight icon in the target tab again.");if(d[0]?.id!==i||d[0]?.url!==r.url)throw new k("GS_CAPTURE_FAILED","The active tab changed during capture. Retry with the preview tab active.");let m=await createImageBitmap(await(await fetch(c)).blob()),p=m.width,f=m.height;return m.close(),{tabId:i,url:r.url,width:p,height:f,format:e.payload.format,captureMs:s,stabilityWaitMs:n,extensionTotalMs:performance.now()-o,renderAppearsStable:e.payload.waitForStable,stable:e.payload.waitForStable,...a,dataUrl:c}}if(e.type==="get_errors"){Q(i);let o=ze.get(i)??[];return ze.set(i,[]),{tabId:i,errors:o}}if(e.type==="reload")return await yd(_,i,r.url,async()=>{await pe(),await X?.publish()},async()=>(await H.getTarget(i)).url??"",()=>H.reload(i,e.payload.bypassCache)),await Qg(i),{tabId:i,url:r.url};if(e.type!=="navigate")throw new k("GS_INVALID_MESSAGE","Unsupported operation.");return Je(e.payload.url,We),await yd(_,i,r.url,async()=>{await pe(),await X?.publish()},async()=>(await H.getTarget(i)).url??"",()=>H.navigate(i,e.payload.url)),await Qg(i),{tabId:i,url:e.payload.url}}async function Qg(e){if(!(te&&M))return;let r=Date.now()+5e3;for(;Date.now()<r;){if(_.selectedTab!==e||_.state==="none"||_.state==="authorized")return;let i=await browser.tabs.get(e).catch(()=>{});if(i?.status==="complete"&&_.isSelectedOrigin(i.url??"")){_.resume(e),await at(e),await pe(),await X?.publish();return}await new Promise(o=>setTimeout(o,100))}}async function j_(){let e=await browser.storage.local.get(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),r=typeof e.continuousAuthPrimaryTabId=="number"?e.continuousAuthPrimaryTabId:null,i=typeof e.continuousAuthOrigin=="string"?e.continuousAuthOrigin:null;if(!(r===null||i===null))try{let o=await browser.tabs.get(r);if(!o.url||!Yg(o.url,i))throw new k("GS_TARGET_CHANGED","Stale persisted target.");Je(o.url,We),_.choose(r,o.url),await Mo(r),await pe()}catch{await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"])}}async function uv(){X?.stop();let e=await browser.storage.local.get(["port","token","allowedOrigins","backgroundCaptureEnabled","continuousAuthorizationEnabled"]);if(M=await browser.permissions.contains({origins:["<all_urls>"]}),oe=e.backgroundCaptureEnabled===!0&&M?"enabled":"disabled",e.backgroundCaptureEnabled===!0&&!M&&await browser.storage.local.set({backgroundCaptureEnabled:!1}),te=e.continuousAuthorizationEnabled===!0&&M,e.continuousAuthorizationEnabled===!0&&!M&&await browser.storage.local.set({continuousAuthorizationEnabled:!1}),We=Array.isArray(e.allowedOrigins)?e.allowedOrigins:[],te&&_.selectedTab===null&&await j_(),typeof e.token!="string"||!/^[a-f0-9]{64}$/.test(e.token))return;let r=Number(e.port??32147);!Number.isInteger(r)||r<1024||r>65535||(X=new Co(r,e.token,P_,zd,i=>{je=i,!i&&_.selectedTab!==null&&(Pd(_.selectedTab),Fo(_.selectedTab)),i&&_.state==="authorized"&&_.selectedTab!==null&&Mo(_.selectedTab),pe()}),X.start())}async function zd(e){let r=e.type==="capture"||e.type.startsWith("capture_"),i=!1,o=mr;if(r&&o!==null){if(kn)throw new k("GS_CAPTURE_BUSY","Wait for the current overlay capture to complete.");Q(_.resolve(e.payload.tabId)),kn=!0;try{(!("includeOverlay"in e.payload)||e.payload.includeOverlay!==!0)&&(i=await Sn(o,{op:"suspend"}),i||(mr=null))}catch(a){throw kn=!1,a}}let t=r&&_.state==="authorized"?_.selectedTab:null;t!==null&&await vr(t,{op:"suspend"});let n;r&&(Sd=!0,n=setTimeout(()=>{pe().catch(()=>{})},120));try{let a=await av(e);if(In=!1,r){let u=a;rv={mode:e.payload&&"waitForStable"in e.payload&&e.payload.waitForStable?"STABLE":"FAST",width:u.width,height:u.height,time:new Date().toISOString()}}return a}catch(a){throw In=!0,nv={code:a instanceof k?a.code:"GS_OPERATION_FAILED",message:Ze(a instanceof Error?a.message:"Operation failed",512),time:new Date().toISOString()},a}finally{t!==null&&await vr(t,{op:"resume"}),i&&o!==null&&(await Sn(o,{op:"resume"}).catch(()=>!1)||(mr=null)),r&&o!==null&&(kn=!1),n!==void 0&&clearTimeout(n),r&&(Sd=!1),pe().catch(()=>{})}}async function De(){let e,r;if(_.selectedTab!==null){let i=await browser.tabs.get(_.selectedTab).catch(()=>{});e=i?.url?yn(i.url,i.url):void 0,je&&_.state==="authorized"&&(r=(await H.getDiagnostics(_.selectedTab).catch(()=>{}))?.viewport)}return{connected:je,paired:je,targetState:_.state,url:e,viewport:r,lastCapture:rv,lastError:nv,backgroundMode:oe,backgroundCapture:{enabled:oe==="enabled",permissionGranted:M},continuousAuthorization:{enabled:te,permissionGranted:M,authorizedOrigin:te&&_.state==="authorized"?_.selectedOrigin:null},consoleCount:pr.count,networkCount:gr.count,runtimeErrorCount:_.selectedTab===null?0:ze.get(_.selectedTab)?.length??0}}async function A_(e){if(e==="status")return De();if(e==="background-enable")return oe="requesting",M=await browser.permissions.contains({origins:["<all_urls>"]}),oe=M?"enabled":"permission_denied",await browser.storage.local.set({backgroundCaptureEnabled:M}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="background-denied")return oe="permission_denied",M=!1,await browser.storage.local.set({backgroundCaptureEnabled:!1}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="background-disable")return oe="disabled",await browser.storage.local.set({backgroundCaptureEnabled:!1}),te||await browser.permissions.remove({origins:["<all_urls>"]}),M=await browser.permissions.contains({origins:["<all_urls>"]}),_.state==="authorized"&&_.selectedTab!==null&&await at(_.selectedTab),await X?.publish(),De();if(e==="continuous-enable")return te=!1,M=await browser.permissions.contains({origins:["<all_urls>"]}),te=M,await browser.storage.local.set({continuousAuthorizationEnabled:M}),te&&_.state==="authorized"&&_.selectedTab!==null&&_.selectedOrigin!==null&&await browser.storage.local.set({continuousAuthPrimaryTabId:_.selectedTab,continuousAuthOrigin:_.selectedOrigin}),await X?.publish(),De();if(e==="continuous-denied")return te=!1,await browser.storage.local.set({continuousAuthorizationEnabled:!1}),await X?.publish(),De();if(e==="continuous-disable")return te=!1,await browser.storage.local.set({continuousAuthorizationEnabled:!1}),await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),oe!=="enabled"&&await browser.permissions.remove({origins:["<all_urls>"]}),M=await browser.permissions.contains({origins:["<all_urls>"]}),await X?.publish(),De();if(e==="disconnect"){let i=_.selectedTab;return i!==null&&(await Pd(i),await Fo(i),_.remove(i)),zn(),ze.clear(),In=!1,await browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),fr.clear(),await pe(),await X?.publish(),De()}if(e==="select"){let[i]=await browser.tabs.query({active:!0,lastFocusedWindow:!0});if(!i?.id)throw new k("GS_NO_TARGET_TAB","Activate your preview page before using this tab.");if(Je(i.url??"",We),!await Td(i))throw new k("GS_TARGET_SELECTION_FAILED","Selection failed. Check the allowed origin and settings.");return De()}if(!je)throw new k("GS_NOT_CONNECTED","Start the GazeSight MCP server and check pairing in settings.");let r=_.resolve();return Q(r),e==="diagnostics"?{status:await De(),console:pr.read(10,!1),network:gr.read(10,!1),runtimeErrors:(ze.get(r)??[]).slice(-10)}:e==="fast"?k_.run({permissionGranted:()=>browser.permissions.contains({permissions:["downloads"]}),capture:async()=>await zd({id:crypto.randomUUID(),version:1,type:"capture",payload:Ce.parse({tabId:r,format:"png",waitForStable:!1})}),download:async i=>{let o=await(await fetch(i.url)).blob(),t=URL.createObjectURL(o);try{return await browser.downloads.download({...i,url:t})}finally{setTimeout(()=>URL.revokeObjectURL(t),3e4)}},waitForCompletion:z_}):(await zd({id:crypto.randomUUID(),version:1,type:"capture",payload:Ce.parse({tabId:r,waitForStable:!0})}),De())}async function Pd(e){await browser.tabs.sendMessage(e,{type:"gazesight-dom-content",operation:{type:"stop_tracking"}},{frameId:0}).catch(()=>{})}async function Td(e){try{return Je(e.url??"",We),_.selectedTab!==null&&(await Pd(_.selectedTab),await Fo(_.selectedTab)),zn(),ze.clear(),_.choose(e.id,e.url),In=!1,te&&_.selectedOrigin!==null&&await browser.storage.local.set({continuousAuthPrimaryTabId:e.id,continuousAuthOrigin:_.selectedOrigin}),await Mo(e.id),await pe(),await X?.publish(),!0}catch{return await browser.runtime.openOptionsPage(),!1}}browser.browserAction.onClicked.addListener(Td);browser.commands.onCommand.addListener(async(e,r)=>{try{let i=await Bg(e,r);i&&await Td(i)}catch{await browser.runtime.openOptionsPage()}});browser.tabs.onRemoved.addListener(e=>{e===_.selectedTab&&(zn(),browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"])),_.remove(e),ze.delete(e),pe(),X?.publish()});browser.windows.onRemoved.addListener(e=>fr.removeWindow(e));browser.tabs.onUpdated.addListener((e,r)=>{if(e===_.selectedTab){if(r.url&&!_.isSelectedOrigin(r.url)){zn(),ze.delete(e),_.reauthorize(e),vr(e,{op:"set",state:"none"}),pe(),X?.publish();return}r.status==="loading"&&(zn(),ze.delete(e),(oe==="enabled"||te)&&M?_.refresh(e):(_.reauthorize(e),vr(e,{op:"set",state:"none"})),pe()),r.status==="complete"&&(te&&M&&browser.tabs.get(e).then(i=>{_.selectedTab===e&&_.state==="reauthorization_required"&&_.isSelectedOrigin(i.url??"")&&(_.resume(e),at(e),pe(),X?.publish())}).catch(()=>{}),Mo(e)),X?.publish()}});browser.runtime.onMessage.addListener((e,r)=>{if(r.id===browser.runtime.id){if(e?.type==="gazesight-ui"){if(!xd(r,browser.runtime.id,browser.runtime.getURL("popup.html"))&&!xd(r,browser.runtime.id,browser.runtime.getURL("permission.html"),!0))return;let i=Wg.safeParse(e);return i.success?A_(i.data.action).then(o=>({ok:!0,value:o}),o=>({ok:!1,error:Ze(o instanceof Error?o.message:"GS_OPERATION_FAILED",512)})):Promise.resolve({ok:!1,error:"GS_INVALID_MESSAGE"})}if(!(!je||_.state!=="authorized"||r.tab?.id!==_.selectedTab||!_.isSelectedOrigin(r.tab?.url??"")||r.frameId!==0)){if(e?.type==="console-diagnostic"){let i=hn.safeParse(e.entry);i.success&&pr.push({...i.data,message:Ze(i.data.message,512)});return}if(e?.type==="runtime-error"&&r.tab?.id!==void 0&&r.frameId===0){let i=hd.safeParse(e.error);if(i.success&&r.tab.id===_.selectedTab){let o=ze.get(r.tab.id)??[];o.push({...i.data,message:Ze(i.data.message,4096),source:i.data.source?yn(i.data.source,r.tab.url??i.data.source):void 0}),ze.set(r.tab.id,o.slice(-200))}}}}});browser.storage.onChanged.addListener((e,r)=>{r==="local"&&["port","token","allowedOrigins"].some(i=>i in e)&&uv()});browser.permissions.onRemoved.addListener(e=>{e.origins?.includes("<all_urls>")&&(M=!1,oe="disabled",te=!1,browser.storage.local.set({backgroundCaptureEnabled:!1,continuousAuthorizationEnabled:!1}),browser.storage.local.remove(["continuousAuthPrimaryTabId","continuousAuthOrigin"]),_.state==="authorized"&&_.selectedTab!==null&&at(_.selectedTab),X?.publish())});browser.permissions.onAdded.addListener(e=>{e.origins?.includes("<all_urls>")&&(M=!0,_.state==="authorized"&&_.selectedTab!==null&&at(_.selectedTab),X?.publish())});uv();})();
|