fix(mattermost): suppress reasoning previews

This commit is contained in:
lawrence3699
2026-04-22 11:44:23 +10:00
committed by Peter Steinberger
parent 367faac596
commit bb43c7b89f
3 changed files with 30 additions and 4 deletions

View File

@@ -252,6 +252,29 @@ describe("shouldClearMattermostDraftPreview", () => {
});
describe("deliverMattermostReplyWithDraftPreview", () => {
it("suppresses reasoning-prefixed finals before preview finalization", async () => {
const draftStream = createDraftStreamMock();
const deliverFinal = vi.fn(async () => {});
await deliverMattermostReplyWithDraftPreview({
payload: { text: " \n Reasoning:\n_hidden_" } as never,
info: { kind: "final" },
client: createMattermostClientMock(),
draftStream,
effectiveReplyToId: "thread-root-1",
resolvePreviewFinalText: (text) => text?.trim(),
previewState: { finalizedViaPreviewPost: false },
logVerboseMessage: vi.fn(),
deliverFinal,
});
expect(deliverFinal).not.toHaveBeenCalled();
expect(draftStream.flush).not.toHaveBeenCalled();
expect(draftStream.discardPending).not.toHaveBeenCalled();
expect(draftStream.clear).not.toHaveBeenCalled();
expect(updateMattermostPostSpy).not.toHaveBeenCalled();
});
it("deletes the preview after a successful normal final send", async () => {
const draftStream = createDraftStreamMock();
const deliverFinal = vi.fn(async () => {});

View File

@@ -55,7 +55,10 @@ import {
type MattermostWebSocketFactory,
} from "./monitor-websocket.js";
import { runWithReconnect } from "./reconnect.js";
import { deliverMattermostReplyPayload } from "./reply-delivery.js";
import {
deliverMattermostReplyPayload,
shouldSuppressMattermostReasoningReply,
} from "./reply-delivery.js";
import type {
ChannelAccountSnapshot,
ChatType,
@@ -289,7 +292,7 @@ type MattermostDraftPreviewDeliverParams = {
export async function deliverMattermostReplyWithDraftPreview(
params: MattermostDraftPreviewDeliverParams,
): Promise<void> {
if (params.payload.isReasoning) {
if (shouldSuppressMattermostReasoningReply(params.payload)) {
return;
}

View File

@@ -26,7 +26,7 @@ type SendMattermostMessage = (
const REASONING_PREFIX = "reasoning:";
function shouldSuppressReasoningReply(payload: ReplyPayload): boolean {
export function shouldSuppressMattermostReasoningReply(payload: ReplyPayload): boolean {
if (payload.isReasoning === true) {
return true;
}
@@ -49,7 +49,7 @@ export async function deliverMattermostReplyPayload(params: {
tableMode: MarkdownTableMode;
sendMessage: SendMattermostMessage;
}): Promise<void> {
if (shouldSuppressReasoningReply(params.payload)) {
if (shouldSuppressMattermostReasoningReply(params.payload)) {
return;
}
const reply = resolveSendableOutboundReplyParts(params.payload, {