Skip to content
Closed
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: 1 addition & 1 deletion gateway/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ def extract_media(content: str) -> Tuple[List[Tuple[str, bool]], str]:
# Extract MEDIA:<path> tags, allowing optional whitespace after the colon
# and quoted/backticked paths for LLM-formatted outputs.
media_pattern = re.compile(
r'''[`"']?MEDIA:\s*(?P<path>`[^`\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<path>`[^`\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`"',;:)\]}]|$))[`"']?'''
)
Comment on lines 2415 to 2417
for match in media_pattern.finditer(content):
path = match.group("path").strip()
Expand Down
13 changes: 13 additions & 0 deletions tests/gateway/test_platform_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading