UNPKG

@copilotkit/a2ui-renderer

Version:

A2UI Renderer for CopilotKit - render A2UI surfaces in React applications

1 lines 1.59 kB
{"version":3,"file":"filter-catalog.cjs","names":["Catalog"],"sources":["../../src/react-renderer/filter-catalog.ts"],"sourcesContent":["import { Catalog } from \"@a2ui/web_core/v0_9\";\nimport type { ComponentApi } from \"@a2ui/web_core/v0_9\";\n\n/**\n * Rebuild a Catalog keeping only components whose `name` passes `predicate`.\n *\n * Pure: does not mutate the source catalog. The returned catalog preserves the\n * original `id`, all `functions`, and the `themeSchema`; only the component set\n * is narrowed. Used by react-core to enforce per-component enable/disable on\n * BOTH the advertisement path (context) and the render path.\n *\n * @typeParam T - The component implementation type carried by the catalog.\n * @param catalog - The source catalog.\n * @param predicate - Returns true to KEEP a component with the given name.\n */\nexport function filterCatalog<T extends ComponentApi>(\n catalog: Catalog<T>,\n predicate: (name: string) => boolean,\n): Catalog<T> {\n const keptComponents: T[] = [];\n for (const [name, component] of catalog.components) {\n if (predicate(name)) {\n keptComponents.push(component);\n }\n }\n const functions = Array.from(catalog.functions.values());\n return new Catalog<T>(\n catalog.id,\n keptComponents,\n functions,\n catalog.themeSchema,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,cACd,SACA,WACY;CACZ,MAAM,iBAAsB,EAAE;AAC9B,MAAK,MAAM,CAAC,MAAM,cAAc,QAAQ,WACtC,KAAI,UAAU,KAAK,CACjB,gBAAe,KAAK,UAAU;CAGlC,MAAM,YAAY,MAAM,KAAK,QAAQ,UAAU,QAAQ,CAAC;AACxD,QAAO,IAAIA,4BACT,QAAQ,IACR,gBACA,WACA,QAAQ,YACT"}