Repository navigation
feat(shell): A2UI v1.0 core — wire validators, catalogs, Monaco schemas - #322
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive support for the A2UI v1.0 protocol alongside v0.9, implementing version-specific strategies for draft management, Monaco schema validation, and cross-frame communication. Key changes include multi-catalog merging, protocol mismatch validation, and automatic rejection of agent function calls when no agent is connected. Feedback on the changes highlights a critical security issue where validation of incoming A2UI_CATALOG messages is ignored, a missing import of linkedSignal in catalog-management.ts, and an incorrect validation rule in v1-0-wire-validator.ts that erroneously requires the optional path property in updateDataModel messages.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
9168dff to
af58b22
Compare
wrenj
left a comment
There was a problem hiding this comment.
LGTM — core v1.0 shell support (wire validators, version mismatch guard, multi-catalog state, gallery strategies, and Monaco schema generation) is well structured and covered by specs. A few non-blocking observations inline.
| if ( | ||
| catalogId === BASIC_CATALOG_ID_V0_9 || | ||
| catalogId === BASIC_CATALOG_ID_V1_0 || | ||
| catalogId === 'https://a2ui.org/specification/v0_9/basic_catalog.json' |
There was a problem hiding this comment.
nit (non-blocking): BASIC_CATALOG_ID_V0_9 is already 'https://a2ui.org/specification/v0_9/basic_catalog.json' (in initial-draft.ts), so this third comparison is a duplicate. If this was meant to cover the alternate v0.9 basic catalog URI seen in older samples, that URI is 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json'.
There was a problem hiding this comment.
Fixed in f673485: Replaced the duplicate BASIC_CATALOG_ID_V0_9 check in shell/src/app/chat/state-sync/state-sync.ts with 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json'.
| } | ||
| return component; | ||
| }); | ||
| if (trimmed.includes('"v1.0"') || trimmed.includes('"1.0"')) { |
There was a problem hiding this comment.
nit (non-blocking): Raw substring matching on '"1.0"' can false-positive if a v0.9 layout contains "1.0" inside a text property or data model value. Detecting the version via detectPayloadVersion after parsing (or checking a "version" key pattern) would avoid misrouting v0.9 drafts through v10Strategy.sanitizeLayout.
There was a problem hiding this comment.
Fixed in f673485: Replaced raw trimmed.includes('"1.0"') substring matching in shell/src/app/chat/state-sync/state-sync.ts with parsed protocol version detection (tryParseJsonArray + detectProtocolVersion).
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| required: ['surfaceId'], |
There was a problem hiding this comment.
nit (non-blocking): V10WireValidator.validateRenderItem requires both surfaceId and a non-empty catalogId on createSurface, whereas createSurfaceEnvelope here only lists required: ['surfaceId']. Including 'catalogId' in required lets Monaco flag missing catalogId directly in the editor before send-time validation rejects it.
There was a problem hiding this comment.
Suggest going the other way: catalogId is optional on createSurface in v1.0 (agent_to_renderer.json requires only surfaceId, and @a2ui/web_core's processCreateSurfaceOp creates a surface with no default catalog when catalogId is omitted). Rather than tightening Monaco, let's relax V10WireValidator.validateRenderItem (v1-0-wire-validator.ts L524, and callRendererFunction.surfaceId at L544, which is also optional in agent_to_renderer.json and runs in a fallback root context in web_core) to validate them only when !== undefined.
Optional in the same function: tightening hasCall (L560, which currently accepts callFunction: [] or {} without @call) and updateComponents (L665, which accepts components: [] vs minItems: 1 in the schema) would match agent_to_renderer.json.
There was a problem hiding this comment.
Addressing @wrenj and @mikzat: Fixed in f673485: Kept createSurface.catalogId optional in Monaco, relaxed V10WireValidator to validate createSurface.catalogId and callRendererFunction.surfaceId only when !== undefined, tightened hasCall (callFunction must be a record with non-empty @call/call), and tightened updateComponents (components.length >= 1).
|
|
||
| protected readonly galleryStrategy = computed<GalleryProtocolStrategy>(() => { | ||
| const version = this.catalogManagement.activeProtocolVersion(); | ||
| return version === 'v1.0' ? new V10GalleryStrategy() : new V09GalleryStrategy(); |
There was a problem hiding this comment.
nit (non-blocking): GalleryCatalog (shell/src/app/gallery/services/gallery-catalog.ts) already exposes an identical public readonly galleryStrategy computed signal (and V09GalleryStrategy / V10GalleryStrategy are stateless). Reusing this.catalogService.galleryStrategy (or shared strategy instances) avoids duplicating the signal and re-instantiating stateless strategies on version toggles.
There was a problem hiding this comment.
Fixed in f673485: Reused this.catalogService.galleryStrategy in Gallery and shared stateless strategy singletons in GalleryCatalog.
mikzat
left a comment
There was a problem hiding this comment.
Clean separation of the v1.0 wire validator, multi-catalog handshake, and Monaco schema strategies. Left a reply on the createSurface.catalogId thread so Monaco stays optional per the v1.0 schema and V10WireValidator is relaxed instead (along with callRendererFunction.surfaceId), and noted a catalog.json alias merge issue in V10MonacoSchemaStrategy that overwrites secondary catalog functions. The agentFunctionResponse and SEND_TO_SERVER items are already addressed further up the stack (#323 and #325) unless this PR lands standalone, and the remaining comments are optional follow-ups.
| 'updateDataModel', | ||
| 'deleteSurface', | ||
| 'callRendererFunction', | ||
| 'callAgentFunctionResponse', |
There was a problem hiding this comment.
Optional: the v1.0 operation key is agentFunctionResponse (AgentFunctionResponseMessage in agent_to_renderer.json), whereas validKeys here (and L574) only accepts callAgentFunctionResponse. Every outgoing agentFunctionResponse fails validateOutgoingMessage and is dropped by HostCommunication.sendMessage, including GuestFrame's NO_AGENT_CONNECTED auto-reject (guest-frame.ts L257). (guest-frame.spec.ts mocks sendRenderA2UI and v1-0-wire-validator.spec.ts L500 tests callAgentFunctionResponse, so unit tests miss it.)
#323 (2f1ea6ee) already adds agentFunctionResponse upstack; if #322 could land on its own, consider moving that fix here and adding a test that runs GuestFrame's rejection payload through CrossFrameValidator.validateOutgoingMessage.
There was a problem hiding this comment.
Fixed in f673485: Added 'agentFunctionResponse' to validKeys in shell/src/app/shell/cross-frame-validator/v1-0-wire-validator.ts and added a test validating GuestFrame's NO_AGENT_CONNECTED rejection payload through CrossFrameValidator.validateOutgoingMessage.
| origin: event.origin, | ||
| timestamp: Date.now(), | ||
| }); | ||
| } |
There was a problem hiding this comment.
Optional: when a SEND_TO_SERVER fails validation, only the sendToServer$ emit is skipped; L507 still runs recordEnvelope(envelope), so the rejected payload lands in the history buffer and on messageStream$. A2aChatView (shell/src/app/agent-chat/a2a-chat-view.ts L222) subscribes to messageStream$ and calls handleSendToServerAction(envelope.payload), so payloads rejected for wrong version, malformed shape, or prototype pollution still reach the chat handler (origin and source checks still apply).
Having A2aChatView subscribe to sendToServer$ keeps debug panels seeing raw traffic while honoring validation. #325 (850ab1b9) already makes this switch further up the stack, so this only matters if #322 lands standalone.
There was a problem hiding this comment.
Fixed in f673485: Subscribed A2aChatView to this.hostCommunication.sendToServer$ in shell/src/app/agent-chat/a2a-chat-view.ts so CrossFrameValidator gates incoming messages on pr4 as well.
| }, | ||
| } | ||
| : {}), | ||
| } |
There was a problem hiding this comment.
For the catalog.json alias schemas, primaryCatalog spreads basePrimaryCatalog's raw $defs, components, and functions on top of the merged maps. The v1.0 basic catalog defines $defs.anyFunction and $defs.anyComponent, which overwrite the merged definitions built at L143–155. Since common_types.json#/$defs/FunctionCall resolves through catalog.json#/$defs/anyFunction, calls to secondary-catalog functions (such as MCP functions) get flagged as invalid in the editor, and spreading an array-form functions also adds "0", "1", … keys (v1-0-monaco-schema-strategy.spec.ts L186 misses this because its fixture omits $defs.anyFunction).
Suggested fix: assign mergedDefs, mergedComponentMap, and mergedFunctions directly on primaryCatalog (matching layoutSchema at L320–322), and add a test fixture whose primary catalog defines $defs.anyFunction.
There was a problem hiding this comment.
Fixed in f673485: Assigned mergedDefs, mergedComponentMap, and mergedFunctions onto primaryCatalog after spreading ...basePrimaryCatalog in shell/src/app/shared/monaco-editor/schemas/v1-0-monaco-schema-strategy.ts and added a test fixture where the primary catalog defines $defs.anyFunction.
| try { | ||
| const payload = this.parseLayoutString(currentLayout); | ||
| if (payload !== null) { | ||
| this.sendValidatedRenderA2UI(payload); |
There was a problem hiding this comment.
Optional: on a v0.9↔v1.0 switch with an untouched draft, StateSync's toObservable updates activeDraft before this effect runs, while the sync effect below (L216) defers layoutJson.set(activeDraftVal) to a microtask. As a result, this effect validates the stale layoutJson() against the new activeProtocolVersion() and logs a spurious PROTOCOL_VERSION_MISMATCH right before the microtask renders the updated draft. Skipping dispatch here when this.layoutJson() !== this.stateSync.activeDraft() avoids the false error since the sync effect will send the updated payload.
There was a problem hiding this comment.
Fixed in f673485: Skipped sendValidatedRenderA2UI in the catalog/version effect of shell/src/app/preview/raw/raw-frame.ts when this.layoutJson() !== this.stateSync.activeDraft().
| * @returns `true` if prototype pollution is detected, `false` otherwise. | ||
| */ | ||
| export function hasPrototypePollution(val: unknown, maxDepth = 10): boolean { | ||
| if (!val || typeof val !== 'object' || maxDepth <= 0) { |
There was a problem hiding this comment.
Optional: hasPrototypePollution returns false once maxDepth (10) reaches 0. The standard v1.0 basic catalog JSON schema already nests 12 levels deep (14 inside an A2UI_CATALOG {catalog, catalogs} handshake), so keys deeper than 10 levels pass unchecked. Consider raising the default limit (e.g. 64) or failing closed when maxDepth is exceeded.
There was a problem hiding this comment.
Fixed in f673485: Raised hasPrototypePollution default maxDepth from 10 to 64 and failed closed (return true) when maxDepth <= 0 in shell/src/app/shell/cross-frame-validator/wire-version-validator.ts.
af58b22 to
f673485
Compare
| ); | ||
|
|
||
| /** Stream of incoming user action events */ | ||
| readonly action$ = this.sendToServer$.pipe( |
There was a problem hiding this comment.
Optional: nothing in the stack (through #325) uses action$, sendToServerError$, GuestFrame.iframeElement, or ComposerErrorTelemetryParams.protocolVersion (which also duplicates the protocol_version that getBaselineDimensions() sends with every event). Can we drop them until something needs them?
There was a problem hiding this comment.
Fixed in b50a95be: removed unused action$, sendToServerError$, GuestFrame.iframeElement, and ComposerErrorTelemetryParams.protocolVersion (along with their unused tests).
| }; | ||
| } | ||
|
|
||
| const componentUnion = |
There was a problem hiding this comment.
Optional: componentUnion builds anyOf from mergedComponents, which includes duplicate schemas from secondary catalogs, so the editor accepts props that only match the secondary Button even though primary wins elsewhere. Using Object.values(mergedComponentMap) makes it match anyComponent and the collision warning.
There was a problem hiding this comment.
Fixed in b50a95be: V10MonacoSchemaStrategy now builds componentUnion from Object.values(mergedComponentMap) so primary catalog schemas win cleanly without accepting duplicate secondary component schemas.
| /** | ||
| * This is a copy synchronized from https://github.com/a2ui-project/a2ui/blob/main/specification/v1_0/json/common_types.json | ||
| */ |
There was a problem hiding this comment.
Nit: this matches what @a2ui/web_core 0.15.0 expects, but spec main has since moved on (@catalogId/@accessibility/@checks). Could the header point at the spec commit or tag it was copied from instead of main, so a re-sync doesn't get ahead of the pinned runtime?
There was a problem hiding this comment.
Fixed in b50a95be: updated the header comment in common-types-schema.ts to pin the exact @a2ui/[email protected] release commit rather than main.
HostCommunication ran CrossFrameValidator on A2UI_CATALOG envelopes but ignored the result, so a prototype-polluted or non-object payload was still forwarded to CatalogManagement. Replace the payload of a failed envelope with a typed CatalogHandshakeErrorPayload carrying the validator's first error, so the handshake fails immediately with the real reason and the malformed object never reaches downstream consumers. V10WireValidator.validateSendToServer required updateDataModel.path to be a non-empty string, while validateRenderItem, the bridge's UpdateDataModelDetails type, and the v0.9 validator all treat it as optional. Accept an absent path and keep rejecting an empty or non-string one. In addition, enforce non-empty string surfaceId. Addresses review feedback on #322.
- Settle handshake with error on watchdog/bridge failures, keeping v0.9 fallback - Add debug-only deferral log in RawFrame without polluting Errors badge - Share isV1ProtocolVersion across CatalogManagement multi-catalog resolution - Import pipeable RxJS operators from rxjs/operators - Remove unused action$, sendToServerError$, iframeElement, and protocolVersion - Build V10MonacoSchemaStrategy componentUnion from mergedComponentMap - Pin common-types-schema.ts to @a2ui/[email protected] release commit
1b8e728 to
efb9e37
Compare
HostCommunication ran CrossFrameValidator on A2UI_CATALOG envelopes but ignored the result, so a prototype-polluted or non-object payload was still forwarded to CatalogManagement. Replace the payload of a failed envelope with a typed CatalogHandshakeErrorPayload carrying the validator's first error, so the handshake fails immediately with the real reason and the malformed object never reaches downstream consumers. V10WireValidator.validateSendToServer required updateDataModel.path to be a non-empty string, while validateRenderItem, the bridge's UpdateDataModelDetails type, and the v0.9 validator all treat it as optional. Accept an absent path and keep rejecting an empty or non-string one. In addition, enforce non-empty string surfaceId. Addresses review feedback on #322.
- Settle handshake with error on watchdog/bridge failures, keeping v0.9 fallback - Add debug-only deferral log in RawFrame without polluting Errors badge - Share isV1ProtocolVersion across CatalogManagement multi-catalog resolution - Import pipeable RxJS operators from rxjs/operators - Remove unused action$, sendToServerError$, iframeElement, and protocolVersion - Build V10MonacoSchemaStrategy componentUnion from mergedComponentMap - Pin common-types-schema.ts to @a2ui/[email protected] release commit
77999dd to
b50a95b
Compare
Add versioned cross-frame wire validators for A2UI v0.9 and v1.0 specifications with strict prototype pollution stripping. Support multi-catalog payloads, merged active catalog signals with collision detection, and protocol version routing across host communication.
Seed v0-9-draft-strategy.ts directly from state-sync.ts to preserve git log --follow and blame history back to main.
Add version-aware draft protocol strategies for v0.9 and v1.0 templates with automatic draft swapping and user edit preservation. Add protocol version mismatch gate for preview frames with structural version inspection and edge-case payload validation.
Seed v0-9-monaco-schema-strategy.ts directly from monaco-editor.ts to preserve git log --follow and blame history back to main.
Add JSON schemas for A2UI v1.0 common types and wire shapes. Update CatalogSchemaResolver and configure Monaco editor JSON schema validation strategies for v0.9 and v1.0 schemas with primary-catalog-wins merging.
Introduce protocol-aware gallery strategies for A2UI v0.9 and v1.0 with multi-catalog provenance and cross-catalog validation support. Add auto-rejection for unsupported demo RPC operations and synchronize protocol versions across preview and guest frames.
HostCommunication ran CrossFrameValidator on A2UI_CATALOG envelopes but ignored the result, so a prototype-polluted or non-object payload was still forwarded to CatalogManagement. Replace the payload of a failed envelope with a typed CatalogHandshakeErrorPayload carrying the validator's first error, so the handshake fails immediately with the real reason and the malformed object never reaches downstream consumers. V10WireValidator.validateSendToServer required updateDataModel.path to be a non-empty string, while validateRenderItem, the bridge's UpdateDataModelDetails type, and the v0.9 validator all treat it as optional. Accept an absent path and keep rejecting an empty or non-string one. In addition, enforce non-empty string surfaceId. Addresses review feedback on #322.
Fix CallAgentFunctionPayload TS2322 compilation failures in rendered-frame.spec.ts by wrapping call literals in callFunction objects. Replace fixed 30ms setTimeout sleeps in demos.spec.ts with vi.waitFor assertions on CatalogManagement signals to prevent race conditions during catalog resolution. Add missing CatalogManagement mock signals in app.routes.spec.ts and a2a-chat-view.spec.ts to satisfy GuestFrame and Gallery requirements.
…chemas, and catalog sync
- Settle handshake with error on watchdog/bridge failures, keeping v0.9 fallback - Add debug-only deferral log in RawFrame without polluting Errors badge - Share isV1ProtocolVersion across CatalogManagement multi-catalog resolution - Import pipeable RxJS operators from rxjs/operators - Remove unused action$, sendToServerError$, iframeElement, and protocolVersion - Build V10MonacoSchemaStrategy componentUnion from mergedComponentMap - Pin common-types-schema.ts to @a2ui/[email protected] release commit
b50a95b to
fca1cf1
Compare
Description
Summary
strict prototype-pollution stripping; support multi-catalog payloads,
merged active-catalog signals with collision detection, and protocol
version routing across host communication.
automatic draft swapping and user-edit preservation, plus a protocol
version mismatch gate for preview frames (
v0-9-draft-strategy.tsisseeded from
state-sync.tsto preserve history).CatalogSchemaResolver, and configure Monaco JSON schema validationstrategies for v0.9 and v1.0 with primary-catalog-wins merging
(
v0-9-monaco-schema-strategy.tsis seeded frommonaco-editor.ts).provenance and cross-catalog validation, auto-reject unsupported demo RPC
operations, and synchronize protocol versions across preview and guest
frames.
Commits
87 files changed, 9813 insertions(+), 712 deletions(-)
Stack
Stacked PR 4/7 — base:
pr3-bridge-v1-0→ 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