'use client' import * as React from 'react' import { Toaster as SonnerToaster, toast as sonnerToast } from 'sonner' import type { ExternalToast } from 'sonner' import { Chevron02DownIcon } from '../icons-v2-generated/arrows/chevron-02-down-icon' import { XmarkIcon } from '../icons-v2-generated/signs-and-symbols/xmark-icon' import { ToolIcon } from '../tool-icon' import type { ToolType } from '../../types/tool.types' import { cn } from '../../utils/cn' export type ToastVariant = 'default' | 'success' | 'warning' | 'error' | 'info' export const dotColorByVariant: Record = { default: 'bg-ods-text-secondary', success: 'bg-ods-success', warning: 'bg-ods-warning', error: 'bg-ods-error', info: 'bg-ods-text-secondary', } export const progressColorByVariant: Record = { default: 'bg-ods-text-secondary', success: 'bg-ods-success', warning: 'bg-ods-warning', error: 'bg-ods-error', info: 'bg-ods-text-secondary', } interface ToastHeaderProps { id: string | number variant: ToastVariant title?: React.ReactNode description?: React.ReactNode duration?: number dismissible?: boolean className?: string showProgress?: boolean } function ToastHeader({ id, variant, title, description, duration = 4000, dismissible = true, className, showProgress = true, }: ToastHeaderProps) { return (
{title ? (

{title}

) : null} {description ? (

{description}

) : null}
{dismissible ? ( ) : null} {showProgress && duration !== Infinity && duration > 0 ? (
) : null}
) } export interface ToastCardProps { id: string | number variant?: ToastVariant title?: React.ReactNode description?: React.ReactNode duration?: number dismissible?: boolean className?: string } export function ToastCard({ id, variant = 'default', title, description, duration = 4000, dismissible = true, className, }: ToastCardProps) { return (
) } export interface CommandApprovalToastProps { id: string | number variant?: ToastVariant title?: React.ReactNode description?: React.ReactNode command: string toolType?: ToolType approvalDescription?: React.ReactNode approveLabel?: string rejectLabel?: string onApprove?: () => void onReject?: () => void duration?: number dismissible?: boolean defaultExpanded?: boolean className?: string } export function CommandApprovalToast({ id, variant = 'warning', title = 'Tech Required', description = 'Approval is required to execute the command.', command, toolType, approvalDescription, approveLabel = 'Approve', rejectLabel = 'Reject', onApprove, onReject, duration = Infinity, dismissible = true, defaultExpanded = false, className, }: CommandApprovalToastProps) { const [expanded, setExpanded] = React.useState(defaultExpanded) const handleApprove = () => { onApprove?.() sonnerToast.dismiss(id) } const handleReject = () => { onReject?.() sonnerToast.dismiss(id) } return (

{command}

{toolType ? : null}
{approvalDescription ? (

{approvalDescription}

) : null}
{expanded ? null : ( )}
) } export type ToasterProps = React.ComponentProps export function Toaster({ position = 'bottom-right', offset = 24, gap = 8, toastOptions, ...rest }: ToasterProps = {}) { const { classNames: userClassNames, ...restToastOptions } = toastOptions ?? {} return ( <> ) } export interface ShowToastOptions extends Omit { title?: React.ReactNode description?: React.ReactNode variant?: ToastVariant } export function showToast(options: ShowToastOptions | string) { const opts: ShowToastOptions = typeof options === 'string' ? { title: options } : options const { title, description, variant = 'default', duration = 4000, dismissible = true, ...rest } = opts return sonnerToast.custom( (id) => ( ), { duration, dismissible, ...rest }, ) } export interface ShowCommandApprovalToastOptions extends Omit, Omit {} export function showCommandApprovalToast(options: ShowCommandApprovalToastOptions) { const { variant, title, description, command, toolType, approvalDescription, approveLabel, rejectLabel, onApprove, onReject, defaultExpanded, duration = Infinity, dismissible = true, ...rest } = options return sonnerToast.custom( (id) => ( ), { duration, dismissible, ...rest }, ) }