fix(tools): added transform response to handle non-json responses for internal tools#1400
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR addresses a bug in the internal tools system where all responses were being parsed as JSON, causing failures when tools returned non-JSON content like XML, plain text, or binary data. The fix introduces conditional JSON parsing logic in the handleInternalRequest function within apps/sim/tools/index.ts.
The core change modifies the response handling to check if a tool has a transformResponse function defined. When present, the code skips JSON parsing entirely and sets responseData to null, allowing the custom transform function to handle the raw Response object using appropriate methods like response.text(), response.blob(), or other format-specific parsers. This preserves backward compatibility while enabling tools to process diverse response formats.
The implementation fits well within the existing tools architecture, which already supports custom response transformations through the transformResponse property. The change is minimal and targeted, only affecting the specific code path where JSON parsing was previously mandatory. A comprehensive test case was added to verify XML response handling, demonstrating the fix works correctly for non-JSON content types.
Confidence score: 4/5
- This PR addresses a clear bug with a focused solution that maintains backward compatibility
- Score reflects solid implementation with good test coverage, though the manual testing approach could be more comprehensive
- Pay close attention to the conditional logic in
handleInternalRequestto ensure edge cases are properly handled
2 files reviewed, 1 comment
Summary
added transform response to handle non-json responses for internal tools
Type of Change
Testing
Tested manually.
Checklist