/** * LobeHub Icon Loader * Dynamically load and render icons from @lobehub/icons * * Supports: * - Basic: "OpenAI", "OpenAI.Color" * - Chained properties: "OpenAI.Avatar.type={'platform'}" * - Size parameter: getLobeIcon("OpenAI", 20) */ import * as LobeIcons from '@lobehub/icons' /** * Parse a property value from string to appropriate type * @param raw - Raw string value * @returns Parsed value (boolean, number, or string) */ function parseValue(raw: string | undefined | null): string | number | boolean { if (raw == null) return true let v = String(raw).trim() // Remove curly braces if (v.startsWith('{') && v.endsWith('}')) { v = v.slice(1, -1).trim() } // Remove quotes if ( (v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")) ) { return v.slice(1, -1) } // Boolean if (v === 'true') return true if (v === 'false') return false // Number if (/^-?\d+(?:\.\d+)?$/.test(v)) return Number(v) // Return as string return v } /** * Get LobeHub icon component by name * @param iconName - Icon name/description (e.g., "OpenAI", "OpenAI.Color", "Claude.Avatar") * @param size - Icon size (default: 20) * @returns Icon component or fallback * * @example * getLobeIcon("OpenAI", 24) * getLobeIcon("OpenAI.Color", 20) * getLobeIcon("Claude.Avatar.type={'platform'}", 32) */ export function getLobeIcon( iconName: string | undefined | null, size: number = 20 ): React.ReactNode { if (!iconName || typeof iconName !== 'string') { return (