fix: validate lancedb memory importance

This commit is contained in:
Peter Steinberger
2026-05-28 21:25:00 -04:00
parent b1117d9862
commit fe76bae1ed
2 changed files with 28 additions and 10 deletions

View File

@@ -2542,9 +2542,19 @@ describe("memory plugin e2e", () => {
expect(loadLanceDbModule).not.toHaveBeenCalled();
expect(add).not.toHaveBeenCalled();
await expect(
storeTool.execute("test-call-bad-importance", {
text: "The user prefers concise replies",
importance: "1.5",
}),
).rejects.toThrow("importance must be a finite number");
expect(embeddingsCreate).not.toHaveBeenCalled();
expect(loadLanceDbModule).not.toHaveBeenCalled();
expect(add).not.toHaveBeenCalled();
const stored = await storeTool.execute("test-call-store", {
text: "The user prefers concise replies",
importance: 0.8,
importance: "0.8",
category: "preference",
});
@@ -2556,6 +2566,7 @@ describe("memory plugin e2e", () => {
});
expect(add).toHaveBeenCalledTimes(1);
expect(firstAddedMemory(add).text).toBe("The user prefers concise replies");
expect(firstAddedMemory(add).importance).toBe(0.8);
},
});
});

View File

@@ -9,10 +9,13 @@
import { Buffer } from "node:buffer";
import { randomUUID } from "node:crypto";
import type * as LanceDB from "@lancedb/lancedb";
import { optionalPositiveIntegerSchema } from "openclaw/plugin-sdk/channel-actions";
import {
optionalFiniteNumberSchema,
optionalPositiveIntegerSchema,
} from "openclaw/plugin-sdk/channel-actions";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import type { MemoryEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import { readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
import { readFiniteNumberParam, readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env";
import {
@@ -767,7 +770,11 @@ export default definePluginEntry({
"Save important information in long-term memory. Use for preferences, facts, decisions.",
parameters: Type.Object({
text: Type.String({ description: "Information to remember" }),
importance: Type.Optional(Type.Number({ description: "Importance 0-1 (default: 0.7)" })),
importance: optionalFiniteNumberSchema({
description: "Importance 0-1 (default: 0.7)",
minimum: 0,
maximum: 1,
}),
category: Type.Optional(
Type.Unsafe<MemoryCategory>({
type: "string",
@@ -776,15 +783,15 @@ export default definePluginEntry({
),
}),
async execute(_toolCallId, params) {
const {
text,
importance = 0.7,
category = "other",
} = params as {
const { text, category = "other" } = params as {
text: string;
importance?: number;
category?: MemoryEntry["category"];
};
const importance =
readFiniteNumberParam(params as Record<string, unknown>, "importance", {
min: 0,
max: 1,
}) ?? 0.7;
if (looksLikePromptInjection(text)) {
return {