- 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>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
/**
|
|
* Chart Tool for Notes
|
|
* Allows AI to generate inline charts from note data
|
|
*/
|
|
|
|
import { tool } from 'ai'
|
|
import { z } from 'zod'
|
|
import { toolRegistry } from './registry'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
// Simple chart generation tool - returns markdown chart
|
|
toolRegistry.register({
|
|
name: 'insert_chart',
|
|
description: 'Generate a chart and return it as markdown. Use when the user asks for a chart, graph, or visualization.',
|
|
isInternal: true,
|
|
buildTool: (ctx) =>
|
|
tool({
|
|
description: `Generate a chart as markdown that will be rendered as an interactive chart.
|
|
|
|
Available chart types:
|
|
- "bar": Vertical bar chart (default for comparisons)
|
|
- "horizontal-bar": Horizontal bar chart (use when labels are long)
|
|
- "line": Line chart (use for time series or trends)
|
|
- "area": Area chart (filled line chart)
|
|
- "pie": Pie chart (use for proportions/percentages)
|
|
- "radar": Radar chart (use for comparing multiple dimensions)
|
|
|
|
CRITICAL - NEVER use Mermaid, flowchart, or other markdown diagram formats. ALWAYS use this tool to generate charts.
|
|
|
|
Chart format:
|
|
\`\`\`chart
|
|
{chartType}
|
|
{title}
|
|
{label1}: {value1}
|
|
{label2}: {value2}
|
|
...
|
|
\`\`\`
|
|
|
|
Example for "show sales by month":
|
|
\`\`\`chart
|
|
bar
|
|
Sales by Month
|
|
Jan: 5000
|
|
Feb: 7500
|
|
Mar: 6200
|
|
\`\`\`
|
|
|
|
Example for "show MRR progression":
|
|
\`\`\`chart
|
|
line
|
|
MRR Growth
|
|
Month 1: 2000
|
|
Month 2: 4500
|
|
Month 3: 8900
|
|
\`\`\``,
|
|
inputSchema: z.object({
|
|
chartMarkdown: z.string().describe('The complete chart markdown block to render (including the ```chart fences)'),
|
|
}),
|
|
execute: async ({ chartMarkdown }) => {
|
|
return {
|
|
chartMarkdown,
|
|
message: 'Chart generated successfully',
|
|
}
|
|
},
|
|
}),
|
|
})
|