import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts"; import { limitsNotice } from "@t3tools/shared/usageLimits"; import { GaugeIcon } from "lucide-react"; import { getDriverOption } from "../settings/providerDriverMeta"; import { RedactedSensitiveText } from "../settings/RedactedSensitiveText"; import { LimitWindows, ResetCredits } from "../usage/UsageLimits"; import { ComposerBanner } from "./ComposerBanner"; import type { ComposerBannerStackItem } from "./ComposerBannerStack"; /** Driver name, then the instance when there could be more than one of that driver. */ function accountLabel(account: UsageLimitsReport["accounts"][number]): string { if (!account.instanceId) return account.label; const driver = getDriverOption(account.driver)?.label ?? String(account.driver); const instance = account.displayName?.trim() || (String(account.instanceId) !== String(account.driver) ? account.instanceId : ""); // The default instance is often named after its driver; saying it twice adds nothing. return instance && instance.toLowerCase() !== driver.toLowerCase() ? `${driver} · ${instance}` : driver; } function AccountSummary({ account }: { readonly account: UsageLimitsReport["accounts"][number] }) { const label = accountLabel(account); return ( <> {label.includes("@") ? ( ) : ( label )} {account.plan ? ` · ${account.plan}` : null} ); } /** The /usage-limits result as a composer notice: it stacks under warnings and dismisses like one. */ export function usageLimitsBannerItem( id: string, report: UsageLimitsReport, environmentId: EnvironmentId, onDismiss: () => void, ): ComposerBannerStackItem { const [first] = report.accounts; const single = report.accounts.length === 1 && first ? first : null; const summary = single ? ( ) : ( `${report.accounts.length} accounts` ); return { id, variant: "info", priority: "notice", icon: , title: "Usage limits", description: summary, dismissLabel: "Dismiss usage limits", onDismiss, children: , }; } function UsageLimitsBannerBody({ report, environmentId, }: { readonly report: UsageLimitsReport; readonly environmentId: EnvironmentId; }) { const now = Date.parse(report.createdAt); return ( {report.accounts.map((account) => { const resetCreditInput = account.resetCreditInput ?? (account.instanceId ? { instanceId: account.instanceId } : undefined); const notice = limitsNotice(account.limits); return (
{report.accounts.length > 1 ? ( ) : null} {notice ? ( {notice} ) : ( )} {resetCreditInput && account.limits.resetCredits ? ( ) : null}
); })} {report.notices.map((notice) => ( {notice} ))}
); }