LibreChat/client
Anubhav Anand d513e55a62
📥 feat: Download Code Blocks as Files (#13715)
*  feat: Add Download button for code blocks

Adds a Download button next to Copy code in both the code block header
bar and the floating bar, saving the block content as a file whose
extension is inferred from the fenced-block language hint.

- getCodeBlockFilename() maps language names to extensions
  (python → code.py), passes extension-like hints through unchanged
  (tsx → code.tsx), and falls back to code.txt; reuses the existing
  triggerDownload() util for the blob download and URL revocation.
- useDownloadCode mirrors useCopyCode (focus restore, 3s reset timer).
- DownloadButton mirrors CopyButton (icon animation, tooltip in
  icon-only mode, aria-label reflecting current state).

Fixes #13470

* Address review: alias extensions + hide floating download on error

- Map alphanumeric language aliases (python3, nodejs, node, golang) to
  their real extension so they download as code.py/.js/.go instead of
  code.python3 etc. — the bare-hint fallback previously passed them
  through verbatim.
- Gate the floating-bar Download button behind error !== true, matching
  CodeBar, so error blocks (e.g. token-balance JSON) don't expose a
  download action once the header scrolls out of view.

* style: show only Run Code with a label in the code block header

Download and Copy code now render as icon-only buttons with tooltips, so
the header reads as one labelled action plus two secondary icons. Below
the md breakpoint Run Code drops its label too, leaving all three as
icons on mobile.

* refactor: extract the shared code bar action button

CopyButton and DownloadButton were identical apart from the icon and
their default labels. Both now wrap a single ActionButton that owns the
class recipe, the icon swap, the label swap and the icon-only tooltip,
so the two cannot drift apart as the bar evolves. The public props of
both components are unchanged.

* fix: keep the Run Code tooltip when its label is hidden

Below the md breakpoint Run Code renders as a bare terminal icon, so it
needs the same hover description Download and Copy already carry. The
button is now always wrapped in the tooltip anchor rather than only in
the explicit iconOnly mode.

* docs: drop the em dash from the extension map comment

---------

Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
2026-08-15 21:09:27 +02:00
..
public
scripts
src 📥 feat: Download Code Blocks as Files (#13715) 2026-08-15 21:09:27 +02:00
sw
test
babel.config.cjs
check_updates.sh
index.html
jest.config.cjs 🚀 chore: Prepare v0.8.8-rc1 (#14394) 2026-08-14 03:24:59 -04:00
jest.resolver.cjs
nginx.conf
package.json 🚀 chore: Prepare v0.8.8-rc1 (#14394) 2026-08-14 03:24:59 -04:00
postcss.config.cjs
tailwind.config.cjs 🎨 feat: Color the Context Gauge by Category and Collapse its Breakdown (#14855) 2026-08-14 22:46:10 -04:00
tsconfig.json
vite.config.ts