Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions specification/v0_9/docs/a2ui_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,53 @@ flowchart TD

```

### Defining Actions

Interactive components (like `Button`) use an `action` property to define what happens when the user interacts with them. Actions can either trigger an event sent to the server or execute a local client-side function.

#### Server Actions

To send an event to the server, the `action` property is defined as an object with a `name` and an optional `context`.

```json
{
"component": "Button",
"text": "Submit",
Comment on lines +283 to +284
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Button component examples in the "Defining Actions" section are incorrect. According to the standard_catalog.json schema, Button does not have a text property. Instead, it requires a child property which should be the ID of a child component (like Text). This issue is present in the "Server Actions", "Local Actions (String Shorthand)", and "Local Actions (Object Definition)" examples.

For example, the server action snippet should be structured like this:

{
  "component": "Button",
  "child": "submit_button_label",
  "action": {
    "name": "submit_form",
    "context": {
      "itemId": "123"
    }
  }
}

...where submit_button_label would be the ID of a Text component defined separately (e.g., {"id": "submit_button_label", "component": "Text", "text": "Submit"}).

Please correct all three examples to align with the Button component's schema.

Suggested change
"component": "Button",
"text": "Submit",
"component": "Button",
"child": "submit_button_label",

"action": {
"name": "submit_form",
"context": {
"itemId": "123"
}
}
}
```

#### Local Actions

To execute a local function, the `action` property can be defined as a string containing a function call expression, or as an object with a `function` property.

**String Shorthand:**

```json
{
"component": "Button",
"text": "Open Link",
"action": "openUrl(${/url})"
}
```

**Object Definition:**

```json
{
"component": "Button",
"text": "Open Link",
"action": {
"function": "openUrl(${/url})"
}
}
```

## Data Model Representation: Binding, Scope, and Interpolation

This section describes how UI components **represent** and reference data from the Data Model. A2UI relies on a strictly defined relationship between the UI structure (Components) and the state (Data Model), defining the mechanics of path resolution, variable scope during iteration, and interpolation.
Expand Down
40 changes: 40 additions & 0 deletions specification/v0_9/json/common_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,46 @@
}
}
}
},
"Action": {
"description": "Defines an interaction handler that can either trigger a server-side event or execute a local client-side function.",
"oneOf": [
{
"type": "object",
"description": "Triggers a server-side event.",
"properties": {
"name": {
"type": "string",
"description": "The name of the action to be dispatched to the server."
},
"context": {
"type": "object",
"description": "A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",
"additionalProperties": {
"$ref": "#/$defs/DynamicValue"
}
}
},
"required": ["name"],
"additionalProperties": false
},
{
"type": "object",
"description": "Executes a local client-side function.",
"properties": {
"function": {
"type": "string",
"description": "A string specifying the local function to trigger (e.g., 'openUrl(${/url})'). This string can represent nested function calls and data model references."
}
},
"required": ["function"],
"additionalProperties": false
},
{
"type": "string",
"description": "Shorthand for a local client-side function execution (e.g. 'openUrl(${/url})')."
}
]
}
Comment on lines +321 to 360
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This pull request introduces a significant new feature: local actions, with both an object and a string shorthand form. However, there are no new test cases being added to verify this new functionality. Adding tests for the new local action formats is important to ensure they are parsed and handled correctly by clients.

References
  1. The repository style guide requires that code changes are accompanied by tests. This change adds a new feature without corresponding tests. (link)

}
}
15 changes: 1 addition & 14 deletions specification/v0_9/json/standard_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,7 @@
"description": "Indicates if this button should be styled as the primary action."
},
"action": {
"type": "object",
"description": "The client-side action to be dispatched when the button is clicked. It includes the action's name and an optional context payload.",
"properties": {
"name": { "type": "string" },
"context": {
"type": "object",
"description": "A JSON object containing the key-value pairs for the action context. Values can be literals or paths. Use literal values unless the value must be dynamically bound to the data model. Do NOT use paths for static IDs.",
"additionalProperties": {
"$ref": "common_types.json#/$defs/DynamicValue"
}
}
},
"required": ["name"],
"additionalProperties": false
"$ref": "common_types.json#/$defs/Action"
}
},
"required": ["component", "child", "action"]
Expand Down
Loading