Skip to content

feat(swift): v1.0 support - #2583

Draft
pinieb wants to merge 8 commits into
a2ui-project:mainfrom
pinieb:feat/swift-v1-0-support
Draft

pinieb wants to merge 8 commits into
a2ui-project:mainfrom
pinieb:feat/swift-v1-0-support

Conversation

@pinieb

@pinieb pinieb commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

This pull request implements A2UI Protocol v1.0 support in the Swift codebase (swift/core, swift/swiftui, and swift/sample) while maintaining backward compatibility with v0.9 and v0.9.1 catalogs and payloads. It also modernizes wire models and error types to use typed enums and updated naming conventions.

Protocol models & versioning

  • Added A2UIProtocolVersion enum (v0.9, v0.9.1, v1.0) with standard raw-value Codable decoding and encoding.
  • Modernized wire message models: renamed types to AgentToRendererMessage, RendererToAgentMessage, RendererAction, and RendererError without legacy type aliases.
  • Refactored ValidationFailedError to use a string-backed Code enum (VALIDATION_FAILED, UNALLOWED_PARENT, UNALLOWED_CHILD) with compiler-synthesized Codable.

Remote procedure calls (RPC)

  • Added v1.0 RPC wire message types: CallRendererFunctionMessage, RendererFunctionResponseMessage, CallAgentFunctionMessage, and AgentFunctionResponseMessage.
  • Added RPCHandler to MessageProcessor for bidirectional function execution and correlation with timeout and error handling.

Catalogs & validation

  • Embedded JSON Schema Draft 2020-12 common_types.json and catalog_definition.json in A2UICommonSchema.swift.
  • Added AllowedCallers, ValidationResult, ValidationSeverity, and UnicodeIdentifierValidator.
  • Extended ComponentAPI with allowedParents and allowedChildren, and FunctionAPI with allowedCallers and requiresUserActivation.
  • Updated GraphTopologyValidator to enforce component composition rules.

State engine updates

  • Implemented explicit null deletion in DataModel.
  • Added dynamic @index evaluation in DataContext for templates.
  • Updated path resolution for empty relative pointers (path: "") and template child instance IDs (<child>_<parent>_<index>).

Basic catalog v1.0

  • Added IndexFunction for accessing iteration index in templates.
  • Updated validation functions (EmailFunction, NumericFunction, RequiredFunction, RegexFunction, LengthFunction) to return ValidationResult.
  • Registered v10Catalog and v10Components with Draft 2020-12 schema compatibility.

Testing & conformance

  • Added V10ConformanceTests with embedded test YAML data in EmbeddedV10YAML.swift, ensuring test suites run self-contained within the repository without requiring unmerged upstream files on disk.
  • Added unit test suites for RPCHandler, A2UIProtocolVersion, CatalogV10, StateEngineV10, and IndexFunction.

Verification

From repository root:

  • swift build: builds cleanly without errors.
  • swift test in swift/core: 225 core tests and 17 conformance tests pass.
  • swift test in swift/swiftui: 58 SwiftUI integration tests pass.
  • swift-format lint -r swift/: 0 warnings, 0 errors.

…esolver

Extract component tree resolution, schema property classification, check validation,
action binding, and dynamic value evaluation from SurfaceViewModel into a dedicated
NodeResolver class.

- Introduce NodeResolver under swift/core/Sources/A2UICore/Resolution/
- Update SurfaceViewModel to compose NodeResolver and publish rootNode
- Add unit tests for NodeResolver in NodeResolverTests

Fixes a2ui-project#2090
…ct#2487)

- Encapsulate SurfaceComponentsModel in NodeResolver alongside DataModel.
- Add convenience initializer accepting SurfaceViewModel directly.
- Expose parameterless resolveTree() -> Node? on the public API surface.
- Restrict recursion machinery and schema evaluation helpers to private.
- Remove SurfaceViewModel.resolveNode(...).
- Support initial components seeding in SurfaceComponentsModel.
- Update NodeResolverTests to test exclusively through the public API surface.
- Add v1.0 JSON schemas and validation support (Draft 2020-12 common_types and catalog_definition)
- Modernize wire models: rename client/server types to AgentToRendererMessage and RendererToAgentMessage (with RendererAction and RendererError, eliminating legacy typealiases)
- Add RPC message models: CallRendererFunctionMessage, RendererFunctionResponseMessage, CallAgentFunctionMessage, AgentFunctionResponseMessage
- Add AllowedCallers, ValidationResult, ValidationSeverity, and UnicodeIdentifierValidator
- Extend ComponentAPI with allowedParents/allowedChildren and FunctionAPI with allowedCallers/requiresUserActivation
- Implement State Engine v1.0 behaviors: explicit null deletion in DataModel, @index in DataContext, template child instance IDs, path resolution for empty relative pointers, and GraphTopologyValidator composition constraints
- Implement bidirectional RPCHandler on MessageProcessor with outboundListener integration
- Update Basic Catalog v1.0: add IndexFunction, modernize validation functions to return ValidationResult, and support v1.0 components
- Add comprehensive unit and v1.0 conformance test suites with embedded test YAMLs
- Replace static validErrorCodes set and manual decoder validation in ValidationFailedError with a string-backed Code enum (VALIDATION_FAILED, UNALLOWED_PARENT, UNALLOWED_CHILD)
- Leverage synthesized Codable for ValidationFailedError
- Update RendererError discriminator to check ValidationFailedError.Code(rawValue:)
- Update MessageErrorMapper to map detail codes directly to Code enum
- Add unit tests verifying all Code cases and rejecting invalid error codes
- Add A2UIProtocolVersion string-backed enum (.v09, .v091, .v10) with loose prefix parsing and synthesized Codable support
- Update AgentToRendererMessage and RendererToAgentMessage to decode and encode version using A2UIProtocolVersion
- Extend ValidationConfig and MessageProcessor.CapabilitiesOptions with typed protocolVersion properties and initializers
- Add isV10 and a2uiProtocolVersion helper properties to CatalogProtocol
- Update A2UIValidator, NodeResolver, and BasicCatalog to use A2UIProtocolVersion
- Add comprehensive decoding and validation unit tests for supported and unsupported version strings
…se prefix parsing

- Remove loose initializer from A2UIProtocolVersion and rely on standard synthesized raw-value Codable
- Enforce strict raw value matching (v0.9, v0.9.1, v1.0) in A2UIValidator, ValidationConfig, MessageProcessor, and CatalogProtocol
- Update unit tests to verify un-prefixed versions (0.9, 1.0) are strictly rejected as invalid protocol versions

@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 updates the A2UI Swift core to support protocol version 1.0, renaming server/client terminology to agent/renderer, refactoring tree resolution into a dedicated NodeResolver, and introducing bidirectional RPC capabilities, composition constraints, and the @index system function. The review feedback highlights a critical concurrency issue in RPCHandler where an unstructured task could cause a data race on pendingCalls, unsafe Double to Int conversions in DataContext and IndexFunction that could lead to crashes or incorrect parsing, and strict version checks in SurfaceViewModel that limit forward compatibility.

Comment thread swift/core/Sources/A2UICore/RPC/RPCHandler.swift Outdated
Comment thread swift/core/Sources/A2UICore/State/DataContext.swift Outdated
Comment thread swift/core/Sources/BasicCatalog/Functions/IndexFunction.swift Outdated
Comment thread swift/core/Sources/A2UICore/Models/SurfaceViewModel.swift
…pealiases

- Fix NumericFunction in BasicFunctions.v10Functions to return validationResult
- Eliminate force unwrapping in NodeResolver and test suites
- Introduce FunctionErrorPayload.Code string-backed enum for standard error codes
- Enforce schema invariants for GenericError and FunctionResponse
- Add A2UIValidator checks for v1.0 RPC actions and reject unrecognized actions
- Wrap lines in GraphTopologyValidator to comply with 100-character line limit
- Restore deprecated typealiases with renamed hint for ServerToClientMessage, ClientToServerMessage, ClientAction, and ClientServerError
…rward compatibility

- Isolate RPCHandler timeout Task to @mainactor to eliminate data race
- Use Int(exactly:) for safe Double-to-Int conversion in DataContext and IndexFunction
- Support Double offset parsing in IndexFunction with fallback
- Implement forward-compatible isAtLeastV10 check on CatalogProtocol
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.

1 participant