MCPcopy
hub / github.com/simstudioai/sim / executeWorkflow

Method executeWorkflow

packages/ts-sdk/src/index.ts:201–281  ·  view source on GitHub ↗

* Execute a workflow with optional input data * @param workflowId - The ID of the workflow to execute * @param input - Input data to pass to the workflow (object, primitive, or array) * @param options - Execution options (timeout, stream, async, etc.)

(
    workflowId: string,
    input?: any,
    options: ExecutionOptions = {}
  )

Source from the content-addressed store, hash-verified

199 * @param options - Execution options (timeout, stream, async, etc.)
200 */
201 async executeWorkflow(
202 workflowId: string,
203 input?: any,
204 options: ExecutionOptions = {}
205 ): Promise<WorkflowExecutionResult | AsyncExecutionResult> {
206 const url = `${this.baseUrl}/api/workflows/${workflowId}/execute`
207 const { timeout = 30000, stream, selectedOutputs, async } = options
208
209 try {
210 const timeoutPromise = new Promise<never>((_, reject) => {
211 setTimeout(() => reject(new Error('TIMEOUT')), timeout)
212 })
213
214 const headers: Record<string, string> = {
215 'Content-Type': 'application/json',
216 'X-API-Key': this.apiKey,
217 }
218 if (async) {
219 headers['X-Execution-Mode'] = 'async'
220 }
221
222 let jsonBody: any = {}
223 if (input !== undefined && input !== null) {
224 if (typeof input === 'object' && input !== null && !Array.isArray(input)) {
225 jsonBody = { ...input }
226 } else {
227 jsonBody = { input }
228 }
229 }
230
231 jsonBody = await this.convertFilesToBase64(jsonBody)
232
233 if (stream !== undefined) {
234 jsonBody.stream = stream
235 }
236 if (selectedOutputs !== undefined) {
237 jsonBody.selectedOutputs = selectedOutputs
238 }
239
240 const fetchPromise = fetch(url, {
241 method: 'POST',
242 headers,
243 body: JSON.stringify(jsonBody),
244 })
245
246 const response = await Promise.race([fetchPromise, timeoutPromise])
247
248 this.updateRateLimitInfo(response)
249
250 if (response.status === 429) {
251 const retryAfter = this.rateLimitInfo?.retryAfter || 1000
252 throw new SimStudioError(
253 `Rate limit exceeded. Retry after ${retryAfter}ms`,
254 'RATE_LIMIT_EXCEEDED',
255 429
256 )
257 }
258

Callers 7

executeWorkflowSyncMethod · 0.95
executeWithRetryMethod · 0.95
basicExampleFunction · 0.95
withInputExampleFunction · 0.95
statusExampleFunction · 0.95
streamingExampleFunction · 0.95
index.test.tsFile · 0.80

Calls 2

convertFilesToBase64Method · 0.95
updateRateLimitInfoMethod · 0.95

Tested by

no test coverage detected