@@ -129,81 +129,96 @@ describe('prismProvider', () => {
129129 )
130130 } )
131131
132- it ( 'uses the shared tool loop with reasoning replay and returns tool results' , async ( ) => {
133- mockPrepareTools . mockReturnValue ( {
134- tools : [
135- {
136- type : 'function' ,
137- function : {
138- name : 'lookup' ,
139- description : 'Look up a value' ,
140- parameters : { type : 'object' , properties : { } , required : [ ] } ,
141- } ,
142- } ,
143- ] ,
144- toolChoice : 'auto' ,
145- forcedTools : [ ] ,
146- } )
147- mockCreateToolStream . mockImplementation (
148- ( options : { onComplete : ( result : Record < string , unknown > ) => void } ) => {
149- options . onComplete ( {
150- content : 'Found it' ,
151- tokens : { input : 10 , output : 5 , total : 15 } ,
152- cost : { input : 0 , output : 0 , toolCost : 0.25 , total : 0.25 } ,
153- toolCalls : { list : [ ] , count : 0 } ,
154- toolResults : [ { value : 'result' } ] ,
155- modelTime : 1 ,
156- toolsTime : 1 ,
157- firstResponseTime : 1 ,
158- iterations : 2 ,
159- } )
160- return new ReadableStream ( {
161- start ( controller ) {
162- controller . close ( )
163- } ,
164- } )
165- }
166- )
167-
168- const result = await prismProvider . executeRequest (
169- request ( {
170- responseFormat : undefined ,
132+ it . each ( [
133+ { mode : 'non-streaming' , stream : false } ,
134+ { mode : 'streaming' , stream : true } ,
135+ ] ) (
136+ 'uses the shared tool loop with reasoning replay and returns tool results ($mode)' ,
137+ async ( { stream } ) => {
138+ mockPrepareTools . mockReturnValue ( {
171139 tools : [
172140 {
173- id : 'lookup' ,
174- description : 'Look up a value' ,
175- params : { } ,
176- parameters : { type : 'object' , properties : { } , required : [ ] } ,
141+ type : 'function' ,
142+ function : {
143+ name : 'lookup' ,
144+ description : 'Look up a value' ,
145+ parameters : { type : 'object' , properties : { } , required : [ ] } ,
146+ } ,
177147 } ,
178148 ] ,
149+ toolChoice : 'auto' ,
150+ forcedTools : [ ] ,
179151 } )
180- )
152+ mockCreateToolStream . mockImplementation (
153+ ( options : { onComplete : ( result : Record < string , unknown > ) => void } ) => {
154+ options . onComplete ( {
155+ content : 'Found it' ,
156+ tokens : { input : 10 , output : 5 , total : 15 } ,
157+ cost : { input : 0 , output : 0 , toolCost : 0.25 , total : 0.25 } ,
158+ toolCalls : { list : [ ] , count : 0 } ,
159+ toolResults : [ { value : 'result' } ] ,
160+ modelTime : 1 ,
161+ toolsTime : 1 ,
162+ firstResponseTime : 1 ,
163+ iterations : 2 ,
164+ } )
165+ return new ReadableStream ( {
166+ start ( controller ) {
167+ controller . close ( )
168+ } ,
169+ } )
170+ }
171+ )
172+
173+ const result = await prismProvider . executeRequest (
174+ request ( {
175+ responseFormat : undefined ,
176+ stream,
177+ tools : [
178+ {
179+ id : 'lookup' ,
180+ description : 'Look up a value' ,
181+ params : { } ,
182+ parameters : { type : 'object' , properties : { } , required : [ ] } ,
183+ } ,
184+ ] ,
185+ } )
186+ )
187+
188+ expect ( mockCreateToolStream ) . toHaveBeenCalledWith (
189+ expect . objectContaining ( {
190+ providerName : 'Prism' ,
191+ preserveAssistantReasoning : true ,
192+ basePayload : expect . objectContaining ( {
193+ model : 'prism/deepseek-v4.1-flash' ,
194+ tool_choice : 'auto' ,
195+ } ) ,
196+ } )
197+ )
181198
182- expect ( mockCreateToolStream ) . toHaveBeenCalledWith (
183- expect . objectContaining ( {
184- providerName : 'Prism' ,
185- preserveAssistantReasoning : true ,
186- basePayload : expect . objectContaining ( {
187- model : 'prism/deepseek-v4.1-flash' ,
188- tool_choice : 'auto' ,
189- } ) ,
199+ if ( 'stream' in result ) {
200+ const reader = result . stream . getReader ( )
201+ while ( ! ( await reader . read ( ) ) . done ) { }
202+ expect ( result . execution . output . toolResults ) . toEqual ( [ { value : 'result' } ] )
203+ return
204+ }
205+
206+ expect ( result ) . toMatchObject ( { toolResults : [ { value : 'result' } ] } )
207+ expect ( mockCalculateCost ) . toHaveBeenCalledWith ( 'prism/deepseek-v4.1-flash' , 10 , 5 )
208+ expect ( result . cost ) . toEqual ( {
209+ input : 0.000003 ,
210+ output : 0.000006 ,
211+ toolCost : 0.25 ,
212+ total : 0.250009 ,
213+ pricing : {
214+ input : 0.3 ,
215+ cachedInput : 0.07 ,
216+ output : 1.2 ,
217+ updatedAt : '2026-09-12' ,
218+ } ,
190219 } )
191- )
192- expect ( result ) . toMatchObject ( { toolResults : [ { value : 'result' } ] } )
193- expect ( mockCalculateCost ) . toHaveBeenCalledWith ( 'prism/deepseek-v4.1-flash' , 10 , 5 )
194- expect ( result . cost ) . toEqual ( {
195- input : 0.000003 ,
196- output : 0.000006 ,
197- toolCost : 0.25 ,
198- total : 0.250009 ,
199- pricing : {
200- input : 0.3 ,
201- cachedInput : 0.07 ,
202- output : 1.2 ,
203- updatedAt : '2026-09-12' ,
204- } ,
205- } )
206- } )
220+ }
221+ )
207222
208223 it . each ( [ 'none' , 'low' , 'medium' , 'high' ] ) ( 'sends Prism reasoning effort %s' , async ( value ) => {
209224 await prismProvider . executeRequest ( request ( { reasoningEffort : value } ) )
0 commit comments