fix(webui): show provider logos in model notices
This commit is contained in:
1 parent
448767d147
commit
8473538e7a
4 files changed
+48
-6
No files matched your search
@@ -1,11 +1,13 @@
|
|||||||
import { ArrowRightLeft, KeyRound, X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { PresetProviderIcon } from "@/components/thread/ModelPresetBadge";
|
||||||
|
|
||||||
/** A live fallback is informative, not a failed message or a changed preset. */
|
/** A live fallback is informative, not a failed message or a changed preset. */
|
||||||
export function ModelFallbackNotice({ model, reauthProviderLabel, onDismiss, onOpenSettings }: {
|
export function ModelFallbackNotice({ model, reauthProvider, reauthProviderLabel, onDismiss, onOpenSettings }: {
|
||||||
model: string;
|
model: string;
|
||||||
|
reauthProvider?: string;
|
||||||
reauthProviderLabel?: string;
|
reauthProviderLabel?: string;
|
||||||
onDismiss: () => void;
|
onDismiss: () => void;
|
||||||
onOpenSettings?: () => void;
|
onOpenSettings?: () => void;
|
||||||
@@ -16,9 +18,12 @@ export function ModelFallbackNotice({ model, reauthProviderLabel, onDismiss, onO
|
|||||||
role="status"
|
role="status"
|
||||||
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-start gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-start gap-2 rounded-control border border-border/60 bg-muted/40 px-3 py-2 text-xs text-foreground/80 animate-in fade-in-0 slide-in-from-bottom-1 motion-reduce:animate-none"
|
||||||
>
|
>
|
||||||
{reauthProviderLabel
|
<PresetProviderIcon
|
||||||
? <KeyRound className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
|
provider={reauthProvider}
|
||||||
: <ArrowRightLeft className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />}
|
label={reauthProviderLabel || model}
|
||||||
|
testId="model-fallback-notice-logo"
|
||||||
|
isHero={false}
|
||||||
|
/>
|
||||||
<div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-3 gap-y-1 leading-5">
|
<div className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-3 gap-y-1 leading-5">
|
||||||
<span className="min-w-0 break-words [overflow-wrap:anywhere]">
|
<span className="min-w-0 break-words [overflow-wrap:anywhere]">
|
||||||
{reauthProviderLabel ? <>
|
{reauthProviderLabel ? <>
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ function SetupPromptLabel({ label }: { label: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function PresetProviderIcon({
|
export function PresetProviderIcon({
|
||||||
label,
|
label,
|
||||||
modelDetail,
|
modelDetail,
|
||||||
provider,
|
provider,
|
||||||
|
|||||||
@@ -1559,6 +1559,7 @@ export function ThreadShell({
|
|||||||
{modelFallback?.chatId === chatId && !modelFallback.dismissed ? (
|
{modelFallback?.chatId === chatId && !modelFallback.dismissed ? (
|
||||||
<ModelFallbackNotice
|
<ModelFallbackNotice
|
||||||
model={modelFallback.model}
|
model={modelFallback.model}
|
||||||
|
reauthProvider={modelFallback.reauthProvider}
|
||||||
reauthProviderLabel={modelFallback.reauthProvider
|
reauthProviderLabel={modelFallback.reauthProvider
|
||||||
? providerDisplayLabel(settings?.providers ?? [], modelFallback.reauthProvider)
|
? providerDisplayLabel(settings?.providers ?? [], modelFallback.reauthProvider)
|
||||||
: undefined}
|
: undefined}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { ModelFallbackNotice } from "@/components/thread/ModelFallbackNotice";
|
||||||
|
import { __clearLogoFallbackCacheForTests } from "@/hooks/useLogoFallback";
|
||||||
|
import { providerBrand } from "@/lib/provider-brand";
|
||||||
|
|
||||||
|
describe("model fallback notice logos", () => {
|
||||||
|
beforeEach(__clearLogoFallbackCacheForTests);
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
it.each(["openai_codex", "xai_grok", "github_copilot"])("shows the rejected %s provider, not the backup", (provider) => {
|
||||||
|
render(<ModelFallbackNotice model="deepseek/deepseek-chat" reauthProvider={provider}
|
||||||
|
reauthProviderLabel={provider} onDismiss={vi.fn()} />);
|
||||||
|
const tile = screen.getByTestId("model-fallback-notice-logo");
|
||||||
|
const image = tile.querySelector("img")!;
|
||||||
|
expect(image).toHaveAttribute("src", providerBrand(provider)!.logoUrl);
|
||||||
|
expect(image).toHaveAttribute("alt", "");
|
||||||
|
expect(tile).toHaveAttribute("aria-hidden", "true");
|
||||||
|
expect(tile).toHaveClass("h-[18px]", "w-[18px]");
|
||||||
|
fireEvent.load(image);
|
||||||
|
expect(tile).toHaveClass("bg-white");
|
||||||
|
for (const url of providerBrand(provider)!.logoUrls) {
|
||||||
|
expect(tile.querySelector("img")).toHaveAttribute("src", url);
|
||||||
|
fireEvent.error(tile.querySelector("img")!);
|
||||||
|
}
|
||||||
|
expect(tile.querySelector("img")).toBeNull();
|
||||||
|
expect(tile).toHaveTextContent(providerBrand(provider)!.initials.slice(0, 2));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the fallback model's brand for a generic notice", () => {
|
||||||
|
render(<ModelFallbackNotice model="xai-grok/grok-4.5" onDismiss={vi.fn()} />);
|
||||||
|
expect(screen.getByTestId("model-fallback-notice-logo").querySelector("img"))
|
||||||
|
.toHaveAttribute("src", providerBrand("xai_grok")!.logoUrl);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user