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
78 changes: 78 additions & 0 deletions components/harpa_ai/actions/run-ai-command/run-ai-command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import harpaAi from "../../harpa_ai.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "harpa_ai-run-ai-command",
name: "Run AI Command",
description: "Run an AI command. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#run-ai-command)",
version: "0.0.1",
type: "action",
props: {
harpaAi,
url: {
type: "string",
label: "URL",
description: "the page to run the AI command over",
},
name: {
type: "string",
label: "Name",
description: "A command name to execute such as Summary",
optional: true,
},
inputs: {
type: "string[]",
label: "Inputs",
description: "An array of Strings, each one passed down into command in place of the user input. Inputs are used to bypass waiting for the user input in multi-step commands. For example [ \"REPORT\", \"DONE\" ] for the Summary command.",
optional: true,
},
resultParam: {
type: "string",
label: "Result Param",
description: "A HARPA {{parameter}} to interpret as the command result. By default is set to \"message\" to take the last chat message. Supports dot notation, e.g. \"g.data.email\". Refer to [AI Commands Guide](https://harpa.ai/chatml/overview) for more details.",
optional: true,
},
node: {
propDefinition: [
harpaAi,
"node",
],
},
timeout: {
propDefinition: [
harpaAi,
"timeout",
],
},
resultsWebhook: {
propDefinition: [
harpaAi,
"resultsWebhook",
],
},
connection: {
type: "string",
label: "Connection",
description: "The title or ID of AI connection to use for AI actions. If not specified or connection not found, default connection is used.",
optional: true,
},
},
async run({ $ }) {
const response = await this.harpaAi.sendAction({
$,
data: {
action: "command",
url: this.url,
name: this.name,
inputs: parseObject(this.inputs),
resultParam: this.resultParam,
node: this.node,
timeout: this.timeout,
resultsWebhook: this.resultsWebhook,
connection: this.connection,
},
});
$.export("$summary", `Ran AI command on ${this.url}`);
return response;
},
};
57 changes: 57 additions & 0 deletions components/harpa_ai/actions/scrape-web-page/scrape-web-page.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import harpaAi from "../../harpa_ai.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "harpa_ai-scrape-web-page",
name: "Scrape Web Page",
description: "Scrape a web page. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#web-page-scraping)",
version: "0.0.1",
type: "action",
props: {
harpaAi,
url: {
type: "string",
label: "URL",
description: "The URL of the web page to scrape",
},
grab: {
type: "string[]",
label: "Grab",
description: "An array of HTML Element selectors to scrape from the page. Refer to the [Scraping Web Page Elements and Data](https://harpa.ai/grid/grid-rest-api-reference#scraping-web-page-elements-and-data) section for more details.",
optional: true,
},
node: {
propDefinition: [
harpaAi,
"node",
],
},
timeout: {
propDefinition: [
harpaAi,
"timeout",
],
},
resultsWebhook: {
propDefinition: [
harpaAi,
"resultsWebhook",
],
},
},
async run({ $ }) {
const response = await this.harpaAi.sendAction({
$,
data: {
action: "scrape",
url: this.url,
grab: parseObject(this.grab),
node: this.node,
timeout: this.timeout,
resultsWebhook: this.resultsWebhook,
},
});
$.export("$summary", `Scraped ${this.url}`);
return response;
},
};
49 changes: 49 additions & 0 deletions components/harpa_ai/actions/search-the-web/search-the-web.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import harpaAi from "../../harpa_ai.app.mjs";

export default {
key: "harpa_ai-search-the-web",
name: "Search the Web",
description: "Search the web. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#search-the-web)",
version: "0.0.1",
type: "action",
props: {
harpaAi,
query: {
type: "string",
label: "Query",
description: "The search term or a query string to search for. Supports search parameters like **site:example.com** or **intitle:keyword**.",
},
node: {
propDefinition: [
harpaAi,
"node",
],
},
timeout: {
propDefinition: [
harpaAi,
"timeout",
],
},
resultsWebhook: {
propDefinition: [
harpaAi,
"resultsWebhook",
],
},
},
async run({ $ }) {
const response = await this.harpaAi.sendAction({
$,
data: {
action: "serp",
query: this.query,
node: this.node,
timeout: this.timeout,
resultsWebhook: this.resultsWebhook,
},
});
$.export("$summary", `Searched the web for ${this.query}`);
return response;
},
};
25 changes: 25 additions & 0 deletions components/harpa_ai/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const parseObject = (obj) => {
if (!obj) {
return undefined;
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
if (Array.isArray(obj)) {
return obj.map(parseObject);
}
if (typeof obj === "object") {
return Object.fromEntries(Object.entries(obj).map(([
key,
value,
]) => [
key,
parseObject(value),
]));
}
return obj;
};
47 changes: 43 additions & 4 deletions components/harpa_ai/harpa_ai.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "harpa_ai",
propDefinitions: {},
propDefinitions: {
node: {
type: "string",
label: "Node",
description: "A target Node ID which should run the command. If omitted, the first available Node will be used.",
optional: true,
},
timeout: {
type: "string",
label: "Timeout",
description: "Synchronous action execution timeout",
optional: true,
},
resultsWebhook: {
type: "string",
label: "Results Webhook",
description: "An asynchronous webhook URL to send the results to upon completion",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.harpa.ai/api/v1";
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this.$auth.api_key}`,
"Content-type": "application/json",
},
...opts,
});
},
sendAction(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/grid",
...opts,
});
},
},
};
7 changes: 5 additions & 2 deletions components/harpa_ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/harpa_ai",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream HARPA AI Components",
"main": "harpa_ai.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
20 changes: 11 additions & 9 deletions pnpm-lock.yaml

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

Loading