import { Severity, CopilotKitError, ErrorVisibility, CopilotKitErrorCode, } from "@copilotkit/shared"; import React from "react"; interface UsageBannerProps { severity?: Severity; message?: string | React.ReactNode; onClose?: () => void; actions?: { primary?: { label: string; onClick: () => void; }; secondary?: { label: string; onClick: () => void; }; }; } export function UsageBanner({ severity = Severity.CRITICAL, message = "", onClose, actions, }: UsageBannerProps) { if (!message || !severity) { return null; } const themes = { [Severity.INFO]: { bg: "#f8fafc", border: "#e2e8f0", text: "#475569", accent: "#3b82f6", }, [Severity.WARNING]: { bg: "#fffbeb", border: "#fbbf24", text: "#92400e", accent: "#f59e0b", }, [Severity.CRITICAL]: { bg: "#fef2f2", border: "#fecaca", text: "#dc2626", accent: "#ef4444", }, }; const theme = themes[severity]; return ( <>
{message}
{actions?.primary && ( )} {onClose && ( )}
); } // Get action button based on error type export const getErrorActions = (error: CopilotKitError) => { switch (error.code) { case CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR: return { primary: { label: "Show me how", onClick: () => window.open( "https://docs.copilotkit.ai/premium#how-do-i-get-access-to-premium-features", "_blank", "noopener,noreferrer", ), }, }; case CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR: return { primary: { label: "Upgrade", onClick: () => window.open( "https://cloud.copilotkit.ai", "_blank", "noopener,noreferrer", ), }, }; default: return undefined; } }; export function renderCopilotKitUsage( error: CopilotKitError, onClose?: () => void, ) { // Route based on error visibility level if (error.visibility !== ErrorVisibility.BANNER) { return null; } return ( ); }