-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - twin #14213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - twin #14213
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (response.status === "COMPLETED") { | ||
$.export("$summary", "Successfully completed browsing"); | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return response; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
26 changes: 26 additions & 0 deletions
26
components/twin/actions/get-task-details/get-task-details.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}...`, | ||
})) || []; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
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, | ||
}); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
browse(args = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/browse", | ||
...args, | ||
}); | ||
}, | ||
getTask({ | ||
taskId, ...args | ||
}) { | ||
return this._makeRequest({ | ||
path: `/task/${taskId}`, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
...args, | ||
}); | ||
}, | ||
listTasks(args = {}) { | ||
return this._makeRequest({ | ||
path: "/tasks", | ||
...args, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.