parseDigest function
- String response
Strip markdown fences (defensive — the SESSION_DIGEST_PROMPT instructs no fences, but small models occasionally add them) and decode the JSON object. Throws FormatException on malformed input.
Implementation
SessionDigest parseDigest(String response) {
var text = response.trim();
if (text.startsWith('```')) {
text = text.replaceFirst(RegExp(r'^```\w*\n?'), '');
text = text.replaceFirst(RegExp(r'\n?```$'), '');
}
final decoded = jsonDecode(text) as Map<String, dynamic>;
return SessionDigest.fromJson(decoded);
}