import { memo, useState } from "react"; import { useStyletron } from "baseui"; import { StatefulPopover, PLACEMENT } from "baseui/popover"; import { ChevronDown, ChevronUp, Star } from "lucide-react"; import { AgentIcon } from "./ui"; import { MODEL_GROUPS, modelLabel, providerAgent, type ModelId } from "./view-model"; const ModelPickerContent = memo(function ModelPickerContent({ value, defaultModel, onChange, onSetDefault, close, }: { value: ModelId; defaultModel: ModelId; onChange: (id: ModelId) => void; onSetDefault: (id: ModelId) => void; close: () => void; }) { const [css, theme] = useStyletron(); const [hoveredId, setHoveredId] = useState(null); return (
{MODEL_GROUPS.map((group) => (
{group.provider}
{group.models.map((model) => { const isActive = model.id === value; const isDefault = model.id === defaultModel; const isHovered = model.id === hoveredId; const agent = providerAgent(group.provider); return (
setHoveredId(model.id)} onMouseLeave={() => setHoveredId(null)} onClick={() => { onChange(model.id); close(); }} className={css({ display: "flex", alignItems: "center", gap: "8px", padding: "6px 12px", cursor: "pointer", fontSize: "12px", fontWeight: isActive ? 600 : 400, color: isActive ? theme.colors.contentPrimary : theme.colors.contentSecondary, borderRadius: "6px", marginLeft: "4px", marginRight: "4px", ":hover": { backgroundColor: "rgba(255, 255, 255, 0.08)" }, })} > {model.label} {isDefault ? : null} {!isDefault && isHovered ? ( { event.stopPropagation(); onSetDefault(model.id); }} /> ) : null}
); })}
))}
); }); export const ModelPicker = memo(function ModelPicker({ value, defaultModel, onChange, onSetDefault, }: { value: ModelId; defaultModel: ModelId; onChange: (id: ModelId) => void; onSetDefault: (id: ModelId) => void; }) { const [css, theme] = useStyletron(); const [isOpen, setIsOpen] = useState(false); return ( setIsOpen(true)} onClose={() => setIsOpen(false)} overrides={{ Body: { style: { backgroundColor: "rgba(32, 32, 32, 0.98)", backdropFilter: "blur(12px)", borderTopLeftRadius: "10px", borderTopRightRadius: "10px", borderBottomLeftRadius: "10px", borderBottomRightRadius: "10px", border: "1px solid rgba(255, 255, 255, 0.10)", boxShadow: "0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04)", zIndex: 100, }, }, Inner: { style: { backgroundColor: "transparent", padding: "0", }, }, }} content={({ close }) => } >
); });