Skip to content

Commit 0bfc8bd

Browse files
authored
Merge pull request #99 from odefun/feat/goose-result-message-825149
fix: handle placeholder Goose result message
2 parents e7748fe + e2b1d05 commit 0bfc8bd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/agents/goose/client.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
117141
function 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
}

0 commit comments

Comments
 (0)