Skip to content

feat(webui): show generated images and audio inline in chat - #6384

Merged
kovtcharov-amd merged 4 commits into
mainfrom
fix/540-inline-media
Nov 2, 2026
Merged

kovtcharov-amd merged 4 commits into
mainfrom
fix/540-inline-media

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

When GAIA generated an image, a song or a sound effect, the Agent UI chat showed only a file path, so you had to go find the file to see or hear it. Now the image appears in the answer (click it for full size) and music and sound effects get a player with the file name and length. Both come back when you reopen the chat. Only files GAIA saved in its own generation folders are shown or served.

Scope, as decided for this PR: this covers rendering what the agent already makes. Microphone input from the original issue is left out; voice input is tracked in #702. Text-to-speech output is not included either. No agent prompts or tool schemas change, so no eval run is needed.

One visible change: a turn that only generates an image or audio, with no text, now ends as done with the card as its answer instead of "GAIA ran its tools but didn't write an answer".

🔍 Technical details
  • The host builds the image / audio card from the tool result's image_path / audio_path in the chat stream loop (media_card in gaia/ui/generated_media.py). That one place covers in-process and relayed turns. No sidecar emits the card, so no sidecar apiVersion bump: audio_path just joins RESULT_PATH_KEYS / SUMMARY_VIEW_KEYS, and an older sidecar gets no audio card.
  • GET /api/media/{kind}/{name} only accepts a plain name with an allowed raster/WAV suffix that is a regular non-symlink file directly in ~/.gaia/cache/sd/images or ~/.gaia/cache/audio/generations. The response carries nosniff and CSP: sandbox. Everything else returns 404.
  • Contract §4.3 gains an additive audio primitive, and image.src now also accepts /api/media/image/<name>. The TUI draws both as caption + saved path (+ length) instead of "Unsupported".
  • fromApiMessages rebuilds message.cards from persisted tool steps (the hydration feat(ui): route email chat through the sidecar /v1/email/query loop (V2-10) #2109 left as a TODO). The post-turn refetch no longer drops those cards.

Test plan

  • python -m pytest tests/unit/chat/ui/test_generated_media.py covers traversal, encoded traversal, absolute paths, symlinks out and in, subfolders, suffixes, the cold state, the relay stream, persistence and the tools' folders matching the served ones. The 3 symlink cases skip on Windows without the privilege and run on Linux CI.
  • python -m pytest tests/unit/chat/ui + relay/SSE/audio/SD suites: 3245 passed
  • npx vitest run (2321 passed, incl. render-media.test.tsx), npx tsc --noEmit
  • cd tui && go test ./...
  • Manual: with enable_sd_tools / enable_audio_generation_tools on, generate an image and a sound effect in gaia chat --ui, then reload the chat. Both cards should still be there.

Fixes #540

Images from generate_image and tracks from generate_music /
generate_sound_effect now appear in the answer instead of as a bare path:
the image (click for full size) and an audio player with the file name and
length. They come back when the chat is reopened.

- The Agent UI host builds the `image` / `audio` card from the tool
  result's saved path, for in-process and relayed turns alike, so no
  sidecar contract version changes; `audio_path` joins the result keys a
  relayed turn carries.
- GET /api/media/{kind}/{name} serves only a plain file name sitting
  directly in GAIA's own image or audio generation folder: traversal,
  absolute paths, symlinks, subfolders and other suffixes are 404s.
- `audio` is a new generic render primitive (additive); the TUI draws it,
  and a generated image, as caption + saved path (+ length).
- A reloaded answer rebuilds its cards from the tool steps that persisted
  them.

Microphone input is out of scope; voice input is tracked in #702.

Fixes #540
@github-actions github-actions Bot added documentation Documentation changes tests Test changes electron Electron app changes tui Go terminal UI (gaia-tui) labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Generated images and music/sound effects now show up inline in the Agent UI chat and come back when you reopen the conversation; the TUI shows a text card instead of "Unsupported". The new file route is tightly locked down: it serves only plain file names sitting directly in GAIA's own generation folders, and the live evidence below shows it refusing traversal, symlinks, subfolders and SVG. I found no blocking issues. Two small UI polish items:

  • The image's new "show full size / show smaller" button label is hard-coded English, so it won't translate in the Arabic UI. Route it through the translation hook.
  • The audio length (e.g. 1:05) isn't marked left-to-right, so it can render oddly in the Arabic layout. Wrap it the way other numbers are.

Real-world evidence

The CI evidence stage started the real backend and called the new media route over HTTP. The rendered chat screenshot is pending strix-halo lane, and the TUI cards were N/A on that lane, so the visual result rests on static review and the component tests until those land.

$ curl -sD- 'http://127.0.0.1:4299/api/media/image/zephyr-violet-otter-92.png'
HTTP/1.1 200 OK
content-type: image/png
x-content-type-options: nosniff
content-security-policy: sandbox
<body: PNG image data, 1 x 1, 69 bytes, sha256 b1ff9c8ea3a780ba>   (on-disk file: b1ff9c8ea3a780ba ✔)

$ curl -sD- 'http://127.0.0.1:4299/api/media/audio/track-desk-17C.wav'
HTTP/1.1 200 OK
content-type: audio/wav
<body: RIFF WAVE audio, PCM 16 bit, mono 16000 Hz, sha256 20eaebffe1816e0f>   (on-disk file: 20eaebffe1816e0f ✔)

$ curl 'http://127.0.0.1:4299/api/media/image/link.png'
HTTP 404  {"detail":"'link.png' is a symlink"}
$ curl 'http://127.0.0.1:4299/api/media/image/..%2F..%2F..%2Foutside%2Fsecret.png'
HTTP 404  {"detail":"Not Found"}
$ curl 'http://127.0.0.1:4299/api/media/image/evil.svg'
HTTP 404  {"detail":"'evil.svg' is not a served image type"}
$ curl 'http://127.0.0.1:4299/api/media/video/zephyr-violet-otter-92.png'
HTTP 404  {"detail":"unknown media kind 'video'"}
image result (in-process): {"render": "image", "data": {"src": "/api/media/image/zephyr-violet-otter-92.png", "path": ".../cache/sd/images/zephyr-violet-otter-92.png", "caption": "a mascot named Zephyr", "alt": "a mascot named Zephyr"}}
audio result (relayed, under data): {"render": "audio", "data": {"src": "/api/media/audio/track-desk-17C.wav", ..., "duration_seconds": 2.0}}
failed call: null
path outside media dir: null

Spot regression: the sibling /api/files/image and /api/files/browse routes and /api/sessions behaved as before, including the 403 for files outside the home folder. There were no server tracebacks.

🔍 Technical details

🟢 Minor

  1. Untranslated aria-label (src/gaia/apps/webui/src/components/render/ImageCard.tsx:48). 'Show smaller' / 'Show full size' are new user-facing strings. CLAUDE.md requires them to go through useT. No render card uses useT yet, so this would be the first; add keys for both strings to the locale files.

  2. Duration not LTR-isolated (src/gaia/apps/webui/src/components/render/AudioCard.tsx:54). CLAUDE.md asks for numbers with units to be wrapped in <bdi dir="ltr">.

                         {data.duration_seconds !== undefined && <bdi dir="ltr">{formatDuration(data.duration_seconds)}</bdi>}
    
  3. Relayed results lose their summary view (src/gaia/ui/_chat_helpers.py:4584). {**event, **card} replaces a relayed tool_result's data (the summary view: summary, success, audio_path) with the card payload. Nothing downstream reads those fields for generate-image or generate-audio results today, so nothing breaks. It is still a silent overwrite worth a one-line comment, or a guard that only merges when data holds nothing beyond the path keys.

Strengths

  • The route checks every layer and fails loudly: plain name, suffix allowlist, root must exist, explicit symlink refusal, resolve(strict=True), then real.parent == root. The card builder also requires the tool's reported path to resolve to the served file, so an image saved elsewhere never gets a URL. Each 404 says why.
  • The card is built once, on the host stream loop, so in-process and relayed turns are both covered without a sidecar API bump. Reload works through the existing step persistence, which finishes the feat(ui): route email chat through the sidecar /v1/email/query loop (V2-10) #2109 hydration TODO.
  • The tests are thorough: encoded traversal, symlinks in and out, the cold state with no folder yet, float WAV headers, and an end-to-end relay stream with persistence. The frontend's resolveMediaSrc repeats the name checks, so the <img>/<audio> allowlist stays the security boundary.

…ngth

The image card's full-size toggle label now goes through the locale files,
and the audio length is wrapped left-to-right so it reads correctly in the
Arabic layout. Notes why a relayed result's data gives way to the card.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Fixed all three in the latest commit. The full-size toggle label now comes from the locale files (English and Arabic), the audio length is wrapped left-to-right, and a one-line comment explains why a relayed result's data is replaced by the card.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/gaia/npm ✅ ALLOW experimental experimental 3 high body.injection.credential_request, body.injection.guardrail_bypass, body.injection.persona_override

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

A tool-reported image or audio path like a UNC share path (//host/share/x.png) made the
server resolve it, which opens an SMB connection and can leak the user's
NTLM credentials, before the generated-folder check ran. The card builder
now refuses UNC, device and NT-namespace spellings, and any path whose
folder is not spelled as the media folder, from the string alone; only then
does it resolve the file.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

A generated-image result that named a network share (for example \host\share\x.png) made the server open that share before deciding the file wasn't GAIA's, which on Windows can hand the user's credentials to the remote host. That's fixed: such paths are now refused from the text alone, and real generated images and audio still show inline.

🔍 Technical details
  • media_card now rejects UNC, \?\, \.\, \??\ and mixed-slash spellings, NUL bytes, and any path whose folder isn't lexically the media folder (raw or resolved spelling), before any resolve/stat. Only then does the existing resolve-and-compare run.
  • New tests cover 14 remote/device spellings in both in-process and relayed form, plus other-drive paths. A spy on os/pathlib asserts the path is never touched. 29 of them fail on the previous head.
  • Corpus of 35 legitimate paths (spaces, unicode, emoji, upper-case, forward slashes, .., resolved, relative, audio) plus negatives, run against the old and new module: identical cards, 0 diffs.
  • Merged origin/main (one conflict in tui/internal/ui/cards/cards.go: kept both audio and main's diff case, and updated the header comment to six primitives with four drawn). go test ./internal/ui/cards ./internal/event passes.
  • Before/after on 170 importer test files: PR + main 4726 passed, 0 failed. Main: 5 timing failures in test_model_slot_discipline.py under -n 8 that pass when run alone on both. No PASS→FAIL.
  • Known limit: if GAIA_CONFIG_DIR itself is on a UNC share, generated media won't preview inline. It fails closed and is logged.

Comment thread src/gaia/ui/generated_media.py Dismissed
Comment thread src/gaia/ui/generated_media.py Dismissed
Comment thread src/gaia/ui/generated_media.py Dismissed
Comment thread src/gaia/ui/routers/files.py Dismissed
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 055f801 Nov 2, 2026
107 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/540-inline-media branch November 2, 2026 06:12
kovtcharov-amd added a commit that referenced this pull request Nov 16, 2026
Main now plays generated audio inline (#6384), so this keeps only the save
folder, the Outputs list and the narration lines. A track saved with save_to
is written to GAIA's audio folder first, so the chat still plays it, and then
copied to the user's folder; the copy is what Outputs lists. Drops the second
audio card, the /api/files/audio route, the generated_audio payload, the TUI
result row the card now covers, and the skill and live-test changes.
kovtcharov-amd added a commit that referenced this pull request Nov 20, 2026
… in Outputs (#6118)

Generated music and sound effects already play in the chat (#6384), but
they could only be saved in GAIA's own cache, the session panel's
Outputs never listed them, and a long generation showed a generic step
line. Now "save it in my game's audio folder" writes a copy there, never
replacing an existing file, while the chat keeps playing GAIA's own
copy; each track is listed under Outputs (the user's copy when there is
one); and both apps' step lines read "Composing 30 s of music: …" or
"Generating a 3 s sound effect".

**Evals to watch:** `generate_music` and `generate_sound_effect` gain a
`save_to` argument, so the next RC eval should compare `gaia_media` and
`gaia_skills_tasks` (the music-gen tasks) against the flagship baseline.

<details>
<summary>🔍 Technical details</summary>

- `save_to` takes an absolute folder or a new `.wav` path. It is checked
against the host's write policy before anything about the path is
reported, refused before generation when relative, missing, existing or
not allowed, and written with exclusive create after generation. A
failed copy leaves no partial file and the error names where the
original is.
- The `music-gen` skill (now 1.1.0) tells the model to pass the user's
folder as `save_to` instead of copying the file by hand.
- The result keeps `audio_path` (GAIA's copy, which the inline player
serves) and adds `saved_to`. The turn summary lists `saved_to` as the
output and records GAIA's copy as `copy_of`, so the Outputs list shows
the track once.
- Cut from the earlier version of this PR because main covers it or it
is a separate change: the second audio card and `/api/files/audio` route
(main's player from #6384), the `generated_audio` result payload and TUI
result row (main's audio card shows path and length), the WAV chunk
parser and missing-model download hint, the rest of the `music-gen`
skill rewrite, and the live-test and lane-allowlist follow-ups.
</details>

## Test plan
- [x] `python -m pytest tests/unit/test_audio_generation_tools.py
tests/unit/chat/ui/test_session_outputs.py
tests/unit/test_sse_narration.py
tests/unit/chat/ui/test_generated_media.py`
- [x] `go test ./internal/ui/chat/...` in `tui/`; `npx tsc --noEmit` and
vitest on the session panel and locales
- [ ] With ACE-Step downloaded: "make 20 seconds of calm piano and save
it in <an existing folder>". The track plays in the chat, the WAV lands
in the folder, Outputs lists it once, and asking again with the same
file name is refused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes electron Electron app changes tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebUI: Multi-modal rendering — display images, audio, and rich content inline in chat

2 participants