Skip to content

Commit 5e05c84

Browse files
committed
fix: track and process fragmented stdout stream
Signed-off-by: Donnie Adams <[email protected]>
1 parent b35abfe commit 5e05c84

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/gptscript.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ export class Run {
305305
this.state = RunState.Running
306306

307307
if (this.process.stdout) {
308+
let frag = ""
308309
this.process.stdout.on("data", (data: any) => {
309-
this.processStdout(data.toString())
310+
frag = this.processStdout(frag + data.toString())
310311
})
311312
}
312313

@@ -339,17 +340,16 @@ export class Run {
339340
})
340341
}
341342

342-
processStdout(data: string | object): void {
343+
processStdout(data: string | object): string {
343344
if (typeof data === "string") {
344345
if (data.trim() === "") {
345-
return
346+
return ""
346347
}
347348

348349
try {
349350
data = JSON.parse(data)
350351
} catch (e) {
351-
this.err = `Failed to parse stdout: "${data}"`
352-
return
352+
return data as string
353353
}
354354
}
355355

@@ -361,6 +361,8 @@ export class Run {
361361
this.state = RunState.Finished
362362
this.chatState = undefined
363363
}
364+
365+
return ""
364366
}
365367

366368
request(tool: any) {
@@ -655,12 +657,14 @@ class RunSubcommand extends Run {
655657
super(subCommand, path, content, opts, bin, gptscriptURL)
656658
}
657659

658-
processStdout(data: string | object) {
660+
processStdout(data: string | object): string {
659661
if (typeof data === "string") {
660662
this.stdout = (this.stdout || "") + data
661663
} else {
662664
this.stdout = JSON.stringify(data)
663665
}
666+
667+
return ""
664668
}
665669
}
666670

0 commit comments

Comments
 (0)