Skip to content

Commit 3798352

Browse files
committed
feat(timeout): add timeout subblock to the api block
1 parent 78410ee commit 3798352

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

apps/sim/blocks/blocks/api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ Example:
8080
generationType: 'json-object',
8181
},
8282
},
83+
{
84+
id: 'timeout',
85+
title: 'Timeout (ms)',
86+
type: 'short-input',
87+
placeholder: '300000',
88+
description:
89+
'Request timeout in milliseconds (default: 300000 = 5 minutes, max: 600000 = 10 minutes)',
90+
mode: 'advanced',
91+
},
8392
],
8493
tools: {
8594
access: ['http_request'],
@@ -90,6 +99,7 @@ Example:
9099
headers: { type: 'json', description: 'Request headers' },
91100
body: { type: 'json', description: 'Request body data' },
92101
params: { type: 'json', description: 'URL query parameters' },
102+
timeout: { type: 'number', description: 'Request timeout in milliseconds' },
93103
},
94104
outputs: {
95105
data: { type: 'json', description: 'API response data (JSON, text, or other formats)' },

apps/sim/lib/core/security/input-validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ export async function secureFetchWithPinnedIP(
931931
method: options.method || 'GET',
932932
headers: sanitizedHeaders,
933933
agent,
934-
timeout: options.timeout || 30000,
934+
timeout: options.timeout || 300000, // Default 5 minutes
935935
}
936936

937937
const protocol = isHttps ? https : http

apps/sim/tools/http/request.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
4848
visibility: 'user-or-llm',
4949
description: 'Form data to send (will set appropriate Content-Type)',
5050
},
51+
timeout: {
52+
type: 'number',
53+
visibility: 'user-only',
54+
description: 'Request timeout in milliseconds (default: 300000 = 5 minutes)',
55+
},
5156
},
5257

5358
request: {

apps/sim/tools/http/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface RequestParams {
88
params?: TableRow[]
99
pathParams?: Record<string, string>
1010
formData?: Record<string, string | Blob>
11+
timeout?: number
1112
}
1213

1314
export interface RequestResponse extends ToolResponse {

apps/sim/tools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ async function executeToolRequest(
640640
method: requestParams.method,
641641
headers: headersRecord,
642642
body: requestParams.body ?? undefined,
643+
timeout: requestParams.timeout,
643644
})
644645

645646
const responseHeaders = new Headers(secureResponse.headers.toRecord())

apps/sim/tools/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ interface RequestParams {
7575
method: string
7676
headers: Record<string, string>
7777
body?: string
78+
timeout?: number
7879
}
7980

8081
/**
@@ -122,7 +123,10 @@ export function formatRequestParams(tool: ToolConfig, params: Record<string, any
122123
}
123124
}
124125

125-
return { url, method, headers, body }
126+
// Get timeout from params (if specified)
127+
const timeout = params.timeout as number | undefined
128+
129+
return { url, method, headers, body, timeout }
126130
}
127131

128132
/**

0 commit comments

Comments
 (0)