mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor: replace OpenCode server restarts with config reloads for faster updates (#70)
This commit is contained in:
1 parent
8be0bbd8a0
commit
2bd2b024b8
11 files changed
+183
-107
No files matched your search
@@ -103,6 +103,19 @@ export const settingsApi = {
|
||||
return data
|
||||
},
|
||||
|
||||
reloadOpenCodeConfig: async (): Promise<{ success: boolean; message: string; details?: string }> => {
|
||||
try {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-reload`)
|
||||
return data
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response?.status === 404) {
|
||||
const result = await axios.post(`${API_BASE_URL}/api/settings/opencode-restart`)
|
||||
return result.data
|
||||
}
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
rollbackOpenCodeConfig: async (): Promise<{ success: boolean; message: string; configName?: string }> => {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-rollback`)
|
||||
return data
|
||||
|
||||
@@ -419,19 +419,20 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as { MSStream?: boolean }).MSStream
|
||||
const isSecureContext = window.isSecureContext || (window.location.protocol === 'http:' && window.location.hostname === 'localhost')
|
||||
|
||||
if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) {
|
||||
if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText()
|
||||
if (text && text.trim()) {
|
||||
return
|
||||
}
|
||||
} catch (err) {
|
||||
} catch {
|
||||
}
|
||||
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
try {
|
||||
const clipboardItems = await navigator.clipboard.read()
|
||||
|
||||
|
||||
for (const item of clipboardItems) {
|
||||
for (const type of item.types) {
|
||||
if (ACCEPTED_FILE_TYPES.includes(type) || type.startsWith('image/')) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogFooter, DialogTitle } from '@/components/ui/dialog'
|
||||
import type { OpenCodeConfig } from '@/api/types/settings'
|
||||
import { parseJsonc } from '@/lib/jsonc'
|
||||
|
||||
@@ -66,60 +66,59 @@ export function OpenCodeConfigEditor({
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOpen || !config) return null
|
||||
if (!config) return null
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-background/80 backdrop-blur-sm">
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
<div className="relative w-full max-w-6xl h-[90vh] bg-background border rounded-lg shadow-lg">
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="flex items-center justify-between p-6 border-b">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Edit Config: {config.name}</h2>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={updateConfig}
|
||||
disabled={isUpdating || !editConfigContent.trim()}
|
||||
>
|
||||
{isUpdating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Update
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent mobileFullscreen className="h-[90vh] max-w-6xl gap-0 flex flex-col p-0 sm:p-6">
|
||||
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
|
||||
<DialogTitle className="text-lg sm:text-xl font-semibold">
|
||||
{`Edit Config: ${config.name}`}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex-1 p-6 overflow-hidden">
|
||||
<div className="h-full flex flex-col">
|
||||
<Label htmlFor="edit-config-content" className="mb-2">
|
||||
Config Content (JSON/JSONC)
|
||||
</Label>
|
||||
<Textarea
|
||||
id="edit-config-content"
|
||||
ref={editTextareaRef}
|
||||
value={editConfigContent}
|
||||
onChange={(e) => {
|
||||
setEditConfigContent(e.target.value)
|
||||
setEditError('')
|
||||
setEditErrorLine(null)
|
||||
}}
|
||||
className="flex-1 font-mono text-sm resize-none"
|
||||
/>
|
||||
{editError && (
|
||||
<p className="text-sm text-red-500 mt-2">
|
||||
{editError}
|
||||
{editErrorLine && (
|
||||
<span className="ml-2 text-xs">(Line {editErrorLine})</span>
|
||||
)}
|
||||
</p>
|
||||
<div className="flex-1 p-0 sm:p-4 overflow-hidden relative">
|
||||
<Textarea
|
||||
id="edit-config-content"
|
||||
ref={editTextareaRef}
|
||||
value={editConfigContent}
|
||||
onChange={(e) => {
|
||||
setEditConfigContent(e.target.value)
|
||||
setEditError('')
|
||||
setEditErrorLine(null)
|
||||
}}
|
||||
className="flex-1 font-mono text-xs sm:text-sm resize-none h-full rounded-none sm:rounded-md"
|
||||
/>
|
||||
{editError && (
|
||||
<div className="absolute bottom-0 left-0 right-0 bg-background/95 border-t p-2 sm:p-3">
|
||||
<p className="text-xs sm:text-sm text-red-500">
|
||||
{editError}
|
||||
{editErrorLine && (
|
||||
<span className="ml-2 text-xs">(Line {editErrorLine})</span>
|
||||
)}
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="p-3 sm:p-4 border-t gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
className="flex-1 sm:flex-none"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={updateConfig}
|
||||
disabled={isUpdating || !editConfigContent.trim()}
|
||||
className="flex-1 sm:flex-none"
|
||||
>
|
||||
{isUpdating && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
Update
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,15 @@ export function OpenCodeConfigManager() {
|
||||
}
|
||||
}
|
||||
|
||||
const reloadConfigMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
return await settingsApi.reloadOpenCodeConfig()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
},
|
||||
})
|
||||
|
||||
const restartServerMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
return await settingsApi.restartOpenCodeServer()
|
||||
@@ -160,10 +169,10 @@ export function OpenCodeConfigManager() {
|
||||
|
||||
const agentsChanged = JSON.stringify(previousContent?.agent) !== JSON.stringify(newContent.agent)
|
||||
if (restartServer || agentsChanged) {
|
||||
showToast.loading('Restarting server...', { id: 'update-restart' })
|
||||
showToast.loading('Reloading server...', { id: 'update-restart' })
|
||||
try {
|
||||
await restartServerMutation.mutateAsync()
|
||||
showToast.success('Configuration updated and server restarted', { id: 'update-restart' })
|
||||
await reloadConfigMutation.mutateAsync()
|
||||
showToast.success('Configuration updated and server reloaded', { id: 'update-restart' })
|
||||
} catch (error) {
|
||||
showToast.error(getRestartErrorMessage(error), { id: 'update-restart' })
|
||||
throw error
|
||||
@@ -214,10 +223,10 @@ export function OpenCodeConfigManager() {
|
||||
await fetchConfigs()
|
||||
|
||||
if (isDefault) {
|
||||
showToast.loading('Restarting server...', { id: 'create-config' })
|
||||
showToast.loading('Reloading server...', { id: 'create-config' })
|
||||
try {
|
||||
await restartServerMutation.mutateAsync()
|
||||
showToast.success('Configuration created and server restarted', { id: 'create-config' })
|
||||
await reloadConfigMutation.mutateAsync()
|
||||
showToast.success('Configuration created and server reloaded', { id: 'create-config' })
|
||||
} catch (error) {
|
||||
showToast.error(getRestartErrorMessage(error), { id: 'create-config' })
|
||||
throw error
|
||||
@@ -254,13 +263,13 @@ export function OpenCodeConfigManager() {
|
||||
}
|
||||
|
||||
const setDefaultConfig = async (config: OpenCodeConfig) => {
|
||||
showToast.loading('Setting default config and restarting server...', { id: 'set-default' })
|
||||
showToast.loading('Setting default config and reloading server...', { id: 'set-default' })
|
||||
try {
|
||||
setIsUpdating(true)
|
||||
await settingsApi.setDefaultOpenCodeConfig(config.name)
|
||||
await fetchConfigs()
|
||||
await restartServerMutation.mutateAsync()
|
||||
showToast.success('Default config updated and server restarted', { id: 'set-default' })
|
||||
await reloadConfigMutation.mutateAsync()
|
||||
showToast.success('Default config updated and server reloaded', { id: 'set-default' })
|
||||
} catch (error) {
|
||||
console.error('Failed to set default config:', error)
|
||||
const errorMessage = error && typeof error === 'object' && 'response' in error
|
||||
@@ -487,17 +496,12 @@ export function OpenCodeConfigManager() {
|
||||
if (!editingConfig) return
|
||||
showToast.loading('Saving configuration...', { id: 'edit-config' })
|
||||
try {
|
||||
const parsedContent = parseJsonc<Record<string, unknown>>(rawContent)
|
||||
const agentsChanged = JSON.stringify(editingConfig.content.agent) !== JSON.stringify(parsedContent.agent)
|
||||
await settingsApi.updateOpenCodeConfig(editingConfig.name, { content: rawContent })
|
||||
await fetchConfigs()
|
||||
if (agentsChanged) {
|
||||
showToast.loading('Restarting server...', { id: 'edit-config' })
|
||||
await restartServerMutation.mutateAsync()
|
||||
showToast.success('Config updated and server restarted', { id: 'edit-config' })
|
||||
} else {
|
||||
showToast.success('Configuration saved', { id: 'edit-config' })
|
||||
}
|
||||
const successMsg = editingConfig.isDefault
|
||||
? 'Configuration saved and server reloaded'
|
||||
: 'Configuration saved'
|
||||
showToast.success(successMsg, { id: 'edit-config' })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('restart')) {
|
||||
|
||||
@@ -10,14 +10,14 @@ import { subscribeToSSE, reconnectSSE, addSSEDirectory, removeSSEDirectory } fro
|
||||
import { parseOpenCodeError } from '@/lib/opencode-errors'
|
||||
|
||||
const handleRestartServer = async () => {
|
||||
showToast.loading('Restarting OpenCode server...', {
|
||||
showToast.loading('Reloading OpenCode configuration...', {
|
||||
id: 'restart-server',
|
||||
})
|
||||
|
||||
|
||||
try {
|
||||
const result = await settingsApi.restartOpenCodeServer()
|
||||
const result = await settingsApi.reloadOpenCodeConfig()
|
||||
if (result.success) {
|
||||
showToast.success(result.message || 'OpenCode server restarted successfully', {
|
||||
showToast.success(result.message || 'OpenCode configuration reloaded successfully', {
|
||||
id: 'restart-server',
|
||||
duration: 3000,
|
||||
})
|
||||
@@ -25,13 +25,13 @@ const handleRestartServer = async () => {
|
||||
window.location.reload()
|
||||
}, 2000)
|
||||
} else {
|
||||
showToast.error(result.message || 'Failed to restart OpenCode server', {
|
||||
showToast.error(result.message || 'Failed to reload OpenCode configuration', {
|
||||
id: 'restart-server',
|
||||
duration: 5000,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to restart OpenCode server', {
|
||||
showToast.error(error instanceof Error ? error.message : 'Failed to reload OpenCode configuration', {
|
||||
id: 'restart-server',
|
||||
duration: 5000,
|
||||
})
|
||||
@@ -282,7 +282,7 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string,
|
||||
showToast.info(`OpenCode v${event.properties.version} is available`, {
|
||||
description: 'A new version is ready to install.',
|
||||
action: {
|
||||
label: 'Restart to Update',
|
||||
label: 'Reload to Update',
|
||||
onClick: handleRestartServer
|
||||
},
|
||||
duration: 10000,
|
||||
|
||||
@@ -31,19 +31,19 @@ export function useServerHealth(enabled = true) {
|
||||
|
||||
const restartMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
return await settingsApi.restartOpenCodeServer()
|
||||
return await settingsApi.reloadOpenCodeConfig()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['health'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
toast.success('Server restarted successfully')
|
||||
toast.success('Server configuration reloaded successfully')
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
const errorMessage = error && typeof error === 'object' && 'response' in error
|
||||
? ((error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.details
|
||||
|| (error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.error
|
||||
|| 'Failed to restart server')
|
||||
: 'Failed to restart server'
|
||||
|| 'Failed to reload configuration')
|
||||
: 'Failed to reload configuration'
|
||||
toast.error(errorMessage)
|
||||
},
|
||||
})
|
||||
@@ -81,7 +81,7 @@ export function useServerHealth(enabled = true) {
|
||||
toast.error(health.error || 'OpenCode server is currently unhealthy', {
|
||||
duration: Infinity,
|
||||
action: {
|
||||
label: 'Restart',
|
||||
label: 'Reload',
|
||||
onClick: () => restartMutation.mutate(),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user