Skip to content

Commit 56a2b2e

Browse files
committed
new component
1 parent 23ebb94 commit 56a2b2e

File tree

3 files changed

+69
-54
lines changed

3 files changed

+69
-54
lines changed

components/burstyai/actions/run-workflow/run-workflow.mjs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,55 @@ import burstyai from "../../burstyai.app.mjs";
33
export default {
44
key: "burstyai-run-workflow",
55
name: "Run Workflow",
6-
description: "Triggers an AI workflow on BurstyAI. The specific workflow to run and optional parameters for the workflow can be configured. [See the documentation](https://burstyai.readme.io/reference)",
6+
description: "Triggers an AI workflow on BurstyAI. [See the documentation](https://burstyai.readme.io/reference)",
77
version: "0.0.1",
88
type: "action",
99
props: {
1010
burstyai,
1111
workflow: {
12-
propDefinition: [
13-
burstyai,
14-
"workflow",
15-
],
12+
type: "string",
13+
label: "Workflow ID",
14+
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`",
1615
},
17-
parameters: {
18-
propDefinition: [
19-
burstyai,
20-
"parameters",
21-
],
16+
params: {
17+
type: "object",
18+
label: "Parameters",
19+
description: "Optional parameters for the workflow",
20+
optional: true,
21+
},
22+
waitForCompletion: {
23+
type: "boolean",
24+
label: "Wait For Completion",
25+
description: "Set to `true` to poll the API in 3-second intervals until the workflow is completed",
26+
optional: true,
2227
},
2328
},
2429
async run({ $ }) {
25-
const response = await this.burstyai.triggerWorkflow({
30+
let response = await this.burstyai.triggerWorkflow({
31+
$,
2632
workflow: this.workflow,
27-
parameters: this.parameters,
33+
data: {
34+
params: this.params || {},
35+
},
2836
});
29-
$.export("$summary", `Successfully triggered workflow ${this.workflow}`);
37+
38+
const jobId = response;
39+
40+
if (this.waitForCompletion) {
41+
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
42+
while (response?.jobStatus !== "END" && response?.jobStatus !== "ERROR") {
43+
response = await this.burstyai.getWorkflowExecutionResult({
44+
$,
45+
jobId,
46+
});
47+
await timer(3000);
48+
}
49+
}
50+
51+
if (response?.status === "END") {
52+
$.export("$summary", `Successfully triggered workflow ${this.workflow}`);
53+
}
54+
3055
return response;
3156
},
3257
};

components/burstyai/burstyai.app.mjs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,39 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "burstyai",
6-
propDefinitions: {
7-
workflow: {
8-
type: "string",
9-
label: "Workflow",
10-
description: "The specific workflow to run",
11-
required: true,
12-
async options() {
13-
const workflows = await this.getWorkflows();
14-
return workflows.map((workflow) => ({
15-
label: workflow.name,
16-
value: workflow.id,
17-
}));
18-
},
19-
},
20-
parameters: {
21-
type: "object",
22-
label: "Parameters",
23-
description: "Optional parameters for the workflow",
24-
optional: true,
25-
},
26-
},
276
methods: {
287
_baseUrl() {
29-
return "https://app.burstyai.com";
8+
return "https://app.burstyai.com/burstyai";
309
},
31-
async _makeRequest(opts = {}) {
10+
_makeRequest(opts = {}) {
3211
const {
3312
$ = this,
34-
method = "GET",
3513
path,
36-
headers,
3714
...otherOpts
3815
} = opts;
3916
return axios($, {
4017
...otherOpts,
41-
method,
42-
url: this._baseUrl() + path,
18+
url: `${this._baseUrl()}${path}`,
4319
headers: {
44-
...headers,
45-
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
20+
Authorization: `Bearer ${this.$auth.api_key}`,
4621
},
4722
});
4823
},
49-
async getWorkflows() {
50-
const res = await this._makeRequest({
51-
path: "/burstyai/aiflows",
52-
});
53-
return res;
54-
},
55-
async triggerWorkflow({
56-
workflow, parameters,
24+
triggerWorkflow({
25+
workflow, ...args
5726
}) {
5827
return this._makeRequest({
5928
method: "POST",
60-
path: `/burstyai/aiflows/${workflow}/async_run`,
61-
data: parameters,
29+
path: `/aiflows/${workflow}/async_run`,
30+
...args,
6231
});
6332
},
64-
async getWorkflowExecutionResult(jobId) {
33+
getWorkflowExecutionResult({
34+
jobId, ...args
35+
}) {
6536
return this._makeRequest({
66-
path: `/burstyai/aiflowjobs/${jobId}/result`,
37+
path: `/aiflowjobs/${jobId}/result`,
38+
...args,
6739
});
6840
},
6941
},

components/burstyai/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/burstyai",
3+
"version": "0.1.0",
4+
"description": "Pipedream BurstyAI Components",
5+
"main": "burstyai.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"burstyai"
9+
],
10+
"homepage": "https://pipedream.com/apps/burstyai",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)