"use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; import { z } from "zod"; import { cn } from "@/lib/utils"; import { Bell, TrendingUp, TrendingDown, Percent, DollarSign, Activity, Trash2, Edit2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Switch } from "@/components/ui/switch"; // Schema for alert configuration const AlertConfigSchema = z.object({ id: z.string(), type: z.enum(["price_above", "price_below", "percent_change", "volume_spike", "whale_activity"]), value: z.number(), enabled: z.boolean(), }); // Schema for alert configuration tool arguments export const AlertConfigurationArgsSchema = z.object({ tokenSymbol: z.string(), tokenName: z.string().optional(), alerts: z.array(AlertConfigSchema), }); export type AlertConfigurationArgs = z.infer; // Schema for alert configuration result export const AlertConfigurationResultSchema = z.object({ success: z.boolean(), message: z.string().optional(), }); export type AlertConfigurationResult = z.infer; const ALERT_TYPE_CONFIG = { price_above: { icon: TrendingUp, label: "Price Above", color: "text-green-500" }, price_below: { icon: TrendingDown, label: "Price Below", color: "text-red-500" }, percent_change: { icon: Percent, label: "% Change", color: "text-blue-500" }, volume_spike: { icon: Activity, label: "Volume Spike", color: "text-purple-500" }, whale_activity: { icon: DollarSign, label: "Whale Activity", color: "text-orange-500" }, }; const formatValue = (type: string, value: number): string => { if (type === "percent_change") return `${value > 0 ? "+" : ""}${value}%`; if (type === "volume_spike") return `${value}x normal`; if (type === "whale_activity") return `>${value.toLocaleString()} USD`; return `$${value < 1 ? value.toFixed(6) : value.toLocaleString()}`; }; /** * AlertConfigurationToolUI - Displays/edits alert configurations for a token * Used when AI responds to "set alert for BULLA" or "show my alerts for BULLA" */ export const AlertConfigurationToolUI = makeAssistantToolUI({ toolName: "configure_alerts", render: ({ args, status }) => { const isLoading = status.type === "running"; const alerts = args.alerts || []; const enabledCount = alerts.filter(a => a.enabled).length; return (
Alerts for {args.tokenSymbol} {enabledCount} active {isLoading && Loading...}
{alerts.length === 0 ? (

No alerts configured

Say "Alert me if {args.tokenSymbol} drops 20%"

) : (
{alerts.map((alert) => { const config = ALERT_TYPE_CONFIG[alert.type]; const Icon = config.icon; return (

{config.label}

{formatValue(alert.type, alert.value)}

); })}
)}
); }, });