mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 20:56:54 +00:00
fix: stabilize flaky tests and sanitize directive-only chat tags
This commit is contained in:
@@ -10,7 +10,10 @@ 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 {
|
||||
stripInlineDirectiveTagsForDisplay,
|
||||
stripInlineDirectiveTagsFromMessageForDisplay,
|
||||
} from "../../utils/directive-tags.js";
|
||||
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
|
||||
import {
|
||||
abortChatRunById,
|
||||
@@ -527,25 +530,6 @@ function nextChatSeq(context: { agentRunSeq: Map<string, number> }, runId: strin
|
||||
return next;
|
||||
}
|
||||
|
||||
function stripMessageDirectiveTags(
|
||||
message: Record<string, unknown> | undefined,
|
||||
): Record<string, unknown> | undefined {
|
||||
if (!message) {
|
||||
return message;
|
||||
}
|
||||
const content = message.content;
|
||||
if (!Array.isArray(content)) {
|
||||
return message;
|
||||
}
|
||||
const cleaned = content.map((part: Record<string, unknown>) => {
|
||||
if (part.type === "text" && typeof part.text === "string") {
|
||||
return { ...part, text: stripInlineDirectiveTagsForDisplay(part.text).text };
|
||||
}
|
||||
return part;
|
||||
});
|
||||
return { ...message, content: cleaned };
|
||||
}
|
||||
|
||||
function broadcastChatFinal(params: {
|
||||
context: Pick<GatewayRequestContext, "broadcast" | "nodeSendToSession" | "agentRunSeq">;
|
||||
runId: string;
|
||||
@@ -558,7 +542,7 @@ function broadcastChatFinal(params: {
|
||||
sessionKey: params.sessionKey,
|
||||
seq,
|
||||
state: "final" as const,
|
||||
message: stripMessageDirectiveTags(params.message),
|
||||
message: stripInlineDirectiveTagsFromMessageForDisplay(params.message),
|
||||
};
|
||||
params.context.broadcast("chat", payload);
|
||||
params.context.nodeSendToSession(params.sessionKey, "chat", payload);
|
||||
@@ -1089,7 +1073,7 @@ export const chatHandlers: GatewayRequestHandlers = {
|
||||
sessionKey: rawSessionKey,
|
||||
seq: 0,
|
||||
state: "final" as const,
|
||||
message: stripMessageDirectiveTags(appended.message),
|
||||
message: stripInlineDirectiveTagsFromMessageForDisplay(appended.message),
|
||||
};
|
||||
context.broadcast("chat", chatPayload);
|
||||
context.nodeSendToSession(rawSessionKey, "chat", chatPayload);
|
||||
|
||||
Reference in New Issue
Block a user