mirror of https://github.com/openclaw/openclaw.git
Compaction/Safeguard: keep multimodal hints in preserved tail
This commit is contained in:
parent
04f2e405aa
commit
b656de6de7
|
|
@ -530,6 +530,22 @@ describe("compaction-safeguard recent-turn preservation", () => {
|
|||
expect(section).toContain("- Assistant: [non-text content: toolCall]");
|
||||
});
|
||||
|
||||
it("keeps non-text placeholders for mixed-content preserved messages", () => {
|
||||
const section = formatPreservedTurnsSection([
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "text", text: "caption text" },
|
||||
{ type: "image", data: "abc", mimeType: "image/png" },
|
||||
],
|
||||
timestamp: 1,
|
||||
} as unknown as AgentMessage,
|
||||
]);
|
||||
|
||||
expect(section).toContain("- User: caption text");
|
||||
expect(section).toContain("[non-text content: image]");
|
||||
});
|
||||
|
||||
it("clamps preserve count into a safe range", () => {
|
||||
expect(resolveRecentTurnsPreserve(undefined)).toBe(3);
|
||||
expect(resolveRecentTurnsPreserve(-1)).toBe(0);
|
||||
|
|
|
|||
|
|
@ -201,6 +201,9 @@ function formatNonTextPlaceholder(content: unknown): string | null {
|
|||
if (content === null || content === undefined) {
|
||||
return null;
|
||||
}
|
||||
if (typeof content === "string") {
|
||||
return null;
|
||||
}
|
||||
if (!Array.isArray(content)) {
|
||||
return "[non-text content]";
|
||||
}
|
||||
|
|
@ -355,7 +358,8 @@ function formatPreservedTurnsSection(messages: AgentMessage[]): string {
|
|||
const nonTextPlaceholder = formatNonTextPlaceholder(
|
||||
(message as { content?: unknown }).content,
|
||||
);
|
||||
const rendered = text || nonTextPlaceholder;
|
||||
const rendered =
|
||||
text && nonTextPlaceholder ? `${text}\n${nonTextPlaceholder}` : text || nonTextPlaceholder;
|
||||
if (!rendered) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue