diff --git a/extensions/active-memory/index.test.ts b/extensions/active-memory/index.test.ts index e6882f99c2e..ae3f006afcf 100644 --- a/extensions/active-memory/index.test.ts +++ b/extensions/active-memory/index.test.ts @@ -42,10 +42,36 @@ describe("active-memory plugin", () => { const runEmbeddedPiAgent = vi.fn(); let stateDir = ""; let configFile: Record = {}; + let pluginConfig: Record = { + agents: ["main"], + logging: true, + }; + const syncRuntimePluginConfig = (nextPluginConfig: Record) => { + pluginConfig = nextPluginConfig; + const plugins = configFile.plugins as Record | undefined; + const entries = plugins?.entries as Record | undefined; + const existingEntry = entries?.["active-memory"] as Record | 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) { + 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: [] }, diff --git a/extensions/active-memory/index.ts b/extensions/active-memory/index.ts index 5cecfaf14e0..b3d308f8ff3 100644 --- a/extensions/active-memory/index.ts +++ b/extensions/active-memory/index.ts @@ -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() ||