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
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(
query: string,
options?: SearchMemoryOptions,
): Promise<Array<Memory>> {
): Promise<{ results: Array<Memory> }> {
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 }> {
@@ -92,7 +92,8 @@ export async function waitForSearchResults(
maxRetries = 4,
): Promise<Memory[]> {
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;
}
@@ -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");
});
});
});