diff --git a/components/burstyai/actions/run-workflow/run-workflow.mjs b/components/burstyai/actions/run-workflow/run-workflow.mjs new file mode 100644 index 0000000000000..1632db78c0b19 --- /dev/null +++ b/components/burstyai/actions/run-workflow/run-workflow.mjs @@ -0,0 +1,57 @@ +import burstyai from "../../burstyai.app.mjs"; + +export default { + key: "burstyai-run-workflow", + name: "Run Workflow", + description: "Triggers an AI workflow on BurstyAI. [See the documentation](https://burstyai.readme.io/reference)", + version: "0.0.1", + type: "action", + props: { + burstyai, + workflow: { + type: "string", + label: "Workflow ID", + description: "The ID of the specific workflow to run. When viewing the workflow in BurstyAI, the ID is the last part of the URL. Example: `65e1cd00141fdc000195cb88`", + }, + params: { + type: "object", + label: "Parameters", + description: "Optional parameters for the workflow", + optional: true, + }, + waitForCompletion: { + type: "boolean", + label: "Wait For Completion", + description: "Set to `true` to poll the API in 3-second intervals until the workflow is completed", + optional: true, + }, + }, + async run({ $ }) { + let response = await this.burstyai.triggerWorkflow({ + $, + workflow: this.workflow, + data: { + params: this.params || {}, + }, + }); + + const jobId = response; + + if (this.waitForCompletion) { + const timer = (ms) => new Promise((res) => setTimeout(res, ms)); + while (response?.jobStatus !== "END" && response?.jobStatus !== "ERROR") { + response = await this.burstyai.getWorkflowExecutionResult({ + $, + jobId, + }); + await timer(3000); + } + } + + if (response?.status === "END") { + $.export("$summary", `Successfully triggered workflow ${this.workflow}`); + } + + return response; + }, +}; diff --git a/components/burstyai/burstyai.app.mjs b/components/burstyai/burstyai.app.mjs index b5fcd54c5859f..41870776056b3 100644 --- a/components/burstyai/burstyai.app.mjs +++ b/components/burstyai/burstyai.app.mjs @@ -1,11 +1,42 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "burstyai", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.burstyai.com/burstyai"; + }, + _makeRequest(opts = {}) { + const { + $ = this, + path, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + triggerWorkflow({ + workflow, ...args + }) { + return this._makeRequest({ + method: "POST", + path: `/aiflows/${workflow}/async_run`, + ...args, + }); + }, + getWorkflowExecutionResult({ + jobId, ...args + }) { + return this._makeRequest({ + path: `/aiflowjobs/${jobId}/result`, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/burstyai/package.json b/components/burstyai/package.json index af853b802a39b..3772fac44d492 100644 --- a/components/burstyai/package.json +++ b/components/burstyai/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/burstyai", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream BurstyAI Components", "main": "burstyai.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/franconnect/franconnect.app.mjs b/components/franconnect/franconnect.app.mjs index 9c10d82abefe0..a014983e54eae 100644 --- a/components/franconnect/franconnect.app.mjs +++ b/components/franconnect/franconnect.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b315a61f035ee..8b004e44dec78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1349,7 +1349,10 @@ importers: specifiers: {} components/burstyai: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/businesslogic: specifiers: