Repository navigation
feat(bridge): A2UI v1.0 protocol strategies, multi-catalog, RPCs - #321
Conversation
There was a problem hiding this comment.
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.
6881103 to
d11454a
Compare
wrenj
left a comment
There was a problem hiding this comment.
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.
| provide: A2UI_RENDERER_CONFIG, | ||
| useFactory: () => { | ||
| const resolvedCatalogs = catalogsClasses.map(cls => inject(cls)); | ||
| const resolvedCatalogs = (catalogs ?? []).map(entry => |
There was a problem hiding this comment.
nit (non-blocking): Now that catalogs.filter(...) above assumes catalogs is non-nullable, (catalogs ?? []) here is also redundant and can be catalogs.map(...).
There was a problem hiding this comment.
Fixed in 58ff10e: Simplified (catalogs ?? []).map(...) to catalogs.map(...) in bridge/src/angular/angular-bridge.ts.
| return resolveDynamicTree<T>( | ||
| value, | ||
| node => { | ||
| if (isDataBinding(node)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+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.
There was a problem hiding this comment.
| if (strategy) { | ||
| return strategy.resolveDynamicValueDeep<T>(value, context, depth); | ||
| } | ||
| return resolveDynamicValueWithContext<T>(value, context); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| */ | ||
| sendOutboundMessage(msg: unknown): void { | ||
| if (!msg || typeof msg !== 'object') return; | ||
| const strategy = resolveProtocolStrategy(this.activeProtocolVersion === '1.0' ? '1.0' : 'v1.0'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fixed in 58ff10e: Simplified sendOutboundMessage in bridge/src/preview-bridge.ts to call resolveProtocolStrategy('1.0') directly.
mikzat
left a comment
There was a problem hiding this comment.
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.
| const jsonMeta = | ||
| typeof catObj['toJson'] === 'function' | ||
| ? (catObj['toJson'] as () => Record<string, unknown> | null | undefined)() | ||
| : undefined; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fixed in 58ff10e: Evaluated catObj.toJson() lazily in normalizeCatalogEntry only when catalogSchema and description metadata are absent.
There was a problem hiding this comment.
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.
| } | ||
| const surfaceId = createSurface.surfaceId; | ||
| if (surfaceId) { | ||
| lastSurfaceId = surfaceId; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Fixed in 58ff10e: Preserved firstSurfaceId ??= surfaceId across batch createSurface messages in bridge/src/preview-bridge.ts.
d11454a to
58ff10e
Compare
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
58ff10e to
4f29ad7
Compare
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
4f29ad7 to
f9bf19a
Compare
f9bf19a to
1f0b64e
Compare
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
1f0b64e to
140dbfb
Compare
Description
Summary
BridgeProtocolStrategy(interface, base class, and v0.9 / v1.0implementations) for protocol envelopes, wire types, synthetic payloads,
and surface-reset detection;
PreviewBridgedelegates normalization,version stamping, and action envelopes to the active strategy.
DynamicValueStrategywith v0.9 ({path},{call, args, returnType})and v1.0 (
['@path'],['@call', args, catalogId]) implementations,preserving ReDoS (
isSafeRegex) and prototype-pollution guards;dynamic-values.tsis renamed tov0-9-dynamic-value-strategy.tstokeep history.
McpFunctionsCatalog(MCP_FUNCTIONS_CATALOG_ID,createMcpFunctionsCatalog) registering the 6 MCP and data functions withzod/v3 schemas, routed lazily through
window.a2uiBridge.activeProtocolVersioninPreviewBridge(default v0.9, negotiatedto canonical 1.0 on 1.0 payloads or catalogs), assigned only after
processor.processMessagessucceeds.GET_CATALOGresolution without network fetch, addcallAgentFunctionforwarding andsendOutboundMessageoverSEND_TO_SERVER, update Angular / Lit / React sandbox adapters to acceptmulti-catalog arrays, dispose React message processors on unmount, and
support
useUniversalComponentsin the Angular sandbox.Commits
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):
pr1-e2e-stabilizationpr2-upgrade-a2ui-depspr3-bridge-v1-0pr4-shell-v1-0-corepr5-shell-v1-0-copilot-rpc-a2apr6-samples-demos-v1-0pr7-qa-cleanupVerification
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 passedyarn test,yarn lint,yarn tsc,yarn prettier:check,yarn generate:demos:checkall exit 0Pre-launch Checklist