mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:00:45 +00:00
fix(plugins): restore cached memory capability on cache hits
This commit is contained in:
@@ -39,7 +39,9 @@ import {
|
|||||||
} from "./memory-embedding-providers.js";
|
} from "./memory-embedding-providers.js";
|
||||||
import {
|
import {
|
||||||
buildMemoryPromptSection,
|
buildMemoryPromptSection,
|
||||||
|
clearMemoryPluginState,
|
||||||
getMemoryRuntime,
|
getMemoryRuntime,
|
||||||
|
listActiveMemoryPublicArtifacts,
|
||||||
listMemoryCorpusSupplements,
|
listMemoryCorpusSupplements,
|
||||||
registerMemoryCorpusSupplement,
|
registerMemoryCorpusSupplement,
|
||||||
registerMemoryFlushPlanResolver,
|
registerMemoryFlushPlanResolver,
|
||||||
@@ -1809,6 +1811,73 @@ module.exports = { id: "throws-after-import", register() {} };`,
|
|||||||
expect(listMemoryEmbeddingProviders()).toEqual([]);
|
expect(listMemoryEmbeddingProviders()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("restores cached memory capability public artifacts on cache hits", async () => {
|
||||||
|
useNoBundledPlugins();
|
||||||
|
const workspaceDir = makeTempDir();
|
||||||
|
const absolutePath = path.join(workspaceDir, "MEMORY.md");
|
||||||
|
fs.writeFileSync(absolutePath, "# Memory\n");
|
||||||
|
const plugin = writePlugin({
|
||||||
|
id: "cached-memory-capability",
|
||||||
|
filename: "cached-memory-capability.cjs",
|
||||||
|
body: `module.exports = {
|
||||||
|
id: "cached-memory-capability",
|
||||||
|
kind: "memory",
|
||||||
|
register(api) {
|
||||||
|
api.registerMemoryCapability({
|
||||||
|
publicArtifacts: {
|
||||||
|
async listArtifacts() {
|
||||||
|
return [{
|
||||||
|
kind: "memory-root",
|
||||||
|
workspaceDir: ${JSON.stringify(workspaceDir)},
|
||||||
|
relativePath: "MEMORY.md",
|
||||||
|
absolutePath: ${JSON.stringify(absolutePath)},
|
||||||
|
agentIds: ["main"],
|
||||||
|
contentType: "markdown",
|
||||||
|
}];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
workspaceDir: plugin.dir,
|
||||||
|
config: {
|
||||||
|
plugins: {
|
||||||
|
load: { paths: [plugin.file] },
|
||||||
|
allow: ["cached-memory-capability"],
|
||||||
|
slots: { memory: "cached-memory-capability" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onlyPluginIds: ["cached-memory-capability"],
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedArtifacts = [
|
||||||
|
{
|
||||||
|
kind: "memory-root",
|
||||||
|
workspaceDir,
|
||||||
|
relativePath: "MEMORY.md",
|
||||||
|
absolutePath,
|
||||||
|
agentIds: ["main"],
|
||||||
|
contentType: "markdown" as const,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const first = loadOpenClawPlugins(options);
|
||||||
|
await expect(listActiveMemoryPublicArtifacts({ cfg: {} as never })).resolves.toEqual(
|
||||||
|
expectedArtifacts,
|
||||||
|
);
|
||||||
|
|
||||||
|
clearMemoryPluginState();
|
||||||
|
|
||||||
|
const second = loadOpenClawPlugins(options);
|
||||||
|
expect(second).toBe(first);
|
||||||
|
await expect(listActiveMemoryPublicArtifacts({ cfg: {} as never })).resolves.toEqual(
|
||||||
|
expectedArtifacts,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("throws when activate:false is used without cache:false", () => {
|
it("throws when activate:false is used without cache:false", () => {
|
||||||
expect(() => loadOpenClawPlugins({ activate: false })).toThrow(
|
expect(() => loadOpenClawPlugins({ activate: false })).toThrow(
|
||||||
"activate:false requires cache:false",
|
"activate:false requires cache:false",
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
} from "./memory-embedding-providers.js";
|
} from "./memory-embedding-providers.js";
|
||||||
import {
|
import {
|
||||||
clearMemoryPluginState,
|
clearMemoryPluginState,
|
||||||
|
getMemoryCapabilityRegistration,
|
||||||
getMemoryFlushPlanResolver,
|
getMemoryFlushPlanResolver,
|
||||||
getMemoryPromptSectionBuilder,
|
getMemoryPromptSectionBuilder,
|
||||||
getMemoryRuntime,
|
getMemoryRuntime,
|
||||||
@@ -148,6 +149,7 @@ export class PluginLoadReentryError extends Error {
|
|||||||
|
|
||||||
type CachedPluginState = {
|
type CachedPluginState = {
|
||||||
registry: PluginRegistry;
|
registry: PluginRegistry;
|
||||||
|
memoryCapability: ReturnType<typeof getMemoryCapabilityRegistration>;
|
||||||
memoryCorpusSupplements: ReturnType<typeof listMemoryCorpusSupplements>;
|
memoryCorpusSupplements: ReturnType<typeof listMemoryCorpusSupplements>;
|
||||||
agentHarnesses: ReturnType<typeof listRegisteredAgentHarnesses>;
|
agentHarnesses: ReturnType<typeof listRegisteredAgentHarnesses>;
|
||||||
compactionProviders: ReturnType<typeof listRegisteredCompactionProviders>;
|
compactionProviders: ReturnType<typeof listRegisteredCompactionProviders>;
|
||||||
@@ -1104,6 +1106,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
|
|||||||
restoreRegisteredCompactionProviders(cached.compactionProviders);
|
restoreRegisteredCompactionProviders(cached.compactionProviders);
|
||||||
restoreRegisteredMemoryEmbeddingProviders(cached.memoryEmbeddingProviders);
|
restoreRegisteredMemoryEmbeddingProviders(cached.memoryEmbeddingProviders);
|
||||||
restoreMemoryPluginState({
|
restoreMemoryPluginState({
|
||||||
|
capability: cached.memoryCapability,
|
||||||
corpusSupplements: cached.memoryCorpusSupplements,
|
corpusSupplements: cached.memoryCorpusSupplements,
|
||||||
promptBuilder: cached.memoryPromptBuilder,
|
promptBuilder: cached.memoryPromptBuilder,
|
||||||
promptSupplements: cached.memoryPromptSupplements,
|
promptSupplements: cached.memoryPromptSupplements,
|
||||||
@@ -1799,6 +1802,7 @@ export function loadOpenClawPlugins(options: PluginLoadOptions = {}): PluginRegi
|
|||||||
|
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
setCachedPluginRegistry(cacheKey, {
|
setCachedPluginRegistry(cacheKey, {
|
||||||
|
memoryCapability: getMemoryCapabilityRegistration(),
|
||||||
memoryCorpusSupplements: listMemoryCorpusSupplements(),
|
memoryCorpusSupplements: listMemoryCorpusSupplements(),
|
||||||
registry,
|
registry,
|
||||||
agentHarnesses: listRegisteredAgentHarnesses(),
|
agentHarnesses: listRegisteredAgentHarnesses(),
|
||||||
|
|||||||
Reference in New Issue
Block a user