fix: order reasoning before reply text

This commit is contained in:
Peter Steinberger
2026-01-07 07:05:07 +01:00
parent 75c66acfd8
commit 03928106c7
4 changed files with 41 additions and 3 deletions

View File

@@ -129,6 +129,42 @@ describe("subscribeEmbeddedPiSession", () => {
expect(payload.text).toBe("Hello block");
});
it("prepends reasoning before text when enabled", () => {
let handler: ((evt: unknown) => void) | undefined;
const session: StubSession = {
subscribe: (fn) => {
handler = fn;
return () => {};
},
};
const onBlockReply = vi.fn();
subscribeEmbeddedPiSession({
session: session as unknown as Parameters<
typeof subscribeEmbeddedPiSession
>[0]["session"],
runId: "run",
onBlockReply,
blockReplyBreak: "message_end",
includeReasoning: true,
});
const assistantMessage = {
role: "assistant",
content: [
{ type: "thinking", thinking: "Because it helps" },
{ type: "text", text: "Final answer" },
],
} as AssistantMessage;
handler?.({ type: "message_end", message: assistantMessage });
expect(onBlockReply).toHaveBeenCalledTimes(1);
const payload = onBlockReply.mock.calls[0][0];
expect(payload.text).toBe("_Reasoning:_\n_Because it helps_\n\nFinal answer");
});
it("emits block replies on text_end and does not duplicate on message_end", () => {
let handler: ((evt: unknown) => void) | undefined;
const session: StubSession = {