File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
packages/core/src/core/openaiContentGenerator Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,27 @@ describe('OpenAIContentConverter', () => {
207207 expect . objectContaining ( { text : 'visible text' } ) ,
208208 ) ;
209209 } ) ;
210+
211+ it ( 'should not throw when streaming chunk has no delta' , ( ) => {
212+ const chunk = converter . convertOpenAIChunkToGemini ( {
213+ object : 'chat.completion.chunk' ,
214+ id : 'chunk-2' ,
215+ created : 456 ,
216+ choices : [
217+ {
218+ index : 0 ,
219+ // Some OpenAI-compatible providers may omit delta entirely.
220+ delta : undefined ,
221+ finish_reason : null ,
222+ logprobs : null ,
223+ } ,
224+ ] ,
225+ model : 'gpt-test' ,
226+ } as unknown as OpenAI . Chat . ChatCompletionChunk ) ;
227+
228+ const parts = chunk . candidates ?. [ 0 ] ?. content ?. parts ;
229+ expect ( parts ) . toEqual ( [ ] ) ;
230+ } ) ;
210231 } ) ;
211232
212233 describe ( 'convertGeminiToolsToOpenAI' , ( ) => {
Original file line number Diff line number Diff line change @@ -799,7 +799,7 @@ export class OpenAIContentConverter {
799799 const parts : Part [ ] = [ ] ;
800800
801801 const reasoningText = ( choice . delta as ExtendedCompletionChunkDelta )
802- . reasoning_content ;
802+ ? .reasoning_content ;
803803 if ( reasoningText ) {
804804 parts . push ( { text : reasoningText , thought : true } ) ;
805805 }
You can’t perform that action at this time.
0 commit comments