Skip to content

test(ts_agent): run the macros conformance suite and document macros - #4542

Open
manfredsteyer wants to merge 4 commits into
a2ui-project:mainfrom
manfredsteyer:feat/ts-agent-macros-conformance
Open

manfredsteyer wants to merge 4 commits into
a2ui-project:mainfrom
manfredsteyer:feat/ts-agent-macros-conformance

Conversation

@manfredsteyer

Copy link
Copy Markdown

Problem

conformance/agent/macros/macros.yaml doesn't run against @a2ui/agent, and its macros and component tree aren't documented.

Changes

  1. Run macros.yaml with reference macros that mirror Python's macro_suite.py. 48 of its 70 cases pass, including 16_reverse_passthrough for transformToInference. The 22 cases that need v0.9 macros are skipped.
  2. Keep agent/builder/builder.yaml in UNSUPPORTED_SUITES until TypeScript has a typed builder.
  3. Add a macros section to the README and a CHANGELOG entry. KNOWN_GAPS.md gets entries for v1.0-only macros, the missing typed builder and the checks that are stricter than Python's, and the codebase blueprint describes the component tree and the macros.

Verification

yarn workspace @a2ui/agent test, lint and format:check pass. typecheck reports the same 20 errors as main, all in test files this PR doesn't touch. The README examples compile against the package.

@manfredsteyer
manfredsteyer force-pushed the feat/ts-agent-macros-conformance branch from 0d48504 to f6871b8 Compare December 2, 2026 17:21
@manfredsteyer

manfredsteyer commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

This PR builds on #4541, and since both come from a fork, the diff includes its commits until it merges. The commit to review here is bda5838.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces macro support (v1.0 only) to the TypeScript A2UI Agent SDK, enabling the definition and expansion of high-level components into base catalog components. It adds a component tree builder and flattener, a MacroExpander for lowering macro invocations, and relocates CatalogSchemaHelper to utility schemas. Additionally, comprehensive unit and conformance tests are added, and documentation is updated. Feedback on the changes suggests using optional chaining and nullish coalescing when querying schemaHelpers to prevent potential TypeErrors, and replacing ES2022/ES2023 array methods (findLast and at) with ES6-compatible alternatives to ensure broader environment compatibility.

Comment on lines +684 to +686
owners.length > 0 &&
owners.every(id =>
this.schemaHelpers.get(id)?.getCustomEnvelopeProperties(name).has('catalogId'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime errors, use optional chaining and a nullish coalescing fallback when accessing has on the result of getCustomEnvelopeProperties. If schemaHelpers.get(id) is undefined or if getCustomEnvelopeProperties returns undefined, calling .has directly will throw a TypeError. This aligns with defensive programming best practices.

      owners.every(id =>
        this.schemaHelpers.get(id)?.getCustomEnvelopeProperties(name)?.has('catalogId') ?? false,
      );
References
  1. Avoid using the non-null assertion operator on lookup results that may fail. Instead, allow the variable to be nullable and handle the undefined case downstream using optional chaining or nullish coalescing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as on #4541: getCustomEnvelopeProperties always returns a set, and ?. already covers a missing helper. Leaving it as is.

Comment on lines +80 to +83
const root =
(instanceId !== undefined
? lowered.findLast(component => component['id'] === instanceId)
: undefined) ?? lowered.at(-1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2022/ES2023 features like Array.prototype.findLast and Array.prototype.at can cause runtime crashes in environments that do not support or polyfill these newer methods. Using standard ES6 methods like reverse().find() and direct index access [length - 1] is safer and more compatible.

Suggested change
const root =
(instanceId !== undefined
? lowered.findLast(component => component['id'] === instanceId)
: undefined) ?? lowered.at(-1);
const root =
(instanceId !== undefined
? [...lowered].reverse().find(component => component['id'] === instanceId)
: undefined) ?? lowered[lowered.length - 1];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package compiles against lib: ["es2023"] (tsconfig.json), so findLast and at are part of the runtime it targets. Node has both since version 18, CI runs Node 22, and @a2ui/catalog-mcp already uses at(-1). Copying and reversing the array would only make this harder to read, so I'm keeping it.

@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Dec 2, 2026
@polina-c

polina-c commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

From triage bot, analysis:

For humans

TL;DR
Case: ditman already started reviewing this change in #4413 and asked for this split. This PR is its third part, on top of #4541.
Suggestion: assign polina-c, who owns the review.

Summary:
Third of the three PRs that split #4413. It runs the macros.yaml conformance suite against @a2ui/agent, where 48 of 70 cases pass and the 22 v0.9 cases are skipped, and documents macros in the README, the CHANGELOG, KNOWN_GAPS.md and the codebase blueprint.

Why flagged for triage:
This PR has no assignee.

Suggestion:

  • ditman reviewed #4413 and asked to split it into three PRs, which #4540, #4541 and #4542 follow. ditman said that polina-c owns the review after that first round, so assign polina-c to all three.
  • The diff includes the commits of #4540 and #4541 until they merge. The author says to review f6871b847. No merge conflicts.
  1. Add labels: component: agent sdk, lang: typescript
  2. Assign: polina-c
  3. Related items: feat(ts_agent): add ComponentBuilderNode and flattenComponentTree #4540, feat(ts_agent): add macros #4541, feat(ts_agent): port macros (MacroExpander) to @a2ui/agent #4413

Reply:

From triage:

Assigning this PR to polina-c, who owns the review that ditman started on #4413.

To adjust the analysis and apply its suggestion, open it in the hosted triage UI, or run in your a2ui checkout:

tools/internal/triage/triage_ui.sh https://github.com/a2ui-project/a2ui/pull/4542
For software
<a2ui>
root = TriageAnalysis(
  tldr="""Case: `ditman` already started reviewing this change in [#4413](https://github.com/a2ui-project/a2ui/pull/4413) and asked for this split. This PR is its third part, on top of [#4541](https://github.com/a2ui-project/a2ui/pull/4541).
Suggestion: assign `polina-c`, who owns the review.""",
  summary="""Third of the three PRs that split [#4413](https://github.com/a2ui-project/a2ui/pull/4413). It runs the `macros.yaml` conformance suite against `@a2ui/agent`, where 48 of 70 cases pass and the 22 v0.9 cases are skipped, and documents macros in the README, the CHANGELOG, `KNOWN_GAPS.md` and the codebase blueprint.""",
  reason="This PR has no assignee.",
  suggestion="""- `ditman` [reviewed](https://github.com/a2ui-project/a2ui/pull/4413#pullrequestreview-6141583583) [#4413](https://github.com/a2ui-project/a2ui/pull/4413) and [asked](https://github.com/a2ui-project/a2ui/pull/4413#pullrequestreview-6141583583) to split it into three PRs, which [#4540](https://github.com/a2ui-project/a2ui/pull/4540), [#4541](https://github.com/a2ui-project/a2ui/pull/4541) and [#4542](https://github.com/a2ui-project/a2ui/pull/4542) follow. `ditman` [said](https://github.com/a2ui-project/a2ui/pull/4413#issuecomment-7320083978) that `polina-c` owns the review after that first round, so assign `polina-c` to all three.
- The diff includes the commits of [#4540](https://github.com/a2ui-project/a2ui/pull/4540) and [#4541](https://github.com/a2ui-project/a2ui/pull/4541) until they merge. The author [says](https://github.com/a2ui-project/a2ui/pull/4542#issuecomment-7353215830) to review [f6871b847](https://github.com/a2ui-project/a2ui/pull/4542/commits/f6871b84741d29a29c32aba662434188d47e94f8). No merge conflicts.""",
  reply="""Assigning this PR to `polina-c`, who owns the review that `ditman` started on [#4413](https://github.com/a2ui-project/a2ui/pull/4413).""",
  added_labels=["component: agent sdk", "lang: typescript"],
  new_assignees=["polina-c"],
  related_items=[4540, 4541, 4413]
)
</a2ui>

This analysis does not change after taking the later submitted comments into account: review from manfredsteyer, review from manfredsteyer, and the force-push of the PR branch, after which the author's comment names a00817903 as the commit to review.

This analysis is auto-created to help humans to triage this item. Please, do not treat it as a team decision.

@manfredsteyer
manfredsteyer force-pushed the feat/ts-agent-macros-conformance branch from f6871b8 to a008179 Compare December 2, 2026 19:18
CatalogSchemaHelper and the component envelope helpers are not specific
to Express: macros need them too. Move schema-helper.ts and its test from
inference-formats/express/ to utils/ without changing them.
Port the component tree of the Python builder: ComponentBuilderNode and
ComponentRef, and flattenComponentTree, which turns a tree of nodes into
the flat component list of updateComponents with deterministic IDs
namespaced under the root.

Nodes are recognized by class, so a plain data object with a component
property stays a value. Two components with the same explicit ID throw
A2uiValidationError instead of producing duplicate IDs.

An array of roots flattened without a rootId keeps each root's own ID
and gives a root without one the ID root_<index>. Python flattens all of
those roots under the prefix root, so their IDs collide.
Port the macros of the Python SDK to @a2ui/agent for v1.0, exported as
the Macros namespace so that their value types, such as Action, don't
clash with @a2ui/web_core.

- defineMacro and the param vocabulary define a macro; the arguments of
  render are typed from its parameters, and component IDs arrive as
  ComponentRefs.
- MacroExpander adds the macros to the inference catalogs and lowers the
  model's messages to the transport catalogs: it checks and coerces the
  arguments, merges the invocation's envelope fields onto the root,
  resolves macros on surfaces that mix catalogs, tracks surfaces and
  applies an onError policy. transformToInference passes messages
  through, as in Python.
Run conformance/agent/macros/macros.yaml with reference macros that
mirror Python's macro_suite.py: 48 of its 70 cases pass, and the 22 that
need v0.9 macros are skipped. agent/builder/builder.yaml stays
unsupported until TypeScript has a typed builder.

Document macros and the component tree in the README, CHANGELOG,
KNOWN_GAPS.md and the codebase blueprint.
@Varun-S10 Varun-S10 self-assigned this Dec 3, 2026
@github-actions github-actions Bot removed the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Dec 3, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @manfredsteyer, thank you for raising this PR. We verified the macros conformance suite (48 of 70 cases pass and 22 v0.9 cases skip as expected) and docs, and they look great, but the branch is behind main with the merge conflict in schema-helper.ts and three @returns JSDoc tags carried from #4540 and #4541. Could you please rebase on latest main so we can review it again?

@manfredsteyer

Copy link
Copy Markdown
Author

Thanks, @Varun-S10. This PR is rebased onto main together with #4540 and #4541, and the macros suite still passes 48 cases and skips 22. The commit to review is now bda5838.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants