From f61a0a4305282868d324a4bd52214a59ca438621 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Tue, 5 May 2026 18:46:17 +0800 Subject: [PATCH] feat: ensure searxng config on reconnect if missing/changed; bump to 1.3.3 Co-authored-by: Cursor --- lib/openclaw-provider.js | 53 +++++++++++++++++++++++++++++++--------- package.json | 2 +- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/lib/openclaw-provider.js b/lib/openclaw-provider.js index b5bb654..8d9ba59 100644 --- a/lib/openclaw-provider.js +++ b/lib/openclaw-provider.js @@ -152,6 +152,37 @@ function removeProviderFromConfig(config, providerId) { } } +const WEB_SEARCH_BASE_URL = 'https://web-search.cutos.ai/'; + +/** + * 检查并补全 searxng web search 配置,返回 true 表示有修改。 + * 激活和重连时均调用,确保配置存在且正确。 + */ +function ensureWebSearchConfig(config) { + let dirty = false; + const expectedSearch = { provider: 'searxng' }; + const expectedSearxng = { config: { webSearch: { baseUrl: WEB_SEARCH_BASE_URL } } }; + + const curSearch = config.tools?.web?.search; + const curSearxng = config.plugins?.entries?.searxng; + + if (!curSearch || curSearch.provider !== 'searxng') { + if (!config.tools) config.tools = {}; + if (!config.tools.web) config.tools.web = {}; + config.tools.web.search = expectedSearch; + dirty = true; + } + + if (!curSearxng || curSearxng.config?.webSearch?.baseUrl !== WEB_SEARCH_BASE_URL) { + if (!config.plugins) config.plugins = {}; + if (!config.plugins.entries) config.plugins.entries = {}; + config.plugins.entries.searxng = expectedSearxng; + dirty = true; + } + + return dirty; +} + function addProviderSync(configFile, providerId, baseUrl, apiKey, models, defaultModelRaw) { const config = readJsonFile(configFile); @@ -195,16 +226,7 @@ function addProviderSync(configFile, providerId, baseUrl, apiKey, models, defaul mode: 'api_key', }; - // web search: 激活时强制写入 searxng 配置 - if (!config.tools) config.tools = {}; - if (!config.tools.web) config.tools.web = {}; - config.tools.web.search = { provider: 'searxng' }; - - if (!config.plugins) config.plugins = {}; - if (!config.plugins.entries) config.plugins.entries = {}; - config.plugins.entries.searxng = { - config: { webSearch: { baseUrl: 'https://web-search.cutos.ai/' } }, - }; + ensureWebSearchConfig(config); writeJsonFile(configFile, config); log.info('openclaw-provider', `provider 已写入: ${providerId}(${models.length} 个模型)`); @@ -342,7 +364,16 @@ function refreshModelsIfChanged(onDone) { const newMd5 = computeModelsMd5(newModels); if (currentMd5 === newMd5) { - log.info('openclaw-provider', `模型列表未变化(${newModels.length} 个),跳过更新`); + // 模型未变,但仍检查 searxng 配置是否缺失或过期 + try { + const cfg = readJsonFile(configFile); + if (ensureWebSearchConfig(cfg)) { + writeJsonFile(configFile, cfg); + log.info('openclaw-provider', 'searxng web search config repaired'); + } else { + log.info('openclaw-provider', `模型列表未变化(${newModels.length} 个),跳过更新`); + } + } catch (_) {} return; } diff --git a/package.json b/package.json index cd58a7e..8621610 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clawd", - "version": "1.3.2", + "version": "1.3.3", "description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket", "main": "lib/client.js", "bin": {