refactor(config): migrate plugin config access

This commit is contained in:
Peter Steinberger
2026-04-27 12:16:48 +01:00
parent 48ebed3ed3
commit 7f3f108521
531 changed files with 3502 additions and 1646 deletions

View File

@@ -90,7 +90,13 @@ describe("active-memory plugin", () => {
resolveStateDir: () => stateDir,
},
config: {
current: () => configFile,
loadConfig: () => configFile,
replaceConfigFile: vi.fn(
async ({ nextConfig }: { nextConfig: Record<string, unknown> }) => {
configFile = nextConfig;
},
),
writeConfigFile: vi.fn(async (nextConfig: Record<string, unknown>) => {
configFile = nextConfig;
}),
@@ -275,7 +281,7 @@ describe("active-memory plugin", () => {
});
expect(offResult.text).toBe("Active Memory: off globally.");
expect(api.runtime.config.writeConfigFile).toHaveBeenCalledTimes(1);
expect(api.runtime.config.replaceConfigFile).toHaveBeenCalledTimes(1);
expect(configFile).toMatchObject({
plugins: {
entries: {

View File

@@ -1932,7 +1932,9 @@ export default definePluginEntry({
warnDeprecatedModelFallbackPolicy(api.pluginConfig);
const refreshLiveConfigFromRuntime = () => {
const livePluginConfig = resolveLivePluginConfigObject(
api.runtime.config?.loadConfig,
api.runtime.config?.current
? () => api.runtime.config.current() as OpenClawConfig
: undefined,
"active-memory",
api.pluginConfig as Record<string, unknown>,
);
@@ -1953,7 +1955,7 @@ export default definePluginEntry({
return { text: formatActiveMemoryCommandHelp() };
}
if (isGlobal) {
const currentConfig = api.runtime.config.loadConfig();
const currentConfig = api.runtime.config.current() as OpenClawConfig;
if (action === "status") {
return {
text: `Active Memory: ${isActiveMemoryGloballyEnabled(currentConfig) ? "on" : "off"} globally.`,
@@ -1961,13 +1963,19 @@ export default definePluginEntry({
}
if (action === "on" || action === "enable" || action === "enabled") {
const nextConfig = updateActiveMemoryGlobalEnabledInConfig(currentConfig, true);
await api.runtime.config.writeConfigFile(nextConfig);
await api.runtime.config.replaceConfigFile({
nextConfig,
afterWrite: { mode: "auto" },
});
refreshLiveConfigFromRuntime();
return { text: "Active Memory: on globally." };
}
if (action === "off" || action === "disable" || action === "disabled") {
const nextConfig = updateActiveMemoryGlobalEnabledInConfig(currentConfig, false);
await api.runtime.config.writeConfigFile(nextConfig);
await api.runtime.config.replaceConfigFile({
nextConfig,
afterWrite: { mode: "auto" },
});
refreshLiveConfigFromRuntime();
return { text: "Active Memory: off globally." };
}