File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,30 @@ function textFromRecord(record: GooseJsonRecord): string {
114114 return joined ;
115115}
116116
117+ function isPlaceholderResult ( text : string ) : boolean {
118+ return / ^ \? + $ / . test ( text . trim ( ) ) ;
119+ }
120+
121+ function stitchAssistantChunks ( chunks : string [ ] ) : string {
122+ let stitched = "" ;
123+ for ( const chunk of chunks ) {
124+ if ( ! chunk ) continue ;
125+ if ( ! stitched ) {
126+ stitched = chunk ;
127+ continue ;
128+ }
129+ if ( chunk . startsWith ( stitched ) ) {
130+ stitched = chunk ;
131+ continue ;
132+ }
133+ if ( stitched . endsWith ( chunk ) ) {
134+ continue ;
135+ }
136+ stitched += chunk ;
137+ }
138+ return stitched ;
139+ }
140+
117141function parseGooseResponse ( output : string ) : {
118142 text : string ;
119143 sessionId ?: string ;
@@ -159,7 +183,9 @@ function parseGooseResponse(output: string): {
159183 throw new Error ( errorMessage ) ;
160184 }
161185
162- const text = ( resultText || assistantChunks [ assistantChunks . length - 1 ] || plainChunks . join ( "\n" ) ) . trim ( ) ;
186+ const assistantText = stitchAssistantChunks ( assistantChunks ) ;
187+ const finalResultText = isPlaceholderResult ( resultText ) ? "" : resultText ;
188+ const text = ( finalResultText || assistantText || plainChunks . join ( "\n" ) ) . trim ( ) ;
163189 if ( ! text ) {
164190 throw new Error ( "Goose returned empty response" ) ;
165191 }
You can’t perform that action at this time.
0 commit comments