refactor: update MemoryClient to support snake_case filter keys and separate filters
This commit is contained in:
@@ -257,10 +257,11 @@ export default class MemoryClient {
|
|||||||
if (this.telemetryId === "") await this.ping();
|
if (this.telemetryId === "") await this.ping();
|
||||||
const payloadKeys = Object.keys(options || {});
|
const payloadKeys = Object.keys(options || {});
|
||||||
this._captureEvent("get_all", [payloadKeys]);
|
this._captureEvent("get_all", [payloadKeys]);
|
||||||
const { page, pageSize, ...rest } = options ?? {};
|
const { page, pageSize, filters, ...rest } = options ?? {};
|
||||||
const body: Record<string, any> = {
|
const body: Record<string, any> = {
|
||||||
output_format: "v1.1",
|
output_format: "v1.1",
|
||||||
...camelToSnakeKeys(rest),
|
...camelToSnakeKeys(rest),
|
||||||
|
...(filters && { filters }),
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = `${this.host}/v2/memories/`;
|
let url = `${this.host}/v2/memories/`;
|
||||||
@@ -283,10 +284,12 @@ export default class MemoryClient {
|
|||||||
if (this.telemetryId === "") await this.ping();
|
if (this.telemetryId === "") await this.ping();
|
||||||
const payloadKeys = Object.keys(options || {});
|
const payloadKeys = Object.keys(options || {});
|
||||||
this._captureEvent("search", [payloadKeys]);
|
this._captureEvent("search", [payloadKeys]);
|
||||||
|
const { filters, ...rest } = options ?? {};
|
||||||
const payload: Record<string, any> = {
|
const payload: Record<string, any> = {
|
||||||
query,
|
query,
|
||||||
output_format: "v1.1",
|
output_format: "v1.1",
|
||||||
...camelToSnakeKeys(options ?? {}),
|
...camelToSnakeKeys(rest),
|
||||||
|
...(filters && { filters }),
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this._fetchWithErrorHandling(
|
const response = await this._fetchWithErrorHandling(
|
||||||
@@ -612,12 +615,16 @@ export default class MemoryClient {
|
|||||||
throw new Error("Missing filters or schema");
|
throw new Error("Missing filters or schema");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { filters, ...rest } = data;
|
||||||
const response = await this._fetchWithErrorHandling(
|
const response = await this._fetchWithErrorHandling(
|
||||||
`${this.host}/v1/exports/`,
|
`${this.host}/v1/exports/`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(camelToSnakeKeys(data)),
|
body: JSON.stringify({
|
||||||
|
...camelToSnakeKeys(rest),
|
||||||
|
filters,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -634,12 +641,16 @@ export default class MemoryClient {
|
|||||||
throw new Error("Missing memoryExportId or filters");
|
throw new Error("Missing memoryExportId or filters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { filters, ...rest } = data;
|
||||||
const response = await this._fetchWithErrorHandling(
|
const response = await this._fetchWithErrorHandling(
|
||||||
`${this.host}/v1/exports/get/`,
|
`${this.host}/v1/exports/get/`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(camelToSnakeKeys(data)),
|
body: JSON.stringify({
|
||||||
|
...camelToSnakeKeys(rest),
|
||||||
|
...(filters && { filters }),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ describeIntegration("MemoryClient Integration — CRUD", () => {
|
|||||||
describe("get all memories", () => {
|
describe("get all memories", () => {
|
||||||
test("returns all memories for test user", async () => {
|
test("returns all memories for test user", async () => {
|
||||||
const memories = await client.getAll({
|
const memories = await client.getAll({
|
||||||
filters: { userId: TEST_USER_ID },
|
filters: { user_id: TEST_USER_ID },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(Array.isArray(memories)).toBe(true);
|
expect(Array.isArray(memories)).toBe(true);
|
||||||
@@ -131,7 +131,7 @@ describeIntegration("MemoryClient Integration — CRUD", () => {
|
|||||||
|
|
||||||
test("returns paginated results with page and page_size", async () => {
|
test("returns paginated results with page and page_size", async () => {
|
||||||
const page1 = await client.getAll({
|
const page1 = await client.getAll({
|
||||||
filters: { userId: TEST_USER_ID },
|
filters: { user_id: TEST_USER_ID },
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 1,
|
pageSize: 1,
|
||||||
});
|
});
|
||||||
@@ -195,7 +195,7 @@ describeIntegration("MemoryClient Integration — CRUD", () => {
|
|||||||
|
|
||||||
test("getAll for non-existent user returns empty array", async () => {
|
test("getAll for non-existent user returns empty array", async () => {
|
||||||
const memories = await client.getAll({
|
const memories = await client.getAll({
|
||||||
filters: { userId: `nonexistent-user-${randomUUID()}` },
|
filters: { user_id: `nonexistent-user-${randomUUID()}` },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(Array.isArray(memories)).toBe(true);
|
expect(Array.isArray(memories)).toBe(true);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export async function waitForMemories(
|
|||||||
): Promise<Memory[]> {
|
): Promise<Memory[]> {
|
||||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
const memories = await withRetry(() =>
|
const memories = await withRetry(() =>
|
||||||
client.getAll({ filters: { userId } }),
|
client.getAll({ filters: { user_id: userId } }),
|
||||||
);
|
);
|
||||||
if (Array.isArray(memories) && memories.length >= minCount) {
|
if (Array.isArray(memories) && memories.length >= minCount) {
|
||||||
return memories;
|
return memories;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
|
|||||||
const results = await waitForSearchResults(
|
const results = await waitForSearchResults(
|
||||||
client,
|
client,
|
||||||
"What is my favorite color?",
|
"What is my favorite color?",
|
||||||
{ filters: { userId: TEST_USER_ID } },
|
{ filters: { user_id: TEST_USER_ID } },
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(Array.isArray(results)).toBe(true);
|
expect(Array.isArray(results)).toBe(true);
|
||||||
@@ -64,7 +64,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
|
|||||||
client,
|
client,
|
||||||
"What do you know about me?",
|
"What do you know about me?",
|
||||||
{
|
{
|
||||||
filters: { OR: [{ userId: TEST_USER_ID }] },
|
filters: { OR: [{ user_id: TEST_USER_ID }] },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
|
|||||||
const response = await client.search(
|
const response = await client.search(
|
||||||
"Tell me about integration test user",
|
"Tell me about integration test user",
|
||||||
{
|
{
|
||||||
filters: { userId: TEST_USER_ID },
|
filters: { user_id: TEST_USER_ID },
|
||||||
topK: 1,
|
topK: 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
await client.search("What is my name?", {
|
await client.search("What is my name?", {
|
||||||
filters: { userId: "u1" },
|
filters: { user_id: "u1" },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(findFetchCall(mock, "/v3/memories/search/", "POST")).toBeDefined();
|
expect(findFetchCall(mock, "/v3/memories/search/", "POST")).toBeDefined();
|
||||||
@@ -41,7 +41,7 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
await client.search("What is my name?", {
|
await client.search("What is my name?", {
|
||||||
filters: { userId: "u1" },
|
filters: { user_id: "u1" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const call = findFetchCall(mock, "/v3/memories/search/", "POST");
|
const call = findFetchCall(mock, "/v3/memories/search/", "POST");
|
||||||
@@ -57,7 +57,7 @@ describe("MemoryClient - search()", () => {
|
|||||||
const mock = setupMockFetch(extra);
|
const mock = setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
await client.search("test", { filters: { userId: "u1" } });
|
await client.search("test", { filters: { user_id: "u1" } });
|
||||||
|
|
||||||
const call = findFetchCall(mock, "/v3/memories/search/", "POST");
|
const call = findFetchCall(mock, "/v3/memories/search/", "POST");
|
||||||
expect(getFetchBody(call!).filters).toEqual({ user_id: "u1" });
|
expect(getFetchBody(call!).filters).toEqual({ user_id: "u1" });
|
||||||
@@ -106,7 +106,7 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
const result = await client.search("nonexistent query", {
|
const result = await client.search("nonexistent query", {
|
||||||
filters: { userId: "u1" },
|
filters: { user_id: "u1" },
|
||||||
});
|
});
|
||||||
expect(result.results).toHaveLength(0);
|
expect(result.results).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user