From b04699ed3bb6d9b4d86decad11843948a998cd6b Mon Sep 17 00:00:00 2001 From: luoxiao6645 Date: Tue, 2 Jun 2026 18:30:52 +0800 Subject: [PATCH] fix(media): add missing extensions to MEDIA delivery whitelist (#37318) Extensions like .md, .py, .json, .yaml were silently dropped because extract_media() and _TOOL_MEDIA_RE used stale hardcoded extension lists that didn't include common document/code types. Changes: - base.py: add .markdown, .toml, .py, .js, .ts, .sh, .bash, .zsh to MEDIA_DELIVERY_EXTS (now 60 extensions, was 52) - run.py: replace two hardcoded extension regexes with _MEDIA_EXT_ALTERNATION imported from base.py, eliminating the duplicate maintenance that caused the mismatch Co-Authored-By: Claude Opus 4.8 --- gateway/platforms/base.py | 6 ++++-- gateway/run.py | 11 +++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index 89806a739312f..7e6fb9f40bccc 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -1169,15 +1169,17 @@ def _log_safe_path(path: str) -> str: # Audio (delivered as voice/audio where supported) ".mp3", ".wav", ".ogg", ".opus", ".m4a", ".flac", # Documents (uploaded as file attachments) - ".pdf", ".docx", ".doc", ".odt", ".rtf", ".txt", ".md", ".epub", + ".pdf", ".docx", ".doc", ".odt", ".rtf", ".txt", ".md", ".markdown", ".epub", # Spreadsheets / data - ".xlsx", ".xls", ".ods", ".csv", ".tsv", ".json", ".xml", ".yaml", ".yml", + ".xlsx", ".xls", ".ods", ".csv", ".tsv", ".json", ".xml", ".yaml", ".yml", ".toml", # Presentations ".pptx", ".ppt", ".odp", ".key", # Archives ".zip", ".tar", ".gz", ".tgz", ".bz2", ".xz", ".7z", ".rar", ".apk", ".ipa", # Web / rendered output ".html", ".htm", + # Scripts / code files (plain-text, safe to deliver as documents) + ".py", ".js", ".ts", ".sh", ".bash", ".zsh", ) # Regex alternation fragment of bare extensions (no leading dot), e.g. diff --git a/gateway/run.py b/gateway/run.py index f11686ccd360b..08df247c15be2 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -680,11 +680,9 @@ def _last_transcript_timestamp(history: Optional[List[Dict[str, Any]]]) -> Any: # pattern so a bare ``MEDIA:`` token in prose (no deliverable extension) is never # auto-appended. Kept local to the auto-append path; the producer-tool allowlist # below is the primary guard, this is the secondary precision guard. +from gateway.platforms.base import _MEDIA_EXT_ALTERNATION # noqa: E402 _TOOL_MEDIA_RE = re.compile( - r'MEDIA:((?:[A-Za-z]:[/\\]|/|~\/)\S+\.(?:png|jpe?g|gif|webp|' - r'mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|' - r'flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|' - r'txt|csv|apk|ipa))', + r'MEDIA:((?:[A-Za-z]:[/\\]|/|~\/)\S+\.(?:' + _MEDIA_EXT_ALTERNATION + r'))', re.IGNORECASE, ) @@ -17764,10 +17762,7 @@ def _clarify_callback_sync(question: str, choices) -> str: _hc = _hm.get("content", "") if "MEDIA:" in _hc: _TOOL_MEDIA_RE = re.compile( - r'MEDIA:((?:[A-Za-z]:[/\\]|/|~\/)\S+\.(?:png|jpe?g|gif|webp|' - r'mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|' - r'flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|' - r'txt|csv|apk|ipa))', + r'MEDIA:((?:[A-Za-z]:[/\\]|/|~\/)\S+\.(?:' + _MEDIA_EXT_ALTERNATION + r'))', re.IGNORECASE ) for _match in _TOOL_MEDIA_RE.finditer(_hc):