@@ -4,9 +4,7 @@ import { ApiQueryAgentResponse } from "./response/api-response.js";
44import {
55 QueryAgentResponse ,
66 ComparisonOperator ,
7- SearchModeResponse ,
87} from "./response/response.js" ;
9- import { QueryAgentSearcher } from "./search.js" ;
108import { ApiSearchModeResponse } from "./response/api-response.js" ;
119import { QueryAgentError } from "./response/error.js" ;
1210
@@ -101,23 +99,6 @@ it("runs the query agent", async () => {
10199 } ) ;
102100} ) ;
103101
104- it ( "prepareSearch returns a QueryAgentSearcher" , async ( ) => {
105- const mockClient = {
106- getConnectionDetails : jest . fn ( ) . mockResolvedValue ( {
107- host : "test-cluster" ,
108- bearerToken : "test-token" ,
109- headers : { "X-Provider" : "test-key" } ,
110- } ) ,
111- } as unknown as WeaviateClient ;
112-
113- const agent = new QueryAgent ( mockClient , {
114- systemPrompt : "test system prompt" ,
115- } ) ;
116-
117- const searcher = agent . configureSearch ( "test query" ) ;
118- expect ( searcher ) . toBeInstanceOf ( QueryAgentSearcher ) ;
119- } ) ;
120-
121102it ( "search-only mode success: caches searches and sends on subsequent request" , async ( ) => {
122103 const mockClient = {
123104 getConnectionDetails : jest . fn ( ) . mockResolvedValue ( {
@@ -195,14 +176,10 @@ it("search-only mode success: caches searches and sends on subsequent request",
195176 } as Response ) ;
196177 } ) as jest . Mock ;
197178
198- const agent = new QueryAgent ( mockClient ) ;
199- const searcher = agent . configureSearch ( "test query" , {
200- collections : [ "test_collection" ] ,
201- } ) ;
202-
203- const first = await searcher . run ( { limit : 2 , offset : 0 } ) ;
179+ const agent = new QueryAgent ( mockClient )
204180
205- expect ( first ) . toEqual < SearchModeResponse < undefined > > ( {
181+ const first = await agent . search ( "test query" , { limit : 2 , collections : [ "test_collection" ] } ) ;
182+ expect ( first ) . toMatchObject ( {
206183 originalQuery : apiSuccess . original_query ,
207184 searches : [
208185 {
@@ -231,14 +208,24 @@ it("search-only mode success: caches searches and sends on subsequent request",
231208 totalTime : 1.5 ,
232209 searchResults : apiSuccess . search_results ,
233210 } ) ;
211+ expect ( typeof first . next ) . toBe ( "function" ) ;
234212
235213 // First request should have searches: null (generation request)
236214 expect ( capturedBodies [ 0 ] . searches ) . toBeNull ( ) ;
237- const second = await searcher . run ( { limit : 2 , offset : 1 } ) ;
215+
216+ // Second request uses the next method on the first response
217+ const second = await first . next ( { limit : 2 , offset : 1 } ) ;
238218 // Second request should include the original searches (execution request)
239219 expect ( capturedBodies [ 1 ] . searches ) . toEqual ( apiSuccess . searches ) ;
240220 // Response mapping should be the same (because response is mocked)
241- expect ( second ) . toEqual ( first ) ;
221+ expect ( second ) . toMatchObject ( {
222+ originalQuery : apiSuccess . original_query ,
223+ searches : first . searches ,
224+ usage : first . usage ,
225+ totalTime : first . totalTime ,
226+ searchResults : first . searchResults ,
227+ } ) ;
228+ expect ( typeof second . next ) . toBe ( "function" ) ;
242229} ) ;
243230
244231it ( "search-only mode failure propagates QueryAgentError" , async ( ) => {
@@ -266,12 +253,8 @@ it("search-only mode failure propagates QueryAgentError", async () => {
266253 ) as jest . Mock ;
267254
268255 const agent = new QueryAgent ( mockClient ) ;
269- const searcher = agent . configureSearch ( "test query" , {
270- collections : [ "test_collection" ] ,
271- } ) ;
272-
273256 try {
274- await searcher . run ( { limit : 2 , offset : 0 } ) ;
257+ await agent . search ( "test query" , { limit : 2 , collections : [ "test_collection" ] } ) ;
275258 } catch ( err ) {
276259 expect ( err ) . toBeInstanceOf ( QueryAgentError ) ;
277260 expect ( err ) . toMatchObject ( {
0 commit comments