Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(keys): make the custom provider "Fetch models" button visible (#1457) (#1502)

Aymen Jeddou1671802c4b01
diff --git a/client/src/components/keys/custom-provider-section.test.tsx b/client/src/components/keys/custom-provider-section.test.tsx
new file mode 100644
index 00000000..15542b31
--- /dev/null
+++ b/client/src/components/keys/custom-provider-section.test.tsx
@@ -0,0 +1,50 @@
+// @vitest-environment jsdom
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { I18nProvider } from '@/i18n'
+import { apiFetch } from '@/lib/api'
+import { CustomProviderSection } from './custom-provider-section'
+
+vi.mock('@/lib/api', () => ({ apiFetch: vi.fn() }))
+vi.mock('@/lib/toast', () => ({ toast: { success: vi.fn(), error: vi.fn(), info: vi.fn() } }))
+
+// #1457: "Fetch models" was an 11px muted text link that users missed.
+let root: Root
+let container: HTMLDivElement
+
+beforeAll(() => {
+ ;(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+})
+beforeEach(() => {
+ vi.mocked(apiFetch).mockReset().mockResolvedValue([])
+ container = document.createElement('div')
+ document.body.appendChild(container)
+ root = createRoot(container)
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ act(() => root.render(<QueryClientProvider client={client}><I18nProvider initialLocale="en"><CustomProviderSection /></I18nProvider></QueryClientProvider>))
+})
+afterEach(() => { act(() => root.unmount()); container.remove() })
+
+function fetchModelsButton() {
+ return [...container.querySelectorAll('button')].find(b => b.textContent === 'Fetch models')!
+}
+
+describe('custom provider "Fetch models" button (#1457)', () => {
+ it('renders as a real button with an icon, not a muted text link', () => {
+ const button = fetchModelsButton()
+ expect(button.getAttribute('data-slot')).toBe('button')
+ expect(button.querySelector('svg')).not.toBeNull()
+ })
+
+ it('stays disabled until the base URL is valid', () => {
+ expect(fetchModelsButton().disabled).toBe(true)
+ const input = container.querySelector<HTMLInputElement>('input[placeholder="http://127.0.0.1:11434/v1"]')!
+ act(() => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, 'http://127.0.0.1:11434/v1')
+ input.dispatchEvent(new Event('input', { bubbles: true }))
+ })
+ expect(fetchModelsButton().disabled).toBe(false)
+ })
+})
diff --git a/client/src/components/keys/custom-provider-section.tsx b/client/src/components/keys/custom-provider-section.tsx
index 717d10eb..eedd166a 100644
--- a/client/src/components/keys/custom-provider-section.tsx
+++ b/client/src/components/keys/custom-provider-section.tsx
@@ -1,4 +1,5 @@
import { useState } from 'react'
+import { ListPlus } from 'lucide-react'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { apiFetch } from '@/lib/api'
import { Button } from '@/components/ui/button'
@@ -182,14 +183,16 @@ export function CustomProviderSection({ onAdded }: { onAdded?: () => void } = {}
<div className="flex items-center justify-between gap-2">
<Label className="text-xs">{customType === 'chat' ? t('keys.customModels') : t('keys.customModel')}</Label>
{customType === 'chat' && (
- <button
+ <Button
type="button"
+ variant="outline"
+ size="xs"
onClick={() => setDiscoverOpen(true)}
disabled={!!baseUrlError}
- className="text-[11px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline disabled:pointer-events-none disabled:opacity-50"
>
+ <ListPlus data-icon="inline-start" />
{t('keys.discoverModels')}
- </button>
+ </Button>
)}
</div>
<Textarea