fix(models): handle binary file downloads in tool execution

Merged
JE
6mo ago
+283-6

Summary

  • File-download actions (e.g. googledrive_unified_download_file) serve raw binary with the file's own MIME type and a Content-Disposition header, so StackOneTool.execute() calling response.json() unconditionally raised UnicodeDecodeError on the first non-UTF-8 byte.
  • execute() now branches on Content-Type: JSON media types (application/json and +json suffixes) 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_name is parsed from Content-Disposition (including RFC 5987 filename*).
  • 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/json or +json types; otherwise return {content: bytes, content_type, status_code, headers, file_name}.
    • Parse file_name from Content-Disposition, including RFC 5987 filename*; 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 unknown filename* charsets, and the helper parsers.