feat: ensure searxng config on reconnect if missing/changed; bump to 1.3.3
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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) {
|
||||
// 模型未变,但仍检查 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user