import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@renderer/components/ui/select'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@renderer/components/ui/tooltip'; import type { CliProviderStatus } from '@shared/types'; interface Props { provider: CliProviderStatus; disabled?: boolean; onSelect: (providerId: CliProviderStatus['providerId'], backendId: string) => void; } export function getOptionDisplayLabel( option: NonNullable[number], resolvedOption: NonNullable[number] | null ): string { if (option.id !== 'auto') { return option.label; } if (resolvedOption?.label) { return `Auto (currently: ${resolvedOption.label})`; } return 'Auto'; } export function getProviderRuntimeBackendSummary(provider: CliProviderStatus): string | null { const options = provider.availableBackends ?? []; if (options.length === 0) { return null; } const selectedBackendId = provider.selectedBackendId ?? options[0]?.id ?? ''; const selectedOption = options.find((option) => option.id === selectedBackendId) ?? options[0]; const resolvedOption = options.find((option) => option.id === provider.resolvedBackendId) ?? null; return getOptionDisplayLabel(selectedOption, resolvedOption); } export const ProviderRuntimeBackendSelector = ({ provider, disabled = false, onSelect, }: Props): React.JSX.Element | null => { const options = provider.availableBackends ?? []; if (options.length === 0) { return null; } const selectedBackendId = provider.selectedBackendId ?? options[0]?.id ?? ''; const selectedOption = options.find((option) => option.id === selectedBackendId) ?? options[0]; const resolvedOption = options.find((option) => option.id === provider.resolvedBackendId) ?? null; const selectedLabel = getOptionDisplayLabel(selectedOption, resolvedOption); return (
Runtime backend {provider.resolvedBackendId && provider.resolvedBackendId !== provider.selectedBackendId && ( Resolved: {resolvedOption?.label ?? provider.resolvedBackendId} )}
{selectedOption && (
{selectedLabel} {selectedOption.recommended ? ( Recommended ) : null} {!selectedOption.available ? ( Unavailable {selectedOption.detailMessage ?? selectedOption.statusMessage ?? 'Unavailable'} ) : null}
{selectedOption.description}
{selectedOption.statusMessage ?
{selectedOption.statusMessage}
: null} {selectedOption.detailMessage && selectedOption.available ? (
{selectedOption.detailMessage}
) : null}
)}
); };