var{defineProperty:J,getOwnPropertyNames:Y,getOwnPropertyDescriptor:Z}=Object,_=Object.prototype.hasOwnProperty;function $(h){return this[h]}var S=(h)=>{var j=(Q??=new WeakMap).get(h),z;if(j)return j;if(j=J({},"__esModule",{value:!0}),h&&typeof h==="object"||typeof h==="function"){for(var D of Y(h))if(!_.call(j,D))J(j,D,{get:$.bind(h,D),enumerable:!(z=Z(h,D))||z.enumerable})}return Q.set(h,j),j},Q;var O=(h)=>h;function T(h,j){this[h]=O.bind(null,j)}var U=(h,j)=>{for(var z in j)J(h,z,{get:j[z],enumerable:!0,configurable:!0,set:T.bind(j,z)})};var b=(h,j)=>()=>(h&&(j=h(h=0)),j);var C={};U(C,{groupByToArray:()=>A,groupByMultiple:()=>V,groupBy:()=>I,getUniqueTags:()=>M,getUniqueOwners:()=>q,getUniqueDomains:()=>B,filterBy:()=>L,GroupingStrategies:()=>K});function L(h,j){return h.filter((z)=>{if(j.tags?.length){if(!j.tags.some((E)=>z.meta.tags?.includes(E)))return!1}if(j.owners?.length){if(!j.owners.some((E)=>z.meta.owners?.includes(E)))return!1}if(j.stability?.length){if(!j.stability.includes(z.meta.stability??"stable"))return!1}if(j.domain){if(K.byDomain(z)!==j.domain)return!1}if(j.keyPattern){let D=z.meta.key??z.meta.key??"",E=j.keyPattern.replace(/\*/g,".*").replace(/\?/g,".");if(!new RegExp(`^${E}$`,"i").test(D))return!1}return!0})}function I(h,j){let z=new Map;for(let D of h){let E=j(D),H=z.get(E);if(H)H.push(D);else z.set(E,[D])}return z}function A(h,j){let z=I(h,j);return Array.from(z.entries()).map(([D,E])=>({key:D,items:E}))}function V(h,j){let z=new Map;for(let D of h){let E=j(D);for(let H of E){let P=z.get(H);if(P)P.push(D);else z.set(H,[D])}}return z}function M(h){let j=new Set;for(let z of h)for(let D of z.meta.tags??[])j.add(D);return Array.from(j).sort()}function q(h){let j=new Set;for(let z of h)for(let D of z.meta.owners??[])j.add(D);return Array.from(j).sort()}function B(h){let j=new Set;for(let z of h)j.add(K.byDomain(z));return Array.from(j).sort()}var K;var W=b(()=>{K={byTag:(h)=>h.meta.tags?.[0]??"untagged",byAllTags:(h)=>h.meta.tags?.length?h.meta.tags:["untagged"],byOwner:(h)=>h.meta.owners?.[0]??"unowned",byDomain:(h)=>{return(h.meta.key??h.meta.key??"").split(".")[0]??"default"},byStability:(h)=>h.meta.stability??"stable",byUrlPath:(h)=>(j)=>{if(!j.path)return"root";return j.path.split("/").filter(Boolean).slice(0,h).join("/")||"root"}}});W();import{compareVersions as R}from"compare-versions";var x=(h)=>`${h.meta.key}.v${h.meta.version}`;class N{contractType;items=new Map;constructor(h,j){this.contractType=h;if(j)j.forEach((z)=>this.register(z))}register(h){let j=x(h);if(this.items.has(j))throw Error(`Duplicate contract \`${this.contractType}\` ${j}`);return this.items.set(j,h),this}count(){return this.items.size}list(){return[...this.items.values()]}get(h,j){if(j!=null)return this.items.get(`${h}.v${j}`);let z;for(let[D,E]of this.items.entries()){if(!D.startsWith(`${h}.v`))continue;if(!z||R(E.meta.version,z.meta.version)>0)z=E}return z}has(h,j){return!!this.get(h,j)}filter(h){return L(this.list(),h)}listByTag(h){return this.list().filter((j)=>j.meta.tags?.includes(h))}listByOwner(h){return this.list().filter((j)=>j.meta.owners?.includes(h))}groupBy(h){return I(this.list(),h)}getUniqueTags(){return M(this.list())}}import{compareVersions as G}from"compare-versions";class X extends N{constructor(h){super("agent",h)}listNames(){let h=new Set;for(let j of this.items.values())h.add(j.meta.key);return[...h]}require(h,j){let z=this.get(h,j);if(!z)throw Error(`Agent spec not found for ${h}${j!=null?`.v${j}`:""}`);return z}has(h,j){return this.get(h,j)!==void 0}getVersions(h){let j=[];for(let z of this.items.values())if(z.meta.key===h)j.push(z);return j.sort((z,D)=>G(z.meta.version,D.meta.version))}}function f(){return new X}export{f as createAgentRegistry,X as AgentRegistry};
