mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 00:14:34 +00:00
refactor(models): reuse validated config snapshot loader
This commit is contained in:
@@ -59,15 +59,20 @@ export const isLocalBaseUrl = (baseUrl: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export async function updateConfig(
|
||||
mutator: (cfg: OpenClawConfig) => OpenClawConfig,
|
||||
): Promise<OpenClawConfig> {
|
||||
export async function loadValidConfigOrThrow(): Promise<OpenClawConfig> {
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
if (!snapshot.valid) {
|
||||
const issues = snapshot.issues.map((issue) => `- ${issue.path}: ${issue.message}`).join("\n");
|
||||
throw new Error(`Invalid config at ${snapshot.path}\n${issues}`);
|
||||
}
|
||||
const next = mutator(snapshot.config);
|
||||
return snapshot.config;
|
||||
}
|
||||
|
||||
export async function updateConfig(
|
||||
mutator: (cfg: OpenClawConfig) => OpenClawConfig,
|
||||
): Promise<OpenClawConfig> {
|
||||
const config = await loadValidConfigOrThrow();
|
||||
const next = mutator(config);
|
||||
await writeConfigFile(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user