Files
t3code/apps/web/src/components/chat/ThreadErrorBanner.tsx
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

89 lines
3.3 KiB
TypeScript

import type { OrchestrationV2ProviderFailureClass } from "@t3tools/contracts";
import { memo } from "react";
import { Alert, AlertAction, AlertDescription } from "../ui/alert";
import { Button } from "../ui/button";
import { CircleAlertIcon, XIcon } from "lucide-react";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { OpenAI } from "../Icons";
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
export function getThreadErrorBannerKey(threadKey: string, error: string | null): string | null {
return error === null ? null : `${threadKey}\u0000${error}`;
}
export function shouldShowThreadErrorBanner(
threadKey: string,
error: string | null,
isDismissed: boolean,
): boolean {
return getThreadErrorBannerKey(threadKey, error) !== null && !isDismissed;
}
// Session-scoped (module-level so it survives ChatView remounts, e.g. route
// changes between threads). Mirrors the branch-mismatch banner: a dismissal
// is remembered per thread key plus message, so navigating away to a thread
// with no error cannot resurrect the banner, while a different error message
// on the same thread still appears.
const sessionDismissedThreadErrorBannerKeys = new Set<string>();
export function dismissThreadErrorBannerForSession(bannerKey: string | null): void {
if (bannerKey !== null) {
sessionDismissedThreadErrorBannerKeys.add(bannerKey);
}
}
export function isThreadErrorBannerDismissedForSession(bannerKey: string | null): boolean {
return bannerKey !== null && sessionDismissedThreadErrorBannerKeys.has(bannerKey);
}
export const ThreadErrorBanner = memo(function ThreadErrorBanner({
error,
onDismiss,
errorClass,
chatGptUsageLimit = false,
}: {
error: string | null;
errorClass?: OrchestrationV2ProviderFailureClass | null;
onDismiss?: () => void;
chatGptUsageLimit?: boolean;
}) {
if (!error) return null;
const variant = errorClass === "usage_limit" ? "warning" : "error";
return (
<div className="pointer-events-auto mx-auto w-fit max-w-[min(48rem,calc(100%-2rem))] pt-3">
<Alert variant={variant} surface="glass" controlAlignment="first-line" data-variant={variant}>
{chatGptUsageLimit ? (
<OpenAI className="size-4 text-foreground!" aria-hidden="true" />
) : (
<CircleAlertIcon />
)}
<AlertDescription>
{chatGptUsageLimit ? (
<div className="space-y-1">
<p className="font-medium">ChatGPT usage limit reached</p>
<p>Review your usage settings in ChatGPT to continue.</p>
</div>
) : (
<Tooltip>
<TooltipTrigger render={<div className="line-clamp-3" />}>{error}</TooltipTrigger>
<TooltipPopup side="top" className="whitespace-pre-wrap">
{error}
</TooltipPopup>
</Tooltip>
)}
</AlertDescription>
{(chatGptUsageLimit || onDismiss) && (
<AlertAction>
{chatGptUsageLimit ? <ChatGptUsageButton variant="default" size="sm" /> : null}
{onDismiss ? (
<Button variant="ghost" size="icon-xs" aria-label="Dismiss error" onClick={onDismiss}>
<XIcon />
</Button>
) : null}
</AlertAction>
)}
</Alert>
</div>
);
});