File tree Expand file tree Collapse file tree 1 file changed +17
-10
lines changed Expand file tree Collapse file tree 1 file changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -32,19 +32,26 @@ const AgentModelAdapter: ChatModelAdapter = {
3232
3333 const eventStream = response . body
3434 . pipeThrough ( new TextDecoderStream ( ) )
35- . pipeThrough ( new EventSourceParserStream ( ) ) ;
35+ . pipeThrough ( new EventSourceParserStream ( ) )
36+ . getReader ( ) ;
3637
3738 let text = "" ;
38- // @ts -expect-error "unknown"
39- for await ( const content of eventStream ) {
40- let data = content . data || "" ;
41- if ( data . length > 2 ) {
42- data = data . substring ( 1 , data . length - 1 ) ;
39+
40+ for ( ; ; ) {
41+ const { done, value} = await eventStream . read ( )
42+ if ( ! done ) {
43+ let data = value . data || "" ;
44+ if ( data . length > 2 ) {
45+ data = data . substring ( 1 , data . length - 1 ) ;
46+ }
47+ text += data ;
48+ yield {
49+ content : [ { type : "text" , text } ] ,
50+ } ;
51+ continue
52+ } else {
53+ break
4354 }
44- text += data ;
45- yield {
46- content : [ { type : "text" , text } ] ,
47- } ;
4855 }
4956 } ,
5057} ;
You can’t perform that action at this time.
0 commit comments