"use client"; import type { ToolCallMessagePartComponent } from "@assistant-ui/react"; import { BarChart, Bar, LineChart, Line, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, } from "recharts"; import { Loader2Icon } from "lucide-react"; type ChartArgs = { title: string; type: "bar" | "line" | "pie"; data: Array>; xKey: string; dataKeys: string[]; }; type ChartResult = { success: boolean; }; const COLORS = [ "oklch(0.646 0.222 41.116)", "oklch(0.6 0.118 184.704)", "oklch(0.398 0.07 227.392)", "oklch(0.828 0.189 84.429)", "oklch(0.769 0.188 70.08)", ]; export const ChartToolUI: ToolCallMessagePartComponent = function ChartUI({ args, status }) { if (status.type === "running" && !args.data?.length) { return (
Generating chart...
); } const { title, type, data, xKey, dataKeys } = args; if (!data?.length || !dataKeys?.length) return null; return (

{title}

{type === "bar" ? ( {dataKeys.map((key, i) => ( ))} ) : type === "line" ? ( {dataKeys.map((key, i) => ( ))} ) : ( {data.map((_, i) => ( ))} )}
); };