fix(chart): improve error handling and color variety

- Add quotaExceeded flag to response for better error UX
- Show dedicated quota exceeded state with upgrade button
- Improve AI prompt to better detect data patterns
- Add chart type-specific colors (blue, indigo, emerald, violet, etc.)
- Replace generic primary/10 colors with varied accent colors

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antigravity
2026-05-23 09:19:52 +00:00
parent a122a0eade
commit 18ffd76c1e
16 changed files with 1042 additions and 134 deletions

View File

@@ -90,11 +90,23 @@ export async function POST(req: Request) {
model: provider(model),
system: `You are a data visualization assistant. Analyze the provided text and suggest appropriate chart types.
CRITICAL: Extract ONLY numerical data present in the text. Do NOT invent values.
DATA EXTRACTION RULES:
- Extract ANY numerical data present in the text
- Look for patterns like: "X: 123", "X = 123", "X is 123", "X (123)", "123X", "X $123", "123%"
- Accept partial data (e.g., if only 2 values exist, that's still valid for a simple chart)
- If fewer than 2 data points exist, return hasData=false with empty suggestions
- Each suggestion must use the SAME extracted data (only chart type differs)
- Return exactly 3 suggestions when data exists
- Provide clear rationale for each chart type choice
CHART TYPE SELECTION:
- bar: Comparing values across categories (default choice)
- horizontal-bar: Categories with long labels
- line: Time series or sequential data
- area: Time series where magnitude matters
- pie: Parts of a whole (percentages or proportions)
- radar: Comparing multiple dimensions
- funnel: Stages or conversion steps
- gauge: Single value vs target
Response format (JSON):
{