Repository navigation
Expand file tree
/
Copy pathapi.ts
More file actions
176 lines (171 loc) · 6.1 KB
/
Copy pathapi.ts
File metadata and controls
176 lines (171 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { ApiIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { IntegrationType } from '@/blocks/types'
import type { RequestResponse } from '@/tools/http/types'
export const ApiBlock: BlockConfig<RequestResponse> = {
type: 'api',
name: 'API',
description: 'Use any API',
longDescription:
'This is a core workflow block. Connect to any external API with support for all standard HTTP methods and customizable request parameters. Configure headers, query parameters, and request bodies. Standard headers (User-Agent, Accept, Cache-Control, etc.) are automatically included.',
docsLink: 'https://docs.sim.ai/workflows/blocks/api',
bestPractices: `
- Curl the endpoint yourself before filling out the API block to make sure it's working IF you have the necessary authentication headers. Clarify with the user if you need any additional headers.
`,
category: 'blocks',
integrationType: IntegrationType.DevOps,
bgColor: '#2F55FF',
icon: ApiIcon,
canvasPresentation: {
defaultTitle: 'API',
sentences: {
default: [
{ text: 'Send', field: 'method', after: 'request to', core: true },
{ field: 'url', core: true },
{ text: ', with body', field: 'body' },
],
},
},
subBlocks: [
{
id: 'url',
title: 'URL',
type: 'short-input',
placeholder: 'Enter URL',
required: true,
},
{
id: 'method',
title: 'Method',
type: 'dropdown',
required: true,
options: [
{ label: 'GET', id: 'GET' },
{ label: 'POST', id: 'POST' },
{ label: 'PUT', id: 'PUT' },
{ label: 'DELETE', id: 'DELETE' },
{ label: 'PATCH', id: 'PATCH' },
],
},
{
id: 'params',
title: 'Query Params',
type: 'table',
columns: ['Key', 'Value'],
},
{
id: 'headers',
title: 'Headers',
type: 'table',
columns: ['Key', 'Value'],
description:
'Custom headers (standard headers like User-Agent, Accept, etc. are added automatically)',
},
{
id: 'body',
title: 'Body',
type: 'code',
placeholder: 'Enter JSON...',
wandConfig: {
enabled: true,
maintainHistory: true,
prompt: `You are an expert JSON programmer.
Generate ONLY the raw JSON object based on the user's request.
The output MUST be a single, valid JSON object, starting with { and ending with }.
Current body: {context}
Do not include any explanations, markdown formatting, or other text outside the JSON object.
You have access to the following variables you can use to generate the JSON body:
- 'params' (object): Contains input parameters derived from the JSON schema. Access these directly using the parameter name wrapped in angle brackets, e.g., '<paramName>'. Do NOT use 'params.paramName'.
- 'environmentVariables' (object): Contains environment variables. Reference these using the double curly brace syntax: '{{ENV_VAR_NAME}}'. Do NOT use 'environmentVariables.VAR_NAME' or env.
Example:
{
"name": "<block.agent.response.content>",
"age": <block.function.output.age>,
"success": true
}`,
placeholder: 'Describe the API request body you need...',
generationType: 'json-object',
},
},
{
id: 'timeout',
title: 'Timeout (ms)',
type: 'short-input',
placeholder: '300000',
description:
'Request timeout in milliseconds (default: 300000 = 5 minutes, max: 600000 = 10 minutes)',
mode: 'advanced',
},
{
id: 'retries',
title: 'Retries',
type: 'short-input',
placeholder: '0',
description:
'Number of retry attempts for timeouts, 429 responses, and 5xx errors (default: 0, no retries)',
mode: 'advanced',
},
{
id: 'retryDelayMs',
title: 'Retry delay (ms)',
type: 'short-input',
placeholder: '500',
description: 'Initial retry delay in milliseconds (exponential backoff)',
mode: 'advanced',
},
{
id: 'retryMaxDelayMs',
title: 'Max retry delay (ms)',
type: 'short-input',
placeholder: '30000',
description: 'Maximum delay between retries in milliseconds',
mode: 'advanced',
},
{
id: 'retryNonIdempotent',
title: 'Retry non-idempotent methods',
type: 'switch',
description: 'Allow retries for POST/PATCH requests (may create duplicate requests)',
mode: 'advanced',
},
{
id: 'proxyUrl',
title: 'Proxy URL',
type: 'short-input',
placeholder: 'http://user:pass@proxy.host:port or {{PROXY_URL}}',
description:
'Optional. Route this request through an http:// proxy (e.g. a residential proxy). Must be http://; the proxy host must be publicly reachable. Keep credentials in an environment variable and reference it like {{PROXY_URL}}.',
mode: 'advanced',
},
],
tools: {
access: ['http_request'],
},
inputs: {
url: { type: 'string', description: 'Request URL' },
method: { type: 'string', description: 'HTTP method' },
headers: { type: 'json', description: 'Request headers' },
body: { type: 'json', description: 'Request body data' },
params: { type: 'json', description: 'URL query parameters' },
timeout: { type: 'number', description: 'Request timeout in milliseconds' },
retries: { type: 'number', description: 'Number of retry attempts for retryable failures' },
retryDelayMs: { type: 'number', description: 'Initial retry delay in milliseconds' },
retryMaxDelayMs: {
type: 'number',
description: 'Maximum delay between retries in milliseconds',
},
retryNonIdempotent: {
type: 'boolean',
description: 'Allow retries for non-idempotent methods like POST/PATCH',
},
proxyUrl: {
type: 'string',
description: 'Optional http:// proxy URL to route the request through',
},
},
outputs: {
data: { type: 'json', description: 'API response data (JSON, text, or other formats)' },
status: { type: 'number', description: 'HTTP status code (200, 404, 500, etc.)' },
headers: { type: 'json', description: 'HTTP response headers as key-value pairs' },
},
}