fix(models): handle binary file downloads in tool execution
Merged
JE
6mo ago+283+283+012345678901234567890123456789-6-6-0123456789
Summary
- File-download actions (e.g.
googledrive_unified_download_file) serve raw binary with the file's own MIME type and aContent-Dispositionheader, soStackOneTool.execute()callingresponse.json()unconditionally raisedUnicodeDecodeErroron the first non-UTF-8 byte. execute()now branches onContent-Type: JSON media types (application/jsonand+jsonsuffixes) are parsed as before; any other type returns the file as{content: bytes, content_type, status_code, headers, file_name}, matching the StackOne generated SDKs' download response shape.file_nameis parsed fromContent-Disposition(including RFC 5987filename*).- Existing JSON responses are unchanged; the fix applies to the RPC tool path transitively.
Note: content holds raw bytes and is not JSON-serializable โ callers that re-serialize tool results (e.g. for an LLM) should handle that key. The sibling stackone-ai-node SDK has the same response.json() gap and warrants a matching fix.
๐ค Generated with Claude Code
Summary by cubic
Fixes StackOneTool.execute() failing on binary downloads by parsing JSON only when the Content-Type is JSON and returning bytes + metadata for other types. Improves filename parsing to honor RFC 5987 charsets. Adds README docs explaining the file-download return shape and the raw-bytes caveat.
- Bug Fixes
- Treat JSON only as
application/jsonor+jsontypes; otherwise return{content: bytes, content_type, status_code, headers, file_name}. - Parse
file_namefromContent-Disposition, including RFC 5987filename*; honor declared charsets (UTF-8/ISO-8859-1), fall back to UTF-8 on unknown labels, and strip quotes on non-conformant values. - Applies to RPC actions (e.g.
googledrive_unified_download_file) as well. - Added tests for binary bodies, missing
Content-Type, JSON with charset, ISO-8859-1 and unknownfilename*charsets, and the helper parsers.
- Treat JSON only as