Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions components/twin/actions/browse/browse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import twin from "../../twin.app.mjs";

export default {
key: "twin-browse",
name: "Browse",
description: "Browse the internet with an AI web navigation agent that can find information for you. [See the documentation](https://docs.twin.so/api-reference/endpoint/browse)",
version: "0.0.1",
type: "action",
props: {
twin,
startUrl: {
type: "string",
label: "Start URL",
description: "The URL where the browsing task should begin",
},
goal: {
type: "string",
label: "Goal",
description: "The goal or objective of the browsing task. Example: \"Find the latest price of AAPL stock.\"",
},
outputType: {
type: "string",
label: "Output Type",
description: "The type of output expected from the task",
options: [
"string",
"url",
"list[url]",
],
default: "string",
optional: true,
},
callbackWithRerun: {
type: "boolean",
label: "Callback With Rerun",
description: "Use the `$.flow.rerun` Node.js helper to rerun the step when the search is completed. This will increase execution time and credit usage as a result. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun/#flow-rerun)",
optional: true,
},
},
async run({ $ }) {
let response, completionCallbackUrl;
const { run } = $.context;
if (run.runs === 1) {
if (this.callbackWithRerun) {
({ resume_url: completionCallbackUrl } = $.flow.rerun(600000, null, 1));
}
response = await this.twin.browse({
$,
data: {
startUrl: this.startUrl,
goal: this.goal,
outputType: this.outputType,
completionCallbackUrl,
},
});
}

if (run.callback_request) {
const { task_id: taskId } = run.callback_request.body;
response = await this.twin.getTask({
taskId,
});
}

if (response.status === "COMPLETED") {
$.export("$summary", "Successfully completed browsing");
}
return response;
},
};
26 changes: 26 additions & 0 deletions components/twin/actions/get-task-details/get-task-details.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import twin from "../../twin.app.mjs";

export default {
key: "twin-get-task-details",
name: "Get Task Details",
description: "Retrieve details of a specific task. [See the documentation](https://docs.twin.so/api-reference/endpoint/get-task)",
version: "0.0.1",
type: "action",
props: {
twin,
taskId: {
propDefinition: [
twin,
"taskId",
],
},
},
async run({ $ }) {
const response = await this.twin.getTask({
$,
taskId: this.taskId,
});
$.export("$summary", `Successfully retrieved details for task with ID: ${this.taskId}`);
return response;
},
};
7 changes: 5 additions & 2 deletions components/twin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/twin",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Twin Components",
"main": "twin.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
63 changes: 58 additions & 5 deletions components/twin/twin.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "twin",
propDefinitions: {},
propDefinitions: {
taskId: {
type: "string",
label: "Task ID",
description: "Identifier of a task",
async options() {
const tasks = await this.listTasks();
return tasks?.map(({
id: value, goal,
}) => ({
value,
label: `${goal.slice(0, 50)}...`,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.twin.so";
},
_headers() {
return {
"x-api-key": this.$auth.api_key,
};
},
_makeRequest({
$ = this,
path,
...args
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: this._headers(),
...args,
});
},
browse(args = {}) {
return this._makeRequest({
method: "POST",
path: "/browse",
...args,
});
},
getTask({
taskId, ...args
}) {
return this._makeRequest({
path: `/task/${taskId}`,
...args,
});
},
listTasks(args = {}) {
return this._makeRequest({
path: "/tasks",
...args,
});
},
},
};
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading