2121from dataclasses import dataclass , field , replace
2222from typing import Any , Dict , List , Optional , Union , TYPE_CHECKING
2323from urllib .parse import urlparse
24+ from a2ui .core .catalog import JsonCatalog
2425
2526from .catalog_provider import A2uiCatalogProvider , FileSystemCatalogProvider
2627from .constants import (
3233 VERSION_0_8 ,
3334 ENCODING ,
3435)
35- from .validator import A2uiValidator
36+
37+ if TYPE_CHECKING :
38+ from .validator import A2uiValidator
3639
3740
3841@dataclass
@@ -48,12 +51,16 @@ class CatalogConfig:
4851 provider: The provider to use to load the catalog schema.
4952 examples_path: The path or glob pattern to the examples.
5053 custom_cuttable_keys: The optional custom set of cuttable keys.
54+ custom_single_refs: The optional list of refs to be treated as single items.
55+ custom_list_refs: The optional list of refs to be treated as list items.
5156 """
5257
5358 name : str
5459 provider : A2uiCatalogProvider
5560 examples_path : Optional [str ] = None
5661 custom_cuttable_keys : Optional [frozenset [str ]] = None
62+ custom_single_refs : Optional [List [str ]] = None
63+ custom_list_refs : Optional [List [str ]] = None
5764
5865 @classmethod
5966 def from_path (
@@ -62,6 +69,8 @@ def from_path(
6269 catalog_path : str ,
6370 examples_path : Optional [str ] = None ,
6471 custom_cuttable_keys : Optional [frozenset [str ]] = None ,
72+ custom_single_refs : Optional [List [str ]] = None ,
73+ custom_list_refs : Optional [List [str ]] = None ,
6574 ) -> "CatalogConfig" :
6675 """Returns a CatalogConfig that loads from a local path or 'file://' URI."""
6776 parsed = urlparse (catalog_path )
@@ -79,6 +88,10 @@ def from_path(
7988 }
8089 if custom_cuttable_keys is not None :
8190 kwargs ["custom_cuttable_keys" ] = custom_cuttable_keys
91+ if custom_single_refs is not None :
92+ kwargs ["custom_single_refs" ] = custom_single_refs
93+ if custom_list_refs is not None :
94+ kwargs ["custom_list_refs" ] = custom_list_refs
8295
8396 return cls (** kwargs )
8497
@@ -151,6 +164,8 @@ class A2uiCatalog:
151164 catalog_schema: The catalog schema.
152165 custom_cuttable_keys: The optional set of keys whose string values can be safely auto-closed
153166 (healed) if fragmented in the stream. If None, the default set is used.
167+ custom_single_refs: The optional list of refs to be treated as single items.
168+ custom_list_refs: The optional list of refs to be treated as list items.
154169 """
155170
156171 version : str
@@ -159,6 +174,8 @@ class A2uiCatalog:
159174 common_types_schema : Dict [str , Any ]
160175 catalog_schema : Dict [str , Any ]
161176 custom_cuttable_keys : Optional [frozenset [str ]] = None
177+ custom_single_refs : Optional [List [str ]] = None
178+ custom_list_refs : Optional [List [str ]] = None
162179
163180 @property
164181 def cuttable_keys (self ) -> frozenset [str ]:
@@ -173,9 +190,22 @@ def catalog_id(self) -> str:
173190 return self .catalog_schema [CATALOG_ID_KEY ]
174191
175192 @property
176- def validator (self ) -> A2uiValidator :
193+ def validator (self ) -> "A2uiValidator" :
194+ from .validator import A2uiValidator
195+
177196 return A2uiValidator (self )
178197
198+ @property
199+ def core_catalog (self ) -> JsonCatalog :
200+ return JsonCatalog (
201+ version = self .version ,
202+ catalog_schema = self .catalog_schema ,
203+ catalog_id = self .catalog_id ,
204+ common_types_schema = self .common_types_schema ,
205+ custom_single_refs = self .custom_single_refs ,
206+ custom_list_refs = self .custom_list_refs ,
207+ )
208+
179209 def _with_pruned_components (self , allowed_components : List [str ]) -> A2uiCatalog :
180210 """Returns a new catalog with only allowed components.
181211
0 commit comments