diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts index 33032c234..915ef64d6 100644 --- a/mem0-ts/src/client/mem0.ts +++ b/mem0-ts/src/client/mem0.ts @@ -280,7 +280,7 @@ export default class MemoryClient { async search( query: string, options?: SearchMemoryOptions, - ): Promise> { + ): Promise<{ results: Array }> { if (this.telemetryId === "") await this.ping(); const payloadKeys = Object.keys(options || {}); this._captureEvent("search", [payloadKeys]); diff --git a/mem0-ts/src/client/tests/memoryClient.search.test.ts b/mem0-ts/src/client/tests/memoryClient.search.test.ts index e0157c546..4cfe27116 100644 --- a/mem0-ts/src/client/tests/memoryClient.search.test.ts +++ b/mem0-ts/src/client/tests/memoryClient.search.test.ts @@ -1,5 +1,5 @@ /** - * MemoryClient unit tests — search (v2 default, filters). + * MemoryClient unit tests — search (v3 endpoint, filters). * Tests verify request construction, not mock response echo. */ import { MemoryClient } from "../mem0"; @@ -17,7 +17,10 @@ installConsoleSuppression(); describe("MemoryClient - search()", () => { test("sends POST to /v3/memories/search/ by default", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); const mock = setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); @@ -30,7 +33,10 @@ describe("MemoryClient - search()", () => { test("includes query in request body", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); const mock = setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); @@ -44,7 +50,10 @@ describe("MemoryClient - search()", () => { test("passes filters through to the API body", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); const mock = setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); @@ -56,7 +65,10 @@ describe("MemoryClient - search()", () => { test("passes complex OR filters through to the API body", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); const mock = setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); @@ -73,23 +85,29 @@ describe("MemoryClient - search()", () => { test("does not crash when called without options", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); - const result: Memory[] = await client.search("query"); - expect(Array.isArray(result)).toBe(true); + const result = await client.search("query"); + expect(result).toHaveProperty("results"); }); test("handles empty results array", async () => { const extra = new Map(); - extra.set("/v3/memories/search/", { status: 200, body: [] }); + extra.set("/v3/memories/search/", { + status: 200, + body: { results: [] }, + }); setupMockFetch(extra); const client = new MemoryClient({ apiKey: TEST_API_KEY }); - const result: Memory[] = await client.search("nonexistent query", { + const result = await client.search("nonexistent query", { filters: { userId: "u1" }, }); - expect(result).toHaveLength(0); + expect(result.results).toHaveLength(0); }); });