Files
NetMesh/components/settings/tabs/ai/ProviderIconBadge.tsx
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

118 lines
3.5 KiB
TypeScript

import React from "react";
import { cn } from "../../../../lib/utils";
import type { ProviderConfig } from "../../../../infrastructure/ai/types";
import type { SettingsIconId } from "./types";
import {
BUILTIN_PROVIDER_ICON_BY_ID,
SETTINGS_ICON_PATHS,
SETTINGS_ICON_COLORS,
} from "./types";
/**
* Optional ProviderConfig-like shape for per-provider customization. Only the
* fields used by the badge are listed so non-provider call sites (Claude/Copilot
* agent cards) can still pass a bare `providerId`.
*/
type ProviderLike = Pick<ProviderConfig, "providerId" | "name" | "iconId" | "iconDataUrl">;
interface BaseProps {
size?: "xs" | "sm" | "md";
}
type Props =
| (BaseProps & { providerId: SettingsIconId; provider?: undefined })
| (BaseProps & { provider: ProviderLike; providerId?: undefined });
const BADGE_DIMENSIONS = {
xs: "w-4 h-4",
sm: "w-5 h-5",
md: "w-8 h-8",
} as const;
const IMG_DIMENSIONS = {
xs: "w-2.5 h-2.5",
sm: "w-3 h-3",
md: "w-4 h-4",
} as const;
const UPLOAD_IMG_DIMENSIONS = {
xs: "w-4 h-4",
sm: "w-5 h-5",
md: "w-8 h-8",
} as const;
export const ProviderIconBadge: React.FC<Props> = (props) => {
const size = props.size ?? "md";
const dim = BADGE_DIMENSIONS[size];
// Branch 1: user-uploaded data URL — render verbatim, no filter, neutral bg.
if (props.provider?.iconDataUrl) {
return (
<div className={cn("rounded-md flex items-center justify-center shrink-0 overflow-hidden bg-zinc-900/40", dim)}>
<img
src={props.provider.iconDataUrl}
alt=""
aria-hidden="true"
draggable={false}
className={cn("object-contain", UPLOAD_IMG_DIMENSIONS[size])}
/>
</div>
);
}
// Branch 2: built-in iconId (lobe-icons subset).
const iconId = props.provider?.iconId;
if (iconId) {
const builtin = BUILTIN_PROVIDER_ICON_BY_ID[iconId];
if (builtin) {
return (
<div className={cn("rounded-md flex items-center justify-center shrink-0 overflow-hidden", dim, builtin.bgColor)}>
<img
src={builtin.path}
alt=""
aria-hidden="true"
draggable={false}
className={cn("object-contain brightness-0 invert", IMG_DIMENSIONS[size])}
/>
</div>
);
}
}
// Branch 3: providerId → existing built-in fallback table.
const fallbackId: SettingsIconId | undefined =
props.providerId ?? (props.provider ? (props.provider.providerId as SettingsIconId) : undefined);
if (fallbackId && fallbackId in SETTINGS_ICON_PATHS) {
return (
<div className={cn("rounded-md flex items-center justify-center shrink-0 overflow-hidden", dim, SETTINGS_ICON_COLORS[fallbackId])}>
<img
src={SETTINGS_ICON_PATHS[fallbackId]}
alt=""
aria-hidden="true"
draggable={false}
className={cn(
"object-contain",
fallbackId === "copilot" ? "brightness-0" : "brightness-0 invert",
IMG_DIMENSIONS[size],
)}
/>
</div>
);
}
// Branch 4: letter avatar from the provider name.
const letter = (props.provider?.name?.trim().charAt(0) ?? "?").toUpperCase();
return (
<div
className={cn(
"rounded-md flex items-center justify-center shrink-0 overflow-hidden bg-zinc-600 text-white font-medium",
dim,
size === "md" ? "text-sm" : size === "sm" ? "text-[10px]" : "text-[9px]",
)}
aria-hidden="true"
>
{letter}
</div>
);
};