import { type ProviderApprovalDecision, type ProviderApprovalOption, type RuntimeRequestId, } from "@t3tools/contracts"; import { memo } from "react"; import { EllipsisIcon, TriangleAlertIcon } from "lucide-react"; import { Button, InlineButton } from "../ui/button"; import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { composerFloatingLayerProps } from "./composerEventScope"; interface ComposerPendingApprovalActionsProps { presentation?: "buttons" | "inline"; requestId: RuntimeRequestId; isResponding: boolean; canRespond: boolean; disabled?: boolean; options?: ReadonlyArray | undefined; onRespondToApproval: ( requestId: RuntimeRequestId, decision: ProviderApprovalDecision, ) => Promise; } const DEFAULT_APPROVAL_OPTIONS = [ { decision: "cancel", label: "Cancel" }, { decision: "decline", label: "Decline" }, { decision: "acceptForSession", label: "Always allow this session" }, { decision: "accept", label: "Approve" }, ] satisfies ReadonlyArray; export const ComposerPendingApprovalActions = memo(function ComposerPendingApprovalActions({ presentation = "buttons", requestId, isResponding, canRespond, disabled = false, options = DEFAULT_APPROVAL_OPTIONS, onRespondToApproval, }: ComposerPendingApprovalActionsProps) { const primaryOptions = options.filter( (option) => option.decision === "decline" || option.decision === "accept", ); const moreOptions = options.filter( (option) => option.decision !== "decline" && option.decision !== "accept", ); const moreMenu = moreOptions.length > 0 ? ( ) : ( ) : null; return ( <> {presentation === "buttons" ? moreMenu : null} {primaryOptions.map((option) => { const buttonProps = { disabled: disabled || isResponding || !canRespond, "aria-description": option.warning, onClick: () => { if (!disabled && !isResponding && canRespond) { void onRespondToApproval(requestId, option.decision); } }, }; const content = ( <> {option.warning ? : null} {option.label} ); const button = presentation === "inline" ? ( {content} ) : ( ); return option.warning ? ( {option.warning} ) : ( button ); })} {presentation === "inline" ? moreMenu : null} ); });