fix(ts-oss): reject empty/blank messages in Memory.add() to prevent hallucinated memories (#5545)

This commit is contained in:
Bartok
2026-06-18 17:36:19 +05:30
committed by GitHub
parent 7ae6a8c36a
commit 1751e7bff9
2 changed files with 37 additions and 0 deletions
@@ -84,6 +84,24 @@ describe("Memory Input Validation", () => {
memory.add(null, { userId: testUserId }),
).rejects.toThrow("messages is required");
});
it("should throw error when messages is an empty array", async () => {
await expect(memory.add([], { userId: testUserId })).rejects.toThrow(
"messages array cannot be empty",
);
});
it("should throw error when messages array contains only blank content", async () => {
await expect(
memory.add([{ role: "user", content: " " }], { userId: testUserId }),
).rejects.toThrow("messages array cannot contain only blank content");
});
it("should throw error when messages is an empty string", async () => {
await expect(memory.add(" ", { userId: testUserId })).rejects.toThrow(
"messages string cannot be empty",
);
});
});
describe("search() threshold validation", () => {