fix(memory): respect memory slot in dreaming config

This commit is contained in:
sky
2026-04-07 11:36:24 +08:00
committed by Vignesh
parent 24d4acb274
commit 9dda94c0f7
6 changed files with 210 additions and 12 deletions

View File

@@ -14,7 +14,8 @@ vi.mock("../agents/agent-scope.js", () => ({
import {
formatMemoryDreamingDay,
isSameMemoryDreamingDay,
resolveMemoryCorePluginConfig,
resolveMemoryDreamingPluginConfig,
resolveMemoryDreamingPluginId,
resolveMemoryDreamingConfig,
resolveMemoryDreamingWorkspaces,
} from "./dreaming.js";
@@ -156,7 +157,38 @@ describe("memory dreaming host helpers", () => {
),
).toBe(true);
expect(
resolveMemoryCorePluginConfig({
resolveMemoryDreamingPluginId({
plugins: {
slots: {
memory: "memos-local-openclaw-plugin",
},
},
} as OpenClawConfig),
).toBe("memos-local-openclaw-plugin");
expect(
resolveMemoryDreamingPluginConfig({
plugins: {
slots: {
memory: "memos-local-openclaw-plugin",
},
entries: {
"memos-local-openclaw-plugin": {
config: {
dreaming: {
enabled: true,
},
},
},
},
},
} as OpenClawConfig),
).toEqual({
dreaming: {
enabled: true,
},
});
expect(
resolveMemoryDreamingPluginConfig({
plugins: {
entries: {
"memory-core": {

View File

@@ -9,6 +9,7 @@ export const DEFAULT_MEMORY_DREAMING_VERBOSE_LOGGING = false;
export const DEFAULT_MEMORY_DREAMING_STORAGE_MODE = "inline";
export const DEFAULT_MEMORY_DREAMING_SEPARATE_REPORTS = false;
export const DEFAULT_MEMORY_DREAMING_FREQUENCY = "0 3 * * *";
export const DEFAULT_MEMORY_DREAMING_PLUGIN_ID = "memory-core";
export const DEFAULT_MEMORY_LIGHT_DREAMING_CRON_EXPR = "0 */6 * * *";
export const DEFAULT_MEMORY_LIGHT_DREAMING_LOOKBACK_DAYS = 2;
@@ -308,16 +309,33 @@ function formatLocalIsoDay(epochMs: number): string {
return `${year}-${month}-${day}`;
}
export function resolveMemoryCorePluginConfig(
export function resolveMemoryDreamingPluginId(
cfg: OpenClawConfig | Record<string, unknown> | undefined,
): string {
const root = asNullableRecord(cfg);
const plugins = asNullableRecord(root?.plugins);
const slots = asNullableRecord(plugins?.slots);
const configuredSlot = normalizeTrimmedString(slots?.memory);
if (configuredSlot && configuredSlot.toLowerCase() !== "none") {
return configuredSlot;
}
return DEFAULT_MEMORY_DREAMING_PLUGIN_ID;
}
export function resolveMemoryDreamingPluginConfig(
cfg: OpenClawConfig | Record<string, unknown> | undefined,
): Record<string, unknown> | undefined {
const root = asNullableRecord(cfg);
const plugins = asNullableRecord(root?.plugins);
const entries = asNullableRecord(plugins?.entries);
const memoryCore = asNullableRecord(entries?.["memory-core"]);
return asNullableRecord(memoryCore?.config) ?? undefined;
const pluginId = resolveMemoryDreamingPluginId(cfg);
const memoryPlugin = asNullableRecord(entries?.[pluginId]);
return asNullableRecord(memoryPlugin?.config) ?? undefined;
}
// Keep the legacy helper name exported until downstream memory plugins migrate.
export const resolveMemoryCorePluginConfig = resolveMemoryDreamingPluginConfig;
export function resolveMemoryDreamingConfig(params: {
pluginConfig?: Record<string, unknown>;
cfg?: OpenClawConfig;