Skip to content

feat(bridge): A2UI v1.0 protocol strategies, multi-catalog, RPCs - #321

Merged
jgindin merged 8 commits into
mainfrom
pr3-bridge-v1-0
Nov 17, 2026
Merged

jgindin merged 8 commits into
mainfrom
pr3-bridge-v1-0

Conversation

@jgindin

@jgindin jgindin commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary

  • Add BridgeProtocolStrategy (interface, base class, and v0.9 / v1.0
    implementations) for protocol envelopes, wire types, synthetic payloads,
    and surface-reset detection; PreviewBridge delegates normalization,
    version stamping, and action envelopes to the active strategy.
  • Add DynamicValueStrategy with v0.9 ({path}, {call, args, returnType})
    and v1.0 (['@path'], ['@call', args, catalogId]) implementations,
    preserving ReDoS (isSafeRegex) and prototype-pollution guards;
    dynamic-values.ts is renamed to v0-9-dynamic-value-strategy.ts to
    keep history.
  • Add McpFunctionsCatalog (MCP_FUNCTIONS_CATALOG_ID,
    createMcpFunctionsCatalog) registering the 6 MCP and data functions with
    zod/v3 schemas, routed lazily through window.a2uiBridge.
  • Track activeProtocolVersion in PreviewBridge (default v0.9, negotiated
    to canonical 1.0 on 1.0 payloads or catalogs), assigned only after
    processor.processMessages succeeds.
  • Support multi-catalog GET_CATALOG resolution without network fetch, add
    callAgentFunction forwarding and sendOutboundMessage over
    SEND_TO_SERVER, update Angular / Lit / React sandbox adapters to accept
    multi-catalog arrays, dispose React message processors on unmount, and
    support useUniversalComponents in the Angular sandbox.

Commits

9dc38fc0 feat(bridge): add v0.9 and v1.0 protocol strategies
88d0f0e3 refactor(bridge): rename dynamic-values to v0-9-dynamic-value-strategy
d2de408a feat(bridge): add v0.9/v1.0 MCP strategies and McpFunctionsCatalog
df2f7cb4 feat(bridge): support multi-catalog GET_CATALOG and v1.0 RPCs
2bde286e fix(bridge): tolerate frozen catalogs in aliasSingleCatalogId
58ff10e9 fix(bridge): address review comments on dynamic value strategies, mcp catalog, and protocol versioning

31 files changed, 4501 insertions(+), 353 deletions(-)

Stack

Stacked PR 3/7 — base: pr2-upgrade-a2ui-deps → merge in order pr1 → pr7.

Each PR in the stack must be merged before the next one, or the next one
must be rebased onto the updated base after its predecessor merges.

Full stack (merge in this order):

Verification

Run at the tip of the stack (pr6-samples-demos-v1-0, af82fb68):

  • shell$ yarn e2e-headless → 229 passed (0 failed, 0 flaky)
  • yarn --cwd shell test:visual → 19 passed
  • yarn test, yarn lint, yarn tsc, yarn prettier:check,
    yarn generate:demos:check all exit 0

Pre-launch Checklist

@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 support for A2UI protocol version 1.0 and multi-catalog configurations across Angular, React, and Lit frameworks, refactoring dynamic value resolution into a version-specific strategy pattern and adding protection against prototype pollution and ReDoS. The review feedback suggests wrapping the catalog ID aliasing in a try-catch block to safely handle frozen catalog objects, and removing a redundant nullish coalescing check in the Angular bridge where the parameter is already strictly typed.

Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/angular/angular-bridge.ts Resolved

@wrenj wrenj 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.

LGTM — clean separation of v0.9 and v1.0 protocol and dynamic-value strategies in bridge, along with multi-catalog resolution and bidirectional RPC support. Leaving a few non-blocking nits inline.

Comment thread bridge/src/angular/angular-bridge.ts Outdated
provide: A2UI_RENDERER_CONFIG,
useFactory: () => {
const resolvedCatalogs = catalogsClasses.map(cls => inject(cls));
const resolvedCatalogs = (catalogs ?? []).map(entry =>

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.

nit (non-blocking): Now that catalogs.filter(...) above assumes catalogs is non-nullable, (catalogs ?? []) here is also redundant and can be catalogs.map(...).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 58ff10e: Simplified (catalogs ?? []).map(...) to catalogs.map(...) in bridge/src/angular/angular-bridge.ts.

return resolveDynamicTree<T>(
value,
node => {
if (isDataBinding(node)) {

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.

nit (non-blocking): V09DynamicValueStrategy.prototype.isDataBinding enforces Object.keys(value).length === 1 and V09DynamicValueStrategy.prototype.isFunctionCall validates args/returnType, whereas the standalone resolveDynamicValueDeep helper calls the looser top-level isDataBinding/isFunctionCall guards (and V09DynamicValueStrategy.prototype.resolveDynamicValueDeep delegates back to it). As a result, v09DynamicValueStrategy.resolveDynamicValueDeep({path: '/foo', extra: 1}, ctx) treats a multi-key plain object as a binding even though v09DynamicValueStrategy.isDataBinding returns false. Using v09DynamicValueStrategy.isDataBinding / isFunctionCall / normalizeFunctionCall inside resolveDynamicValueDeep keeps both entry points consistent.

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.

+1 — this is also a regression from the previous dynamic-values.ts, where the top-level isDataBinding and isFunctionCall helpers (re-exported via mcp/index.ts) enforced those strict checks too, so restoring them on the module-level guards would cover both entry points.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressing @wrenj and @mikzat: Fixed in 58ff10e: Updated module-level isDataBinding (Object.keys(value).length === 1) and isFunctionCall (args record and optional string returnType) in bridge/src/mcp/v0-9-dynamic-value-strategy.ts and delegated V09DynamicValueStrategy methods to them.

if (strategy) {
return strategy.resolveDynamicValueDeep<T>(value, context, depth);
}
return resolveDynamicValueWithContext<T>(value, context);

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.

nit (non-blocking): When strategy is omitted, resolveDynamicValueDeep(value, context, depth) does not forward depth into resolveDynamicValueWithContext (which hardcodes initial depth 0), so resolveDynamicRecord(..., depth) -> resolveDynamicValueDeep(value, context, depth + 1) resets depth back to 0. Adding an optional depth = 0 parameter to resolveDynamicValueWithContext and forwarding it here preserves the MAX_RESOLUTION_DEPTH guard across nested record calls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 58ff10e: Added optional depth = 0 to resolveDynamicValueWithContext in bridge/src/mcp/dynamic-value-strategy.ts and forwarded depth from resolveDynamicValueDeep so MAX_RESOLUTION_DEPTH is enforced across nested arrays/objects.

Comment thread bridge/src/preview-bridge.ts Outdated
*/
sendOutboundMessage(msg: unknown): void {
if (!msg || typeof msg !== 'object') return;
const strategy = resolveProtocolStrategy(this.activeProtocolVersion === '1.0' ? '1.0' : 'v1.0');

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.

nit (non-blocking): Both branches of this.activeProtocolVersion === '1.0' ? '1.0' : 'v1.0' resolve to the v1.0 strategy. Since sendOutboundMessage is specifically for v1.0 outbound listener payloads, resolveProtocolStrategy('1.0') makes that intent direct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 58ff10e: Simplified sendOutboundMessage in bridge/src/preview-bridge.ts to call resolveProtocolStrategy('1.0') directly.

@mikzat mikzat 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.

The protocol strategy split, multi-catalog handshake, and RPC wiring look solid overall. Two items look worth fixing before merge (or as an immediate fix-forward): normalizeFunctionCall in v1-0-dynamic-value-strategy.ts rewriting args to @args (which drops arguments on nested v1.0 calls), and the new isSafeRegex guard in mcp/functions/common.ts rejecting valid RE2 patterns in regexCapture/regexReplace. The MCP catalog schema required / allowedCallers questions and the remaining Optional: / Nit: notes can be handled here or in a follow-up.

Comment thread bridge/src/mcp/v1-0-mcp-catalog.ts Resolved
Comment thread bridge/src/mcp/v1-0-mcp-catalog.ts Resolved
Comment thread bridge/src/mcp/functions/common.ts Resolved
Comment thread bridge/src/react/react-bridge.ts Resolved
Comment thread bridge/src/mcp/v1-0-mcp-catalog.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/preview-bridge.ts Outdated
const jsonMeta =
typeof catObj['toJson'] === 'function'
? (catObj['toJson'] as () => Record<string, unknown> | null | undefined)()
: undefined;

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.

Nit: normalizeCatalogEntry calls catObj.toJson() unconditionally even when catObj.catalogSchema is used and title/description are already present on Catalog, which serializes and deep-clones the catalog document an extra time. Calling toJson() lazily only when catalogSchema is absent (or metadata is missing) would avoid the duplicate work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 58ff10e: Evaluated catObj.toJson() lazily in normalizeCatalogEntry only when catalogSchema and description metadata are absent.

@jgindin jgindin Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Followed up and fixed in 92efbc8c: normalizeCatalogEntry in preview-bridge.ts now guards against calling toJson() whenever catalogSchema is already present (even if title/description are unset), avoiding redundant serialization and deep-cloning.

Comment thread bridge/src/preview-bridge.ts Outdated
}
const surfaceId = createSurface.surfaceId;
if (surfaceId) {
lastSurfaceId = surfaceId;

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.

Nit: onSurfaceReady now receives lastSurfaceId (the last createSurface in a batch), whereas payload.find(...) previously reported the first one. Worth confirming that change is intentional (or keeping firstSurfaceId ??= surfaceId).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 58ff10e: Preserved firstSurfaceId ??= surfaceId across batch createSurface messages in bridge/src/preview-bridge.ts.

Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/bridge-message.ts Resolved
@jgindin
jgindin added this pull request to stack #332 November 16, 2026 13:16
jgindin added a commit that referenced this pull request Nov 16, 2026
aliasSingleCatalogId mutates a catalog object taken from the renderer
config. If a sample passes a frozen or otherwise read-only catalog, the
id assignment throws inside catalog resolution. Wrap the assignment in
a try/catch that warns instead, since aliasing is best-effort.

Also drop the redundant `catalogs ?? []` guard in provideA2uiSandbox;
the parameter is non-nullable.

Addresses review feedback on #321.
jgindin added a commit that referenced this pull request Nov 16, 2026
… catalog, and protocol versioning

Address all 18 review comments on PR #321:
- Simplify catalog mapping in Angular bridge.
- Survive minification for UniversalOnlyComponent check in Angular.
- Expose model property on Angular RendererProcessor wrapper.
- Enforce strict property checks on v0.9 dynamic value strategy.
- Forward depth in resolveDynamicValueWithContext to guard MAX_DEPTH.
- Avoid v0.9 function-call guessing on literal objects in v1.0.
- Use standard 'args' key in v1.0 function calls without '@Args'.
- Map undefined fields to null in McpFunctionsCatalog schemas.
- Restrict pure data functions to rendererOrAgent, others rendererOnly.
- Remove redundant isSafeRegex guard before RE2JS compilation.
- Ensure dispose cleanup is called on unmount in React bridge.
- Direct protocol resolution in sendOutboundMessage to v1.0 strategy.
- Normalize protocol versions consistently across catalog inference.
- Gate multi-catalog schema responses strictly on isMultiCatalog.
- Tag and isolate catalog in-memory normalization errors in logging.
- Lazily evaluate catalogSchema toJson only when schema is absent.
- Preserve first created surfaceId in multi-surface batch ready event.
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard normalizeCatalogEntry against calling toJson() when catalogSchema exists

- Defer catalog extractability checks until network fallback with console.warn

- Share isV1ProtocolVersion helper across bridge and protocol strategies

- Check UniversalOnlyComponent by identity without fragile name fallback

- Throw A2uiExpressionError on prototype-pollution paths in updateDataModel

- Remove manualProcessor / setActiveProcessor and simplify getActiveProcessor

- Stop resolveDynamicTree when normalized function calls pass through unchanged

- Remove redundant aliasing and lastResolvedCatalogId in notifyCatalogResolved

- Restore @deprecated CatalogDetails export for compatibility
jgindin added a commit that referenced this pull request Nov 16, 2026
aliasSingleCatalogId mutates a catalog object taken from the renderer
config. If a sample passes a frozen or otherwise read-only catalog, the
id assignment throws inside catalog resolution. Wrap the assignment in
a try/catch that warns instead, since aliasing is best-effort.

Also drop the redundant `catalogs ?? []` guard in provideA2uiSandbox;
the parameter is non-nullable.

Addresses review feedback on #321.
jgindin added a commit that referenced this pull request Nov 16, 2026
… catalog, and protocol versioning

Address all 18 review comments on PR #321:
- Simplify catalog mapping in Angular bridge.
- Survive minification for UniversalOnlyComponent check in Angular.
- Expose model property on Angular RendererProcessor wrapper.
- Enforce strict property checks on v0.9 dynamic value strategy.
- Forward depth in resolveDynamicValueWithContext to guard MAX_DEPTH.
- Avoid v0.9 function-call guessing on literal objects in v1.0.
- Use standard 'args' key in v1.0 function calls without '@Args'.
- Map undefined fields to null in McpFunctionsCatalog schemas.
- Restrict pure data functions to rendererOrAgent, others rendererOnly.
- Remove redundant isSafeRegex guard before RE2JS compilation.
- Ensure dispose cleanup is called on unmount in React bridge.
- Direct protocol resolution in sendOutboundMessage to v1.0 strategy.
- Normalize protocol versions consistently across catalog inference.
- Gate multi-catalog schema responses strictly on isMultiCatalog.
- Tag and isolate catalog in-memory normalization errors in logging.
- Lazily evaluate catalogSchema toJson only when schema is absent.
- Preserve first created surfaceId in multi-surface batch ready event.
jgindin added a commit that referenced this pull request Nov 16, 2026
- Guard normalizeCatalogEntry against calling toJson() when catalogSchema exists

- Defer catalog extractability checks until network fallback with console.warn

- Share isV1ProtocolVersion helper across bridge and protocol strategies

- Check UniversalOnlyComponent by identity without fragile name fallback

- Throw A2uiExpressionError on prototype-pollution paths in updateDataModel

- Remove manualProcessor / setActiveProcessor and simplify getActiveProcessor

- Stop resolveDynamicTree when normalized function calls pass through unchanged

- Remove redundant aliasing and lastResolvedCatalogId in notifyCatalogResolved

- Restore @deprecated CatalogDetails export for compatibility
jgindin added a commit that referenced this pull request Nov 16, 2026
Export isV1ProtocolVersion from the mocked a2ui-bridge module in
ng-basic-catalog tests so PreviewBridge tests pass on PRs #321-#323.
Base automatically changed from pr2-upgrade-a2ui-deps to main November 16, 2026 23:50
Add BridgeProtocolStrategy interface, BaseBridgeProtocolStrategy base
class, and concrete implementations for v0.9 and v1.0 protocol
envelopes, wire types, and synthetic payloads. Update PreviewBridge to
delegate surface reset detection through protocol strategies.

Implement multi-catalog schema normalization and GET_CATALOG handshake
resolution returning both primary schema and all schemas for backwards
and forwards compatibility. Add sendOutboundMessage to forward outbound
RPC messages to window.parent over SEND_TO_SERVER.

Update Angular, Lit, and React sandbox adapters to accept two-argument
signatures supporting multi-catalog arrays, class providers, and direct
instances, guard single-catalog ID aliasing on catalog resolution, and
wire processorOptions.outboundListener to forward remote calls.
Rename dynamic-values.ts to v0-9-dynamic-value-strategy.ts to prepare
for A2UI v1.0 dynamic value evaluation strategy without breaking file
history. Update internal callers to point to the renamed module.
Introduce DynamicValueStrategy interface with version-specific
strategies for A2UI v0.9 and v1.0 dynamic values:
- v0.9 strategy handles {path} bindings and {call, args, returnType}.
- v1.0 strategy resolves bracket-notated ['@path'] bindings and
  ['@call', args, catalogId] calls, strictly omitting returnType.
- Author McpFunctionsCatalog with MCP_FUNCTIONS_CATALOG_ID and
  createMcpFunctionsCatalog registering all 6 MCP and data functions
  using zod/v3 schemas and lazy singleton routing via window.a2uiBridge.
- Preserve ReDoS validation via isSafeRegex and sanitize object
  prototypes against pollution during dynamic value resolution.
- Provide deduplicated resolveDynamicTree helper in strategy module.
Extend PreviewBridge and framework bridges (Angular, Lit, React) to
negotiate canonical A2UI v1.0 wire protocol messages alongside v0.9.

Key changes:
- Track activeProtocolVersion in PreviewBridge, defaulting to v0.9 and
  negotiating canonical 1.0 upon receiving 1.0 payloads or catalogs.
- Safe activeProtocolVersion assignment in handleRenderA2ui only after
  processor.processMessages succeeds to avoid corrupting state.
- Delegate normalization, version stamping, and action envelopes to
  BridgeProtocolStrategy.
- Support multi-catalog GET_CATALOG resolution without network fetch.
- Add callAgentFunction forwarding on PreviewBridge and framework
  adapters.
- Dispose message processors cleanly on React component unmount.
- Support useUniversalComponents in Angular sandbox bootstrapping.
aliasSingleCatalogId mutates a catalog object taken from the renderer
config. If a sample passes a frozen or otherwise read-only catalog, the
id assignment throws inside catalog resolution. Wrap the assignment in
a try/catch that warns instead, since aliasing is best-effort.

Also drop the redundant `catalogs ?? []` guard in provideA2uiSandbox;
the parameter is non-nullable.

Addresses review feedback on #321.
… catalog, and protocol versioning

Address all 18 review comments on PR #321:
- Simplify catalog mapping in Angular bridge.
- Survive minification for UniversalOnlyComponent check in Angular.
- Expose model property on Angular RendererProcessor wrapper.
- Enforce strict property checks on v0.9 dynamic value strategy.
- Forward depth in resolveDynamicValueWithContext to guard MAX_DEPTH.
- Avoid v0.9 function-call guessing on literal objects in v1.0.
- Use standard 'args' key in v1.0 function calls without '@Args'.
- Map undefined fields to null in McpFunctionsCatalog schemas.
- Restrict pure data functions to rendererOrAgent, others rendererOnly.
- Remove redundant isSafeRegex guard before RE2JS compilation.
- Ensure dispose cleanup is called on unmount in React bridge.
- Direct protocol resolution in sendOutboundMessage to v1.0 strategy.
- Normalize protocol versions consistently across catalog inference.
- Gate multi-catalog schema responses strictly on isMultiCatalog.
- Tag and isolate catalog in-memory normalization errors in logging.
- Lazily evaluate catalogSchema toJson only when schema is absent.
- Preserve first created surfaceId in multi-surface batch ready event.
- Guard normalizeCatalogEntry against calling toJson() when catalogSchema exists

- Defer catalog extractability checks until network fallback with console.warn

- Share isV1ProtocolVersion helper across bridge and protocol strategies

- Check UniversalOnlyComponent by identity without fragile name fallback

- Throw A2uiExpressionError on prototype-pollution paths in updateDataModel

- Remove manualProcessor / setActiveProcessor and simplify getActiveProcessor

- Stop resolveDynamicTree when normalized function calls pass through unchanged

- Remove redundant aliasing and lastResolvedCatalogId in notifyCatalogResolved

- Restore @deprecated CatalogDetails export for compatibility
Export isV1ProtocolVersion from the mocked a2ui-bridge module in
ng-basic-catalog tests so PreviewBridge tests pass on PRs #321-#323.
@jgindin
jgindin merged commit be5e24d into main Nov 17, 2026
15 checks passed
@jgindin
jgindin deleted the pr3-bridge-v1-0 branch November 17, 2026 00:39
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