mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:31:00 +00:00
fix(outbound): strip internal runtime scaffolding
This commit is contained in:
@@ -72,6 +72,26 @@ describe("discordOutbound", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("sanitizes internal runtime scaffolding before Discord delivery", () => {
|
||||
expect(
|
||||
discordOutbound.sanitizeText?.({
|
||||
text: "<previous_response>null</previous_response>visible",
|
||||
payload: { text: "<previous_response>null</previous_response>visible" },
|
||||
}),
|
||||
).toBe("visible");
|
||||
});
|
||||
|
||||
it("preserves Discord-native angle markup while stripping internal scaffolding", () => {
|
||||
expect(
|
||||
discordOutbound.sanitizeText?.({
|
||||
text: "soon <t:1710000000:R> run </deploy:123> <previous_response>null</previous_response>",
|
||||
payload: {
|
||||
text: "soon <t:1710000000:R> run </deploy:123> <previous_response>null</previous_response>",
|
||||
},
|
||||
}),
|
||||
).toBe("soon <t:1710000000:R> run </deploy:123> ");
|
||||
});
|
||||
|
||||
it("forwards explicit formatting options to Discord text sends", async () => {
|
||||
await discordOutbound.sendText?.({
|
||||
cfg: {},
|
||||
|
||||
@@ -26,6 +26,19 @@ import {
|
||||
} from "./outbound-send-context.js";
|
||||
|
||||
export const DISCORD_TEXT_CHUNK_LIMIT = 2000;
|
||||
const DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_BLOCK_RE =
|
||||
/<\s*(system-reminder|previous_response)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi;
|
||||
const DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_SELF_CLOSING_RE =
|
||||
/<\s*(?:system-reminder|previous_response)\b[^>]*\/\s*>/gi;
|
||||
const DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_TAG_RE =
|
||||
/<\s*\/?\s*(?:system-reminder|previous_response)\b[^>]*>/gi;
|
||||
|
||||
function stripDiscordInternalRuntimeScaffolding(text: string): string {
|
||||
return text
|
||||
.replace(DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_BLOCK_RE, "")
|
||||
.replace(DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_SELF_CLOSING_RE, "")
|
||||
.replace(DISCORD_INTERNAL_RUNTIME_SCAFFOLDING_TAG_RE, "");
|
||||
}
|
||||
|
||||
type DiscordThreadBindingsModule = typeof import("./monitor/thread-bindings.js");
|
||||
|
||||
@@ -97,6 +110,7 @@ export const discordOutbound: ChannelOutboundAdapter = {
|
||||
maxLines: ctx?.formatting?.maxLinesPerMessage,
|
||||
}),
|
||||
textChunkLimit: DISCORD_TEXT_CHUNK_LIMIT,
|
||||
sanitizeText: ({ text }) => stripDiscordInternalRuntimeScaffolding(text),
|
||||
pollMaxOptions: 10,
|
||||
normalizePayload: ({ payload }) => normalizeDiscordApprovalPayload(payload),
|
||||
presentationCapabilities: {
|
||||
|
||||
Reference in New Issue
Block a user