Skip to content

Commit 0d8b70f

Browse files
authored
fix(channels): strip internal tool text in Reef and Zalo Personal (#112621)
1 parent d585c0c commit 0d8b70f

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎extensions/reef/src/outbound.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ describe("reefOutboundAdapter", () => {
1818
expect(reefOutboundAdapter.deliveryMode).toBe("gateway");
1919
});
2020

21+
it("removes internal tool text while preserving user-visible examples", () => {
22+
const sanitizeText = reefOutboundAdapter.sanitizeText;
23+
if (!sanitizeText) {
24+
throw new Error("expected Reef outbound sanitizeText hook");
25+
}
26+
const sanitize = (text: string) => sanitizeText({ text, payload: { text } });
27+
const fenced = ["```xml", '<tool_call>{"name":"exec"}</tool_call>', "```"].join("\n");
28+
29+
expect(sanitize("Done.\n⚠️ 🛠️ `search repos (agent)` failed")).toBe("Done.");
30+
expect(sanitize('<tool_call>{"name":"exec"}</tool_call>Message sent.')).toBe("Message sent.");
31+
expect(sanitize("The encrypted message was delivered.")).toBe(
32+
"The encrypted message was delivered.",
33+
);
34+
expect(sanitize(fenced)).toBe(fenced);
35+
expect(sanitize("⚠️ 🛠️ `search repos (agent)` failed")).toBe("");
36+
});
37+
2138
it("normalizes the SDK target and delegates only message content/context to the guarded flow", async () => {
2239
const order: string[] = [];
2340
const send = vi.fn(

‎extensions/reef/src/outbound.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
OutboundDeliveryResult,
88
} from "openclaw/plugin-sdk/channel-send-result";
99
import { PlatformMessageNotDispatchedError } from "openclaw/plugin-sdk/error-runtime";
10+
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
1011
import { canonicalBytes, REEF_MAX_PLAINTEXT_BYTES } from "../protocol/index.js";
1112
import { normalizeReefTarget } from "./config-schema.js";
1213
import { isPermanentReefOutboundRejection, prepareReefMessageId } from "./flow.js";
@@ -141,6 +142,7 @@ export const reefOutboundAdapter: ChannelOutboundAdapter = {
141142
deliveryMode: "gateway",
142143
textChunkLimit: REEF_MAX_PLAINTEXT_BYTES,
143144
chunker: chunkReefText,
145+
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
144146
prepareConversationTurnMessageId: ({ text, threadId }) => {
145147
// Runs in Gateway correlation setup before the operation and queue row exist.
146148
assertAtomicReefMessageFits({ text, threadId });

‎extensions/zalouser/src/channel.adapters.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { createStaticReplyToModeResolver } from "openclaw/plugin-sdk/conversatio
1818
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
1919
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
2020
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
21+
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
2122
import {
2223
checkZcaAuthenticated,
2324
listZalouserAccountIds,
@@ -469,7 +470,8 @@ export const zalouserOutboundAdapter = {
469470
emptyResult: createEmptyChannelResult("zalouser"),
470471
}),
471472
...zalouserRawSendResultAdapter,
472-
};
473+
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
474+
} satisfies ChannelOutboundAdapter;
473475

474476
export const zalouserMessagingAdapter = {
475477
targetPrefixes: ["zalouser", "zlu"],

‎extensions/zalouser/src/channel.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ describe("zalouser outbound", () => {
9898
} as never);
9999
});
100100

101+
it("removes internal tool text while preserving user-visible examples", () => {
102+
const sanitizeText = zalouserOutboundAdapter.sanitizeText;
103+
if (!sanitizeText) {
104+
throw new Error("expected Zalo Personal outbound sanitizeText hook");
105+
}
106+
const sanitize = (text: string) => sanitizeText({ text, payload: { text } });
107+
const fenced = ["```xml", '<tool_call>{"name":"exec"}</tool_call>', "```"].join("\n");
108+
109+
expect(sanitize("Done.\n⚠️ 🛠️ `search repos (agent)` failed")).toBe("Done.");
110+
expect(sanitize('<tool_call>{"name":"exec"}</tool_call>Message sent.')).toBe("Message sent.");
111+
expect(sanitize("The personal message was delivered.")).toBe(
112+
"The personal message was delivered.",
113+
);
114+
expect(sanitize(fenced)).toBe(fenced);
115+
expect(sanitize("⚠️ 🛠️ `search repos (agent)` failed")).toBe("");
116+
});
117+
101118
it("passes markdown chunk settings through sendText", async () => {
102119
const sendText = requireZalouserSendText();
103120

0 commit comments

Comments
 (0)