From 2da2ded2d83efa96eeec49511b74d548907ae132 Mon Sep 17 00:00:00 2001 From: Soumil Rathi Date: Mon, 13 Apr 2026 13:25:25 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20restore=20v3=20search=20response=20forma?= =?UTF-8?q?t=20=E2=80=94=20return=20{results:=20[...]}=20not=20bare=20arra?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The v3 API returns {results: [...]} and the client should pass that through without unwrapping. Updated return type to Promise<{results: Array}>, removed the unwrap logic, and fixed integration tests to access .results. Co-Authored-By: Claude Opus 4.6 (1M context) --- mem0-ts/src/client/mem0.ts | 5 ++--- mem0-ts/src/client/tests/integration/helpers.ts | 3 ++- mem0-ts/src/client/tests/integration/search.test.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts index a9b6cd15e..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]); @@ -298,8 +298,7 @@ export default class MemoryClient { body: JSON.stringify(payload), }, ); - // Unwrap v1.1 format: { results: [...] } → [...] - return Array.isArray(response) ? response : (response?.results ?? response); + return response; } async delete(memoryId: string): Promise<{ message: string }> { diff --git a/mem0-ts/src/client/tests/integration/helpers.ts b/mem0-ts/src/client/tests/integration/helpers.ts index e873b66b6..8afd9df8d 100644 --- a/mem0-ts/src/client/tests/integration/helpers.ts +++ b/mem0-ts/src/client/tests/integration/helpers.ts @@ -92,7 +92,8 @@ export async function waitForSearchResults( maxRetries = 4, ): Promise { for (let attempt = 1; attempt <= maxRetries; attempt++) { - const results = await withRetry(() => client.search(query, options)); + const response = await withRetry(() => client.search(query, options)); + const results = response?.results ?? []; if (results.length > 0) { return results; } diff --git a/mem0-ts/src/client/tests/integration/search.test.ts b/mem0-ts/src/client/tests/integration/search.test.ts index 1f3e9cf89..3e5f3f3b7 100644 --- a/mem0-ts/src/client/tests/integration/search.test.ts +++ b/mem0-ts/src/client/tests/integration/search.test.ts @@ -108,16 +108,16 @@ describeIntegration("MemoryClient Integration — Search & History", () => { // ─── Edge cases ───────────────────────────────────────── describe("edge cases", () => { test("search for non-existent user returns empty results", async () => { - const results = await client.search("anything", { + const response = await client.search("anything", { filters: { userId: `nonexistent-user-${randomUUID()}` }, }); - expect(Array.isArray(results)).toBe(true); - expect(results.length).toBe(0); + expect(response).toHaveProperty("results"); + expect(response.results).toHaveLength(0); }); test("search with top_k param does not throw", async () => { - const results = await client.search( + const response = await client.search( "Tell me about integration test user", { filters: { userId: TEST_USER_ID }, @@ -125,7 +125,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => { }, ); - expect(Array.isArray(results)).toBe(true); + expect(response).toHaveProperty("results"); }); }); });