Skip to content

The agent that grows with you

fix(discord): suppress link embeds in tool preview markdown links

Tekniumdd600d1ace72
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..917bb57cf7b
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+coffee-the-dev
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py
index c064716fd52..56cb90a9491 100644
--- a/plugins/platforms/discord/adapter.py
+++ b/plugins/platforms/discord/adapter.py
@@ -46,11 +46,14 @@ def _format_discord_markdown_link(label: str, url: str) -> str:
URL label can therefore win over the Markdown destination and remain a
broken link. Dropping only the scheme keeps the preview recognizable while
leaving one unambiguous click target.
+
+ The destination is wrapped in angle brackets (``<url>``) so Discord does
+ not unfurl an OG-preview embed under every tool progress bubble.
"""
label = _DISCORD_URL_LABEL_SCHEME_RE.sub("", label, count=1)
escaped_label = _DISCORD_MARKDOWN_LINK_LABEL_RE.sub(r"\\\1", label)
escaped_url = quote(url, safe=":/?#[]@!$&'*+,;=%")
- return f"[{escaped_label}]({escaped_url})"
+ return f"[{escaped_label}](<{escaped_url}>)"
class _Snowflake:
diff --git a/tests/gateway/test_discord_format.py b/tests/gateway/test_discord_format.py
index 56726fc2b2e..5684eb6f1c5 100644
--- a/tests/gateway/test_discord_format.py
+++ b/tests/gateway/test_discord_format.py
@@ -54,7 +54,7 @@ class TestDiscordToolPreviewFormatting:
out = adapter.format_tool_preview(ToolPreview(visible, truncated=True, url=url))
- assert out == f"[hermes-agent.nousresearch...]({url})"
+ assert out == f"[hermes-agent.nousresearch...](<{url}>)"
def test_truncated_url_label_is_not_a_second_url_target(self):
from agent.display import ToolPreview
@@ -67,7 +67,7 @@ class TestDiscordToolPreviewFormatting:
assert out == (
"[centaur.run/secrets/advanced-...]"
- "(https://centaur.run/secrets/advanced-permissioning)"
+ "(<https://centaur.run/secrets/advanced-permissioning>)"
)
def test_link_escapes_discord_markdown_delimiters(self):
@@ -82,7 +82,7 @@ class TestDiscordToolPreviewFormatting:
assert adapter.format_tool_preview(preview) == (
r"[example.com/docs/\[beta\]...]"
- r"(https://example.com/docs/_%28beta%29)"
+ r"(<https://example.com/docs/_%28beta%29>)"
)
def test_structured_tool_event_uses_clickable_truncated_url(self):
@@ -99,7 +99,7 @@ class TestDiscordToolPreviewFormatting:
)
assert out is not None
- assert f"[{visible.removeprefix('https://')}]({url})" in out
+ assert f"[{visible.removeprefix('https://')}](<{url}>)" in out
def test_untruncated_url_remains_plain(self):
from agent.display import ToolPreview
diff --git a/tests/gateway/test_run_progress_topics.py b/tests/gateway/test_run_progress_topics.py
index d3adf9160b8..18020f0a964 100644
--- a/tests/gateway/test_run_progress_topics.py
+++ b/tests/gateway/test_run_progress_topics.py
@@ -577,7 +577,7 @@ def test_discord_truncated_tool_url_links_to_full_destination(monkeypatch, tmp_p
assert adapter.sent
visible = UrlPreviewAgent.URL[:37] + "..."
label = visible.removeprefix("https://")
- assert f"[{label}]({UrlPreviewAgent.URL})" in adapter.sent[0]["content"]
+ assert f"[{label}](<{UrlPreviewAgent.URL}>)" in adapter.sent[0]["content"]
class CommentaryAgent: