mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
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:
1 parent
5620388aa6
commit
1da1ec617a
4 files changed
+37
-19
No files matched your search
@@ -74,10 +74,13 @@ export function createOAuthRoutes() {
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
logger.info(`OAuth callback successful for ${providerId}, reloading OpenCode configuration`)
|
||||
await opencodeServerManager.reloadConfig()
|
||||
|
||||
|
||||
try {
|
||||
await opencodeServerManager.reloadConfig()
|
||||
} catch (reloadError) {
|
||||
logger.warn(`Failed to reload OpenCode config after OAuth callback for ${providerId}:`, reloadError)
|
||||
}
|
||||
|
||||
return c.json(data)
|
||||
} catch (error) {
|
||||
logger.error('OAuth callback error:', error)
|
||||
|
||||
@@ -4,6 +4,7 @@ import { AuthService } from '../services/auth'
|
||||
import { SetCredentialRequestSchema } from '../../../shared/src/schemas/auth'
|
||||
import { logger } from '../utils/logger'
|
||||
import { setOpenCodeAuth, deleteOpenCodeAuth } from '../services/proxy'
|
||||
import { opencodeServerManager } from '../services/opencode-single-server'
|
||||
|
||||
export function createProvidersRoutes() {
|
||||
const app = new Hono()
|
||||
@@ -42,6 +43,13 @@ export function createProvidersRoutes() {
|
||||
}
|
||||
|
||||
await authService.set(providerId, validated.apiKey)
|
||||
|
||||
try {
|
||||
await opencodeServerManager.reloadConfig()
|
||||
} catch (reloadError) {
|
||||
logger.warn(`Failed to reload OpenCode config after saving credentials for ${providerId}:`, reloadError)
|
||||
}
|
||||
|
||||
return c.json({ success: true })
|
||||
} catch (error) {
|
||||
logger.error('Failed to set provider credentials:', error)
|
||||
@@ -62,6 +70,13 @@ export function createProvidersRoutes() {
|
||||
}
|
||||
|
||||
await authService.delete(providerId)
|
||||
|
||||
try {
|
||||
await opencodeServerManager.reloadConfig()
|
||||
} catch (reloadError) {
|
||||
logger.warn(`Failed to reload OpenCode config after deleting credentials for ${providerId}:`, reloadError)
|
||||
}
|
||||
|
||||
return c.json({ success: true })
|
||||
} catch (error) {
|
||||
logger.error('Failed to delete provider credentials:', error)
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import type { QueryClient } from '@tanstack/react-query'
|
||||
|
||||
export function invalidateProviderCaches(queryClient: QueryClient) {
|
||||
queryClient.invalidateQueries({ queryKey: ['provider-credentials'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['provider-auth-methods'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['providers'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['providers-with-models'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'providers'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['providers-for-execution-model'] })
|
||||
}
|
||||
|
||||
export function invalidateConfigCaches(queryClient: QueryClient) {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'config'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode-config'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['mcp-status'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['providers'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'providers'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode-skills'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['managed-skills'] })
|
||||
invalidateProviderCaches(queryClient)
|
||||
}
|
||||
|
||||
export function invalidateSettingsCaches(queryClient: QueryClient, userId = 'default') {
|
||||
@@ -26,8 +34,3 @@ export function invalidateSessionCaches(queryClient: QueryClient) {
|
||||
query.queryKey[1] === 'messages'),
|
||||
})
|
||||
}
|
||||
|
||||
export function invalidateAllConfigRelatedCaches(queryClient: QueryClient, userId = 'default') {
|
||||
invalidateSettingsCaches(queryClient, userId)
|
||||
invalidateSessionCaches(queryClient)
|
||||
}
|
||||
Reference in new issue
Block a user