Expand description
Pulling A2UI out of a model’s response.
When A2UI is generated by prompting rather than by structured output, the
model returns prose with one or more A2UI blocks embedded in it, fenced by
A2UI_OPEN_TAG and A2UI_CLOSE_TAG. parse_response splits that into
ordered ResponseParts: the conversational text preceding each block, and
the block’s parsed JSON.
§Why this is a scanner and not a string split
A close tag can appear inside a JSON string literal — a Text component
whose content mentions </a2ui-json> is perfectly legal — so the scanner
tracks string state and escapes rather than searching for the next
occurrence.
§Repairing model output
parse_and_fix applies the two repairs that are safe because they cannot
change the meaning of valid JSON: normalizing smart quotes, and dropping
trailing commas. It only reaches for them after a straight parse has failed,
and it wraps a lone object in an array, since A2UI payloads are always lists
of messages.
Structs§
- Response
Part - One segment of a model response.
Functions§
- has_
a2ui_ parts - Whether the content contains a complete A2UI block.
- parse_
and_ fix - Parses a raw A2UI block, repairing the model’s usual JSON slips.
- parse_
response - Splits a full model response into text and parsed A2UI blocks.
- unwrap_
response - Splits a response into parts without parsing the block contents.