Improve model name resolution for agent sessions

- Extract actual model ID from session model string and resolve model details
- Use resolved model name, provider, and group when available instead of defaults
- Remove redundant API model handling in getModelName function
This commit is contained in:
suyao 2025-09-20 16:33:56 +08:00
parent 1c045231c8
commit 3ae1b3d4cb
No known key found for this signature in database
2 changed files with 11 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import { loggerService } from '@logger'
import { QuickPanelView } from '@renderer/components/QuickPanel'
import { useSession } from '@renderer/hooks/agents/useSession'
import { getModel } from '@renderer/hooks/useModel'
import { useSettings } from '@renderer/hooks/useSettings'
import { useTimer } from '@renderer/hooks/useTimer'
import PasteService from '@renderer/services/PasteService'
@ -108,12 +109,18 @@ const AgentSessionInputbar: FC<Props> = ({ agentId, sessionId }) => {
})
const userMessageBlocks: MessageBlock[] = [mainBlock]
// Extract the actual model ID from session.model (format: "sessionId:modelId")
const actualModelId = session?.model ? session.model.split(':').pop() : undefined
// Try to find the actual model from providers
const actualModel = actualModelId ? getModel(actualModelId) : undefined
const model: Model | undefined = session?.model
? {
id: session.model,
name: session.model.split(':').pop() || session.model, // Extract model name after ':'
provider: 'agent-session',
group: 'agent-session'
name: actualModel?.name || actualModelId || session.model, // Use actual model name if found
provider: actualModel?.provider || 'agent-session',
group: actualModel?.group || 'agent-session'
}
: undefined

View File

@ -1,6 +1,5 @@
import store from '@renderer/store'
import { Model } from '@renderer/types'
import { ApiModel } from '@renderer/types/apiModels'
import { pick } from 'lodash'
import { getProviderName } from './ProviderService'
@ -19,16 +18,8 @@ export const hasModel = (m?: Model) => {
return allModels.find((model) => model.id === m?.id)
}
export function getModelName(model?: Model | ApiModel) {
export function getModelName(model?: Model) {
const modelName = model?.name || model?.id || ''
console.log(model)
// For API models that have provider_name field, use it directly
const apiModel = model as ApiModel
if (apiModel?.provider_name) {
return `${modelName} | ${apiModel.provider_name}`
}
// For legacy models, look up the provider in the store
const provider = store.getState().llm.providers.find((p) => p.id === model?.provider)
if (provider) {
const providerName = getProviderName(model as Model)