@uibot/registry 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/component-replacement.d.ts +10 -0
  2. package/dist/index.js +7 -7
  3. package/dist/resources.d.ts +1 -0
  4. package/dist/resources.js +3 -3
  5. package/dist/shadcn/r/admin-shell.json +16 -3
  6. package/dist/shadcn/r/charts.json +44 -17
  7. package/dist/shadcn/r/chat-workspace.json +1 -1
  8. package/dist/shadcn/r/collection-cell-editor.json +1 -1
  9. package/dist/shadcn/r/collection-panel-drawer.json +1 -1
  10. package/dist/shadcn/r/collection-record-menu.json +1 -1
  11. package/dist/shadcn/r/collection-shared.json +1 -1
  12. package/dist/shadcn/r/commerce-workspace.json +1 -1
  13. package/dist/shadcn/r/console-page.json +1 -1
  14. package/dist/shadcn/r/console-shell.json +1 -1
  15. package/dist/shadcn/r/creation-html-generation.json +2 -2
  16. package/dist/shadcn/r/creation-reference-generation.json +2 -2
  17. package/dist/shadcn/r/creation-revision-export.json +2 -2
  18. package/dist/shadcn/r/creation-shared.json +2 -2
  19. package/dist/shadcn/r/creation-variant-compare.json +3 -3
  20. package/dist/shadcn/r/creation-workspace.json +3 -3
  21. package/dist/shadcn/r/crm-workspace.json +1 -1
  22. package/dist/shadcn/r/dashboard-01.json +78 -0
  23. package/dist/shadcn/r/dashboard.json +113 -3
  24. package/dist/shadcn/r/data-table.json +120 -10
  25. package/dist/shadcn/r/data.json +9 -2
  26. package/dist/shadcn/r/document-assistant.json +1 -1
  27. package/dist/shadcn/r/document-workspace.json +1 -1
  28. package/dist/shadcn/r/drilldown-menu.json +1 -1
  29. package/dist/shadcn/r/education-workspace.json +1 -1
  30. package/dist/shadcn/r/feedback.json +15 -2
  31. package/dist/shadcn/r/form.json +1 -1
  32. package/dist/shadcn/r/layout.json +27 -8
  33. package/dist/shadcn/r/nav.json +38 -10
  34. package/dist/shadcn/r/shadcn-admin.json +1 -1
  35. package/dist/shadcn/r/sidebar-primitives.json +1 -1
  36. package/dist/shadcn/r/workspace.json +9 -2
  37. package/dist/shadcn/registry.json +55 -27
  38. package/package.json +2 -2
@@ -0,0 +1,10 @@
1
+ import type { BlockNode, CatalogEntry } from "@uibot/contracts";
2
+ export interface ComponentReplacementTarget {
3
+ component: string;
4
+ variant: string;
5
+ title: string;
6
+ }
7
+ /** Only installed, explicitly compatible components participate. No data is evaluated. */
8
+ export declare function componentReplacementTargets(block: BlockNode, components: Record<string, CatalogEntry>): ComponentReplacementTarget[];
9
+ /** Preserve the complete node and its binding expressions; never silently drop authored fields. */
10
+ export declare function replaceCompatibleComponent(block: BlockNode, components: Record<string, CatalogEntry>, target: Pick<ComponentReplacementTarget, "component" | "variant">, instanceId?: string): BlockNode;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{lstatSync as zr,mkdirSync as at,readFileSync as qr,realpathSync as Hr,writeFileSync as ct}from"fs";import{basename as Kr,dirname as Ie,isAbsolute as Wr,resolve as O,sep as ot}from"path";function mt(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",r=e.manifest.items??[],i=new Map;for(let o of r)i.set(o.name,o);if(e.lockfile===null)return{ok:!1,lockfilePath:t,registryName:e.manifest.name,lockCount:0,manifestCount:r.length,drifts:[{name:"*",kind:"missing-in-lock",detail:"lockfile missing or unreadable"}]};let n=[],a=new Set;for(let o of e.lockfile.artifacts??[]){a.add(o.name);let s=i.get(o.name);if(!s){n.push({name:o.name,kind:"missing-in-manifest",lockVersion:o.version,detail:`locked ${o.name}@${o.version} not present in registry manifest`});continue}let c=ft(s);if(c&&c!==o.version)n.push({name:o.name,kind:"version-mismatch",lockVersion:o.version,manifestVersion:c,detail:`${o.name}: lock ${o.version} \u2260 registry ${c}`})}return{ok:n.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:r.length,drifts:n}}function ft(e){return e.artifact?.version??e.version}function yt(){return{version:1,artifacts:[]}}function ht(e){return{version:1,artifacts:e}}import{readFileSync as bt,realpathSync as we}from"fs";import{resolve as z,relative as Ct,dirname as Rt,extname as xt,sep as pe}from"path";function kt(e){if(e.endsWith(".css"))return"style";if(e.endsWith(".tsx")||e.endsWith(".jsx"))return"component";if(/(^|\/)use-[^/]+\.ts$/.test(e))return"hook";return"lib"}function St(e){let t=e.readFile??((c)=>bt(c,"utf8")),r=new Map,i=(c,l=z(e.sourceDir))=>{let u=Ct(l,z(c));if(u===".."||u.startsWith(`..${pe}`)||u.startsWith(pe))throw Error(`Block dependency outside sourceDir: ${c}`);return u.replaceAll(pe,"/")},n=(c)=>{if(i(z(e.sourceDir,c)),!e.readFile)i(we(z(e.sourceDir,c)),we(e.sourceDir));let l=r.get(c);if(l!==void 0)return l;let u=t(z(e.sourceDir,c));return r.set(c,u),u},a=(c)=>{let l=new Map,u=(f)=>{if(l.has(f))return;let p=n(f);l.set(f,{path:f,type:kt(f),content:p});let d=p.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let m of d){let y=i(z(e.sourceDir,Rt(f),m[1]??"")),h=xt(y)?[y]:[`${y}.ts`,`${y}.tsx`,`${y}/index.ts`,`${y}/index.tsx`],A;for(let N of h)try{n(N),A=N;break}catch(_){if(_ instanceof Error&&_.message.includes("outside sourceDir"))throw _}if(!A)throw Error(`Unresolved block dependency: ${f} -> ${m[1]}`);u(A)}};return u(c),[...l.values()]},o=(c)=>{let l=new Set;for(let u of c){if(typeof u.content!=="string")continue;for(let f of u.content.matchAll(/(?:\bfrom\s*|\bimport\s*)["']([^."'/][^"']*|@[^"']+)["']/g)){let p=f[1]??"";if(p.startsWith("node:"))continue;let d=p.startsWith("@")?p.split("/").slice(0,2).join("/"):p.split("/")[0]??"";if(d==="react"||d==="react-dom"||d.startsWith("@uibot/"))continue;l.add(d)}}return[...l].sort()},s=[];for(let c of Object.keys(e.catalog)){let l=e.blockFileMap[c];if(l===void 0)continue;let u=e.catalog[c];if(u===void 0)continue;let f=n(l),p=a(l),d=o(p);s.push({name:c,category:u.category,description:u.description,sourceCode:f,files:p,catalogEntry:u,...d.length>0?{dependencies:d}:{}})}return s}function Cn(e){return e.flatMap((t)=>St(t))}import{readdirSync as It,readFileSync as At,statSync as wt}from"fs";import{basename as Pt,join as vt}from"path";var Et="0.1.0";function Pe(e){let{dir:t}=e,r;try{r=It(t)}catch{return[]}let i=e.defaultVersion??Et,n=e.defaultLevel??"L4",a=e.defaultCategory??"template",o=[];for(let s of r){if(!/\.ya?ml$/i.test(s))continue;let c=vt(t,s);try{if(!wt(c).isFile())continue}catch{continue}let l=At(c,"utf8");if(!l.trim())continue;let u=Pt(s).replace(/\.ya?ml$/i,""),f=Tt(u),p=Ot(u),d=_t(l)??`${p} template`;o.push({name:f,version:i,title:p,description:d,yaml:l,absolutePath:c,templateContract:{name:f,description:d,level:n,category:a,keywords:[f,u.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:Ft(l)}})}return o.sort((s,c)=>s.name.localeCompare(c.name))}function Dt(e){let t=new Map;for(let r of e)for(let i of Pe(r)){let n=t.get(i.name);if(n)throw Error(`duplicate template source name "${i.name}": ${n.absolutePath} and ${i.absolutePath}`);t.set(i.name,i)}return[...t.values()].sort((r,i)=>r.name.localeCompare(i.name))}function ve(e){return{kind:"template",name:e.name,version:e.version,files:[{path:`${e.name}.yaml`,type:"template",content:e.yaml,target:`${e.name}.yaml`}],templateContract:e.templateContract}}function ge(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:ve(e)}}function Tt(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function Ot(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function _t(e){return(e.match(/^\s*title:\s*["']?(.+?)["']?\s*$/m)??e.match(/^\s*-\s*id:.*\n\s*path:.*\n\s*title:\s*["']?(.+?)["']?\s*$/m))?.[1]?.trim()}function Ft(e){let t=new Set;for(let r of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}for(let r of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}return[...t].sort()}var Mt="0.1.0";function Nt(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??Mt,runtime:t.runtime??"react",files:e.files,...e.dependencies?{dependencies:e.dependencies}:{},...e.registryDependencies?{registryDependencies:e.registryDependencies}:{},...e.catalogEntry.tags?{tags:e.catalogEntry.tags}:{},catalogEntry:e.catalogEntry}}function Ee(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:Nt(e,t)}}function An(e,t){let r={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},i=e.map((a)=>Ee(a,r)),n=(t.templates??[]).map((a)=>ge(a));return{name:t.name,items:[...i,...n]}}function wn(e,t={}){return Ee(e,t)}import{posix as L}from"path";var jt={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},Ri=Array.from(new Set(Object.values(jt).flat()));var De=["component","template","design-guide","example","skill","block","package","theme"],te=["experimental","candidate","recommended"],Te=["declared","verified","external-consumer"],re=["missing","declared","verified","external-consumer"],Y=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],Vt=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([...[["function","functions"],["scenario","scenarios"],["unit","units"],["industry","industries"]].map(([e,t])=>Object.freeze({name:e,property:t,type:"string",multiple:!0,cliEncoding:"comma-separated"})),Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels and fixed snapshot identity/closure without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var me="uibot.registry.item.v1";var $t=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Ai=[...$t,"radius","font-display","font-body","font-mono"];var D=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),k=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Oe=(e)=>D(e)&&Object.entries(e).every(([t,r])=>k(t)&&k(r));function Li(e){if(e.composition===void 0)return;let t=e.composition;if(!D(t)||t.schema!=="uibot.solution-composition.v1"||!Array.isArray(t.pages))throw Error("invalid-solution-composition");let r=new Set;for(let i of t.pages){if(!D(i)||!k(i.resourceId)||!k(i.version)||typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)||!k(i.sourcePageId)||!k(i.targetPageId)||r.has(i.targetPageId)||!D(i.baseline)||i.baseline.id!==i.targetPageId||typeof i.baseline.path!=="string"||!Array.isArray(i.baseline.blocks)||!D(i.bindings)||!["source","target"].includes(String(i.bindings.layout))||!Oe(i.bindings.paths)||!Oe(i.bindings.connections)||i.bindings.frame!==void 0&&(!D(i.bindings.frame)||Object.keys(i.bindings.frame).some((n)=>!["props","slots","events"].includes(n)))||i.detached!==void 0&&typeof i.detached!=="boolean"||i.configuration!==void 0&&(!D(i.configuration)||Object.entries(i.configuration).some(([n,a])=>!k(n)||!["string","number","boolean"].includes(typeof a)||typeof a==="number"&&!Number.isFinite(a))))throw Error("invalid-solution-adoption");r.add(i.targetPageId)}if(t.regions!==void 0){if(!Array.isArray(t.regions))throw Error("invalid-solution-regions");let i=new Set;for(let n of t.regions){if(!D(n)||!k(n.resourceId)||!k(n.version)||typeof n.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(n.sourceHash)||!k(n.targetPageId)||i.has(n.targetPageId)||!k(n.role)||n.target!=="page-frame"||!k(n.contentBlockId)||!D(n.baseline)||!k(n.baseline.type))throw Error("invalid-solution-region");i.add(n.targetPageId)}}}var Ut="https://ui.shadcn.com/schema/registry.json",zt="https://ui.shadcn.com/schema/registry-item.json",qt=["clsx","tailwind-merge"],Ht="components/uibot",Kt="lib",Wt="@uibot",Gt="uibot/templates",fe="uibot-base",_e="uibot-theme";function ye(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Fe(e,t){let r=e.sourceCode;if(r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(o,s,c)=>`import ${s??"type "}${c} from "${t.rendererShimImport}";`),t.contractsShimImport){let o=t.contractsShimImport;r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(s,c,l)=>`import ${c??"type "}${l} from "${o}";`)}let i=new Set,n=new Set(["Children","Component","PureComponent","Fragment","StrictMode","Profiler","Suspense","Activity","ViewTransition"]);r=r.replace(/\bReact\.([A-Z]\w*)/g,(o,s)=>{if(n.has(s))return o;return i.add(s),s});let a=!1;if(r=r.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(a=!0,`
2
+ import{lstatSync as Hr,mkdirSync as at,readFileSync as Kr,realpathSync as Wr,writeFileSync as ct}from"fs";import{basename as Gr,dirname as Se,isAbsolute as Yr,resolve as O,sep as ot}from"path";function mt(e){let t=e.lockfilePath??"uibot.artifacts.lock.json",r=e.manifest.items??[],i=new Map;for(let o of r)i.set(o.name,o);if(e.lockfile===null)return{ok:!1,lockfilePath:t,registryName:e.manifest.name,lockCount:0,manifestCount:r.length,drifts:[{name:"*",kind:"missing-in-lock",detail:"lockfile missing or unreadable"}]};let n=[],a=new Set;for(let o of e.lockfile.artifacts??[]){a.add(o.name);let s=i.get(o.name);if(!s){n.push({name:o.name,kind:"missing-in-manifest",lockVersion:o.version,detail:`locked ${o.name}@${o.version} not present in registry manifest`});continue}let c=ft(s);if(c&&c!==o.version)n.push({name:o.name,kind:"version-mismatch",lockVersion:o.version,manifestVersion:c,detail:`${o.name}: lock ${o.version} \u2260 registry ${c}`})}return{ok:n.length===0,lockfilePath:t,registryName:e.manifest.name,lockCount:(e.lockfile.artifacts??[]).length,manifestCount:r.length,drifts:n}}function ft(e){return e.artifact?.version??e.version}function yt(){return{version:1,artifacts:[]}}function ht(e){return{version:1,artifacts:e}}import{readFileSync as bt,realpathSync as we}from"fs";import{resolve as z,relative as Ct,dirname as Rt,extname as xt,sep as pe}from"path";function kt(e){if(e.endsWith(".css"))return"style";if(e.endsWith(".tsx")||e.endsWith(".jsx"))return"component";if(/(^|\/)use-[^/]+\.ts$/.test(e))return"hook";return"lib"}function It(e){let t=e.readFile??((c)=>bt(c,"utf8")),r=new Map,i=(c,l=z(e.sourceDir))=>{let u=Ct(l,z(c));if(u===".."||u.startsWith(`..${pe}`)||u.startsWith(pe))throw Error(`Block dependency outside sourceDir: ${c}`);return u.replaceAll(pe,"/")},n=(c)=>{if(i(z(e.sourceDir,c)),!e.readFile)i(we(z(e.sourceDir,c)),we(e.sourceDir));let l=r.get(c);if(l!==void 0)return l;let u=t(z(e.sourceDir,c));return r.set(c,u),u},a=(c)=>{let l=new Map,u=(f)=>{if(l.has(f))return;let p=n(f);l.set(f,{path:f,type:kt(f),content:p});let d=p.matchAll(/(?:\bfrom\s*|\bimport\s*)["'](\.[^"']+)["']/g);for(let m of d){let y=i(z(e.sourceDir,Rt(f),m[1]??"")),h=xt(y)?[y]:[`${y}.ts`,`${y}.tsx`,`${y}/index.ts`,`${y}/index.tsx`],A;for(let N of h)try{n(N),A=N;break}catch(_){if(_ instanceof Error&&_.message.includes("outside sourceDir"))throw _}if(!A)throw Error(`Unresolved block dependency: ${f} -> ${m[1]}`);u(A)}};return u(c),[...l.values()]},o=(c)=>{let l=new Set;for(let u of c){if(typeof u.content!=="string")continue;for(let f of u.content.matchAll(/(?:\bfrom\s*|\bimport\s*)["']([^."'/][^"']*|@[^"']+)["']/g)){let p=f[1]??"";if(p.startsWith("node:"))continue;let d=p.startsWith("@")?p.split("/").slice(0,2).join("/"):p.split("/")[0]??"";if(d==="react"||d==="react-dom"||d.startsWith("@uibot/"))continue;l.add(d)}}return[...l].sort()},s=[];for(let c of Object.keys(e.catalog)){let l=e.blockFileMap[c];if(l===void 0)continue;let u=e.catalog[c];if(u===void 0)continue;let f=n(l),p=a(l),d=o(p);s.push({name:c,category:u.category,description:u.description,sourceCode:f,files:p,catalogEntry:u,...d.length>0?{dependencies:d}:{}})}return s}function xn(e){return e.flatMap((t)=>It(t))}import{readdirSync as St,readFileSync as At,statSync as wt}from"fs";import{basename as Pt,join as vt}from"path";var Et="0.1.0";function Pe(e){let{dir:t}=e,r;try{r=St(t)}catch{return[]}let i=e.defaultVersion??Et,n=e.defaultLevel??"L4",a=e.defaultCategory??"template",o=[];for(let s of r){if(!/\.ya?ml$/i.test(s))continue;let c=vt(t,s);try{if(!wt(c).isFile())continue}catch{continue}let l=At(c,"utf8");if(!l.trim())continue;let u=Pt(s).replace(/\.ya?ml$/i,""),f=Tt(u),p=Ot(u),d=_t(l)??`${p} template`;o.push({name:f,version:i,title:p,description:d,yaml:l,absolutePath:c,templateContract:{name:f,description:d,level:n,category:a,keywords:[f,u.toLowerCase(),"uibot-template",...e.extraKeywords??[]],composedFrom:Ft(l)}})}return o.sort((s,c)=>s.name.localeCompare(c.name))}function Dt(e){let t=new Map;for(let r of e)for(let i of Pe(r)){let n=t.get(i.name);if(n)throw Error(`duplicate template source name "${i.name}": ${n.absolutePath} and ${i.absolutePath}`);t.set(i.name,i)}return[...t.values()].sort((r,i)=>r.name.localeCompare(i.name))}function ve(e){return{kind:"template",name:e.name,version:e.version,files:[{path:`${e.name}.yaml`,type:"template",content:e.yaml,target:`${e.name}.yaml`}],templateContract:e.templateContract}}function ge(e){return{name:e.name,kind:"template",title:e.title,description:e.description,artifact:ve(e)}}function Tt(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-|-$/g,"").toLowerCase()}function Ot(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,(t)=>t.toUpperCase())}function _t(e){return(e.match(/^\s*title:\s*["']?(.+?)["']?\s*$/m)??e.match(/^\s*-\s*id:.*\n\s*path:.*\n\s*title:\s*["']?(.+?)["']?\s*$/m))?.[1]?.trim()}function Ft(e){let t=new Set;for(let r of e.matchAll(/^\s*-\s*type:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}for(let r of e.matchAll(/^\s*template:\s*["']?([^"'#\n]+?)["']?\s*$/gm)){let i=r[1]?.trim();if(i)t.add(i)}return[...t].sort()}var Mt="0.1.0";function Nt(e,t={}){return{kind:"component",name:e.name,version:t.defaultVersion??Mt,runtime:t.runtime??"react",files:e.files,...e.dependencies?{dependencies:e.dependencies}:{},...e.registryDependencies?{registryDependencies:e.registryDependencies}:{},...e.catalogEntry.tags?{tags:e.catalogEntry.tags}:{},catalogEntry:e.catalogEntry}}function Ee(e,t={}){return{name:e.name,kind:"component",title:e.catalogEntry.name,description:e.description??e.catalogEntry.description,artifact:Nt(e,t)}}function Pn(e,t){let r={...t.runtime?{runtime:t.runtime}:{},...t.defaultVersion?{defaultVersion:t.defaultVersion}:{}},i=e.map((a)=>Ee(a,r)),n=(t.templates??[]).map((a)=>ge(a));return{name:t.name,items:[...i,...n]}}function vn(e,t={}){return Ee(e,t)}import{posix as L}from"path";var Bt={spec:["html","markdown","zip"],prototype:["html","zip"],deck:["html","pptx","zip"],poster:["html","zip"]},ki=Array.from(new Set(Object.values(Bt).flat()));var De=["component","template","design-guide","example","skill","block","package","theme"],te=["experimental","candidate","recommended"],Te=["declared","verified","external-consumer"],re=["missing","declared","verified","external-consumer"],Y=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure","packed-install","typecheck","browser"],Vt=Object.freeze([Object.freeze({name:"manifest",summary:"Describe query operations and list the derived resource index.",positionals:Object.freeze([]),options:Object.freeze([])}),Object.freeze({name:"search",summary:"Search resources with deterministic bilingual ranking and reasons.",positionals:Object.freeze([Object.freeze({name:"text",property:"text",type:"string",required:!1})]),options:Object.freeze([...[["function","functions"],["scenario","scenarios"],["unit","units"],["industry","industries"]].map(([e,t])=>Object.freeze({name:e,property:t,type:"string",multiple:!0,cliEncoding:"comma-separated"})),Object.freeze({name:"kind",property:"kinds",type:"resource-kind",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"tag",property:"tags",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"category",property:"categories",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"capability",property:"capabilities",type:"string",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"maturity",property:"maturities",type:"resource-maturity",multiple:!0,cliEncoding:"comma-separated"}),Object.freeze({name:"limit",property:"limit",type:"positive-integer"})])}),Object.freeze({name:"get",summary:"Resolve one canonical resource id or unambiguous alias.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])}),Object.freeze({name:"build",summary:"Plan dependency closure and gaps without writing or installing.",positionals:Object.freeze([Object.freeze({name:"root",property:"roots",type:"string",required:!0,variadic:!0})]),options:Object.freeze([])}),Object.freeze({name:"docs",summary:"Read curated public documentation for one resource.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"locale",property:"locale",type:"string"},{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"examples",summary:"Read one bounded page of examples and exact dependencies. Follow nextPage for complete source.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([{name:"page",property:"page",type:"positive-integer"}])}),Object.freeze({name:"install-plan",summary:"Describe distribution channels and fixed snapshot identity/closure without installing or writing.",positionals:Object.freeze([Object.freeze({name:"id-or-alias",property:"id",type:"string",required:!0})]),options:Object.freeze([])})]);var me="uibot.registry.item.v1";var $t=["background","foreground","card","card-foreground","popover","popover-foreground","primary","primary-foreground","secondary","secondary-foreground","muted","muted-foreground","accent","accent-foreground","border","input","ring","destructive","destructive-foreground","success","success-foreground","warning","warning-foreground"],Pi=[...$t,"radius","font-display","font-body","font-mono"];var D=(e)=>!!e&&typeof e==="object"&&!Array.isArray(e),k=(e)=>typeof e==="string"&&e.length>0&&!["__proto__","prototype","constructor"].includes(e),Oe=(e)=>D(e)&&Object.entries(e).every(([t,r])=>k(t)&&k(r));function Bi(e){if(e.composition===void 0)return;let t=e.composition;if(!D(t)||t.schema!=="uibot.solution-composition.v1"||!Array.isArray(t.pages))throw Error("invalid-solution-composition");let r=new Set;for(let i of t.pages){if(!D(i)||!k(i.resourceId)||!k(i.version)||typeof i.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(i.sourceHash)||!k(i.sourcePageId)||!k(i.targetPageId)||r.has(i.targetPageId)||!D(i.baseline)||i.baseline.id!==i.targetPageId||typeof i.baseline.path!=="string"||!Array.isArray(i.baseline.blocks)||!D(i.bindings)||!["source","target"].includes(String(i.bindings.layout))||!Oe(i.bindings.paths)||!Oe(i.bindings.connections)||i.bindings.frame!==void 0&&(!D(i.bindings.frame)||Object.keys(i.bindings.frame).some((n)=>!["props","slots","events"].includes(n)))||i.detached!==void 0&&typeof i.detached!=="boolean"||i.configuration!==void 0&&(!D(i.configuration)||Object.entries(i.configuration).some(([n,a])=>!k(n)||!["string","number","boolean"].includes(typeof a)||typeof a==="number"&&!Number.isFinite(a))))throw Error("invalid-solution-adoption");r.add(i.targetPageId)}if(t.regions!==void 0){if(!Array.isArray(t.regions))throw Error("invalid-solution-regions");let i=new Set;for(let n of t.regions){if(!D(n)||!k(n.resourceId)||!k(n.version)||typeof n.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(n.sourceHash)||!k(n.targetPageId)||i.has(n.targetPageId)||!k(n.role)||n.target!=="page-frame"||!k(n.contentBlockId)||!D(n.baseline)||!k(n.baseline.type))throw Error("invalid-solution-region");i.add(n.targetPageId)}}}var zt="https://ui.shadcn.com/schema/registry.json",qt="https://ui.shadcn.com/schema/registry-item.json",Ht=["clsx","tailwind-merge"],Kt="components/uibot",Wt="lib",Gt="@uibot",Yt="uibot/templates",fe="uibot-base",_e="uibot-theme";function ye(e){return e.replace(/\./g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Fe(e,t){let r=e.sourceCode;if(r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/renderer-react["'];?/g,(o,s,c)=>`import ${s??"type "}${c} from "${t.rendererShimImport}";`),t.contractsShimImport){let o=t.contractsShimImport;r=r.replace(/import\s+(type\s+)?(\{[^}]*\})\s+from\s+["']@uibot\/contracts["'];?/g,(s,c,l)=>`import ${c??"type "}${l} from "${o}";`)}let i=new Set,n=new Set(["Children","Component","PureComponent","Fragment","StrictMode","Profiler","Suspense","Activity","ViewTransition"]);r=r.replace(/\bReact\.([A-Z]\w*)/g,(o,s)=>{if(n.has(s))return o;return i.add(s),s});let a=!1;if(r=r.replace(/(?:^|\n)function cn\([\s\S]*?\)\s*(?::[^\n{]+)?\{[\s\S]*?\n\}\n?/,()=>(a=!0,`
3
3
  `)),a){let o=`import { cn } from "${t.cnUtilImport}";
4
4
  `,s=r.indexOf(`
5
5
  `,r.indexOf("import "));if(s>=0)r=`${r.slice(0,s+1)}${o}${r.slice(s+1)}`;else r=o+r}if(i.size>0){let o=[...i].sort().join(", "),s=/import\s+type\s+\{([^}]*)\}\s+from\s+["']react["'];?/;if(s.test(r))r=r.replace(s,(c,l)=>`import type { ${[...new Set([...l.split(",").map((f)=>f.trim()).filter(Boolean),...i])].sort().join(", ")} } from "react";`);else{let c=`import type { ${o} } from "react";
@@ -7,9 +7,9 @@ import{lstatSync as zr,mkdirSync as at,readFileSync as qr,realpathSync as Hr,wri
7
7
  `,r.indexOf("import "));if(l>=0)r=`${r.slice(0,l+1)}${c}${r.slice(l+1)}`;else r=c+r}}return`${r.replace(/\n{3,}/g,`
8
8
 
9
9
  `).trimStart().trimEnd()}
10
- `}function Yt(e){let t={category:e.category,level:e.level};if(e.props)t.props=e.props;if(e.slots)t.slots=e.slots;if(e.events)t.events=e.events;if(e.usageScenarios)t.scenarios=e.usageScenarios;if(e.constraints)t.constraints=e.constraints;return t}function ts(e){return{light:Me(e,":root"),dark:Me(e,".dark")}}function Me(e,t){let r={},i=new RegExp(`${Le(t)}\\s*\\{`,"g"),n;while((n=i.exec(e))!==null){let a=n.index+n[0].length,o=1,s=a;for(;s<e.length&&o>0;s++){let l=e[s];if(l==="{")o++;else if(l==="}")o--}let c=e.slice(a,s-1);for(let l of c.matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)){let u=l[1],f=l[2];if(u!==void 0&&f!==void 0)r[u]=f.trim()}}return r}function Le(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rs(e,t){let r=t.sharedDependencies??qt,i=t.channel??"public",n=Zt(t),a=(t.componentsDir??Ht).replace(/\/$/,""),o=(t.libDir??Kt).replace(/\/$/,""),s=`${o}/uibot-renderer.ts`,c=`${o}/utils.ts`,l=`${o}/uibot-contracts.ts`,u="@/lib/uibot-renderer",f="@/lib/utils",p="@/lib/uibot-contracts",d={},m={name:fe,type:"registry:lib",description:"UIBot runtime base: RendererComponent type shim + cn util. Pulled automatically by every UIBot block.",dependencies:r,files:[{path:s,content:t.rendererShimContent,type:"registry:lib"},{path:c,content:t.cnUtilContent,type:"registry:lib"},...t.contractsShimContent?[{path:l,content:t.contractsShimContent,type:"registry:lib"}]:[]],meta:{base:!0}};if(d[fe]=m,t.cssVars)d[_e]={name:_e,type:"registry:theme",description:"UIBot OKLCH palette for the semantic tokens the blocks use. Optional: skip it when the host defines its own.",files:[],cssVars:t.cssVars};let y=new Map,h=new Map,A=new Map,N=new Map;for(let g of e){let v=g.files[0]?.path??`${ye(g.name)}.tsx`,x=g.channel??"public",b=N.get(v);if(b&&b!==x)throw Error(`${v} mixes ${b} and ${x} blocks; split the file`);N.set(v,x)}for(let g of e){if((g.channel??"public")!==i)continue;let x=g.files[0]?.path??`${ye(g.name)}.tsx`,b=y.get(x);if(!b){let R=ye(rr(x,g.name)),ee=Fe(g,{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),F=`${a}/${R}.tsx`,W={schema:me,item:R,channel:i,components:[]};A.set(R,W),b={name:R,type:"registry:ui",description:g.description??g.catalogEntry.description,dependencies:["react",...g.dependencies??[]],registryDependencies:[n(fe)],files:g.files.length<=1?[{path:F,target:F,content:ee,type:"registry:ui"}]:g.files.map((G)=>{if(typeof G.content!=="string")throw Error(`Missing block source content: ${G.path}`);let Ae=`${a}/${G.path.replace(/^blocks\//,"")}`;return{path:Ae,target:Ae,content:Fe({...g,sourceCode:tr(G.path,G.content,g)},{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),type:"registry:ui"}}),meta:{...Yt(g.catalogEntry),provides:[g.name],uibot:W}},y.set(x,b),d[R]=b}else{let R=b.meta;if(R.provides&&!R.provides.includes(g.name))R.provides.push(g.name)}let E=A.get(b.name);if(E?.components&&!h.has(g.name))E.components.push(Xt(g,b,a)),h.set(g.name,b.name)}for(let[g,v]of A){let x=d[g];if(!x)continue;v.components?.sort((E,R)=>E.name.localeCompare(R.name));let b=`${a}/${g}.uibot.json`;x.files.push({path:b,target:b,content:`${JSON.stringify(v,null,2)}
11
- `,type:"registry:ui"})}let _={},ue=(t.templates??[]).filter((g)=>(g.channel??"public")===i),gt=new Set(ue.map((g)=>g.name));for(let g of ue){if(d[g.name])throw Error(`template item "${g.name}" collides with a component item`);let v=g.templateContract.composedFrom??[],x=new Set,b=[];for(let F of v){let W=h.get(F);if(W)x.add(n(W));else if(gt.has(F)&&F!==g.name)x.add(n(F));else b.push(F)}if(b.length>0)_[g.name]=b;let E=`${o}/${Gt}`,R=`${g.name}.uibot.yaml`,ee={schema:me,item:g.name,channel:i,template:{file:R,contract:g.templateContract}};d[g.name]={name:g.name,type:"registry:block",description:g.description,registryDependencies:[...x].sort(),files:[{path:`${E}/${R}`,target:`${E}/${R}`,content:g.yaml,type:"registry:lib"},{path:`${E}/${g.name}.uibot.json`,target:`${E}/${g.name}.uibot.json`,content:`${JSON.stringify(ee,null,2)}
12
- `,type:"registry:lib"}],meta:{uibot:ee}}}return Jt(d,t.composites??[],{channel:i,ref:n,componentsDir:a}),{registry:{$schema:Ut,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(d).map((g)=>({name:g.name,type:g.type,...g.description?{description:g.description}:{},...g.registryDependencies?{registryDependencies:g.registryDependencies}:{},...g.dependencies?{dependencies:g.dependencies}:{}}))},items:d,unresolvedTemplateTypes:_}}function Jt(e,t,r){let i=new Map;for(let n of t){if(i.has(n.name)||e[n.name])throw Error(`composite item "${n.name}" collides with another item`);i.set(n.name,n)}for(let n of t){let a=n.channel??"public",o=Ne(n),s=new Set(n.files.map((l)=>l.path));for(let l of n.requires??[]){let u=i.get(l);if(!u)throw Error(`composite "${n.name}" requires unknown "${l}"`);if((u.channel??"public")!==a)throw Error(`composite "${n.name}" (${a}) requires "${l}" from another channel`);if(Ne(u)!==o)throw Error(`composite "${n.name}" requires "${l}" from another directory`);for(let f of u.files)s.add(f.path)}for(let l of n.files){if(!Be.test(l.path))throw Error(`composite "${n.name}" file "${l.path}" must be a plain relative path`);for(let u of Qt(l.content)){if(!u.startsWith("./")||u.includes("/../"))throw Error(`${n.name}/${l.path} imports ${u}; only ./ imports within the item directory are allowed`);let f=u.slice(2).replace(/\.js$/,"");if(![f,`${f}.ts`,`${f}.tsx`,`${f}/index.ts`,`${f}/index.tsx`].some((d)=>s.has(d)))throw Error(`${n.name}/${l.path} imports ${u}, which no required item ships`)}}if(a!==r.channel)continue;let c=n.files.map((l)=>{let u=`${r.componentsDir}/${o}/${l.path}`;return{path:u,target:u,content:l.content,type:l.path.endsWith(".tsx")?"registry:component":"registry:lib"}});e[n.name]={name:n.name,type:n.type,description:n.description,dependencies:["react",...n.dependencies??[]],registryDependencies:[...n.primitives??[],...(n.requires??[]).map(r.ref)],files:c,meta:{composite:!0,channel:a}}}}var Be=/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/i;function Ne(e){if(!Be.test(e.dir)||e.dir.split("/").includes(".."))throw Error(`composite "${e.name}" dir "${e.dir}" must be a plain relative path`);return e.dir}function Qt(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),r=[],i=[/\bfrom\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g];for(let n of i)for(let a of t.matchAll(n))r.push(a[1]??"");return r}function Zt(e){if(e.baseUrl){let r=e.baseUrl.replace(/\/$/,"");return(i)=>`${r}/r/${i}.json`}let t=e.namespace??Wt;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(r)=>`${t}/${r}`}function Xt(e,t,r){let i=e.name.replace(/\./g,""),n=`${r}/`,a=t.files.find((o)=>o.path.startsWith(n)&&/\.(tsx|ts)$/.test(o.path)&&er(o.content,i));if(!a)throw Error(`block "${e.name}" has no named export "${i}" in item "${t.name}"`);return{name:e.name,export:i,module:a.path.slice(n.length),catalog:e.catalogEntry}}function er(e,t){let r=Le(t),i=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${r}\\b`).test(i))return!0;for(let n of i.matchAll(/export\s*\{([^}]*)\}/g)){let a=(n[1]??"").split(",").map((s)=>{let[,c]=s.trim().split(/\s+as\s+/);return(c??s.trim().replace(/^type\s+/,"")).trim()}),o=(n[1]??"").split(",").map((s)=>s.trim()).filter((s)=>s.startsWith("type ")).map((s)=>s.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!o.includes(t))return!0}return!1}function tr(e,t,r){let i=new Set(r.files.map((a)=>a.path)),n=(a)=>a.replace(/^blocks\//,"");return t.replace(/((?:\bfrom\s*|\bimport\s*)["'])(\.[^"']+)(["'])/g,(a,o,s,c)=>{let l=L.normalize(L.join(L.dirname(e),s)),f=(L.extname(l)?[l]:[l,`${l}.ts`,`${l}.tsx`,`${l}/index.ts`,`${l}/index.tsx`]).find((d)=>i.has(d));if(!f)return a;let p=L.relative(L.dirname(n(e)),n(f));if(!L.extname(s))p=p.replace(/\.(tsx?|jsx?)$/,"");if(!p.startsWith("."))p=`./${p}`;return o+p+c})}function rr(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var ns=zt;function nr(e="/api/registry"){let t=(e||"/api/registry").trim(),r=t.startsWith("/")?t:`/${t}`;return r.length>1?r.replace(/\/$/,""):r}function J(e,t=200){return Response.json(e,{status:t})}function os(e){let t=nr(e.basePath),r=`${t}/registry.json`,i=`${t}/artifacts/`,n=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(o){let s=new URL(o.url);if(o.method!=="GET")return J({error:"Method not allowed"},405);if(s.pathname===r)return J(e.manifest);if(s.pathname.startsWith(i)){let c=s.pathname.slice(i.length),l=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),u=n.get(l);if(!u)return J({error:`Artifact '${l}' not found`},404);return J(u)}return J({error:"Not found"},404)}}var he="uibot.resource.admission.v1",ir=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],or=["packed-install","typecheck","browser"],cs=["invalid-admission-manifest","invalid-admission-record","invalid-admission-check","duplicate-admission-record","unknown-admission-resource","missing-source-metadata","missing-license-metadata","dependency-closure-failed"];class je extends Error{expected;actual;code="resource-admission-index-mismatch";constructor(e,t){super(`resource admission index mismatch: expected ${e}, received ${t}`);this.expected=e;this.actual=t;this.name="ResourceAdmissionIndexMismatchError"}}class Ve extends Error{issueCount;code="resource-admission-report-rejected";constructor(e){super(`resource admission report contains ${e.toString()} issue(s)`);this.issueCount=e;this.name="ResourceAdmissionReportRejectedError"}}class $e extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var sr=new Set(Y),ar=new Set(re),Ue=new WeakSet,ne={missing:0,declared:1,verified:2,"external-consumer":3};function cr(e,t){return e<t?-1:e>t?1:0}function q(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function ie(e,t){let r=new Set(t);return Object.keys(e).every((i)=>r.has(i))}function ze(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(cr)}function lr(e,t,r,i){if(!q(r)||!ie(r,["status","evidence"])){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!ar.has(r.status)||r.status==="missing"){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} status must be declared, verified or external-consumer`});return}if(!Array.isArray(r.evidence)||r.evidence.length===0||r.evidence.some((n)=>typeof n!=="string"||!n.trim())){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} evidence must be a non-empty string array`});return}return{status:r.status,evidence:ze(r.evidence)}}function dr(e){if(e===void 0)return;if(!q(e)||!ie(e,["source","version","license"]))return;if(Object.values(e).some((r)=>r!==void 0&&typeof r!=="string"))return;return{...typeof e.source==="string"&&e.source.trim()?{source:e.source.trim()}:{},...typeof e.version==="string"&&e.version.trim()?{version:e.version.trim()}:{},...typeof e.license==="string"&&e.license.trim()?{license:e.license.trim()}:{}}}function ur(e,t){let r=new Map,i=[];if(!q(t)||!ie(t,["schemaVersion","records"])||t.schemaVersion!==he||!Array.isArray(t.records))return i.push({code:"invalid-admission-manifest",detail:`expected ${he} with a records array`}),{records:r,issues:i};let n=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!q(a)||!ie(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!q(a.checks)){i.push({code:"invalid-admission-record",...q(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let o=a.resourceId.trim();if(r.has(o)){i.push({code:"duplicate-admission-record",resourceId:o,detail:o});continue}if(!n.has(o)){i.push({code:"unknown-admission-resource",resourceId:o,detail:o});continue}let s=dr(a.provenance);if(a.provenance!==void 0&&!s){i.push({code:"invalid-admission-record",resourceId:o,detail:"provenance must contain only string source, version and license fields"});continue}let c={},l=!1;for(let[u,f]of Object.entries(a.checks)){if(!sr.has(u)){i.push({code:"invalid-admission-check",resourceId:o,detail:`unknown receipt check: ${u}`}),l=!0;continue}let p=u,d=lr(o,p,f,i);if(d)c[p]=d;else l=!0}if(l)continue;r.set(o,{resourceId:o,...s?{provenance:s}:{},checks:c})}return{records:r,issues:i}}function pr(e){let t=new Map(e.resources.map((n)=>[n.id,n])),r=new Map;function i(n,a,o,s){if(r.has(n)||s.has(a))return;if(o.has(a)){r.set(n,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(n,`missing dependency ${a}`);return}o.add(a);for(let l of c.dependencies)if(i(n,l,o,s),r.has(n))break;o.delete(a),s.add(a)}for(let n of e.resources)i(n.id,n.id,new Set,new Set);return r}var gr=/^(unknown|unlicensed|none|n\/?a)$/i,mr=/^SPDX-License-Identifier:\s*(\S+)/im,fr=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function B(e){let t=e?.trim();if(!t||gr.test(t))return;return t}function yr(e){if(!e?.trim())return;let t=e.match(mr)?.[1];if(t)return B(t);let r=e.match(fr)?.[1];if(!r)return;let i=r.toLowerCase();if(i.startsWith("mit"))return"MIT";if(i.startsWith("apache"))return"Apache-2.0";if(i.startsWith("bsd-2"))return"BSD-2-Clause";if(i.startsWith("bsd-3"))return"BSD-3-Clause";if(i==="isc")return"ISC";if(i==="unlicense")return"Unlicense";return}function ls(e){return B(e.frontmatterLicense)??B(e.packageJsonLicense)??yr(e.licenseFileText)}function qe(e){return Boolean(B(e))}var Q={states:/\b(disabled|loading|error|empty|pending|busy|children|active|muted|boolean-state)\b/i,accessibility:/\b(label|aria|accessible|alt|role)\b/i,"light-theme":/:root\b|\b(light(?:-theme)?|theme token|css variables?)\b/i,"dark-theme":/\b(dark(?:-theme)?)\b/i,responsive:/\b(size|responsive|breakpoint|sm|md|lg|xl|full)\b/i};function be(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let i of e)be(i,t);return}let r=e;for(let[i,n]of Object.entries(r)){if(t.push(i),i==="type"&&n==="boolean")t.push("boolean-state");be(n,t)}}function hr(e){let t=[];return be(e.props,t),[e.name,e.description,...e.tags??[],...e.usageScenarios??[],...e.constraints??[],...t,...Object.keys(e.slots??{}),...Object.keys(e.events??{}),e.slots&&Object.keys(e.slots).length>0?"empty":""].join(`
13
- `)}function ds(e,t={}){let r=[hr(e),t.sourceText??"",t.stylesText??""].join(`
14
- `);return{contract:Boolean(e.props&&Object.keys(e.props).length>0||e.events&&Object.keys(e.events).length>0||e.slots&&Object.keys(e.slots).length>0)?"verified":"declared",states:Q.states.test(r)?"verified":"missing",accessibility:Q.accessibility.test(r)?"verified":"missing","light-theme":Q["light-theme"].test(r)?"verified":"missing","dark-theme":Q["dark-theme"].test(r)?"verified":"missing",responsive:Q.responsive.test(r)?"verified":"missing"}}function br(e){return{source:"declared",license:qe(e.source.license)?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"}}function Cr(e){if(!ir.every((i)=>ne[e[i]]>=ne.verified))return"experimental";return or.every((i)=>e[i]==="external-consumer")?"recommended":"candidate"}function He(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((n)=>({id:n.id,kind:n.kind,title:n.title,description:n.description,...n.category?{category:n.category}:{},tags:n.tags,aliases:n.aliases,capabilities:n.capabilities,dependencies:n.dependencies,source:n.source})),aliases:e.aliases}),r=0xcbf29ce484222325n,i=0x100000001b3n;for(let n of new TextEncoder().encode(t))r^=BigInt(n),r=BigInt.asUintN(64,r*i);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function Rr(e,t,r){let i=br(e),n=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],a=[];if(r)a.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:r});else i["dependency-closure"]="verified",n.push(`resource://index/${e.id}`);if(t)for(let c of Y){if(c==="dependency-closure")continue;let l=t.checks[c];if(!l)continue;if(c==="source"&&ne[l.status]>=ne.verified&&(!t.provenance?.source||!t.provenance.version)){a.push({code:"missing-source-metadata",resourceId:e.id,check:c,detail:"verified source requires provenance.source and provenance.version"});continue}if(c==="license"&&!qe(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(i[c]=l.status,n.push(...l.evidence),c==="source"&&t.provenance?.source)n.push(t.provenance.source)}let o=Cr(i),s={level:o==="recommended"?"external-consumer":o==="candidate"?"verified":"declared",maturity:o,checks:i,evidence:ze(n)};return Object.freeze(s.checks),Object.freeze(s.evidence),Object.freeze(s),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:s,issues:a})}function us(e,t){let r=ur(e,t),i=pr(e),n=e.resources.map((c)=>Rr(c,r.records.get(c.id),i.get(c.id))),a=[...r.issues,...n.flatMap((c)=>c.issues)],o=Object.fromEntries(te.map((c)=>[c,0]));for(let c of n)o[c.receipt.maturity]+=1;Object.freeze(n),Object.freeze(o);for(let c of a)Object.freeze(c);Object.freeze(a);let s=Object.freeze({schemaVersion:he,indexFingerprint:He(e),resources:n,counts:o,issues:a});return Ue.add(s),s}function ps(e,t){if(!Ue.has(t))throw new $e;if(t.issues.length>0)throw new Ve(t.issues.length);let r=He(e);if(r!==t.indexFingerprint)throw new je(t.indexFingerprint,r);let i=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),n=e.resources.map((a)=>{let o=i.get(a.id);if(!o)return a;return Object.freeze({...a,receipt:o})});return Object.freeze(n),Object.freeze({schemaVersion:e.schemaVersion,resources:n,aliases:e.aliases})}var xr="uibot.resource.index.v1",fs=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class K extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function S(e,t){return e<t?-1:e>t?1:0}function C(e){return e.normalize("NFKC").replace(/([\p{Lu}]+)([\p{Lu}][\p{Ll}])/gu,"$1 $2").replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu,"$1 $2").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function kr(e){let t=C(e).replace(/ /g,"-");if(!t)throw new K("invalid-resource-source-id",e);return t}function T(e,t){return`${e}:${kr(t)}`}function oe(e){let t=new Map;for(let r of e){let i=r?.trim();if(!i)continue;let n=C(i);if(!n||t.has(n))continue;t.set(n,i)}return[...t.entries()].sort(([r],[i])=>S(r,i)).map(([,r])=>r)}function Z(e){return{level:"declared",maturity:"experimental",checks:{source:"declared",license:e?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"},evidence:[]}}function Sr(e){let t=B(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.sourceHash?{sourceHash:e.sourceHash}:{},...e.packageName?{packageName:e.packageName}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function H(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:oe(e.tags),aliases:oe(e.aliases),capabilities:oe(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(S),source:Sr(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function Ir(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function Ar(e){if(e.solution){let t=(r)=>{if(r&&typeof r==="object"){for(let i of Object.values(r))t(i);Object.freeze(r)}};t(e.solution)}return Object.freeze(e.tags),Object.freeze(e.aliases),Object.freeze(e.capabilities),Object.freeze(e.dependencies),Object.freeze(e.source),Object.freeze(e.receipt.checks),Object.freeze(e.receipt.evidence),Object.freeze(e.receipt),Object.freeze(e)}function wr(e){let t=new Map;for(let r of Object.keys(e).sort(S)){let i=e[r];if(!i)continue;let n=T("component",r);for(let a of oe([r,i.name])){let o=C(a),s=t.get(o)??[];if(!s.includes(n))s.push(n);t.set(o,s.sort(S))}}return t}function Pr(e,t,r){let i=r.get(C(e))??[];if(i.length===0)throw new K("dangling-resource-dependency",`${t} -> ${T("component",e)}`);if(i.length>1)throw new K("ambiguous-resource-dependency",`${t} -> ${e}: ${i.join(",")}`);return i[0]}function vr(e,t,r,i){let n=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(i,n))return T("template",n);return Pr(e,t,r)}function X(e,t,r){return B(r?.[e]??t)}function ys(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>S(t,r)).map(([t,r])=>({id:`${t}-example`,title:`${r.name} Example`,description:r.description,category:r.category,tags:r.keywords,aliases:[`${t} example`,`${r.name} example`],capabilities:["example:template"],dependencies:[T("template",t)]}))}function hs(e){let t=e.components??{},r=e.templates??{},i=e.designGuides??[],n=e.examples??[],a=e.skills??[],o=e.licenses,s=wr(t),c=[];for(let d of Object.keys(t).sort(S)){let m=t[d];if(!m)continue;let y=T("component",d),h=X(y,void 0,o);c.push(H({id:y,kind:"component",title:m.name,description:m.description,category:m.category,tags:m.tags??[],aliases:[d,m.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of Object.keys(r).sort(S)){let m=r[d];if(!m)continue;let y=T("template",d),h=X(y,void 0,o);c.push(H({id:y,kind:"template",title:m.name,description:m.description,category:m.category,tags:m.keywords,aliases:[d,m.name],capabilities:[],dependencies:(m.composedFrom??[]).map((A)=>vr(A,y,s,r)),source:{type:"template-contract",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of[...i].sort((m,y)=>S(m.id,y.id))){let m=T("design-guide",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"design-guide",title:d.title,description:Ir(d),category:d.category,tags:d.tags,aliases:[d.id,d.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:d.id,...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...n].sort((m,y)=>S(m.id,y.id))){let m=T("example",d.id),y=X(m,d.license,o);c.push(H({id:m,kind:"example",title:d.title,description:d.description,...d.category?{category:d.category}:{},tags:d.tags??[],aliases:[d.id,d.title,...d.aliases??[]],capabilities:d.capabilities??[],dependencies:d.dependencies??[],source:{type:"example",id:d.id,...d.version?{version:d.version}:{},...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...a].sort((m,y)=>S(m.id,y.id))){let m=T("skill",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"skill",title:d.title,description:d.description?.trim()||d.title,tags:[...d.tags??[],...d.triggers??[]],aliases:[d.id,d.title,...d.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:d.id,...d.version?{version:d.version}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of e.additional??[])c.push(H(d));c.sort((d,m)=>S(d.id,m.id));let l=new Set;for(let d of c){if(l.has(d.id))throw new K("duplicate-resource-id",d.id);l.add(d.id)}for(let d of c)for(let m of d.dependencies)if(!l.has(m))throw new K("dangling-resource-dependency",`${d.id} -> ${m}`);let u=new Map;for(let d of c)for(let m of d.aliases){let y=C(m);if(!y)continue;let h=u.get(y)??new Set;h.add(d.id),u.set(y,h)}let f=Object.freeze(Object.fromEntries([...u.entries()].sort(([d],[m])=>S(d,m)).map(([d,m])=>[d,Object.freeze([...m].sort(S))]))),p=Object.freeze(c.map(Ar));return Object.freeze({schemaVersion:xr,resources:p,aliases:f})}var Er=[["chat","assistant","\u804A\u5929","\u52A9\u624B","\u5BF9\u8BDD"],["document","documents","\u6587\u6863","\u5199\u4F5C"],["auth","authentication","\u8BA4\u8BC1","\u767B\u5F55"],["data table","data grid","datatable","table","\u8868\u683C","\u6570\u636E\u8868","\u6570\u636E\u8868\u683C"],["button","action button","\u6309\u94AE","\u64CD\u4F5C\u6309\u94AE"],["dashboard","admin dashboard","\u4EEA\u8868\u76D8","\u540E\u53F0","\u7BA1\u7406\u540E\u53F0"],["kanban","kanban board","\u770B\u677F","\u4EFB\u52A1\u770B\u677F"],["form","input form","\u8868\u5355","\u8F93\u5165\u8868\u5355"],["navigation","nav","sidebar","\u5BFC\u822A","\u4FA7\u8FB9\u680F"]],Dr=Object.freeze(Er.map((e)=>Object.freeze([...e]))),Ke=new Map;for(let e of Dr){let t=Object.freeze([...new Set(e.map(C).filter(Boolean))].sort());for(let r of t)Ke.set(r,t)}function Ce(e){let t=C(e);return Ke.get(t)??Object.freeze([t])}var Ss=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class w extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var ke=Object.freeze({function:180,scenario:180,unit:180,industry:180,"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),Tr=Object.freeze(Object.keys(ke)),We=new Map(Tr.map((e,t)=>[e,t])),Ge=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function I(e,t){return e<t?-1:e>t?1:0}function Ye(e){return new Set((e??[]).map(C).filter(Boolean))}function j(e,t){let r=Ye(t);if(r.size===0)return!0;let i=Ye(e);return[...r].some((n)=>i.has(n))}function Or(e,t){if(!j(e.solution?.functions??[],t.functions))return!1;if(!j(e.solution?.scenarios??[],t.scenarios))return!1;if(!j(e.solution?[e.solution.unit]:[],t.units))return!1;if(!j(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!j(e.tags,t.tags))return!1;if(!j(e.category?[e.category]:[],t.categories))return!1;if(!j(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function _r(e){return Boolean(e.functions?.length||e.scenarios?.length||e.units?.length||e.industries?.length||e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function P(e,t,r,i=ke[t]){if(e.some((n)=>n.code===t&&n.value===r))return;e.push({code:t,value:r,score:i})}function Re(e,t){return e.find((r)=>C(r)===t)}function xe(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities,...e.solution?.functions??[],...e.solution?.scenarios??[],...e.solution?.industries??[]]}function Fr(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let i=Array.from({length:t.length+1},(n,a)=>a);for(let n=1;n<=e.length;n+=1){let a=[n],o=n;for(let s=1;s<=t.length;s+=1){let c=(i[s-1]??r+1)+(e[n-1]===t[s-1]?0:1),l=Math.min((i[s]??r+1)+1,(a[s-1]??r+1)+1,c);a.push(l),o=Math.min(o,l)}if(o>r)return r+1;i=a}return i[t.length]??r+1}function Je(e,t){let r=C(t),i=[];if(C(e.id)===r)P(i,"exact-id",e.id);if(C(e.title)===r)P(i,"exact-title",e.title);let n=Re(e.aliases,r);if(n)P(i,"alias",n);let a=Re(e.tags,r);if(a)P(i,"tag",a);let o=Re(e.capabilities,r);if(o)P(i,"capability",o);if(e.category&&C(e.category)===r)P(i,"category",e.category);if(!n){let l=Ce(r).filter((f)=>f!==r),u=new Set(xe(e).map(C));if(l.some((f)=>u.has(f)))P(i,"alias",t.trim())}let s=r.split(" ").filter(Boolean),c=C(xe(e).join(" "));if(s.length>0&&s.every((l)=>c.includes(l)))P(i,"token",t.trim());if(i.length===0&&r.length>=4){let l;for(let u of xe(e)){let f=C(u);if(f.length<4)continue;let p=Fr(r,f,2);if(p<=2&&(!l||p<l.distance||p===l.distance&&I(u,l.value)<0))l={value:u,distance:p}}if(l)P(i,"fuzzy",l.value,ke.fuzzy-l.distance)}return i.sort((l,u)=>{if(l.score!==u.score)return u.score-l.score;return(We.get(l.code)??99)-(We.get(u.code)??99)||I(l.value,u.value)})}function Qe(e,t,r){if(t.has(r))return[r];let i=C(r),n=e.aliases[i];if(n?.length)return[...n];let a=new Set;for(let o of Ce(i))for(let s of e.aliases[o]??[])a.add(s);return[...a].sort(I)}function Ze(e,t){return new w("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function Xe(e){let t=new Map(e.resources.map((i)=>[i.id,i]));function r(i){let n=i.trim(),a=Qe(e,t,n);if(a.length===0)throw new w("resource-not-found",n);if(a.length>1)throw Ze(n,a);let o=a[0],s=o?t.get(o):void 0;if(!s)throw new w("resource-not-found",n);return s}return Object.freeze({manifest:()=>e,search(i){let n=i.text?.trim()??"";if(!n&&!_r(i))throw new w("resource-query-empty","text or filter is required");if(i.limit!==void 0&&(!Number.isInteger(i.limit)||i.limit<=0))throw new w("resource-query-invalid-limit",String(i.limit));let a=e.resources.filter((o)=>Or(o,i)).filter((o)=>!n||Je(o,n).length>0).map((o)=>{let s=n?Je(o,n):[];for(let[c,l]of[[i.functions,"function"],[i.scenarios,"scenario"],[i.units,"unit"],[i.industries,"industry"]])if(c?.length)P(s,l,c.join(","));return{resource:o,score:s.reduce((c,l)=>c+l.score,0),reasons:s}}).filter((o)=>!n||o.reasons.length>0).sort((o,s)=>s.score-o.score||I(o.resource.id,s.resource.id));return i.limit===void 0?a:a.slice(0,i.limit)},get:r,build(i){if(i.length===0||i.every((p)=>!p.trim()))throw new w("resource-query-empty","at least one build root is required");let n=[],a=new Set;for(let p of i){let d=p.trim(),m=Qe(e,t,d);if(m.length===0)n.push({id:d,reason:"missing-resource"});else if(m.length>1)throw Ze(d,m);else{let y=m[0];if(y)a.add(y)}}let o=new Set,s=new Set,c=new Set,l=[],u=[],f=(p,d)=>{if(o.has(p))return;if(s.has(p)){n.push({id:p,...d?{requiredBy:d}:{},reason:"dependency-cycle"});return}let m=t.get(p);if(!m){n.push({id:p,...d?{requiredBy:d}:{},reason:"missing-resource"});return}s.add(p),c.add(p);let y=[...m.dependencies].sort((h,A)=>{let N=t.get(h),_=t.get(A);return(Ge.get(N?.kind??"")??99)-(Ge.get(_?.kind??"")??99)||I(h,A)});for(let h of y)u.push({from:p,to:h,relation:"depends-on"}),f(h,p);s.delete(p),o.add(p),l.push(p)};for(let p of[...a].sort(I))f(p);return{roots:[...a].sort(I),nodes:[...c].sort(I).map((p)=>{let d=t.get(p);if(!d)throw new w("resource-not-found",p);return{id:p,kind:d.kind,maturity:d.receipt.maturity}}),edges:u.sort((p,d)=>I(p.from,d.from)||I(p.to,d.to)),order:l,gaps:n.sort((p,d)=>I(p.id,d.id)||I(p.requiredBy??"",d.requiredBy??"")||I(p.reason,d.reason))}}})}function Mr(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");jr(e);let t=e;if(t.schemaVersion!=="uibot.public-resources.v1"||typeof t.release?.version!=="string"||!/^[a-f0-9]{64}$/.test(t.release?.sourceHash)||t.index?.schemaVersion!=="uibot.resource.index.v1"||!Array.isArray(t.index.resources)||!t.index.aliases||!t.showcases)throw Error("invalid-public-resource-bundle");if(t.documents&&(!Array.isArray(t.documents)||t.documents.some((n)=>typeof n.title!=="string"||typeof n.markdown!=="string"||!/^\/(?:en\/)?docs\/[a-z0-9-]+$/.test(n.path))))throw Error("invalid-public-documentation");let r=new Set,i=new Set;for(let n of t.index.resources){if(!n||typeof n.id!=="string"||r.has(n.id)||!De.includes(n.kind)||!n.id.startsWith(`${n.kind}:`)||typeof n.description!=="string"||typeof n.title!=="string"||!Array.isArray(n.dependencies)||!n.source||!n.receipt||!Array.isArray(n.aliases)||!Array.isArray(n.tags)||!Array.isArray(n.capabilities)||![n.aliases,n.dependencies,n.tags,n.capabilities].every((o)=>o.every((s)=>typeof s==="string"&&s.length<=1000))||!["catalog","template-contract","design-md","example","skill","registry","package","theme"].includes(n.source.type)||typeof n.source.id!=="string"||n.source.sourceHash!==void 0&&!/^[a-f0-9]{64}$/.test(n.source.sourceHash)||n.source.packageName!==void 0&&(typeof n.source.packageName!=="string"||!n.source.packageName.startsWith("@uibot/"))||!te.includes(n.receipt.maturity)||!Te.includes(n.receipt.level)||!Array.isArray(n.receipt.evidence)||!n.receipt.evidence.every((o)=>typeof o==="string")||!Y.every((o)=>re.includes(n.receipt.checks?.[o])))throw Error("invalid-public-resource");if(r.add(n.id),n.solution){let o=n.solution;if(![o.functions,o.scenarios,o.industries,o.hostRequirements,o.limitations].every((s)=>Array.isArray(s)&&s.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(o.unit)||!["interactive-demo","needs-enhancement"].includes(o.readiness)||o.members!==void 0&&(!Array.isArray(o.members)||o.members.some((s)=>typeof s.resourceId!=="string"||typeof s.version!=="string"||!s.version||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))))throw Error("invalid-resource-solution")}let a=t.showcases[n.id];if(!a||a.resourceId!==n.id||typeof a.docs?.zh!=="string"||typeof a.docs?.en!=="string"||!Array.isArray(a.examples)||!Array.isArray(a.distributions))throw Error("invalid-resource-showcase");if(a.collection!==void 0){let o=a.collection;if(!o||typeof o.id!=="string"||!/^[a-z0-9-]+$/.test(o.id)||typeof o.group?.id!=="string"||!/^[a-z0-9-]+$/.test(o.group.id)||[o.title,o.group.title].some((s)=>!s||[s.zh,s.en].some((c)=>typeof c!=="string"||!c.trim()||c.length>200)))throw Error("invalid-resource-collection")}if(a.agentKit!==void 0){let o=a.agentKit;if(i.has(n.source?.id))throw Error("invalid-resource-agent-kit");if(i.add(n.source?.id),!o||!["skill","prompt","recipe"].includes(o.type)||(o.type==="skill"?n.kind!=="skill":n.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(n.source.id)||o.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[o.type]||[o.summary?.zh,o.summary?.en].some((s)=>typeof s!=="string"||!s.trim())||!Array.isArray(o.resources)||new Set(o.resources.map((s)=>s?.id)).size!==o.resources.length||o.resources.some((s)=>!s||!n.dependencies.includes(s.id)||!t.index.resources.some((c)=>c.id===s.id&&(c.source.version??null)===s.version)||s.version!==null&&(typeof s.version!=="string"||!s.version)||typeof s.contentHash!=="string"||!/^[a-f0-9]{64}$/.test(s.contentHash)||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))||o.resources.length!==n.dependencies.length)throw Error("invalid-resource-agent-kit")}if(a.solutionControls!==void 0){let o=new Set;if(!Array.isArray(a.solutionControls)||a.solutionControls.some((s)=>{if(!s||typeof s.id!=="string"||o.has(s.id)||typeof s.label?.zh!=="string"||typeof s.label?.en!=="string"||!Array.isArray(s.values)||!s.values.length||s.values.some((c)=>!["string","boolean","number"].includes(typeof c)||typeof c==="number"&&!Number.isFinite(c))||typeof s.target?.pageId!=="string"||typeof s.target?.property!=="string"||["__proto__","prototype","constructor"].includes(s.target.property)||s.target.blockId!==void 0&&typeof s.target.blockId!=="string")return!0;return o.add(s.id),!1}))throw Error("invalid-solution-controls")}if(a.templateContract&&(a.templateContract.name!==n.source.id||typeof a.templateContract.description!=="string"||!["L3","L4","L5"].includes(a.templateContract.level)||!["feature","template","page","app"].includes(a.templateContract.category)||!Array.isArray(a.templateContract.keywords)))throw Error("invalid-public-template-contract");if(typeof a.title?.zh!=="string"||typeof a.title?.en!=="string"||a.examples.some((o)=>!o||typeof o.id!=="string"||typeof o.title!=="string"||typeof o.code!=="string"||!["spec","tsx","source"].includes(o.mode)||!["tsx","json","yaml","css","ts"].includes(o.language)||!Array.isArray(o.dependencies)||!o.dependencies.every((s)=>typeof s==="string"))||a.distributions.some((o)=>!o||!["spec","npm","shadcn"].includes(o.channel)||typeof o.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(o.name)||typeof o.version!=="string"||!["source","published"].includes(o.availability)))throw Error("invalid-resource-content")}for(let[n,a]of Object.entries(t.index.aliases))if(!n||!Array.isArray(a)||a.some((o)=>!r.has(o)))throw Error("invalid-public-resource-alias");if(Object.keys(t.showcases).some((n)=>!r.has(n)))throw Error("unexpected-public-resource-showcase");for(let n of t.index.resources)for(let a of n.dependencies)if(!r.has(a))throw Error("invalid-public-resource-dependency");if(t.distributionSnapshot){let n=t.distributionSnapshot;if(!/^[a-f0-9]{64}$/.test(n.snapshotId)||n.manifestPath!==`../snapshots/${n.snapshotId}/snapshot.json`||!n.resources||!n.unavailable||!n.external||Object.entries(n.external).some(([a,o])=>!Object.hasOwn(n.unavailable,a)||!Array.isArray(o)||o.some((s)=>typeof s!=="string"||s.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[a,o]of Object.entries(n.resources))if(!r.has(a)||o.version!==(t.index.resources.find((s)=>s.id===a)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(o.resourceHash)||!Array.isArray(o.entrypoints)||!o.entrypoints.length||!Array.isArray(o.closure)||![...o.entrypoints,...o.closure].every((s)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(s))||o.entrypoints.some((s)=>!o.closure.includes(s)))throw Error("invalid-distribution-snapshot-resource")}}function vs(e){Mr(e),e=JSON.parse(JSON.stringify(e));let t=(n)=>{if(n&&typeof n==="object"){for(let a of Object.values(n))t(a);Object.freeze(n)}};t(e);let r=Xe(e.index),i=(n)=>{let a=r.get(n),o=e.showcases[a.id];if(!o)throw new w("resource-not-found",a.id);return o};return Object.freeze({...r,get(n){let a=r.get(n),o=i(n).agentKit;return o?Object.freeze({...a,agentKit:o}):a},docs(n,a="zh",o=1){if(a!=="zh"&&a!=="en")throw Error("unsupported-resource-locale");let s=i(n);return{resourceId:s.resourceId,locale:a,...Lr(s.docs[a],o),release:e.release}},examples(n,a=1){let o=i(n);return{resourceId:o.resourceId,...Br(o.examples,a),release:e.release}},installPlan(n){let a=i(n);return{resourceId:a.resourceId,distributions:a.distributions,dependencies:r.build([a.resourceId]),release:e.release,snapshot:e.distributionSnapshot&&Object.hasOwn(e.distributionSnapshot.resources,a.resourceId)?{snapshotId:e.distributionSnapshot.snapshotId,manifestPath:e.distributionSnapshot.manifestPath,...e.distributionSnapshot.resources[a.resourceId]}:null,snapshotUnavailable:e.distributionSnapshot?.unavailable[a.resourceId]??null,install:a.distributions.map((o)=>Nr(o,e.distributionSnapshot,a.resourceId))}}})}function Nr(e,t,r){let{channel:i,name:n,version:a}=e;if(i==="npm")return{channel:i,name:n,command:`add ${n}@${a}`,note:null};if(i==="spec")return{channel:i,name:n,command:null,note:"Read the Spec through examples and compile it strictly with the matching Catalog."};let o=!!t&&Object.hasOwn(t.resources,r),s=t?.external[r]??[];return{channel:i,name:n,command:`shadcn add @uibot/${n}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:s,note:o?"A hash-pinned snapshot exists: export and verify it, then map @uibot to the local snapshot server.":s.length?`No hash-pinned snapshot: the install also pulls stock shadcn items (${s.join(", ")}) from the host's default registry. Installing through the portal mapping still works; report the files as not snapshot-verified.`:"No hash-pinned snapshot; report the files as not snapshot-verified."}}var M=24000;function et(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new w("resource-query-invalid-limit","page is outside the available range")}function Lr(e,t){let r=Math.max(1,Math.ceil(e.length/M));return et(t,r),{markdown:e.slice((t-1)*M,t*M),page:t,totalPages:r,...t<r?{nextPage:t+1}:{}}}function Br(e,t){let r=e.flatMap((i)=>Array.from({length:Math.max(1,Math.ceil(i.code.length/M))},(n,a)=>({...i,code:i.code.slice(a*M,(a+1)*M),codeOffset:a*M,codeLength:i.code.length,complete:i.code.length<=M})));return et(t,r.length),{examples:r.slice(t-1,t),page:t,totalPages:r.length,...t<r.length?{nextPage:t+1}:{}}}function jr(e){let t=0,r=0,i=new Set,n=(a,o)=>{if(++t>300000||o>64)throw Error("public-resource-budget-exceeded");if(typeof a==="string"){if(r+=new TextEncoder().encode(a).length,r>16777216)throw Error("public-resource-budget-exceeded")}else if(a&&typeof a==="object"){if(i.has(a))throw Error("invalid-public-resource-cycle");let s=Object.getPrototypeOf(a);if(!Array.isArray(a)&&s!==Object.prototype&&s!==null)throw Error("invalid-public-resource-object");i.add(a);for(let[c,l]of Object.entries(a))n(c,o+1),n(l,o+1);i.delete(a)}else if(a!==null&&typeof a!=="boolean"&&(typeof a!=="number"||!Number.isFinite(a)))throw Error("invalid-public-resource-json")};n(e,1)}import{createHash as Vr}from"crypto";var le=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,se=/^[a-f0-9]{64}$/,ae=/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/,tt=new TextEncoder,$r=new TextDecoder("utf-8",{fatal:!0});function de(e){return Vr("sha256").update(e).digest("hex")}function V(e){let t=0,r=(n,a)=>{if(++t>400000||a>32)throw Error("snapshot-json-budget-exceeded");if(Array.isArray(n))return n.map((o)=>r(o,a+1));if(n&&typeof n==="object"){if(Object.getPrototypeOf(n)!==Object.prototype)throw Error("snapshot-invalid-json");return Object.fromEntries(Object.keys(n).sort().map((o)=>[o,r(n[o],a+1)]))}if(n===null||typeof n==="string"||typeof n==="boolean"||typeof n==="number"&&Number.isFinite(n))return n;throw Error("snapshot-invalid-json")},i=JSON.stringify(r(e,0));if(tt.encode(i).length>16777216)throw Error("snapshot-json-budget-exceeded");return i}function ce(e){if(typeof e!=="string"||!/^[a-zA-Z0-9_./-]+$/.test(e)||e.split("/").some((t)=>!t||t==="."||t==="..")||e.startsWith("/"))throw Error(`snapshot-unsafe-path: ${e}`)}function Se(e,t){return ce(e),{path:e,bytes:t.byteLength,sha256:de(t)}}function Ur(e){if(typeof e!=="string"||!e.startsWith("@uibot/")||!le.test(e.slice(7)))throw Error(`snapshot-external-registry-dependency: ${e}`);return e.slice(7)}function rt(e,t){if(!le.test(e)||t.byteLength>16777216)throw Error("snapshot-invalid-item");let r=JSON.parse($r.decode(t));if(r.name!==e||!Array.isArray(r.files)||r.files.length>2000||(r.devDependencies?.length??0)>0)throw Error(`snapshot-invalid-item: ${e}`);let i={};for(let s of r.dependencies??[]){let c=s.lastIndexOf("@"),l=s.slice(0,c),u=s.slice(c+1);if(c<1||!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u)||i[l]&&i[l]!==u)throw Error(`snapshot-unpinned-npm-dependency: ${s}`);i[l]=u}let n=[...new Set((r.registryDependencies??[]).map(Ur))].sort(),a=new Set,o=r.files.map((s)=>{if(typeof s.content!=="string")throw Error(`snapshot-missing-file-content: ${e}`);let c=s.target??s.path;if(ce(c),a.has(c))throw Error(`snapshot-duplicate-target: ${c}`);return a.add(c),{...Se(s.path,tt.encode(s.content)),target:c}});return{...Se(`r/${e}.json`,t),registryDependencies:n,npmDependencies:i,files:o}}function nt(e,t){let r=new Set,i=new Set,n=(s)=>{if(!le.test(s)||!Object.hasOwn(e,s))throw Error(`snapshot-missing-item: ${s}`);if(i.has(s))throw Error(`snapshot-dependency-cycle: ${s}`);if(r.has(s))return;i.add(s);for(let c of e[s].registryDependencies)n(c);i.delete(s),r.add(s)};if(!t.length)throw Error("snapshot-empty-entrypoints");t.forEach(n);let a=new Map,o=new Map;for(let s of r){for(let c of e[s].files){let l=a.get(c.target);if(l&&l!==c.sha256)throw Error(`snapshot-target-conflict: ${c.target}`);a.set(c.target,c.sha256)}for(let[c,l]of Object.entries(e[s].npmDependencies)){if(o.has(c)&&o.get(c)!==l)throw Error(`snapshot-npm-conflict: ${c}`);o.set(c,l)}}return[...r].sort()}function Ts(e){let t=Object.fromEntries(Object.entries(e.items).map(([a,o])=>[a,rt(a,o)])),r=Object.fromEntries(Object.entries(e.resources).map(([a,o])=>[a,{...o,closure:nt(t,o.entrypoints)}])),i={schemaVersion:"uibot.distribution.snapshot.v1",bundleHash:e.bundleHash,version:e.version,namespace:"@uibot",resources:r,items:t,license:"MIT AND ISC",licenseFiles:Object.entries(e.licenseFiles).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>Se(a,o))},n={...i,snapshotId:de(V(i))};return it(n),n}function it(e,t){if(!e||typeof e!=="object")throw Error("snapshot-invalid-manifest");V(e);let r=e,{snapshotId:i,...n}=r;if(r.schemaVersion!=="uibot.distribution.snapshot.v1"||r.namespace!=="@uibot"||r.license!=="MIT AND ISC"||!ae.test(r.version)||!se.test(r.bundleHash)||!se.test(i)||t!==void 0&&t!==i||de(V(n))!==i)throw Error("snapshot-identity-mismatch");if(!r.items||!r.resources||!Array.isArray(r.licenseFiles)||!r.licenseFiles.length)throw Error("snapshot-invalid-manifest");let a=(s)=>{if(ce(s.path),!se.test(s.sha256)||!Number.isSafeInteger(s.bytes)||s.bytes<0||s.bytes>16777216)throw Error("snapshot-invalid-file-digest")},o=new Set;for(let s of r.licenseFiles){if(a(s),!s.path.startsWith("licenses/")||o.has(s.path))throw Error("snapshot-invalid-license");o.add(s.path)}for(let[s,c]of Object.entries(r.items)){if(a(c),!le.test(s)||c.path!==`r/${s}.json`||!Array.isArray(c.registryDependencies)||!Array.isArray(c.files)||!c.npmDependencies)throw Error("snapshot-invalid-item");for(let l of c.files)a(l),ce(l.target);for(let[l,u]of Object.entries(c.npmDependencies))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u))throw Error("snapshot-unpinned-npm-dependency")}for(let s of Object.values(r.resources))if(!ae.test(s.version)||!se.test(s.resourceHash)||!Array.isArray(s.entrypoints)||V(nt(r.items,s.entrypoints))!==V(s.closure))throw Error("snapshot-resource-closure-mismatch")}function Os(e,t,r,i){it(e,i);let n=Object.hasOwn(e.resources,t)?e.resources[t]:void 0;if(!n)throw Error(`snapshot-resource-unavailable: ${t}`);let a=(s)=>{let c=r.get(s.path);if(!c||c.byteLength!==s.bytes||de(c)!==s.sha256)throw Error(`snapshot-file-mismatch: ${s.path}`);return c},o={};for(let s of n.closure){let c=e.items[s],l=rt(s,a(c));if(V(l)!==V(c))throw Error(`snapshot-item-metadata-mismatch: ${s}`);Object.assign(o,c.npmDependencies)}return e.licenseFiles.forEach(a),{snapshotId:e.snapshotId,resourceId:t,closure:[...n.closure],npmDependencies:o}}function Gr(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function Yr(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class Jr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}class Qr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}async function lt(e,t){let r=await fetch(e,t?{headers:t}:{});if(!r.ok)throw Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);return await r.json()}async function Zr(e,t){let r=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,i=await lt(r,t);return Gr(i)}async function Xr(e,t){let r=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,i=await lt(r,t);return Yr(i)}class en{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=Zr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((r)=>r.name===e)}}class tn{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=Xr(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).plugins.find((r)=>r.pluginId===e)}}class rn{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}class nn{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}var on="uibot.artifacts.lock.json";function sn(e){return O(e,"components","registry")}function an(e){return O(e,"templates","registry")}function cn(e,t){if(e.kind==="component")return O(t.componentsDir??sn(t.workspaceRoot));return O(t.templatesDir??an(t.workspaceRoot))}function ln(e){return O(e.workspaceRoot,e.lockfilePath??on)}function dn(e){try{return JSON.parse(qr(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function un(e,t){at(Ie(e),{recursive:!0}),ct(e,`${JSON.stringify(t,null,2)}
15
- `,"utf8")}function pn(e,t){return{version:1,artifacts:[...e.artifacts.filter((i)=>i.name!==t.name),t].sort((i,n)=>i.name.localeCompare(n.name))}}function gn(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class U extends Error{artifactName;offendingPath;baseDir;constructor(e,t,r){super(`Artifact "${e}" file path escapes workspace: "${t}" resolves outside "${r}"`);this.artifactName=e;this.offendingPath=t;this.baseDir=r;this.name="ArtifactContainmentError"}}function dt(e,t){let r=t.endsWith(ot)?t:t+ot;return e===t||e.startsWith(r)}function st(e){let t=O(e),r=[];while(!0)try{return zr(t),O(Hr(t),...r)}catch(i){if(i.code!=="ENOENT")throw i;let n=Ie(t);if(n===t)throw i;r.unshift(Kr(t)),t=n}}function ut(e,t,r,i){try{let n=st(t),a=st(e);if(!dt(a,n))throw new U(r,i,t)}catch(n){if(n instanceof U)throw n;throw new U(r,i,t)}}function pt(e,t,r){if(e.includes("\x00"))throw new U(r,e,t);if(Wr(e))throw new U(r,e,t);let i=O(t,e);if(!dt(i,t))throw new U(r,e,t);return ut(i,t,r,e),i}function mn(e,t){let r=[];for(let i of e.files){let n=i.target??i.path;r.push(pt(n,t,e.name))}return r}function Ns(e,t){let r=O(t.workspaceRoot),i=cn(e,t);ut(i,r,e.name,i);let n=pt(e.name,i,e.name),a=mn(e,n),o=[];for(let f=0;f<e.files.length;f++){let p=e.files[f],d=a[f];at(Ie(d),{recursive:!0}),ct(d,p.content??"","utf8"),o.push(d)}let s={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=ln(t),l=dn(c),u=pn(l,s);return un(c,u),{artifactLock:s,catalogPatch:gn(e),writtenFiles:o}}export{U as ArtifactContainmentError,rn as ArtifactRegistryResolver,Jr as MemoryArtifactRegistrySource,Qr as MemoryPluginRegistrySource,nn as PluginRegistryResolver,cs as RESOURCE_ADMISSION_ERROR_CODES,he as RESOURCE_ADMISSION_SCHEMA_VERSION,or as RESOURCE_EXTERNAL_CHECKS,fs as RESOURCE_INDEX_ERROR_CODES,xr as RESOURCE_INDEX_SCHEMA_VERSION,ir as RESOURCE_PREFLIGHT_CHECKS,Dr as RESOURCE_QUERY_ALIAS_GROUPS,Ss as RESOURCE_QUERY_ERROR_CODES,Vt as RESOURCE_QUERY_OPERATION_MANIFEST,ke as RESOURCE_QUERY_SCORE_WEIGHTS,en as RemoteArtifactRegistrySource,tn as RemotePluginRegistrySource,je as ResourceAdmissionIndexMismatchError,$e as ResourceAdmissionReportNotDerivedError,Ve as ResourceAdmissionReportRejectedError,K as ResourceIndexError,w as ResourceQueryError,ns as SHADCN_REGISTRY_ITEM_SCHEMA,fe as UIBOT_BASE_ITEM,_e as UIBOT_THEME_ITEM,ps as applyResourceAdmissionReport,ce as assertDistributionPath,it as assertDistributionSnapshot,pt as assertPathContained,Mr as assertPublicResourceBundle,us as assessResourceAdmissions,ys as buildExamplesFromL4Templates,hs as buildResourceIndex,rs as buildShadcnRegistry,An as buildUiBotRegistryManifest,Yt as catalogEntryToMeta,Cn as collectAllBlockSources,St as collectBlockSources,Pe as collectTemplateSources,Dt as collectTemplateSourcesFromDirs,mt as compareLockToManifest,Ts as createDistributionSnapshot,vs as createPublicResourceQueryService,Xe as createResourceQueryService,os as createUIBotRegistryHttpHandler,ls as deriveResourceLicense,rt as describeDistributionItem,V as distributionCanonicalJson,nt as distributionClosure,de as distributionSha256,wn as emitArtifactJson,yt as emptyLockfile,ds as evaluateCatalogPreflight,Ce as expandResourceQueryAliases,Zr as fetchArtifactRegistryManifest,Xr as fetchPluginDistributionManifest,Ns as installArtifactToWorkspace,ht as lockfileWith,nr as normalizeRegistryBasePath,C as normalizeResourceAlias,B as normalizeResourceLicense,ts as parseOklchCssVars,Yr as parsePluginDistributionManifest,Gr as parseRegistryManifest,He as resourceAdmissionIndexFingerprint,Ur as snapshotDependencyName,ge as templateSourceToRegistryItem,Ee as toArtifactRegistryItem,Nt as toComponentArtifact,ye as toItemName,T as toResourceId,ve as toTemplateArtifact,Fe as transformBlockSource,Os as verifyDistributionSnapshot};
10
+ `}function Jt(e){let t={category:e.category,level:e.level};if(e.props)t.props=e.props;if(e.slots)t.slots=e.slots;if(e.events)t.events=e.events;if(e.usageScenarios)t.scenarios=e.usageScenarios;if(e.constraints)t.constraints=e.constraints;return t}function os(e){return{light:Me(e,":root"),dark:Me(e,".dark")}}function Me(e,t){let r={},i=new RegExp(`${Le(t)}\\s*\\{`,"g"),n;while((n=i.exec(e))!==null){let a=n.index+n[0].length,o=1,s=a;for(;s<e.length&&o>0;s++){let l=e[s];if(l==="{")o++;else if(l==="}")o--}let c=e.slice(a,s-1);for(let l of c.matchAll(/--([\w-]+)\s*:\s*([^;]+);/g)){let u=l[1],f=l[2];if(u!==void 0&&f!==void 0)r[u]=f.trim()}}return r}function Le(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ss(e,t){let r=t.sharedDependencies??Ht,i=t.channel??"public",n=Xt(t),a=(t.componentsDir??Kt).replace(/\/$/,""),o=(t.libDir??Wt).replace(/\/$/,""),s=`${o}/uibot-renderer.ts`,c=`${o}/utils.ts`,l=`${o}/uibot-contracts.ts`,u="@/lib/uibot-renderer",f="@/lib/utils",p="@/lib/uibot-contracts",d={},m={name:fe,type:"registry:lib",description:"UIBot runtime base: RendererComponent type shim + cn util. Pulled automatically by every UIBot block.",dependencies:r,files:[{path:s,content:t.rendererShimContent,type:"registry:lib"},{path:c,content:t.cnUtilContent,type:"registry:lib"},...t.contractsShimContent?[{path:l,content:t.contractsShimContent,type:"registry:lib"}]:[]],meta:{base:!0}};if(d[fe]=m,t.cssVars)d[_e]={name:_e,type:"registry:theme",description:"UIBot OKLCH palette for the semantic tokens the blocks use. Optional: skip it when the host defines its own.",files:[],cssVars:t.cssVars};let y=new Map,h=new Map,A=new Map,N=new Map;for(let g of e){let v=g.files[0]?.path??`${ye(g.name)}.tsx`,x=g.channel??"public",b=N.get(v);if(b&&b!==x)throw Error(`${v} mixes ${b} and ${x} blocks; split the file`);N.set(v,x)}for(let g of e){if((g.channel??"public")!==i)continue;let x=g.files[0]?.path??`${ye(g.name)}.tsx`,b=y.get(x);if(!b){let R=ye(nr(x,g.name)),ee=Fe(g,{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),F=`${a}/${R}.tsx`,W={schema:me,item:R,channel:i,components:[]};A.set(R,W),b={name:R,type:"registry:ui",description:g.description??g.catalogEntry.description,dependencies:["react",...g.dependencies??[]],registryDependencies:[n(fe)],files:g.files.length<=1?[{path:F,target:F,content:ee,type:"registry:ui"}]:g.files.map((G)=>{if(typeof G.content!=="string")throw Error(`Missing block source content: ${G.path}`);let Ae=`${a}/${G.path.replace(/^blocks\//,"")}`;return{path:Ae,target:Ae,content:Fe({...g,sourceCode:rr(G.path,G.content,g)},{rendererShimImport:"@/lib/uibot-renderer",cnUtilImport:"@/lib/utils",...t.contractsShimContent?{contractsShimImport:"@/lib/uibot-contracts"}:{}}),type:"registry:ui"}}),meta:{...Jt(g.catalogEntry),provides:[g.name],uibot:W}},y.set(x,b),d[R]=b}else{let R=b.meta;if(R.provides&&!R.provides.includes(g.name))R.provides.push(g.name)}let E=A.get(b.name);if(E?.components&&!h.has(g.name))E.components.push(er(g,b,a)),h.set(g.name,b.name)}for(let[g,v]of A){let x=d[g];if(!x)continue;v.components?.sort((E,R)=>E.name.localeCompare(R.name));let b=`${a}/${g}.uibot.json`;x.files.push({path:b,target:b,content:`${JSON.stringify(v,null,2)}
11
+ `,type:"registry:ui"})}let _={},ue=(t.templates??[]).filter((g)=>(g.channel??"public")===i),gt=new Set(ue.map((g)=>g.name));for(let g of ue){if(d[g.name])throw Error(`template item "${g.name}" collides with a component item`);let v=g.templateContract.composedFrom??[],x=new Set,b=[];for(let F of v){let W=h.get(F);if(W)x.add(n(W));else if(gt.has(F)&&F!==g.name)x.add(n(F));else b.push(F)}if(b.length>0)_[g.name]=b;let E=`${o}/${Yt}`,R=`${g.name}.uibot.yaml`,ee={schema:me,item:g.name,channel:i,template:{file:R,contract:g.templateContract}};d[g.name]={name:g.name,type:"registry:block",description:g.description,registryDependencies:[...x].sort(),files:[{path:`${E}/${R}`,target:`${E}/${R}`,content:g.yaml,type:"registry:lib"},{path:`${E}/${g.name}.uibot.json`,target:`${E}/${g.name}.uibot.json`,content:`${JSON.stringify(ee,null,2)}
12
+ `,type:"registry:lib"}],meta:{uibot:ee}}}return Qt(d,t.composites??[],{channel:i,ref:n,componentsDir:a}),{registry:{$schema:zt,name:t.registryName,...t.homepage?{homepage:t.homepage}:{},items:Object.values(d).map((g)=>({name:g.name,type:g.type,...g.description?{description:g.description}:{},...g.registryDependencies?{registryDependencies:g.registryDependencies}:{},...g.dependencies?{dependencies:g.dependencies}:{}}))},items:d,unresolvedTemplateTypes:_}}function Qt(e,t,r){let i=new Map;for(let n of t){if(i.has(n.name)||e[n.name])throw Error(`composite item "${n.name}" collides with another item`);i.set(n.name,n)}for(let n of t){let a=n.channel??"public",o=Ne(n),s=new Set(n.files.map((l)=>l.path));for(let l of n.requires??[]){let u=i.get(l);if(!u)throw Error(`composite "${n.name}" requires unknown "${l}"`);if((u.channel??"public")!==a)throw Error(`composite "${n.name}" (${a}) requires "${l}" from another channel`);if(Ne(u)!==o)throw Error(`composite "${n.name}" requires "${l}" from another directory`);for(let f of u.files)s.add(f.path)}for(let l of n.files){if(!je.test(l.path))throw Error(`composite "${n.name}" file "${l.path}" must be a plain relative path`);for(let u of Zt(l.content)){if(!u.startsWith("./")||u.includes("/../"))throw Error(`${n.name}/${l.path} imports ${u}; only ./ imports within the item directory are allowed`);let f=u.slice(2).replace(/\.js$/,"");if(![f,`${f}.ts`,`${f}.tsx`,`${f}/index.ts`,`${f}/index.tsx`].some((d)=>s.has(d)))throw Error(`${n.name}/${l.path} imports ${u}, which no required item ships`)}}if(a!==r.channel)continue;let c=n.files.map((l)=>{let u=`${r.componentsDir}/${o}/${l.path}`;return{path:u,target:u,content:l.content,type:l.path.endsWith(".tsx")?"registry:component":"registry:lib"}});e[n.name]={name:n.name,type:n.type,description:n.description,dependencies:["react",...n.dependencies??[]],registryDependencies:[...n.primitives??[],...(n.requires??[]).map(r.ref)],files:c,meta:{composite:!0,channel:a}}}}var je=/^[a-z0-9][a-z0-9._-]*(\/[a-z0-9][a-z0-9._-]*)*$/i;function Ne(e){if(!je.test(e.dir)||e.dir.split("/").includes(".."))throw Error(`composite "${e.name}" dir "${e.dir}" must be a plain relative path`);return e.dir}function Zt(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1"),r=[],i=[/\bfrom\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*["'](\.{1,2}\/[^"']+)["']/g,/\bimport\s*\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g];for(let n of i)for(let a of t.matchAll(n))r.push(a[1]??"");return r}function Xt(e){if(e.baseUrl){let r=e.baseUrl.replace(/\/$/,"");return(i)=>`${r}/r/${i}.json`}let t=e.namespace??Gt;if(!/^@[a-z0-9][a-z0-9-]*$/.test(t))throw Error(`registry namespace must look like "@uibot", got "${t}"`);return(r)=>`${t}/${r}`}function er(e,t,r){let i=e.name.replace(/\./g,""),n=`${r}/`,a=t.files.find((o)=>o.path.startsWith(n)&&/\.(tsx|ts)$/.test(o.path)&&tr(o.content,i));if(!a)throw Error(`block "${e.name}" has no named export "${i}" in item "${t.name}"`);return{name:e.name,export:i,module:a.path.slice(n.length),catalog:e.catalogEntry}}function tr(e,t){let r=Le(t),i=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,"");if(new RegExp(`export\\s+(?:const|let|function|class)\\s+${r}\\b`).test(i))return!0;for(let n of i.matchAll(/export\s*\{([^}]*)\}/g)){let a=(n[1]??"").split(",").map((s)=>{let[,c]=s.trim().split(/\s+as\s+/);return(c??s.trim().replace(/^type\s+/,"")).trim()}),o=(n[1]??"").split(",").map((s)=>s.trim()).filter((s)=>s.startsWith("type ")).map((s)=>s.replace(/^type\s+/,"").split(/\s+as\s+/).pop()?.trim());if(a.includes(t)&&!o.includes(t))return!0}return!1}function rr(e,t,r){let i=new Set(r.files.map((a)=>a.path)),n=(a)=>a.replace(/^blocks\//,"");return t.replace(/((?:\bfrom\s*|\bimport\s*)["'])(\.[^"']+)(["'])/g,(a,o,s,c)=>{let l=L.normalize(L.join(L.dirname(e),s)),f=(L.extname(l)?[l]:[l,`${l}.ts`,`${l}.tsx`,`${l}/index.ts`,`${l}/index.tsx`]).find((d)=>i.has(d));if(!f)return a;let p=L.relative(L.dirname(n(e)),n(f));if(!L.extname(s))p=p.replace(/\.(tsx?|jsx?)$/,"");if(!p.startsWith("."))p=`./${p}`;return o+p+c})}function nr(e,t){return(e.split("/").pop()??t).replace(/\.(tsx|ts|jsx|js)$/,"")||t}var as=qt;function ir(e="/api/registry"){let t=(e||"/api/registry").trim(),r=t.startsWith("/")?t:`/${t}`;return r.length>1?r.replace(/\/$/,""):r}function J(e,t=200){return Response.json(e,{status:t})}function ls(e){let t=ir(e.basePath),r=`${t}/registry.json`,i=`${t}/artifacts/`,n=new Map(e.manifest.items.map((a)=>[a.name,a]));return async function(o){let s=new URL(o.url);if(o.method!=="GET")return J({error:"Method not allowed"},405);if(s.pathname===r)return J(e.manifest);if(s.pathname.startsWith(i)){let c=s.pathname.slice(i.length),l=decodeURIComponent(c.endsWith(".json")?c.slice(0,-5):c),u=n.get(l);if(!u)return J({error:`Artifact '${l}' not found`},404);return J(u)}return J({error:"Not found"},404)}}var he="uibot.resource.admission.v1",or=["source","license","contract","states","accessibility","light-theme","dark-theme","responsive","dependency-closure"],sr=["packed-install","typecheck","browser"],ps=["invalid-admission-manifest","invalid-admission-record","invalid-admission-check","duplicate-admission-record","unknown-admission-resource","missing-source-metadata","missing-license-metadata","dependency-closure-failed"];class Be extends Error{expected;actual;code="resource-admission-index-mismatch";constructor(e,t){super(`resource admission index mismatch: expected ${e}, received ${t}`);this.expected=e;this.actual=t;this.name="ResourceAdmissionIndexMismatchError"}}class Ve extends Error{issueCount;code="resource-admission-report-rejected";constructor(e){super(`resource admission report contains ${e.toString()} issue(s)`);this.issueCount=e;this.name="ResourceAdmissionReportRejectedError"}}class $e extends Error{code="resource-admission-report-not-derived";constructor(){super("resource admission report must come directly from assessResourceAdmissions");this.name="ResourceAdmissionReportNotDerivedError"}}var ar=new Set(Y),cr=new Set(re),Ue=new WeakSet,ne={missing:0,declared:1,verified:2,"external-consumer":3};function lr(e,t){return e<t?-1:e>t?1:0}function q(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function ie(e,t){let r=new Set(t);return Object.keys(e).every((i)=>r.has(i))}function ze(e){return[...new Set(e.map((t)=>t.trim()).filter(Boolean))].sort(lr)}function dr(e,t,r,i){if(!q(r)||!ie(r,["status","evidence"])){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} must contain only status and evidence`});return}if(typeof r.status!=="string"||!cr.has(r.status)||r.status==="missing"){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} status must be declared, verified or external-consumer`});return}if(!Array.isArray(r.evidence)||r.evidence.length===0||r.evidence.some((n)=>typeof n!=="string"||!n.trim())){i.push({code:"invalid-admission-check",resourceId:e,check:t,detail:`${t} evidence must be a non-empty string array`});return}return{status:r.status,evidence:ze(r.evidence)}}function ur(e){if(e===void 0)return;if(!q(e)||!ie(e,["source","version","license"]))return;if(Object.values(e).some((r)=>r!==void 0&&typeof r!=="string"))return;return{...typeof e.source==="string"&&e.source.trim()?{source:e.source.trim()}:{},...typeof e.version==="string"&&e.version.trim()?{version:e.version.trim()}:{},...typeof e.license==="string"&&e.license.trim()?{license:e.license.trim()}:{}}}function pr(e,t){let r=new Map,i=[];if(!q(t)||!ie(t,["schemaVersion","records"])||t.schemaVersion!==he||!Array.isArray(t.records))return i.push({code:"invalid-admission-manifest",detail:`expected ${he} with a records array`}),{records:r,issues:i};let n=new Set(e.resources.map((a)=>a.id));for(let a of t.records){if(!q(a)||!ie(a,["resourceId","provenance","checks"])||typeof a.resourceId!=="string"||!a.resourceId.trim()||!q(a.checks)){i.push({code:"invalid-admission-record",...q(a)&&typeof a.resourceId==="string"?{resourceId:a.resourceId}:{},detail:"record must contain only resourceId, optional provenance and checks"});continue}let o=a.resourceId.trim();if(r.has(o)){i.push({code:"duplicate-admission-record",resourceId:o,detail:o});continue}if(!n.has(o)){i.push({code:"unknown-admission-resource",resourceId:o,detail:o});continue}let s=ur(a.provenance);if(a.provenance!==void 0&&!s){i.push({code:"invalid-admission-record",resourceId:o,detail:"provenance must contain only string source, version and license fields"});continue}let c={},l=!1;for(let[u,f]of Object.entries(a.checks)){if(!ar.has(u)){i.push({code:"invalid-admission-check",resourceId:o,detail:`unknown receipt check: ${u}`}),l=!0;continue}let p=u,d=dr(o,p,f,i);if(d)c[p]=d;else l=!0}if(l)continue;r.set(o,{resourceId:o,...s?{provenance:s}:{},checks:c})}return{records:r,issues:i}}function gr(e){let t=new Map(e.resources.map((n)=>[n.id,n])),r=new Map;function i(n,a,o,s){if(r.has(n)||s.has(a))return;if(o.has(a)){r.set(n,`dependency cycle reached ${a}`);return}let c=t.get(a);if(!c){r.set(n,`missing dependency ${a}`);return}o.add(a);for(let l of c.dependencies)if(i(n,l,o,s),r.has(n))break;o.delete(a),s.add(a)}for(let n of e.resources)i(n.id,n.id,new Set,new Set);return r}var mr=/^(unknown|unlicensed|none|n\/?a)$/i,fr=/^SPDX-License-Identifier:\s*(\S+)/im,yr=/^(?:the\s+)?(mit|apache(?:\s+license(?:\s*,?\s*version\s*2\.0)?)?|bsd-2-clause|bsd-3-clause|isc|unlicense)\b/i;function j(e){let t=e?.trim();if(!t||mr.test(t))return;return t}function hr(e){if(!e?.trim())return;let t=e.match(fr)?.[1];if(t)return j(t);let r=e.match(yr)?.[1];if(!r)return;let i=r.toLowerCase();if(i.startsWith("mit"))return"MIT";if(i.startsWith("apache"))return"Apache-2.0";if(i.startsWith("bsd-2"))return"BSD-2-Clause";if(i.startsWith("bsd-3"))return"BSD-3-Clause";if(i==="isc")return"ISC";if(i==="unlicense")return"Unlicense";return}function gs(e){return j(e.frontmatterLicense)??j(e.packageJsonLicense)??hr(e.licenseFileText)}function qe(e){return Boolean(j(e))}var Q={states:/\b(disabled|loading|error|empty|pending|busy|children|active|muted|boolean-state)\b/i,accessibility:/\b(label|aria|accessible|alt|role)\b/i,"light-theme":/:root\b|\b(light(?:-theme)?|theme token|css variables?)\b/i,"dark-theme":/\b(dark(?:-theme)?)\b/i,responsive:/\b(size|responsive|breakpoint|sm|md|lg|xl|full)\b/i};function be(e,t){if(!e||typeof e!=="object")return;if(Array.isArray(e)){for(let i of e)be(i,t);return}let r=e;for(let[i,n]of Object.entries(r)){if(t.push(i),i==="type"&&n==="boolean")t.push("boolean-state");be(n,t)}}function br(e){let t=[];return be(e.props,t),[e.name,e.description,...e.tags??[],...e.usageScenarios??[],...e.constraints??[],...t,...Object.keys(e.slots??{}),...Object.keys(e.events??{}),e.slots&&Object.keys(e.slots).length>0?"empty":""].join(`
13
+ `)}function ms(e,t={}){let r=[br(e),t.sourceText??"",t.stylesText??""].join(`
14
+ `);return{contract:Boolean(e.props&&Object.keys(e.props).length>0||e.events&&Object.keys(e.events).length>0||e.slots&&Object.keys(e.slots).length>0)?"verified":"declared",states:Q.states.test(r)?"verified":"missing",accessibility:Q.accessibility.test(r)?"verified":"missing","light-theme":Q["light-theme"].test(r)?"verified":"missing","dark-theme":Q["dark-theme"].test(r)?"verified":"missing",responsive:Q.responsive.test(r)?"verified":"missing"}}function Cr(e){return{source:"declared",license:qe(e.source.license)?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"}}function Rr(e){if(!or.every((i)=>ne[e[i]]>=ne.verified))return"experimental";return sr.every((i)=>e[i]==="external-consumer")?"recommended":"candidate"}function He(e){let t=JSON.stringify({schemaVersion:e.schemaVersion,resources:e.resources.map((n)=>({id:n.id,kind:n.kind,title:n.title,description:n.description,...n.category?{category:n.category}:{},tags:n.tags,aliases:n.aliases,capabilities:n.capabilities,dependencies:n.dependencies,source:n.source})),aliases:e.aliases}),r=0xcbf29ce484222325n,i=0x100000001b3n;for(let n of new TextEncoder().encode(t))r^=BigInt(n),r=BigInt.asUintN(64,r*i);return`fnv1a64:${r.toString(16).padStart(16,"0")}`}function xr(e,t,r){let i=Cr(e),n=[`resource://${e.source.type}/${e.source.id}`,`resource://contract/${e.id}`],a=[];if(r)a.push({code:"dependency-closure-failed",resourceId:e.id,check:"dependency-closure",detail:r});else i["dependency-closure"]="verified",n.push(`resource://index/${e.id}`);if(t)for(let c of Y){if(c==="dependency-closure")continue;let l=t.checks[c];if(!l)continue;if(c==="source"&&ne[l.status]>=ne.verified&&(!t.provenance?.source||!t.provenance.version)){a.push({code:"missing-source-metadata",resourceId:e.id,check:c,detail:"verified source requires provenance.source and provenance.version"});continue}if(c==="license"&&!qe(t.provenance?.license)){a.push({code:"missing-license-metadata",resourceId:e.id,check:c,detail:"license evidence requires a concrete provenance.license"});continue}if(i[c]=l.status,n.push(...l.evidence),c==="source"&&t.provenance?.source)n.push(t.provenance.source)}let o=Rr(i),s={level:o==="recommended"?"external-consumer":o==="candidate"?"verified":"declared",maturity:o,checks:i,evidence:ze(n)};return Object.freeze(s.checks),Object.freeze(s.evidence),Object.freeze(s),Object.freeze(a),Object.freeze({resourceId:e.id,receipt:s,issues:a})}function fs(e,t){let r=pr(e,t),i=gr(e),n=e.resources.map((c)=>xr(c,r.records.get(c.id),i.get(c.id))),a=[...r.issues,...n.flatMap((c)=>c.issues)],o=Object.fromEntries(te.map((c)=>[c,0]));for(let c of n)o[c.receipt.maturity]+=1;Object.freeze(n),Object.freeze(o);for(let c of a)Object.freeze(c);Object.freeze(a);let s=Object.freeze({schemaVersion:he,indexFingerprint:He(e),resources:n,counts:o,issues:a});return Ue.add(s),s}function ys(e,t){if(!Ue.has(t))throw new $e;if(t.issues.length>0)throw new Ve(t.issues.length);let r=He(e);if(r!==t.indexFingerprint)throw new Be(t.indexFingerprint,r);let i=new Map(t.resources.map((a)=>[a.resourceId,a.receipt])),n=e.resources.map((a)=>{let o=i.get(a.id);if(!o)return a;return Object.freeze({...a,receipt:o})});return Object.freeze(n),Object.freeze({schemaVersion:e.schemaVersion,resources:n,aliases:e.aliases})}var kr="uibot.resource.index.v1",Cs=["invalid-resource-source-id","duplicate-resource-id","dangling-resource-dependency","ambiguous-resource-dependency"];class K extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceIndexError"}}function I(e,t){return e<t?-1:e>t?1:0}function C(e){return e.normalize("NFKC").replace(/([\p{Lu}]+)([\p{Lu}][\p{Ll}])/gu,"$1 $2").replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu,"$1 $2").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function Ir(e){let t=C(e).replace(/ /g,"-");if(!t)throw new K("invalid-resource-source-id",e);return t}function T(e,t){return`${e}:${Ir(t)}`}function oe(e){let t=new Map;for(let r of e){let i=r?.trim();if(!i)continue;let n=C(i);if(!n||t.has(n))continue;t.set(n,i)}return[...t.entries()].sort(([r],[i])=>I(r,i)).map(([,r])=>r)}function Z(e){return{level:"declared",maturity:"experimental",checks:{source:"declared",license:e?"declared":"missing",contract:"declared",states:"missing",accessibility:"missing","light-theme":"missing","dark-theme":"missing",responsive:"missing","dependency-closure":"missing","packed-install":"missing",typecheck:"missing",browser:"missing"},evidence:[]}}function Sr(e){let t=j(e.license);return{type:e.type,id:e.id,...e.version?{version:e.version}:{},...e.sourceHash?{sourceHash:e.sourceHash}:{},...e.packageName?{packageName:e.packageName}:{},...e.url?{url:e.url}:{},...t?{license:t}:{}}}function H(e){return{id:e.id,kind:e.kind,title:e.title,description:e.description,...e.category?{category:e.category}:{},tags:oe(e.tags),aliases:oe(e.aliases),capabilities:oe(e.capabilities),dependencies:[...new Set(e.dependencies)].sort(I),source:Sr(e.source),receipt:e.receipt,...e.solution?{solution:structuredClone(e.solution)}:{}}}function Ar(e){return(e.body.split(/\r?\n/).map((r)=>r.replace(/^#+\s*/,"").trim()).find(Boolean)??e.title).slice(0,240)}function wr(e){if(e.solution){let t=(r)=>{if(r&&typeof r==="object"){for(let i of Object.values(r))t(i);Object.freeze(r)}};t(e.solution)}return Object.freeze(e.tags),Object.freeze(e.aliases),Object.freeze(e.capabilities),Object.freeze(e.dependencies),Object.freeze(e.source),Object.freeze(e.receipt.checks),Object.freeze(e.receipt.evidence),Object.freeze(e.receipt),Object.freeze(e)}function Pr(e){let t=new Map;for(let r of Object.keys(e).sort(I)){let i=e[r];if(!i)continue;let n=T("component",r);for(let a of oe([r,i.name])){let o=C(a),s=t.get(o)??[];if(!s.includes(n))s.push(n);t.set(o,s.sort(I))}}return t}function vr(e,t,r){let i=r.get(C(e))??[];if(i.length===0)throw new K("dangling-resource-dependency",`${t} -> ${T("component",e)}`);if(i.length>1)throw new K("ambiguous-resource-dependency",`${t} -> ${e}: ${i.join(",")}`);return i[0]}function Er(e,t,r,i){let n=e.startsWith("template:")?e.slice(9):e;if(Object.hasOwn(i,n))return T("template",n);return vr(e,t,r)}function X(e,t,r){return j(r?.[e]??t)}function Rs(e){return Object.entries(e).filter(([,t])=>t.level==="L4").sort(([t],[r])=>I(t,r)).map(([t,r])=>({id:`${t}-example`,title:`${r.name} Example`,description:r.description,category:r.category,tags:r.keywords,aliases:[`${t} example`,`${r.name} example`],capabilities:["example:template"],dependencies:[T("template",t)]}))}function xs(e){let t=e.components??{},r=e.templates??{},i=e.designGuides??[],n=e.examples??[],a=e.skills??[],o=e.licenses,s=Pr(t),c=[];for(let d of Object.keys(t).sort(I)){let m=t[d];if(!m)continue;let y=T("component",d),h=X(y,void 0,o);c.push(H({id:y,kind:"component",title:m.name,description:m.description,category:m.category,tags:m.tags??[],aliases:[d,m.name],capabilities:["catalog:component"],dependencies:[],source:{type:"catalog",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of Object.keys(r).sort(I)){let m=r[d];if(!m)continue;let y=T("template",d),h=X(y,void 0,o);c.push(H({id:y,kind:"template",title:m.name,description:m.description,category:m.category,tags:m.keywords,aliases:[d,m.name],capabilities:[],dependencies:(m.composedFrom??[]).map((A)=>Er(A,y,s,r)),source:{type:"template-contract",id:d,...h?{license:h}:{}},receipt:Z(Boolean(h))}))}for(let d of[...i].sort((m,y)=>I(m.id,y.id))){let m=T("design-guide",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"design-guide",title:d.title,description:Ar(d),category:d.category,tags:d.tags,aliases:[d.id,d.title],capabilities:["designMd:source"],dependencies:[],source:{type:"design-md",id:d.id,...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...n].sort((m,y)=>I(m.id,y.id))){let m=T("example",d.id),y=X(m,d.license,o);c.push(H({id:m,kind:"example",title:d.title,description:d.description,...d.category?{category:d.category}:{},tags:d.tags??[],aliases:[d.id,d.title,...d.aliases??[]],capabilities:d.capabilities??[],dependencies:d.dependencies??[],source:{type:"example",id:d.id,...d.version?{version:d.version}:{},...d.sourceUrl?{url:d.sourceUrl}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of[...a].sort((m,y)=>I(m.id,y.id))){let m=T("skill",d.id),y=X(m,void 0,o);c.push(H({id:m,kind:"skill",title:d.title,description:d.description?.trim()||d.title,tags:[...d.tags??[],...d.triggers??[]],aliases:[d.id,d.title,...d.triggers??[]],capabilities:["skill:definition"],dependencies:[],source:{type:"skill",id:d.id,...d.version?{version:d.version}:{},...y?{license:y}:{}},receipt:Z(Boolean(y))}))}for(let d of e.additional??[])c.push(H(d));c.sort((d,m)=>I(d.id,m.id));let l=new Set;for(let d of c){if(l.has(d.id))throw new K("duplicate-resource-id",d.id);l.add(d.id)}for(let d of c)for(let m of d.dependencies)if(!l.has(m))throw new K("dangling-resource-dependency",`${d.id} -> ${m}`);let u=new Map;for(let d of c)for(let m of d.aliases){let y=C(m);if(!y)continue;let h=u.get(y)??new Set;h.add(d.id),u.set(y,h)}let f=Object.freeze(Object.fromEntries([...u.entries()].sort(([d],[m])=>I(d,m)).map(([d,m])=>[d,Object.freeze([...m].sort(I))]))),p=Object.freeze(c.map(wr));return Object.freeze({schemaVersion:kr,resources:p,aliases:f})}var Dr=[["chat","assistant","\u804A\u5929","\u52A9\u624B","\u5BF9\u8BDD"],["document","documents","\u6587\u6863","\u5199\u4F5C"],["auth","authentication","\u8BA4\u8BC1","\u767B\u5F55"],["data table","data grid","datatable","table","\u8868\u683C","\u6570\u636E\u8868","\u6570\u636E\u8868\u683C"],["button","action button","\u6309\u94AE","\u64CD\u4F5C\u6309\u94AE"],["dashboard","admin dashboard","\u4EEA\u8868\u76D8","\u540E\u53F0","\u7BA1\u7406\u540E\u53F0"],["kanban","kanban board","\u770B\u677F","\u4EFB\u52A1\u770B\u677F"],["form","input form","\u8868\u5355","\u8F93\u5165\u8868\u5355"],["navigation","nav","sidebar","\u5BFC\u822A","\u4FA7\u8FB9\u680F"]],Tr=Object.freeze(Dr.map((e)=>Object.freeze([...e]))),Ke=new Map;for(let e of Tr){let t=Object.freeze([...new Set(e.map(C).filter(Boolean))].sort());for(let r of t)Ke.set(r,t)}function Ce(e){let t=C(e);return Ke.get(t)??Object.freeze([t])}var Ps=["resource-query-empty","resource-query-invalid-limit","resource-not-found","resource-alias-ambiguous"];class w extends Error{code;detail;constructor(e,t){super(`${e}: ${t}`);this.code=e;this.detail=t;this.name="ResourceQueryError"}}var ke=Object.freeze({function:180,scenario:180,unit:180,industry:180,"exact-id":1000,"exact-title":900,alias:800,tag:600,capability:500,category:400,token:200,fuzzy:100}),Or=Object.freeze(Object.keys(ke)),We=new Map(Or.map((e,t)=>[e,t])),Ge=new Map([["component",0],["template",1],["design-guide",2],["example",3],["skill",4]]);function S(e,t){return e<t?-1:e>t?1:0}function Ye(e){return new Set((e??[]).map(C).filter(Boolean))}function B(e,t){let r=Ye(t);if(r.size===0)return!0;let i=Ye(e);return[...r].some((n)=>i.has(n))}function _r(e,t){if(!B(e.solution?.functions??[],t.functions))return!1;if(!B(e.solution?.scenarios??[],t.scenarios))return!1;if(!B(e.solution?[e.solution.unit]:[],t.units))return!1;if(!B(e.solution?.industries??[],t.industries))return!1;if(t.kinds?.length&&!t.kinds.includes(e.kind))return!1;if(!B(e.tags,t.tags))return!1;if(!B(e.category?[e.category]:[],t.categories))return!1;if(!B(e.capabilities,t.capabilities))return!1;if(t.maturities?.length&&!t.maturities.includes(e.receipt.maturity))return!1;return!0}function Fr(e){return Boolean(e.functions?.length||e.scenarios?.length||e.units?.length||e.industries?.length||e.kinds?.length||e.tags?.length||e.categories?.length||e.capabilities?.length||e.maturities?.length)}function P(e,t,r,i=ke[t]){if(e.some((n)=>n.code===t&&n.value===r))return;e.push({code:t,value:r,score:i})}function Re(e,t){return e.find((r)=>C(r)===t)}function xe(e){return[e.id,e.title,...e.aliases,...e.tags,...e.category?[e.category]:[],...e.capabilities,...e.solution?.functions??[],...e.solution?.scenarios??[],...e.solution?.industries??[]]}function Mr(e,t,r){if(Math.abs(e.length-t.length)>r)return r+1;let i=Array.from({length:t.length+1},(n,a)=>a);for(let n=1;n<=e.length;n+=1){let a=[n],o=n;for(let s=1;s<=t.length;s+=1){let c=(i[s-1]??r+1)+(e[n-1]===t[s-1]?0:1),l=Math.min((i[s]??r+1)+1,(a[s-1]??r+1)+1,c);a.push(l),o=Math.min(o,l)}if(o>r)return r+1;i=a}return i[t.length]??r+1}function Je(e,t){let r=C(t),i=[];if(C(e.id)===r)P(i,"exact-id",e.id);if(C(e.title)===r)P(i,"exact-title",e.title);let n=Re(e.aliases,r);if(n)P(i,"alias",n);let a=Re(e.tags,r);if(a)P(i,"tag",a);let o=Re(e.capabilities,r);if(o)P(i,"capability",o);if(e.category&&C(e.category)===r)P(i,"category",e.category);if(!n){let l=Ce(r).filter((f)=>f!==r),u=new Set(xe(e).map(C));if(l.some((f)=>u.has(f)))P(i,"alias",t.trim())}let s=r.split(" ").filter(Boolean),c=C(xe(e).join(" "));if(s.length>0&&s.every((l)=>c.includes(l)))P(i,"token",t.trim());if(i.length===0&&r.length>=4){let l;for(let u of xe(e)){let f=C(u);if(f.length<4)continue;let p=Mr(r,f,2);if(p<=2&&(!l||p<l.distance||p===l.distance&&S(u,l.value)<0))l={value:u,distance:p}}if(l)P(i,"fuzzy",l.value,ke.fuzzy-l.distance)}return i.sort((l,u)=>{if(l.score!==u.score)return u.score-l.score;return(We.get(l.code)??99)-(We.get(u.code)??99)||S(l.value,u.value)})}function Qe(e,t,r){if(t.has(r))return[r];let i=C(r),n=e.aliases[i];if(n?.length)return[...n];let a=new Set;for(let o of Ce(i))for(let s of e.aliases[o]??[])a.add(s);return[...a].sort(S)}function Ze(e,t){return new w("resource-alias-ambiguous",`${e.trim()}: ${t.join(",")}`)}function Xe(e){let t=new Map(e.resources.map((i)=>[i.id,i]));function r(i){let n=i.trim(),a=Qe(e,t,n);if(a.length===0)throw new w("resource-not-found",n);if(a.length>1)throw Ze(n,a);let o=a[0],s=o?t.get(o):void 0;if(!s)throw new w("resource-not-found",n);return s}return Object.freeze({manifest:()=>e,search(i){let n=i.text?.trim()??"";if(!n&&!Fr(i))throw new w("resource-query-empty","text or filter is required");if(i.limit!==void 0&&(!Number.isInteger(i.limit)||i.limit<=0))throw new w("resource-query-invalid-limit",String(i.limit));let a=e.resources.filter((o)=>_r(o,i)).filter((o)=>!n||Je(o,n).length>0).map((o)=>{let s=n?Je(o,n):[];for(let[c,l]of[[i.functions,"function"],[i.scenarios,"scenario"],[i.units,"unit"],[i.industries,"industry"]])if(c?.length)P(s,l,c.join(","));return{resource:o,score:s.reduce((c,l)=>c+l.score,0),reasons:s}}).filter((o)=>!n||o.reasons.length>0).sort((o,s)=>s.score-o.score||S(o.resource.id,s.resource.id));return i.limit===void 0?a:a.slice(0,i.limit)},get:r,build(i){if(i.length===0||i.every((p)=>!p.trim()))throw new w("resource-query-empty","at least one build root is required");let n=[],a=new Set;for(let p of i){let d=p.trim(),m=Qe(e,t,d);if(m.length===0)n.push({id:d,reason:"missing-resource"});else if(m.length>1)throw Ze(d,m);else{let y=m[0];if(y)a.add(y)}}let o=new Set,s=new Set,c=new Set,l=[],u=[],f=(p,d)=>{if(o.has(p))return;if(s.has(p)){n.push({id:p,...d?{requiredBy:d}:{},reason:"dependency-cycle"});return}let m=t.get(p);if(!m){n.push({id:p,...d?{requiredBy:d}:{},reason:"missing-resource"});return}s.add(p),c.add(p);let y=[...m.dependencies].sort((h,A)=>{let N=t.get(h),_=t.get(A);return(Ge.get(N?.kind??"")??99)-(Ge.get(_?.kind??"")??99)||S(h,A)});for(let h of y)u.push({from:p,to:h,relation:"depends-on"}),f(h,p);s.delete(p),o.add(p),l.push(p)};for(let p of[...a].sort(S))f(p);return{roots:[...a].sort(S),nodes:[...c].sort(S).map((p)=>{let d=t.get(p);if(!d)throw new w("resource-not-found",p);return{id:p,kind:d.kind,maturity:d.receipt.maturity}}),edges:u.sort((p,d)=>S(p.from,d.from)||S(p.to,d.to)),order:l,gaps:n.sort((p,d)=>S(p.id,d.id)||S(p.requiredBy??"",d.requiredBy??"")||S(p.reason,d.reason))}}})}function Nr(e){if(!e||typeof e!=="object")throw Error("invalid-public-resource-bundle");$r(e);let t=e;if(t.schemaVersion!=="uibot.public-resources.v1"||typeof t.release?.version!=="string"||!/^[a-f0-9]{64}$/.test(t.release?.sourceHash)||t.index?.schemaVersion!=="uibot.resource.index.v1"||!Array.isArray(t.index.resources)||!t.index.aliases||!t.showcases)throw Error("invalid-public-resource-bundle");if(t.documents&&(!Array.isArray(t.documents)||t.documents.some((n)=>typeof n.title!=="string"||typeof n.markdown!=="string"||!/^\/(?:en\/)?docs\/[a-z0-9-]+$/.test(n.path))))throw Error("invalid-public-documentation");let r=new Set,i=new Set;for(let n of t.index.resources){if(!n||typeof n.id!=="string"||r.has(n.id)||!De.includes(n.kind)||!n.id.startsWith(`${n.kind}:`)||typeof n.description!=="string"||typeof n.title!=="string"||!Array.isArray(n.dependencies)||!n.source||!n.receipt||!Array.isArray(n.aliases)||!Array.isArray(n.tags)||!Array.isArray(n.capabilities)||![n.aliases,n.dependencies,n.tags,n.capabilities].every((o)=>o.every((s)=>typeof s==="string"&&s.length<=1000))||!["catalog","template-contract","design-md","example","skill","registry","package","theme"].includes(n.source.type)||typeof n.source.id!=="string"||n.source.sourceHash!==void 0&&!/^[a-f0-9]{64}$/.test(n.source.sourceHash)||n.source.packageName!==void 0&&(typeof n.source.packageName!=="string"||!n.source.packageName.startsWith("@uibot/"))||!te.includes(n.receipt.maturity)||!Te.includes(n.receipt.level)||!Array.isArray(n.receipt.evidence)||!n.receipt.evidence.every((o)=>typeof o==="string")||!Y.every((o)=>re.includes(n.receipt.checks?.[o])))throw Error("invalid-public-resource");if(r.add(n.id),n.solution){let o=n.solution;if(![o.functions,o.scenarios,o.industries,o.hostRequirements,o.limitations].every((s)=>Array.isArray(s)&&s.every((c)=>typeof c==="string"&&c.length>0&&c.length<=2000))||!["page","flow","industry"].includes(o.unit)||!["interactive-demo","needs-enhancement"].includes(o.readiness)||o.members!==void 0&&(!Array.isArray(o.members)||o.members.some((s)=>typeof s.resourceId!=="string"||typeof s.version!=="string"||!s.version||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))))throw Error("invalid-resource-solution")}let a=t.showcases[n.id];if(!a||a.resourceId!==n.id||typeof a.docs?.zh!=="string"||typeof a.docs?.en!=="string"||!Array.isArray(a.examples)||!Array.isArray(a.distributions))throw Error("invalid-resource-showcase");if(a.collection!==void 0){let o=a.collection;if(!o||typeof o.id!=="string"||!/^[a-z0-9-]+$/.test(o.id)||typeof o.group?.id!=="string"||!/^[a-z0-9-]+$/.test(o.group.id)||[o.title,o.group.title].some((s)=>!s||[s.zh,s.en].some((c)=>typeof c!=="string"||!c.trim()||c.length>200)))throw Error("invalid-resource-collection")}if(a.agentKit!==void 0){let o=a.agentKit;if(i.has(n.source?.id))throw Error("invalid-resource-agent-kit");if(i.add(n.source?.id),!o||!["skill","prompt","recipe"].includes(o.type)||(o.type==="skill"?n.kind!=="skill":n.kind!=="example")||!/^[a-z][a-z0-9-]*$/.test(n.source.id)||o.fileName!=={skill:"SKILL.md",prompt:"PROMPT.md",recipe:"RECIPE.md"}[o.type]||[o.summary?.zh,o.summary?.en].some((s)=>typeof s!=="string"||!s.trim())||!Array.isArray(o.resources)||new Set(o.resources.map((s)=>s?.id)).size!==o.resources.length||o.resources.some((s)=>!s||!n.dependencies.includes(s.id)||!t.index.resources.some((c)=>c.id===s.id&&(c.source.version??null)===s.version)||s.version!==null&&(typeof s.version!=="string"||!s.version)||typeof s.contentHash!=="string"||!/^[a-f0-9]{64}$/.test(s.contentHash)||s.sourceHash!==void 0&&(typeof s.sourceHash!=="string"||!/^[a-f0-9]{64}$/.test(s.sourceHash)))||o.resources.length!==n.dependencies.length)throw Error("invalid-resource-agent-kit")}if(a.solutionControls!==void 0){let o=new Set;if(!Array.isArray(a.solutionControls)||a.solutionControls.some((s)=>{if(!s||typeof s.id!=="string"||o.has(s.id)||typeof s.label?.zh!=="string"||typeof s.label?.en!=="string"||!Array.isArray(s.values)||!s.values.length||s.values.some((c)=>!["string","boolean","number"].includes(typeof c)||typeof c==="number"&&!Number.isFinite(c))||typeof s.target?.pageId!=="string"||typeof s.target?.property!=="string"||["__proto__","prototype","constructor"].includes(s.target.property)||s.target.blockId!==void 0&&typeof s.target.blockId!=="string")return!0;return o.add(s.id),!1}))throw Error("invalid-solution-controls")}if(a.templateContract&&(a.templateContract.name!==n.source.id||typeof a.templateContract.description!=="string"||!["L3","L4","L5"].includes(a.templateContract.level)||!["feature","template","page","app"].includes(a.templateContract.category)||!Array.isArray(a.templateContract.keywords)))throw Error("invalid-public-template-contract");if(typeof a.title?.zh!=="string"||typeof a.title?.en!=="string"||a.examples.some((o)=>!o||typeof o.id!=="string"||typeof o.title!=="string"||typeof o.code!=="string"||!["spec","tsx","source"].includes(o.mode)||!["tsx","json","yaml","css","ts"].includes(o.language)||!Array.isArray(o.dependencies)||!o.dependencies.every((s)=>typeof s==="string"))||a.distributions.some((o)=>!o||!["spec","npm","shadcn"].includes(o.channel)||typeof o.name!=="string"||!/^[@a-zA-Z0-9._/-]+$/.test(o.name)||typeof o.version!=="string"||!["source","published"].includes(o.availability)||o.connections!==void 0&&(o.channel!=="spec"||!Array.isArray(o.connections)||o.connections.some((s)=>typeof s!=="string"||!s))))throw Error("invalid-resource-content")}for(let[n,a]of Object.entries(t.index.aliases))if(!n||!Array.isArray(a)||a.some((o)=>!r.has(o)))throw Error("invalid-public-resource-alias");if(Object.keys(t.showcases).some((n)=>!r.has(n)))throw Error("unexpected-public-resource-showcase");for(let n of t.index.resources)for(let a of n.dependencies)if(!r.has(a))throw Error("invalid-public-resource-dependency");if(t.distributionSnapshot){let n=t.distributionSnapshot;if(!/^[a-f0-9]{64}$/.test(n.snapshotId)||n.manifestPath!==`../snapshots/${n.snapshotId}/snapshot.json`||!n.resources||!n.unavailable||!n.external||Object.entries(n.external).some(([a,o])=>!Object.hasOwn(n.unavailable,a)||!Array.isArray(o)||o.some((s)=>typeof s!=="string"||s.startsWith("@uibot/"))))throw Error("invalid-distribution-snapshot-reference");for(let[a,o]of Object.entries(n.resources))if(!r.has(a)||o.version!==(t.index.resources.find((s)=>s.id===a)?.source.version??t.release.version)||!/^[a-f0-9]{64}$/.test(o.resourceHash)||!Array.isArray(o.entrypoints)||!o.entrypoints.length||!Array.isArray(o.closure)||![...o.entrypoints,...o.closure].every((s)=>/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(s))||o.entrypoints.some((s)=>!o.closure.includes(s)))throw Error("invalid-distribution-snapshot-resource")}}function Os(e){Nr(e),e=JSON.parse(JSON.stringify(e));let t=(n)=>{if(n&&typeof n==="object"){for(let a of Object.values(n))t(a);Object.freeze(n)}};t(e);let r=Xe(e.index),i=(n)=>{let a=r.get(n),o=e.showcases[a.id];if(!o)throw new w("resource-not-found",a.id);return o};return Object.freeze({...r,get(n){let a=r.get(n),o=i(n).agentKit;return o?Object.freeze({...a,agentKit:o}):a},docs(n,a="zh",o=1){if(a!=="zh"&&a!=="en")throw Error("unsupported-resource-locale");let s=i(n);return{resourceId:s.resourceId,locale:a,...Br(s.docs[a],o),release:e.release}},examples(n,a=1){let o=i(n);return{resourceId:o.resourceId,...Vr(o.examples,a),release:e.release}},installPlan(n){let a=i(n);return{resourceId:a.resourceId,distributions:a.distributions,dependencies:r.build([a.resourceId]),release:e.release,snapshot:e.distributionSnapshot&&Object.hasOwn(e.distributionSnapshot.resources,a.resourceId)?{snapshotId:e.distributionSnapshot.snapshotId,manifestPath:e.distributionSnapshot.manifestPath,...e.distributionSnapshot.resources[a.resourceId]}:null,snapshotUnavailable:e.distributionSnapshot?.unavailable[a.resourceId]??null,install:a.distributions.map((o)=>jr(o,e.distributionSnapshot,a.resourceId))}}})}var Lr={"NowAPI.Collection":{real:"@uibot/connection-nowapi",demo:"createAdminPreviewDriver from @uibot/blocks-shadcn/solutions"},"Mock.Collection":{real:null,demo:"@uibot/connection-mock/browser"},Http:{real:"@uibot/connection-http",demo:null},"Pg.Collection":{real:"@uibot/connection-pg (server only)",demo:null}};function jr(e,t,r){let{channel:i,name:n,version:a}=e;if(i==="npm")return{channel:i,name:n,command:`add ${n}@${a}`,note:null};if(i==="spec"){let c=Object.entries(e.dependencies??{}).map(([l,u])=>`${l}@${u}`);return{channel:i,name:n,command:c.length?`add ${c.join(" ")}`:null,drivers:(e.connections??[]).map((l)=>({type:l,...Lr[l]??{real:null,demo:null}})),note:"Read the Spec through examples (join paginated code), compile it strictly at build time with the Catalog from @uibot/blocks-shadcn/catalog (plus the other packages listed), then render with createLiveRuntimeAdapter from @uibot/runtime and UIBotLiveRenderer from @uibot/renderer-react, one adapter per page. Register a driver for each connection type."}}let o=!!t&&Object.hasOwn(t.resources,r),s=t?.external[r]??[];return{channel:i,name:n,command:`shadcn add @uibot/${n}`,registries:{"@uibot":"/r/{name}.json"},externalRegistryDependencies:s,note:o?"A hash-pinned snapshot exists: export and verify it, then map @uibot to the local snapshot server.":s.length?`No hash-pinned snapshot: the install also pulls stock shadcn items (${s.join(", ")}) from the host's default registry. Installing through the portal mapping still works; report the files as not snapshot-verified.`:"No hash-pinned snapshot; report the files as not snapshot-verified."}}var M=24000;function et(e,t){if(!Number.isSafeInteger(e)||e<1||e>Math.max(1,t))throw new w("resource-query-invalid-limit","page is outside the available range")}function Br(e,t){let r=Math.max(1,Math.ceil(e.length/M));return et(t,r),{markdown:e.slice((t-1)*M,t*M),page:t,totalPages:r,...t<r?{nextPage:t+1}:{}}}function Vr(e,t){let r=e.flatMap((i)=>Array.from({length:Math.max(1,Math.ceil(i.code.length/M))},(n,a)=>({...i,code:i.code.slice(a*M,(a+1)*M),codeOffset:a*M,codeLength:i.code.length,complete:i.code.length<=M})));return et(t,r.length),{examples:r.slice(t-1,t),page:t,totalPages:r.length,...t<r.length?{nextPage:t+1}:{}}}function $r(e){let t=0,r=0,i=new Set,n=(a,o)=>{if(++t>300000||o>64)throw Error("public-resource-budget-exceeded");if(typeof a==="string"){if(r+=new TextEncoder().encode(a).length,r>16777216)throw Error("public-resource-budget-exceeded")}else if(a&&typeof a==="object"){if(i.has(a))throw Error("invalid-public-resource-cycle");let s=Object.getPrototypeOf(a);if(!Array.isArray(a)&&s!==Object.prototype&&s!==null)throw Error("invalid-public-resource-object");i.add(a);for(let[c,l]of Object.entries(a))n(c,o+1),n(l,o+1);i.delete(a)}else if(a!==null&&typeof a!=="boolean"&&(typeof a!=="number"||!Number.isFinite(a)))throw Error("invalid-public-resource-json")};n(e,1)}import{createHash as Ur}from"crypto";var le=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,se=/^[a-f0-9]{64}$/,ae=/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/,tt=new TextEncoder,zr=new TextDecoder("utf-8",{fatal:!0});function de(e){return Ur("sha256").update(e).digest("hex")}function V(e){let t=0,r=(n,a)=>{if(++t>400000||a>32)throw Error("snapshot-json-budget-exceeded");if(Array.isArray(n))return n.map((o)=>r(o,a+1));if(n&&typeof n==="object"){if(Object.getPrototypeOf(n)!==Object.prototype)throw Error("snapshot-invalid-json");return Object.fromEntries(Object.keys(n).sort().map((o)=>[o,r(n[o],a+1)]))}if(n===null||typeof n==="string"||typeof n==="boolean"||typeof n==="number"&&Number.isFinite(n))return n;throw Error("snapshot-invalid-json")},i=JSON.stringify(r(e,0));if(tt.encode(i).length>16777216)throw Error("snapshot-json-budget-exceeded");return i}function ce(e){if(typeof e!=="string"||!/^[a-zA-Z0-9_./-]+$/.test(e)||e.split("/").some((t)=>!t||t==="."||t==="..")||e.startsWith("/"))throw Error(`snapshot-unsafe-path: ${e}`)}function Ie(e,t){return ce(e),{path:e,bytes:t.byteLength,sha256:de(t)}}function qr(e){if(typeof e!=="string"||!e.startsWith("@uibot/")||!le.test(e.slice(7)))throw Error(`snapshot-external-registry-dependency: ${e}`);return e.slice(7)}function rt(e,t){if(!le.test(e)||t.byteLength>16777216)throw Error("snapshot-invalid-item");let r=JSON.parse(zr.decode(t));if(r.name!==e||!Array.isArray(r.files)||r.files.length>2000||(r.devDependencies?.length??0)>0)throw Error(`snapshot-invalid-item: ${e}`);let i={};for(let s of r.dependencies??[]){let c=s.lastIndexOf("@"),l=s.slice(0,c),u=s.slice(c+1);if(c<1||!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u)||i[l]&&i[l]!==u)throw Error(`snapshot-unpinned-npm-dependency: ${s}`);i[l]=u}let n=[...new Set((r.registryDependencies??[]).map(qr))].sort(),a=new Set,o=r.files.map((s)=>{if(typeof s.content!=="string")throw Error(`snapshot-missing-file-content: ${e}`);let c=s.target??s.path;if(ce(c),a.has(c))throw Error(`snapshot-duplicate-target: ${c}`);return a.add(c),{...Ie(s.path,tt.encode(s.content)),target:c}});return{...Ie(`r/${e}.json`,t),registryDependencies:n,npmDependencies:i,files:o}}function nt(e,t){let r=new Set,i=new Set,n=(s)=>{if(!le.test(s)||!Object.hasOwn(e,s))throw Error(`snapshot-missing-item: ${s}`);if(i.has(s))throw Error(`snapshot-dependency-cycle: ${s}`);if(r.has(s))return;i.add(s);for(let c of e[s].registryDependencies)n(c);i.delete(s),r.add(s)};if(!t.length)throw Error("snapshot-empty-entrypoints");t.forEach(n);let a=new Map,o=new Map;for(let s of r){for(let c of e[s].files){let l=a.get(c.target);if(l&&l!==c.sha256)throw Error(`snapshot-target-conflict: ${c.target}`);a.set(c.target,c.sha256)}for(let[c,l]of Object.entries(e[s].npmDependencies)){if(o.has(c)&&o.get(c)!==l)throw Error(`snapshot-npm-conflict: ${c}`);o.set(c,l)}}return[...r].sort()}function Ms(e){let t=Object.fromEntries(Object.entries(e.items).map(([a,o])=>[a,rt(a,o)])),r=Object.fromEntries(Object.entries(e.resources).map(([a,o])=>[a,{...o,closure:nt(t,o.entrypoints)}])),i={schemaVersion:"uibot.distribution.snapshot.v1",bundleHash:e.bundleHash,version:e.version,namespace:"@uibot",resources:r,items:t,license:"MIT AND ISC",licenseFiles:Object.entries(e.licenseFiles).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>Ie(a,o))},n={...i,snapshotId:de(V(i))};return it(n),n}function it(e,t){if(!e||typeof e!=="object")throw Error("snapshot-invalid-manifest");V(e);let r=e,{snapshotId:i,...n}=r;if(r.schemaVersion!=="uibot.distribution.snapshot.v1"||r.namespace!=="@uibot"||r.license!=="MIT AND ISC"||!ae.test(r.version)||!se.test(r.bundleHash)||!se.test(i)||t!==void 0&&t!==i||de(V(n))!==i)throw Error("snapshot-identity-mismatch");if(!r.items||!r.resources||!Array.isArray(r.licenseFiles)||!r.licenseFiles.length)throw Error("snapshot-invalid-manifest");let a=(s)=>{if(ce(s.path),!se.test(s.sha256)||!Number.isSafeInteger(s.bytes)||s.bytes<0||s.bytes>16777216)throw Error("snapshot-invalid-file-digest")},o=new Set;for(let s of r.licenseFiles){if(a(s),!s.path.startsWith("licenses/")||o.has(s.path))throw Error("snapshot-invalid-license");o.add(s.path)}for(let[s,c]of Object.entries(r.items)){if(a(c),!le.test(s)||c.path!==`r/${s}.json`||!Array.isArray(c.registryDependencies)||!Array.isArray(c.files)||!c.npmDependencies)throw Error("snapshot-invalid-item");for(let l of c.files)a(l),ce(l.target);for(let[l,u]of Object.entries(c.npmDependencies))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(l)||!ae.test(u))throw Error("snapshot-unpinned-npm-dependency")}for(let s of Object.values(r.resources))if(!ae.test(s.version)||!se.test(s.resourceHash)||!Array.isArray(s.entrypoints)||V(nt(r.items,s.entrypoints))!==V(s.closure))throw Error("snapshot-resource-closure-mismatch")}function Ns(e,t,r,i){it(e,i);let n=Object.hasOwn(e.resources,t)?e.resources[t]:void 0;if(!n)throw Error(`snapshot-resource-unavailable: ${t}`);let a=(s)=>{let c=r.get(s.path);if(!c||c.byteLength!==s.bytes||de(c)!==s.sha256)throw Error(`snapshot-file-mismatch: ${s.path}`);return c},o={};for(let s of n.closure){let c=e.items[s],l=rt(s,a(c));if(V(l)!==V(c))throw Error(`snapshot-item-metadata-mismatch: ${s}`);Object.assign(o,c.npmDependencies)}return e.licenseFiles.forEach(a),{snapshotId:e.snapshotId,resourceId:t,closure:[...n.closure],npmDependencies:o}}function Jr(e){if(!e.name)throw Error("Artifact registry manifest requires a name");return e}function Qr(e){if(!e.name)throw Error("Plugin distribution manifest requires a name");return e}class Zr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}class Xr{id;priority;items;constructor(e,t,r){this.id=e;this.priority=t;this.items=r}get(e){return this.items[e]}}async function lt(e,t){let r=await fetch(e,t?{headers:t}:{});if(!r.ok)throw Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);return await r.json()}async function en(e,t){let r=e.endsWith("/registry.json")?e:`${e.replace(/\/$/,"")}/registry.json`,i=await lt(r,t);return Jr(i)}async function tn(e,t){let r=e.endsWith("/plugins.json")?e:`${e.replace(/\/$/,"")}/plugins.json`,i=await lt(r,t);return Qr(i)}class rn{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=en(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).items.find((r)=>r.name===e)}}class nn{options;id;priority;manifestPromise;constructor(e){this.options=e;this.id=e.id??e.registryUrl,this.priority=e.priority}getManifest(){return this.manifestPromise??=tn(this.options.registryUrl,this.options.headers),this.manifestPromise}async get(e){return(await this.getManifest()).plugins.find((r)=>r.pluginId===e)}}class on{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}class sn{sources;constructor(e){this.sources=e}async resolve(e){let t=[...this.sources].sort((r,i)=>r.priority-i.priority);for(let r of t){let i=await r.get(e);if(i)return i}return}}var an="uibot.artifacts.lock.json";function cn(e){return O(e,"components","registry")}function ln(e){return O(e,"templates","registry")}function dn(e,t){if(e.kind==="component")return O(t.componentsDir??cn(t.workspaceRoot));return O(t.templatesDir??ln(t.workspaceRoot))}function un(e){return O(e.workspaceRoot,e.lockfilePath??an)}function pn(e){try{return JSON.parse(Kr(e,"utf8"))}catch{return{version:1,artifacts:[]}}}function gn(e,t){at(Se(e),{recursive:!0}),ct(e,`${JSON.stringify(t,null,2)}
15
+ `,"utf8")}function mn(e,t){return{version:1,artifacts:[...e.artifacts.filter((i)=>i.name!==t.name),t].sort((i,n)=>i.name.localeCompare(n.name))}}function fn(e){if(e.kind==="component")return{components:{[e.name]:e.catalogEntry}};return{templates:{[e.name]:e.templateContract}}}class U extends Error{artifactName;offendingPath;baseDir;constructor(e,t,r){super(`Artifact "${e}" file path escapes workspace: "${t}" resolves outside "${r}"`);this.artifactName=e;this.offendingPath=t;this.baseDir=r;this.name="ArtifactContainmentError"}}function dt(e,t){let r=t.endsWith(ot)?t:t+ot;return e===t||e.startsWith(r)}function st(e){let t=O(e),r=[];while(!0)try{return Hr(t),O(Wr(t),...r)}catch(i){if(i.code!=="ENOENT")throw i;let n=Se(t);if(n===t)throw i;r.unshift(Gr(t)),t=n}}function ut(e,t,r,i){try{let n=st(t),a=st(e);if(!dt(a,n))throw new U(r,i,t)}catch(n){if(n instanceof U)throw n;throw new U(r,i,t)}}function pt(e,t,r){if(e.includes("\x00"))throw new U(r,e,t);if(Yr(e))throw new U(r,e,t);let i=O(t,e);if(!dt(i,t))throw new U(r,e,t);return ut(i,t,r,e),i}function yn(e,t){let r=[];for(let i of e.files){let n=i.target??i.path;r.push(pt(n,t,e.name))}return r}function Vs(e,t){let r=O(t.workspaceRoot),i=dn(e,t);ut(i,r,e.name,i);let n=pt(e.name,i,e.name),a=yn(e,n),o=[];for(let f=0;f<e.files.length;f++){let p=e.files[f],d=a[f];at(Se(d),{recursive:!0}),ct(d,p.content??"","utf8"),o.push(d)}let s={name:e.name,version:e.version,source:t.source??"registry",installedAt:new Date().toISOString()},c=un(t),l=pn(c),u=mn(l,s);return gn(c,u),{artifactLock:s,catalogPatch:fn(e),writtenFiles:o}}export{U as ArtifactContainmentError,on as ArtifactRegistryResolver,Zr as MemoryArtifactRegistrySource,Xr as MemoryPluginRegistrySource,sn as PluginRegistryResolver,ps as RESOURCE_ADMISSION_ERROR_CODES,he as RESOURCE_ADMISSION_SCHEMA_VERSION,sr as RESOURCE_EXTERNAL_CHECKS,Cs as RESOURCE_INDEX_ERROR_CODES,kr as RESOURCE_INDEX_SCHEMA_VERSION,or as RESOURCE_PREFLIGHT_CHECKS,Tr as RESOURCE_QUERY_ALIAS_GROUPS,Ps as RESOURCE_QUERY_ERROR_CODES,Vt as RESOURCE_QUERY_OPERATION_MANIFEST,ke as RESOURCE_QUERY_SCORE_WEIGHTS,rn as RemoteArtifactRegistrySource,nn as RemotePluginRegistrySource,Be as ResourceAdmissionIndexMismatchError,$e as ResourceAdmissionReportNotDerivedError,Ve as ResourceAdmissionReportRejectedError,K as ResourceIndexError,w as ResourceQueryError,as as SHADCN_REGISTRY_ITEM_SCHEMA,fe as UIBOT_BASE_ITEM,_e as UIBOT_THEME_ITEM,ys as applyResourceAdmissionReport,ce as assertDistributionPath,it as assertDistributionSnapshot,pt as assertPathContained,Nr as assertPublicResourceBundle,fs as assessResourceAdmissions,Rs as buildExamplesFromL4Templates,xs as buildResourceIndex,ss as buildShadcnRegistry,Pn as buildUiBotRegistryManifest,Jt as catalogEntryToMeta,xn as collectAllBlockSources,It as collectBlockSources,Pe as collectTemplateSources,Dt as collectTemplateSourcesFromDirs,mt as compareLockToManifest,Ms as createDistributionSnapshot,Os as createPublicResourceQueryService,Xe as createResourceQueryService,ls as createUIBotRegistryHttpHandler,gs as deriveResourceLicense,rt as describeDistributionItem,V as distributionCanonicalJson,nt as distributionClosure,de as distributionSha256,vn as emitArtifactJson,yt as emptyLockfile,ms as evaluateCatalogPreflight,Ce as expandResourceQueryAliases,en as fetchArtifactRegistryManifest,tn as fetchPluginDistributionManifest,Vs as installArtifactToWorkspace,ht as lockfileWith,ir as normalizeRegistryBasePath,C as normalizeResourceAlias,j as normalizeResourceLicense,os as parseOklchCssVars,Qr as parsePluginDistributionManifest,Jr as parseRegistryManifest,He as resourceAdmissionIndexFingerprint,qr as snapshotDependencyName,ge as templateSourceToRegistryItem,Ee as toArtifactRegistryItem,Nt as toComponentArtifact,ye as toItemName,T as toResourceId,ve as toTemplateArtifact,Fe as transformBlockSource,Ns as verifyDistributionSnapshot};
@@ -4,3 +4,4 @@ export * from "./public-resources.js";
4
4
  export * from "./solution-spec.js";
5
5
  export * from "./solution-composition.js";
6
6
  export * from "./solution-regions.js";
7
+ export * from "./component-replacement.js";