Skip to main content

ExtensionComponent

Trait ExtensionComponent 

Source
pub trait ExtensionComponent:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn schema(&self) -> Value;
    fn usage(&self) -> &'static str;
    fn home(
        &self,
        component: &ResolvedComponent<'_>,
    ) -> Result<HomeNode, String>;

    // Provided methods
    fn children(&self) -> &'static [ChildSlot] { ... }
    fn allowed_parents(&self) -> &'static [&'static str] { ... }
    fn allowed_children(&self) -> &'static [&'static str] { ... }
}
Expand description

A component an extension catalog adds to forms 1.0 (spec 3.3 §6.1 genui, extension catalogs).

A component only shows: its schema may not declare action, event or checks, and an instance that carries any of them is refused. home says what the web home and the terminal show for it; a host that registers a renderer for the component (the React DrawnView’s renderers) may draw its resolved properties instead.

§Example

use adk_surface::genui::{ExtensionComponent, HomeNode, ResolvedComponent};
use serde_json::{Value, json};

struct Metric;

impl ExtensionComponent for Metric {
    fn name(&self) -> &'static str {
        "Metric"
    }
    fn schema(&self) -> Value {
        json!({
            "type": "object",
            "properties": {
                "id": { "type": "string" },
                "component": { "const": "Metric" },
                "label": { "$ref": "https://a2ui.org/specification/v0_9/common_types.json#/$defs/DynamicString" },
                "value": { "$ref": "https://a2ui.org/specification/v0_9/common_types.json#/$defs/DynamicValue" }
            },
            "required": ["id", "component", "label", "value"],
            "additionalProperties": false
        })
    }
    fn usage(&self) -> &'static str {
        "Metric: one number with its label, such as {label: \"Open incidents\", value: 3}"
    }
    fn home(&self, metric: &ResolvedComponent<'_>) -> Result<HomeNode, String> {
        let value = metric.get("value").map(Value::to_string).unwrap_or_default();
        Ok(HomeNode::Row(vec![
            HomeNode::caption(metric.str("label").unwrap_or_default()),
            HomeNode::heading(3, value.trim_matches('"')),
        ]))
    }
}

Required Methods§

Source

fn name(&self) -> &'static str

The component’s type, unique in the catalog and not one of forms’ or of the components forms leaves out.

Source

fn schema(&self) -> Value

Its A2UI component schema (JSON Schema). It may $ref the A2UI common types and the catalog’s #/$defs/CatalogComponentCommon, and declares no $defs, functions, action, event, checks or URI formats.

Source

fn usage(&self) -> &'static str

One line the render tools tell the model about it: what it shows and its shape.

Source

fn home(&self, component: &ResolvedComponent<'_>) -> Result<HomeNode, String>

What the home and the terminal show for it, from its resolved properties. It must be pure: the same component always projects the same way.

§Errors

Returns why the component cannot be shown; the drawing is refused with that reason.

Provided Methods§

Source

fn children(&self) -> &'static [ChildSlot]

The properties that hold other components, by id; none for a component that holds nothing.

Source

fn allowed_parents(&self) -> &'static [&'static str]

The component types that may hold it (A2UI 1.0 allowedParents, "Surface" for the top level); empty for any.

Source

fn allowed_children(&self) -> &'static [&'static str]

The component types it may hold (A2UI 1.0 allowedChildren); empty for any.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§