Skip to content

Commit 2725f35

Browse files
committed
skyvern init
1 parent f35b601 commit 2725f35

File tree

6 files changed

+298
-6
lines changed

6 files changed

+298
-6
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import skyvern from "../../skyvern.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "skyvern-create-run-task",
6+
name: "Create and Run Task",
7+
description: "Create a new task and run it instantly in Skyvern. Useful for one-off automations. [See the documentation](https://docs.skyvern.com/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
skyvern,
12+
taskName: {
13+
propDefinition: [
14+
skyvern,
15+
"taskName",
16+
],
17+
},
18+
taskGoal: {
19+
propDefinition: [
20+
skyvern,
21+
"taskGoal",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.skyvern.createAndRunTask({
27+
taskName: this.taskName,
28+
taskGoal: this.taskGoal,
29+
});
30+
$.export("$summary", `Created and ran task with ID ${response.task_id}`);
31+
return response;
32+
},
33+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import skyvern from "../../skyvern.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "skyvern-get-workflow-run-details",
6+
name: "Get Workflow Run Details",
7+
description: "Retrieve details of a specific Skyvern workflow run. Useful for checking the status and result of a run. [See the documentation](https://docs.skyvern.com/workflows/getting-workflows)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
skyvern,
12+
workflowId: {
13+
propDefinition: [
14+
skyvern,
15+
"workflowId",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.skyvern.getWorkflowRunDetails({
21+
workflowId: this.workflowId,
22+
});
23+
$.export("$summary", `Successfully retrieved details for workflow run with ID: ${this.workflowId}`);
24+
return response;
25+
},
26+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import skyvern from "../../skyvern.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "skyvern-run-workflow",
6+
name: "Run Workflow",
7+
description: "Trigger a predefined workflow in Skyvern, allowing the execution of complex routines from Pipedream. [See the documentation](https://docs.skyvern.com/workflows/running-workflows)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
skyvern,
12+
workflowId: {
13+
propDefinition: [
14+
skyvern,
15+
"workflowId",
16+
],
17+
},
18+
data: {
19+
type: "object",
20+
label: "Data",
21+
description: "The data field is used to pass in required and optional parameters that a workflow accepts",
22+
optional: true,
23+
},
24+
proxyLocation: {
25+
type: "string",
26+
label: "Proxy Location",
27+
description: "Proxy location for the web browser. Please pass 'RESIDENTIAL'.",
28+
optional: true,
29+
},
30+
webhookCallbackUrl: {
31+
type: "string",
32+
label: "Webhook Callback URL",
33+
description: "URL where system will send callback once it finishes executing the workflow run.",
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.skyvern.triggerWorkflow({
39+
workflowId: this.workflowId,
40+
data: this.data,
41+
proxyLocation: this.proxyLocation,
42+
webhookCallbackUrl: this.webhookCallbackUrl,
43+
});
44+
45+
$.export("$summary", `Successfully triggered workflow with ID ${response.workflow_id}`);
46+
return response;
47+
},
48+
};

components/skyvern/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

components/skyvern/skyvern.app.mjs

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,109 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "skyvern",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
workspace: {
8+
type: "string",
9+
label: "Workspace",
10+
description: "The workspace scope for workflows",
11+
async options() {
12+
const workflows = await this.listWorkflows();
13+
return workflows.map((workflow) => ({
14+
label: workflow.title,
15+
value: workflow.workspace_id,
16+
}));
17+
},
18+
},
19+
workflowId: {
20+
type: "string",
21+
label: "Workflow ID",
22+
description: "The unique identifier for a workflow",
23+
},
24+
taskName: {
25+
type: "string",
26+
label: "Task Name",
27+
description: "The name of the task to be created and run",
28+
},
29+
taskGoal: {
30+
type: "string",
31+
label: "Task Goal",
32+
description: "The goal of the task to be created and run",
33+
},
34+
},
535
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
36+
_baseUrl() {
37+
return "https://api.skyvern.com/api/v1";
38+
},
39+
async _makeRequest(opts = {}) {
40+
const {
41+
$ = this, method = "GET", path = "/", headers, ...otherOpts
42+
} = opts;
43+
return axios($, {
44+
...otherOpts,
45+
method,
46+
url: this._baseUrl() + path,
47+
headers: {
48+
...headers,
49+
"x-api-key": this.$auth.api_key,
50+
},
51+
});
52+
},
53+
async listWorkflows(opts = {}) {
54+
const params = {
55+
only_workflows: true,
56+
...opts,
57+
};
58+
return this._makeRequest({
59+
path: "/workflows",
60+
params,
61+
});
62+
},
63+
async emitNewWorkflowEvent({
64+
workspace, ...opts
65+
}) {
66+
const path = `/workflows/${workspace}/events`;
67+
return this._makeRequest({
68+
path,
69+
...opts,
70+
});
71+
},
72+
async getWorkflowRunDetails({
73+
workflowId, ...opts
74+
}) {
75+
const path = `/workflows/runs/${workflowId}`;
76+
return this._makeRequest({
77+
path,
78+
...opts,
79+
});
80+
},
81+
async triggerWorkflow({
82+
workflowId, data, proxyLocation, webhookCallbackUrl, ...opts
83+
}) {
84+
return this._makeRequest({
85+
method: "POST",
86+
path: `/workflows/${workflowId}/run`,
87+
data: {
88+
data,
89+
proxy_location: proxyLocation,
90+
webhook_callback_url: webhookCallbackUrl,
91+
},
92+
...opts,
93+
});
94+
},
95+
async createAndRunTask({
96+
taskName, taskGoal, ...opts
97+
}) {
98+
return this._makeRequest({
99+
method: "POST",
100+
path: "/tasks",
101+
data: {
102+
name: taskName,
103+
navigation_goal: taskGoal,
104+
...opts,
105+
},
106+
});
9107
},
10108
},
11-
};
109+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import skyvern from "../../skyvern.app.mjs";
2+
import {
3+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
key: "skyvern-new-or-updated-workflow",
8+
name: "New or Updated Workflow",
9+
description: "Emits a new event when a workflow is created or updated in Skyvern. [See the documentation](https://docs.skyvern.com/workflows/getting-workflows)",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
skyvern,
15+
db: "$.service.db",
16+
workspace: {
17+
propDefinition: [
18+
skyvern,
19+
"workspace",
20+
],
21+
},
22+
timer: {
23+
type: "$.interface.timer",
24+
default: {
25+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
26+
},
27+
},
28+
},
29+
methods: {
30+
_getLastWorkflowVersion() {
31+
return this.db.get("lastWorkflowVersion") || {};
32+
},
33+
_setLastWorkflowVersion(workflows) {
34+
const lastWorkflowVersion = workflows.reduce((acc, workflow) => {
35+
acc[workflow.workflow_id] = workflow.version;
36+
return acc;
37+
}, {});
38+
this.db.set("lastWorkflowVersion", lastWorkflowVersion);
39+
},
40+
},
41+
hooks: {
42+
async deploy() {
43+
const workflows = await this.skyvern.listWorkflows({
44+
workspace: this.workspace,
45+
});
46+
const last50Workflows = workflows.slice(-50);
47+
48+
for (const workflow of last50Workflows) {
49+
this.$emit(workflow, {
50+
id: workflow.workflow_id,
51+
summary: `New or Updated Workflow: ${workflow.title}`,
52+
ts: Date.now(),
53+
});
54+
}
55+
56+
this._setLastWorkflowVersion(last50Workflows);
57+
},
58+
async activate() {
59+
// Add any logic for when the component is activated
60+
},
61+
async deactivate() {
62+
// Add any logic for when the component is deactivated
63+
},
64+
},
65+
async run() {
66+
const lastWorkflowVersion = this._getLastWorkflowVersion();
67+
const workflows = await this.skyvern.listWorkflows({
68+
workspace: this.workspace,
69+
});
70+
71+
for (const workflow of workflows) {
72+
const previousVersion = lastWorkflowVersion[workflow.workflow_id];
73+
74+
if (!previousVersion || workflow.version > previousVersion) {
75+
this.$emit(workflow, {
76+
id: workflow.workflow_id,
77+
summary: `New or Updated Workflow: ${workflow.title}`,
78+
ts: Date.now(),
79+
});
80+
81+
lastWorkflowVersion[workflow.workflow_id] = workflow.version;
82+
}
83+
}
84+
85+
this._setLastWorkflowVersion(workflows);
86+
},
87+
};

0 commit comments

Comments
 (0)