Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/channel/openclaw-sdk-untyped.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ declare module "openclaw/plugin-sdk/plugin-state-runtime" {
declare module "openclaw/plugin-sdk/web-content-extractor" {
/** Converts sanitized HTML into coarse markdown plus an optional title. */
export function htmlToMarkdown(html: string): { text: string; title?: string };
/** Removes markdown decoration for plain text extraction. */
export function markdownToText(markdown: string): string;
}

declare module "openclaw/plugin-sdk/outbound-media" {
Expand Down
51 changes: 51 additions & 0 deletions src/channel/src/inbound-sdk-compat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { AgentMail } from "agentmail";
import { describe, expect, it, vi } from "vitest";

// OpenClaw 2026.10.5-beta.2 no longer exports markdownToText from this SDK subpath.
vi.mock("openclaw/plugin-sdk/web-content-extractor", async (importOriginal) => {
const { htmlToMarkdown } =
await importOriginal<typeof import("openclaw/plugin-sdk/web-content-extractor")>();
return { htmlToMarkdown };
});

import { resolveAgentMailMessageText } from "./inbound.js";

describe("AgentMail HTML with the current OpenClaw SDK exports", () => {
it.each(["extractedHtml", "html"] as const)("converts %s without markdownToText", (field) => {
const message = {
[field]: '<h2>Next steps</h2><ul><li>Read <a href="https://example.com/guide">the guide</a></li></ul>',
} as AgentMail.Message;

expect(resolveAgentMailMessageText(message)).toBe(
"## Next steps\n\n- Read [the guide](https://example.com/guide)",
);
});

it("prefers extracted HTML over quoted plain-text history", () => {
expect(
resolveAgentMailMessageText({
extractedHtml: "<p>New reply</p>",
text: "New reply\n\nOld quoted history",
html: "<p>Old HTML history</p>",
} as AgentMail.Message),
).toBe("New reply");
});

it("falls back to plain text when extracted HTML has no visible content", () => {
expect(
resolveAgentMailMessageText({
extractedHtml: "<script>hidden()</script>",
text: "Plain-text reply",
} as AgentMail.Message),
).toBe("Plain-text reply");
});

it("falls back to the subject when HTML has no visible content", () => {
expect(
resolveAgentMailMessageText({
html: "<script>hidden()</script>",
subject: " Subject-only request ",
} as AgentMail.Message),
).toBe("Subject-only request");
});
});
6 changes: 3 additions & 3 deletions src/channel/src/inbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AgentMailError, type AgentMail, type AgentMailClient } from "agentmail"
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
import { buildAgentSessionKey, parseAgentSessionKey } from "openclaw/plugin-sdk/routing";
import { htmlToMarkdown, markdownToText } from "openclaw/plugin-sdk/web-content-extractor";
import { htmlToMarkdown } from "openclaw/plugin-sdk/web-content-extractor";
import type { AgentMailLog } from "./log.js";
import { createAgentMailClient } from "./client.js";
import { isAgentMailSenderAllowed, parseSingleFromMailbox } from "./mailbox.js";
Expand Down Expand Up @@ -135,7 +135,7 @@ export function resolveAgentMailMessageText(message: AgentMail.Message): string
}
const extractedHtml = message.extractedHtml?.trim();
const extractedHtmlText = extractedHtml
? markdownToText(htmlToMarkdown(extractedHtml).text).trim()
? htmlToMarkdown(extractedHtml).text.trim()
: "";
if (extractedHtmlText) {
return extractedHtmlText;
Expand All @@ -145,7 +145,7 @@ export function resolveAgentMailMessageText(message: AgentMail.Message): string
return text;
}
const html = message.html?.trim();
const htmlText = html ? markdownToText(htmlToMarkdown(html).text).trim() : "";
const htmlText = html ? htmlToMarkdown(html).text.trim() : "";
return htmlText || message.subject?.trim() || "";
}

Expand Down
Loading