From e51df348ce99f64115c2c2b2381efab7e0850344 Mon Sep 17 00:00:00 2001 From: chaithanyak42 Date: Tue, 14 Apr 2026 01:48:22 +0530 Subject: [PATCH] fix(ts-sdk): unwrap v1.1 search response in client, fix TS2339 type errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit search() now unwraps { results: [...] } -> [...] internally (same pattern getAll() already uses), so callers always get Array. Removes redundant unwrap logic from integration test helpers and search.test.ts that caused TS2339 'Property results does not exist on type never' — the false branch of Array.isArray() was unreachable since search() is typed as returning Array. Co-Authored-By: Claude Opus 4.6 (1M context) --- mem0-ts/src/client/mem0.ts | 3 ++- mem0-ts/src/client/tests/integration/helpers.ts | 6 +----- mem0-ts/src/client/tests/integration/search.test.ts | 12 ++---------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts index 33032c234..a9b6cd15e 100644 --- a/mem0-ts/src/client/mem0.ts +++ b/mem0-ts/src/client/mem0.ts @@ -298,7 +298,8 @@ export default class MemoryClient { body: JSON.stringify(payload), }, ); - return response; + // Unwrap v1.1 format: { results: [...] } → [...] + return Array.isArray(response) ? response : (response?.results ?? 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 1eb137264..e873b66b6 100644 --- a/mem0-ts/src/client/tests/integration/helpers.ts +++ b/mem0-ts/src/client/tests/integration/helpers.ts @@ -92,11 +92,7 @@ export async function waitForSearchResults( maxRetries = 4, ): Promise { for (let attempt = 1; attempt <= maxRetries; attempt++) { - const response = await withRetry(() => client.search(query, options)); - // v3 returns { results: [...] }, unwrap for backward compat - const results = Array.isArray(response) - ? response - : (response?.results ?? []); + const results = await withRetry(() => client.search(query, options)); 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 9f3a51610..1f3e9cf89 100644 --- a/mem0-ts/src/client/tests/integration/search.test.ts +++ b/mem0-ts/src/client/tests/integration/search.test.ts @@ -108,30 +108,22 @@ describeIntegration("MemoryClient Integration — Search & History", () => { // ─── Edge cases ───────────────────────────────────────── describe("edge cases", () => { test("search for non-existent user returns empty results", async () => { - const response = await client.search("anything", { + const results = await client.search("anything", { filters: { userId: `nonexistent-user-${randomUUID()}` }, }); - // v3 returns { results: [...] } - const results = Array.isArray(response) - ? response - : (response?.results ?? []); expect(Array.isArray(results)).toBe(true); expect(results.length).toBe(0); }); test("search with top_k param does not throw", async () => { - const response = await client.search( + const results = await client.search( "Tell me about integration test user", { filters: { userId: TEST_USER_ID }, topK: 1, }, ); - // v3 returns { results: [...] } - const results = Array.isArray(response) - ? response - : (response?.results ?? []); expect(Array.isArray(results)).toBe(true); });