fix(webui): keep model management available and bundle core provider logos
This commit is contained in:
1 parent
4fd4dc522d
commit
0cac850737
14 files changed
+207
-37
No files matched your search
@@ -0,0 +1,25 @@
|
||||
Bundled provider icons: deepseek-color.svg, anthropic.svg, openai.svg, gemini-color.svg.
|
||||
Source: https://github.com/lobehub/lobe-icons/tree/79b551cf26aab9ea4ac701fb807160950a5b860f/packages/static-svg/icons
|
||||
Unmodified SVG assets. Brand marks belong to their respective owners.
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 LobeHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Anthropic</title><path d="M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"></path></svg>
|
||||
|
After Width: | Height: | Size: 369 B |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>DeepSeek</title><path d="M23.748 4.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434 1.202-.422 1.84.027 1.436.633 2.58 1.838 3.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526 5.526 0 01-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365 11.365 0 00-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055 3.055 0 01-.465.137 9.597 9.597 0 00-2.883-.102c-1.885.21-3.39 1.102-4.497 2.623C.082 8.606-.231 10.684.152 12.85c.403 2.284 1.569 4.175 3.36 5.653 1.858 1.533 3.997 2.284 6.438 2.14 1.482-.085 3.133-.284 4.994-1.86.47.234.962.327 1.78.397.63.059 1.236-.03 1.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926 1.096-1.296 2.746-2.642 3.392-7.003.05-.347.007-.565 0-.845-.004-.17.035-.237.23-.256a4.173 4.173 0 001.545-.475c1.396-.763 1.96-2.015 2.093-3.517.02-.23-.004-.467-.247-.588zM11.581 18c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696 4.696 0 011.529-.039c2.132.312 3.946 1.265 5.468 2.774.868.86 1.525 1.887 2.202 2.891.72 1.066 1.494 2.082 2.48 2.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306 0 01.415-.287.302.302 0 01.2.288.306.306 0 01-.31.307.303.303 0 01-.304-.308zm3.11 1.596c-.2.081-.399.151-.59.16a1.245 1.245 0 01-.798-.254c-.274-.23-.47-.358-.552-.758a1.73 1.73 0 01.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559 0 01-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136 1.146.016.352.144.618.408 1.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z" fill="#4D6BFE"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Gemini</title><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="#3186FF"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-0-_R_0_)"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-1-_R_0_)"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-2-_R_0_)"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-0-_R_0_" x1="7" x2="11" y1="15.5" y2="12"><stop stop-color="#08B962"></stop><stop offset="1" stop-color="#08B962" stop-opacity="0"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-1-_R_0_" x1="8" x2="11.5" y1="5.5" y2="11"><stop stop-color="#F94543"></stop><stop offset="1" stop-color="#F94543" stop-opacity="0"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-2-_R_0_" x1="3.5" x2="17.5" y1="13.5" y2="12"><stop stop-color="#FABC12"></stop><stop offset=".46" stop-color="#FABC12" stop-opacity="0"></stop></linearGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>OpenAI</title><path d="M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -442,6 +442,15 @@ function OverviewValueLogo({
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"col-start-1 row-start-1 grid h-full w-full place-items-center rounded-md text-[7.5px] font-semibold text-white",
|
||||
logoLoaded ? "opacity-0" : "opacity-100",
|
||||
)}
|
||||
style={{ backgroundColor: brand.color }}
|
||||
>
|
||||
{brand.initials}
|
||||
</span>
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
@@ -450,7 +459,7 @@ function OverviewValueLogo({
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"object-contain",
|
||||
"col-start-1 row-start-1 object-contain",
|
||||
isLogoTile ? "h-5 w-5" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
|
||||
@@ -600,6 +600,15 @@ export function ProviderPickerIcon({
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"col-start-1 row-start-1 grid h-full w-full place-items-center rounded-md text-[7.5px] font-semibold text-white",
|
||||
logoLoaded ? "opacity-0" : "opacity-100",
|
||||
)}
|
||||
style={{ backgroundColor: brand?.color }}
|
||||
>
|
||||
{brand?.initials}
|
||||
</span>
|
||||
<img
|
||||
src={logoUrl}
|
||||
alt=""
|
||||
@@ -608,7 +617,7 @@ export function ProviderPickerIcon({
|
||||
referrerPolicy="no-referrer"
|
||||
draggable={false}
|
||||
className={cn(
|
||||
"object-contain",
|
||||
"col-start-1 row-start-1 object-contain",
|
||||
isLogoTile ? "h-5 w-5" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
|
||||
@@ -138,6 +138,8 @@ export function ModelPresetBadge({
|
||||
: modelPresets.map((preset, index) => index === listedIndex ? activePreset : preset);
|
||||
const opensSetup = Boolean(onClick);
|
||||
const canSwitch = !opensSetup && Boolean(onPresetChange) && activeName !== "" && presets.length > 1;
|
||||
const canOpenPicker = !opensSetup && (canSwitch || Boolean(onManageModels));
|
||||
const pickerPresets = activeName && onPresetChange ? presets : [activePreset];
|
||||
const currentIndex = Math.max(0, presets.findIndex((preset) => preset.name === activeName));
|
||||
const pillHeight = isHero ? 32 : 36;
|
||||
const pillStride = pillHeight + PILL_GAP_PX;
|
||||
@@ -250,6 +252,7 @@ export function ModelPresetBadge({
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
|
||||
if (!canSwitch) return;
|
||||
const targetByKey: Record<string, number> = {
|
||||
ArrowUp: currentIndex - 1,
|
||||
ArrowDown: currentIndex + 1,
|
||||
@@ -276,7 +279,7 @@ export function ModelPresetBadge({
|
||||
);
|
||||
|
||||
const Container = opensSetup ? "button" : "span";
|
||||
const badge = !canSwitch ? (
|
||||
const badge = !canOpenPicker ? (
|
||||
<TooltipTrigger asChild>
|
||||
<Container
|
||||
aria-label={label}
|
||||
@@ -334,7 +337,7 @@ export function ModelPresetBadge({
|
||||
className={cn(
|
||||
"thread-composer-model-badge group relative inline-flex w-fit min-w-0 max-w-[min(18rem,44vw)] cursor-pointer appearance-none border-0 bg-transparent p-0 shadow-none focus-visible:outline-none",
|
||||
motion && "z-10 cursor-grabbing",
|
||||
!motion && "cursor-grab",
|
||||
canSwitch && !motion && "cursor-grab",
|
||||
isHero ? "h-8" : "h-9",
|
||||
)}
|
||||
>
|
||||
@@ -388,6 +391,7 @@ export function ModelPresetBadge({
|
||||
align="end"
|
||||
side="top"
|
||||
sideOffset={10}
|
||||
collisionPadding={12}
|
||||
role="dialog"
|
||||
aria-label={switchModelLabel}
|
||||
onOpenAutoFocus={(event) => {
|
||||
@@ -407,12 +411,24 @@ export function ModelPresetBadge({
|
||||
<div
|
||||
role="listbox"
|
||||
aria-label={switchModelLabel}
|
||||
onKeyDown={(event) => {
|
||||
const options = Array.from(event.currentTarget.querySelectorAll<HTMLButtonElement>('[role="option"]'));
|
||||
const index = options.indexOf(document.activeElement as HTMLButtonElement);
|
||||
const targets: Record<string, number> = {
|
||||
ArrowUp: index - 1, ArrowDown: index + 1, Home: 0, End: options.length - 1,
|
||||
};
|
||||
const target = targets[event.key];
|
||||
if (target === undefined || options.length === 0) return;
|
||||
event.preventDefault();
|
||||
options[wrapIndex(target, options.length)].focus();
|
||||
}}
|
||||
className="max-h-[min(16rem,var(--radix-popover-content-available-height))] overflow-y-auto py-1 scrollbar-thin scrollbar-track-transparent"
|
||||
>
|
||||
{presets.map((preset) => (
|
||||
{pickerPresets.map((preset) => (
|
||||
<PresetOption
|
||||
key={preset.name}
|
||||
preset={preset}
|
||||
label={preset.name || label}
|
||||
selected={preset.name === activeName}
|
||||
onSelect={selectPreset}
|
||||
/>
|
||||
@@ -450,10 +466,12 @@ export function ModelPresetBadge({
|
||||
|
||||
function PresetOption({
|
||||
preset,
|
||||
label,
|
||||
selected,
|
||||
onSelect,
|
||||
}: {
|
||||
preset: ModelPresetOption;
|
||||
label: string;
|
||||
selected: boolean;
|
||||
onSelect: (name: string) => void;
|
||||
}) {
|
||||
@@ -462,7 +480,7 @@ function PresetOption({
|
||||
<button
|
||||
type="button"
|
||||
role="option"
|
||||
aria-label={preset.name}
|
||||
aria-label={label}
|
||||
aria-selected={selected}
|
||||
onClick={() => onSelect(preset.name)}
|
||||
className={cn(
|
||||
@@ -473,14 +491,14 @@ function PresetOption({
|
||||
)}
|
||||
>
|
||||
<PresetProviderIcon
|
||||
label={preset.name}
|
||||
label={label}
|
||||
modelDetail={detail}
|
||||
provider={preset.provider}
|
||||
isHero={false}
|
||||
/>
|
||||
<span className="flex min-w-0 flex-1 items-baseline gap-1.5 overflow-hidden whitespace-nowrap max-sm:flex-col max-sm:items-start max-sm:gap-0.5 max-sm:whitespace-normal">
|
||||
<span className="shrink-0 text-[13px] font-medium text-foreground max-sm:max-w-full max-sm:break-words">{preset.name}</span>
|
||||
{detail && detail !== preset.name ? (
|
||||
<span className="shrink-0 text-[13px] font-medium text-foreground max-sm:max-w-full max-sm:break-words">{label}</span>
|
||||
{detail && detail !== label ? (
|
||||
<span className="truncate text-[12px] text-muted-foreground">{detail}</span>
|
||||
) : null}
|
||||
</span>
|
||||
@@ -611,6 +629,16 @@ export function PresetProviderIcon({
|
||||
)}
|
||||
aria-hidden
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"col-start-1 row-start-1 grid h-full w-full place-items-center rounded-[5px] text-white",
|
||||
isHero ? "text-[7.5px]" : "text-[8px]",
|
||||
logoLoaded ? "opacity-0" : "opacity-100",
|
||||
)}
|
||||
style={brand ? { backgroundColor: brand.color } : undefined}
|
||||
>
|
||||
{brand ? brand.initials.slice(0, 2) : <Sparkles className="h-3 w-3 text-muted-foreground/65" />}
|
||||
</span>
|
||||
{logoUrl ? (
|
||||
<img
|
||||
src={logoUrl}
|
||||
@@ -620,26 +648,14 @@ export function PresetProviderIcon({
|
||||
loading="lazy"
|
||||
referrerPolicy="no-referrer"
|
||||
className={cn(
|
||||
"object-contain",
|
||||
"col-start-1 row-start-1 object-contain",
|
||||
isLogoTile ? "h-full w-full" : "h-3.5 w-3.5",
|
||||
logoLoaded ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
onLoad={onLogoLoad}
|
||||
onError={onLogoError}
|
||||
/>
|
||||
) : brand ? (
|
||||
<span
|
||||
className={cn(
|
||||
"grid h-full w-full place-items-center rounded-full text-white",
|
||||
isHero ? "text-[7.5px]" : "text-[8px]",
|
||||
)}
|
||||
style={{ backgroundColor: brand.color }}
|
||||
>
|
||||
{brand.initials.slice(0, 2)}
|
||||
</span>
|
||||
) : (
|
||||
<Sparkles className="h-3 w-3 text-muted-foreground/65" />
|
||||
)}
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -47,33 +47,29 @@ export function useLogoFallback(urls: readonly string[] | undefined) {
|
||||
const safeUrls = useMemo(() => logoUrlsFromKey(cacheKey), [cacheKey]);
|
||||
const [logoIndex, setLogoIndex] = useState(() => firstUsableLogoIndex(safeUrls));
|
||||
const logoUrl = logoIndex >= 0 ? safeUrls[logoIndex] : undefined;
|
||||
const [logoLoaded, setLogoLoaded] = useState(
|
||||
() => Boolean(logoUrl && loadedLogoUrls.has(logoUrl)),
|
||||
);
|
||||
const [loadedUrl, setLoadedUrl] = useState<string>();
|
||||
const logoLoaded = Boolean(logoUrl && (loadedUrl === logoUrl || loadedLogoUrls.has(logoUrl)));
|
||||
|
||||
useEffect(() => {
|
||||
setLogoIndex(firstUsableLogoIndex(safeUrls));
|
||||
}, [cacheKey, safeUrls]);
|
||||
|
||||
useEffect(() => {
|
||||
setLogoLoaded(Boolean(logoUrl && loadedLogoUrls.has(logoUrl)));
|
||||
}, [logoUrl]);
|
||||
|
||||
const onLogoLoad = useCallback(() => {
|
||||
if (!logoUrl || logoIndex < 0) return;
|
||||
loadedLogoUrls.add(logoUrl);
|
||||
failedLogoUrls.delete(logoUrl);
|
||||
resolvedLogoIndexByKey.set(cacheKey, logoIndex);
|
||||
setLogoLoaded(true);
|
||||
setLoadedUrl(logoUrl);
|
||||
}, [cacheKey, logoIndex, logoUrl]);
|
||||
|
||||
const onLogoError = useCallback(() => {
|
||||
if (!logoUrl || logoIndex < 0) return;
|
||||
failedLogoUrls.add(logoUrl);
|
||||
loadedLogoUrls.delete(logoUrl);
|
||||
if (resolvedLogoIndexByKey.get(cacheKey) === logoIndex) {
|
||||
resolvedLogoIndexByKey.delete(cacheKey);
|
||||
}
|
||||
setLogoLoaded(false);
|
||||
setLoadedUrl(undefined);
|
||||
setLogoIndex(nextLogoIndex(safeUrls, logoIndex));
|
||||
}, [cacheKey, logoIndex, logoUrl, safeUrls]);
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import anthropicLogo from "@/assets/providers/anthropic.svg";
|
||||
import deepseekLogo from "@/assets/providers/deepseek-color.svg";
|
||||
import geminiLogo from "@/assets/providers/gemini-color.svg";
|
||||
import openaiLogo from "@/assets/providers/openai.svg";
|
||||
|
||||
export interface ProviderBrand {
|
||||
logoUrl: string;
|
||||
logoUrls: string[];
|
||||
@@ -155,7 +160,7 @@ const PROVIDER_LABEL_ALIASES: Record<string, string> = {
|
||||
const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
aihubmix: { ...brand("aihubmix.com", "#111827", "AH"), logoLayout: "tile" },
|
||||
ant_ling: brand("ant-ling.com", "#7C3AED", "AL"),
|
||||
anthropic: brand("anthropic.com", "#D97757", "A"),
|
||||
anthropic: brand("anthropic.com", "#D97757", "A", [anthropicLogo]),
|
||||
assemblyai: brand("assemblyai.com", "#111827", "AA"),
|
||||
atomic_chat: brand("atomic.chat", "#111827", "AC"),
|
||||
azure_openai: brand("azure.microsoft.com", "#0078D4", "AZ"),
|
||||
@@ -164,13 +169,13 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
brave: brand("brave.com", "#FB542B", "B"),
|
||||
byteplus: brand("byteplus.com", "#325CFF", "BP"),
|
||||
dashscope: brand("dashscope.aliyun.com", "#FF6A00", "DS"),
|
||||
deepseek: brand("deepseek.com", "#4D6BFE", "DS"),
|
||||
deepseek: brand("deepseek.com", "#4D6BFE", "DS", [deepseekLogo]),
|
||||
duckduckgo: brand("duckduckgo.com", "#DE5833", "DDG"),
|
||||
edenai: brand("edenai.co", "#080F35", "EA", [
|
||||
"https://cdn.prod.website-files.com/61e7d259b7746e2d1df0b68d/6a63231f5c459827c2d18d7a_eden%20ai%20logo%20light.png",
|
||||
]),
|
||||
exa: { ...brand("exa.ai", "#5B5BF6", "E"), logoLayout: "tile" },
|
||||
gemini: brand("gemini.google.com", "#4285F4", "G"),
|
||||
gemini: brand("gemini.google.com", "#4285F4", "G", [geminiLogo]),
|
||||
github_copilot: brand("github.com", "#24292F", "GH", [
|
||||
"https://raw.githubusercontent.com/primer/octicons/main/icons/copilot-24.svg",
|
||||
]),
|
||||
@@ -202,7 +207,7 @@ const PROVIDER_BRANDS: Record<string, ProviderBrand> = {
|
||||
olostep: { ...brand("olostep.com", "#111827", "O"), logoLayout: "tile" },
|
||||
nvidia: brand("nvidia.com", "#76B900", "NV"),
|
||||
ollama: brand("ollama.com", "#111827", "O"),
|
||||
openai: brand("openai.com", "#111827", "AI"),
|
||||
openai: brand("openai.com", "#111827", "AI", [openaiLogo]),
|
||||
opencode: brand("opencode.ai", "#111827", "OC", [
|
||||
"https://opencode.ai/favicon-96x96-v3.png",
|
||||
]),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -62,6 +62,82 @@ describe("ModelPresetBadge setup tooltip", () => {
|
||||
});
|
||||
|
||||
describe("ModelPresetBadge selected preset tooltip", () => {
|
||||
it.each([true, false])("keeps the single-preset menu and management reachable (hero: %s)", async (isHero) => {
|
||||
const user = userEvent.setup();
|
||||
const onPresetChange = vi.fn();
|
||||
const onManageModels = vi.fn();
|
||||
render(
|
||||
<ModelPresetBadge
|
||||
label="deepseek-flash"
|
||||
modelPreset="deepseek-flash"
|
||||
modelDetail="deepseek/deepseek-v4-flash"
|
||||
modelPresets={[{ name: "deepseek-flash", provider: "deepseek" }]}
|
||||
onPresetChange={onPresetChange}
|
||||
onManageModels={onManageModels}
|
||||
isHero={isHero}
|
||||
/>,
|
||||
);
|
||||
const trigger = screen.getByRole("button", { name: "deepseek-flash" });
|
||||
expect(trigger).not.toHaveClass("cursor-grab");
|
||||
await user.tab();
|
||||
expect(trigger).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
const selected = await screen.findByRole("option", { name: "deepseek-flash" });
|
||||
expect(selected).toHaveAttribute("aria-selected", "true");
|
||||
expect(selected).toHaveFocus();
|
||||
expect(screen.getAllByRole("option")).toHaveLength(1);
|
||||
await user.click(selected);
|
||||
expect(onPresetChange).not.toHaveBeenCalled();
|
||||
await user.click(trigger);
|
||||
await user.tab();
|
||||
expect(screen.getByRole("button", { name: "Manage models" })).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(onManageModels).toHaveBeenCalledTimes(1);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not start drag switching with only one preset", () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
render(<ModelPresetBadge label="only" modelPreset="only" onPresetChange={vi.fn()} onManageModels={vi.fn()} isHero />);
|
||||
const trigger = screen.getByRole("button", { name: "only" });
|
||||
fireEvent.pointerDown(trigger, { pointerId: 1, pointerType: "touch", clientY: 100 });
|
||||
act(() => vi.advanceTimersByTime(500));
|
||||
expect(screen.queryByTestId("composer-model-pill-viewport")).not.toBeInTheDocument();
|
||||
fireEvent.pointerUp(trigger, { pointerId: 1, pointerType: "touch", clientY: 100 });
|
||||
fireEvent.click(trigger);
|
||||
expect(screen.getByRole("button", { name: "Manage models" })).toBeInTheDocument();
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("offers management for an implicit default without inventing a named preset", async () => {
|
||||
const onPresetChange = vi.fn();
|
||||
const onManageModels = vi.fn();
|
||||
render(<ModelPresetBadge label="deepseek-chat" provider="deepseek" onPresetChange={onPresetChange} onManageModels={onManageModels} isHero />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "deepseek-chat" }));
|
||||
const current = screen.getByRole("option", { name: "deepseek-chat" });
|
||||
expect(current).toHaveAttribute("aria-selected", "true");
|
||||
fireEvent.click(current);
|
||||
expect(onPresetChange).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "deepseek-chat" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Manage models" }));
|
||||
expect(onManageModels).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("moves focus within an open picker without changing the model until selection", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onPresetChange = vi.fn();
|
||||
render(<ModelPresetBadge label="zhipu" modelPreset="zhipu" modelPresets={presets} onPresetChange={onPresetChange} isHero />);
|
||||
await user.click(screen.getByRole("button", { name: "zhipu" }));
|
||||
await user.keyboard("{ArrowDown}");
|
||||
expect(screen.getByRole("option", { name: "codex" })).toHaveFocus();
|
||||
expect(onPresetChange).not.toHaveBeenCalled();
|
||||
await user.keyboard("{Enter}");
|
||||
expect(onPresetChange).toHaveBeenCalledWith("codex");
|
||||
});
|
||||
|
||||
it("shows the selected preset on hover and preserves the preset picker", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onPresetChange = vi.fn();
|
||||
|
||||
@@ -9,6 +9,11 @@ import {
|
||||
} from "@/lib/provider-brand";
|
||||
|
||||
describe("provider brand logos", () => {
|
||||
it.each(["deepseek", "anthropic", "openai", "openai_codex", "gemini"])("bundles %s's primary logo without an external request", (provider) => {
|
||||
expect(providerBrand(provider)?.logoUrl).toMatch(/^\/src\/assets\/providers\/.*\.svg$/);
|
||||
expect(providerBrand(provider)?.logoUrl).toBe(providerBrand(provider)?.logoUrls[0]);
|
||||
});
|
||||
|
||||
it("covers Eden AI, OpenCode variants, and Kimi Coding with their official assets", () => {
|
||||
expect(providerBrand("edenai")?.logoUrl).toContain("cdn.prod.website-files.com/");
|
||||
expect(providerBrand("opencode")?.logoUrl).toBe("https://opencode.ai/favicon-96x96-v3.png");
|
||||
|
||||
@@ -39,9 +39,13 @@ describe.each(["picker", "overview", "composer", "hero"] as const)("%s provider
|
||||
expectFrame(icon);
|
||||
expect(icon).toHaveClass("bg-muted");
|
||||
expect(image).toHaveClass("h-3.5", "w-3.5", "opacity-0");
|
||||
const fallback = icon.querySelector("span")!;
|
||||
expect(fallback).toHaveTextContent(providerBrand(provider)!.initials);
|
||||
expect(fallback).toHaveClass("opacity-100");
|
||||
fireEvent.load(image);
|
||||
expect(icon).toHaveClass("bg-white");
|
||||
expect(image).toHaveClass("opacity-100");
|
||||
expect(fallback).toHaveClass("opacity-0");
|
||||
});
|
||||
|
||||
it("avoids the Moonshot halo, and insets unknown fallback images", () => {
|
||||
|
||||
@@ -52,4 +52,25 @@ describe("useLogoFallback", () => {
|
||||
|
||||
expect(screen.getByText("No logo")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not treat a different provider's image as already loaded", () => {
|
||||
const view = render(<TestLogo urls={["/first.svg"]} />);
|
||||
fireEvent.load(screen.getByRole("img"));
|
||||
expect(screen.getByText("Loaded")).toBeInTheDocument();
|
||||
view.rerender(<TestLogo urls={["/second.svg"]} />);
|
||||
expect(screen.getByRole("img")).toHaveAttribute("src", "/second.svg");
|
||||
expect(screen.getByText("Loading")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("invalidates a previously loaded candidate if it later fails", () => {
|
||||
const urls = ["/first.svg", "/second.svg"];
|
||||
const view = render(<TestLogo urls={urls} />);
|
||||
fireEvent.load(screen.getByRole("img"));
|
||||
fireEvent.error(screen.getByRole("img"));
|
||||
expect(screen.getByText("Loading")).toBeInTheDocument();
|
||||
view.unmount();
|
||||
render(<TestLogo urls={urls} />);
|
||||
expect(screen.getByRole("img")).toHaveAttribute("src", "/second.svg");
|
||||
expect(screen.getByText("Loading")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user