File tree 2 files changed +26
-22
lines changed
2 files changed +26
-22
lines changed Original file line number Diff line number Diff line change 3
3
"version" : " v0.5.0" ,
4
4
"description" : " Run gptscript in node.js" ,
5
5
"main" : " dist/gptscript.js" ,
6
- "type" : " module" ,
7
6
"repository" : {
8
7
"type" : " git" ,
9
8
"url" : " git+https://github.com/gptscript-ai/node-gptscript.git"
Original file line number Diff line number Diff line change @@ -184,26 +184,32 @@ export class Run {
184
184
this . req = http . request ( options , ( res : http . IncomingMessage ) => {
185
185
this . state = RunState . Running
186
186
res . on ( "data" , ( chunk : any ) => {
187
- const c = chunk . toString ( ) . replace ( / ^ ( d a t a : ) / , "" ) . trim ( )
188
- if ( c === "[DONE]" ) {
189
- return
190
- }
191
-
192
- let e : any
193
- try {
194
- e = JSON . parse ( frag + c )
195
- } catch {
196
- frag += c
197
- return
198
- }
199
- frag = ""
200
-
201
- if ( e . stderr ) {
202
- this . stderr = ( this . stderr || "" ) + ( typeof e . stderr === "string" ? e . stderr : JSON . stringify ( e . stderr ) )
203
- } else if ( e . stdout ) {
204
- this . stdout = ( this . stdout || "" ) + ( typeof e . stdout === "string" ? e . stdout : JSON . stringify ( e . stdout ) )
205
- } else {
206
- frag = this . emitEvent ( frag + c )
187
+ for ( let line of ( chunk . toString ( ) + frag ) . split ( "\n" ) ) {
188
+ const c = line . replace ( / ^ ( d a t a : ) / , "" ) . trim ( )
189
+ if ( ! c ) {
190
+ continue
191
+ }
192
+
193
+ if ( c === "[DONE]" ) {
194
+ return
195
+ }
196
+
197
+ let e : any
198
+ try {
199
+ e = JSON . parse ( c )
200
+ } catch {
201
+ frag = c
202
+ return
203
+ }
204
+ frag = ""
205
+
206
+ if ( e . stderr ) {
207
+ this . stderr = ( this . stderr || "" ) + ( typeof e . stderr === "string" ? e . stderr : JSON . stringify ( e . stderr ) )
208
+ } else if ( e . stdout ) {
209
+ this . stdout = ( this . stdout || "" ) + ( typeof e . stdout === "string" ? e . stdout : JSON . stringify ( e . stdout ) )
210
+ } else {
211
+ frag = this . emitEvent ( c )
212
+ }
207
213
}
208
214
} )
209
215
@@ -270,7 +276,6 @@ export class Run {
270
276
if ( ! event ) {
271
277
continue
272
278
}
273
-
274
279
let f : Frame
275
280
try {
276
281
f = JSON . parse ( event ) as Frame
You can’t perform that action at this time.
0 commit comments