pub fn wrap_error_envelope(
surface_id: &str,
message: &str,
errors: &[ValidationError],
) -> Result<String>Expand description
Builds the payload reporting that a surface could not be produced.
Deliberately not an operations envelope. A2UI_OPERATIONS_KEY is the
content sniff, so carrying it — even with an empty list — leaves a failed
generation indistinguishable from a rendered one to every consumer that keys
on it, history included. Upstream draws the same
line: its tool returns the validated operations under one key on success and
error on failure, never both, and its part converter checks error first
and emits no A2UI at all.
error is therefore the human-readable message, the way upstream sends it.
The specification’s structured validation fields sit alongside it rather
than nested under it, since error is already the spec’s message, with the
full validation list under details for callers that route on the codes.
use ag_ui_a2ui::toolkit::envelope::{is_operations_envelope, wrap_error_envelope};
let json = wrap_error_envelope("s1", "could not build the surface", &[]).unwrap();
let value: serde_json::Value = serde_json::from_str(&json).unwrap();
assert_eq!(value["error"], "could not build the surface");
assert!(!is_operations_envelope(&value));§Errors
Returns Error::Json if the error list cannot be
serialized.