feat: support binary file downloads with --output flag#104
Open
siddharth-bhansali wants to merge 1 commit intomainfrom
Open
feat: support binary file downloads with --output flag#104siddharth-bhansali wants to merge 1 commit intomainfrom
siddharth-bhansali wants to merge 1 commit intomainfrom
Conversation
Add support for non-JSON (binary) responses from API passthrough. When the response Content-Type is not JSON or text, the CLI now handles it gracefully instead of crashing on JSON.parse. - Without --output: returns metadata (size, contentType, message) - With --output <path>: saves binary data to the specified file Fixes Google Drive alt=media downloads and native Doc exports that return binary PDF/docx/image data. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5884ac6 to
1deef8b
Compare
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
Adds support for binary (non-JSON) responses from the API passthrough layer, fixing a crash that occurred when downloading files from Google Drive and other platforms that return binary data.
The Problem
When using actions that return binary data (e.g., Google Drive
Get Filewithalt=media, orExportfor native Google Docs), the CLI crashed with:This happened because
executePassthroughRequestunconditionally calledJSON.parse()on the response body, which fails for binary content like PDFs, images, and documents.This blocked a very common workflow — downloading document files from Google Drive for local processing by AI agents.
The Fix
Binary response detection (
src/lib/api.ts)Content-Typeheaderapplication/jsonortext/*, treat it as binary--output: return metadata (size,contentType, and a message prompting the user to use--output)--output <path>: save the raw binary data to the specified file pathNew
--outputflag (src/index.ts,src/commands/actions.ts,src/lib/types.ts)--output <path>option toone actions executeUsage
Verified
alt=mediawithout--outputnot valid JSONalt=mediawith--output%PDF-1.4header)not valid JSON.pdf403: Export only supports Docs Editors filesFiles Changed
src/lib/api.ts— Binary response detection and file saving logicsrc/lib/types.ts— AddedoutputtoExecuteActionArgssrc/commands/actions.ts— Passoutputoption through to APIsrc/index.ts— Register--outputCLI optionCloses withoneai/knowledge#46