555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { addMemories, retrieveMemories } from "../src";
|
|
import { LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
import { testConfig } from "../config/test-config";
|
|
|
|
describe("Memory Core Functions", () => {
|
|
const { userId } = testConfig;
|
|
jest.setTimeout(20000);
|
|
|
|
describe("addMemories", () => {
|
|
it("should successfully add memories and return correct format", async () => {
|
|
const messages: LanguageModelV3Prompt = [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
{ type: "text", text: "I love red cars." },
|
|
{ type: "text", text: "I like Toyota Cars." },
|
|
{ type: "text", text: "I prefer SUVs." },
|
|
],
|
|
}
|
|
];
|
|
|
|
const response = await addMemories(messages, { user_id: userId });
|
|
|
|
expect(Array.isArray(response)).toBe(true);
|
|
response.forEach((memory: { event: any; }) => {
|
|
expect(memory).toHaveProperty('id');
|
|
expect(memory).toHaveProperty('data');
|
|
expect(memory).toHaveProperty('event');
|
|
expect(memory.event).toBe('ADD');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("retrieveMemories", () => {
|
|
beforeEach(async () => {
|
|
// Add some test memories before each retrieval test
|
|
const messages: LanguageModelV3Prompt = [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
{ type: "text", text: "I love red cars." },
|
|
{ type: "text", text: "I like Toyota Cars." },
|
|
{ type: "text", text: "I prefer SUVs." },
|
|
],
|
|
}
|
|
];
|
|
await addMemories(messages, { user_id: userId });
|
|
});
|
|
|
|
it("should retrieve memories with string prompt", async () => {
|
|
const prompt = "Which car would I prefer?";
|
|
const response = await retrieveMemories(prompt, { user_id: userId });
|
|
|
|
expect(typeof response).toBe('string');
|
|
expect(response.match(/Memory:/g)?.length).toBeGreaterThan(2);
|
|
});
|
|
|
|
it("should retrieve memories with array of prompts", async () => {
|
|
const messages: LanguageModelV3Prompt = [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
{ type: "text", text: "Which car would I prefer?" },
|
|
{ type: "text", text: "Suggest me some cars" },
|
|
],
|
|
}
|
|
];
|
|
|
|
const response = await retrieveMemories(messages, { user_id: userId });
|
|
|
|
expect(typeof response).toBe('string');
|
|
expect(response.match(/Memory:/g)?.length).toBeGreaterThan(2);
|
|
});
|
|
});
|
|
}); |