"use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; import { z } from "zod"; import { cn } from "@/lib/utils"; import { AlertTriangle, TrendingUp, TrendingDown, Activity, Zap, Eye, Bell, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; // Schema for proactive alert tool arguments export const ProactiveAlertArgsSchema = z.object({ alertType: z.enum(["price_surge", "price_drop", "whale_buy", "whale_sell", "volume_spike", "safety_warning"]), tokenSymbol: z.string(), tokenName: z.string().optional(), value: z.number(), previousValue: z.number().optional(), message: z.string(), severity: z.enum(["info", "warning", "critical"]).optional(), timestamp: z.string().optional(), }); export type ProactiveAlertArgs = z.infer; // Schema for proactive alert result export const ProactiveAlertResultSchema = z.object({ acknowledged: z.boolean(), }); export type ProactiveAlertResult = z.infer; const ALERT_TYPE_CONFIG = { price_surge: { icon: TrendingUp, color: "text-green-500", bgColor: "bg-green-500/10", borderColor: "border-l-green-500" }, price_drop: { icon: TrendingDown, color: "text-red-500", bgColor: "bg-red-500/10", borderColor: "border-l-red-500" }, whale_buy: { icon: Zap, color: "text-green-500", bgColor: "bg-green-500/10", borderColor: "border-l-green-500" }, whale_sell: { icon: Zap, color: "text-red-500", bgColor: "bg-red-500/10", borderColor: "border-l-red-500" }, volume_spike: { icon: Activity, color: "text-purple-500", bgColor: "bg-purple-500/10", borderColor: "border-l-purple-500" }, safety_warning: { icon: AlertTriangle, color: "text-yellow-500", bgColor: "bg-yellow-500/10", borderColor: "border-l-yellow-500" }, }; const SEVERITY_CONFIG = { info: { badge: "secondary", pulse: false }, warning: { badge: "warning", pulse: false }, critical: { badge: "destructive", pulse: true }, }; /** * ProactiveAlertToolUI - Displays AI-initiated alerts in chat * Used when AI proactively notifies user about price changes, whale activity, etc. */ export const ProactiveAlertToolUI = makeAssistantToolUI({ toolName: "proactive_alert", render: ({ args, result }) => { const config = ALERT_TYPE_CONFIG[args.alertType]; const severity = args.severity || "info"; const severityConfig = SEVERITY_CONFIG[severity]; const Icon = config.icon; const isAcknowledged = result?.acknowledged; const formatChange = () => { if (args.previousValue === undefined) return null; const change = ((args.value - args.previousValue) / args.previousValue) * 100; return change; }; const change = formatChange(); return (
{/* Alert Icon */}
{/* Content */}
{args.alertType.replace("_", " ")} {args.tokenSymbol} {change !== null && ( = 0 ? "text-green-500" : "text-red-500" )}> {change >= 0 ? "+" : ""}{change.toFixed(1)}% )} {args.timestamp && ( {args.timestamp} )}

{args.message}

{/* Dismiss */} {!isAcknowledged && ( )}
{/* Action buttons */} {!isAcknowledged && (
)}
); }, });