mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:50:45 +00:00
test: tighten whatsapp outbound sanitizer follow-up
This commit is contained in:
@@ -24,6 +24,7 @@ import { elide } from "./util.js";
|
||||
|
||||
export async function deliverWebReply(params: {
|
||||
replyResult: ReplyPayload;
|
||||
normalizedReplyResult?: ReturnType<typeof normalizeWhatsAppOutboundPayload<ReplyPayload>>;
|
||||
msg: WebInboundMsg;
|
||||
mediaLocalRoots?: readonly string[];
|
||||
maxMediaBytes: number;
|
||||
@@ -45,9 +46,11 @@ export async function deliverWebReply(params: {
|
||||
}
|
||||
const tableMode = params.tableMode ?? "code";
|
||||
const chunkMode = params.chunkMode ?? "length";
|
||||
const normalizedReply = normalizeWhatsAppOutboundPayload(replyResult, {
|
||||
normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation,
|
||||
});
|
||||
const normalizedReply =
|
||||
params.normalizedReplyResult ??
|
||||
normalizeWhatsAppOutboundPayload(replyResult, {
|
||||
normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation,
|
||||
});
|
||||
const convertedText = markdownToWhatsApp(convertMarkdownTables(normalizedReply.text, tableMode));
|
||||
const textChunks = chunkMarkdownTextWithMode(convertedText, textLimit, chunkMode);
|
||||
const mediaList = normalizedReply.mediaUrls ?? [];
|
||||
|
||||
@@ -327,6 +327,7 @@ export async function dispatchWhatsAppBufferedReply(params: {
|
||||
}
|
||||
await params.deliverReply({
|
||||
replyResult: normalizedDeliveryPayload,
|
||||
normalizedReplyResult: normalizedDeliveryPayload,
|
||||
msg: params.msg,
|
||||
mediaLocalRoots,
|
||||
maxMediaBytes: params.maxMediaBytes,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
sanitizeAssistantVisibleText,
|
||||
sanitizeAssistantVisibleTextWithProfile,
|
||||
stripToolCallXmlTags,
|
||||
stripAssistantInternalScaffolding,
|
||||
} from "./assistant-visible-text.js";
|
||||
import { stripModelSpecialTokens } from "./model-special-tokens.js";
|
||||
@@ -504,6 +505,17 @@ describe("stripAssistantInternalScaffolding", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("stripToolCallXmlTags", () => {
|
||||
it("strips plural function/tool wrapper XML only when the opt-in flag is enabled", () => {
|
||||
const input =
|
||||
'prefix <function_calls><invoke name="find">secret</invoke></function_calls> suffix';
|
||||
expect(stripToolCallXmlTags(input)).toBe(input);
|
||||
expect(stripToolCallXmlTags(input, { stripFunctionCallsXmlPayloads: true })).toBe(
|
||||
"prefix suffix",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sanitizeAssistantVisibleText", () => {
|
||||
it("strips minimax, tool XML, downgraded tool markers, and think tags in one pass", () => {
|
||||
const input = [
|
||||
|
||||
Reference in New Issue
Block a user