fix(chart): rewrite suggestion logic with better error handling

- Remove conflicting tool approach, use direct JSON
- Add fallback: extract numbers from regex if AI fails
- Add debug section to show what content was analyzed
- Be more lenient: any 2+ numbers = valid chart
- Better error messages
- Add console logging for debugging

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antigravity
2026-05-23 09:36:26 +00:00
parent 625a79a1f9
commit 54385e9f10
2 changed files with 111 additions and 67 deletions

View File

@@ -53,6 +53,7 @@ export function ChartSuggestionsDialog({
suggestCharts({ content, selection, noteId })
.then(data => {
if (aborted) return
console.log('[ChartSuggestionsDialog] Response:', data)
setResponse(data)
setLoading(false)
})
@@ -61,10 +62,10 @@ export function ChartSuggestionsDialog({
console.error('[ChartSuggestionsDialog] Error:', err)
setResponse({
suggestions: [],
analyzedText: '',
detectedData: '',
analyzedText: textToAnalyze?.substring(0, 100) || '',
detectedData: 'Error occurred',
hasData: false,
error: err.message || 'Failed to load suggestions',
error: err.message || 'Network error - check console',
})
setLoading(false)
})
@@ -192,6 +193,17 @@ export function ChartSuggestionsDialog({
<li> Percentages or proportions</li>
<li> Time-series data</li>
</ul>
<div className="mt-4 pt-4 border-t border-border/50">
<details className="text-left">
<summary className="text-xs text-muted-foreground cursor-pointer hover:text-foreground">
Debug: Show what was analyzed
</summary>
<pre className="mt-2 text-xs bg-muted p-2 rounded overflow-auto max-h-32">
{textToAnalyze.substring(0, 500)}
{textToAnalyze.length > 500 && '...'}
</pre>
</details>
</div>
</div>
</div>
) : (