-
Notifications
You must be signed in to change notification settings - Fork 83
Add documentation for the a2ui protocol message lifecycle #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacobsimionato
wants to merge
1
commit into
flutter:main
Choose a base branch
from
jacobsimionato:a2ui_docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||
| # A2UI Message Lifecycle | ||||||||
|
|
||||||||
| [A2UI](https://a2ui.org/) is a new protocol for servers to describe a user interface to a client by sending a stream of JSON messages. This document outlines the roles of the three core message types: `surfaceUpdate`, `DataModelUpdate`, and `beginRendering`. | ||||||||
|
|
||||||||
| ## Core Concepts | ||||||||
|
|
||||||||
| Two principles guide the protocol's design: | ||||||||
|
|
||||||||
| 1. **Separation of Concerns:** The UI's **structure** (components) is managed independently from its **state** (data). This allows for efficient state updates without resending the UI definition. | ||||||||
| 2. **Progressive Rendering:** The client can render the UI incrementally as it receives messages. | ||||||||
|
|
||||||||
| ## Key Messages | ||||||||
|
|
||||||||
| ### 1. `surfaceUpdate` | ||||||||
|
|
||||||||
| This message defines the structure of the UI. It contains a list of components, such as text fields, buttons, or layout containers, each with a unique ID. The client buffers these component definitions upon receipt. | ||||||||
|
|
||||||||
| ### 2. `DataModelUpdate` | ||||||||
|
|
||||||||
| This message provides the state for the UI. It updates a client-side JSON data model that components can bind to. For example, a `DataModelUpdate` can specify the text for a label or the URL for an image. | ||||||||
|
|
||||||||
| ### 3. `beginRendering` | ||||||||
|
|
||||||||
| This message signals the client that it is permitted to start rendering a UI surface. The timing of this message determines the rendering behavior. | ||||||||
|
|
||||||||
| ## Rendering Lifecycle | ||||||||
|
|
||||||||
| The protocol supports two rendering strategies based on the timing of the `beginRendering` message. | ||||||||
|
|
||||||||
| ### Strategy 1: Coordinated Initial Render | ||||||||
|
|
||||||||
| This strategy involves buffering messages to render a complete initial UI. | ||||||||
|
|
||||||||
| 1. **Stream Structure and State:** The server sends one or more `surfaceUpdate` and `DataModelUpdate` messages. The client buffers the components and data without rendering. | ||||||||
| 2. **Send Render Signal:** The server sends the `beginRendering` message after the necessary UI information has been transmitted. | ||||||||
| 3. **Render:** Upon receiving `beginRendering`, the client assembles and displays the complete UI from its buffer. | ||||||||
|
|
||||||||
| This approach prevents the user from seeing a partially loaded UI. | ||||||||
|
|
||||||||
| ### Strategy 2: Progressive Streaming Render | ||||||||
|
|
||||||||
| This strategy renders UI components as they are received. | ||||||||
|
|
||||||||
| 1. **Send Render Signal Early:** The server sends the `beginRendering` message as one of the first messages for a surface. | ||||||||
| 2. **Stream and Render:** The server then sends `surfaceUpdate` and `DataModelUpdate` messages. The client immediately renders or updates the UI as each message is received. | ||||||||
|
|
||||||||
| This approach can improve perceived performance for complex UIs. | ||||||||
|
|
||||||||
| ### Dynamic Updates | ||||||||
|
|
||||||||
| After the initial render, the server can send additional `surfaceUpdate` or `DataModelUpdate` messages at any time to modify the UI in response to events. | ||||||||
|
|
||||||||
| ## Future Considerations | ||||||||
|
|
||||||||
| Future versions of the A2UI specification may deprecate the `beginRendering` message. In such a scenario, `surfaceUpdate` messages would render immediately upon receipt, with a default root component ID assumed by the client. This would simplify the protocol by making the progressive streaming model the default behavior. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a common convention to add a newline at the end of text files. This helps prevent issues with some tools and file concatenations.
Suggested change
|
||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation is clear and well-written. I have a couple of suggestions to improve its accuracy and completeness:
deleteSurfacemessage, which is part of the A2UI protocol and handled in the codebase. It would be beneficial to include it for completeness.surfaceUpdatestates that "The client buffers these component definitions upon receipt." This is only true for "Strategy 1". For "Strategy 2", components are rendered immediately. The description should be more general to cover both cases.