fix(usage-logs): show provider icons for CN models (align with classic frontend) - #5631
Conversation
resolveModelProvider in model-badge.tsx only covered mainstream providers (OpenAI/Claude/Gemini/Grok/DeepSeek/Qwen/Doubao/Moonshot/Mistral/Meta/Cohere). Models from Zhipu (glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi rendered as grey dots instead of their brand icons in the usage logs table. Add keyword mappings for these providers, aligning coverage with the classic frontend's getModelCategories. Icons resolved via @lobehub/icons.
Walkthrough
ChangesCN Provider Icon Mappings
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
web/default/src/features/usage-logs/components/model-badge.tsx (1)
82-111: ⚡ Quick winConsider replacing the growing
ifchain with a mapping table.This block is now long and repetitive; a config-driven matcher (pattern list + provider payload) will be easier to extend and less error-prone.
As per coding guidelines, “Keep functions with low cyclomatic complexity; extract complex logic into smaller functions with meaningful variable and function names following camelCase conventions.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/default/src/features/usage-logs/components/model-badge.tsx` around lines 82 - 111, Replace the repetitive if-chain that checks various model patterns (minimax, glm-, mimo-, ernie, spark, hunyuan, baichuan, internlm, step-, yi-) with a configuration-driven mapping table. Create an array or object that maps pattern lists to provider objects containing icon and label properties, then iterate through this config to find the matching provider based on the model name instead of executing multiple hasAny() conditional statements. This will reduce cyclomatic complexity and make the code easier to maintain and extend with new providers.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/default/src/features/usage-logs/components/model-badge.tsx`:
- Around line 91-95: The provider detection logic in model-badge.tsx uses
substring matching with hasAny() calls that can incorrectly match unrelated
model IDs containing those substrings (e.g., 'ernie' or 'spark'). Replace the
simple substring-based checks in the conditions for Baidu (hasAny(['ernie']))
and iFlyTek (hasAny(['spark'])) with boundary-aware or prefix-aware matching
that checks for these tokens as complete identifiers or at word boundaries,
ensuring only actual models from these providers are detected correctly.
---
Nitpick comments:
In `@web/default/src/features/usage-logs/components/model-badge.tsx`:
- Around line 82-111: Replace the repetitive if-chain that checks various model
patterns (minimax, glm-, mimo-, ernie, spark, hunyuan, baichuan, internlm,
step-, yi-) with a configuration-driven mapping table. Create an array or object
that maps pattern lists to provider objects containing icon and label
properties, then iterate through this config to find the matching provider based
on the model name instead of executing multiple hasAny() conditional statements.
This will reduce cyclomatic complexity and make the code easier to maintain and
extend with new providers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ff665242-bff6-4f80-919f-c52b78371fba
📒 Files selected for processing (1)
web/default/src/features/usage-logs/components/model-badge.tsx
| if (hasAny(['ernie'])) { | ||
| return { icon: 'Wenxin.Color', label: 'Baidu' } | ||
| } | ||
| if (hasAny(['spark'])) { | ||
| return { icon: 'Spark.Color', label: 'iFlyTek' } |
There was a problem hiding this comment.
Avoid ambiguous substring matching for provider detection.
Using plain includes('ernie') / includes('spark') can misclassify unrelated model IDs that merely contain those substrings. Prefer boundary/prefix-aware checks for these tokens.
Suggested tightening
- if (hasAny(['ernie'])) {
+ if (/\bernie(?:-|$)/.test(model)) {
return { icon: 'Wenxin.Color', label: 'Baidu' }
}
- if (hasAny(['spark'])) {
+ if (/\bspark(?:-|$)/.test(model)) {
return { icon: 'Spark.Color', label: 'iFlyTek' }
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/default/src/features/usage-logs/components/model-badge.tsx` around lines
91 - 95, The provider detection logic in model-badge.tsx uses substring matching
with hasAny() calls that can incorrectly match unrelated model IDs containing
those substrings (e.g., 'ernie' or 'spark'). Replace the simple substring-based
checks in the conditions for Baidu (hasAny(['ernie'])) and iFlyTek
(hasAny(['spark'])) with boundary-aware or prefix-aware matching that checks for
these tokens as complete identifiers or at word boundaries, ensuring only actual
models from these providers are detected correctly.
…c frontend) (QuantumNous#5631) resolveModelProvider in model-badge.tsx only covered mainstream providers (OpenAI/Claude/Gemini/Grok/DeepSeek/Qwen/Doubao/Moonshot/Mistral/Meta/Cohere). Models from Zhipu (glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi rendered as grey dots instead of their brand icons in the usage logs table. Add keyword mappings for these providers, aligning coverage with the classic frontend's getModelCategories. Icons resolved via @lobehub/icons.
…c frontend) (QuantumNous#5631) resolveModelProvider in model-badge.tsx only covered mainstream providers (OpenAI/Claude/Gemini/Grok/DeepSeek/Qwen/Doubao/Moonshot/Mistral/Meta/Cohere). Models from Zhipu (glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi rendered as grey dots instead of their brand icons in the usage logs table. Add keyword mappings for these providers, aligning coverage with the classic frontend's getModelCategories. Icons resolved via @lobehub/icons.
…c frontend) (QuantumNous#5631) resolveModelProvider in model-badge.tsx only covered mainstream providers (OpenAI/Claude/Gemini/Grok/DeepSeek/Qwen/Doubao/Moonshot/Mistral/Meta/Cohere). Models from Zhipu (glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi rendered as grey dots instead of their brand icons in the usage logs table. Add keyword mappings for these providers, aligning coverage with the classic frontend's getModelCategories. Icons resolved via @lobehub/icons.
…c frontend) (QuantumNous#5631) resolveModelProvider in model-badge.tsx only covered mainstream providers (OpenAI/Claude/Gemini/Grok/DeepSeek/Qwen/Doubao/Moonshot/Mistral/Meta/Cohere). Models from Zhipu (glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi rendered as grey dots instead of their brand icons in the usage logs table. Add keyword mappings for these providers, aligning coverage with the classic frontend's getModelCategories. Icons resolved via @lobehub/icons.
Important
📝 变更描述 / Description
Fixes the usage-logs model badge so models from Zhipu (
glm-), MiniMax, Xiaomi MiMo, Baidu (ernie), iFlyTek (spark), Tencent (hunyuan), Baichuan, InternLM, StepFun, and Yi render their brand icon instead of a grey dot.Why it works:
resolveModelProvider()inweb/default/src/features/usage-logs/components/model-badge.tsxmaps a model name to a provider via keyword matching, then renders the@lobehub/iconsglyph. It previously only covered the mainstream providers and returnednullfor the ones above, which triggered the grey-dot fallback. This PR adds the missing keyword→icon mappings, aligned with what the classic frontend already does ingetModelCategories()(web/classic/src/helpers/render.jsx) — so the two frontends now agree. No new dependency; all icons already exist in@lobehub/icons.Only
web/defaultis changed (the file where the bug lives).web/classicalready covers these providers, so it is left untouched to keep the diff focused.🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
resolveModelProvider模式,无副作用。web/default/src/features/usage-logs/components/model-badge.tsx一个文件(+30 行)。tsc --noEmit通过;已在生产部署验证(usage-logs 现正确显示 Zhipu/MiniMax/XiaomiMiMo 等图标)。📸 运行证明 / Proof of Work
Before: usage-logs
Modelcolumn showed a grey dot forglm-5.2/minimax-m3/mimo-v2.5-pro.After (verified on a live deployment): the same column renders the Zhipu / MiniMax / XiaomiMiMo SVG brand icons, matching the pricing page. Icons confirmed present in the production JS bundle via
<svg><title>(Zhipu, Minimax, XiaomiMiMo, …).Summary by CodeRabbit