The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(matrix): import markdown once in the standalone sender, drop the None sentinel
kshitijk4poor05fdbf631735
diff --git a/plugins/platforms/matrix/adapter.py b/plugins/platforms/matrix/adapter.pyindex 398d96ea3fd..1a288fb0f56 100644--- a/plugins/platforms/matrix/adapter.py+++ b/plugins/platforms/matrix/adapter.py@@ -3145,14 +3145,13 @@ async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_fdata = await resp.json()return {"success": True, "platform": "matrix", "chat_id": chat_id,"message_id": data.get("event_id")}- result = Nonefor payload in _standalone_payloads(message):try:result = await asyncio.wait_for(_do_send(payload), timeout=30)except asyncio.TimeoutError:return send_error("Matrix API timeout (30s)")if not result.get("success"):- break+ return resultreturn resultexcept Exception as e:return send_error(f"Matrix send failed: {e}")@@ -3161,11 +3160,13 @@ async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_fdef _standalone_payloads(message: str) -> list[Dict[str, Any]]:"""One m.room.message content per chunk. The caller chunks on characters, and a chunk ofnon-Latin text can still exceed the homeserver's byte cap, so re-chunk on UTF-8 bytes."""+ _md = None+ with suppress(ImportError):+ import markdown as _mdpayloads = []for chunk in BasePlatformAdapter.truncate_message(message, MATRIX_MAX_MESSAGE_LENGTH_CEILING, _utf8_len):payload = {"msgtype": "m.text", "body": chunk}- with suppress(ImportError):- import markdown as _md+ if _md is not None:tokenized, tex_store = _latex_to_tokens(chunk)html = _md.markdown(tokenized, extensions=["fenced_code", "tables"])formatted = {"format": "org.matrix.custom.html", "formatted_body": _tokens_to_mx_maths(