Expand description
Semantic validation of a component tree.
JSON Schema can say that children is an array of strings. It cannot say
that every one of those strings names a component that exists, that the tree
has a root, or that a → b → a is a loop the renderer will never finish
drawing. That is what this module checks.
Every failure is a ValidationError carrying a machine-readable
ErrorCode, a path locator into the components list, and a sentence
written to be fed straight back to a model on retry. The validator collects
all errors rather than stopping at the first, so one retry can fix
everything at once.
§Depth
The component graph is walked iteratively, with an explicit worklist, in
every case — cycle detection, reachability, and scope assignment. That is not
a style preference: the graph is model-generated and its depth is bounded by
nothing, so a recursive walk would abort the process rather than fail a
request. MAX_DEPTH is therefore a policy about what a renderer will
draw, not what keeps this crate standing, and it can be raised safely.
§Full surfaces and incremental updates
A payload that creates a surface is held to the full contract: a root must
exist and every child reference must resolve within the payload. An
incremental updateComponents is not — its components may legitimately
reference ids the renderer already holds, and it need not include the root.
ValidateOptions::incremental_update relaxes exactly those two rules;
duplicate ids and cycles still fail, because those are broken either way.
use ag_ui_a2ui::{catalog::Catalog, message::Component, validate::{ErrorCode, Validator}};
use serde_json::json;
let catalog = Catalog::basic();
let report = Validator::new(&catalog).validate(&[
Component::new("root", "Card").with("child", json!("nope")),
]);
assert_eq!(report.errors[0].code, ErrorCode::UnresolvedChild);
assert_eq!(report.errors[0].path, "components[0].child");Structs§
- Validate
Options - What the validator should demand of a payload.
- Validation
Error - One semantic failure, located and explained.
- Validation
Report - What a validation run found.
- Validator
- Validates component trees against a catalog.
Enums§
- Error
Code - The complete set of semantic failures this validator reports.
Constants§
- MAX_
DEPTH - Deepest nesting accepted by default, for both the component graph and the raw JSON of a message.
- MAX_
FUNCTION_ CALL_ DEPTH - Deepest chain of nested function calls accepted by default.