mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:40:44 +00:00
fix(hooks): refresh active memory config at runtime
This commit is contained in:
@@ -42,10 +42,36 @@ describe("active-memory plugin", () => {
|
||||
const runEmbeddedPiAgent = vi.fn();
|
||||
let stateDir = "";
|
||||
let configFile: Record<string, unknown> = {};
|
||||
let pluginConfig: Record<string, unknown> = {
|
||||
agents: ["main"],
|
||||
logging: true,
|
||||
};
|
||||
const syncRuntimePluginConfig = (nextPluginConfig: Record<string, unknown>) => {
|
||||
pluginConfig = nextPluginConfig;
|
||||
const plugins = configFile.plugins as Record<string, unknown> | undefined;
|
||||
const entries = plugins?.entries as Record<string, unknown> | undefined;
|
||||
const existingEntry = entries?.["active-memory"] as Record<string, unknown> | undefined;
|
||||
configFile = {
|
||||
...configFile,
|
||||
plugins: {
|
||||
...plugins,
|
||||
entries: {
|
||||
...entries,
|
||||
"active-memory": {
|
||||
...existingEntry,
|
||||
enabled: true,
|
||||
config: nextPluginConfig,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
const api: any = {
|
||||
pluginConfig: {
|
||||
agents: ["main"],
|
||||
logging: true,
|
||||
get pluginConfig() {
|
||||
return pluginConfig;
|
||||
},
|
||||
set pluginConfig(nextPluginConfig: Record<string, unknown>) {
|
||||
syncRuntimePluginConfig(nextPluginConfig);
|
||||
},
|
||||
config: {},
|
||||
id: "active-memory",
|
||||
@@ -93,10 +119,10 @@ describe("active-memory plugin", () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
api.pluginConfig = {
|
||||
syncRuntimePluginConfig({
|
||||
agents: ["main"],
|
||||
logging: true,
|
||||
};
|
||||
});
|
||||
api.config = {
|
||||
agents: {
|
||||
defaults: {
|
||||
@@ -310,6 +336,35 @@ describe("active-memory plugin", () => {
|
||||
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("uses live runtime config for before_prompt_build enablement", async () => {
|
||||
configFile = {
|
||||
plugins: {
|
||||
entries: {
|
||||
"active-memory": {
|
||||
enabled: true,
|
||||
config: {
|
||||
enabled: false,
|
||||
agents: ["main"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = await hooks.before_prompt_build(
|
||||
{ prompt: "what wings should i order after a live config disable?", messages: [] },
|
||||
{
|
||||
agentId: "main",
|
||||
trigger: "user",
|
||||
sessionKey: "agent:main:live-config-disable",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not run for agents that are not explicitly targeted", async () => {
|
||||
const result = await hooks.before_prompt_build(
|
||||
{ prompt: "what wings should i order?", messages: [] },
|
||||
|
||||
@@ -1961,6 +1961,7 @@ export default definePluginEntry({
|
||||
|
||||
api.on("before_prompt_build", async (event, ctx) => {
|
||||
try {
|
||||
refreshLiveConfigFromRuntime();
|
||||
const resolvedAgentId = resolveStatusUpdateAgentId(ctx);
|
||||
const resolvedSessionKey =
|
||||
ctx.sessionKey?.trim() ||
|
||||
|
||||
Reference in New Issue
Block a user