File size: 4,740 Bytes
6111b2b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | "use client";
/**
* ProviderIcon — Renders a provider logo using @lobehub/icons with static asset fallbacks.
*
* Strategy (#529):
* 1. Try @lobehub/icons direct icon components (no @lobehub/ui peer runtime)
* 2. Fall back to /providers/{id}.png (existing static assets)
* 3. Fall back to /providers/{id}.svg (SVG assets)
* 4. Fall back to a generic AI icon
*
* Usage:
* <ProviderIcon providerId="openai" size={24} />
* <ProviderIcon providerId="anthropic" size={28} type="color" />
*/
import { createElement, memo, useState } from "react";
import Image from "next/image";
import { getLobeProviderIcon } from "./lobeProviderIcons";
interface ProviderIconProps {
providerId: string;
size?: number;
type?: "mono" | "color";
className?: string;
style?: React.CSSProperties;
}
function GenericProviderIcon({ size }: { size: number }) {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" style={{ flex: "none" }}>
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.5" opacity="0.4" />
<path d="M8 12h8M12 8v8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
</svg>
);
}
const KNOWN_PNGS = new Set([
"agentrouter",
"inner-ai",
"aimlapi",
"anthropic-m",
"blackbox",
"claude",
"continue",
"copilot",
"cursor",
"deepgram",
"ironclaw",
"kie",
"nanobot",
"oai-cc",
"oai-r",
"openclaw",
"zeroclaw",
"adapta-web",
"blackbox-web",
"cliproxyapi",
"empower",
"gigachat",
"heroku",
"lemonade",
"linkup-search",
"llamafile",
"llamagate",
"maritalk",
"nanogpt",
"nscale",
"ovhcloud",
"piapi",
"predibase",
"reka",
]);
const KNOWN_SVGS = new Set([
"apikey",
"bazaarlink",
"brave",
"brave-search",
"cartesia",
"360ai",
"huggingchat",
"iflytek",
"sparkdesk",
"arcee-ai",
"inclusionai",
"krutrim",
"liquid",
"monsterapi",
"nomic",
"poolside",
"clarifai",
"command-code",
"claude-web",
"docker-model-runner",
"droid",
"gemini-cli",
"gitlab",
"gitlab-duo",
"inworld",
"kiro",
"kilo-gateway",
"kilocode",
"modal",
"nlpcloud",
"oauth",
"oci",
"opencode",
"playht",
"puter",
"qianfan",
"sap",
"scaleway",
"serper-search",
"searxng-search",
"synthetic",
"wandb",
"youcom-search",
]);
const ProviderIcon = memo(function ProviderIcon({
providerId,
size = 24,
type = "color",
className,
style,
}: ProviderIconProps) {
const normalizedId = providerId.toLowerCase();
const lobeIcon = getLobeProviderIcon(normalizedId, type);
const hasPng = KNOWN_PNGS.has(normalizedId);
const hasSvg = KNOWN_SVGS.has(normalizedId);
const [failedAssets, setFailedAssets] = useState<Record<string, true>>({});
const pngKey = `${normalizedId}:png`;
const svgKey = `${normalizedId}:svg`;
const usePng = !lobeIcon && hasPng && !failedAssets[pngKey];
const useSvg = !lobeIcon && hasSvg && !failedAssets[svgKey] && (!hasPng || failedAssets[pngKey]);
if (lobeIcon) {
return (
<span
className={className}
style={{ display: "inline-flex", alignItems: "center", ...style }}
>
{createElement(lobeIcon, {
"aria-label": providerId,
size,
style: { flex: "none" },
})}
</span>
);
}
if (usePng) {
return (
<span
className={className}
style={{ display: "inline-flex", alignItems: "center", ...style }}
>
<Image
src={`/providers/${normalizedId}.png`}
alt={providerId}
width={size}
height={size}
style={{ objectFit: "contain" }}
onError={() => {
setFailedAssets((current) => ({ ...current, [pngKey]: true }));
}}
unoptimized
/>
</span>
);
}
if (useSvg) {
return (
<span
className={className}
style={{ display: "inline-flex", alignItems: "center", ...style }}
>
<Image
src={`/providers/${normalizedId}.svg`}
alt={providerId}
width={size}
height={size}
style={{ objectFit: "contain" }}
onError={() => setFailedAssets((current) => ({ ...current, [svgKey]: true }))}
unoptimized
/>
</span>
);
}
return (
<span className={className} style={{ display: "inline-flex", alignItems: "center", ...style }}>
<GenericProviderIcon size={size} />
</span>
);
});
export default ProviderIcon;
export type { ProviderIconProps };
|