diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index d396015468862..5e2b8c735fe73 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -2413,7 +2413,7 @@ def extract_media(content: str) -> Tuple[List[Tuple[str, bool]], str]: # Extract MEDIA: tags, allowing optional whitespace after the colon # and quoted/backticked paths for LLM-formatted outputs. media_pattern = re.compile( - r'''[`"']?MEDIA:\s*(?P`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?''' + r'''[`"']?MEDIA:\s*(?P`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|md|json|ya?ml|toml|log|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?''' ) for match in media_pattern.finditer(content): path = match.group("path").strip() diff --git a/tests/gateway/test_platform_base.py b/tests/gateway/test_platform_base.py index b7d96d4dc3ee4..a66e188e26903 100644 --- a/tests/gateway/test_platform_base.py +++ b/tests/gateway/test_platform_base.py @@ -348,6 +348,19 @@ def test_as_document_directive_alone_does_not_attach_voice_flag(self): assert media == [("/tmp/x.jpg", False)] # voice flag stays False assert "[[as_document]]" not in cleaned + @pytest.mark.parametrize( + "ext", + ["md", "json", "yaml", "yml", "toml", "log"], + ) + def test_media_tag_accepts_text_config_extensions(self, ext): + """MEDIA: tags must extract text/config artifact paths so callers can + deliver them as file attachments instead of leaving the raw tag in + the platform message body (see issue #32601, bug 1).""" + content = f"MEDIA:/tmp/notes.{ext}" + media, cleaned = BasePlatformAdapter.extract_media(content) + assert media == [(f"/tmp/notes.{ext}", False)] + assert "MEDIA:" not in cleaned + def test_both_directives_can_coexist(self): """A response could (rarely) contain both [[audio_as_voice]] for an ogg file AND [[as_document]] for an attached image. The voice flag