fix: reload OpenCode config and invalidate provider caches after credential changes (#183)

- Trigger reloadConfig() after API key save/delete in providers route so the
  OpenCode server immediately recognizes newly connected providers
- Wrap reloadConfig() in try/catch in both providers.ts and oauth.ts so
  credential operations succeed even if the reload fails transiently
- Add invalidateProviderCaches() utility covering all provider-related query
  keys, replacing scattered manual invalidation across ProviderSettings
- Remove duplicate provider key invalidation from invalidateConfigCaches()
  by delegating to invalidateProviderCaches()
- Remove unused invalidateAllConfigRelatedCaches() export

Fixes #180
This commit is contained in:
Chris Scott authored and GitHub committed 2026-04-07 10:23:55 -04:00
1 parent 5620388aa6
commit 1da1ec617a
4 files changed
+37 -19

No files matched your search

@@ -1,6 +1,6 @@
import { useState, useMemo, useCallback } from 'react'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Input } from '@/components/ui/input'
import { DeleteDialog } from '@/components/ui/delete-dialog'
@@ -12,6 +12,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { OAuthAuthorizeDialog } from './OAuthAuthorizeDialog'
import { OAuthCallbackDialog } from './OAuthCallbackDialog'
import { ApiKeyDialog } from '@/components/model/ApiKeyDialog'
import { invalidateProviderCaches } from '@/lib/queryInvalidation'
export function ProviderSettings() {
const [selectedProvider, setSelectedProvider] = useState<string | null>(null)
@@ -48,9 +49,7 @@ export function ProviderSettings() {
const deleteCredentialMutation = useMutation({
mutationFn: (providerId: string) => providerCredentialsApi.delete(providerId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['provider-credentials'] })
queryClient.invalidateQueries({ queryKey: ['providers'] })
queryClient.invalidateQueries({ queryKey: ['providers-with-models'] })
invalidateProviderCaches(queryClient)
},
})
@@ -81,7 +80,7 @@ export function ProviderSettings() {
}
const handleOAuthSuccess = () => {
queryClient.invalidateQueries({ queryKey: ['provider-credentials'] })
invalidateProviderCaches(queryClient)
setOauthCallbackDialogOpen(false)
setOauthResponse(null)
setSelectedProvider(null)
@@ -138,9 +137,7 @@ export function ProviderSettings() {
const handleApiKeySuccess = useCallback(() => {
setApiKeyDialogOpen(false)
setApiKeyProvider(null)
queryClient.invalidateQueries({ queryKey: ['provider-credentials'] })
queryClient.invalidateQueries({ queryKey: ['providers'] })
queryClient.invalidateQueries({ queryKey: ['providers-with-models'] })
invalidateProviderCaches(queryClient)
}, [queryClient])
const handleApiKeyDialogClose = useCallback((open: boolean) => {