Skip to main content

find_prior_surface_in

Function find_prior_surface_in 

Source
pub fn find_prior_surface_in(messages: &[Message]) -> Option<PriorSurface>
Expand description

find_prior_surface over an AG-UI conversation.

The agent stores nothing between runs, so “what is the user looking at” comes from the thread the client sent: this replays the A2UI operations already in it and reports the surface they built.

use ag_ui_a2ui::agui::find_prior_surface_in;
use ag_ui_a2ui::toolkit::envelope::wrap_as_operations_envelope;
use ag_ui_a2ui::{AgentMessage, Component};
use ag_ui::Message;
use serde_json::json;

let rendered = wrap_as_operations_envelope(&[
    AgentMessage::create_surface("board", "basic"),
    AgentMessage::update_components(
        "board",
        vec![Component::new("root", "Text").with("text", json!("hello"))],
    ),
])?;

let thread = [
    Message::user("m-1", "show me the board"),
    Message::tool("m-2", "call-1", rendered),
];

let prior = find_prior_surface_in(&thread).expect("the thread rendered a surface");
assert_eq!(prior.surface_id, "board");
assert_eq!(prior.catalog_id.as_deref(), Some("basic"));
assert!(prior.component("root").is_some());