Build: sync main manifests and harden Matrix reasoning suppression

This commit is contained in:
Gustavo Madeira Santana
2026-03-12 00:57:09 +00:00
parent 2f71349c03
commit 3d82e38d9d
6 changed files with 94 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
filterMessagingToolMediaDuplicates,
shouldSuppressReasoningPayload,
shouldSuppressMessagingToolReplies,
} from "./reply-payloads.js";
@@ -154,3 +155,27 @@ describe("shouldSuppressMessagingToolReplies", () => {
).toBe(true);
});
});
describe("shouldSuppressReasoningPayload", () => {
it("suppresses raw reasoning-prefix text even when isReasoning is absent", () => {
expect(shouldSuppressReasoningPayload({ text: " Reasoning:\n_hidden_" })).toBe(true);
});
it("suppresses thinking-tag-only text even when isReasoning is absent", () => {
expect(shouldSuppressReasoningPayload({ text: "<think>hidden</think>" })).toBe(true);
});
it("does not suppress text that merely mentions reasoning mid-message", () => {
expect(
shouldSuppressReasoningPayload({
text: "Intro line\nReasoning: appears in content but is not a prefix",
}),
).toBe(false);
});
it("does not suppress messages that contain an answer outside thinking tags", () => {
expect(shouldSuppressReasoningPayload({ text: "<think>hidden</think>Visible answer" })).toBe(
false,
);
});
});

View File

@@ -4,6 +4,7 @@ import { normalizeChannelId } from "../../channels/plugins/index.js";
import type { ReplyToMode } from "../../config/types.js";
import { normalizeTargetForProvider } from "../../infra/outbound/target-normalization.js";
import { normalizeOptionalAccountId } from "../../routing/account-id.js";
import { stripReasoningTagsFromText } from "../../shared/text/reasoning-tags.js";
import { parseTelegramTarget } from "../../telegram/targets.js";
import type { OriginatingChannelType } from "../templating.js";
import type { ReplyPayload } from "../types.js";
@@ -71,7 +72,18 @@ export function isRenderablePayload(payload: ReplyPayload): boolean {
}
export function shouldSuppressReasoningPayload(payload: ReplyPayload): boolean {
return payload.isReasoning === true;
if (payload.isReasoning === true) {
return true;
}
const text = payload.text;
if (typeof text !== "string") {
return false;
}
if (text.trimStart().toLowerCase().startsWith("reasoning:")) {
return true;
}
const stripped = stripReasoningTagsFromText(text, { mode: "strict", trim: "both" });
return !stripped && stripped !== text;
}
export function applyReplyThreading(params: {