@@ -9,13 +9,13 @@ type ThinkingStreamCallback = (text: string) => void
99const DATA_PREFIX = 'data: '
1010const DONE_TOKEN = '[DONE]'
1111
12- const process_stream_chunk = async (
12+ const process_stream_chunk = (
1313 chunk : string ,
1414 buffer : string
15- ) : Promise < {
15+ ) : {
1616 updated_buffer : string
1717 new_content : string
18- } > => {
18+ } => {
1919 let updated_buffer = buffer
2020 let new_content = ''
2121 try {
@@ -33,8 +33,9 @@ const process_stream_chunk = async (
3333 if ( ! json_string || json_string == DONE_TOKEN ) continue
3434
3535 const json_data = JSON . parse ( json_string )
36- if ( json_data . choices ?. [ 0 ] ?. delta ?. content ) {
37- new_content += json_data . choices [ 0 ] . delta . content
36+ const content = json_data . choices ?. [ 0 ] ?. delta ?. content
37+ if ( typeof content == 'string' ) {
38+ new_content += content
3839 }
3940 } catch ( parse_error ) {
4041 Logger . warn ( {
@@ -262,7 +263,7 @@ export const make_api_request = async (params: {
262263 let stream_closed = false
263264
264265 response . data . on ( 'data' , async ( chunk : string ) => {
265- const { updated_buffer, new_content } = await process_stream_chunk (
266+ const { updated_buffer, new_content } = process_stream_chunk (
266267 chunk ,
267268 buffer
268269 )
@@ -293,8 +294,9 @@ export const make_api_request = async (params: {
293294 . trim ( )
294295 if ( json_string && json_string !== DONE_TOKEN ) {
295296 const json_data = JSON . parse ( json_string )
296- if ( json_data . choices ?. [ 0 ] ?. delta ?. content ) {
297- process_content ( json_data . choices [ 0 ] . delta . content )
297+ const content = json_data . choices ?. [ 0 ] ?. delta ?. content
298+ if ( typeof content === 'string' ) {
299+ process_content ( content )
298300 }
299301 }
300302 }
0 commit comments