Skip to main content

read_function_message

Function read_function_message 

Source
pub fn read_function_message(
    message: &Value,
) -> Result<Option<FunctionMessage>, WireError>
Expand description

Reads an A2UI 1.0 function message: a call or its answer. Ok(None) when message is not one (a surface message, say).

§Errors

A function message that is not A2UI 1.0 (v0.9.1 has none), or that lacks what 1.0 requires: a functionCallId; a callFunction with its @call; the catalogId of an agent’s call; the surfaceId of a renderer’s; exactly one of an answer’s value and error, and an error’s code and message.

§Example

use adk_surface::genui::{FunctionCaller, FunctionMessage, read_function_message};
use serde_json::json;

let read = read_function_message(&json!({ "version": "1.0", "callAgentFunction": {
    "surfaceId": "s", "functionCallId": "c2", "callFunction": { "@call": "lookupProvider" } } }))?;
assert!(matches!(read, Some(FunctionMessage::Call(call)) if call.caller == FunctionCaller::Renderer));
assert_eq!(read_function_message(&json!({ "version": "1.0", "deleteSurface": { "surfaceId": "s" } }))?, None);