[BUG]: (web_core) `Catalog.catalogSchema` does not round-trip catalogs loaded from JSON
Summary
Catalog.catalogSchema (typescript/web_core/src/catalog/types.ts:273) rebuilds a catalog JSON Schema from the catalog's Zod schemas through generateCatalogSchema (schema_generator.ts). For a catalog built with Catalog.fromSchema / loadCatalogFromSchema, the source document goes JSON → Zod → JSON, and the result differs from the source in structure, content, and order. For v1.0 catalogs the result does not validate against specification/v1_0/json/catalog_definition.json.
Evidence
Loading conformance/test_data/catalogs/simplified_catalog_v1_0.json and reading catalogSchema:
- Functions lose the
FunctionCallenvelope. The source{type, description, returnType, requiresUserActivation, properties: {call: {const}, args: {...}}, required: [call, args]}comes back as{type, properties: <args properties>, required, description, unevaluatedProperties}.returnType,requiresUserActivation, andallowedCallersare dropped (schema_generator.ts:315-359) althoughFunctionApistill holds them (schema_loader.ts:807-825). $ref: common_types.json#/$defs/Childcomes back as$ref: #/$defs/ComponentId.ChildSchemais the same object asComponentIdSchema(common-types.ts:296), andconvertRefToZodstamps theChildname only when the property has its own description (schema_loader.ts:211-218).- Components gain an
idproperty andcomponentmoves to the end (schema_generator.ts:247-253). The loader removesid/componentfrom the Zod shape and flattensallOf(schema_loader.ts:488-490, 555-655), so the source order cannot be recovered. On the v1.0 basic catalog this moveschecksto the front of the six Checkable components. - Also lost: catalog
$id,title,description,protocolVersion; component-leveldescription;allOf/mixin references;format;examples;deprecated; args-levelanyOf(length, numeric); source$defs; thecommon_types.json#/$defs/...reference form (rewritten to#/$defs/..., with common types copied into$defs); theanyFunctiondiscriminator.
Per catalog_definition.json (FunctionCallValidationSchema, FunctionDefinition, $defs restricted to anyComponent/anyFunction) and protocol rules 2, 3, 5, and 6 in specification/v1_0/docs/a2ui_protocol.md, the generated v1.0 document is not a valid catalog. It also omits protocolVersion, so loading it again treats it as 0.9.
Impact
- The Direct JSON prompt (a2ui_agent direct_json/prompt_generator.ts:76) shows the model flattened function shapes without
callorreturnType, and without component descriptions. The Python SDK sends the source document. - The Express format needs the source JSON for property order and
$refnames, so the TypeScript agent SDK keeps a separate registry of source documents (a WeakMap keyed by catalog) instead of readingcatalogSchema. - v1.0 inline catalogs in renderer capabilities (message-processor.ts:231) are sent in this non-conformant shape.
- v0.9 inline catalogs send empty
parametersfor every function:generateLegacyInlineCatalogreadsproperties.args(message-processor.ts:281-288), which the flattened shape does not have. - The TypeScript conformance matcher (conformance_test.mjs:1219-1280) does not check function contents, so
test_v09_catalog_schema_with_defs, which expects the envelope, passes anyway.
Suggested fix
Keep the source JSON per component and per function when loading from JSON, plus the catalog-level metadata and non-union $defs, and have generateCatalogSchema emit the source when it is present, rebuilding anyComponent/anyFunction from the remaining items. The Python (catalog.py:759-860) and Dart (catalog.dart:290-337) SDKs already work this way. Pruned catalogs keep working because each item carries its own source.
Separately:
- Always stamp the source
$defsname inconvertRefToZod, soChildsurvives. - For code-defined catalogs, emit functions in the spec's call/args shape with
returnType. This one is a breaking change and needsconformance/test_data/converted_basic_catalog_v*.jsonand the Python code-defined path updated too.
Tests: byte-for-byte round trip of the simplified, v1.0 basic, and v0.9 basic catalogs; round trip after pruning; validation of v1.0 output against catalog_definition.json; a v0.9 inline catalog test asserting non-empty parameters.
Source: a2ui-project/a2ui