GeezerVison is showing github.com — fix(http): stop treating 200 bodies with status and data keys as prox… · simstudioai/sim@60b2ddf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/http/request.ts -21Lines changed: 0 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,7 +181,6 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = { | 181 | 181 | transformResponse: async (response: Response) => { | 182 | 182 | const contentType = response.headers.get('content-type') || '' | 183 | 183 |
| 184 | | - // Standard response handling | 185 | 184 | const headers: Record<string, string> = {} | 186 | 185 | response.headers.forEach((value, key) => { | 187 | 186 | headers[key] = value | @@ -194,26 +193,6 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = { | 194 | 193 | }) | 195 | 194 | const data = contentType.includes('application/json') ? JSON.parse(responseText) : responseText | 196 | 195 |
| 197 | | - // Check if this is a proxy response (structured response from /api/proxy) | 198 | | - if ( | 199 | | - contentType.includes('application/json') && | 200 | | - typeof data === 'object' && | 201 | | - data !== null && | 202 | | - data.data !== undefined && | 203 | | - data.status !== undefined | 204 | | - ) { | 205 | | - return { | 206 | | - success: data.success, | 207 | | - output: { | 208 | | - data: data.data, | 209 | | - status: data.status, | 210 | | - headers: data.headers || {}, | 211 | | - }, | 212 | | - error: data.success ? undefined : data.error, | 213 | | - } | 214 | | - } | 215 | | - | 216 | | - // Direct response handling | 217 | 196 | return { | 218 | 197 | success: response.ok, | 219 | 198 | output: { | |
Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/http/webhook_request.ts -18Lines changed: 0 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,24 +85,6 @@ export const webhookRequestTool: ToolConfig<WebhookRequestParams, RequestRespons | 85 | 85 | ? response.json() | 86 | 86 | : response.text()) | 87 | 87 |
| 88 | | - if ( | 89 | | - contentType.includes('application/json') && | 90 | | - typeof data === 'object' && | 91 | | - data !== null && | 92 | | - data.data !== undefined && | 93 | | - data.status !== undefined | 94 | | - ) { | 95 | | - return { | 96 | | - success: data.success, | 97 | | - output: { | 98 | | - data: data.data, | 99 | | - status: data.status, | 100 | | - headers: data.headers || {}, | 101 | | - }, | 102 | | - error: data.success ? undefined : data.error, | 103 | | - } | 104 | | - } | 105 | | - | 106 | 88 | return { | 107 | 89 | success: response.ok, | 108 | 90 | output: { | |
Collapse file Copy file name to clipboardExpand all lines: apps/sim/tools/index.test.ts +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,7 @@ import { fileGetContentTool } from '@/tools/file/get' | 85 | 85 | import { fileFetchTool } from '@/tools/file/parser' | 86 | 86 | import { buildFunctionExecuteBody, functionExecuteTool } from '@/tools/function/execute' | 87 | 87 | import { searchUsersV2Tool } from '@/tools/github/search_users' | | 88 | +import { httpRequestTool, webhookRequestTool } from '@/tools/http' | 88 | 89 | import { jamaDeleteItemTool } from '@/tools/jama/delete_item' | 89 | 90 | import { jamaDeleteRelationshipTool } from '@/tools/jama/delete_relationship' | 90 | 91 | import { memoryAddTool } from '@/tools/memory/add' | @@ -5528,6 +5529,49 @@ describe('Internal Route Trust', () => { | 5528 | 5529 | }) | 5529 | 5530 | }) | 5530 | 5531 |
| | 5532 | +describe('HTTP tools report the real HTTP outcome', () => { | | 5533 | + const stubbedHttpRequestTool = tools.http_request | | 5534 | + | | 5535 | + beforeEach(() => { | | 5536 | + Object.assign(tools, { http_request: httpRequestTool, webhook_request: webhookRequestTool }) | | 5537 | + mockValidateUrlWithDNS.mockResolvedValue({ isValid: true, resolvedIP: '93.184.216.34' }) | | 5538 | + }) | | 5539 | + | | 5540 | + afterEach(() => { | | 5541 | + vi.resetAllMocks() | | 5542 | + tools.http_request = stubbedHttpRequestTool | | 5543 | + Reflect.deleteProperty(tools, 'webhook_request') | | 5544 | + }) | | 5545 | + | | 5546 | + it.each([ | | 5547 | + ['http_request', { url: 'https://api.example.com/orders', method: 'POST', body: {} }], | | 5548 | + ['webhook_request', { url: 'https://api.example.com/hooks', body: {} }], | | 5549 | + ])( | | 5550 | + '%s treats a 200 whose body has top-level status and data as a success', | | 5551 | + async (toolId, params) => { | | 5552 | + mockSecureFetchWithPinnedIP.mockResolvedValueOnce( | | 5553 | + toSecureFetchResponse( | | 5554 | + Response.json( | | 5555 | + { status: 'success', data: { orderId: 'A-1001' } }, | | 5556 | + { headers: { 'x-request-id': 'req-123' } } | | 5557 | + ) | | 5558 | + ) | | 5559 | + ) | | 5560 | + | | 5561 | + const result = await executeTool(toolId, params, { skipPostProcess: true }) | | 5562 | + | | 5563 | + expect(result, result.error).toMatchObject({ | | 5564 | + success: true, | | 5565 | + output: { | | 5566 | + status: 200, | | 5567 | + data: { status: 'success', data: { orderId: 'A-1001' } }, | | 5568 | + headers: expect.objectContaining({ 'x-request-id': 'req-123' }), | | 5569 | + }, | | 5570 | + }) | | 5571 | + } | | 5572 | + ) | | 5573 | +}) | | 5574 | + | 5531 | 5575 | describe('File Parameter Normalization', () => { | 5532 | 5576 | let cleanupEnvVars: () => void | 5533 | 5577 |
| |
|