Skip to main content

MessageProcessor

Struct MessageProcessor 

Source
pub struct MessageProcessor {
    pub model: SurfaceGroupModel,
    /* private fields */
}
Expand description

Parses A2UI JSON messages and applies them to the state models.

Fields§

§model: SurfaceGroupModel

The state model (all active surfaces).

Implementations§

Source§

impl MessageProcessor

Source

pub fn new(catalogs: Vec<Catalog>) -> Self

Create a new processor with the given catalogs.

Source

pub fn reset(&mut self)

Reset all processed state (surfaces and outgoing messages) while keeping the registered catalogs intact.

Use this to replay a sample from scratch instead of constructing a new processor with MessageProcessor::new(vec![]), which would silently drop the catalogs and cause every component type to be flagged as “unknown”.

Source

pub fn parse_message(json: &str) -> Result<A2uiMessage>

Parse a raw JSON string into an A2uiMessage.

Source

pub fn parse_jsonl(jsonl: &str) -> Vec<Result<A2uiMessage>>

Parse a JSONL stream (newline-delimited JSON objects).

Source

pub fn process_message(&mut self, msg: A2uiMessage) -> Result<()>

Process a single parsed message.

Source

pub fn process_messages( &mut self, messages: Vec<A2uiMessage>, ) -> Vec<Result<()>>

Process multiple messages sequentially.

Source

pub fn drain_outgoing(&mut self) -> Vec<ClientMessage>

Drain outgoing client-to-server messages produced during processing.

Call this after process_message / process_messages to retrieve any functionResponse, error, or other client messages that should be sent back to the server.

Source

pub fn catalog_type_exists(&self, component_type: &str) -> bool

Check if a component type exists in any registered catalog.

Source

pub fn registered_catalog_ids(&self) -> Vec<String>

Return the IDs of all registered catalogs (native + inline).

Source

pub fn register_inline_catalog(&mut self, json: Value) -> Result<()>

Register an inline catalog from a raw JSON value.

The catalog is parsed via [capabilities::parse_inline_catalog]. Each declared function becomes a [SchemaOnlyFunction] in a fresh Catalog (so handle_call_function can discover and reject execution attempts). Declared components have no native renderer and are not added to catalog.components — at render time they fall back to the generic renderer.

Source

pub fn register_action( &mut self, surface_id: &str, action_id: &str, response_path: Option<String>, ) -> Result<()>

Register a pending action that expects a server response.

Call this when the caller sends an action message with wantResponse: true. The response_path (if any) tells the processor where to store the server’s response value in the data model.

Source

pub fn load_sample(json: &str) -> Result<(String, String, Vec<A2uiMessage>)>

Load a sample file (wrapping messages in {name, description, messages}).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.