Add log level configuration support (#272)

Add log level configuration support via config.yaml and UI settings.

---------

Co-authored-by: Shantur Rathore <i@shantur.com>
This commit is contained in:
bluelovers
2026-04-02 18:12:33 +08:00
committed by GitHub
parent e82e529a8f
commit 893d5f9296
14 changed files with 235 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ export type DiffViewMode = "split" | "unified"
export type ExpansionPreference = "expanded" | "collapsed"
export type ToolInputsVisibilityPreference = "hidden" | "collapsed" | "expanded"
export type ListeningMode = "local" | "all"
export type ServerLogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR"
export type SpeechProviderPreference = "openai-compatible"
export type SpeechPlaybackMode = "streaming" | "buffered"
export type SpeechTtsFormat = "mp3" | "wav" | "opus" | "aac"
@@ -94,6 +95,7 @@ interface UiConfigBucket {
interface ServerConfigBucket {
listeningMode?: ListeningMode
logLevel?: ServerLogLevel
environmentVariables?: Record<string, string>
opencodeBinary?: string
speech?: Partial<SpeechSettings>
@@ -272,13 +274,17 @@ function normalizeUiState(input?: UiStateBucket | null): NormalizedUiState {
function normalizeServerConfig(
input?: ServerConfigBucket | null,
): Required<Pick<ServerConfigBucket, "listeningMode" | "environmentVariables" | "opencodeBinary">> & { speech: SpeechSettings } {
): Required<Pick<ServerConfigBucket, "listeningMode" | "logLevel" | "environmentVariables" | "opencodeBinary">> & { speech: SpeechSettings } {
const source = input ?? {}
const listeningMode = source.listeningMode === "all" ? "all" : "local"
const logLevel =
source.logLevel === "INFO" || source.logLevel === "WARN" || source.logLevel === "ERROR" || source.logLevel === "DEBUG"
? source.logLevel
: "DEBUG"
const opencodeBinary = typeof source.opencodeBinary === "string" && source.opencodeBinary.trim() ? source.opencodeBinary : "opencode"
const environmentVariables = normalizeRecord(source.environmentVariables)
const speech = normalizeSpeechSettings(source.speech)
return { listeningMode, opencodeBinary, environmentVariables, speech }
return { listeningMode, logLevel, opencodeBinary, environmentVariables, speech }
}
function getModelKey(model: { providerId: string; modelId: string }): string {
@@ -409,6 +415,11 @@ function updateLastUsedBinary(path: string): void {
void patchStateOwner("ui", { opencodeBinaries: nextList }).catch((error) => log.error("Failed to update binary list", error))
}
function updateLogLevel(level: ServerLogLevel): void {
const target = level ?? "DEBUG"
void patchConfigOwner("server", { logLevel: target }).catch((error) => log.error("Failed to set log level", error))
}
async function updateSpeechSettings(updates: SpeechSettingsUpdate): Promise<void> {
const apiKeyPatch = updates.apiKey
const { apiKey: _apiKey, ...restUpdates } = updates
@@ -612,8 +623,9 @@ interface ConfigContextValue {
updateEnvironmentVariables: typeof updateEnvironmentVariables
addEnvironmentVariable: typeof addEnvironmentVariable
removeEnvironmentVariable: typeof removeEnvironmentVariable
updateLastUsedBinary: typeof updateLastUsedBinary
updateSpeechSettings: typeof updateSpeechSettings
updateLastUsedBinary: typeof updateLastUsedBinary
updateLogLevel: typeof updateLogLevel
updateSpeechSettings: typeof updateSpeechSettings
// ui-owned state
recentFolders: typeof recentFolders
@@ -663,6 +675,7 @@ const configContextValue: ConfigContextValue = {
addEnvironmentVariable,
removeEnvironmentVariable,
updateLastUsedBinary,
updateLogLevel,
updateSpeechSettings,
recentFolders,
opencodeBinaries,
@@ -746,6 +759,7 @@ export {
addEnvironmentVariable,
removeEnvironmentVariable,
updateLastUsedBinary,
updateLogLevel,
updateSpeechSettings,
addRecentFolder,
removeRecentFolder,