mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:30:45 +00:00
refactor(config): migrate plugin config access
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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." };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user