Skip to content

[5417] refactor(frontend): move drive mount calls onto the generated Fern client - #5519

Open
mmabrouk wants to merge 1 commit into
chore/mounts-binary-openapi-fern-regenfrom
refactor/drive-mounts-onto-fern-client
Open

[5417] refactor(frontend): move drive mount calls onto the generated Fern client#5519
mmabrouk wants to merge 1 commit into
chore/mounts-binary-openapi-fern-regenfrom
refactor/drive-mounts-onto-fern-client

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

Closes #5417. Stacked on #5518 — review that one first, and merge it first. Base is chore/mounts-binary-openapi-fern-regen, not main, so this diff shows only its own four files.

The problem

The drive reached four mount endpoints through raw axios and raw fetch against hand-built URLs. web/AGENTS.md rules that out for frontend API code, and it is the deviation #5417 was filed about.

Three of the four had no alternative until now. The generated client parsed those bodies as JSON, which corrupts a zip or a file's bytes. #5518 fixes that at the source, so all four can move.

Call site Was Now
agentDrive.ts agent mount probe axios.post to /mounts/agents/query queryAgentMount
driveMedia.ts file bytes axios.get with responseType: "blob" fetchMountFileBytes
driveMedia.ts download-all, Chromium raw fetch with a hand-built JWT header exportMountFiles().stream()
driveMedia.ts download-all, Safari/Firefox axios.post with responseType: "blob" exportMountFiles().blob()

The change

The three Fern calls go into @agenta/entities/session, next to the mount queries already there, and follow the same shape as their neighbours: callFern, projectScopedRequest, and zod validation on the one that returns JSON. The drive components keep only browser concerns, which is the object URLs and the save-file picker.

Download behavior is unchanged. exportMountFiles returns the body unread, so the caller still chooses:

const archive = await exportMountFiles({mounts, projectId, filename})
const body = archive?.stream()   // Chromium: chunk-at-a-time to disk, memory stays bounded
const blob = await archive.blob() // Safari/Firefox: buffered, then anchor-click

Two deliberate details:

  • The returned type is restated in the package rather than re-exported from Fern, so consumers do not take a dependency on generated types.
  • It does not retry. The backend streams the zip member by member, so a mid-stream failure has already sent its 200; retrying would restart a potentially large export rather than recover it.

On dropping the hand-built Authorization header: the raw fetch attached a JWT itself. The Fern client authenticates with cookies via withCredentials. This is not a new dependency, because the drive's own file listing already goes through the Fern client on the same endpoints. If cookie auth did not work for mounts, the drive would not list files at all today.

What stays as it is

mountFileDownloadUrl still builds a /mounts/{id}/files/download URL string. That is not a request our code makes; it is a src for a media tag so the browser streams the bytes progressively and they never enter the JS heap. There is no client call to route it through.

Verification

  • The three routes were driven through the real generated client against a local server returning a non-JSON payload. exportMountFiles().blob(), exportMountFiles().stream() and downloadMountFile().blob() each return the exact bytes, byte-for-byte. This is the defect the ticket describes, verified directly.
  • No axios or raw fetch call remains anywhere in web/oss/src/components/Drives.
  • @agenta/entities typechecks and lints clean; the two changed web/oss files lint clean.
  • tsc over web/oss reports no error in any file this PR touches. The project has 587 pre-existing errors elsewhere, none of them in Drives or the session API.

Not covered

These paths are typed and compile, but I have not clicked through a download on a live stack. Both existing stacks on the dev box belong to other work, so a live run needs a stack that carries the API change from #5518. Worth a manual "download all" in both a Chromium and a Firefox profile before merge.

https://claude.ai/code/session_011npNAXwcM2adqdSX6QGcsz

…ient

The drive called four mount endpoints through raw axios and raw fetch, against
hand-built URLs, which web/AGENTS.md rules out for frontend API code. Three of them
had no choice until now: the generated client parsed the zip and file bodies as JSON
and corrupted them. The previous commit fixes that at the source.

Add the three calls to @agenta/entities/session, next to the mount queries that
already live there: queryAgentMount, fetchMountFileBytes and exportMountFiles. They
follow the same shape as their neighbours (callFern, projectScopedRequest, and zod
validation on the JSON one).

exportMountFiles returns the unread body so the caller still picks how to consume it.
The Chromium path streams it to disk a chunk at a time, and the Safari/Firefox path
buffers a blob, exactly as before. The type is restated in the package rather than
re-exported from Fern, so consumers do not depend on generated types. It does not
retry: the backend streams the zip member by member, so a mid-stream failure has
already sent its 200 and a retry would restart a large export rather than recover it.

The drive components keep only browser concerns (object URLs, the save-file picker).
The hand-built Authorization header goes away with the raw fetch; the client
authenticates the same way the drive's file listing already does.

Refs #5417

Claude-Session: https://claude.ai/code/session_011npNAXwcM2adqdSX6QGcsz
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 25, 2026
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jul 25, 2026 6:38pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d49f5993-a024-426a-ad65-2658f676124d

📥 Commits

Reviewing files that changed from the base of the PR and between 4033641 and c12586c.

📒 Files selected for processing (4)
  • web/oss/src/components/Drives/agentDrive.ts
  • web/oss/src/components/Drives/driveMedia.ts
  • web/packages/agenta-entities/src/session/api/api.ts
  • web/packages/agenta-entities/src/session/index.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for querying agent mounts.
    • Added individual mount file downloads.
    • Added archive exports for downloading files from multiple mounts.
    • Archive downloads support both streaming and standard browser download options.
  • Bug Fixes

    • Improved handling of missing or unavailable mount data and download requests.
    • Tightened validation before starting mount downloads.

Walkthrough

Drives now use shared session APIs for agent mount queries, individual file downloads, and multi-mount ZIP exports. The session package exposes these APIs and archive types, supporting both streaming-to-disk and buffered download flows.

Changes

Mount session API integration

Layer / File(s) Summary
Session mount APIs
web/packages/agenta-entities/src/session/api/api.ts
Adds agent mount querying, mount file byte retrieval, and streaming or buffered multi-mount archive export APIs.
Public session exports
web/packages/agenta-entities/src/session/index.ts
Re-exports the new mount helpers and archive types.
Drives integration
web/oss/src/components/Drives/agentDrive.ts, web/oss/src/components/Drives/driveMedia.ts
Replaces direct Axios and fetch calls with session helpers for mount lookup, file downloads, and archive exports.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Drives
  participant SessionAPI
  participant MountsClient
  participant FileSystem
  User->>Drives: Download mount files
  Drives->>SessionAPI: exportMountFiles(mounts, projectId, filename)
  SessionAPI->>MountsClient: Start ZIP export
  MountsClient-->>SessionAPI: Archive stream or blob
  SessionAPI-->>Drives: MountArchiveDownload
  Drives->>FileSystem: Write stream or create blob URL
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: moving drive mount calls to the generated Fern client.
Description check ✅ Passed The description matches the diff and summarizes the Fern client migration and download behavior accurately.
Linked Issues check ✅ Passed The diff moves drive mount/file calls onto generated session helpers and adds the binary archive download API surface.
Out of Scope Changes check ✅ Passed All edits are tied to drive mount/file APIs and their client plumbing; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/drive-mounts-onto-fern-client

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dosubot dosubot Bot added Frontend refactoring A code change that neither fixes a bug nor adds a feature labels Jul 25, 2026
@mmabrouk

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-production-aef5.up.railway.app/w
Project agenta-oss-pr-5519
Image tag pr-5519-d44a2ce
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-07-25T18:47:52.740Z

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

Labels

Frontend refactoring A code change that neither fixes a bug nor adds a feature size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants