File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type {
77 OutboundDeliveryResult ,
88} from "openclaw/plugin-sdk/channel-send-result" ;
99import { PlatformMessageNotDispatchedError } from "openclaw/plugin-sdk/error-runtime" ;
10+ import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking" ;
1011import { canonicalBytes , REEF_MAX_PLAINTEXT_BYTES } from "../protocol/index.js" ;
1112import { normalizeReefTarget } from "./config-schema.js" ;
1213import { 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 } ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { createStaticReplyToModeResolver } from "openclaw/plugin-sdk/conversatio
1818import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime" ;
1919import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env" ;
2020import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime" ;
21+ import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking" ;
2122import {
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
474476export const zalouserMessagingAdapter = {
475477 targetPrefixes : [ "zalouser" , "zlu" ] ,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments