fix(worker): don't double-append streamed answer when completed event carries content
This commit is contained in:
@@ -42,3 +42,19 @@ export const resolveTurnOutcome = (args: {
|
||||
}
|
||||
return { text };
|
||||
};
|
||||
|
||||
// Pure decision for whether the `content` on an `assistant_completed` event
|
||||
// should be folded into the accumulated assistant text.
|
||||
//
|
||||
// Some runtimes (Claude `-p --output-format stream-json`, OpenCode) emit the
|
||||
// final answer TWICE: once as streamed `assistant_delta` chunks and again as
|
||||
// the `content` on the terminal `assistant_completed`/`result` event. Appending
|
||||
// both yields a doubled "<answer><answer>". So only fold in the completed
|
||||
// content when nothing has streamed yet (a runtime that emits only a final
|
||||
// result). When deltas already carried the answer, skip it. The truly-empty
|
||||
// case is still covered by resolveTurnOutcome's recoveredText/finalMessage
|
||||
// fallback, so nothing is lost.
|
||||
export const shouldAppendCompletedContent = (
|
||||
currentText: string,
|
||||
completedContent?: string,
|
||||
): boolean => Boolean(completedContent) && !currentText.trim();
|
||||
|
||||
Reference in New Issue
Block a user