fix: Fix linter error

This commit is contained in:
Vanalite 2025-09-29 19:59:53 +07:00
parent 987063fede
commit b062e6840a
2 changed files with 24 additions and 17 deletions

View File

@ -14,7 +14,7 @@ type ModelProvider = {
displayName?: string displayName?: string
capabilities: string[] capabilities: string[]
}> }>
settings: any[] settings: unknown[]
} }
type Model = { type Model = {
@ -23,6 +23,16 @@ type Model = {
capabilities?: string[] capabilities?: string[]
} }
type MockHookReturn = {
providers: ModelProvider[]
selectedProvider: string
selectedModel: Model
getProviderByName: (name: string) => ModelProvider | undefined
selectModelProvider: () => void
getModelBy: (id: string) => Model | undefined
updateProvider: () => void
}
// Mock the dependencies // Mock the dependencies
vi.mock('@/hooks/useModelProvider', () => ({ vi.mock('@/hooks/useModelProvider', () => ({
useModelProvider: vi.fn(), useModelProvider: vi.fn(),
@ -142,10 +152,10 @@ describe('DropdownModelProvider - Display Name Integration', () => {
), ),
selectModelProvider: vi.fn(), selectModelProvider: vi.fn(),
getModelBy: vi.fn((id: string) => getModelBy: vi.fn((id: string) =>
mockProviders[0].models.find((m: any) => m.id === id) mockProviders[0].models.find((m: Model) => m.id === id)
), ),
updateProvider: vi.fn(), updateProvider: vi.fn(),
} as any) } as MockHookReturn)
}) })
it('should display custom model name in the trigger button', () => { it('should display custom model name in the trigger button', () => {
@ -167,10 +177,10 @@ describe('DropdownModelProvider - Display Name Integration', () => {
), ),
selectModelProvider: vi.fn(), selectModelProvider: vi.fn(),
getModelBy: vi.fn((id: string) => getModelBy: vi.fn((id: string) =>
mockProviders[0].models.find((m: any) => m.id === id) mockProviders[0].models.find((m: Model) => m.id === id)
), ),
updateProvider: vi.fn(), updateProvider: vi.fn(),
} as any) } as MockHookReturn)
render(<DropdownModelProvider />) render(<DropdownModelProvider />)
@ -219,10 +229,10 @@ describe('DropdownModelProvider - Display Name Integration', () => {
), ),
selectModelProvider: mockSelectModelProvider, selectModelProvider: mockSelectModelProvider,
getModelBy: vi.fn((id: string) => getModelBy: vi.fn((id: string) =>
mockProviders[0].models.find((m: any) => m.id === id) mockProviders[0].models.find((m: Model) => m.id === id)
), ),
updateProvider: vi.fn(), updateProvider: vi.fn(),
} as any) } as MockHookReturn)
render(<DropdownModelProvider />) render(<DropdownModelProvider />)
@ -253,10 +263,10 @@ describe('DropdownModelProvider - Display Name Integration', () => {
), ),
selectModelProvider: vi.fn(), selectModelProvider: vi.fn(),
getModelBy: vi.fn((id: string) => getModelBy: vi.fn((id: string) =>
mockProviders[0].models.find((m: any) => m.id === id) mockProviders[0].models.find((m: Model) => m.id === id)
), ),
updateProvider: vi.fn(), updateProvider: vi.fn(),
} as any) } as MockHookReturn)
rerender(<DropdownModelProvider />) rerender(<DropdownModelProvider />)
// Check trigger now shows Short Name // Check trigger now shows Short Name

View File

@ -23,7 +23,6 @@ import {
} from '@tabler/icons-react' } from '@tabler/icons-react'
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { useTranslation } from '@/i18n/react-i18next-compat' import { useTranslation } from '@/i18n/react-i18next-compat'
import { useServiceHub } from '@/hooks/useServiceHub'
import { toast } from 'sonner' import { toast } from 'sonner'
// No need to define our own interface, we'll use the existing Model type // No need to define our own interface, we'll use the existing Model type
@ -37,7 +36,7 @@ export const DialogEditModel = ({
modelId, modelId,
}: DialogEditModelProps) => { }: DialogEditModelProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const { updateProvider, setProviders } = useModelProvider() const { updateProvider } = useModelProvider()
const [selectedModelId, setSelectedModelId] = useState<string>('') const [selectedModelId, setSelectedModelId] = useState<string>('')
const [displayName, setDisplayName] = useState<string>('') const [displayName, setDisplayName] = useState<string>('')
const [originalDisplayName, setOriginalDisplayName] = useState<string>('') const [originalDisplayName, setOriginalDisplayName] = useState<string>('')
@ -46,7 +45,6 @@ export const DialogEditModel = ({
>({}) >({})
const [isOpen, setIsOpen] = useState(false) const [isOpen, setIsOpen] = useState(false)
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const serviceHub = useServiceHub()
const [capabilities, setCapabilities] = useState<Record<string, boolean>>({ const [capabilities, setCapabilities] = useState<Record<string, boolean>>({
completion: false, completion: false,
vision: false, vision: false,
@ -82,8 +80,7 @@ export const DialogEditModel = ({
// Get the currently selected model // Get the currently selected model
const selectedModel = provider.models.find( const selectedModel = provider.models.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any (m: Model) => m.id === selectedModelId
(m: any) => m.id === selectedModelId
) )
// Initialize capabilities and display name from selected model // Initialize capabilities and display name from selected model
@ -99,7 +96,7 @@ export const DialogEditModel = ({
reasoning: modelCapabilities.includes('reasoning'), reasoning: modelCapabilities.includes('reasoning'),
}) })
// Use existing displayName if available, otherwise fall back to model ID // Use existing displayName if available, otherwise fall back to model ID
const displayNameValue = (selectedModel as any).displayName || selectedModel.id const displayNameValue = (selectedModel as Model & { displayName?: string }).displayName || selectedModel.id
setDisplayName(displayNameValue) setDisplayName(displayNameValue)
setOriginalDisplayName(displayNameValue) setOriginalDisplayName(displayNameValue)
@ -147,7 +144,7 @@ export const DialogEditModel = ({
// Update display name if changed // Update display name if changed
if (displayName !== originalDisplayName) { if (displayName !== originalDisplayName) {
// Update the model in the provider models array with displayName // Update the model in the provider models array with displayName
updatedModels = updatedModels.map((m: any) => { updatedModels = updatedModels.map((m: Model) => {
if (m.id === selectedModelId) { if (m.id === selectedModelId) {
return { return {
...m, ...m,
@ -168,7 +165,7 @@ export const DialogEditModel = ({
.map(([capName]) => capName) .map(([capName]) => capName)
// Find and update the model in the provider // Find and update the model in the provider
updatedModels = updatedModels.map((m: any) => { updatedModels = updatedModels.map((m: Model) => {
if (m.id === selectedModelId) { if (m.id === selectedModelId) {
return { return {
...m, ...m,