mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-28 08:52:45 +00:00
fix: preserve rewritten stream snapshots in webchat (#58641) (thanks @neeravmakwana)
This commit is contained in:
@@ -134,6 +134,25 @@ describe("handleChatEvent", () => {
|
||||
expect(state.chatMessages).toEqual([]);
|
||||
});
|
||||
|
||||
it("replaces the stream when a delta snapshot gets shorter", () => {
|
||||
const state = createState({
|
||||
sessionKey: "main",
|
||||
chatRunId: "run-1",
|
||||
chatStream: "Alpha beta",
|
||||
});
|
||||
const payload: ChatEventPayload = {
|
||||
runId: "run-1",
|
||||
sessionKey: "main",
|
||||
state: "delta",
|
||||
message: {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Alpha" }],
|
||||
},
|
||||
};
|
||||
expect(handleChatEvent(state, payload)).toBe("delta");
|
||||
expect(state.chatStream).toBe("Alpha");
|
||||
});
|
||||
|
||||
it("returns final for another run when payload has no message", () => {
|
||||
const state = createActiveStreamingState();
|
||||
const payload: ChatEventPayload = {
|
||||
|
||||
@@ -295,10 +295,7 @@ export function handleChatEvent(state: ChatState, payload?: ChatEventPayload) {
|
||||
if (payload.state === "delta") {
|
||||
const next = extractText(payload.message);
|
||||
if (typeof next === "string" && !isSilentReplyStream(next)) {
|
||||
const current = state.chatStream ?? "";
|
||||
if (!current || next.length >= current.length) {
|
||||
state.chatStream = next;
|
||||
}
|
||||
state.chatStream = next;
|
||||
}
|
||||
} else if (payload.state === "final") {
|
||||
const finalMessage = normalizeFinalAssistantMessage(payload.message);
|
||||
|
||||
Reference in New Issue
Block a user