fix: 保留 completed agentMessage 事件 (#56)

Co-authored-by: Codex <codex@pikas.tech>
This commit is contained in:
Lyon
2026-06-02 07:09:12 +08:00
committed by GitHub
parent 5544db96fb
commit 719584e2ce
5 changed files with 52 additions and 16 deletions
+7 -4
View File
@@ -90,11 +90,14 @@ function messageFromEvents(events: RunEvent[]): string | null {
}
function assistantReply(events: RunEvent[]): string {
return events
.filter((event) => event.type === "assistant_message")
const assistantEvents = events.filter((event) => event.type === "assistant_message");
const authoritative = assistantEvents
.filter((event) => event.payload.replyAuthority === true || event.payload.final === true)
.map((event) => textPayload(event.payload))
.filter((text) => text.length > 0)
.join("");
.filter((text) => text.length > 0);
const latestAuthoritative = authoritative.at(-1);
if (latestAuthoritative) return latestAuthoritative;
return assistantEvents.map((event) => textPayload(event.payload)).filter((text) => text.length > 0).join("");
}
function textPayload(payload: JsonRecord): string {