From 6665c4fc5f1a204d0b3b031d995d6e32c743340d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Mon, 16 Mar 2026 19:24:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20#89=20stripUiFields=E6=B8=85=E7=90=86ver?= =?UTF-8?q?sion=20info=E6=A0=B9=E5=AD=97=E6=AE=B5,=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E6=B1=A1=E6=9F=93openclaw.json=E5=AF=BC=E8=87=B4Gateway?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/dev-api.js | 32 ++++++++++++++++++++++---------- src-tauri/src/commands/config.rs | 18 ++++++++++++++++-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/scripts/dev-api.js b/scripts/dev-api.js index a46790a..cb42623 100644 --- a/scripts/dev-api.js +++ b/scripts/dev-api.js @@ -560,17 +560,29 @@ function getUid() { } function stripUiFields(config) { + // 清理根层级 ClawPanel 内部字段(version info 等),避免污染 openclaw.json + // Issue #89: 这些字段被写入 openclaw.json 后导致 Gateway 无法启动(Unknown config keys) + const uiRootKeys = [ + 'current', 'latest', 'recommended', 'update_available', + 'latest_update_available', 'is_recommended', 'ahead_of_recommended', + 'panel_version', 'source', + ] + for (const key of uiRootKeys) { + delete config[key] + } + // 清理模型测试相关的临时字段 const providers = config?.models?.providers - if (!providers) return config - for (const p of Object.values(providers)) { - if (!Array.isArray(p.models)) continue - for (const m of p.models) { - if (typeof m !== 'object') continue - delete m.lastTestAt - delete m.latency - delete m.testStatus - delete m.testError - if (!m.name && m.id) m.name = m.id + if (providers) { + for (const p of Object.values(providers)) { + if (!Array.isArray(p.models)) continue + for (const m of p.models) { + if (typeof m !== 'object') continue + delete m.lastTestAt + delete m.latency + delete m.testStatus + delete m.testError + if (!m.name && m.id) m.name = m.id + } } } return config diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index 225e9c1..dc8c5c7 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -565,10 +565,24 @@ fn has_ui_fields(val: &Value) -> bool { false } -/// 递归清理 models 数组中的 UI 专属字段(lastTestAt, latency, testStatus, testError) -/// 并为缺少 name 字段的模型自动补上 name = id +/// 清理 ClawPanel 内部字段,避免污染 openclaw.json 导致 Gateway 启动失败 +/// Issue #89: version info 字段被写入 openclaw.json → Unknown config keys fn strip_ui_fields(mut val: Value) -> Value { if let Some(obj) = val.as_object_mut() { + // 清理根层级 ClawPanel 内部字段(version info 等) + for key in &[ + "current", + "latest", + "recommended", + "update_available", + "latest_update_available", + "is_recommended", + "ahead_of_recommended", + "panel_version", + "source", + ] { + obj.remove(*key); + } // 处理 models.providers.xxx.models 结构 if let Some(models_val) = obj.get_mut("models") { if let Some(models_obj) = models_val.as_object_mut() {