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