feat: write searxng config via .env + openclaw.json on activation/reconnect; bump to 1.3.4
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -125,14 +125,6 @@ function removeProviderByName(providerId) {
|
||||
delete config.auth.profiles[`${providerId}:default`];
|
||||
}
|
||||
|
||||
// web search: 解绑时精确删除 searxng 相关配置
|
||||
if (config.plugins?.entries?.searxng) {
|
||||
delete config.plugins.entries.searxng;
|
||||
}
|
||||
if (config.tools?.web?.search?.provider === 'searxng') {
|
||||
delete config.tools.web.search;
|
||||
}
|
||||
|
||||
writeJsonFile(configFile, config);
|
||||
log.info('openclaw-provider', `provider 已移除: ${providerId}`);
|
||||
}
|
||||
@@ -155,28 +147,59 @@ function removeProviderFromConfig(config, providerId) {
|
||||
const WEB_SEARCH_BASE_URL = 'https://web-search.cutos.ai/';
|
||||
|
||||
/**
|
||||
* 检查并补全 searxng web search 配置,返回 true 表示有修改。
|
||||
* 激活和重连时均调用,确保配置存在且正确。
|
||||
* 写入 .env 中的 KEY=value,已存在相同行则跳过,存在不同值则替换,不存在则追加。
|
||||
*/
|
||||
function ensureWebSearchConfig(config) {
|
||||
function ensureEnvVar(envFile, key, value) {
|
||||
const line = `${key}="${value}"`;
|
||||
let content = '';
|
||||
try { content = fs.readFileSync(envFile, 'utf8'); } catch (_) {}
|
||||
|
||||
const re = new RegExp(`^${key}=.*`, 'm');
|
||||
if (re.test(content)) {
|
||||
const updated = content.replace(re, line);
|
||||
if (updated !== content) {
|
||||
fs.writeFileSync(envFile, updated, 'utf8');
|
||||
}
|
||||
} else {
|
||||
const sep = content.length && !content.endsWith('\n') ? '\n' : '';
|
||||
fs.writeFileSync(envFile, content + sep + line + '\n', 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并补全 searxng web search 配置(openclaw.json),返回 true 表示有修改。
|
||||
*/
|
||||
function ensureWebSearchConfig(configFile, config) {
|
||||
let dirty = false;
|
||||
const expectedSearch = { provider: 'searxng' };
|
||||
const expectedSearxng = { config: { webSearch: { baseUrl: WEB_SEARCH_BASE_URL } } };
|
||||
|
||||
// .env: SEARXNG_BASE_URL
|
||||
try {
|
||||
const envFile = path.join(path.dirname(configFile), '.env');
|
||||
ensureEnvVar(envFile, 'SEARXNG_BASE_URL', WEB_SEARCH_BASE_URL);
|
||||
} catch (e) {
|
||||
log.warn('openclaw-provider', `ensureEnvVar failed: ${e.message}`);
|
||||
}
|
||||
|
||||
// tools.web.search / tools.web.fetch
|
||||
const curSearch = config.tools?.web?.search;
|
||||
const curSearxng = config.plugins?.entries?.searxng;
|
||||
|
||||
if (!curSearch || curSearch.provider !== 'searxng') {
|
||||
const curFetch = config.tools?.web?.fetch;
|
||||
if (!curSearch?.openaiCodex || curFetch?.enabled !== true) {
|
||||
if (!config.tools) config.tools = {};
|
||||
if (!config.tools.web) config.tools.web = {};
|
||||
config.tools.web.search = expectedSearch;
|
||||
config.tools.web.search = { openaiCodex: {} };
|
||||
config.tools.web.fetch = { enabled: true };
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (!curSearxng || curSearxng.config?.webSearch?.baseUrl !== WEB_SEARCH_BASE_URL) {
|
||||
// plugins.entries.searxng
|
||||
const cur = config.plugins?.entries?.searxng;
|
||||
if (!cur || cur.enabled !== true || cur.config?.webSearch?.baseUrl !== WEB_SEARCH_BASE_URL) {
|
||||
if (!config.plugins) config.plugins = {};
|
||||
if (!config.plugins.entries) config.plugins.entries = {};
|
||||
config.plugins.entries.searxng = expectedSearxng;
|
||||
config.plugins.entries.searxng = {
|
||||
config: { webSearch: { baseUrl: WEB_SEARCH_BASE_URL } },
|
||||
enabled: true,
|
||||
};
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@@ -226,7 +249,7 @@ function addProviderSync(configFile, providerId, baseUrl, apiKey, models, defaul
|
||||
mode: 'api_key',
|
||||
};
|
||||
|
||||
ensureWebSearchConfig(config);
|
||||
ensureWebSearchConfig(configFile, config);
|
||||
|
||||
writeJsonFile(configFile, config);
|
||||
log.info('openclaw-provider', `provider 已写入: ${providerId}(${models.length} 个模型)`);
|
||||
@@ -364,12 +387,12 @@ function refreshModelsIfChanged(onDone) {
|
||||
const newMd5 = computeModelsMd5(newModels);
|
||||
|
||||
if (currentMd5 === newMd5) {
|
||||
// 模型未变,但仍检查 searxng 配置是否缺失或过期
|
||||
// 模型未变,但仍检查 web search 配置是否缺失或过期
|
||||
try {
|
||||
const cfg = readJsonFile(configFile);
|
||||
if (ensureWebSearchConfig(cfg)) {
|
||||
if (ensureWebSearchConfig(configFile, cfg)) {
|
||||
writeJsonFile(configFile, cfg);
|
||||
log.info('openclaw-provider', 'searxng web search config repaired');
|
||||
log.info('openclaw-provider', 'web search config repaired');
|
||||
} else {
|
||||
log.info('openclaw-provider', `模型列表未变化(${newModels.length} 个),跳过更新`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "clawd",
|
||||
"version": "1.3.3",
|
||||
"version": "1.3.4",
|
||||
"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