Skip to main content

parse_envelope

Function parse_envelope 

Source
pub fn parse_envelope(raw: &str) -> Result<Envelope, DispatchError>
Expand description

Extract a Warble render envelope from raw agent output. The agent is asked to emit only the JSON envelope, but models routinely wrap it in ```json fences or surround it with a sentence. This is deliberately forgiving:

  1. try to parse the whole string as JSON;
  2. else pull the contents of the first json / fenced block;
  3. else scan for the first balanced {...} object that contains a top-level "blocks" key.

Returns an error if none of those yield an object with a blocks array.