refactor(agent): replace agent type label map with switch statement

Simplify agent type label handling by replacing the map with a direct switch statement. Also update related type references and array type assertions for consistency.
This commit is contained in:
icarus 2025-09-22 12:14:45 +08:00
parent bd6428d473
commit 8cd40a471e
3 changed files with 10 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import ClaudeAvatar from '@renderer/assets/images/models/claude.png'
import { AgentBase, AgentEntity } from '@renderer/types'
import { AgentBase, AgentType } from '@renderer/types'
// base agent config. no default config for now.
const DEFAULT_AGENT_CONFIG: Omit<AgentBase, 'model'> = {
@ -11,7 +11,7 @@ export const DEFAULT_CLAUDE_CODE_CONFIG: Omit<AgentBase, 'model'> = {
...DEFAULT_AGENT_CONFIG
} as const
export const getAgentAvatar = (type: AgentEntity['type']): string => {
export const getAgentAvatar = (type: AgentType): string => {
switch (type) {
case 'claude-code':
return ClaudeAvatar

View File

@ -346,10 +346,11 @@ export const getBuiltinOcrProviderLabel = (key: BuiltinOcrProviderId) => {
else return getLabel(builtinOcrProviderKeyMap, key)
}
const agentTypeKeyMap = {
'claude-code': 'Claude Code'
} as const satisfies Record<AgentType, string>
export const getAgentTypeLabel = (key: AgentType) => {
return getLabel(agentTypeKeyMap, key, t('agent.type.unknown'))
switch (key) {
case 'claude-code':
return 'Claude Code'
default:
return 'Unknown Type'
}
}

View File

@ -53,8 +53,8 @@ const AgentSettingPopupContainer: React.FC<AgentSettingPopupParams> = ({ tab, ag
key: 'prompt',
label: t('agent.settings.prompt')
}
] satisfies { key: AgentSettingPopupTab; label: string }[]
).filter(Boolean) as { key: string; label: string }[]
] as const satisfies { key: AgentSettingPopupTab; label: string }[]
).filter(Boolean)
const ModalContent = () => {
if (!agent) {