From 592e6725bae30974d6672cf3d7fb6660bc7d9ed6 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 29 Jun 2026 13:52:11 +0300 Subject: [PATCH] fix: check conversation_stream flag for streaming request detection --- src/Typesense/MultiSearch.ts | 4 +-- test/streaming.node.mock.spec.ts | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Typesense/MultiSearch.ts b/src/Typesense/MultiSearch.ts index 660d93d0..1b038d1c 100644 --- a/src/Typesense/MultiSearch.ts +++ b/src/Typesense/MultiSearch.ts @@ -124,8 +124,8 @@ export default class MultiSearch { ); } - private isStreamingRequest(commonParams: { streamConfig?: unknown }) { - return commonParams.streamConfig !== undefined; + private isStreamingRequest(commonParams: { conversation_stream?: boolean }) { + return commonParams.conversation_stream === true; } private hasAnySearchObjectPagination(searchRequests: MultiSearchRequestsSchema) { diff --git a/test/streaming.node.mock.spec.ts b/test/streaming.node.mock.spec.ts index ea916a5a..cf622fca 100644 --- a/test/streaming.node.mock.spec.ts +++ b/test/streaming.node.mock.spec.ts @@ -152,6 +152,57 @@ describe("Streaming responses with axios-mock-adapter", () => { expect(response.results[0].hits?.length).toBeGreaterThan(0); }); + it("should not treat multisearch as streaming when streamConfig is set but conversation_stream is not", async () => { + const onChunk = vi.fn(); + const onComplete = vi.fn(); + const onError = vi.fn(); + + const streamConfig: MultiSearchResultsStreamConfig<[Essay]> = { + onChunk, + onComplete, + onError, + }; + + let capturedResponseType: string | undefined; + + const jsonResponse = { + results: [ + { + found: 0, + hits: [], + }, + ], + }; + + mock.onAny().reply((config) => { + capturedResponseType = config.responseType; + return [200, jsonResponse, { "content-type": "application/json" }]; + }); + + const response = await client.multiSearch.perform<[Essay]>( + { + searches: [ + { + collection: "test-collection", + query_by: "title", + }, + ], + }, + { + q: "*", + streamConfig, + }, + ); + + expect(capturedResponseType).not.toBe("stream"); + expect(onChunk).not.toHaveBeenCalled(); + expect(onComplete).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); + expect(response).toEqual(jsonResponse); + expect(response).not.toHaveProperty("conversation_id"); + expect(response).not.toHaveProperty("message"); + }); + it("should invoke onError callback when an error occurs during stream processing", async () => { const onChunk = vi.fn(); const onComplete = vi.fn();