mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Bump version to 0.8.21 (#99)
* Add timeout handling and recovery for OpenCode upgrade/install operations - Extract DEFAULT_AGENTS_MD to constants file - Add 90s timeout for opencode upgrade/install commands - Implement server recovery when upgrade/install fails - Update frontend error handling for recovery status - Add settings route tests * Add centralized query cache invalidation utility * Bump version to 0.8.21
This commit is contained in:
1 parent
3661f0a271
commit
a02f7a2e98
14 files changed
+1100
-126
No files matched your search
@@ -139,12 +139,22 @@ export const settingsApi = {
|
||||
message: string
|
||||
oldVersion?: string
|
||||
newVersion?: string
|
||||
recovered?: boolean
|
||||
recoveryMessage?: string
|
||||
}> => {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-install-version`, { version })
|
||||
return data
|
||||
},
|
||||
|
||||
upgradeOpenCode: async (): Promise<{ success: boolean; message: string; oldVersion?: string; newVersion?: string; upgraded: boolean }> => {
|
||||
upgradeOpenCode: async (): Promise<{
|
||||
success: boolean
|
||||
message: string
|
||||
oldVersion?: string
|
||||
newVersion?: string
|
||||
upgraded: boolean
|
||||
recovered?: boolean
|
||||
recoveryMessage?: string
|
||||
}> => {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-upgrade`)
|
||||
return data
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ import { AddMcpServerDialog } from './AddMcpServerDialog'
|
||||
import { McpServerCard } from './McpServerCard'
|
||||
import { useMcpServers } from '@/hooks/useMcpServers'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
interface McpServerConfig {
|
||||
type: 'local' | 'remote'
|
||||
@@ -61,8 +62,7 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
|
||||
await onUpdate(updatedConfig)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode-config'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['mcp-status'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
setDeleteConfirmServer(null)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { parseJsonc, hasJsoncComments } from '@/lib/jsonc'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
import type { OpenCodeConfig } from '@/api/types/settings'
|
||||
|
||||
interface Command {
|
||||
@@ -86,7 +87,7 @@ export function OpenCodeConfigManager() {
|
||||
return await settingsApi.reloadOpenCodeConfig()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -95,7 +96,7 @@ export function OpenCodeConfigManager() {
|
||||
return await settingsApi.restartOpenCodeServer()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -104,16 +105,30 @@ export function OpenCodeConfigManager() {
|
||||
return await settingsApi.upgradeOpenCode()
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
if (data.upgraded) {
|
||||
showToast.success(`Upgraded to v${data.newVersion} and server restarted`, { id: 'upgrade-opencode' })
|
||||
} else {
|
||||
showToast.success('OpenCode is already up to date', { id: 'upgrade-opencode' })
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to upgrade OpenCode', { id: 'upgrade-opencode' })
|
||||
onError: (error) => {
|
||||
invalidateConfigCaches(queryClient)
|
||||
|
||||
const defaultMessage = 'Failed to upgrade OpenCode'
|
||||
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { recovered?: boolean; recoveryMessage?: string; newVersion?: string } } }).response
|
||||
const data = response?.data
|
||||
|
||||
if (data?.recovered) {
|
||||
showToast.success(`Upgrade failed but server recovered at v${data.newVersion}`, { id: 'upgrade-opencode' })
|
||||
} else {
|
||||
showToast.error(data?.recoveryMessage || defaultMessage, { id: 'upgrade-opencode' })
|
||||
}
|
||||
} else {
|
||||
showToast.error(defaultMessage, { id: 'upgrade-opencode' })
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -170,9 +185,8 @@ export function OpenCodeConfigManager() {
|
||||
}
|
||||
} else {
|
||||
showToast.success('Configuration updated')
|
||||
invalidateConfigCaches(queryClient)
|
||||
}
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
} catch (error) {
|
||||
console.error('Failed to update config:', error)
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to update config'), { id: 'update-restart' })
|
||||
@@ -226,7 +240,7 @@ export function OpenCodeConfigManager() {
|
||||
showToast.success('Configuration created', { id: 'create-config' })
|
||||
}
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
} catch (error) {
|
||||
console.error('Failed to create config:', error)
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to create configuration'), { id: 'create-config' })
|
||||
@@ -243,9 +257,11 @@ export function OpenCodeConfigManager() {
|
||||
setIsUpdating(true)
|
||||
await settingsApi.deleteOpenCodeConfig(config.name)
|
||||
setDeleteConfirmConfig(null)
|
||||
if (selectedConfig?.id === config.id) {
|
||||
setSelectedConfig(null)
|
||||
}
|
||||
fetchConfigs()
|
||||
// Invalidate agents cache in case deleted config had agents
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
} catch (error) {
|
||||
console.error('Failed to delete config:', error)
|
||||
} finally {
|
||||
@@ -485,7 +501,7 @@ export function OpenCodeConfigManager() {
|
||||
? 'Configuration saved and server reloaded'
|
||||
: 'Configuration saved'
|
||||
showToast.success(successMsg, { id: 'edit-config' })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
} catch (error) {
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to save configuration'), { id: 'edit-config' })
|
||||
throw error
|
||||
@@ -570,7 +586,7 @@ export function OpenCodeConfigManager() {
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Commands</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys(selectedConfig.content.command as Record<string, Command> || {}).length} configured
|
||||
{Object.keys((selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}).length} configured
|
||||
</span>
|
||||
</div>
|
||||
<Edit className={`h-4 w-4 transition-transform ${expandedSections.commands ? 'rotate-90' : ''}`} />
|
||||
@@ -578,7 +594,7 @@ export function OpenCodeConfigManager() {
|
||||
<div className={`${expandedSections.commands ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-1 sm:p-4 max-h-[50vh] overflow-y-auto">
|
||||
<CommandsEditor
|
||||
commands={(selectedConfig.content.command as Record<string, Command>) || {}}
|
||||
commands={(selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}}
|
||||
onChange={(commands) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -607,7 +623,7 @@ export function OpenCodeConfigManager() {
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">Agents</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys(selectedConfig.content.agent as Record<string, Agent> || {}).length} configured
|
||||
{Object.keys((selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}).length} configured
|
||||
</span>
|
||||
</div>
|
||||
<Edit className={`h-4 w-4 transition-transform ${expandedSections.agents ? 'rotate-90' : ''}`} />
|
||||
@@ -615,7 +631,7 @@ export function OpenCodeConfigManager() {
|
||||
<div className={`${expandedSections.agents ? 'block' : 'hidden'} border-t border-border`}>
|
||||
<div className="p-4 max-h-[50vh] overflow-y-auto">
|
||||
<AgentsEditor
|
||||
agents={(selectedConfig.content.agent as Record<string, Agent>) || {}}
|
||||
agents={(selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}}
|
||||
onChange={(agents) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -644,7 +660,7 @@ export function OpenCodeConfigManager() {
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<h4 className="text-sm font-medium truncate">MCP Servers</h4>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{Object.keys((selectedConfig.content.mcp as Record<string, unknown>) || {}).length} configured
|
||||
{Object.keys((selectedConfig.content?.mcp as Record<string, unknown> | undefined) ?? {}).length} configured
|
||||
</span>
|
||||
</div>
|
||||
<Edit className={`h-4 w-4 transition-transform ${expandedSections.mcp ? 'rotate-90' : ''}`} />
|
||||
|
||||
@@ -30,8 +30,22 @@ export function VersionSelectDialog({ open, onOpenChange }: VersionSelectDialogP
|
||||
showToast.success(result.message)
|
||||
onOpenChange(false)
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to install version')
|
||||
onError: (error) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode-versions'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['server-health'] })
|
||||
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { recovered?: boolean; recoveryMessage?: string; newVersion?: string } } }).response
|
||||
const data = response?.data
|
||||
|
||||
if (data?.recovered) {
|
||||
showToast.success(`Install failed but server recovered at v${data.newVersion}`)
|
||||
} else {
|
||||
showToast.error(data?.recoveryMessage || 'Failed to install version')
|
||||
}
|
||||
} else {
|
||||
showToast.error('Failed to install version')
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useMessages } from './useOpenCode'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useSessionAgent } from './useSessionAgent'
|
||||
import { useModelSelection } from './useModelSelection'
|
||||
|
||||
interface ContextUsage {
|
||||
@@ -43,11 +42,8 @@ async function fetchProviders(opcodeUrl: string): Promise<ProvidersResponse> {
|
||||
|
||||
export const useContextUsage = (opcodeUrl: string | null | undefined, sessionID: string | undefined, directory?: string): ContextUsage => {
|
||||
const { data: messages, isLoading: messagesLoading } = useMessages(opcodeUrl, sessionID, directory)
|
||||
const sessionAgent = useSessionAgent(opcodeUrl, sessionID, directory)
|
||||
const { modelString: globalModelString } = useModelSelection(opcodeUrl, directory)
|
||||
const modelString = sessionAgent.model
|
||||
? `${sessionAgent.model.providerID}/${sessionAgent.model.modelID}`
|
||||
: globalModelString
|
||||
const modelString = globalModelString
|
||||
|
||||
const { data: providersData } = useQuery({
|
||||
queryKey: ['providers', opcodeUrl],
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { invalidateConfigCaches, invalidateSettingsCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
interface HealthResponse {
|
||||
status: 'healthy' | 'degraded' | 'unhealthy'
|
||||
@@ -34,8 +33,7 @@ export function useServerHealth(enabled = true) {
|
||||
return await settingsApi.reloadOpenCodeConfig()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
toast.success('Server configuration reloaded successfully')
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
@@ -53,9 +51,7 @@ export function useServerHealth(enabled = true) {
|
||||
return await settingsApi.rollbackOpenCodeConfig()
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['settings'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
invalidateSettingsCaches(queryClient)
|
||||
toast.success(data.message)
|
||||
},
|
||||
onError: () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
|
||||
export function useSettings(userId = 'default') {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -43,8 +44,8 @@ export function useSettings(userId = 'default') {
|
||||
}
|
||||
},
|
||||
onSettled: () => {
|
||||
// Refetch to ensure server state
|
||||
queryClient.invalidateQueries({ queryKey: ['settings', userId] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { QueryClient } from '@tanstack/react-query'
|
||||
|
||||
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'] })
|
||||
}
|
||||
|
||||
export function invalidateSettingsCaches(queryClient: QueryClient, userId = 'default') {
|
||||
queryClient.invalidateQueries({ queryKey: ['settings', userId] })
|
||||
invalidateConfigCaches(queryClient)
|
||||
}
|
||||
|
||||
export function invalidateSessionCaches(queryClient: QueryClient) {
|
||||
queryClient.invalidateQueries({
|
||||
predicate: (query) =>
|
||||
query.queryKey[0] === 'opencode' &&
|
||||
(query.queryKey[1] === 'sessions' ||
|
||||
query.queryKey[1] === 'session' ||
|
||||
query.queryKey[1] === 'messages'),
|
||||
})
|
||||
}
|
||||
|
||||
export function invalidateAllConfigRelatedCaches(queryClient: QueryClient, userId = 'default') {
|
||||
invalidateSettingsCaches(queryClient, userId)
|
||||
invalidateSessionCaches(queryClient)
|
||||
}
|
||||
Reference in new issue
Block a user