Repository navigation
feat(python,cli)!: self-stamp v1.0 builders & stateless MacroExpander - #4550
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a breaking change where generated v1.0 catalog builders and Dart a2ui_cli v1.0 output now self-stamp their catalog URI by default (@catalogId on components and catalogId on non-system function calls). Additionally, MacroExpander has been refactored to be pure and stateless, removing base_catalogs, register_catalog(), internal surface tracking, and the surface_catalogs parameter from transport transformation methods. Conformance tests, golden files, and Python builders have been updated to align with this new stateless architecture. As there are no review comments, I have no additional feedback to provide.
…xpander stateless Signed-off-by: Jacob Simionato <jsimionato@google.com>
8199590 to
a76c7ba
Compare
72def38 to
64020df
Compare
|
GitHub marked this PR as merged when I reordered the stack: its commit became reachable from the old base branch. Nothing landed on |
Problem
In A2UI v1.0, surfaces can mix components from multiple catalogs by tagging each component with
@catalogIdand each catalog function call withcatalogId. Previously, generated Python v1.0 builders omitted catalog IDs, which forcedMacroExpander(the server-side engine that expands high-level macros into client primitive components) to hold mutable session state: a registry of client-supported catalogs, a 256-entry surface-to-default-catalog cache, a per-callsurface_catalogsescape hatch, and post-expansion auto-stamping walks.That mutable state made
MacroExpanderunsafe to share across concurrent requests and coupled macro expansion to catalog registration order. Having generated v1.0 builders carry their own catalog IDs eliminates that state completely.Summary
dart/a2ui_cli(the Python builder code generator) and regeneratea2ui.builder.v1_0.catalogs.basicso v1.0 component builders and catalog function calls automatically emit their owning catalog URI when serialized to wire messages (leaving built-in@-prefixed system functions unannotated, supportingcatalog_id=Noneopt-out, and leaving v0.9 builders unchanged).MacroExpander: Remove all mutable catalog registries, surface-tracking caches, and post-expansion auto-stamping walks, making oneMacroExpanderinstance safe to share across concurrent requests and sessions.createSurfacewhosecatalogIdnames the macro catalog, stripcreateSurface.catalogIdto produce a defaultless surface (no top-levelcatalogId), where every expanded primitive carries its own explicit@catalogId.Breaking & behavior changes
Warning
Breaking API change for v1.0
MacroExpandercallers and custom v1.0 builder classes.MacroExpanderAPIs: Removedbase_catalogsfromMacroExpander.__init__, removedMacroExpander.register_catalog(), and removed thesurface_catalogsargument fromtransform_to_transport()andatransform_to_transport().base_catalogs,register_catalog(), andsurface_catalogs=calls. For custom v1.0 builders, attach the owning catalog URI directly on your builder class (from a2ui.builder.v1_0 import ComponentBuilderNode;class MyWidget(ComponentBuilderNode, catalog_id=MY_CATALOG_ID):).a2ui.builder.v1_0.catalogs.basiccomponents (@catalogId) and catalog functions (catalogId) include the Basic Catalog URI when serialized. Passcatalog_id=Noneon a call to opt out.MacroExpander.transform_catalogs()raisesA2uiCatalogErrorif a client-supported (transport) v1.0 catalog sharesmacro_catalog_id.catalog_id="https://..."toMacroExpander(...)so macros live in their own sidecar catalog. (v0.9 continues augmenting the single catalog in place.)New public API
(Need compact single-catalog wire payloads? A follow-up PR adds an optional
DefaultCatalogSimplifierpipeline stage.)Diff breakdown & where to review
+190 / -686dart/a2ui_cliPython emitter (+17 / -4) and statelessMacroExpander(+173 / -682,-496net prod lines)+116 / -18python/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py+328 / -304test_macros.py, and conformance harness+178 / -97macros.yamland regenerated 33 v1.0 builder/macro golden JSONs (1 renamed)+40 / -32macros/README.md,conformance/agent/macros/README.md, andpython/a2ui_agent/CHANGELOG.md+852 / -1137-285lines); core review is 2 production files (+190 / -686)Start here
dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart): Verify component and function default stamping,@-prefixed system function exclusion, andcatalog_id=Noneopt-out without breaking v0.9 output.python/a2ui_agent/src/a2ui/transformers/macros/expander.py): Scrutinize v1.0 vs. v0.9 macro-matching rules, stripping macrocreateSurface.catalogId, and transport-catalog collision checks.conformance/agent/macros/macros.yaml): Confirm the updated v1.0 test cases accurately capture self-stamping on defaultless surfaces.Implementation details
dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart&python/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py:class <Name>(ComponentBuilderNode, catalog_id=CATALOG_ID):for v1.0 component builders (v0.9 remains unannotated).__init__on non-system v1.0 function classes that setskwargs["catalog_id"] = CATALOG_IDwhen neithercatalog_idnorcatalogIdis passed, and pops explicitcatalog_id=None/catalogId=Noneso callers can opt out without tripping strictNonevalidation duringmodel_validate.python/a2ui_agent/src/a2ui/transformers/macros/expander.py:base_catalogs,register_catalog(),_surface_catalogsLRU,_catalog_base_components,_catalog_base_functions,_auto_stamp_components,_stamp_nested_function_calls,surface_catalogs=, and_resolve_base_catalog_for_component.createSurface.catalogIdin v1.0 whenevercatalogId == self.macro_catalog_id(producing a defaultless v1.0 surface) and tracks surface defaults only within the currentmessagesbatch (batch_surfaces)._resolve_macro_invocation: in v1.0, explicit@catalogIdmatches iff it equalsself.macro_catalog_id; unannotated components expand if the in-batchcreateSurfaceusedself.macro_catalog_idor in standalone updates whenself.catalog_id is None. In v0.9, unscoped expanders expand registered macros across all turns and scoped expanders require an in-batchcreateSurfacematch.transform_catalogs()whosecatalog_id == self.macro_catalog_id.conformance/agent/macros/,python/a2ui_agent/tests/conformance/macro_suite.py):35_v1_0_auto_stamping_from_base_catalogs_on_defaultless_surface.jsonto35_v1_0_self_stamping_builders_on_defaultless_surface.jsonand regenerated all 33 v1.0 builder and macro goldens.Verification — Dart CLI, mypy (0 errors), all 56 conformance goldens, and 5,536 Python tests passed
dart format --output=none --set-exit-if-changed lib/ test/+dart analyze --fatal-infos+dart test -r compactindart/a2ui_cli: 115 passed, 0 issuesuv run pyink --check: clean across all changed Python filesuv run mypy .: 0 issues across 249 source filesuv run --project python/a2ui_agent python3 python/a2ui_agent/tests/conformance/regenerate_goldens.py --check: all 56 goldens up to date and validuv run pytest python/a2ui_core/tests/ python/a2ui_agent/tests/ python/a2ui_a2a/tests/ python/a2ui_adk/tests/ -q: 5,536 passed, 0 failed