#2933·a2ui

[BUG]: (web_core) `Catalog.catalogSchema` does not round-trip catalogs loaded from JSON

Author: ditmanCreated Oct 1, 2026Updated Oct 1, 2026
Labelsstatus: needs-triage

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 FunctionCall envelope. 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, and allowedCallers are dropped (schema_generator.ts:315-359) although FunctionApi still holds them (schema_loader.ts:807-825).
  • $ref: common_types.json#/$defs/Child comes back as $ref: #/$defs/ComponentId. ChildSchema is the same object as ComponentIdSchema (common-types.ts:296), and convertRefToZod stamps the Child name only when the property has its own description (schema_loader.ts:211-218).
  • Components gain an id property and component moves to the end (schema_generator.ts:247-253). The loader removes id/component from the Zod shape and flattens allOf (schema_loader.ts:488-490, 555-655), so the source order cannot be recovered. On the v1.0 basic catalog this moves checks to the front of the six Checkable components.
  • Also lost: catalog $id, title, description, protocolVersion; component-level description; allOf/mixin references; format; examples; deprecated; args-level anyOf (length, numeric); source $defs; the common_types.json#/$defs/... reference form (rewritten to #/$defs/..., with common types copied into $defs); the anyFunction discriminator.

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 call or returnType, and without component descriptions. The Python SDK sends the source document.
  • The Express format needs the source JSON for property order and $ref names, so the TypeScript agent SDK keeps a separate registry of source documents (a WeakMap keyed by catalog) instead of reading catalogSchema.
  • v1.0 inline catalogs in renderer capabilities (message-processor.ts:231) are sent in this non-conformant shape.
  • v0.9 inline catalogs send empty parameters for every function: generateLegacyInlineCatalog reads properties.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 $defs name in convertRefToZod, so Child survives.
  • For code-defined catalogs, emit functions in the spec's call/args shape with returnType. This one is a breaking change and needs conformance/test_data/converted_basic_catalog_v*.json and 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.