fix(openclaw): skip runtime setup during metadata registration (#5383)
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
* Regression tests for per-agent memory isolation helpers and
|
* Regression tests for per-agent memory isolation helpers and
|
||||||
* message filtering logic.
|
* message filtering logic.
|
||||||
*/
|
*/
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect, vi } from "vitest";
|
||||||
import {
|
import memoryPlugin, {
|
||||||
extractAgentId,
|
extractAgentId,
|
||||||
effectiveUserId,
|
effectiveUserId,
|
||||||
agentUserId,
|
agentUserId,
|
||||||
@@ -16,6 +16,47 @@ import {
|
|||||||
filterMessagesForExtraction,
|
filterMessagesForExtraction,
|
||||||
} from "./index.ts";
|
} from "./index.ts";
|
||||||
|
|
||||||
|
function createPluginApi(registrationMode?: string) {
|
||||||
|
return {
|
||||||
|
pluginConfig: {
|
||||||
|
mode: "platform",
|
||||||
|
apiKey: "test-api-key",
|
||||||
|
userId: "alice",
|
||||||
|
},
|
||||||
|
registrationMode,
|
||||||
|
logger: {
|
||||||
|
info: vi.fn(),
|
||||||
|
warn: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
debug: vi.fn(),
|
||||||
|
},
|
||||||
|
resolvePath: vi.fn((p: string) => p),
|
||||||
|
registerTool: vi.fn(),
|
||||||
|
on: vi.fn(),
|
||||||
|
registerCli: vi.fn(),
|
||||||
|
registerCommand: vi.fn(),
|
||||||
|
registerService: vi.fn(),
|
||||||
|
registerMemoryCapability: vi.fn(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("plugin registration modes", () => {
|
||||||
|
it("keeps cli-metadata registration free of runtime side effects", () => {
|
||||||
|
const api = createPluginApi("cli-metadata");
|
||||||
|
|
||||||
|
memoryPlugin.register(api as any);
|
||||||
|
|
||||||
|
expect(api.registerCli).toHaveBeenCalledTimes(1);
|
||||||
|
expect(api.registerService).not.toHaveBeenCalled();
|
||||||
|
expect(api.registerMemoryCapability).not.toHaveBeenCalled();
|
||||||
|
expect(api.registerTool).not.toHaveBeenCalled();
|
||||||
|
expect(api.on).not.toHaveBeenCalled();
|
||||||
|
expect(api.logger.info).not.toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining("openclaw-mem0: registered"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// extractAgentId
|
// extractAgentId
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ const memoryPlugin = definePluginEntry({
|
|||||||
baseUrl: pluginAuth.baseUrl,
|
baseUrl: pluginAuth.baseUrl,
|
||||||
};
|
};
|
||||||
const cfg = mem0ConfigSchema.parse(api.pluginConfig, fileConfig);
|
const cfg = mem0ConfigSchema.parse(api.pluginConfig, fileConfig);
|
||||||
|
const isMetadataRegistration = api.registrationMode === "cli-metadata";
|
||||||
|
|
||||||
// Telemetry context bound to this plugin instance's config
|
// Telemetry context bound to this plugin instance's config
|
||||||
const telemetryCtx = {
|
const telemetryCtx = {
|
||||||
@@ -122,6 +123,21 @@ const memoryPlugin = definePluginEntry({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isMetadataRegistration) {
|
||||||
|
registerCliCommands(
|
||||||
|
api,
|
||||||
|
null as any,
|
||||||
|
null as any,
|
||||||
|
cfg,
|
||||||
|
() => cfg.userId,
|
||||||
|
(id: string) => `${cfg.userId}:agent:${id}`,
|
||||||
|
() => ({ user_id: cfg.userId, top_k: cfg.topK }),
|
||||||
|
() => undefined,
|
||||||
|
(cmd: string) => _captureEvent(`openclaw.cli.${cmd}`, { command: cmd }),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.needsSetup) {
|
if (cfg.needsSetup) {
|
||||||
api.logger.warn(
|
api.logger.warn(
|
||||||
"openclaw-mem0: API key not configured. Memory features are disabled.\n" +
|
"openclaw-mem0: API key not configured. Memory features are disabled.\n" +
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ declare module "openclaw/plugin-sdk" {
|
|||||||
|
|
||||||
export interface OpenClawPluginApi {
|
export interface OpenClawPluginApi {
|
||||||
pluginConfig: Record<string, unknown>;
|
pluginConfig: Record<string, unknown>;
|
||||||
|
registrationMode?: "full" | "cli-metadata" | string;
|
||||||
logger: {
|
logger: {
|
||||||
info(msg: string): void;
|
info(msg: string): void;
|
||||||
warn(msg: string): void;
|
warn(msg: string): void;
|
||||||
|
|||||||
Reference in New Issue
Block a user