fix: clawd 不再写 agents/main/agent/auth-profiles.json
clawd 以 root 身份运行,写该目录会导致 gateway(sts 用户)的 agents 目录被 root 创建。 clawd 只需修改 openclaw.json,gateway 重启后会自行读取,无需操作 gateway 内部目录。 Made-with: Cursor
This commit is contained in:
@@ -31,10 +31,6 @@ function restartGateway() {
|
||||
});
|
||||
}
|
||||
|
||||
function authProfilesPathFromConfig(configFile) {
|
||||
return path.join(path.dirname(configFile), 'agents', 'main', 'agent', 'auth-profiles.json');
|
||||
}
|
||||
|
||||
function buildModelsUrl(baseUrl) {
|
||||
let u = String(baseUrl || '').trim().replace(/\/+$/, '');
|
||||
if (!/\/v1$/.test(u)) u = `${u}/v1`;
|
||||
@@ -105,7 +101,7 @@ function writeJsonFile(filePath, obj) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步:从 openclaw.json + auth-profiles.json 删除指定 provider(解绑)。
|
||||
* 同步:从 openclaw.json 删除指定 provider(解绑)。
|
||||
* 若 primary 指向该 provider,先置为空串。
|
||||
*/
|
||||
function removeProviderByName(providerId) {
|
||||
@@ -146,20 +142,6 @@ function removeProviderByName(providerId) {
|
||||
}
|
||||
|
||||
writeJsonFile(configFile, config);
|
||||
|
||||
const authPath = authProfilesPathFromConfig(configFile);
|
||||
try {
|
||||
if (fs.existsSync(authPath)) {
|
||||
const authProfiles = readJsonFile(authPath);
|
||||
if (authProfiles.profiles?.[`${providerId}:default`]) {
|
||||
delete authProfiles.profiles[`${providerId}:default`];
|
||||
writeJsonFile(authPath, authProfiles);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn('openclaw-provider', `auth-profiles 更新失败: ${e.message}`);
|
||||
}
|
||||
|
||||
log.info('openclaw-provider', `provider 已移除: ${providerId}`);
|
||||
restartGateway();
|
||||
}
|
||||
@@ -223,24 +205,6 @@ function addProviderSync(configFile, providerId, baseUrl, apiKey, models, defaul
|
||||
};
|
||||
|
||||
writeJsonFile(configFile, config);
|
||||
|
||||
const authPath = authProfilesPathFromConfig(configFile);
|
||||
try {
|
||||
let authProfiles = { profiles: {} };
|
||||
if (fs.existsSync(authPath)) {
|
||||
authProfiles = readJsonFile(authPath);
|
||||
if (!authProfiles.profiles) authProfiles.profiles = {};
|
||||
}
|
||||
authProfiles.profiles[`${providerId}:default`] = {
|
||||
type: 'api_key',
|
||||
provider: providerId,
|
||||
key: apiKey,
|
||||
};
|
||||
writeJsonFile(authPath, authProfiles);
|
||||
} catch (e) {
|
||||
log.warn('openclaw-provider', `auth-profiles 写入失败: ${e.message}`);
|
||||
}
|
||||
|
||||
log.info('openclaw-provider', `provider 已写入: ${providerId}(${models.length} 个模型)`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user