mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 15:20:21 +00:00
fix(memory): respect memory slot in dreaming config
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
loadDreamDiary,
|
||||
loadDreamingStatus,
|
||||
resolveConfiguredDreaming,
|
||||
updateDreamingEnabled,
|
||||
type DreamingState,
|
||||
} from "./dreaming.ts";
|
||||
@@ -105,6 +106,25 @@ describe("dreaming controller", () => {
|
||||
|
||||
it("patches config to update global dreaming enablement", async () => {
|
||||
const { state, request } = createState();
|
||||
state.configSnapshot = {
|
||||
hash: "hash-1",
|
||||
config: {
|
||||
plugins: {
|
||||
slots: {
|
||||
memory: "memos-local-openclaw-plugin",
|
||||
},
|
||||
entries: {
|
||||
"memos-local-openclaw-plugin": {
|
||||
config: {
|
||||
dreaming: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
request.mockResolvedValue({ ok: true });
|
||||
|
||||
const ok = await updateDreamingEnabled(state, false);
|
||||
@@ -117,10 +137,55 @@ describe("dreaming controller", () => {
|
||||
sessionKey: "main",
|
||||
}),
|
||||
);
|
||||
const requestPayload = request.mock.calls[0]?.[1] as { raw?: string };
|
||||
expect(JSON.parse(String(requestPayload.raw))).toEqual({
|
||||
plugins: {
|
||||
entries: {
|
||||
"memos-local-openclaw-plugin": {
|
||||
config: {
|
||||
dreaming: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(state.dreamingModeSaving).toBe(false);
|
||||
expect(state.dreamingStatusError).toBeNull();
|
||||
});
|
||||
|
||||
it("reads dreaming enabled state from the selected memory slot plugin", () => {
|
||||
expect(
|
||||
resolveConfiguredDreaming({
|
||||
plugins: {
|
||||
slots: {
|
||||
memory: "memos-local-openclaw-plugin",
|
||||
},
|
||||
entries: {
|
||||
"memos-local-openclaw-plugin": {
|
||||
config: {
|
||||
dreaming: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"memory-core": {
|
||||
config: {
|
||||
dreaming: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
pluginId: "memos-local-openclaw-plugin",
|
||||
enabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("fails gracefully when config hash is missing", async () => {
|
||||
const { state, request } = createState();
|
||||
state.configSnapshot = {};
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { ConfigSnapshot } from "../types.ts";
|
||||
|
||||
export type DreamingPhaseId = "light" | "deep" | "rem";
|
||||
const DEFAULT_DREAM_DIARY_PATH = "DREAMS.md";
|
||||
const DEFAULT_DREAMING_PLUGIN_ID = "memory-core";
|
||||
|
||||
type DreamingPhaseStatusBase = {
|
||||
enabled: boolean;
|
||||
@@ -139,6 +140,32 @@ function normalizePhaseStatusBase(record: Record<string, unknown> | null): Dream
|
||||
};
|
||||
}
|
||||
|
||||
function resolveDreamingPluginId(configValue: Record<string, unknown> | null): string {
|
||||
const plugins = asRecord(configValue?.plugins);
|
||||
const slots = asRecord(plugins?.slots);
|
||||
const configuredSlot = normalizeTrimmedString(slots?.memory);
|
||||
if (configuredSlot && configuredSlot.toLowerCase() !== "none") {
|
||||
return configuredSlot;
|
||||
}
|
||||
return DEFAULT_DREAMING_PLUGIN_ID;
|
||||
}
|
||||
|
||||
export function resolveConfiguredDreaming(configValue: Record<string, unknown> | null): {
|
||||
pluginId: string;
|
||||
enabled: boolean;
|
||||
} {
|
||||
const pluginId = resolveDreamingPluginId(configValue);
|
||||
const plugins = asRecord(configValue?.plugins);
|
||||
const entries = asRecord(plugins?.entries);
|
||||
const pluginEntry = asRecord(entries?.[pluginId]);
|
||||
const config = asRecord(pluginEntry?.config);
|
||||
const dreaming = asRecord(config?.dreaming);
|
||||
return {
|
||||
pluginId,
|
||||
enabled: normalizeBoolean(dreaming?.enabled, false),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeDreamingStatus(raw: unknown): DreamingStatus | null {
|
||||
const record = asRecord(raw);
|
||||
if (!record) {
|
||||
@@ -286,10 +313,11 @@ export async function updateDreamingEnabled(
|
||||
state: DreamingState,
|
||||
enabled: boolean,
|
||||
): Promise<boolean> {
|
||||
const { pluginId } = resolveConfiguredDreaming(asRecord(state.configSnapshot?.config) ?? null);
|
||||
const ok = await writeDreamingPatch(state, {
|
||||
plugins: {
|
||||
entries: {
|
||||
"memory-core": {
|
||||
[pluginId]: {
|
||||
config: {
|
||||
dreaming: {
|
||||
enabled,
|
||||
|
||||
Reference in New Issue
Block a user