Skip to content

fix: Let Remote Agents download generated files - #18706

Open
Kicer86 wants to merge 1 commit into
LibreChat-AI:devfrom
Kicer86:fix/remote-agent-file-download
Open

Kicer86 wants to merge 1 commit into
LibreChat-AI:devfrom
Kicer86:fix/remote-agent-file-download

Conversation

@Kicer86

@Kicer86 Kicer86 commented Nov 22, 2026

Copy link
Copy Markdown

Pull Request

Before submitting, please review the Contributing Guide.

Documentation changes belong in the LibreChat documentation repository.

Summary

Remote Agent responses can include generated image or file attachments, but their URLs currently point to resources protected by browser-session authentication. A headless client authenticated with a Remote Agent Bearer credential can receive the attachment metadata but cannot download its content.

This PR adds an authenticated file-content endpoint under the Remote Agents API and emits its URL in librechat:attachment events. Remote Agent clients can download authorized generated files using the same Bearer credential as the Responses request, without maintaining a browser session or exposing storage paths.

Fixes #18705

How it works

Agent tool output
  -> stored file metadata
  -> librechat:attachment with /api/agents/v1/files/:file_id/content
  -> Remote Agent client sends GET with its Bearer credential
  -> Remote Agent authentication and feature checks
  -> tenant, ownership and file ACL validation
  -> configured storage strategy streams the content

The endpoint reuses the existing Remote Agent authentication boundary, fileAccess authorization and storage strategy functions. Responses use Cache-Control: no-store and X-Content-Type-Options: nosniff, and file contents are streamed rather than buffered.

Type of change

  • Bug fix

Testing

  1. Request a response through the Remote Agents API that produces a generated file.
  2. Confirm that the resulting librechat:attachment contains /api/agents/v1/files/:file_id/content.
  3. Request that URL using the same Remote Agent Bearer credential.
  4. Confirm that an authorized file is streamed using its configured storage strategy.
  5. Confirm that missing credentials, invalid credentials, disabled Remote Agents and unauthorized file access are rejected.
  6. Confirm that stream-open and stream-transfer failures are handled without exposing storage paths.

Tested environments/configuration:

  • OS: Linux on Raspberry Pi
  • LibreChat base: dev at 407b35307a47b43bb79dcfd902ae9d94c13f6243
  • Authentication: Remote Agent Bearer credentials
  • Storage: mocked local and strategy-backed file streams
  • Local Node.js: 22; the current dev branch requires Node.js 24, so full TypeScript validation is deferred to GitHub CI

Automated tests:

  • npx jest --ci --runInBand --coverage=false src/files/remote.spec.ts src/app/metrics.spec.ts — 72 tests passed
  • npm run test:ci --workspace=api -- --runInBand server/routes/agents/__tests__/files.spec.js server/controllers/agents/__tests__/callbacks.spec.js — 58 tests passed
  • ESLint passed
  • Prettier passed
  • Import sorting passed
  • package.json validation passed
  • Circular dependency checks passed
  • npm run build:packages passed after synchronizing dependencies with the current dev lockfile

Screenshots / recordings

No user-facing change.

Risk / compatibility

This adds a new authenticated API route and changes the attachment URL emitted to Remote Agent clients. It does not make files public and does not weaken secureImageLinks; requests still pass through Remote Agent authentication, tenant resolution, feature checks and the existing file ACL middleware.

The endpoint supports existing storage strategies through their download-stream implementation. A strategy without download-stream support returns 501 Not Implemented. Stream-open failures return an error without exposing the underlying storage path.

There are no database migrations, schema changes, configuration changes or new runtime dependencies.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary
  • Required dependency changes have been merged/published
  • Required documentation PR: N/A

@Kicer86
Kicer86 requested a review from danny-avila as a code owner November 22, 2026 16:46
@github-actions
github-actions Bot changed the base branch from main to dev November 22, 2026 16:46
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for the contribution! LibreChat merges all changes into dev first — main only moves at release time — so this pull request's base branch was switched from main to dev automatically.

Nothing is needed from you; your commits, reviews and discussion are unchanged. If the diff now shows files you did not touch, rebase onto dev:

git remote add upstream https://github.com/LibreChat-AI/LibreChat.git
git fetch upstream dev
git rebase upstream/dev
git push --force-with-lease

Maintainers: apply the target: main label and restore the base branch if this one genuinely belongs on main.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant