fix: read config from file for reload and improve provider validation

- Change reloadConfig to read from opencode.json file instead of HTTP API
- Add logging for OpenCode PATCH responses to aid debugging
- Make providerId optional in schema with custom validation when needed
- Update test to mock fs.readFile instead of fetch
This commit is contained in:
Chris Scott committed 2026-04-13 21:44:39 -04:00
1 parent 1f55bcdfc2
commit 8cfc6c0a17
5 files changed
+24 -35

No files matched your search

+5 -11
View File
@@ -384,18 +384,12 @@ class OpenCodeServerManager {
async reloadConfig(): Promise<void> {
logger.info('Reloading OpenCode configuration (via API)')
try {
const response = await fetch(`http://${OPENCODE_SERVER_HOST}:${OPENCODE_SERVER_PORT}/config`, {
method: 'GET'
})
const configPath = getOpenCodeConfigFilePath()
const fileContent = await fs.readFile(configPath, 'utf-8')
const fileConfig = JSON.parse(fileContent) as Record<string, unknown>
logger.info(`Read config from file for reload: ${configPath}`)
if (!response.ok) {
throw new Error(`Failed to get current config: ${response.status}`)
}
const currentConfig = await response.json() as Record<string, unknown>
logger.info('Triggering OpenCode config reload via PATCH')
const patchResult = await patchOpenCodeConfig(currentConfig)
const patchResult = await patchOpenCodeConfig(fileConfig)
if (!patchResult.success) {
const errorMessage = patchResult.error || 'Failed to reload config'
const validationIssues = patchResult.details || []
+2 -1
View File
@@ -197,8 +197,9 @@ export async function patchOpenCodeConfig(config: Record<string, unknown>): Prom
}
const responseText = await response.text()
logger.warn(`OpenCode PATCH response (${response.status}): ${responseText.slice(0, 500)}`)
const { details, errorMessage: initialError } = parseErrorResponse(responseText)
if (details.length === 0) {
logger.error(`Failed to patch OpenCode config: ${initialError}`)
return { success: false, error: initialError, details }