isJsonComplete static method
Checks if JSON structure appears complete
Implementation
static bool isJsonComplete(String buffer) {
final clean = buffer.trim();
if (clean.isEmpty) return false;
// Direct JSON: starts with { and ends with }
if (clean.startsWith('{') && clean.endsWith('}')) {
return _isBalancedJson(clean);
}
// Markdown JSON block: ```json...```
if (clean.contains('```json') && clean.endsWith('```')) {
return true;
}
// Any markdown block: ```...```
if (clean.startsWith('```') && clean.endsWith('```') && clean.lastIndexOf('```') > clean.indexOf('```')) {
return true;
}
// Tool code block: <tool_code>...</tool_code>
if (clean.contains('<tool_code>') && clean.contains('</tool_code>')) {
return true;
}
return false;
}