fix: restore v3 search response format — return {results: [...]} not bare array

The v3 API returns {results: [...]} and the client should pass that
through without unwrapping. Updated return type to Promise<{results: Array<Memory>}>,
removed the unwrap logic, and fixed integration tests to access .results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Soumil Rathi
2026-04-13 13:25:25 -07:00
co-authored by Claude Opus 4.6
parent 0aa0f44ac4
commit 2da2ded2d8
3 changed files with 9 additions and 9 deletions
+2 -3
View File
@@ -280,7 +280,7 @@ export default class MemoryClient {
async search( async search(
query: string, query: string,
options?: SearchMemoryOptions, options?: SearchMemoryOptions,
): Promise<Array<Memory>> { ): Promise<{ results: Array<Memory> }> {
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]);
@@ -298,8 +298,7 @@ export default class MemoryClient {
body: JSON.stringify(payload), body: JSON.stringify(payload),
}, },
); );
// Unwrap v1.1 format: { results: [...] } → [...] return response;
return Array.isArray(response) ? response : (response?.results ?? response);
} }
async delete(memoryId: string): Promise<{ message: string }> { async delete(memoryId: string): Promise<{ message: string }> {
@@ -92,7 +92,8 @@ export async function waitForSearchResults(
maxRetries = 4, maxRetries = 4,
): Promise<Memory[]> { ): Promise<Memory[]> {
for (let attempt = 1; attempt <= maxRetries; attempt++) { 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) { if (results.length > 0) {
return results; return results;
} }
@@ -108,16 +108,16 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
// ─── Edge cases ───────────────────────────────────────── // ─── Edge cases ─────────────────────────────────────────
describe("edge cases", () => { describe("edge cases", () => {
test("search for non-existent user returns empty results", async () => { 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()}` }, filters: { userId: `nonexistent-user-${randomUUID()}` },
}); });
expect(Array.isArray(results)).toBe(true); expect(response).toHaveProperty("results");
expect(results.length).toBe(0); expect(response.results).toHaveLength(0);
}); });
test("search with top_k param does not throw", async () => { 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", "Tell me about integration test user",
{ {
filters: { userId: TEST_USER_ID }, filters: { userId: TEST_USER_ID },
@@ -125,7 +125,7 @@ describeIntegration("MemoryClient Integration — Search & History", () => {
}, },
); );
expect(Array.isArray(results)).toBe(true); expect(response).toHaveProperty("results");
}); });
}); });
}); });