fix(openclaw): graceful startup without API key
Plugin no longer throws during register() when API key is missing. Instead it registers successfully, logs a clear setup message with the exact command to run, and disables memory features until configured. Before: openclaw plugins install -> register() throws -> gateway logs error After: openclaw plugins install -> registers ok -> logs setup instructions Users see: openclaw-mem0: API key not configured. Memory features are disabled. To set up, run: openclaw config set plugins.entries.openclaw-mem0.config.apiKey "m0-your-key" openclaw gateway restart Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7e9824e394
commit
5a5e201dd9
+4
-8
@@ -196,14 +196,9 @@ export const mem0ConfigSchema = {
|
|||||||
const mode: Mem0Mode =
|
const mode: Mem0Mode =
|
||||||
cfg.mode === "oss" || cfg.mode === "open-source" ? "open-source" : "platform";
|
cfg.mode === "oss" || cfg.mode === "open-source" ? "open-source" : "platform";
|
||||||
|
|
||||||
// Platform mode requires apiKey
|
// Platform mode requires apiKey — but don't throw on missing config.
|
||||||
if (mode === "platform") {
|
// The plugin should register successfully and log a setup message.
|
||||||
if (typeof cfg.apiKey !== "string" || !cfg.apiKey) {
|
const needsSetup = mode === "platform" && (typeof cfg.apiKey !== "string" || !cfg.apiKey);
|
||||||
throw new Error(
|
|
||||||
"apiKey is required for platform mode (set mode: \"open-source\" for self-hosted)",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve env vars in oss config
|
// Resolve env vars in oss config
|
||||||
let ossConfig: Mem0Config["oss"];
|
let ossConfig: Mem0Config["oss"];
|
||||||
@@ -241,6 +236,7 @@ export const mem0ConfigSchema = {
|
|||||||
searchThreshold:
|
searchThreshold:
|
||||||
typeof cfg.searchThreshold === "number" ? cfg.searchThreshold : 0.5,
|
typeof cfg.searchThreshold === "number" ? cfg.searchThreshold : 0.5,
|
||||||
topK: typeof cfg.topK === "number" ? cfg.topK : 5,
|
topK: typeof cfg.topK === "number" ? cfg.topK : 5,
|
||||||
|
needsSetup,
|
||||||
oss: ossConfig,
|
oss: ossConfig,
|
||||||
skills:
|
skills:
|
||||||
cfg.skills && typeof cfg.skills === "object" && !Array.isArray(cfg.skills)
|
cfg.skills && typeof cfg.skills === "object" && !Array.isArray(cfg.skills)
|
||||||
|
|||||||
@@ -94,6 +94,25 @@ const memoryPlugin = {
|
|||||||
|
|
||||||
register(api: OpenClawPluginApi) {
|
register(api: OpenClawPluginApi) {
|
||||||
const cfg = mem0ConfigSchema.parse(api.pluginConfig);
|
const cfg = mem0ConfigSchema.parse(api.pluginConfig);
|
||||||
|
|
||||||
|
// If API key is missing, register successfully but skip all memory operations.
|
||||||
|
// This prevents install from failing and gives the user a clear setup message.
|
||||||
|
if (cfg.needsSetup) {
|
||||||
|
api.logger.warn(
|
||||||
|
"openclaw-mem0: API key not configured. Memory features are disabled.\n" +
|
||||||
|
" To set up, run:\n" +
|
||||||
|
' openclaw config set plugins.entries.openclaw-mem0.config.apiKey "m0-your-key"\n' +
|
||||||
|
" openclaw gateway restart\n" +
|
||||||
|
" Get your key at: https://app.mem0.ai/dashboard/api-keys"
|
||||||
|
);
|
||||||
|
api.registerService({
|
||||||
|
id: "openclaw-mem0",
|
||||||
|
start: () => { api.logger.info("openclaw-mem0: waiting for API key configuration"); },
|
||||||
|
stop: () => {},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const provider = createProvider(cfg, api);
|
const provider = createProvider(cfg, api);
|
||||||
|
|
||||||
// Track current session ID for tool-level session scoping.
|
// Track current session ID for tool-level session scoping.
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ export type Mem0Config = {
|
|||||||
autoRecall: boolean;
|
autoRecall: boolean;
|
||||||
searchThreshold: number;
|
searchThreshold: number;
|
||||||
topK: number;
|
topK: number;
|
||||||
|
// Setup state
|
||||||
|
needsSetup?: boolean;
|
||||||
// Agentic harness skills
|
// Agentic harness skills
|
||||||
skills?: SkillsConfig;
|
skills?: SkillsConfig;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user