The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(ui): centralize toast messages and history
Steven Enamakelef5c6efe3fbb
diff --git a/app/src/components/intelligence/Toast.tsx b/app/src/components/intelligence/Toast.tsxindex dfb20e1e43..e662314eb3 100644--- a/app/src/components/intelligence/Toast.tsx+++ b/app/src/components/intelligence/Toast.tsx@@ -1,161 +1,37 @@-import { useCallback, useEffect, useState } from 'react';+import { useEffect, useRef } from 'react';-import { useT } from '../../lib/i18n/I18nContext';import type { ToastNotification } from '../../types/intelligence';-import { Button, CloseIcon } from '../ui';--interface ToastProps {- notification: ToastNotification;- onRemove: (id: string) => void;-}--const TOAST_ICONS = {- success: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />- </svg>- ),- error: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />- </svg>- ),- warning: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth={2}- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"- />- </svg>- ),- info: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth={2}- d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"- />- </svg>- ),-};--// Use the theme-aware `surface` token, not the fixed-white `neutral-0`: with-// `text-content` (near-white in dark mode) a hard-white background rendered as-// white-on-white in dark mode.-const TOAST_STYLES = {- success: 'bg-surface border-sage-500 text-content',- error: 'bg-surface border-coral-500 text-content',- warning: 'bg-surface border-amber-500 text-content',- info: 'bg-surface border-primary-500 text-content',-};--const TOAST_ICON_STYLES = {- success: 'text-sage-600',- error: 'text-coral-500',- warning: 'text-amber-600',- info: 'text-primary-500',-};--function Toast({ notification, onRemove }: ToastProps) {- const { t } = useT();- const [isVisible, setIsVisible] = useState(false);- const [isExiting, setIsExiting] = useState(false);-- const handleRemove = useCallback(() => {- setIsExiting(true);- setTimeout(() => {- onRemove(notification.id);- }, 200);- }, [onRemove, notification.id]);-- useEffect(() => {- // Animate in- const showTimer = setTimeout(() => setIsVisible(true), 50);-- // Auto remove after duration- const duration = notification.duration || 4000;- const removeTimer = setTimeout(() => {- handleRemove();- }, duration);-- return () => {- clearTimeout(showTimer);- clearTimeout(removeTimer);- };- }, [notification, handleRemove]);-- const icon = TOAST_ICONS[notification.type];- const styles = TOAST_STYLES[notification.type];- const iconStyle = TOAST_ICON_STYLES[notification.type];-- return (- <div- className={`- transform transition-all duration-200 ease-in-out- ${isVisible && !isExiting ? 'translate-x-0 opacity-100' : 'translate-x-full opacity-0'}- ${isExiting ? 'scale-95' : ''}- `}>- <div- className={`- flex items-center gap-3 p-4 rounded-lg shadow-large border-l-4 border backdrop-blur-sm- max-w-sm w-full- ${styles}- `}>- {/* Icon */}- <div className={`shrink-0 ${iconStyle}`}>{icon}</div>-- {/* Content */}- <div className="flex-1 min-w-0">- <h4 className="text-sm font-medium">{notification.title}</h4>- {notification.message && (- <p className="text-xs text-content-muted mt-1">{notification.message}</p>- )}- </div>-- {/* Action button */}- {notification.action && (- <Button- variant="tertiary"- size="xs"- onClick={notification.action.handler}- className="underline hover:no-underline shrink-0 px-0 h-auto">- {notification.action.label}- </Button>- )}-- {/* Close button */}- <Button- variant="tertiary"- size="xs"- iconOnly- aria-label={t('notifications.card.dismiss', 'Dismiss notification')}- onClick={handleRemove}- className="shrink-0 text-content-faint hover:text-content-secondary">- <CloseIcon className="w-4 h-4" />- </Button>- </div>- </div>- );-}+import { toast } from '../ui/Toast';interface ToastContainerProps {notifications: ToastNotification[];onRemove: (id: string) => void;}+/** Bridges legacy page toast state into the single app-wide toast manager. */export function ToastContainer({ notifications, onRemove }: ToastContainerProps) {- if (notifications.length === 0) return null;+ const dispatched = useRef(new Set<string>());++ useEffect(() => {+ for (const notification of notifications) {+ if (dispatched.current.has(notification.id)) continue;+ dispatched.current.add(notification.id);+ toast.add({+ type: notification.type,+ title: notification.title,+ description: notification.message,+ ...(notification.action+ ? {+ actionProps: {+ children: notification.action.label,+ onClick: notification.action.handler,+ },+ }+ : {}),+ });+ onRemove(notification.id);+ }+ }, [notifications, onRemove]);- return (- <div className="fixed top-4 right-4 z-50 space-y-2 pointer-events-none">- <div className="pointer-events-auto">- {notifications.map(notification => (- <Toast key={notification.id} notification={notification} onRemove={onRemove} />- ))}- </div>- </div>- );+ return null;}diff --git a/app/src/components/ui/Toast.tsx b/app/src/components/ui/Toast.tsxindex 05895ac413..72b631f89d 100644--- a/app/src/components/ui/Toast.tsx+++ b/app/src/components/ui/Toast.tsx@@ -25,7 +25,41 @@ export interface ToastData {icon?: ReactNode;}-export const toast = ToastPrimitive.createToastManager<ToastData>();+const toastManager = ToastPrimitive.createToastManager<ToastData>();++/** A privacy-conscious record of recent toast events for diagnostics. */+export interface ToastLogEntry {+ id: string;+ type?: string;+ title: string;+ description?: string;+ timestamp: number;+}++const TOAST_LOG_LIMIT = 100;+const toastLog: ToastLogEntry[] = [];++/** Returns a copy of the most recent toast events, newest first. */+export function getToastLog(): ToastLogEntry[] {+ return toastLog.map(entry => ({ ...entry }));+}++/** Clears the in-memory diagnostic history. */+export function clearToastLog(): void {+ toastLog.length = 0;+}++/** The global toast manager also records every emitted toast for diagnostics. */+export const toast = Object.assign({}, toastManager, {+ add(options: Parameters<typeof toastManager.add>[0]) {+ const id = toastManager.add(options);+ const title = typeof options.title === 'string' ? options.title : '';+ const description = typeof options.description === 'string' ? options.description : undefined;+ toastLog.unshift({ id, type: options.type, title, description, timestamp: Date.now() });+ if (toastLog.length > TOAST_LOG_LIMIT) toastLog.length = TOAST_LOG_LIMIT;+ return id;+ },+});type ToastType = 'success' | 'info' | 'warning' | 'error' | 'loading';