mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:28:26 +00:00
fix(gateway): strip inline directive tags from displayed text
This commit is contained in:
@@ -10,6 +10,7 @@ import type { MsgContext } from "../../auto-reply/templating.js";
|
||||
import { createReplyPrefixOptions } from "../../channels/reply-prefix.js";
|
||||
import { resolveSessionFilePath } from "../../config/sessions.js";
|
||||
import { resolveSendPolicy } from "../../sessions/send-policy.js";
|
||||
import { stripInlineDirectiveTagsForDisplay } from "../../utils/directive-tags.js";
|
||||
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
|
||||
import {
|
||||
abortChatRunById,
|
||||
@@ -103,9 +104,10 @@ function sanitizeChatHistoryContentBlock(block: unknown): { block: unknown; chan
|
||||
const entry = { ...(block as Record<string, unknown>) };
|
||||
let changed = false;
|
||||
if (typeof entry.text === "string") {
|
||||
const res = truncateChatHistoryText(entry.text);
|
||||
const stripped = stripInlineDirectiveTagsForDisplay(entry.text);
|
||||
const res = truncateChatHistoryText(stripped.text);
|
||||
entry.text = res.text;
|
||||
changed ||= res.truncated;
|
||||
changed ||= stripped.changed || res.truncated;
|
||||
}
|
||||
if (typeof entry.partialJson === "string") {
|
||||
const res = truncateChatHistoryText(entry.partialJson);
|
||||
@@ -158,9 +160,10 @@ function sanitizeChatHistoryMessage(message: unknown): { message: unknown; chang
|
||||
}
|
||||
|
||||
if (typeof entry.content === "string") {
|
||||
const res = truncateChatHistoryText(entry.content);
|
||||
const stripped = stripInlineDirectiveTagsForDisplay(entry.content);
|
||||
const res = truncateChatHistoryText(stripped.text);
|
||||
entry.content = res.text;
|
||||
changed ||= res.truncated;
|
||||
changed ||= stripped.changed || res.truncated;
|
||||
} else if (Array.isArray(entry.content)) {
|
||||
const updated = entry.content.map((block) => sanitizeChatHistoryContentBlock(block));
|
||||
if (updated.some((item) => item.changed)) {
|
||||
@@ -170,9 +173,10 @@ function sanitizeChatHistoryMessage(message: unknown): { message: unknown; chang
|
||||
}
|
||||
|
||||
if (typeof entry.text === "string") {
|
||||
const res = truncateChatHistoryText(entry.text);
|
||||
const stripped = stripInlineDirectiveTagsForDisplay(entry.text);
|
||||
const res = truncateChatHistoryText(stripped.text);
|
||||
entry.text = res.text;
|
||||
changed ||= res.truncated;
|
||||
changed ||= stripped.changed || res.truncated;
|
||||
}
|
||||
|
||||
return { message: changed ? entry : message, changed };
|
||||
|
||||
Reference in New Issue
Block a user