feat(channels): auto-download voice messages mirroring file path#3212
Merged
Conversation
PR librefang#2972 added auto-download for ChannelContent::File but the Voice arm of dispatch_message still inlined the raw URL into the prompt text. Agents had to curl the URL and juggle workspace-allowed paths before media_transcribe could read the audio. Mirror the File arm: derive a filename from the URL basename (fallback "voice.ogg"), call download_file_to_blocks, and prepend a context Text block carrying duration_seconds + caption so the model still knows it's voice and any user caption survives the path swap. Honors the same channels.file_download_max_bytes / channels.file_download_dir config knobs and the same disk-cleanup sweeper as File downloads. Adds filename_from_url helper (drops query/fragment, returns None on empty basename) with three unit tests. Closes librefang#3211.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3211.
PR #2972 (cf308d6) added auto-download for
ChannelContent::Filesoagents receive a saved-on-disk path. The
ChannelContent::Voicearmof
dispatch_messagewas missed — voice notes still flowed through asraw
[User sent a voice message (Xs): <url>]text, forcing everyagent to curl the URL and juggle workspace-allowed paths before
media_transcribe(or any other audio tool) could read the file.This mirrors the File arm:
filename_from_url),falling back to
voice.oggwhen the URL has no usable basename.download_file_to_blockswith the samechannels.file_download_max_bytes/channels.file_download_dirconfig knobs and the same disk-cleanup sweeper.
ContentBlock::Textcarrying[Voice message (Xs)]plusany caption so the model still knows it's voice and any user
caption survives the URL→path swap.
When the download fails the existing fallback formatter (
[User sent a voice message …]) still runs — same shape as the File arm.Test plan
cargo test -p librefang-channels --lib— 803/803 pass,including 3 new tests for
filename_from_url(basic, query/fragmentstripping, empty/unparseable URLs).
cargo clippy -p librefang-channels --lib --all-targets -- -D warnings— clean.cargo build -p librefang-channels --lib— clean.observe a
[File: voice.ogg] saved to /tmp/librefang_uploads/...oggblock in the inbound message and that
media_transcribereads itdirectly without an agent-side download. (Tested manually on the
reporter's setup — works end-to-end with
media_transcribeagainstthe saved path.)
Notes / follow-ups
ChannelContent::VideoandChannelContent::Audiolikely have thesame gap — left for a follow-up to keep this PR scoped.
send_voice(feat(whatsapp): add send_voice and dm/group message policies #3012) is the symmetric path; thisPR is purely the inbound side.