@mwillbanks/ast-mcp 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast-mcp.js +292 -292
- package/dist/ast-mcp.js.map +14 -13
- package/dist/workers/code-intelligence-worker.js +2 -2
- package/dist/workers/code-intelligence-worker.js.map +4 -4
- package/package.json +1 -1
- package/src/helpers/mcp-schema.ts +91 -8
- package/src/intelligence/mutation/journal.ts +101 -20
- package/src/intelligence/mutation/locks.ts +92 -28
- package/src/patch/engine.ts +166 -87
- package/src/runtime/attributes.ts +158 -1
- package/src/runtime/file-delete.ts +111 -65
- package/src/runtime/file-rename.ts +126 -20
- package/src/runtime/parent-directories.ts +114 -0
- package/src/tools/code-intelligence-compute.ts +14 -6
- package/src/tools/code-intelligence-worker.ts +11 -2
- package/src/tools/code-intelligence.ts +126 -40
- package/src/tools/files.ts +2 -2
- package/src/tools/lifecycle.ts +30 -29
- package/templates/AGENTS.md +1 -0
- package/templates/skills/ast-mcp/SKILL.md +2 -0
- package/templates/skills/ast-mcp/references/agents-guidance.md +1 -0
- package/templates/skills/ast-mcp/references/patch-state-machine.md +8 -2
- package/templates/skills/ast-mcp/references/tool-catalog.md +4 -1
|
@@ -56,6 +56,6 @@ ${t.join(`
|
|
|
56
56
|
}
|
|
57
57
|
`)}return b.write("payload.value = newResult;"),b.write("return payload;"),b.compile()},s,a=$e,l=!M.jitless,u=l&&hn.value,p=t.catchall,f;e._zod.parse=(m,h)=>{f??(f=n.value);let y=m.value;if(!a(y))return m.issues.push({expected:"object",code:"invalid_type",input:y,inst:e}),m;if(l&&u&&h?.async===!1&&h.jitless!==!0){if(!s)s=i(t.shape);if(m=s(m,h),!p)return m;return vi([],y,m,h,f,e,h?.abortEarly===!0)}return r(m,h)}});function Eo(e,t,r,n){for(let i of e)if(i.issues.length===0)return t.value=i.value,t;let o=e.filter((i)=>!Y(i));if(o.length===1)return t.value=o[0].value,o[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((i)=>i.issues.map((s)=>Q(s,n,B())))}),t}var hr=d("$ZodUnion",(e,t)=>{k.init(e,t),z(e,"optin",(n)=>n.def.options.some((o)=>o._zod.optin==="defaulted")?"defaulted":n.def.options.some((o)=>o._zod.optin!==void 0)?"optional":void 0),z(e,"optout",(n)=>n.def.options.some((o)=>o._zod.optout==="optional")?"optional":void 0),z(e,"values",(n)=>{if(n.def.options.every((o)=>o._zod.values))return new Set(n.def.options.flatMap((o)=>Array.from(o._zod.values)));return}),z(e,"pattern",(n)=>{if(n.def.options.every((o)=>o._zod.pattern)){let o=n.def.options.map((i)=>i._zod.pattern);return new RegExp(`^(${o.map((i)=>ot(i.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(n,o)=>{if(r)return r(n,o);let i=!1,s=[];for(let a of t.options){let l=a._zod.run({value:n.value,issues:[]},o);if(l instanceof Promise)s.push(l),i=!0;else{if(l.issues.length===0)return l;s.push(l)}}if(!i)return Eo(s,n,e,o);return Promise.all(s).then((a)=>Eo(a,n,e,o))}});function zu(e){let t=new Map;for(let r of e.options){let n=r._zod.propValues?.[e.discriminator];if(!n||n.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);for(let o of n)if(t.has(o)){if(o!==void 0)throw Error(`Duplicate discriminator value "${String(o)}"`);t.set(o,null)}else t.set(o,r)}return t}var Si=d("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,hr.init(e,t);let r=e._zod.parse;z(e,"propValues",(o)=>{let i={},s=0;for(let a of o.def.options){let l=a._zod.propValues;if(!l||Object.keys(l).length===0)throw Error(`Invalid discriminated union option at index "${o.def.options.indexOf(a)}"`);if(l[o.def.discriminator]?.has(void 0))s++;for(let[c,u]of Object.entries(l)){if(!Object.prototype.hasOwnProperty.call(i,c))G(i,c,new Set);for(let p of u)i[c].add(p)}}if(!o.def.unionFallback&&s>1)i[o.def.discriminator]?.delete(void 0);return i}),t.options.forEach((o,i)=>{let s=Te(o._zod.def);if(s&&!Object.prototype.hasOwnProperty.call(s,t.discriminator))throw Error(`Invalid discriminated union option at index "${i}"`)});let n=Re(()=>zu(t));e._zod.parse=(o,i)=>{let s=o.value;if(!$e(s))return o.issues.push({code:"invalid_type",expected:"object",input:s,inst:e}),o;let a=s?.[t.discriminator],l=n.value.get(a);if(l&&(a!==void 0||i.direction!=="backward"))return l._zod.run(o,i);if(t.unionFallback||i.direction==="backward")return r(o,i);return o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(n.value.keys()).filter((c)=>n.value.get(c)!==null),input:s,path:[t.discriminator],inst:e}),o}}),wi=d("$ZodIntersection",(e,t)=>{k.init(e,t),e._zod.parse=(r,n)=>{let o=r.value,i=t.left._zod.run({value:o,issues:[]},n),s=t.right._zod.run({value:o,issues:[]},n);if(i instanceof Promise||s instanceof Promise)return Promise.all([i,s]).then(([l,c])=>Co(r,l,c));return Co(r,i,s)}});function pr(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(xe(e)&&xe(t)){let r=Object.keys(t),n=Object.keys(e).filter((i)=>r.indexOf(i)!==-1),o={...e,...t};if(Object.prototype.hasOwnProperty.call(o,"__proto__"))delete o.__proto__;for(let i of n){if(i==="__proto__")continue;let s=pr(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};o[i]=s.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let n=0;n<e.length;n++){let o=e[n],i=t[n],s=pr(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[n,...s.mergeErrorPath]};r.push(s.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function Co(e,t,r){let n=new Map,o,i=new Map,s=(c,u)=>{let p;if(c.code==="unrecognized_keys"&&!c.path?.length)o??(o=c),p=c.keys;else if(c.code==="invalid_key"&&c.origin==="record"&&c.path?.length===1){let f=String(c.path[0]);if(!i.has(f))i.set(f,c);p=[f]}else return!1;for(let f of p){if(!n.has(f))n.set(f,{});n.get(f)[u]=!0}return!0};for(let c of t.issues)if(!s(c,"l"))e.issues.push(c);for(let c of r.issues)if(!s(c,"r"))e.issues.push(c);let a=[...n].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(a.length){let c=o?a.filter((u)=>o.keys.includes(u)):[];if(c.length)e.issues.push({...o,keys:c});for(let u of a)if(!c.includes(u)&&i.has(u))e.issues.push(i.get(u))}let l=pr(t.value,r.value);if(!l.valid){if(Y(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(l.mergeErrorPath)}`)}return e.value=l.data,e}var $i=d("$ZodRecord",(e,t)=>{k.init(e,t);let r=M.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let i=n.value;if(!xe(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;let s=[],a=t.keyType._zod.values;if(a&&!t.partial){n.value=r?r.alloc(e,n,{},o):{};let l=new Set;for(let u of a)if(typeof u==="string"||typeof u==="number"||typeof u==="symbol"){if(l.add(typeof u==="number"?u.toString():u),u==="__proto__")continue;let p=t.keyType._zod.run({value:u,issues:[]},o);if(p instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(p.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map((h)=>Q(h,o,B())),input:u,path:[u],inst:e});continue}let f=p.value;if(f==="__proto__")continue;let m=t.valueType._zod.run({value:i[u],issues:[]},o);if(m instanceof Promise)s.push(m.then((h)=>{if(h.issues.length)n.issues.push(...pe(u,h.issues));n.value[f]=h.value}));else{if(m.issues.length)n.issues.push(...pe(u,m.issues));n.value[f]=m.value}}let c;for(let u in i)if(!l.has(u))if(t.mode==="loose"){if(u==="__proto__")continue;n.value[u]=i[u]}else c=c??[],c.push(u);if(c&&c.length>0)n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:c,continue:!0})}else{n.value=r?r.alloc(e,n,{},o):{};let l;for(let c of Reflect.ownKeys(i)){if(c==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(i,c))continue;let u=t.keyType._zod.run({value:c,issues:[]},o);if(u instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof c==="string"&&Le.test(c)&&u.issues.length){let h=t.keyType._zod.run({value:Number(c),issues:[]},o);if(h instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(h.issues.length===0)u=h}if(u.issues.length){if(t.mode==="loose")n.value[c]=i[c];else if(a)l=l??[],l.push(c);else n.issues.push({code:"invalid_key",origin:"record",issues:u.issues.map((h)=>Q(h,o,B())),input:c,path:[c],inst:e});continue}let f=u.value;if(f==="__proto__")continue;let m=t.valueType._zod.run({value:i[c],issues:[]},o);if(m instanceof Promise)s.push(m.then((h)=>{if(h.issues.length)n.issues.push(...pe(c,h.issues));n.value[f]=h.value}));else{if(m.issues.length)n.issues.push(...pe(c,m.issues));n.value[f]=m.value}}if(l&&l.length>0)n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:l,continue:!0})}if(s.length)return Promise.all(s).then(()=>n);return n}});var ki=d("$ZodEnum",(e,t)=>{k.init(e,t);let r=Ce(t.entries),n=new Set(r);e._zod.values=n,z(e,"pattern",(o)=>{let i=Ce(o.def.entries).filter((s)=>gn.has(typeof s));return new RegExp(i.length?`^(${i.map((s)=>le(s.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,i)=>{let s=o.value;if(n.has(s))return o;return o.issues.push({code:"invalid_value",values:r,input:s,inst:e}),o}}),Ii=d("$ZodLiteral",(e,t)=>{k.init(e,t);let r=new Set(t.values);e._zod.values=r,z(e,"pattern",(n)=>{let o=n.def.values;return new RegExp(o.length?`^(${o.map((i)=>typeof i==="string"?le(i):i?le(i.toString()):String(i)).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(n,o)=>{let i=n.value;if(r.has(i))return n;return n.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),n}});var Pi=d("$ZodTransform",(e,t)=>{k.init(e,t),e._zod.optin="optional",M.memoizer?.guard(e),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new De(e.constructor.name);let o=t.transform(r.value,r);if(n.async)return(o instanceof Promise?o:Promise.resolve(o)).then((s)=>(r.value=s,r));if(o instanceof Promise)throw new ee;return r.value=o,r}});function No(e,t){return e.value=t.issues.length?void 0:t.value,e}var gr=d("$ZodOptional",(e,t)=>{k.init(e,t),z(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",z(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),z(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${ot(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((i)=>No(r,i));return No(r,o)}return t.innerType._zod.run(r,n)}}),Zi=d("$ZodExactOptional",(e,t)=>{gr.init(e,t),z(e,"values",(r)=>r.def.innerType._zod.values),z(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,n)=>t.innerType._zod.run(r,n)}),Oi=d("$ZodNullable",(e,t)=>{k.init(e,t),z(e,"optin",(r)=>r.def.innerType._zod.optin),z(e,"optout",(r)=>r.def.innerType._zod.optout),z(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${ot(n.source)}|null)$`):void 0}),z(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,n)=>{if(r.value===null)return r;return t.innerType._zod.run(r,n)}}),Ai=d("$ZodDefault",(e,t)=>{k.init(e,t),e._zod.optin="defaulted",z(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)return r.value=t.defaultValue,r;let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>Ro(i,t));return Ro(o,t)}});function Ro(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var Ei=d("$ZodPrefault",(e,t)=>{k.init(e,t),e._zod.optin="defaulted",z(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,n)}}),Ci=d("$ZodNonOptional",(e,t)=>{k.init(e,t),z(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(r,n)=>{let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>To(i,e));return To(o,e)}});function To(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function Do(e,t,r,n){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((o)=>Q(o,n,B()))},input:e.value}),e}var Ni=d("$ZodCatch",(e,t)=>{k.init(e,t),z(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),z(e,"optout",(r)=>r.def.innerType._zod.optout),z(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((i)=>Do(r,i,t,n));return Do(r,o,t,n)}});var Ri=d("$ZodPipe",(e,t)=>{k.init(e,t),z(e,"values",(r)=>r.def.in._zod.values),z(e,"optin",(r)=>r.def.in._zod.optin),z(e,"optout",(r)=>r.def.out._zod.optout),z(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,n)=>{if(n.direction==="backward"){let i=t.out._zod.run(r,n);if(i instanceof Promise)return i.then((s)=>yt(s,t.in,n));return yt(i,t.in,n)}let o=t.in._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>yt(i,t.out,n));return yt(o,t.out,n)}});function yt(e,t,r){if(e.issues.some((n)=>n.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var Ti=d("$ZodReadonly",(e,t)=>{k.init(e,t),z(e,"propValues",(r)=>r.def.innerType._zod.propValues),z(e,"values",(r)=>r.def.innerType._zod.values),z(e,"optin",(r)=>r.def.innerType?._zod?.optin),z(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then(Lo);return Lo(o)}});function Lo(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var Di=d("$ZodLazy",(e,t)=>{k.init(e,t),ln(e._zod,"innerType",()=>{let r=t;if(!r._cachedInner)r._cachedInner=t.getter();return r._cachedInner}),z(e,"pattern",(r)=>r.innerType?._zod?.pattern),z(e,"propValues",(r)=>r.innerType?._zod?.propValues),z(e,"optin",(r)=>r.innerType?._zod?.optin??void 0),z(e,"optout",(r)=>r.innerType?._zod?.optout??void 0),e._zod.parse=(r,n)=>e._zod.innerType._zod.run(r,n)}),Li=d("$ZodCustom",(e,t)=>{R.init(e,t),k.init(e,t),e._zod.parse=(r,n)=>r,e._zod.check=(r)=>{let n=r.value,o=t.fn(n);if(o instanceof Promise)return o.then((i)=>jo(i,r,n,e));jo(o,r,n,e);return}});function jo(e,t,r,n){if(!e){let o={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};if(n._zod.def.params)o.params=n._zod.def.params;t.issues.push(_e(o))}}class Mi extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var xr="~memo",ji=[];function Fi(e){return e!==null&&typeof e==="object"}function yr(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var Ui=new WeakMap,Fe=0,wt=1,Ue=2;function $t(e,t,r){let n=Ui.get(e);if(n!==void 0)return n?Ue:Fe;if(t.has(e))return Ue;t.add(e);let o=Fe,i=(u)=>{if(o!==Ue&&u?._zod){let p=$t(u,t,r);if(p>o)o=p}},s=(u,p)=>{let f=Fe;for(let m of Reflect.ownKeys(u)){let h=Object.getOwnPropertyDescriptor(u,m);if(p&&!h.enumerable)continue;let y=h.get?wt:h.value?._zod?$t(h.value,t,r):Fe;if(y>f)f=y}return f},a=(u)=>{if(u>o)o=u},l=e._zod.def,c=l.type;switch(c){case"object":{let u=Te(l);a(u?s(u,!0):wt),i(l.catchall);break}case"array":i(l.element);break;case"tuple":for(let u of l.items)i(u);i(l.rest);break;case"record":case"map":i(l.keyType),i(l.valueType);break;case"set":i(l.valueType);break;case"union":for(let u of l.options)i(u);break;case"intersection":i(l.left),i(l.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":i(l.innerType);break;case"pipe":i(l.in),i(l.out);break;case"function":i(l.input),i(l.output);break;case"lazy":{let u=l._cachedInner??(r?e._zod.innerType:void 0);a(u?$t(u,t,!1):wt);break}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":break;default:for(let u in l){let p=Object.getOwnPropertyDescriptor(l,u);if(!p||p.get)continue;let f=p.value;if(!f||typeof f!=="object")continue;if(f._zod)i(f);else if(Array.isArray(f))for(let m of f)i(m)}}return t.delete(e),Su(e,o)}function Su(e,t){if(t!==wt)Ui.set(e,t===Ue);return t}function wu(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var zt,St=[],$u={alloc(e,t,r){let n=zt;if(!n)return r;zt=void 0;let o={value:r,issues:null};return n.set(t.value,o),St.push(o),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,n=(o,i)=>{if(i.direction!=="backward"&&ku(i,o.value))throw new Mi;return r(o,i)};if(e._zod.parse=n,e._zod.run===r)e._zod.run=n})},attach(e){var t;let r,n=!1,o,i;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let s=e._zod.parse,a=(l,c)=>{if(r===void 0){let S=$t(e,new Set,!1);if(S===Fe){if(e._zod.parse=s,e._zod.run===a)e._zod.run=s;return s(l,c)}if(S===Ue||n)r=!0;else n=!0}let u=l.value;if(!Fi(u))return s(l,c);let p=c[xr];if(!p)p={buckets:new WeakMap,backEdges:void 0},c[xr]=p;let f;if(o===c)f=i;else f=wu(p,e),o=c,i=f;let m=f.get(u);if(m){if(l.value=m.value,m.issues){if(m.issues.length)l.issues.push(...yr(m.issues))}else l.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(m.value);return l}zt=f;let h=St.length,y=s(l,c);zt=void 0;let b=St.length>h?St.pop():void 0;if(y instanceof Promise)return y.then((S)=>{if(b)b.issues=S.issues.length?yr(S.issues):ji;return S});if(b)b.issues=y.issues.length?yr(y.issues):ji;return y};if(e._zod.parse=a,e._zod.run===s)e._zod.run=a})}};function Bi(){return $u}function ku(e,t){let r=e[xr]?.backEdges;return r!==void 0&&Fi(t)&&r.has(t)}var Iu=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(i){return e[i]??null}let r={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",currency_code:"currency code",credit_card:"credit card number",iban:"IBAN",jwt:"JWT",template_literal:"input"},n={nan:"NaN"};function o(i,s){if(i==="number"&&typeof s==="number"&&!Number.isFinite(s))return String(s);return n[i]??i}return(i)=>{switch(i.code){case"invalid_type":{let s=o(i.expected),a=vn(i.input),l=o(a,i.input);return`Invalid input: expected ${s}, received ${l}`}case"invalid_value":if(i.values.length===1)return`Invalid input: expected ${Xt(i.values[0])}`;return`Invalid option: expected one of ${Kt(i.values,"|")}`;case"too_big":{let s=i.exact?"exactly ":i.inclusive?"<=":"<",a=t(i.origin);if(a)return`Too big: expected ${i.origin??"value"} to have ${s}${i.maximum.toString()} ${a.unit??"elements"}`;return`Too big: expected ${i.origin??"value"} to be ${s}${i.maximum.toString()}`}case"too_small":{let s=i.exact?"exactly ":i.inclusive?">=":">",a=t(i.origin);if(a)return`Too small: expected ${i.origin} to have ${s}${i.minimum.toString()} ${a.unit}`;return`Too small: expected ${i.origin} to be ${s}${i.minimum.toString()}`}case"invalid_format":{let s=i;if(s.format==="starts_with")return`Invalid string: must start with "${s.prefix}"`;if(s.format==="ends_with")return`Invalid string: must end with "${s.suffix}"`;if(s.format==="includes")return`Invalid string: must include "${s.includes}"`;if(s.format==="regex")return`Invalid string: must match pattern ${s.pattern}`;return`Invalid ${r[s.format]??i.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${i.divisor}`;case"unrecognized_keys":return`Unrecognized key${i.keys.length>1?"s":""}: ${Kt(i.keys,", ")}`;case"invalid_key":return`Invalid key in ${i.origin}`;case"invalid_union":if(i.options&&Array.isArray(i.options)&&i.options.length>0)return`Invalid discriminator value. Expected ${i.options.map((a)=>`'${a}'`).join(" | ")}`;if(i.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${i.origin}`;default:return"Invalid input"}}};function _r(){return{localeError:Iu()}}var Ji;class Vi{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let n={...r,...this._map.get(e)};return Object.keys(n).length?n:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function Pu(){return new Vi}(Ji=globalThis).__zod_globalRegistry??(Ji.__zod_globalRegistry=Pu());var be=globalThis.__zod_globalRegistry;function Gi(e){if(e.checks)e.checks=[...e.checks];return e}function Ki(e,t){return new e(Gi({type:"string",...g(t)}))}function Wi(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...g(t)})}function qi(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...g(t)})}function Xi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...g(t)})}function Hi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...g(t)})}function Yi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...g(t)})}function Qi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...g(t)})}function es(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...g(t)})}function ts(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...g(t)})}function rs(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...g(t)})}function ns(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...g(t)})}function os(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...g(t)})}function is(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...g(t)})}function ss(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...g(t)})}function as(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...g(t)})}function cs(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...g(t)})}function us(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...g(t)})}function ls(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...g(t)})}function ps(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...g(t)})}function fs(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...g(t)})}function ds(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...g(t)})}function ms(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...g(t)})}function hs(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...g(t)})}function kt(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...g(t)})}function It(e,t){return new e({type:"string",format:"date",check:"string_format",...g(t)})}function Pt(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...g(t)})}function Zt(e,t){return new e({type:"string",format:"duration",check:"string_format",...g(t)})}function gs(e,t){return new e(Gi({type:"number",checks:[],...g(t)}))}function ys(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...g(t)})}function xs(e,t){return new e({type:"boolean",...g(t)})}function _s(e,t){return new e({type:"null",...g(t)})}function bs(e){return new e({type:"unknown"})}function vs(e,t){return new e({type:"never",...g(t)})}function Ot(e,t){return new cr({check:"less_than",...g(t),value:e,inclusive:!1})}function Be(e,t){return new cr({check:"less_than",...g(t),value:e,inclusive:!0})}function At(e,t){return new ur({check:"greater_than",...g(t),value:e,inclusive:!1})}function Je(e,t){return new ur({check:"greater_than",...g(t),value:e,inclusive:!0})}function Et(e,t){return new go({check:"multiple_of",...g(t),value:e})}function Ct(e,t){return new xo({check:"max_length",...g(t),maximum:e})}function ke(e,t){return new _o({check:"min_length",...g(t),minimum:e})}function Nt(e,t){return new bo({check:"length_equals",...g(t),length:e})}function br(e,t){return new vo({check:"string_format",format:"regex",...g(t),pattern:e})}function vr(e){return new zo({check:"string_format",format:"lowercase",...g(e)})}function zr(e){return new So({check:"string_format",format:"uppercase",...g(e)})}function Sr(e,t){return new wo({check:"string_format",format:"includes",...g(t),includes:e})}function wr(e,t){return new $o({check:"string_format",format:"starts_with",...g(t),prefix:e})}function $r(e,t){return new ko({check:"string_format",format:"ends_with",...g(t),suffix:e})}function fe(e){return new Io({check:"overwrite",tx:e})}function kr(e){return fe((t)=>t.normalize(e))}function Ir(){return fe((e)=>e.trim())}function Pr(){return fe((e)=>e.toLowerCase())}function Zr(){return fe((e)=>e.toUpperCase())}function Or(){return fe((e)=>mn(e))}function zs(e,t,r){return new e({type:"array",element:t,...g(r)})}function Ss(e,t,r){let n=g(r);return n.abort??(n.abort=!0),new e({type:"custom",check:"custom",fn:t,...n})}function ws(e,t,r){return new e({type:"custom",check:"custom",fn:t,...g(r)})}function $s(e,t){let r=Zu((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(_e(o,n.value,r._zod.def));else{let i=o;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=n.value;i.inst??(i.inst=r),i.continue??(i.continue=!r._zod.def.abort),n.issues.push(_e(i))}},e(n.value,n)),t);return r}function Zu(e,t){let r=new R({check:"custom",...g(t)});return r._zod.check=e,r}function Ve(e,...t){for(let r of t)for(let n of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,n))G(e,n,r[n]);return e}function Er(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??be,target:t,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 ie(e,t,r,n,o){let i=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:n.path,message:o}):t.unrepresentable;if(i==="any")return!1;if(i===void 0||i==="throw")throw Error(o);return Object.assign(r,i),!0}function A(e,t,r={path:[],schemaPath:[]}){var n;let o=e._zod.def,i=t.seen.get(e);if(i){if(i.count++,r.schemaPath.includes(e))i.cycle=r.path;return i.schema}let s={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,s),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{let u={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,u);else{let f=s.schema,m=t.processors[o.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);m(e,t,f,u)}let p=e._zod.parent;if(p){if(!s.ref)s.ref=p;A(p,t,u),t.seen.get(p).isParent=!0}}let l=t.metadataRegistry.get(e);if(l)Ve(s.schema,l);if(t.io==="input"&&D(e))delete s.schema.examples,delete s.schema.default;if(t.io==="input"&&"_prefault"in s.schema)(n=s.schema).default??(n.default=s.schema._prefault);return delete s.schema._prefault,t.seen.get(e).schema}function ks(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Cr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let n=new Map;for(let s of e.seen.entries()){let a=e.metadataRegistry.get(s[0])?.id;if(a){let l=n.get(a);if(l&&l!==s[0])throw Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);n.set(a,s[0])}}let o=(s)=>{let a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let p=e.external.registry.get(s[0])?.id,f=e.external.uri??((h)=>h);if(p)return{ref:f(p)};let m=s[1].defId??s[1].schema.id??`schema${e.counter++}`;return s[1].defId=m,{defId:m,ref:`${f("__shared")}#/${a}/${ks(m)}`}}let l="#",c=`${l}/${a}/`;if(s[1]===r&&!s[1].schema.id)return{ref:l};let u=s[1].schema.id??`__schema${e.counter++}`;return{defId:u,ref:c+ks(u)}},i=(s)=>{if(s[1].schema.$ref)return;let a=s[1],{ref:l,defId:c}=o(s);if(a.def={...a.schema},c)a.defId=c;let u=a.schema;for(let p in u)delete u[p];u.$ref=l};if(e.cycles==="throw")for(let s of e.seen.entries()){let a=s[1];if(a.cycle)throw Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
|
|
58
58
|
|
|
59
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of e.seen.entries()){let a=s[1];if(t===s[0]){i(s);continue}if(e.external){let c=e.external.registry.get(s[0])?.id;if(t!==s[0]&&c){i(s);continue}}if(e.metadataRegistry.get(s[0])?.id){i(s);continue}if(a.cycle){i(s);continue}if(a.count>1){if(e.reused==="ref")i(s)}}if(e.external)e.sharedDefsExtractedFor=e.external}function Zs(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let n of t){if(!n||typeof n!=="object")return;Zs(n);let o=Object.keys(n);if(o.length!==1||o[0]!=="type")return;let i=n.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!=="string")return;if(!r.includes(s))r.push(s)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var Os=new Set(["type","properties","required","additionalProperties"]),Is=["oneOf","anyOf"];function Ps(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function Ar(e){let t=[];for(let i of e){if(typeof i!=="object"||i.type!=="object")return null;for(let s in i)if(!Os.has(s))return null;t.push(i)}let r={},n=new Set;for(let i of t){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let a=[];for(let c of t){let u=c.properties?.[s]??Ps(c);if(u===null||u===void 0)continue;if(!a.some((p)=>JSON.stringify(p)===JSON.stringify(u)))a.push(u)}let l=a.length===1?a[0]:Ar(a)??{allOf:a};G(r,s,l)}for(let s of i.required??[])n.add(s)}let o={type:"object",properties:r};if(n.size)o.required=[...n];if(t.every((i)=>i.additionalProperties===!1))o.additionalProperties=!1;else{let i=[];for(let s of t){let a=Ps(s);if(a&&!i.some((l)=>JSON.stringify(l)===JSON.stringify(a)))i.push(a)}if(i.length===1)o.additionalProperties=i[0];else if(i.length>1)o.additionalProperties={allOf:i}}return o}function Ou(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let o of Os)if(o in e)return;let r=t.filter((o)=>Is.some((i)=>Array.isArray(o[i]))),n=null;if(!r.length)n=Ar(t);else{let o=r[0],i=Is.find((l)=>Array.isArray(o[l]));if(Object.keys(o).length!==1)return;let s=t.filter((l)=>l!==o),a=o[i].map((l)=>Ar([...s,l]));if(a.some((l)=>!l))return;n={[i]:a}}if(!n)return;delete e.allOf,Ve(e,n)}function Nr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let n=(a)=>{let l=e.seen.get(a);if(l.ref===null)return;let c=l.def??l.schema,u={...c},p=l.ref;if(l.ref=null,p){n(p);let m=e.seen.get(p),h=m.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))c.allOf=c.allOf??[],c.allOf.push(h);else Ve(c,h);if(Ve(c,u),a._zod.parent===p)for(let b in c){if(b==="$ref"||b==="allOf")continue;if(!(b in u))delete c[b]}if(h.$ref&&m.def)for(let b in c){if(b==="$ref"||b==="allOf")continue;if(b in m.def&&JSON.stringify(c[b])===JSON.stringify(m.def[b]))delete c[b]}}let f=a._zod.parent;if(f&&f!==p){n(f);let m=e.seen.get(f);if(m?.schema.$ref){if(c.$ref=m.schema.$ref,m.def)for(let h in c){if(h==="$ref"||h==="allOf")continue;if(h in m.def&&JSON.stringify(c[h])===JSON.stringify(m.def[h]))delete c[h]}}}e.override({zodSchema:a,jsonSchema:c,path:l.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let a of[...e.seen.entries()].reverse())n(a[0]);if(e.target!=="openapi-3.0")for(let a of e.seen.entries())Zs(a[1].def??a[1].schema);for(let a of e.deferred)a();if(e.intersections.length){let a=new Map;for(let l of e.seen.values())for(let c of[l.schema,l.def]){let u=c?.allOf;if(!Array.isArray(u))continue;let p=a.get(u);if(p)p.push(c);else a.set(u,[c])}for(let l of e.intersections)for(let c of a.get(l)??[])Ou(c)}}let o={};if(e.target==="draft-2020-12")o.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")o.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")o.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");o.$id=e.external.uri(a)}Ve(o,r.defId?r.schema:r.def??r.schema);let i=e.metadataRegistry.get(t)?.id;if(i!==void 0&&o.id===i)delete o.id;let s=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let a of e.seen.entries()){let l=a[1];if(l.def&&l.defId){if(l.def.id===l.defId)delete l.def.id;G(s,l.defId,l.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")o.$defs=s;else o.definitions=s;try{let a=JSON.parse(JSON.stringify(o));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:Ge(t,"input",e.processors),output:Ge(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function D(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let n=e._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return D(n.element,r);if(n.type==="set")return D(n.valueType,r);if(n.type==="lazy")return D(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault"||n.type==="catch")return D(n.innerType,r);if(n.type==="intersection")return D(n.left,r)||D(n.right,r);if(n.type==="record"||n.type==="map")return D(n.keyType,r)||D(n.valueType,r);if(n.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return D(n.in,r)||D(n.out,r)}if(n.type==="object"){for(let o in n.shape)if(D(n.shape[o],r))return!0;return!1}if(n.type==="union"){for(let o of n.options)if(D(o,r))return!0;return!1}if(n.type==="tuple"){for(let o of n.items)if(D(o,r))return!0;if(n.rest&&D(n.rest,r))return!0;return!1}return!1}var As=(e,t={})=>(r)=>{let n=Er({...r,processors:t});return A(e,n),Cr(n,e),Nr(n,e)},Ge=(e,t,r={})=>(n)=>{let{libraryOptions:o,target:i}=n??{},s=Er({...o??{},target:i,io:t,processors:r});return A(e,s),Cr(s,e),Nr(s,e)};var Ie=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},Pe=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},Es=(e,t)=>{Ie(e,"minimum",t),Pe(e,"maximum",t)},Ts=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},Ds=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},Ls=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},js=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},Cs=(e,t)=>Ie(e,"minimum",t.minimum),Ns=(e,t)=>Pe(e,"maximum",t.maximum),Rs=(e)=>(t,r)=>{js(t,r.format);let[n,o]=e[r.format];Ie(t,"minimum",n),Pe(t,"maximum",o)},Au={greater_than:(e,t)=>Ie(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>Pe(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>Ts(e,t.value),number_format:Rs(it),bigint_format:Rs(Ht),min_length:Cs,max_length:Ns,length_equals:(e,t)=>Es(e,t.length),min_size:Cs,max_size:Ns,size_equals:(e,t)=>Es(e,t.size),string_format:(e,t)=>{if(js(e,t.format),t.pattern)Ds(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>Ls(e,t.mime)};function K(e){let t={},r=e._zod.def,n=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let i of n)Au[i._zod.def.check]?.(t,i._zod.def);let o=e._zod.bag;if(o.minimum!==void 0)Ie(t,"minimum",o.minimum);if(o.exclusiveMinimum!==void 0)Ie(t,"exclusiveMinimum",o.exclusiveMinimum);if(o.maximum!==void 0)Pe(t,"maximum",o.maximum);if(o.exclusiveMaximum!==void 0)Pe(t,"exclusiveMaximum",o.exclusiveMaximum);if(o.multipleOf!==void 0)Ts(t,o.multipleOf);if(o.format!==void 0){if(t.format??(t.format=o.format),o.format.includes("int"))t.isInt=!0}if(o.mime)Ls(t,o.mime);for(let i of o.patterns??[])Ds(t,i);return t}var Eu={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Cu=new Map([[dr,ro],[vt,no]]),Ms=(e)=>Cu.get(e)??e,Fs=(e,t,r,n)=>{let o=r;o.type="string";let{minimum:i,maximum:s,format:a,patterns:l,contentEncoding:c,laxFormat:u}=K(e);if(typeof i==="number")o.minLength=i;if(typeof s==="number")o.maxLength=s;if(a){if(o.format=Eu[a]??a,o.format==="")delete o.format;if(a==="time"||u)delete o.format}if(c)o.contentEncoding=c;if(l&&l.size>0){let p=[...l].map(Ms);if(p.length===1)o.pattern=p[0].source;else if(p.length>1)o.allOf=[...p.map((f)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))]}},Us=(e,t,r,n)=>{let o=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:l,exclusiveMinimum:c,isInt:u}=K(e);o.type=u?"integer":"number";let p=typeof c==="number"&&c>=(i??Number.NEGATIVE_INFINITY),f=typeof l==="number"&&l<=(s??Number.POSITIVE_INFINITY),m=t.target==="draft-04"||t.target==="openapi-3.0";if(p)if(m)o.minimum=c,o.exclusiveMinimum=!0;else o.exclusiveMinimum=c;else if(typeof i==="number")o.minimum=i;if(f)if(m)o.maximum=l,o.exclusiveMaximum=!0;else o.exclusiveMaximum=l;else if(typeof s==="number")o.maximum=s;if(a){let h=new Set;for(let S of a)if(Number.isFinite(S)&&S!==0)h.add(Math.abs(S));else ie(e,t,o,n,`A multipleOf divisor of ${S} cannot be represented in JSON Schema`);let[y,...b]=h;if(y!==void 0)o.multipleOf=y;if(b.length)o.allOf=[...o.allOf??[],...b.map((S)=>({multipleOf:S}))]}},Bs=(e,t,r,n)=>{r.type="boolean"};var Js=(e,t,r,n)=>{if(t.target==="openapi-3.0")r.type="string",r.nullable=!0,r.enum=[null];else r.type="null"};var Vs=(e,t,r,n)=>{r.not={}};var Gs=(e,t,r,n)=>{};var Ks=(e,t,r,n)=>{let o=e._zod.def,i=Ce(o.entries);if(i.length===0){r.not={};return}if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";r.enum=i},Ws=(e,t,r,n)=>{let o=e._zod.def;if(o.values.length===0){r.not={};return}let i=[];for(let s of o.values)if(s===void 0){if(ie(e,t,r,n,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s==="bigint"){if(ie(e,t,r,n,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length===0);else if(i.length===1){let s=i[0];if(r.type=s===null?"null":typeof s,t.target==="draft-04"||t.target==="openapi-3.0")r.enum=[s];else r.const=s}else{if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";if(i.every((s)=>typeof s==="boolean"))r.type="boolean";if(i.every((s)=>s===null))r.type="null";r.enum=i}};var qs=(e,t,r,n)=>{ie(e,t,r,n,"Custom types cannot be represented in JSON Schema")};var Xs=(e,t,r,n)=>{ie(e,t,r,n,"Transforms cannot be represented in JSON Schema")};var Hs=(e,t,r,n)=>{let o=r,i=e._zod.def,{minimum:s,maximum:a}=K(e);if(typeof s==="number")o.minItems=s;if(typeof a==="number")o.maxItems=a;o.type="array",o.items=A(i.element,t,{...n,path:[...n.path,"items"]})};function Rt(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return Rt(t.out);if(t.type==="catch")return Rt(t.innerType);return e._zod.optin}var Ys=(e,t,r,n)=>{let o=r,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&ie(e,t,o,n,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(let c in s)G(o.properties,c,A(s[c],t,{...n,path:[...n.path,"properties",c]}));let l=[];for(let c of Object.keys(s)){let u=i.shape[c];if(t.io==="input"?Rt(u)===void 0:u._zod.optout===void 0)l.push(c)}if(l.length>0)o.required=l;if(i.catchall?._zod.def.type==="never")o.additionalProperties=!1;else if(!i.catchall){if(t.io==="output")o.additionalProperties=!1}else if(i.catchall)o.additionalProperties=A(i.catchall,t,{...n,path:[...n.path,"additionalProperties"]})},Qs=(e,t,r,n)=>{let o=e._zod.def,i=o.inclusive===!1,s=o.options.map((a,l)=>A(a,t,{...n,path:[...n.path,i?"oneOf":"anyOf",l]}));if(i)r.oneOf=s;else r.anyOf=s},ea=(e,t,r,n)=>{let o=e._zod.def,i=A(o.left,t,{...n,path:[...n.path,"allOf",0]}),s=A(o.right,t,{...n,path:[...n.path,"allOf",1]}),a=(c)=>("allOf"in c)&&Object.keys(c).length===1,l=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];r.allOf=l,t.intersections.push(l)};function Rr(e,t,r){if(t.$ref){if(r.has(t))return t;r.add(t);let h=e.get(t)?.def;if(!h)return t;let y=Rr(e,h,r);return y===h?t:y}for(let h of["anyOf","oneOf"]){let y=t[h];if(!Array.isArray(y))continue;let b=y.map((S)=>Rr(e,S,r));if(b.some((S,E)=>S!==y[E]))t={...t,[h]:b}}let n=Array.isArray(t.type)?t.type:[t.type],o=!n.includes("string")&&n.some((h)=>h==="number"||h==="integer"),i=t.enum??(t.const!==void 0?[t.const]:void 0);if(!o&&!i?.some((h)=>typeof h==="number"))return t;let{minimum:s,maximum:a,exclusiveMinimum:l,exclusiveMaximum:c,multipleOf:u,format:p,id:f,...m}=t;if(m.enum)m.enum=m.enum.map((h)=>typeof h==="number"?String(h):h);else if(typeof m.const==="number")m.const=String(m.const);if(!o)return m;if(m.type="string",!i)m.pattern=(n.includes("number")?Le:sr).source;return m}var Tr=new WeakMap;function Nu(e){let t=new Map;for(let n of e.seen.values())if(n.def&&!t.has(n.schema))t.set(n.schema,n);let r=new Map;for(let n of Tr.get(e)??[]){let o=e.seen.get(n),i=(o?.def??o?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=Rr(t,i,new Set);if(s!==i)r.set(i,s)}if(!r.size)return;for(let n of e.seen.values())for(let o of[n.schema,n.def]){let i=o&&r.get(o.propertyNames);if(i)o.propertyNames=i}}var ta=(e,t,r,n)=>{let o=r,i=e._zod.def;o.type="object";let s=i.keyType,a=K(s).patterns;if(i.mode==="loose"&&a&&a.size>0){let u=A(i.valueType,t,{...n,path:[...n.path,"patternProperties","*"]});o.patternProperties={};for(let p of a)G(o.patternProperties,Ms(p).source,u)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){o.propertyNames=A(i.keyType,t,{...n,path:[...n.path,"propertyNames"]});let u=Tr.get(t);if(!u)u=[],Tr.set(t,u),t.deferred.push(()=>Nu(t));u.push(e)}o.additionalProperties=A(i.valueType,t,{...n,path:[...n.path,"additionalProperties"]})}let l=s._zod.values,c=t.io==="input"&&Rt(i.valueType)!==void 0;if(l&&!i.partial&&!c){let u=[...l].filter((p)=>typeof p==="string"||typeof p==="number");if(u.length>0)o.required=u.map(String)}},ra=(e,t,r,n)=>{let o=e._zod.def,i=A(o.innerType,t,n),s=t.seen.get(e);if(t.target==="openapi-3.0")s.ref=o.innerType,r.nullable=!0;else r.anyOf=[i,{type:"null"}]},na=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType},Dr=Symbol();function oa(e,t,r,n,o){let i=!1,s=JSON.stringify(e,(a,l)=>{if(typeof l!=="bigint")return l;return i=!0,null});if(!i)return JSON.parse(s);return ie(t,r,n,o,"BigInt defaults cannot be represented in JSON Schema"),Dr}var ia=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s=oa(o.defaultValue,e,t,r,n);if(s!==Dr)r.default=s},sa=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);if(i.ref=o.innerType,t.io!=="input")return;let s=oa(o.defaultValue,e,t,r,n);if(s!==Dr)r._prefault=s},aa=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{ie(e,t,r,n,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},ca=(e,t,r,n)=>{let o=e._zod.def,i=o.in._zod.traits.has("$ZodTransform"),s=t.io==="input"?i?o.out:o.in:o.out;A(s,t,n);let a=t.seen.get(e);a.ref=s},ua=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType,r.readOnly=!0};var Lr=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType},la=(e,t,r,n)=>{let o=e._zod.innerType;A(o,t,n);let i=t.seen.get(e);i.ref=o};var pa=new WeakSet([Object.prototype,Error.prototype]);function Tt(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let n=r(this);return Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0})}})}var Bu=(e,t)=>{Zn.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(pa.has(r))return;pa.add(r),Tt(r,"format",(n)=>(o)=>An(n,o)),Tt(r,"flatten",(n)=>(o)=>On(n,o)),Tt(r,"addIssue",(n)=>(o)=>{n.issues.push(o),n.message=JSON.stringify(n.issues,Ne,2)}),Tt(r,"addIssues",(n)=>(o)=>{n.issues.push(...o),n.message=JSON.stringify(n.issues,Ne,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var J=d("ZodError",Bu,void 0,{Parent:Error});var fa=ft(J),da=dt(J),ma=mt(J),ha=ht(J),ga=Cn(J),ya=Nn(J),xa=Rn(J),_a=Tn(J),ba=Dn(J),va=Ln(J),za=jn(J),Sa=Mn(J);function Vu(){if(!M.localeError)B(_r())}function Lt(){if(!M.memoizer)B({memoizer:Bi()})}var Z=d("ZodType",(e,t)=>(Vu(),k.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(U(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return H(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ul(e,t))},superRefine(e,t){return this.check(Bl(e,t))},overwrite(e){return this.check(fe(e))},optional(){return Ia(this)},exactOptional(){return Il(this)},nullable(){return Pa(this)},nullish(){return Ia(Pa(this))},nonoptional(e){return Cl(this,e)},array(){return se(this)},or(e){return Ca([this,e])},and(e){return zl(this,e)},transform(e){return Za(this,kl(e))},default(e){return Ol(this,e)},prefault(e){return El(this,e)},catch(e){return Rl(this,e)},pipe(e){return Za(this,e)},readonly(){return Ll(this)},describe(e){let t=this.clone();return be.add(t,{description:e}),t},meta(...e){if(e.length===0)return be.get(this);let t=this.clone();return be.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get "~standard"(){return lt(this,"~standard",{...fr(this),jsonSchema:{input:Ge(this,"input"),output:Ge(this,"output")}})},set "~standard"(e){oe(this,"~standard",e)},parse:function e(t,r){return fa(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await da(this,t,r,{callee:e})},safeParse(e,t){return ma(this,e,t)},async safeParseAsync(e,t){return ha(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){oe(this,"spa",e)},validate(e,t){return rr(this,e,t)},validateAsync(e,t){return nr(this,e,t)},encode:function e(t,r){return ga(this,t,r,{callee:e})},decode:function e(t,r){return ya(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await xa(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await _a(this,t,r,{callee:e})},safeEncode(e,t){return ba(this,e,t)},safeDecode(e,t){return va(this,e,t)},async safeEncodeAsync(e,t){return za(this,e,t)},async safeDecodeAsync(e,t){return Sa(this,e,t)},toJSONSchema(e){return As(this,{})(e)},get description(){return be.get(this)?.description},get _def(){return this._zod.def}}),Oa=d("_ZodString",(e,t)=>{bt.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Fs(e,r,n,o)},Sn({format:(e)=>K(e).format??null,minLength:(e)=>K(e).minimum??null,maxLength:(e)=>K(e).maximum??null},{regex(...e){return this.check(br(...e))},includes(...e){return this.check(Sr(...e))},startsWith(...e){return this.check(wr(...e))},endsWith(...e){return this.check($r(...e))},min(...e){return this.check(ke(...e))},max(...e){return this.check(Ct(...e))},length(...e){return this.check(Nt(...e))},nonempty(...e){return this.check(ke(1,...e))},lowercase(e){return this.check(vr(e))},uppercase(e){return this.check(zr(e))},trim(){return this.check(Ir())},normalize(...e){return this.check(kr(...e))},toLowerCase(){return this.check(Pr())},toUpperCase(){return this.check(Zr())},slugify(){return this.check(Or())}})),Gu=d("ZodString",(e,t)=>{bt.init(e,t),Oa.init(e,t)},{email(e){return this.check(Wi(Ku,e))},url(e){return this.check(es(qu,e))},jwt(e){return this.check(hs(ll,e))},emoji(e){return this.check(ts(Xu,e))},guid(e){return this.check(qi(Wu,e))},uuid(e){return this.check(Xi(Dt,e))},uuidv4(e){return this.check(Hi(Dt,e))},uuidv6(e){return this.check(Yi(Dt,e))},uuidv7(e){return this.check(Qi(Dt,e))},nanoid(e){return this.check(rs(Hu,e))},cuid(e){return this.check(ns(Yu,e))},cuid2(e){return this.check(os(Qu,e))},ulid(e){return this.check(is(el,e))},base64(e){return this.check(fs(al,e))},base64url(e){return this.check(ds(cl,e))},xid(e){return this.check(ss(tl,e))},ksuid(e){return this.check(as(rl,e))},ipv4(e){return this.check(cs(nl,e))},ipv6(e){return this.check(us(ol,e))},cidrv4(e){return this.check(ls(il,e))},cidrv6(e){return this.check(ps(sl,e))},e164(e){return this.check(ms(ul,e))},datetime(e){return this.check(kt(We,e))},date(e){return this.check(It(qe,e))},time(e){return this.check(Pt(Xe,e))},duration(e){return this.check(Zt(He,e))}});function te(e){return Ki(Gu,e)}var O=d("ZodStringFormat",(e,t)=>{P.init(e,t),Oa.init(e,t)}),We=d("ZodISODateTime",(e,t)=>{ei.init(e,t),O.init(e,t)}),qe=d("ZodISODate",(e,t)=>{ti.init(e,t),O.init(e,t)}),Xe=d("ZodISOTime",(e,t)=>{ri.init(e,t),O.init(e,t)}),He=d("ZodISODuration",(e,t)=>{ni.init(e,t),O.init(e,t)}),Ku=d("ZodEmail",(e,t)=>{Bo.init(e,t),O.init(e,t)});var Wu=d("ZodGUID",(e,t)=>{Fo.init(e,t),O.init(e,t)});var Dt=d("ZodUUID",(e,t)=>{Uo.init(e,t),O.init(e,t)});var qu=d("ZodURL",(e,t)=>{Go.init(e,t),O.init(e,t)});var Xu=d("ZodEmoji",(e,t)=>{Ko.init(e,t),O.init(e,t)});var Hu=d("ZodNanoID",(e,t)=>{Wo.init(e,t),O.init(e,t)});var Yu=d("ZodCUID",(e,t)=>{qo.init(e,t),O.init(e,t)});var Qu=d("ZodCUID2",(e,t)=>{Xo.init(e,t),O.init(e,t)});var el=d("ZodULID",(e,t)=>{Ho.init(e,t),O.init(e,t)});var tl=d("ZodXID",(e,t)=>{Yo.init(e,t),O.init(e,t)});var rl=d("ZodKSUID",(e,t)=>{Qo.init(e,t),O.init(e,t)});var nl=d("ZodIPv4",(e,t)=>{oi.init(e,t),O.init(e,t)});var ol=d("ZodIPv6",(e,t)=>{si.init(e,t),O.init(e,t)});var il=d("ZodCIDRv4",(e,t)=>{ai.init(e,t),O.init(e,t)});var sl=d("ZodCIDRv6",(e,t)=>{ci.init(e,t),O.init(e,t)});var al=d("ZodBase64",(e,t)=>{li.init(e,t),O.init(e,t)});var cl=d("ZodBase64URL",(e,t)=>{pi.init(e,t),O.init(e,t)});var ul=d("ZodE164",(e,t)=>{fi.init(e,t),O.init(e,t)});var ll=d("ZodJWT",(e,t)=>{di.init(e,t),O.init(e,t)});var Aa=d("ZodNumber",(e,t)=>{mr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Us(e,r,n,o),e.isFinite=!0},Sn({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=K(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=K(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=K(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>K(e).format??null},{gt(e,t){return this.check(At(e,t))},gte(e,t){return this.check(Je(e,t))},min(e,t){return this.check(Je(e,t))},lt(e,t){return this.check(Ot(e,t))},lte(e,t){return this.check(Be(e,t))},max(e,t){return this.check(Be(e,t))},int(e){return this.check(wa(e))},safe(e){return this.check(wa(e))},positive(e){return this.check(At(0,e))},nonnegative(e){return this.check(Je(0,e))},negative(e){return this.check(Ot(0,e))},nonpositive(e){return this.check(Be(0,e))},multipleOf(e,t){return this.check(Et(e,t))},step(e,t){return this.check(Et(e,t))},finite(){return this}}));function Ye(e){return gs(Aa,e)}var pl=d("ZodNumberFormat",(e,t)=>{mi.init(e,t),Aa.init(e,t)});function wa(e){return ys(pl,e)}var fl=d("ZodBoolean",(e,t)=>{hi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Bs(e,r,n,o)});function Mr(e){return xs(fl,e)}var dl=d("ZodNull",(e,t)=>{gi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Js(e,r,n,o)});function ml(e){return _s(dl,e)}var hl=d("ZodUnknown",(e,t)=>{yi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Gs(e,r,n,o)});function $a(){return bs(hl)}var gl=d("ZodNever",(e,t)=>{xi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Vs(e,r,n,o)});function yl(e){return vs(gl,e)}var xl=d("ZodArray",(e,t)=>{Lt(),_i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Hs(e,r,n,o),e.element=t.element},{min(e,t){return this.check(ke(e,t))},nonempty(e){return this.check(ke(1,e))},max(e,t){return this.check(Ct(e,t))},length(e,t){return this.check(Nt(e,t))},unwrap(){return this.element}});function se(e,t){return zs(xl,e,t)}var _l=d("ZodObject",(e,t)=>{Lt(),zi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ys(e,r,n,o),Xc(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return ae(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(U(this._zod.def,{catchall:e}))},passthrough(){return this.clone(U(this._zod.def,{catchall:$a()}))},loose(){return this.clone(U(this._zod.def,{catchall:$a()}))},strict(){return this.clone(U(this._zod.def,{catchall:yl()}))},strip(){return this.clone(U(this._zod.def,{catchall:void 0}))},extend(e){return Uc(this,e)},safeExtend(e){return Bc(this,e)},merge(e){return Jc(this,e)},pick(e){return Mc(this,e)},omit(e){return Fc(this,e)},partial(...e){return _n(Ra,this,e[0])},exactPartial(...e){return _n(Ta,this,e[0],"exactPartial")},required(...e){return Vc(Da,this,e[0])}});function N(e,t){let r={type:"object",shape:e??{},...g(t)};return new _l(r)}var Ea=d("ZodUnion",(e,t)=>{hr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Qs(e,r,n,o),e.options=t.options});function Ca(e,t){return new Ea({type:"union",options:e,...g(t)})}var bl=d("ZodDiscriminatedUnion",(e,t)=>{Ea.init(e,t),Si.init(e,t)});function Na(e,t,r){return new bl({type:"union",options:t,discriminator:e,...g(r)})}var vl=d("ZodIntersection",(e,t)=>{wi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ea(e,r,n,o)});function zl(e,t){return new vl({type:"intersection",left:e,right:t})}var ka=d("ZodRecord",(e,t)=>{Lt(),$i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ta(e,r,n,o),e.keyType=t.keyType,e.valueType=t.valueType});function Sl(e,t,r){if(!t||!t._zod)return new ka({type:"record",keyType:te(),valueType:e,...g(t)});return new ka({type:"record",keyType:e,valueType:t,...g(r)})}var jr=d("ZodEnum",(e,t)=>{ki.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(n,o,i)=>Ks(e,n,o,i),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(n,o)=>{let i={};for(let s of n)if(r.has(s))i[s]=t.entries[s];else throw Error(`Key ${s} not found in enum`);return new jr({...t,checks:[],...g(o),entries:i})},e.exclude=(n,o)=>{let i={...t.entries};for(let s of n)if(r.has(s))delete i[s];else throw Error(`Key ${s} not found in enum`);return new jr({...t,checks:[],...g(o),entries:i})}});function ae(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new jr({type:"enum",entries:r,...g(t)})}var wl=d("ZodLiteral",(e,t)=>{Ii.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ws(e,r,n,o),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Qe(e,t){return new wl({type:"literal",values:Array.isArray(e)?e:[e],...g(t)})}var $l=d("ZodTransform",(e,t)=>{Lt(),Pi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Xs(e,r,n,o),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new De(e.constructor.name);r.addIssue=(i)=>{if(typeof i==="string")r.issues.push(_e(i,r.value,t));else{let s=i;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=r.value;s.inst??(s.inst=e),r.issues.push(_e(s))}};let o=t.transform(r.value,r);if(o instanceof Promise)return o.then((i)=>(r.value=i,r));return r.value=o,r}});function kl(e){return new $l({type:"transform",transform:e})}var Ra=d("ZodOptional",(e,t)=>{gr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Lr(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ia(e){return new Ra({type:"optional",innerType:e})}var Ta=d("ZodExactOptional",(e,t)=>{Zi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Lr(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Il(e){return new Ta({type:"optional",innerType:e})}var Pl=d("ZodNullable",(e,t)=>{Oi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ra(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Pa(e){return new Pl({type:"nullable",innerType:e})}var Zl=d("ZodDefault",(e,t)=>{Ai.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ia(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ol(e,t){return new Zl({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():qt(t)}})}var Al=d("ZodPrefault",(e,t)=>{Ei.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>sa(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function El(e,t){return new Al({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():qt(t)}})}var Da=d("ZodNonOptional",(e,t)=>{Ci.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>na(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Cl(e,t){return new Da({type:"nonoptional",innerType:e,...g(t)})}var Nl=d("ZodCatch",(e,t)=>{Ni.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>aa(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Rl(e,t){return new Nl({type:"catch",innerType:e,catchValue:typeof t==="function"?t:wn(t)})}var Tl=d("ZodPipe",(e,t)=>{Ri.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ca(e,r,n,o),e.in=t.in,e.out=t.out});function Za(e,t){return new Tl({type:"pipe",in:e,out:t})}var Dl=d("ZodReadonly",(e,t)=>{Ti.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ua(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ll(e){return new Dl({type:"readonly",innerType:e})}var jl=d("ZodLazy",(e,t)=>{Di.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>la(e,r,n,o),e.unwrap=()=>e._zod.def.getter()});function Ml(e){return new jl({type:"lazy",getter:e})}var La=d("ZodCustom",(e,t)=>{Li.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>qs(e,r,n,o)});function Fl(e,t){return Ss(La,e??(()=>!0),t)}function Ul(e,t={}){return ws(La,e,t)}function Bl(e,t){return $s(e,t)}function Jl(e){return kt(We,e)}function Vl(e){return It(qe,e)}function Gl(e){return Pt(Xe,e)}function Kl(e){return Zt(He,e)}import{createHash as Wl}from"crypto";import ja from"path";var Mt="ast-mcp.intelligence.v1",L=te().regex(/^[a-f0-9]{64}$/),ql=te().regex(/^[a-z][a-z0-9-]*:v1:[a-f0-9]{64}$/);function F(e){if(!/^[a-z][a-z0-9-]*$/.test(e))throw TypeError("Identity namespace must be lowercase kebab-case");return te().regex(new RegExp(`^${e}:v1:[a-f0-9]{64}$`),`Identity must use the ${e} namespace`)}var Ft=F("source"),Ut=F("syntax-facts"),Fa=F("chunks"),Ua=F("resolved-relationships"),Om=F("revision-manifest"),Ba=F("dirty-overlay"),Jr=F("repository"),Vr=F("revision"),Am=F("workspace"),Em=F("storage-domain"),Cm=F("generation"),Nm=F("job"),Rm=F("reader-pin"),Tm=F("search-hit"),W=te().trim().min(1);function Ja(e){return ja.posix.isAbsolute(e)||ja.win32.isAbsolute(e)}var Va=te().refine(Ja,"Path must be absolute"),Gr=te().min(1).refine((e)=>!Ja(e),{message:"Repository path must be relative"}).refine((e)=>!e.includes(String.fromCharCode(92))&&!e.includes(String.fromCharCode(0))&&!e.split("/").includes("..")&&!e.split("/").includes("."),{message:"Repository path must use normalized forward-slash segments"}).refine((e)=>e!=="."&&!e.startsWith("./")&&!e.includes("//")&&!e.endsWith("/"),{message:"Repository path must be normalized"});var Dm=Fr.datetime({offset:!0}),Ma=N({column:Ye().int().nonnegative(),line:Ye().int().nonnegative()}),Lm=N({end:Ma,endByte:Ye().int().nonnegative(),start:Ma,startByte:Ye().int().nonnegative()}).superRefine((e,t)=>{if(e.endByte<e.startByte)t.addIssue({code:"custom",message:"endByte must be greater than or equal to startByte",path:["endByte"]});if(e.end.line<e.start.line||e.end.line===e.start.line&&e.end.column<e.start.column)t.addIssue({code:"custom",message:"end position must not precede start position",path:["end"]})}),Ur=Ml(()=>Ca([ml(),Mr(),Fl((e)=>typeof e==="number"&&Number.isFinite(e),"Identity numbers must be finite"),te(),se(Ur),Sl(te(),Ur)])),Xl=te().regex(/^[a-z][a-z0-9-]*$/,"Identity namespace must be lowercase kebab-case"),Hl=N({namespace:Xl,value:Ur}).strict();function Br(e){if(e===null)return"null";if(typeof e==="string")return JSON.stringify(e);if(typeof e==="boolean")return e?"true":"false";if(typeof e==="number"){if(!Number.isFinite(e))throw TypeError("Identity numbers must be finite");return Object.is(e,-0)?"0":JSON.stringify(e)}if(Array.isArray(e))return`[${e.map((r)=>Br(r)).join(",")}]`;let t=e;return`{${Object.keys(t).sort().map((r)=>`${JSON.stringify(r)}:${Br(t[r]??null)}`).join(",")}}`}function Kr(e,t){let r=Hl.parse({namespace:e,value:t}),n=Wl("sha256").update(Br(r.value)).digest("hex");return ql.parse(`${r.namespace}:v1:${n}`)}var Yl=N({contentDigest:L}).strict(),Ql=N({languageId:W,parserFingerprint:L,sourceArtifactId:Ft}).strict(),Bm=Na("documentKind",[N({chunkerFingerprint:L,documentKind:Qe("code"),extractedContentDigest:L,semanticContextDigest:L,syntaxFactsArtifactId:Ut}).strict(),N({chunkerFingerprint:L,documentKind:ae(["markdown","text","rtf","structured"]),extractedContentDigest:L,semanticContextDigest:L,sourceArtifactId:Ft}).strict()]),Jm=N({chunkArtifactId:Fa,dimensions:Ye().int().positive(),dtype:ae(["float32","float16","int8","uint8"]),exactInputDigest:L,modelId:W,modelRevision:W,normalized:Mr(),pooling:ae(["mean","cls","none"]),tokenizerId:W,tokenizerRevision:W}).strict(),Vm=N({environmentFingerprint:L,resolverFingerprint:L,syntaxFactsArtifactId:Ut}).strict();function Ga(e,t){let r=new Set;e.forEach((n,o)=>{if(r.has(n.path))t.addIssue({code:"custom",message:"Artifact entries must have unique repository paths",path:["entries",o,"path"]});r.add(n.path)})}var ep=N({path:Gr,resolvedRelationshipsArtifactId:Ua.nullable(),sourceArtifactId:Ft,syntaxFactsArtifactId:Ut.nullable()}).strict(),Gm=N({dirtyOverlayId:Ba.nullable(),entries:se(ep),repositoryId:Jr,revisionId:Vr}).strict().superRefine((e,t)=>{Ga(e.entries,t)}),tp=N({contentDigest:L.nullable(),path:Gr,status:ae(["added","modified","deleted"])}).strict().superRefine((e,t)=>{if(e.status!=="deleted"!==(e.contentDigest!==null))t.addIssue({code:"custom",message:e.status==="deleted"?"Deleted overlay entries cannot have content":"Added and modified overlay entries require content",path:["contentDigest"]})}),Km=N({baseRevisionId:Vr,checkoutRoot:Va,entries:se(tp),repositoryId:Jr}).strict().superRefine((e,t)=>{Ga(e.entries,t)}),Ka=(e)=>Kr("source",Yl.parse(e)),Wa=(e)=>Kr("syntax-facts",Ql.parse(e));import{stat as ip}from"fs/promises";import{isAbsolute as sp,resolve as Xa}from"path";import{registerDynamicLanguage as ap}from"@ast-grep/napi";var rp=ae(["supported","partial","unsupported"]),np=ae(["tree-sitter","ast-grep","structured-parser","text","custom","none"]),re=N({implementationFingerprint:L.nullable(),limitations:se(W),provider:np,status:rp}).strict().superRefine((e,t)=>{if(e.status==="unsupported"){if(e.provider!=="none"||e.implementationFingerprint!==null)t.addIssue({code:"custom",message:"Unsupported capabilities cannot claim an implementation"});if(e.limitations.length===0)t.addIssue({code:"custom",message:"Unsupported capabilities must explain their limitation",path:["limitations"]});return}if(e.provider==="none"||e.implementationFingerprint===null)t.addIssue({code:"custom",message:"Supported capabilities require an implementation"});if(e.status==="partial"&&e.limitations.length===0)t.addIssue({code:"custom",message:"Partial capabilities must state their limitations",path:["limitations"]});if(e.status==="supported"&&e.limitations.length>0)t.addIssue({code:"custom",message:"Capabilities with limitations must be marked partial",path:["status"]})}),op=Na("mode",[N({mode:Qe("none")}).strict(),N({formats:se(ae(["json","jsonc","yaml","toml","markdown","rtf"])).min(1),mode:Qe("native"),preservesComments:Mr()}).strict(),N({formats:se(ae(["json","jsonc","yaml","toml","markdown","rtf"])).min(1),limitation:W,mode:Qe("text-fallback")}).strict()]),qa=N({callResolution:re,embeddedLanguageIds:se(W),embeddedLanguages:re,exportResolution:re,extensions:se(W),importResolution:re,inheritanceResolution:re,languageId:W,match:re,parse:re,rewrite:re,schemaVersion:Qe(Mt),structuralRead:re,structuredParser:op,symbolExtraction:re}).strict().superRefine((e,t)=>{if(e.embeddedLanguages.status==="unsupported"&&e.embeddedLanguageIds.length>0)t.addIssue({code:"custom",message:"Unsupported embedded languages cannot list language IDs",path:["embeddedLanguageIds"]});if(e.rewrite.status!=="unsupported"&&(e.parse.status==="unsupported"||e.match.status==="unsupported"))t.addIssue({code:"custom",message:"Rewrite support requires parse and match support",path:["rewrite"]});if(e.structuredParser.mode!=="none"&&e.structuralRead.status==="unsupported")t.addIssue({code:"custom",message:"Structured parser behavior requires structural reads",path:["structuredParser"]})});var qr="ast-mcp.ts-js.v1",Oe=(e)=>j(JSON.stringify(e));function Ha(e){let t;try{t=structuredClone(e)}catch{throw TypeError("Dynamic grammar manifest must be cloneable")}if(t.schemaVersion!=="ast-mcp.dynamic-grammars.v1")throw TypeError("Unsupported dynamic grammar manifest version");if(!Array.isArray(t.entries))throw TypeError("Dynamic grammar manifest entries must be an array");if(!/^[a-f0-9]{64}$/.test(t.fingerprint))throw TypeError("Dynamic grammar manifest fingerprint is invalid");if(Oe(t.entries)!==t.fingerprint)throw TypeError("Dynamic grammar manifest fingerprint mismatch");let r=t.entries.map((n)=>{if(!n.descriptor.dynamicAsset)throw TypeError("Dynamic grammar manifest entry requires an asset");return Object.freeze({descriptor:Object.freeze({...n.descriptor,dynamicAsset:Object.freeze({...n.descriptor.dynamicAsset}),extensions:Object.freeze([...n.descriptor.extensions])}),implementation:Object.freeze({...n.implementation})})});return Object.freeze({entries:Object.freeze(r),fingerprint:t.fingerprint,schemaVersion:t.schemaVersion})}function cp(e){return{astGrepLanguage:e.astGrepLanguage,dynamicAsset:null,extensions:e.extensions,grammarFingerprint:Oe({astGrepLanguage:e.astGrepLanguage,extensions:[...e.extensions],grammarVersion:e.grammarVersion,languageId:e.languageId}),grammarVersion:e.grammarVersion,languageId:e.languageId}}var up=we.map(cp),Wr=new WeakMap,lp=(e)=>({callResolution:!1,embeddedLanguages:!1,exportResolution:!1,importResolution:!1,inheritanceResolution:!1,match:e.structuralOperations.match,parse:e.structuralOperations.parse,rewrite:e.structuralOperations.rewrite,structuralRead:e.structuralOperations.structuralRead,symbolExtraction:e.analysis.symbolExtraction}),Ze=(e)=>({implementationFingerprint:null,limitations:[e],provider:"none",status:"unsupported"}),Ya=(e,t)=>({implementationFingerprint:t,limitations:[],provider:e,status:"supported"});class Qa{#t;#e=new Map(up.map((e)=>[e.languageId,e]));#r=new Map(we.map((e)=>[e.languageId,lp(e)]));#n=!1;constructor(e=ap){this.#t=e}get(e){let t=this.#e.get(e);if(!t)throw TypeError(`Unsupported parser language: ${e}`);return t}list(){return[...this.#e.values()].sort((e,t)=>e.languageId.localeCompare(t.languageId))}capabilities(e){let t=this.get(e),r=this.#r.get(e);if(!r)throw TypeError("Missing language implementation");let n=Oe({extractor:qr,languageId:e}),o=Ya("ast-grep",t.grammarFingerprint),i=r.symbolExtraction?Ya("custom",n):Ze("This adapter does not extract code symbols");return this.assertHonest(e,{callResolution:Ze("Call resolution requires an environment-specific resolver"),embeddedLanguageIds:[],embeddedLanguages:Ze("No embedded-language extractor is registered"),exportResolution:Ze("Export resolution requires an environment-specific resolver"),extensions:[...t.extensions],importResolution:Ze("Import resolution requires an environment-specific resolver"),inheritanceResolution:Ze("Inheritance resolution requires an environment-specific resolver"),languageId:e,match:o,parse:o,rewrite:o,schemaVersion:Mt,structuralRead:o,structuredParser:{mode:"none"},symbolExtraction:i})}assertHonest(e,t){let r=qa.parse(t),n=this.#r.get(e);if(!n)throw TypeError("Missing language implementation");let o=[["parse","parse"],["structuralRead","structuralRead"],["match","match"],["rewrite","rewrite"],["symbolExtraction","symbolExtraction"],["importResolution","importResolution"],["exportResolution","exportResolution"],["callResolution","callResolution"],["inheritanceResolution","inheritanceResolution"],["embeddedLanguages","embeddedLanguages"]];for(let[i,s]of o){let a=r[s];if(!n[i]&&a.status!=="unsupported")throw TypeError(`Capability ${String(s)} has no registered implementation`);if(n[i]&&a.status==="unsupported")throw TypeError(`Capability ${String(s)} hides a registered implementation`)}return r}async addDynamic(e,t){if(this.#n)throw TypeError("Dynamic grammars must be configured before parsing");if(this.#e.has(e.languageId))throw TypeError(`Parser language is already registered: ${e.languageId}`);if(!e.dynamicAsset)throw TypeError("Dynamic grammars require a native library asset");if(await pp(e.dynamicAsset),this.#n)throw TypeError("Dynamic grammars must be configured before parsing");if(this.#e.has(e.languageId))throw TypeError(`Parser language is already registered: ${e.languageId}`);let r={expandoChar:e.dynamicAsset.expandoChar??null,languageSymbol:e.dynamicAsset.languageSymbol??null,libraryPath:Xa(e.dynamicAsset.libraryPath),metaVarChar:e.dynamicAsset.metaVarChar??null,sha256:e.dynamicAsset.sha256},n=Oe({astGrepLanguage:e.astGrepLanguage,dynamicAsset:r,extensions:[...e.extensions],grammarVersion:e.grammarVersion,languageId:e.languageId});if(e.grammarFingerprint&&e.grammarFingerprint!==n)throw TypeError("Dynamic grammar fingerprint does not match its asset");if(Wr.has(this.#t))throw TypeError("Dynamic grammars must be configured before parsing");this.#e.set(e.languageId,{...e,dynamicAsset:{...e.dynamicAsset,libraryPath:r.libraryPath},grammarFingerprint:n}),this.#r.set(e.languageId,t)}dynamicManifest(){let e=[...this.#e.values()].filter((r)=>r.dynamicAsset!==null).sort((r,n)=>r.languageId.localeCompare(n.languageId)).map((r)=>{let n=this.#r.get(r.languageId);if(!n)throw TypeError("Missing language implementation");let o=r.dynamicAsset;if(!o)throw TypeError("Missing dynamic grammar asset");let i=Object.freeze({...r,dynamicAsset:Object.freeze({...o}),extensions:Object.freeze([...r.extensions])});return Object.freeze({descriptor:i,implementation:Object.freeze({...n})})}),t=Object.freeze(e);return Ha({entries:t,fingerprint:Oe(t),schemaVersion:"ast-mcp.dynamic-grammars.v1"})}async loadDynamicManifest(e){let t=Ha(e);for(let r of t.entries)await this.addDynamic(r.descriptor,r.implementation)}registerDynamicGrammars(){if(this.#n)return;let e={...on};for(let n of this.#e.values()){if(!n.dynamicAsset)continue;e[n.astGrepLanguage]={extensions:[...n.extensions],libraryPath:Xa(n.dynamicAsset.libraryPath),...n.dynamicAsset.languageSymbol?{languageSymbol:n.dynamicAsset.languageSymbol}:{},...n.dynamicAsset.metaVarChar?{metaVarChar:n.dynamicAsset.metaVarChar}:{},...n.dynamicAsset.expandoChar?{expandoChar:n.dynamicAsset.expandoChar}:{}}}let t=Oe(Object.fromEntries(Object.entries(e).sort(([n],[o])=>n.localeCompare(o)))),r=Wr.get(this.#t);if(r===void 0)this.#t(e),Wr.set(this.#t,t);else if(r!==t)throw TypeError("A different grammar set is already registered in this process");this.#n=!0}}async function pp(e){if(!sp(e.libraryPath))throw TypeError("Dynamic grammar library path must be absolute");if(!/\.(?:dylib|dll|node|so)$/i.test(e.libraryPath))throw TypeError("Dynamic grammar asset must use a native library filename");if(!(await ip(e.libraryPath)).isFile())throw TypeError("Dynamic grammar asset is not a file");let r=new Uint8Array(await Bun.file(e.libraryPath).slice(0,4).arrayBuffer()),n=new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0);if(!(n===2135247942||r[0]===77&&r[1]===90||n===3405691582||n===3199925962||n===3489328638||n===3472551422||n===4277009103||n===4277009102))throw TypeError("Dynamic grammar asset is not a recognized native library");let i=new Bun.CryptoHasher("sha256");if(i.update(await Bun.file(e.libraryPath).arrayBuffer()),i.digest("hex")!==e.sha256)throw TypeError("Dynamic grammar asset fingerprint mismatch")}var et=new Qa;class tt extends Error{code;retryable;constructor(e){super(e.message);this.name="ParserError",this.code=e.code,this.retryable=e.retryable}toJSON(){return{code:this.code,message:this.message,retryable:this.retryable}}}var tc=new Map([["class_declaration","class"],["abstract_class_declaration","class"],["interface_declaration","interface"],["function_declaration","function"],["generator_function_declaration","function"],["method_definition","method"],["method_signature","method"],["type_alias_declaration","type"],["enum_declaration","enum"],["internal_module","namespace"],["module","namespace"]]),Xr=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier"]);function Ae(e,t,r){return j(JSON.stringify([e,t,...r]))}function rc(e){return e.trim().slice(1,-1)}function me(e,t){return e.coordinates.fromAstRange(t.range())}var V=(e)=>String(e.kind());function dp(e,t){for(let r of e.namedChildren())if(t.includes(V(r)))return r;return null}function Bt(e){let t=e.field("name");if(t)return t;return dp(e,["identifier","type_identifier","property_identifier"])}function rt(e){let t=V(e);if(t==="identifier"||t==="shorthand_property_identifier_pattern")return[e];if(t==="pair_pattern"){let r=e.field("value")??e.namedChildren().at(-1);return r?rt(r):[]}if(t==="assignment_pattern"||t==="object_assignment_pattern"){let r=e.field("left")??e.namedChildren()[0];return r?rt(r):[]}if(t==="rest_pattern"){let r=e.field("argument")??e.namedChildren()[0];return r?rt(r):[]}return e.namedChildren().flatMap((r)=>rt(r))}function mp(e){let t=e.parent();while(t){let r=V(t);if(r==="export_statement")return!0;if(r==="program"||r==="class_body")return!1;t=t.parent()}return!1}function hp(e,t,r){let n=tc.get(V(t)),o=t.kind()==="variable_declarator"?rt(t.field("name")??t.namedChildren()[0]??t):n?[Bt(t)].filter((a)=>a!==null):[],i=t.kind()==="variable_declarator"?"variable":n;if(!i||o.length===0)return[];let s=me(e,t);return o.map((a)=>{let l=a.text(),c=r?`${r.qualifiedName}.${l}`:l;return{declarationRange:me(e,a),exported:mp(t),id:Ae(e.sourceDigest,"symbol",[i,c,s.startCoordinate.utf16Offset,s.endCoordinate.utf16Offset]),kind:i,name:l,qualifiedName:c,range:s}})}function gp(e,t){let r=[...t.namedChildren()].reverse().find((c)=>c.kind()==="string");if(!r)return;let n=rc(r.text()),o=t.text(),i=/^import\s+type\b/.test(o),s=t.namedChildren().find((c)=>c.kind()==="import_clause"),a=[];if(!s)a.push({importedName:"*side-effect*",localName:"*side-effect*"});else{let c=s.namedChildren().find((f)=>f.kind()==="identifier");if(c)a.push({importedName:"default",localName:c.text()});let u=s.namedChildren().find((f)=>f.kind()==="namespace_import");if(u){let f=u.namedChildren().find((m)=>m.kind()==="identifier");if(f)a.push({importedName:"*",localName:f.text()})}let p=s.namedChildren().find((f)=>f.kind()==="named_imports");for(let f of p?.namedChildren()??[]){if(f.kind()!=="import_specifier")continue;let m=f.namedChildren().filter((y)=>Xr.has(V(y))),h=m[0]?.text();if(!h)continue;a.push({importedName:h,localName:m.at(-1)?.text()??h})}}let l=me(e,t);for(let c of a)e.imports.push({id:Ae(e.sourceDigest,"import",[n,c.importedName,c.localName,l.startCoordinate.utf16Offset]),importedName:c.importedName,localName:c.localName,range:l,source:n,typeOnly:i})}function yp(e,t){let r=me(e,t),n=[...t.namedChildren()].reverse().find((c)=>c.kind()==="string"),o=n?rc(n.text()):null,i=/^export\s+type\b/.test(t.text()),s=t.namedChildren().find((c)=>[...tc.keys(),"lexical_declaration","variable_declaration"].includes(V(c))),a=[];if(s)if(["lexical_declaration","variable_declaration"].includes(V(s)))for(let c of s.namedChildren()){let u=Bt(c)?.text();if(u)a.push({exportedName:u,localName:u})}else{let c=Bt(s)?.text();if(c)a.push({exportedName:c,localName:c})}let l=t.namedChildren().find((c)=>c.kind()==="export_clause");for(let c of l?.namedChildren()??[]){let u=c.namedChildren().filter((f)=>Xr.has(V(f))),p=u[0]?.text();if(!p)continue;a.push({exportedName:u.at(-1)?.text()??p,localName:p})}if(/^export\s+default\b/.test(t.text()))a.push({exportedName:"default",localName:a[0]?.localName??null});if(/^export\s+\*/.test(t.text()))a.push({exportedName:"*",localName:null});for(let c of a)e.exports.push({exportedName:c.exportedName,id:Ae(e.sourceDigest,"export",[c.exportedName,c.localName,o,r.startCoordinate.utf16Offset]),localName:c.localName,range:r,source:o,typeOnly:i})}function xp(e,t,r){let n=t.field("function")??t.namedChildren()[0]??null;if(!n)return;let o=me(e,t);e.calls.push({callee:n.text(),enclosingSymbolId:r?.id??null,id:Ae(e.sourceDigest,"call",[n.text(),o.startCoordinate.utf16Offset]),range:o})}function ec(e,t,r,n,o){for(let i of t.namedChildren()){let s=me(e,i);n.push({id:Ae(e.sourceDigest,o,[r?.id??null,i.text(),s.startCoordinate.utf16Offset]),range:s,sourceSymbolId:r?.id??null,targetName:i.text()})}}function _p(e){if(e.kind()==="type_identifier")return"type";let t=e.parent();if(!t)return"read";if(["variable_declarator","required_parameter","optional_parameter"].includes(V(t))&&Bt(t)?.id()===e.id())return"write";return t.field("left")?.id()===e.id()?"write":"read"}function nc(e,t,r,n){if(e.nodes.length>=e.maxNodes){if(!e.truncated)e.truncated=!0,e.diagnostics.push({code:"truncated",message:"Syntax node limit reached",range:me(e,t),severity:"warning"});return null}let o=me(e,t),i=rn(e.sourceDigest,V(t),o.startCoordinate.utf16Offset,o.endCoordinate.utf16Offset),s={childIds:[],id:i,kind:V(t),named:t.isNamed(),parentId:r,range:o};if(e.nodes.push(s),t.kind()==="ERROR"||t.kind()==="error")e.diagnostics.push({code:"parse-error",message:"Parser recovered from malformed source",range:o,severity:"error"});else if(V(t).startsWith("MISSING"))e.diagnostics.push({code:"missing-node",message:"Parser inserted a missing syntax node",range:o,severity:"error"});let a=hp(e,t,n);e.symbols.push(...a);let l=a[0]??n;if(t.kind()==="import_statement")gp(e,t);if(t.kind()==="export_statement")yp(e,t);if(t.kind()==="call_expression")xp(e,t,l);if(t.kind()==="extends_clause")ec(e,t,l,e.inheritance,"inheritance");if(t.kind()==="implements_clause")ec(e,t,l,e.implementations,"implementation");if(Xr.has(V(t)))e.references.push({enclosingSymbolId:l?.id??null,id:Ae(e.sourceDigest,"reference",[t.text(),o.startCoordinate.utf16Offset]),name:t.text(),range:o,role:_p(t)});for(let c of t.namedChildren()){let u=nc(e,c,i,l);if(u)s.childIds.push(u)}return i}function de(e){return e.sort((t,r)=>t.range.startCoordinate.utf16Offset-r.range.startCoordinate.utf16Offset||t.range.endCoordinate.utf16Offset-r.range.endCoordinate.utf16Offset)}function oc(e,t=et){if(e.maxNodes!==void 0&&(!Number.isFinite(e.maxNodes)||!Number.isInteger(e.maxNodes)||e.maxNodes<1))throw new tt({code:"invalid-request",message:"Parser maxNodes must be a finite positive integer",retryable:!1});let r=j(e.source),n;try{n=t.get(e.languageId)}catch(f){throw new tt({code:"invalid-language",message:f instanceof Error?f.message:"Unsupported language",retryable:!1})}let o=e.grammarVersion?j(JSON.stringify([n.grammarFingerprint,e.grammarVersion])):n.grammarFingerprint,i=j(JSON.stringify([e.languageId,e.extractorVersion??qr])),s=j(JSON.stringify([o,i])),a=Ka({contentDigest:r}),l=Wa({languageId:e.languageId,parserFingerprint:s,sourceArtifactId:a});t.registerDynamicGrammars();let c=fp(n.astGrepLanguage,e.source).root(),u={calls:[],coordinates:new ve(e.source),diagnostics:[],exports:[],implementations:[],imports:[],inheritance:[],maxNodes:e.maxNodes??250000,nodes:[],references:[],sourceDigest:r,symbols:[],truncated:!1},p=nc(u,c,null,null);if(!p)throw new tt({code:"worker-error",message:"Parser produced no root syntax node",retryable:!1});return{calls:de(u.calls),diagnostics:de(u.diagnostics),exports:de(u.exports),extractorFingerprint:i,grammarFingerprint:o,implementations:de(u.implementations),imports:de(u.imports),inheritance:de(u.inheritance),languageId:e.languageId,nodes:u.nodes,parserFingerprint:s,partial:u.diagnostics.length>0,references:de(u.references),rootNodeId:p,schemaVersion:"ast-mcp.syntax-facts.v1",sourceArtifactId:a,sourceDigest:r,symbols:de(u.symbols),syntaxFactsArtifactId:l}}import{parse as ic}from"@ast-grep/napi";function Hr(e,t,r){return e.start.index-t.start.index||e.end.index-t.end.index||(r?r.left.localeCompare(r.right):0)}function bp(e,t,r,n){let o=n.get(t);n.registerDynamicGrammars();let i=ic(o.astGrepLanguage,e).root(),s=new ve(e),a=i.findAll(r).sort((c,u)=>Hr(c.range(),u.range(),{left:String(c.kind()),right:String(u.kind())}));return{matches:a.map((c,u)=>{let p=s.fromAstRange(c.range());return{id:j(JSON.stringify([o.grammarFingerprint,j(e),r,p.startCoordinate.utf16Offset,p.endCoordinate.utf16Offset])),kind:String(c.kind()),ordinal:u,range:p,text:c.text()}}),nodes:a}}function Yr(e,t,r,n=et){return bp(e,t,r,n).matches}function vp(e,t){return e.replace(/\$\$\$([A-Z_][A-Z0-9_]*)|\$([A-Z_][A-Z0-9_]*)/g,(r,n,o)=>{if(n){let i=t.getMultipleMatches(n),s=i[0],a=i.at(-1);if(!s||!a)return"";return t.getRoot().root().text().slice(s.range().start.index,a.range().end.index)}if(!o)return r;return t.getMatch(o)?.text()??r})}function sc(e,t,r,n=et){let o=n.get(t);n.registerDynamicGrammars();let i=ic(o.astGrepLanguage,e).root(),s=new ve(e),a=[],l=[],c=[];for(let[p,f]of r.entries()){if(!Number.isInteger(f.expectedMatches)||f.expectedMatches<0)throw TypeError("Expected match count must be a nonnegative integer");let m=i.findAll(f.pattern).sort((h,y)=>Hr(h.range(),y.range()));if(m.length!==f.expectedMatches)throw RangeError("Structural operation "+p+" expected "+f.expectedMatches+" matches but found "+m.length);if(Array.isArray(f.replacement)&&f.replacement.length!==m.length)throw RangeError(`Structural operation ${p} requires one replacement per match`);m.forEach((h,y)=>{let b=s.fromAstRange(h.range()),S={id:j(JSON.stringify([o.grammarFingerprint,j(e),p,f.pattern,b.startCoordinate.utf16Offset,b.endCoordinate.utf16Offset])),kind:String(h.kind()),ordinal:y,range:b,text:h.text()},E=Array.isArray(f.replacement)?f.replacement[y]??"":f.replacement,X=vp(E,h);a.push(S),l.push({matchId:S.id,range:b,replacement:X}),c.push({endPos:b.endCoordinate.utf16Offset,insertedText:X,startPos:b.startCoordinate.utf16Offset})})}let u=l.map((p,f)=>({edit:p,native:c[f]})).sort((p,f)=>p.edit.range.startCoordinate.utf16Offset-f.edit.range.startCoordinate.utf16Offset||p.edit.range.endCoordinate.utf16Offset-f.edit.range.endCoordinate.utf16Offset);for(let p=1;p<u.length;p+=1){let f=u[p-1]?.edit,m=u[p]?.edit;if(f&&m&&m.range.startCoordinate.utf16Offset<f.range.endCoordinate.utf16Offset)throw RangeError("Structural rewrite matches overlap")}return{edits:u.map((p)=>p.edit),matches:[...a].sort((p,f)=>p.range.startCoordinate.utf16Offset-f.range.startCoordinate.utf16Offset||p.range.endCoordinate.utf16Offset-f.range.endCoordinate.utf16Offset),source:i.commitEdits(u.map((p)=>{if(!p.native)throw TypeError("Missing native edit");return p.native}))}}import he from"path";function ce(e,t){return he.relative(e,t).split(he.sep).join("/")}function I(e){if(e?.aborted)throw e.reason}function nt(e,t,r=!1){return e.facts.symbols.map((n)=>({exported:n.exported,kind:n.kind,name:n.name,path:ce(t,e.path),qualifiedName:n.qualifiedName,range:{endLine:n.range.end.line+1,startLine:n.range.start.line+1},...r?{source:e.source.slice(n.range.startCoordinate.utf16Offset,n.range.endCoordinate.utf16Offset)}:{}}))}function cc(e,t){return e.facts.symbols.filter((r)=>r.name===t||r.qualifiedName===t||r.qualifiedName.endsWith(`.${t}`))}function zp(e,t,r,n,o=!1,i){I(i);let s=new Map(Jt(e,i,(c)=>c.facts.symbols.map((u)=>(I(i),[u.id,u.qualifiedName])))),a=new Set(Jt(e,i,(c)=>cc(c,r).map((u)=>(I(i),u.id)))),l=[];for(let c of e){I(i);for(let u of c.facts.calls){if(I(i),!(n==="in"?u.callee===r||u.callee.endsWith(`.${r}`):u.enclosingSymbolId!==null&&a.has(u.enclosingSymbolId)))continue;l.push({callee:u.callee,caller:u.enclosingSymbolId===null?null:s.get(u.enclosingSymbolId)??null,path:ce(t,c.path),...o?{range:{endLine:u.range.end.line+1,startLine:u.range.start.line+1}}:{line:u.range.start.line+1}})}}return l.sort((c,u)=>c.path.localeCompare(u.path)||(c.line??c.range?.startLine??0)-(u.line??u.range?.startLine??0)||c.callee.localeCompare(u.callee))}function ac(e,t,r,n,o,i,s){let a=new Map,l=[r],c=new Set;for(let u=0;u<o&&l.length>0;u+=1){let p=new Set;for(let f of l.sort()){if(I(s),c.has(f))continue;c.add(f);for(let m of zp(e,t,f,n,i,s)){I(s),a.set(JSON.stringify(m),m);let h=n==="out"?m.callee:m.caller;if(h&&!c.has(h))p.add(h)}}l=[...p]}return[...a.values()]}function Sp(e,t){if(Buffer.byteLength(e)<=t)return e;let r="",n=0;for(let o of e){let i=Buffer.byteLength(o);if(n+i>t)break;r+=o,n+=i}return r}function T(e,t){let r=t.limit??t.top_k??200,n=t.budget??Number.POSITIVE_INFINITY,o=[],i=2;for(let s of e.slice(0,r)){let a=Buffer.byteLength(JSON.stringify(s)),l=o.length===0?0:1;if(i+a+l>n)break;o.push(s),i+=a+l}return{items:o,total:e.length,truncated:o.length<e.length}}function wp(e,t){let r=he.posix.normalize(e);if(he.posix.extname(r))return t.filter((n)=>n===r);return t.filter((n)=>n===r||n.replace(/\.[^./]+$/u,"")===r||n.startsWith(`${r}/index.`))}function $p(e,t){let r=e.indexOf("*");if(r<0)return e;return`${e.slice(0,r)}${t}${e.slice(r+1)}`}function kp(e,t){return t.flatMap((r)=>{if(!r.hasWildcard)return e===r.prefix?r.targets:[];if(!e.startsWith(r.prefix)||!e.endsWith(r.suffix))return[];let n=r.prefix.length,o=e.length-r.suffix.length;if(o<n)return[];let i=e.slice(n,o);return r.targets.map((s)=>$p(s,i))})}async function Ip(e,t,r,n=[]){let o=e.map((a)=>ce(t,a.path)).sort(),i=e.flatMap((a)=>{I(r);let l=ce(t,a.path);return[...a.facts.imports.map((c)=>({from:l,source:c.source})),...a.facts.exports.filter((c)=>c.source!==null).map((c)=>({from:l,source:c.source}))]}),s=new Map;for(let a of i){I(r);let l=a.source.startsWith(".")?[he.posix.normalize(he.posix.join(he.posix.dirname(a.from),a.source))]:kp(a.source,n),c=[...new Set(l.flatMap((u)=>wp(u,o)))].sort();if(c.length===0){let u={ambiguous:!1,external:!0,from:a.from,to:a.source};s.set(JSON.stringify(u),u);continue}for(let u of c){let p={ambiguous:c.length>1,external:!1,from:a.from,to:u};s.set(JSON.stringify(p),p)}}return[...s.values()].sort((a,l)=>a.from.localeCompare(l.from)||a.to.localeCompare(l.to))}function Pp(e,t,r){let n=new Map;for(let u of e){if(u.external)continue;let p=n.get(u.from)??[];if(!p.includes(u.to))p.push(u.to);n.set(u.from,p.sort())}let o=new Map,i=[],s=new Map,a=new Set,l=(u)=>{let p=u.slice(0,-1),m=p.map((h,y)=>[...p.slice(y),...p.slice(0,y)]).map((h)=>h.join(" -> ")).sort()[0];return`${m} -> ${m?.split(" -> ")[0]??""}`},c=(u)=>{I(r),o.set(u,"active"),s.set(u,i.length),i.push(u);for(let p of n.get(u)??[]){if(a.size>t)break;let f=o.get(p);if(f==="active"){let m=s.get(p);a.add(l([...i.slice(m),p]))}else if(f!=="done")c(p)}i.pop(),s.delete(u),o.set(u,"done")};for(let u of[...n.keys()].sort()){if(a.size>t)break;if(!o.has(u))c(u)}return{cycles:[...a].sort().slice(0,t),truncated:a.size>t}}function Jt(e,t,r){let n=[];for(let o of e)I(t),n.push(...r(o));return n}async function uc(e,t,r,n,o,i){if(e==="squeeze"){I(i);let v=(t.text??t.query??"").replace(/\s+/g," ").trim(),_=t.budget??8000,w=Sp(v,_);return{schema:"ast-mcp.squeeze.v1",text:w,truncated:w!==v}}if(e==="run"&&t.write)throw Object.assign(Error("run write mode is replaced by hash-guarded file_patch with patchStrategy=ast"),{code:"use_file_patch",retryable:!0,suggestedNextCall:"file_hash then file_patch"});let s=`ast-mcp.${e}.v1`;if(e==="map"||e==="digest"){let x=Jt(r,i,(_)=>[{diagnostics:_.facts.diagnostics,language:_.facts.languageId,partial:_.facts.partial,path:ce(n,_.path),symbols:nt(_,n).slice(0,t.max_members??(e==="digest"?50:200))}]),v=T(x,t);return{files:v.items,schema:s,total:v.total,truncated:v.truncated}}if(e==="show"){let x=new Set(t.symbols??(t.target?[t.target]:[])),v=r.flatMap((_)=>(I(i),nt(_,n,!0))).filter((_)=>x.size===0||x.has(_.name)||x.has(_.qualifiedName));return{schema:s,...T(v,t)}}if(e==="surface")return{schema:s,...T(r.flatMap((x)=>(I(i),nt(x,n))).filter((x)=>x.exported),t)};if(e==="implements"){let x=t.target??"",v=Jt(r,i,(_)=>[..._.facts.implementations,..._.facts.inheritance].filter((w)=>w.targetName===x||w.targetName.endsWith(`.${x}`)).map((w)=>({path:ce(n,_.path),range:w.range,target:w.targetName})));return{schema:s,...T(v,t)}}if(e==="search"||e==="find_related"){let x=(t.query??t.target??t.path??"").toLowerCase(),v=r.flatMap((_)=>(I(i),nt(_,n,!0))).filter((_)=>_.name.toLowerCase().includes(x)||_.qualifiedName.toLowerCase().includes(x)||_.source?.toLowerCase().includes(x)).map(({source:_,...w})=>({...w,snippet:_?.slice(0,1000)}));return{schema:s,...T(v,t)}}if(e==="run"){if(!t.pattern)throw Error("run requires pattern");let x=[];for(let v of r){if(I(i),!t.rewrite){x.push(...Yr(v.source,v.facts.languageId,t.pattern).map((ge)=>({...ge,path:ce(n,v.path)}))),I(i);continue}I(i);let _=Yr(v.source,v.facts.languageId,t.pattern);I(i);let w=sc(v.source,v.facts.languageId,[{expectedMatches:_.length,pattern:t.pattern,replacement:t.rewrite}]);I(i),x.push(...w.edits.map((ge)=>({...ge,path:ce(n,v.path)})))}return{schema:s,...T(x,t)}}let a=await Ip(r,n,i,o),l=a.filter((x)=>(I(i),(!t.hide_external||!x.external)&&(!t.hide_ambiguous||!x.ambiguous)));if(e==="graph")return{schema:s,...T(l,t)};if(e==="cycles"){let x=t.limit??t.top_k??200;return{...Pp(l,x,i),schema:s}}if(e==="deps"||e==="reverse_deps"){let x=t.file??t.path,v=x?ce(n,he.resolve(n,x)):"",_=l.filter((w)=>e==="deps"?w.from===v:w.to===v);return{schema:s,...T(_,t)}}let c=t.target??"",u=t.detail==="full",p=t.direct?1:t.depth??1,f=ac(r,n,c,"in",p,u,i),m=ac(r,n,c,"out",p,u,i);if(e==="callers")return{schema:s,...T(f,t)};if(e==="callees")return{schema:s,...T(m,t)};if(e==="trace")return{callees:T(m,t),callers:T(f,t),depth:p,schema:s,target:c};let h=a.filter((x)=>(I(i),x.to.includes(c))),y=[...f,...h].filter((x)=>(I(i),("path"in x)&&/(?:^|\/)(?:test|tests|__tests__)(?:\/|$)|\.(?:test|spec)\./.test(x.path)));if(e==="impact")return{callees:T(m,t),callers:T(f,t),dependents:T(h,t),schema:s,target:c,tests:T(y,t)};let b=r.flatMap((x)=>(I(i),cc(x,c).flatMap(()=>(I(i),nt(x,n,!0))))).filter((x)=>x.name===c||x.qualifiedName.endsWith(`.${c}`)),S=t.budget??32000,E={callees:[],callers:[],definitions:[],schema:s,target:c,truncated:!1},X=[...b.map((x)=>["definitions",x]),...f.map((x)=>["callers",x]),...m.map((x)=>["callees",x])];for(let[x,v]of X){I(i);let _={...E,[x]:[...E[x],v]};if(Buffer.byteLength(JSON.stringify(_))>S){E.truncated=!0;break}E[x].push(v)}return E}var Qr=globalThis;Qr.onmessage=async({data:e})=>{try{let t=e.kind==="compiler-config"?Bun.JSONC.parse(e.source):e.kind==="parse"?oc({languageId:e.languageId,source:e.source,maxNodes:1e5}):await uc(e.name,e.input,e.files,e.root,e.aliases),r=Buffer.byteLength(JSON.stringify(t));if(r>16777216)throw Object.assign(Error("Parsed data exceeds the request byte limit; narrow paths, glob, or scan_limit"),{code:"intelligence_budget_exceeded",retryable:!0});Qr.postMessage({ok:!0,value:t,bytes:r})}catch(t){let r=t;Qr.postMessage({ok:!1,error:{code:r.code??"worker_error",message:r.message??"Code intelligence worker failed",retryable:r.retryable??!1}})}};
|
|
59
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of e.seen.entries()){let a=s[1];if(t===s[0]){i(s);continue}if(e.external){let c=e.external.registry.get(s[0])?.id;if(t!==s[0]&&c){i(s);continue}}if(e.metadataRegistry.get(s[0])?.id){i(s);continue}if(a.cycle){i(s);continue}if(a.count>1){if(e.reused==="ref")i(s)}}if(e.external)e.sharedDefsExtractedFor=e.external}function Zs(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let n of t){if(!n||typeof n!=="object")return;Zs(n);let o=Object.keys(n);if(o.length!==1||o[0]!=="type")return;let i=n.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!=="string")return;if(!r.includes(s))r.push(s)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var Os=new Set(["type","properties","required","additionalProperties"]),Is=["oneOf","anyOf"];function Ps(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function Ar(e){let t=[];for(let i of e){if(typeof i!=="object"||i.type!=="object")return null;for(let s in i)if(!Os.has(s))return null;t.push(i)}let r={},n=new Set;for(let i of t){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let a=[];for(let c of t){let u=c.properties?.[s]??Ps(c);if(u===null||u===void 0)continue;if(!a.some((p)=>JSON.stringify(p)===JSON.stringify(u)))a.push(u)}let l=a.length===1?a[0]:Ar(a)??{allOf:a};G(r,s,l)}for(let s of i.required??[])n.add(s)}let o={type:"object",properties:r};if(n.size)o.required=[...n];if(t.every((i)=>i.additionalProperties===!1))o.additionalProperties=!1;else{let i=[];for(let s of t){let a=Ps(s);if(a&&!i.some((l)=>JSON.stringify(l)===JSON.stringify(a)))i.push(a)}if(i.length===1)o.additionalProperties=i[0];else if(i.length>1)o.additionalProperties={allOf:i}}return o}function Ou(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let o of Os)if(o in e)return;let r=t.filter((o)=>Is.some((i)=>Array.isArray(o[i]))),n=null;if(!r.length)n=Ar(t);else{let o=r[0],i=Is.find((l)=>Array.isArray(o[l]));if(Object.keys(o).length!==1)return;let s=t.filter((l)=>l!==o),a=o[i].map((l)=>Ar([...s,l]));if(a.some((l)=>!l))return;n={[i]:a}}if(!n)return;delete e.allOf,Ve(e,n)}function Nr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let n=(a)=>{let l=e.seen.get(a);if(l.ref===null)return;let c=l.def??l.schema,u={...c},p=l.ref;if(l.ref=null,p){n(p);let m=e.seen.get(p),h=m.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))c.allOf=c.allOf??[],c.allOf.push(h);else Ve(c,h);if(Ve(c,u),a._zod.parent===p)for(let b in c){if(b==="$ref"||b==="allOf")continue;if(!(b in u))delete c[b]}if(h.$ref&&m.def)for(let b in c){if(b==="$ref"||b==="allOf")continue;if(b in m.def&&JSON.stringify(c[b])===JSON.stringify(m.def[b]))delete c[b]}}let f=a._zod.parent;if(f&&f!==p){n(f);let m=e.seen.get(f);if(m?.schema.$ref){if(c.$ref=m.schema.$ref,m.def)for(let h in c){if(h==="$ref"||h==="allOf")continue;if(h in m.def&&JSON.stringify(c[h])===JSON.stringify(m.def[h]))delete c[h]}}}e.override({zodSchema:a,jsonSchema:c,path:l.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let a of[...e.seen.entries()].reverse())n(a[0]);if(e.target!=="openapi-3.0")for(let a of e.seen.entries())Zs(a[1].def??a[1].schema);for(let a of e.deferred)a();if(e.intersections.length){let a=new Map;for(let l of e.seen.values())for(let c of[l.schema,l.def]){let u=c?.allOf;if(!Array.isArray(u))continue;let p=a.get(u);if(p)p.push(c);else a.set(u,[c])}for(let l of e.intersections)for(let c of a.get(l)??[])Ou(c)}}let o={};if(e.target==="draft-2020-12")o.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")o.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")o.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");o.$id=e.external.uri(a)}Ve(o,r.defId?r.schema:r.def??r.schema);let i=e.metadataRegistry.get(t)?.id;if(i!==void 0&&o.id===i)delete o.id;let s=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let a of e.seen.entries()){let l=a[1];if(l.def&&l.defId){if(l.def.id===l.defId)delete l.def.id;G(s,l.defId,l.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")o.$defs=s;else o.definitions=s;try{let a=JSON.parse(JSON.stringify(o));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:Ge(t,"input",e.processors),output:Ge(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function D(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let n=e._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return D(n.element,r);if(n.type==="set")return D(n.valueType,r);if(n.type==="lazy")return D(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault"||n.type==="catch")return D(n.innerType,r);if(n.type==="intersection")return D(n.left,r)||D(n.right,r);if(n.type==="record"||n.type==="map")return D(n.keyType,r)||D(n.valueType,r);if(n.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return D(n.in,r)||D(n.out,r)}if(n.type==="object"){for(let o in n.shape)if(D(n.shape[o],r))return!0;return!1}if(n.type==="union"){for(let o of n.options)if(D(o,r))return!0;return!1}if(n.type==="tuple"){for(let o of n.items)if(D(o,r))return!0;if(n.rest&&D(n.rest,r))return!0;return!1}return!1}var As=(e,t={})=>(r)=>{let n=Er({...r,processors:t});return A(e,n),Cr(n,e),Nr(n,e)},Ge=(e,t,r={})=>(n)=>{let{libraryOptions:o,target:i}=n??{},s=Er({...o??{},target:i,io:t,processors:r});return A(e,s),Cr(s,e),Nr(s,e)};var Ie=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},Pe=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},Es=(e,t)=>{Ie(e,"minimum",t),Pe(e,"maximum",t)},Ts=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},Ds=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},Ls=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},js=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},Cs=(e,t)=>Ie(e,"minimum",t.minimum),Ns=(e,t)=>Pe(e,"maximum",t.maximum),Rs=(e)=>(t,r)=>{js(t,r.format);let[n,o]=e[r.format];Ie(t,"minimum",n),Pe(t,"maximum",o)},Au={greater_than:(e,t)=>Ie(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>Pe(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>Ts(e,t.value),number_format:Rs(it),bigint_format:Rs(Ht),min_length:Cs,max_length:Ns,length_equals:(e,t)=>Es(e,t.length),min_size:Cs,max_size:Ns,size_equals:(e,t)=>Es(e,t.size),string_format:(e,t)=>{if(js(e,t.format),t.pattern)Ds(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>Ls(e,t.mime)};function K(e){let t={},r=e._zod.def,n=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let i of n)Au[i._zod.def.check]?.(t,i._zod.def);let o=e._zod.bag;if(o.minimum!==void 0)Ie(t,"minimum",o.minimum);if(o.exclusiveMinimum!==void 0)Ie(t,"exclusiveMinimum",o.exclusiveMinimum);if(o.maximum!==void 0)Pe(t,"maximum",o.maximum);if(o.exclusiveMaximum!==void 0)Pe(t,"exclusiveMaximum",o.exclusiveMaximum);if(o.multipleOf!==void 0)Ts(t,o.multipleOf);if(o.format!==void 0){if(t.format??(t.format=o.format),o.format.includes("int"))t.isInt=!0}if(o.mime)Ls(t,o.mime);for(let i of o.patterns??[])Ds(t,i);return t}var Eu={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Cu=new Map([[dr,ro],[vt,no]]),Ms=(e)=>Cu.get(e)??e,Fs=(e,t,r,n)=>{let o=r;o.type="string";let{minimum:i,maximum:s,format:a,patterns:l,contentEncoding:c,laxFormat:u}=K(e);if(typeof i==="number")o.minLength=i;if(typeof s==="number")o.maxLength=s;if(a){if(o.format=Eu[a]??a,o.format==="")delete o.format;if(a==="time"||u)delete o.format}if(c)o.contentEncoding=c;if(l&&l.size>0){let p=[...l].map(Ms);if(p.length===1)o.pattern=p[0].source;else if(p.length>1)o.allOf=[...p.map((f)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))]}},Us=(e,t,r,n)=>{let o=r,{minimum:i,maximum:s,multipleOf:a,exclusiveMaximum:l,exclusiveMinimum:c,isInt:u}=K(e);o.type=u?"integer":"number";let p=typeof c==="number"&&c>=(i??Number.NEGATIVE_INFINITY),f=typeof l==="number"&&l<=(s??Number.POSITIVE_INFINITY),m=t.target==="draft-04"||t.target==="openapi-3.0";if(p)if(m)o.minimum=c,o.exclusiveMinimum=!0;else o.exclusiveMinimum=c;else if(typeof i==="number")o.minimum=i;if(f)if(m)o.maximum=l,o.exclusiveMaximum=!0;else o.exclusiveMaximum=l;else if(typeof s==="number")o.maximum=s;if(a){let h=new Set;for(let S of a)if(Number.isFinite(S)&&S!==0)h.add(Math.abs(S));else ie(e,t,o,n,`A multipleOf divisor of ${S} cannot be represented in JSON Schema`);let[y,...b]=h;if(y!==void 0)o.multipleOf=y;if(b.length)o.allOf=[...o.allOf??[],...b.map((S)=>({multipleOf:S}))]}},Bs=(e,t,r,n)=>{r.type="boolean"};var Js=(e,t,r,n)=>{if(t.target==="openapi-3.0")r.type="string",r.nullable=!0,r.enum=[null];else r.type="null"};var Vs=(e,t,r,n)=>{r.not={}};var Gs=(e,t,r,n)=>{};var Ks=(e,t,r,n)=>{let o=e._zod.def,i=Ce(o.entries);if(i.length===0){r.not={};return}if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";r.enum=i},Ws=(e,t,r,n)=>{let o=e._zod.def;if(o.values.length===0){r.not={};return}let i=[];for(let s of o.values)if(s===void 0){if(ie(e,t,r,n,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s==="bigint"){if(ie(e,t,r,n,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length===0);else if(i.length===1){let s=i[0];if(r.type=s===null?"null":typeof s,t.target==="draft-04"||t.target==="openapi-3.0")r.enum=[s];else r.const=s}else{if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";if(i.every((s)=>typeof s==="boolean"))r.type="boolean";if(i.every((s)=>s===null))r.type="null";r.enum=i}};var qs=(e,t,r,n)=>{ie(e,t,r,n,"Custom types cannot be represented in JSON Schema")};var Xs=(e,t,r,n)=>{ie(e,t,r,n,"Transforms cannot be represented in JSON Schema")};var Hs=(e,t,r,n)=>{let o=r,i=e._zod.def,{minimum:s,maximum:a}=K(e);if(typeof s==="number")o.minItems=s;if(typeof a==="number")o.maxItems=a;o.type="array",o.items=A(i.element,t,{...n,path:[...n.path,"items"]})};function Rt(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return Rt(t.out);if(t.type==="catch")return Rt(t.innerType);return e._zod.optin}var Ys=(e,t,r,n)=>{let o=r,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&ie(e,t,o,n,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(let c in s)G(o.properties,c,A(s[c],t,{...n,path:[...n.path,"properties",c]}));let l=[];for(let c of Object.keys(s)){let u=i.shape[c];if(t.io==="input"?Rt(u)===void 0:u._zod.optout===void 0)l.push(c)}if(l.length>0)o.required=l;if(i.catchall?._zod.def.type==="never")o.additionalProperties=!1;else if(!i.catchall){if(t.io==="output")o.additionalProperties=!1}else if(i.catchall)o.additionalProperties=A(i.catchall,t,{...n,path:[...n.path,"additionalProperties"]})},Qs=(e,t,r,n)=>{let o=e._zod.def,i=o.inclusive===!1,s=o.options.map((a,l)=>A(a,t,{...n,path:[...n.path,i?"oneOf":"anyOf",l]}));if(i)r.oneOf=s;else r.anyOf=s},ea=(e,t,r,n)=>{let o=e._zod.def,i=A(o.left,t,{...n,path:[...n.path,"allOf",0]}),s=A(o.right,t,{...n,path:[...n.path,"allOf",1]}),a=(c)=>("allOf"in c)&&Object.keys(c).length===1,l=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];r.allOf=l,t.intersections.push(l)};function Rr(e,t,r){if(t.$ref){if(r.has(t))return t;r.add(t);let h=e.get(t)?.def;if(!h)return t;let y=Rr(e,h,r);return y===h?t:y}for(let h of["anyOf","oneOf"]){let y=t[h];if(!Array.isArray(y))continue;let b=y.map((S)=>Rr(e,S,r));if(b.some((S,E)=>S!==y[E]))t={...t,[h]:b}}let n=Array.isArray(t.type)?t.type:[t.type],o=!n.includes("string")&&n.some((h)=>h==="number"||h==="integer"),i=t.enum??(t.const!==void 0?[t.const]:void 0);if(!o&&!i?.some((h)=>typeof h==="number"))return t;let{minimum:s,maximum:a,exclusiveMinimum:l,exclusiveMaximum:c,multipleOf:u,format:p,id:f,...m}=t;if(m.enum)m.enum=m.enum.map((h)=>typeof h==="number"?String(h):h);else if(typeof m.const==="number")m.const=String(m.const);if(!o)return m;if(m.type="string",!i)m.pattern=(n.includes("number")?Le:sr).source;return m}var Tr=new WeakMap;function Nu(e){let t=new Map;for(let n of e.seen.values())if(n.def&&!t.has(n.schema))t.set(n.schema,n);let r=new Map;for(let n of Tr.get(e)??[]){let o=e.seen.get(n),i=(o?.def??o?.schema)?.propertyNames;if(!i||i===!0||r.has(i))continue;let s=Rr(t,i,new Set);if(s!==i)r.set(i,s)}if(!r.size)return;for(let n of e.seen.values())for(let o of[n.schema,n.def]){let i=o&&r.get(o.propertyNames);if(i)o.propertyNames=i}}var ta=(e,t,r,n)=>{let o=r,i=e._zod.def;o.type="object";let s=i.keyType,a=K(s).patterns;if(i.mode==="loose"&&a&&a.size>0){let u=A(i.valueType,t,{...n,path:[...n.path,"patternProperties","*"]});o.patternProperties={};for(let p of a)G(o.patternProperties,Ms(p).source,u)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){o.propertyNames=A(i.keyType,t,{...n,path:[...n.path,"propertyNames"]});let u=Tr.get(t);if(!u)u=[],Tr.set(t,u),t.deferred.push(()=>Nu(t));u.push(e)}o.additionalProperties=A(i.valueType,t,{...n,path:[...n.path,"additionalProperties"]})}let l=s._zod.values,c=t.io==="input"&&Rt(i.valueType)!==void 0;if(l&&!i.partial&&!c){let u=[...l].filter((p)=>typeof p==="string"||typeof p==="number");if(u.length>0)o.required=u.map(String)}},ra=(e,t,r,n)=>{let o=e._zod.def,i=A(o.innerType,t,n),s=t.seen.get(e);if(t.target==="openapi-3.0")s.ref=o.innerType,r.nullable=!0;else r.anyOf=[i,{type:"null"}]},na=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType},Dr=Symbol();function oa(e,t,r,n,o){let i=!1,s=JSON.stringify(e,(a,l)=>{if(typeof l!=="bigint")return l;return i=!0,null});if(!i)return JSON.parse(s);return ie(t,r,n,o,"BigInt defaults cannot be represented in JSON Schema"),Dr}var ia=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s=oa(o.defaultValue,e,t,r,n);if(s!==Dr)r.default=s},sa=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);if(i.ref=o.innerType,t.io!=="input")return;let s=oa(o.defaultValue,e,t,r,n);if(s!==Dr)r._prefault=s},aa=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{ie(e,t,r,n,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},ca=(e,t,r,n)=>{let o=e._zod.def,i=o.in._zod.traits.has("$ZodTransform"),s=t.io==="input"?i?o.out:o.in:o.out;A(s,t,n);let a=t.seen.get(e);a.ref=s},ua=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType,r.readOnly=!0};var Lr=(e,t,r,n)=>{let o=e._zod.def;A(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType},la=(e,t,r,n)=>{let o=e._zod.innerType;A(o,t,n);let i=t.seen.get(e);i.ref=o};var pa=new WeakSet([Object.prototype,Error.prototype]);function Tt(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let n=r(this);return Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0})}})}var Bu=(e,t)=>{Zn.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(pa.has(r))return;pa.add(r),Tt(r,"format",(n)=>(o)=>An(n,o)),Tt(r,"flatten",(n)=>(o)=>On(n,o)),Tt(r,"addIssue",(n)=>(o)=>{n.issues.push(o),n.message=JSON.stringify(n.issues,Ne,2)}),Tt(r,"addIssues",(n)=>(o)=>{n.issues.push(...o),n.message=JSON.stringify(n.issues,Ne,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var J=d("ZodError",Bu,void 0,{Parent:Error});var fa=ft(J),da=dt(J),ma=mt(J),ha=ht(J),ga=Cn(J),ya=Nn(J),xa=Rn(J),_a=Tn(J),ba=Dn(J),va=Ln(J),za=jn(J),Sa=Mn(J);function Vu(){if(!M.localeError)B(_r())}function Lt(){if(!M.memoizer)B({memoizer:Bi()})}var Z=d("ZodType",(e,t)=>(Vu(),k.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(U(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return H(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ul(e,t))},superRefine(e,t){return this.check(Bl(e,t))},overwrite(e){return this.check(fe(e))},optional(){return Ia(this)},exactOptional(){return Il(this)},nullable(){return Pa(this)},nullish(){return Ia(Pa(this))},nonoptional(e){return Cl(this,e)},array(){return se(this)},or(e){return Ca([this,e])},and(e){return zl(this,e)},transform(e){return Za(this,kl(e))},default(e){return Ol(this,e)},prefault(e){return El(this,e)},catch(e){return Rl(this,e)},pipe(e){return Za(this,e)},readonly(){return Ll(this)},describe(e){let t=this.clone();return be.add(t,{description:e}),t},meta(...e){if(e.length===0)return be.get(this);let t=this.clone();return be.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get "~standard"(){return lt(this,"~standard",{...fr(this),jsonSchema:{input:Ge(this,"input"),output:Ge(this,"output")}})},set "~standard"(e){oe(this,"~standard",e)},parse:function e(t,r){return fa(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await da(this,t,r,{callee:e})},safeParse(e,t){return ma(this,e,t)},async safeParseAsync(e,t){return ha(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){oe(this,"spa",e)},validate(e,t){return rr(this,e,t)},validateAsync(e,t){return nr(this,e,t)},encode:function e(t,r){return ga(this,t,r,{callee:e})},decode:function e(t,r){return ya(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await xa(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await _a(this,t,r,{callee:e})},safeEncode(e,t){return ba(this,e,t)},safeDecode(e,t){return va(this,e,t)},async safeEncodeAsync(e,t){return za(this,e,t)},async safeDecodeAsync(e,t){return Sa(this,e,t)},toJSONSchema(e){return As(this,{})(e)},get description(){return be.get(this)?.description},get _def(){return this._zod.def}}),Oa=d("_ZodString",(e,t)=>{bt.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Fs(e,r,n,o)},Sn({format:(e)=>K(e).format??null,minLength:(e)=>K(e).minimum??null,maxLength:(e)=>K(e).maximum??null},{regex(...e){return this.check(br(...e))},includes(...e){return this.check(Sr(...e))},startsWith(...e){return this.check(wr(...e))},endsWith(...e){return this.check($r(...e))},min(...e){return this.check(ke(...e))},max(...e){return this.check(Ct(...e))},length(...e){return this.check(Nt(...e))},nonempty(...e){return this.check(ke(1,...e))},lowercase(e){return this.check(vr(e))},uppercase(e){return this.check(zr(e))},trim(){return this.check(Ir())},normalize(...e){return this.check(kr(...e))},toLowerCase(){return this.check(Pr())},toUpperCase(){return this.check(Zr())},slugify(){return this.check(Or())}})),Gu=d("ZodString",(e,t)=>{bt.init(e,t),Oa.init(e,t)},{email(e){return this.check(Wi(Ku,e))},url(e){return this.check(es(qu,e))},jwt(e){return this.check(hs(ll,e))},emoji(e){return this.check(ts(Xu,e))},guid(e){return this.check(qi(Wu,e))},uuid(e){return this.check(Xi(Dt,e))},uuidv4(e){return this.check(Hi(Dt,e))},uuidv6(e){return this.check(Yi(Dt,e))},uuidv7(e){return this.check(Qi(Dt,e))},nanoid(e){return this.check(rs(Hu,e))},cuid(e){return this.check(ns(Yu,e))},cuid2(e){return this.check(os(Qu,e))},ulid(e){return this.check(is(el,e))},base64(e){return this.check(fs(al,e))},base64url(e){return this.check(ds(cl,e))},xid(e){return this.check(ss(tl,e))},ksuid(e){return this.check(as(rl,e))},ipv4(e){return this.check(cs(nl,e))},ipv6(e){return this.check(us(ol,e))},cidrv4(e){return this.check(ls(il,e))},cidrv6(e){return this.check(ps(sl,e))},e164(e){return this.check(ms(ul,e))},datetime(e){return this.check(kt(We,e))},date(e){return this.check(It(qe,e))},time(e){return this.check(Pt(Xe,e))},duration(e){return this.check(Zt(He,e))}});function te(e){return Ki(Gu,e)}var O=d("ZodStringFormat",(e,t)=>{P.init(e,t),Oa.init(e,t)}),We=d("ZodISODateTime",(e,t)=>{ei.init(e,t),O.init(e,t)}),qe=d("ZodISODate",(e,t)=>{ti.init(e,t),O.init(e,t)}),Xe=d("ZodISOTime",(e,t)=>{ri.init(e,t),O.init(e,t)}),He=d("ZodISODuration",(e,t)=>{ni.init(e,t),O.init(e,t)}),Ku=d("ZodEmail",(e,t)=>{Bo.init(e,t),O.init(e,t)});var Wu=d("ZodGUID",(e,t)=>{Fo.init(e,t),O.init(e,t)});var Dt=d("ZodUUID",(e,t)=>{Uo.init(e,t),O.init(e,t)});var qu=d("ZodURL",(e,t)=>{Go.init(e,t),O.init(e,t)});var Xu=d("ZodEmoji",(e,t)=>{Ko.init(e,t),O.init(e,t)});var Hu=d("ZodNanoID",(e,t)=>{Wo.init(e,t),O.init(e,t)});var Yu=d("ZodCUID",(e,t)=>{qo.init(e,t),O.init(e,t)});var Qu=d("ZodCUID2",(e,t)=>{Xo.init(e,t),O.init(e,t)});var el=d("ZodULID",(e,t)=>{Ho.init(e,t),O.init(e,t)});var tl=d("ZodXID",(e,t)=>{Yo.init(e,t),O.init(e,t)});var rl=d("ZodKSUID",(e,t)=>{Qo.init(e,t),O.init(e,t)});var nl=d("ZodIPv4",(e,t)=>{oi.init(e,t),O.init(e,t)});var ol=d("ZodIPv6",(e,t)=>{si.init(e,t),O.init(e,t)});var il=d("ZodCIDRv4",(e,t)=>{ai.init(e,t),O.init(e,t)});var sl=d("ZodCIDRv6",(e,t)=>{ci.init(e,t),O.init(e,t)});var al=d("ZodBase64",(e,t)=>{li.init(e,t),O.init(e,t)});var cl=d("ZodBase64URL",(e,t)=>{pi.init(e,t),O.init(e,t)});var ul=d("ZodE164",(e,t)=>{fi.init(e,t),O.init(e,t)});var ll=d("ZodJWT",(e,t)=>{di.init(e,t),O.init(e,t)});var Aa=d("ZodNumber",(e,t)=>{mr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Us(e,r,n,o),e.isFinite=!0},Sn({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=K(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=K(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=K(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>K(e).format??null},{gt(e,t){return this.check(At(e,t))},gte(e,t){return this.check(Je(e,t))},min(e,t){return this.check(Je(e,t))},lt(e,t){return this.check(Ot(e,t))},lte(e,t){return this.check(Be(e,t))},max(e,t){return this.check(Be(e,t))},int(e){return this.check(wa(e))},safe(e){return this.check(wa(e))},positive(e){return this.check(At(0,e))},nonnegative(e){return this.check(Je(0,e))},negative(e){return this.check(Ot(0,e))},nonpositive(e){return this.check(Be(0,e))},multipleOf(e,t){return this.check(Et(e,t))},step(e,t){return this.check(Et(e,t))},finite(){return this}}));function Ye(e){return gs(Aa,e)}var pl=d("ZodNumberFormat",(e,t)=>{mi.init(e,t),Aa.init(e,t)});function wa(e){return ys(pl,e)}var fl=d("ZodBoolean",(e,t)=>{hi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Bs(e,r,n,o)});function Mr(e){return xs(fl,e)}var dl=d("ZodNull",(e,t)=>{gi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Js(e,r,n,o)});function ml(e){return _s(dl,e)}var hl=d("ZodUnknown",(e,t)=>{yi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Gs(e,r,n,o)});function $a(){return bs(hl)}var gl=d("ZodNever",(e,t)=>{xi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Vs(e,r,n,o)});function yl(e){return vs(gl,e)}var xl=d("ZodArray",(e,t)=>{Lt(),_i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Hs(e,r,n,o),e.element=t.element},{min(e,t){return this.check(ke(e,t))},nonempty(e){return this.check(ke(1,e))},max(e,t){return this.check(Ct(e,t))},length(e,t){return this.check(Nt(e,t))},unwrap(){return this.element}});function se(e,t){return zs(xl,e,t)}var _l=d("ZodObject",(e,t)=>{Lt(),zi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ys(e,r,n,o),Xc(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return ae(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(U(this._zod.def,{catchall:e}))},passthrough(){return this.clone(U(this._zod.def,{catchall:$a()}))},loose(){return this.clone(U(this._zod.def,{catchall:$a()}))},strict(){return this.clone(U(this._zod.def,{catchall:yl()}))},strip(){return this.clone(U(this._zod.def,{catchall:void 0}))},extend(e){return Uc(this,e)},safeExtend(e){return Bc(this,e)},merge(e){return Jc(this,e)},pick(e){return Mc(this,e)},omit(e){return Fc(this,e)},partial(...e){return _n(Ra,this,e[0])},exactPartial(...e){return _n(Ta,this,e[0],"exactPartial")},required(...e){return Vc(Da,this,e[0])}});function N(e,t){let r={type:"object",shape:e??{},...g(t)};return new _l(r)}var Ea=d("ZodUnion",(e,t)=>{hr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Qs(e,r,n,o),e.options=t.options});function Ca(e,t){return new Ea({type:"union",options:e,...g(t)})}var bl=d("ZodDiscriminatedUnion",(e,t)=>{Ea.init(e,t),Si.init(e,t)});function Na(e,t,r){return new bl({type:"union",options:t,discriminator:e,...g(r)})}var vl=d("ZodIntersection",(e,t)=>{wi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ea(e,r,n,o)});function zl(e,t){return new vl({type:"intersection",left:e,right:t})}var ka=d("ZodRecord",(e,t)=>{Lt(),$i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ta(e,r,n,o),e.keyType=t.keyType,e.valueType=t.valueType});function Sl(e,t,r){if(!t||!t._zod)return new ka({type:"record",keyType:te(),valueType:e,...g(t)});return new ka({type:"record",keyType:e,valueType:t,...g(r)})}var jr=d("ZodEnum",(e,t)=>{ki.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(n,o,i)=>Ks(e,n,o,i),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(n,o)=>{let i={};for(let s of n)if(r.has(s))i[s]=t.entries[s];else throw Error(`Key ${s} not found in enum`);return new jr({...t,checks:[],...g(o),entries:i})},e.exclude=(n,o)=>{let i={...t.entries};for(let s of n)if(r.has(s))delete i[s];else throw Error(`Key ${s} not found in enum`);return new jr({...t,checks:[],...g(o),entries:i})}});function ae(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new jr({type:"enum",entries:r,...g(t)})}var wl=d("ZodLiteral",(e,t)=>{Ii.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ws(e,r,n,o),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Qe(e,t){return new wl({type:"literal",values:Array.isArray(e)?e:[e],...g(t)})}var $l=d("ZodTransform",(e,t)=>{Lt(),Pi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Xs(e,r,n,o),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new De(e.constructor.name);r.addIssue=(i)=>{if(typeof i==="string")r.issues.push(_e(i,r.value,t));else{let s=i;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=r.value;s.inst??(s.inst=e),r.issues.push(_e(s))}};let o=t.transform(r.value,r);if(o instanceof Promise)return o.then((i)=>(r.value=i,r));return r.value=o,r}});function kl(e){return new $l({type:"transform",transform:e})}var Ra=d("ZodOptional",(e,t)=>{gr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Lr(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ia(e){return new Ra({type:"optional",innerType:e})}var Ta=d("ZodExactOptional",(e,t)=>{Zi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Lr(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Il(e){return new Ta({type:"optional",innerType:e})}var Pl=d("ZodNullable",(e,t)=>{Oi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ra(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Pa(e){return new Pl({type:"nullable",innerType:e})}var Zl=d("ZodDefault",(e,t)=>{Ai.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ia(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ol(e,t){return new Zl({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():qt(t)}})}var Al=d("ZodPrefault",(e,t)=>{Ei.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>sa(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function El(e,t){return new Al({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():qt(t)}})}var Da=d("ZodNonOptional",(e,t)=>{Ci.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>na(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Cl(e,t){return new Da({type:"nonoptional",innerType:e,...g(t)})}var Nl=d("ZodCatch",(e,t)=>{Ni.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>aa(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Rl(e,t){return new Nl({type:"catch",innerType:e,catchValue:typeof t==="function"?t:wn(t)})}var Tl=d("ZodPipe",(e,t)=>{Ri.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ca(e,r,n,o),e.in=t.in,e.out=t.out});function Za(e,t){return new Tl({type:"pipe",in:e,out:t})}var Dl=d("ZodReadonly",(e,t)=>{Ti.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ua(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ll(e){return new Dl({type:"readonly",innerType:e})}var jl=d("ZodLazy",(e,t)=>{Di.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>la(e,r,n,o),e.unwrap=()=>e._zod.def.getter()});function Ml(e){return new jl({type:"lazy",getter:e})}var La=d("ZodCustom",(e,t)=>{Li.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>qs(e,r,n,o)});function Fl(e,t){return Ss(La,e??(()=>!0),t)}function Ul(e,t={}){return ws(La,e,t)}function Bl(e,t){return $s(e,t)}function Jl(e){return kt(We,e)}function Vl(e){return It(qe,e)}function Gl(e){return Pt(Xe,e)}function Kl(e){return Zt(He,e)}import{createHash as Wl}from"crypto";import ja from"path";var Mt="ast-mcp.intelligence.v1",L=te().regex(/^[a-f0-9]{64}$/),ql=te().regex(/^[a-z][a-z0-9-]*:v1:[a-f0-9]{64}$/);function F(e){if(!/^[a-z][a-z0-9-]*$/.test(e))throw TypeError("Identity namespace must be lowercase kebab-case");return te().regex(new RegExp(`^${e}:v1:[a-f0-9]{64}$`),`Identity must use the ${e} namespace`)}var Ft=F("source"),Ut=F("syntax-facts"),Fa=F("chunks"),Ua=F("resolved-relationships"),Om=F("revision-manifest"),Ba=F("dirty-overlay"),Jr=F("repository"),Vr=F("revision"),Am=F("workspace"),Em=F("storage-domain"),Cm=F("generation"),Nm=F("job"),Rm=F("reader-pin"),Tm=F("search-hit"),W=te().trim().min(1);function Ja(e){return ja.posix.isAbsolute(e)||ja.win32.isAbsolute(e)}var Va=te().refine(Ja,"Path must be absolute"),Gr=te().min(1).refine((e)=>!Ja(e),{message:"Repository path must be relative"}).refine((e)=>!e.includes(String.fromCharCode(92))&&!e.includes(String.fromCharCode(0))&&!e.split("/").includes("..")&&!e.split("/").includes("."),{message:"Repository path must use normalized forward-slash segments"}).refine((e)=>e!=="."&&!e.startsWith("./")&&!e.includes("//")&&!e.endsWith("/"),{message:"Repository path must be normalized"});var Dm=Fr.datetime({offset:!0}),Ma=N({column:Ye().int().nonnegative(),line:Ye().int().nonnegative()}),Lm=N({end:Ma,endByte:Ye().int().nonnegative(),start:Ma,startByte:Ye().int().nonnegative()}).superRefine((e,t)=>{if(e.endByte<e.startByte)t.addIssue({code:"custom",message:"endByte must be greater than or equal to startByte",path:["endByte"]});if(e.end.line<e.start.line||e.end.line===e.start.line&&e.end.column<e.start.column)t.addIssue({code:"custom",message:"end position must not precede start position",path:["end"]})}),Ur=Ml(()=>Ca([ml(),Mr(),Fl((e)=>typeof e==="number"&&Number.isFinite(e),"Identity numbers must be finite"),te(),se(Ur),Sl(te(),Ur)])),Xl=te().regex(/^[a-z][a-z0-9-]*$/,"Identity namespace must be lowercase kebab-case"),Hl=N({namespace:Xl,value:Ur}).strict();function Br(e){if(e===null)return"null";if(typeof e==="string")return JSON.stringify(e);if(typeof e==="boolean")return e?"true":"false";if(typeof e==="number"){if(!Number.isFinite(e))throw TypeError("Identity numbers must be finite");return Object.is(e,-0)?"0":JSON.stringify(e)}if(Array.isArray(e))return`[${e.map((r)=>Br(r)).join(",")}]`;let t=e;return`{${Object.keys(t).sort().map((r)=>`${JSON.stringify(r)}:${Br(t[r]??null)}`).join(",")}}`}function Kr(e,t){let r=Hl.parse({namespace:e,value:t}),n=Wl("sha256").update(Br(r.value)).digest("hex");return ql.parse(`${r.namespace}:v1:${n}`)}var Yl=N({contentDigest:L}).strict(),Ql=N({languageId:W,parserFingerprint:L,sourceArtifactId:Ft}).strict(),Bm=Na("documentKind",[N({chunkerFingerprint:L,documentKind:Qe("code"),extractedContentDigest:L,semanticContextDigest:L,syntaxFactsArtifactId:Ut}).strict(),N({chunkerFingerprint:L,documentKind:ae(["markdown","text","rtf","structured"]),extractedContentDigest:L,semanticContextDigest:L,sourceArtifactId:Ft}).strict()]),Jm=N({chunkArtifactId:Fa,dimensions:Ye().int().positive(),dtype:ae(["float32","float16","int8","uint8"]),exactInputDigest:L,modelId:W,modelRevision:W,normalized:Mr(),pooling:ae(["mean","cls","none"]),tokenizerId:W,tokenizerRevision:W}).strict(),Vm=N({environmentFingerprint:L,resolverFingerprint:L,syntaxFactsArtifactId:Ut}).strict();function Ga(e,t){let r=new Set;e.forEach((n,o)=>{if(r.has(n.path))t.addIssue({code:"custom",message:"Artifact entries must have unique repository paths",path:["entries",o,"path"]});r.add(n.path)})}var ep=N({path:Gr,resolvedRelationshipsArtifactId:Ua.nullable(),sourceArtifactId:Ft,syntaxFactsArtifactId:Ut.nullable()}).strict(),Gm=N({dirtyOverlayId:Ba.nullable(),entries:se(ep),repositoryId:Jr,revisionId:Vr}).strict().superRefine((e,t)=>{Ga(e.entries,t)}),tp=N({contentDigest:L.nullable(),path:Gr,status:ae(["added","modified","deleted"])}).strict().superRefine((e,t)=>{if(e.status!=="deleted"!==(e.contentDigest!==null))t.addIssue({code:"custom",message:e.status==="deleted"?"Deleted overlay entries cannot have content":"Added and modified overlay entries require content",path:["contentDigest"]})}),Km=N({baseRevisionId:Vr,checkoutRoot:Va,entries:se(tp),repositoryId:Jr}).strict().superRefine((e,t)=>{Ga(e.entries,t)}),Ka=(e)=>Kr("source",Yl.parse(e)),Wa=(e)=>Kr("syntax-facts",Ql.parse(e));import{stat as ip}from"fs/promises";import{isAbsolute as sp,resolve as Xa}from"path";import{registerDynamicLanguage as ap}from"@ast-grep/napi";var rp=ae(["supported","partial","unsupported"]),np=ae(["tree-sitter","ast-grep","structured-parser","text","custom","none"]),re=N({implementationFingerprint:L.nullable(),limitations:se(W),provider:np,status:rp}).strict().superRefine((e,t)=>{if(e.status==="unsupported"){if(e.provider!=="none"||e.implementationFingerprint!==null)t.addIssue({code:"custom",message:"Unsupported capabilities cannot claim an implementation"});if(e.limitations.length===0)t.addIssue({code:"custom",message:"Unsupported capabilities must explain their limitation",path:["limitations"]});return}if(e.provider==="none"||e.implementationFingerprint===null)t.addIssue({code:"custom",message:"Supported capabilities require an implementation"});if(e.status==="partial"&&e.limitations.length===0)t.addIssue({code:"custom",message:"Partial capabilities must state their limitations",path:["limitations"]});if(e.status==="supported"&&e.limitations.length>0)t.addIssue({code:"custom",message:"Capabilities with limitations must be marked partial",path:["status"]})}),op=Na("mode",[N({mode:Qe("none")}).strict(),N({formats:se(ae(["json","jsonc","yaml","toml","markdown","rtf"])).min(1),mode:Qe("native"),preservesComments:Mr()}).strict(),N({formats:se(ae(["json","jsonc","yaml","toml","markdown","rtf"])).min(1),limitation:W,mode:Qe("text-fallback")}).strict()]),qa=N({callResolution:re,embeddedLanguageIds:se(W),embeddedLanguages:re,exportResolution:re,extensions:se(W),importResolution:re,inheritanceResolution:re,languageId:W,match:re,parse:re,rewrite:re,schemaVersion:Qe(Mt),structuralRead:re,structuredParser:op,symbolExtraction:re}).strict().superRefine((e,t)=>{if(e.embeddedLanguages.status==="unsupported"&&e.embeddedLanguageIds.length>0)t.addIssue({code:"custom",message:"Unsupported embedded languages cannot list language IDs",path:["embeddedLanguageIds"]});if(e.rewrite.status!=="unsupported"&&(e.parse.status==="unsupported"||e.match.status==="unsupported"))t.addIssue({code:"custom",message:"Rewrite support requires parse and match support",path:["rewrite"]});if(e.structuredParser.mode!=="none"&&e.structuralRead.status==="unsupported")t.addIssue({code:"custom",message:"Structured parser behavior requires structural reads",path:["structuredParser"]})});var qr="ast-mcp.ts-js.v1",Oe=(e)=>j(JSON.stringify(e));function Ha(e){let t;try{t=structuredClone(e)}catch{throw TypeError("Dynamic grammar manifest must be cloneable")}if(t.schemaVersion!=="ast-mcp.dynamic-grammars.v1")throw TypeError("Unsupported dynamic grammar manifest version");if(!Array.isArray(t.entries))throw TypeError("Dynamic grammar manifest entries must be an array");if(!/^[a-f0-9]{64}$/.test(t.fingerprint))throw TypeError("Dynamic grammar manifest fingerprint is invalid");if(Oe(t.entries)!==t.fingerprint)throw TypeError("Dynamic grammar manifest fingerprint mismatch");let r=t.entries.map((n)=>{if(!n.descriptor.dynamicAsset)throw TypeError("Dynamic grammar manifest entry requires an asset");return Object.freeze({descriptor:Object.freeze({...n.descriptor,dynamicAsset:Object.freeze({...n.descriptor.dynamicAsset}),extensions:Object.freeze([...n.descriptor.extensions])}),implementation:Object.freeze({...n.implementation})})});return Object.freeze({entries:Object.freeze(r),fingerprint:t.fingerprint,schemaVersion:t.schemaVersion})}function cp(e){return{astGrepLanguage:e.astGrepLanguage,dynamicAsset:null,extensions:e.extensions,grammarFingerprint:Oe({astGrepLanguage:e.astGrepLanguage,extensions:[...e.extensions],grammarVersion:e.grammarVersion,languageId:e.languageId}),grammarVersion:e.grammarVersion,languageId:e.languageId}}var up=we.map(cp),Wr=new WeakMap,lp=(e)=>({callResolution:!1,embeddedLanguages:!1,exportResolution:!1,importResolution:!1,inheritanceResolution:!1,match:e.structuralOperations.match,parse:e.structuralOperations.parse,rewrite:e.structuralOperations.rewrite,structuralRead:e.structuralOperations.structuralRead,symbolExtraction:e.analysis.symbolExtraction}),Ze=(e)=>({implementationFingerprint:null,limitations:[e],provider:"none",status:"unsupported"}),Ya=(e,t)=>({implementationFingerprint:t,limitations:[],provider:e,status:"supported"});class Qa{#t;#e=new Map(up.map((e)=>[e.languageId,e]));#r=new Map(we.map((e)=>[e.languageId,lp(e)]));#n=!1;constructor(e=ap){this.#t=e}get(e){let t=this.#e.get(e);if(!t)throw TypeError(`Unsupported parser language: ${e}`);return t}list(){return[...this.#e.values()].sort((e,t)=>e.languageId.localeCompare(t.languageId))}capabilities(e){let t=this.get(e),r=this.#r.get(e);if(!r)throw TypeError("Missing language implementation");let n=Oe({extractor:qr,languageId:e}),o=Ya("ast-grep",t.grammarFingerprint),i=r.symbolExtraction?Ya("custom",n):Ze("This adapter does not extract code symbols");return this.assertHonest(e,{callResolution:Ze("Call resolution requires an environment-specific resolver"),embeddedLanguageIds:[],embeddedLanguages:Ze("No embedded-language extractor is registered"),exportResolution:Ze("Export resolution requires an environment-specific resolver"),extensions:[...t.extensions],importResolution:Ze("Import resolution requires an environment-specific resolver"),inheritanceResolution:Ze("Inheritance resolution requires an environment-specific resolver"),languageId:e,match:o,parse:o,rewrite:o,schemaVersion:Mt,structuralRead:o,structuredParser:{mode:"none"},symbolExtraction:i})}assertHonest(e,t){let r=qa.parse(t),n=this.#r.get(e);if(!n)throw TypeError("Missing language implementation");let o=[["parse","parse"],["structuralRead","structuralRead"],["match","match"],["rewrite","rewrite"],["symbolExtraction","symbolExtraction"],["importResolution","importResolution"],["exportResolution","exportResolution"],["callResolution","callResolution"],["inheritanceResolution","inheritanceResolution"],["embeddedLanguages","embeddedLanguages"]];for(let[i,s]of o){let a=r[s];if(!n[i]&&a.status!=="unsupported")throw TypeError(`Capability ${String(s)} has no registered implementation`);if(n[i]&&a.status==="unsupported")throw TypeError(`Capability ${String(s)} hides a registered implementation`)}return r}async addDynamic(e,t){if(this.#n)throw TypeError("Dynamic grammars must be configured before parsing");if(this.#e.has(e.languageId))throw TypeError(`Parser language is already registered: ${e.languageId}`);if(!e.dynamicAsset)throw TypeError("Dynamic grammars require a native library asset");if(await pp(e.dynamicAsset),this.#n)throw TypeError("Dynamic grammars must be configured before parsing");if(this.#e.has(e.languageId))throw TypeError(`Parser language is already registered: ${e.languageId}`);let r={expandoChar:e.dynamicAsset.expandoChar??null,languageSymbol:e.dynamicAsset.languageSymbol??null,libraryPath:Xa(e.dynamicAsset.libraryPath),metaVarChar:e.dynamicAsset.metaVarChar??null,sha256:e.dynamicAsset.sha256},n=Oe({astGrepLanguage:e.astGrepLanguage,dynamicAsset:r,extensions:[...e.extensions],grammarVersion:e.grammarVersion,languageId:e.languageId});if(e.grammarFingerprint&&e.grammarFingerprint!==n)throw TypeError("Dynamic grammar fingerprint does not match its asset");if(Wr.has(this.#t))throw TypeError("Dynamic grammars must be configured before parsing");this.#e.set(e.languageId,{...e,dynamicAsset:{...e.dynamicAsset,libraryPath:r.libraryPath},grammarFingerprint:n}),this.#r.set(e.languageId,t)}dynamicManifest(){let e=[...this.#e.values()].filter((r)=>r.dynamicAsset!==null).sort((r,n)=>r.languageId.localeCompare(n.languageId)).map((r)=>{let n=this.#r.get(r.languageId);if(!n)throw TypeError("Missing language implementation");let o=r.dynamicAsset;if(!o)throw TypeError("Missing dynamic grammar asset");let i=Object.freeze({...r,dynamicAsset:Object.freeze({...o}),extensions:Object.freeze([...r.extensions])});return Object.freeze({descriptor:i,implementation:Object.freeze({...n})})}),t=Object.freeze(e);return Ha({entries:t,fingerprint:Oe(t),schemaVersion:"ast-mcp.dynamic-grammars.v1"})}async loadDynamicManifest(e){let t=Ha(e);for(let r of t.entries)await this.addDynamic(r.descriptor,r.implementation)}registerDynamicGrammars(){if(this.#n)return;let e={...on};for(let n of this.#e.values()){if(!n.dynamicAsset)continue;e[n.astGrepLanguage]={extensions:[...n.extensions],libraryPath:Xa(n.dynamicAsset.libraryPath),...n.dynamicAsset.languageSymbol?{languageSymbol:n.dynamicAsset.languageSymbol}:{},...n.dynamicAsset.metaVarChar?{metaVarChar:n.dynamicAsset.metaVarChar}:{},...n.dynamicAsset.expandoChar?{expandoChar:n.dynamicAsset.expandoChar}:{}}}let t=Oe(Object.fromEntries(Object.entries(e).sort(([n],[o])=>n.localeCompare(o)))),r=Wr.get(this.#t);if(r===void 0)this.#t(e),Wr.set(this.#t,t);else if(r!==t)throw TypeError("A different grammar set is already registered in this process");this.#n=!0}}async function pp(e){if(!sp(e.libraryPath))throw TypeError("Dynamic grammar library path must be absolute");if(!/\.(?:dylib|dll|node|so)$/i.test(e.libraryPath))throw TypeError("Dynamic grammar asset must use a native library filename");if(!(await ip(e.libraryPath)).isFile())throw TypeError("Dynamic grammar asset is not a file");let r=new Uint8Array(await Bun.file(e.libraryPath).slice(0,4).arrayBuffer()),n=new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0);if(!(n===2135247942||r[0]===77&&r[1]===90||n===3405691582||n===3199925962||n===3489328638||n===3472551422||n===4277009103||n===4277009102))throw TypeError("Dynamic grammar asset is not a recognized native library");let i=new Bun.CryptoHasher("sha256");if(i.update(await Bun.file(e.libraryPath).arrayBuffer()),i.digest("hex")!==e.sha256)throw TypeError("Dynamic grammar asset fingerprint mismatch")}var et=new Qa;class tt extends Error{code;retryable;constructor(e){super(e.message);this.name="ParserError",this.code=e.code,this.retryable=e.retryable}toJSON(){return{code:this.code,message:this.message,retryable:this.retryable}}}var tc=new Map([["class_declaration","class"],["abstract_class_declaration","class"],["interface_declaration","interface"],["function_declaration","function"],["generator_function_declaration","function"],["method_definition","method"],["method_signature","method"],["type_alias_declaration","type"],["enum_declaration","enum"],["internal_module","namespace"],["module","namespace"]]),Xr=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier"]);function Ae(e,t,r){return j(JSON.stringify([e,t,...r]))}function rc(e){return e.trim().slice(1,-1)}function me(e,t){return e.coordinates.fromAstRange(t.range())}var V=(e)=>String(e.kind());function dp(e,t){for(let r of e.namedChildren())if(t.includes(V(r)))return r;return null}function Bt(e){let t=e.field("name");if(t)return t;return dp(e,["identifier","type_identifier","property_identifier"])}function rt(e){let t=V(e);if(t==="identifier"||t==="shorthand_property_identifier_pattern")return[e];if(t==="pair_pattern"){let r=e.field("value")??e.namedChildren().at(-1);return r?rt(r):[]}if(t==="assignment_pattern"||t==="object_assignment_pattern"){let r=e.field("left")??e.namedChildren()[0];return r?rt(r):[]}if(t==="rest_pattern"){let r=e.field("argument")??e.namedChildren()[0];return r?rt(r):[]}return e.namedChildren().flatMap((r)=>rt(r))}function mp(e){let t=e.parent();while(t){let r=V(t);if(r==="export_statement")return!0;if(r==="program"||r==="class_body")return!1;t=t.parent()}return!1}function hp(e,t,r){let n=tc.get(V(t)),o=t.kind()==="variable_declarator"?rt(t.field("name")??t.namedChildren()[0]??t):n?[Bt(t)].filter((a)=>a!==null):[],i=t.kind()==="variable_declarator"?"variable":n;if(!i||o.length===0)return[];let s=me(e,t);return o.map((a)=>{let l=a.text(),c=r?`${r.qualifiedName}.${l}`:l;return{declarationRange:me(e,a),exported:mp(t),id:Ae(e.sourceDigest,"symbol",[i,c,s.startCoordinate.utf16Offset,s.endCoordinate.utf16Offset]),kind:i,name:l,qualifiedName:c,range:s}})}function gp(e,t){let r=[...t.namedChildren()].reverse().find((c)=>c.kind()==="string");if(!r)return;let n=rc(r.text()),o=t.text(),i=/^import\s+type\b/.test(o),s=t.namedChildren().find((c)=>c.kind()==="import_clause"),a=[];if(!s)a.push({importedName:"*side-effect*",localName:"*side-effect*"});else{let c=s.namedChildren().find((f)=>f.kind()==="identifier");if(c)a.push({importedName:"default",localName:c.text()});let u=s.namedChildren().find((f)=>f.kind()==="namespace_import");if(u){let f=u.namedChildren().find((m)=>m.kind()==="identifier");if(f)a.push({importedName:"*",localName:f.text()})}let p=s.namedChildren().find((f)=>f.kind()==="named_imports");for(let f of p?.namedChildren()??[]){if(f.kind()!=="import_specifier")continue;let m=f.namedChildren().filter((y)=>Xr.has(V(y))),h=m[0]?.text();if(!h)continue;a.push({importedName:h,localName:m.at(-1)?.text()??h})}}let l=me(e,t);for(let c of a)e.imports.push({id:Ae(e.sourceDigest,"import",[n,c.importedName,c.localName,l.startCoordinate.utf16Offset]),importedName:c.importedName,localName:c.localName,range:l,source:n,typeOnly:i})}function yp(e,t){let r=me(e,t),n=[...t.namedChildren()].reverse().find((c)=>c.kind()==="string"),o=n?rc(n.text()):null,i=/^export\s+type\b/.test(t.text()),s=t.namedChildren().find((c)=>[...tc.keys(),"lexical_declaration","variable_declaration"].includes(V(c))),a=[];if(s)if(["lexical_declaration","variable_declaration"].includes(V(s)))for(let c of s.namedChildren()){let u=Bt(c)?.text();if(u)a.push({exportedName:u,localName:u})}else{let c=Bt(s)?.text();if(c)a.push({exportedName:c,localName:c})}let l=t.namedChildren().find((c)=>c.kind()==="export_clause");for(let c of l?.namedChildren()??[]){let u=c.namedChildren().filter((f)=>Xr.has(V(f))),p=u[0]?.text();if(!p)continue;a.push({exportedName:u.at(-1)?.text()??p,localName:p})}if(/^export\s+default\b/.test(t.text()))a.push({exportedName:"default",localName:a[0]?.localName??null});if(/^export\s+\*/.test(t.text()))a.push({exportedName:"*",localName:null});for(let c of a)e.exports.push({exportedName:c.exportedName,id:Ae(e.sourceDigest,"export",[c.exportedName,c.localName,o,r.startCoordinate.utf16Offset]),localName:c.localName,range:r,source:o,typeOnly:i})}function xp(e,t,r){let n=t.field("function")??t.namedChildren()[0]??null;if(!n)return;let o=me(e,t);e.calls.push({callee:n.text(),enclosingSymbolId:r?.id??null,id:Ae(e.sourceDigest,"call",[n.text(),o.startCoordinate.utf16Offset]),range:o})}function ec(e,t,r,n,o){for(let i of t.namedChildren()){let s=me(e,i);n.push({id:Ae(e.sourceDigest,o,[r?.id??null,i.text(),s.startCoordinate.utf16Offset]),range:s,sourceSymbolId:r?.id??null,targetName:i.text()})}}function _p(e){if(e.kind()==="type_identifier")return"type";let t=e.parent();if(!t)return"read";if(["variable_declarator","required_parameter","optional_parameter"].includes(V(t))&&Bt(t)?.id()===e.id())return"write";return t.field("left")?.id()===e.id()?"write":"read"}function nc(e,t,r,n){if(e.nodes.length>=e.maxNodes){if(!e.truncated)e.truncated=!0,e.diagnostics.push({code:"truncated",message:"Syntax node limit reached",range:me(e,t),severity:"warning"});return null}let o=me(e,t),i=rn(e.sourceDigest,V(t),o.startCoordinate.utf16Offset,o.endCoordinate.utf16Offset),s={childIds:[],id:i,kind:V(t),named:t.isNamed(),parentId:r,range:o};if(e.nodes.push(s),t.kind()==="ERROR"||t.kind()==="error")e.diagnostics.push({code:"parse-error",message:"Parser recovered from malformed source",range:o,severity:"error"});else if(V(t).startsWith("MISSING"))e.diagnostics.push({code:"missing-node",message:"Parser inserted a missing syntax node",range:o,severity:"error"});let a=hp(e,t,n);e.symbols.push(...a);let l=a[0]??n;if(t.kind()==="import_statement")gp(e,t);if(t.kind()==="export_statement")yp(e,t);if(t.kind()==="call_expression")xp(e,t,l);if(t.kind()==="extends_clause")ec(e,t,l,e.inheritance,"inheritance");if(t.kind()==="implements_clause")ec(e,t,l,e.implementations,"implementation");if(Xr.has(V(t)))e.references.push({enclosingSymbolId:l?.id??null,id:Ae(e.sourceDigest,"reference",[t.text(),o.startCoordinate.utf16Offset]),name:t.text(),range:o,role:_p(t)});for(let c of t.namedChildren()){let u=nc(e,c,i,l);if(u)s.childIds.push(u)}return i}function de(e){return e.sort((t,r)=>t.range.startCoordinate.utf16Offset-r.range.startCoordinate.utf16Offset||t.range.endCoordinate.utf16Offset-r.range.endCoordinate.utf16Offset)}function oc(e,t=et){if(e.maxNodes!==void 0&&(!Number.isFinite(e.maxNodes)||!Number.isInteger(e.maxNodes)||e.maxNodes<1))throw new tt({code:"invalid-request",message:"Parser maxNodes must be a finite positive integer",retryable:!1});let r=j(e.source),n;try{n=t.get(e.languageId)}catch(f){throw new tt({code:"invalid-language",message:f instanceof Error?f.message:"Unsupported language",retryable:!1})}let o=e.grammarVersion?j(JSON.stringify([n.grammarFingerprint,e.grammarVersion])):n.grammarFingerprint,i=j(JSON.stringify([e.languageId,e.extractorVersion??qr])),s=j(JSON.stringify([o,i])),a=Ka({contentDigest:r}),l=Wa({languageId:e.languageId,parserFingerprint:s,sourceArtifactId:a});t.registerDynamicGrammars();let c=fp(n.astGrepLanguage,e.source).root(),u={calls:[],coordinates:new ve(e.source),diagnostics:[],exports:[],implementations:[],imports:[],inheritance:[],maxNodes:e.maxNodes??250000,nodes:[],references:[],sourceDigest:r,symbols:[],truncated:!1},p=nc(u,c,null,null);if(!p)throw new tt({code:"worker-error",message:"Parser produced no root syntax node",retryable:!1});return{calls:de(u.calls),diagnostics:de(u.diagnostics),exports:de(u.exports),extractorFingerprint:i,grammarFingerprint:o,implementations:de(u.implementations),imports:de(u.imports),inheritance:de(u.inheritance),languageId:e.languageId,nodes:u.nodes,parserFingerprint:s,partial:u.diagnostics.length>0,references:de(u.references),rootNodeId:p,schemaVersion:"ast-mcp.syntax-facts.v1",sourceArtifactId:a,sourceDigest:r,symbols:de(u.symbols),syntaxFactsArtifactId:l}}import{parse as ic}from"@ast-grep/napi";function Hr(e,t,r){return e.start.index-t.start.index||e.end.index-t.end.index||(r?r.left.localeCompare(r.right):0)}function bp(e,t,r,n){let o=n.get(t);n.registerDynamicGrammars();let i=ic(o.astGrepLanguage,e).root(),s=new ve(e),a=i.findAll(r).sort((c,u)=>Hr(c.range(),u.range(),{left:String(c.kind()),right:String(u.kind())}));return{matches:a.map((c,u)=>{let p=s.fromAstRange(c.range());return{id:j(JSON.stringify([o.grammarFingerprint,j(e),r,p.startCoordinate.utf16Offset,p.endCoordinate.utf16Offset])),kind:String(c.kind()),ordinal:u,range:p,text:c.text()}}),nodes:a}}function Yr(e,t,r,n=et){return bp(e,t,r,n).matches}function vp(e,t){return e.replace(/\$\$\$([A-Z_][A-Z0-9_]*)|\$([A-Z_][A-Z0-9_]*)/g,(r,n,o)=>{if(n){let i=t.getMultipleMatches(n),s=i[0],a=i.at(-1);if(!s||!a)return"";return t.getRoot().root().text().slice(s.range().start.index,a.range().end.index)}if(!o)return r;return t.getMatch(o)?.text()??r})}function sc(e,t,r,n=et){let o=n.get(t);n.registerDynamicGrammars();let i=ic(o.astGrepLanguage,e).root(),s=new ve(e),a=[],l=[],c=[];for(let[p,f]of r.entries()){if(!Number.isInteger(f.expectedMatches)||f.expectedMatches<0)throw TypeError("Expected match count must be a nonnegative integer");let m=i.findAll(f.pattern).sort((h,y)=>Hr(h.range(),y.range()));if(m.length!==f.expectedMatches)throw RangeError("Structural operation "+p+" expected "+f.expectedMatches+" matches but found "+m.length);if(Array.isArray(f.replacement)&&f.replacement.length!==m.length)throw RangeError(`Structural operation ${p} requires one replacement per match`);m.forEach((h,y)=>{let b=s.fromAstRange(h.range()),S={id:j(JSON.stringify([o.grammarFingerprint,j(e),p,f.pattern,b.startCoordinate.utf16Offset,b.endCoordinate.utf16Offset])),kind:String(h.kind()),ordinal:y,range:b,text:h.text()},E=Array.isArray(f.replacement)?f.replacement[y]??"":f.replacement,X=vp(E,h);a.push(S),l.push({matchId:S.id,range:b,replacement:X}),c.push({endPos:b.endCoordinate.utf16Offset,insertedText:X,startPos:b.startCoordinate.utf16Offset})})}let u=l.map((p,f)=>({edit:p,native:c[f]})).sort((p,f)=>p.edit.range.startCoordinate.utf16Offset-f.edit.range.startCoordinate.utf16Offset||p.edit.range.endCoordinate.utf16Offset-f.edit.range.endCoordinate.utf16Offset);for(let p=1;p<u.length;p+=1){let f=u[p-1]?.edit,m=u[p]?.edit;if(f&&m&&m.range.startCoordinate.utf16Offset<f.range.endCoordinate.utf16Offset)throw RangeError("Structural rewrite matches overlap")}return{edits:u.map((p)=>p.edit),matches:[...a].sort((p,f)=>p.range.startCoordinate.utf16Offset-f.range.startCoordinate.utf16Offset||p.range.endCoordinate.utf16Offset-f.range.endCoordinate.utf16Offset),source:i.commitEdits(u.map((p)=>{if(!p.native)throw TypeError("Missing native edit");return p.native}))}}import he from"path";function ce(e,t){return he.relative(e,t).split(he.sep).join("/")}function I(e){if(e?.aborted)throw e.reason}function nt(e,t,r=!1){return e.facts.symbols.map((n)=>({exported:n.exported,kind:n.kind,name:n.name,path:ce(t,e.path),qualifiedName:n.qualifiedName,range:{endLine:n.range.end.line+1,startLine:n.range.start.line+1},...r?{source:e.source.slice(n.range.startCoordinate.utf16Offset,n.range.endCoordinate.utf16Offset)}:{}}))}function cc(e,t){return e.facts.symbols.filter((r)=>r.name===t||r.qualifiedName===t||r.qualifiedName.endsWith(`.${t}`))}function zp(e,t,r,n,o=!1,i){I(i);let s=new Map(Jt(e,i,(c)=>c.facts.symbols.map((u)=>(I(i),[u.id,u.qualifiedName])))),a=new Set(Jt(e,i,(c)=>cc(c,r).map((u)=>(I(i),u.id)))),l=[];for(let c of e){I(i);for(let u of c.facts.calls){if(I(i),!(n==="in"?u.callee===r||u.callee.endsWith(`.${r}`):u.enclosingSymbolId!==null&&a.has(u.enclosingSymbolId)))continue;l.push({callee:u.callee,caller:u.enclosingSymbolId===null?null:s.get(u.enclosingSymbolId)??null,path:ce(t,c.path),...o?{range:{endLine:u.range.end.line+1,startLine:u.range.start.line+1}}:{line:u.range.start.line+1}})}}return l.sort((c,u)=>c.path.localeCompare(u.path)||(c.line??c.range?.startLine??0)-(u.line??u.range?.startLine??0)||c.callee.localeCompare(u.callee))}function ac(e,t,r,n,o,i,s){let a=new Map,l=[r],c=new Set;for(let u=0;u<o&&l.length>0;u+=1){let p=new Set;for(let f of l.sort()){if(I(s),c.has(f))continue;c.add(f);for(let m of zp(e,t,f,n,i,s)){I(s),a.set(JSON.stringify(m),m);let h=n==="out"?m.callee:m.caller;if(h&&!c.has(h))p.add(h)}}l=[...p]}return[...a.values()]}function Sp(e,t){if(Buffer.byteLength(e)<=t)return e;let r="",n=0;for(let o of e){let i=Buffer.byteLength(o);if(n+i>t)break;r+=o,n+=i}return r}function T(e,t){let r=t.limit??t.top_k??200,n=t.budget??Number.POSITIVE_INFINITY,o=[],i=2;for(let s of e.slice(0,r)){let a=Buffer.byteLength(JSON.stringify(s)),l=o.length===0?0:1;if(i+a+l>n)break;o.push(s),i+=a+l}return{items:o,total:e.length,truncated:o.length<e.length}}function wp(e,t){let r=he.posix.normalize(e);if(he.posix.extname(r))return t.filter((n)=>n===r);return t.filter((n)=>n===r||n.replace(/\.[^./]+$/u,"")===r||n.startsWith(`${r}/index.`))}function $p(e,t){let r=e.indexOf("*");if(r<0)return e;return`${e.slice(0,r)}${t}${e.slice(r+1)}`}function kp(e,t){return t.flatMap((r)=>{if(!r.hasWildcard)return e===r.prefix?r.targets:[];if(!e.startsWith(r.prefix)||!e.endsWith(r.suffix))return[];let n=r.prefix.length,o=e.length-r.suffix.length;if(o<n)return[];let i=e.slice(n,o);return r.targets.map((s)=>$p(s,i))})}async function Ip(e,t,r,n=[]){let o=e.map((a)=>ce(t,a.path)).sort(),i=e.flatMap((a)=>{I(r);let l=ce(t,a.path);return[...a.facts.imports.map((c)=>({from:l,source:c.source})),...a.facts.exports.filter((c)=>c.source!==null).map((c)=>({from:l,source:c.source}))]}),s=new Map;for(let a of i){I(r);let l=a.source.startsWith(".")?[he.posix.normalize(he.posix.join(he.posix.dirname(a.from),a.source))]:kp(a.source,n),c=[...new Set(l.flatMap((u)=>wp(u,o)))].sort();if(c.length===0){let u={ambiguous:!1,external:!0,from:a.from,to:a.source};s.set(JSON.stringify(u),u);continue}for(let u of c){let p={ambiguous:c.length>1,external:!1,from:a.from,to:u};s.set(JSON.stringify(p),p)}}return[...s.values()].sort((a,l)=>a.from.localeCompare(l.from)||a.to.localeCompare(l.to))}function Pp(e,t,r){let n=new Map;for(let u of e){if(u.external)continue;let p=n.get(u.from)??[];if(!p.includes(u.to))p.push(u.to);n.set(u.from,p.sort())}let o=new Map,i=[],s=new Map,a=new Set,l=(u)=>{let p=u.slice(0,-1),m=p.map((h,y)=>[...p.slice(y),...p.slice(0,y)]).map((h)=>h.join(" -> ")).sort()[0];return`${m} -> ${m?.split(" -> ")[0]??""}`},c=(u)=>{I(r),o.set(u,"active"),s.set(u,i.length),i.push(u);for(let p of n.get(u)??[]){if(a.size>t)break;let f=o.get(p);if(f==="active"){let m=s.get(p);a.add(l([...i.slice(m),p]))}else if(f!=="done")c(p)}i.pop(),s.delete(u),o.set(u,"done")};for(let u of[...n.keys()].sort()){if(a.size>t)break;if(!o.has(u))c(u)}return{cycles:[...a].sort().slice(0,t),truncated:a.size>t}}function Jt(e,t,r){let n=[];for(let o of e)I(t),n.push(...r(o));return n}async function uc(e,t,r,n,o,i){if(e==="squeeze"){I(i);let v=(t.text??t.query??"").replace(/\s+/g," ").trim(),_=t.budget??8000,w=Sp(v,_);return{schema:"ast-mcp.squeeze.v1",text:w,truncated:w!==v}}if(e==="run"&&t.write)throw Object.assign(Error("run write mode is replaced by hash-guarded file_patch with patchStrategy=ast"),{code:"use_file_patch",retryable:!0,suggestedNextCall:"file_hash then file_patch"});let s=`ast-mcp.${e}.v1`;if(e==="map"||e==="digest"){let x=t.max_members??(e==="digest"?50:200),v=Jt(r,i,(w)=>[{diagnostics:w.facts.diagnostics,language:w.facts.languageId,partial:w.facts.partial,path:ce(n,w.path),symbols:nt(w,n).slice(0,x)}]),_=T(v,t);return{files:_.items,schema:s,total:_.total,truncated:_.truncated||r.some((w)=>w.facts.symbols.length>x)}}if(e==="show"){let x=new Set(t.symbols??(t.target?[t.target]:[])),v=r.flatMap((_)=>(I(i),nt(_,n,!0))).filter((_)=>x.size===0||x.has(_.name)||x.has(_.qualifiedName));return{schema:s,...T(v,t)}}if(e==="surface")return{schema:s,...T(r.flatMap((x)=>(I(i),nt(x,n))).filter((x)=>x.exported),t)};if(e==="implements"){let x=t.target??"",v=Jt(r,i,(_)=>[..._.facts.implementations,..._.facts.inheritance].filter((w)=>w.targetName===x||w.targetName.endsWith(`.${x}`)).map((w)=>({path:ce(n,_.path),range:w.range,target:w.targetName})));return{schema:s,...T(v,t)}}if(e==="search"||e==="find_related"){let x=(t.query??t.target??t.path??"").toLowerCase(),v=r.flatMap((_)=>(I(i),nt(_,n,!0))).filter((_)=>_.name.toLowerCase().includes(x)||_.qualifiedName.toLowerCase().includes(x)||_.source?.toLowerCase().includes(x)).map(({source:_,...w})=>({...w,snippet:_?.slice(0,1000)}));return{schema:s,...T(v,t)}}if(e==="run"){if(!t.pattern)throw Error("run requires pattern");let x=[];for(let v of r){if(I(i),!t.rewrite){x.push(...Yr(v.source,v.facts.languageId,t.pattern).map((ge)=>({...ge,path:ce(n,v.path)}))),I(i);continue}I(i);let _=Yr(v.source,v.facts.languageId,t.pattern);I(i);let w=sc(v.source,v.facts.languageId,[{expectedMatches:_.length,pattern:t.pattern,replacement:t.rewrite}]);I(i),x.push(...w.edits.map((ge)=>({...ge,path:ce(n,v.path)})))}return{schema:s,...T(x,t)}}let a=await Ip(r,n,i,o),l=a.filter((x)=>(I(i),(!t.hide_external||!x.external)&&(!t.hide_ambiguous||!x.ambiguous)));if(e==="graph")return{schema:s,...T(l,t)};if(e==="cycles"){let x=t.limit??t.top_k??200,v=Pp(l,x,i),_=T(v.cycles,{...t,budget:t.budget??1e6});return{cycles:_.items,schema:s,truncated:v.truncated||_.truncated}}if(e==="deps"||e==="reverse_deps"){let x=t.file??t.path,v=x?ce(n,he.resolve(n,x)):"",_=l.filter((w)=>e==="deps"?w.from===v:w.to===v);return{schema:s,...T(_,t)}}let c=t.target??"",u=t.detail==="full",p=t.direct?1:t.depth??1,f=ac(r,n,c,"in",p,u,i),m=ac(r,n,c,"out",p,u,i);if(e==="callers")return{schema:s,...T(f,t)};if(e==="callees")return{schema:s,...T(m,t)};if(e==="trace")return{callees:T(m,t),callers:T(f,t),depth:p,schema:s,target:c};let h=a.filter((x)=>(I(i),x.to.includes(c))),y=[...f,...h].filter((x)=>(I(i),("path"in x)&&/(?:^|\/)(?:test|tests|__tests__)(?:\/|$)|\.(?:test|spec)\./.test(x.path)));if(e==="impact")return{callees:T(m,t),callers:T(f,t),dependents:T(h,t),schema:s,target:c,tests:T(y,t)};let b=r.flatMap((x)=>(I(i),cc(x,c).flatMap(()=>(I(i),nt(x,n,!0))))).filter((x)=>x.name===c||x.qualifiedName.endsWith(`.${c}`)),S=t.budget??32000,E={callees:[],callers:[],definitions:[],schema:s,target:c,truncated:!1},X=[...b.map((x)=>["definitions",x]),...f.map((x)=>["callers",x]),...m.map((x)=>["callees",x])];for(let[x,v]of X){I(i);let _={...E,[x]:[...E[x],v]};if(Buffer.byteLength(JSON.stringify(_))>S){E.truncated=!0;break}E[x].push(v)}return E}var Qr=globalThis;Qr.onmessage=async({data:e})=>{try{let t=e.kind==="compiler-config"?Bun.JSONC.parse(e.source):e.kind==="parse"?oc({languageId:e.languageId,source:e.source,maxNodes:1e5}):await uc(e.name,e.input,e.files,e.root,e.aliases),r=Buffer.byteLength(JSON.stringify(t)),n=e.kind==="parse"?e.maxReplyBytes??16777216:16777216;if(r>n)throw Object.assign(Error("Parsed data exceeds the request byte limit; narrow paths, glob, or scan_limit"),{code:"intelligence_budget_exceeded",retryable:!0});Qr.postMessage({ok:!0,value:t,bytes:r})}catch(t){let r=t;Qr.postMessage({ok:!1,error:{code:r.code??"worker_error",message:r.message??"Code intelligence worker failed",retryable:r.retryable??!1}})}};
|
|
60
60
|
|
|
61
|
-
//# debugId=
|
|
61
|
+
//# debugId=C8FF26545261CDC664756E2164756E21
|