Skip to content

Commit 26b357e

Browse files
committed
new components
1 parent 50c8bfe commit 26b357e

File tree

6 files changed

+257
-6
lines changed

6 files changed

+257
-6
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import harpaAi from "../../harpa_ai.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "harpa_ai-run-ai-command",
6+
name: "Run AI Command",
7+
description: "Run an AI command. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#run-ai-command)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
harpaAi,
12+
url: {
13+
type: "string",
14+
label: "URL",
15+
description: "the page to run the AI command over",
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "A command name to execute such as Summary",
21+
optional: true,
22+
},
23+
inputs: {
24+
type: "string[]",
25+
label: "Inputs",
26+
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.",
27+
optional: true,
28+
},
29+
resultParam: {
30+
type: "string",
31+
label: "Result Param",
32+
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.",
33+
optional: true,
34+
},
35+
node: {
36+
propDefinition: [
37+
harpaAi,
38+
"node",
39+
],
40+
},
41+
timeout: {
42+
propDefinition: [
43+
harpaAi,
44+
"timeout",
45+
],
46+
},
47+
resultsWebhook: {
48+
propDefinition: [
49+
harpaAi,
50+
"resultsWebhook",
51+
],
52+
},
53+
connection: {
54+
type: "string",
55+
label: "Connection",
56+
description: "The title or ID of AI connection to use for AI actions. If not specified or connection not found, default connection is used.",
57+
optional: true,
58+
},
59+
},
60+
async run({ $ }) {
61+
const response = await this.harpaAi.sendAction({
62+
$,
63+
data: {
64+
action: "command",
65+
url: this.url,
66+
name: this.name,
67+
inputs: parseObject(this.inputs),
68+
resultParam: this.resultParam,
69+
node: this.node,
70+
timeout: this.timeout,
71+
resultsWebhook: this.resultsWebhook,
72+
connection: this.connection,
73+
},
74+
});
75+
$.export("$summary", `Ran AI command on ${this.url}`);
76+
return response;
77+
},
78+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import harpaAi from "../../harpa_ai.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "harpa_ai-scrape-web-page",
6+
name: "Scrape Web Page",
7+
description: "Scrape a web page. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#web-page-scraping)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
harpaAi,
12+
url: {
13+
type: "string",
14+
label: "URL",
15+
description: "The URL of the web page to scrape",
16+
},
17+
grab: {
18+
type: "string[]",
19+
label: "Grab",
20+
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.",
21+
optional: true,
22+
},
23+
node: {
24+
propDefinition: [
25+
harpaAi,
26+
"node",
27+
],
28+
},
29+
timeout: {
30+
propDefinition: [
31+
harpaAi,
32+
"timeout",
33+
],
34+
},
35+
resultsWebhook: {
36+
propDefinition: [
37+
harpaAi,
38+
"resultsWebhook",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.harpaAi.sendAction({
44+
$,
45+
data: {
46+
action: "scrape",
47+
url: this.url,
48+
grab: parseObject(this.grab),
49+
node: this.node,
50+
timeout: this.timeout,
51+
resultsWebhook: this.resultsWebhook,
52+
},
53+
});
54+
$.export("$summary", `Scraped ${this.url}`);
55+
return response;
56+
},
57+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import harpaAi from "../../harpa_ai.app.mjs";
2+
3+
export default {
4+
key: "harpa_ai-search-the-web",
5+
name: "Search the Web",
6+
description: "Search the web. [See the documentation](https://harpa.ai/grid/grid-rest-api-reference#search-the-web)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
harpaAi,
11+
query: {
12+
type: "string",
13+
label: "Query",
14+
description: "The search term or a query string to search for. Supports search parameters like **site:example.com** or **intitle:keyword**.",
15+
},
16+
node: {
17+
propDefinition: [
18+
harpaAi,
19+
"node",
20+
],
21+
},
22+
timeout: {
23+
propDefinition: [
24+
harpaAi,
25+
"timeout",
26+
],
27+
},
28+
resultsWebhook: {
29+
propDefinition: [
30+
harpaAi,
31+
"resultsWebhook",
32+
],
33+
},
34+
},
35+
async run({ $ }) {
36+
const response = await this.harpaAi.sendAction({
37+
$,
38+
data: {
39+
action: "serp",
40+
query: this.query,
41+
node: this.node,
42+
timeout: this.timeout,
43+
resultsWebhook: this.resultsWebhook,
44+
},
45+
});
46+
$.export("$summary", `Searched the web for ${this.query}`);
47+
return response;
48+
},
49+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
if (Array.isArray(obj)) {
13+
return obj.map(parseObject);
14+
}
15+
if (typeof obj === "object") {
16+
return Object.fromEntries(Object.entries(obj).map(([
17+
key,
18+
value,
19+
]) => [
20+
key,
21+
parseObject(value),
22+
]));
23+
}
24+
return obj;
25+
};
Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "harpa_ai",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
node: {
8+
type: "string",
9+
label: "Node",
10+
description: "A target Node ID which should run the command. If omitted, the first available Node will be used.",
11+
optional: true,
12+
},
13+
timeout: {
14+
type: "string",
15+
label: "Timeout",
16+
description: "Synchronous action execution timeout",
17+
optional: true,
18+
},
19+
resultsWebhook: {
20+
type: "string",
21+
label: "Results Webhook",
22+
description: "An asynchronous webhook URL to send the results to upon completion",
23+
optional: true,
24+
},
25+
},
526
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
27+
_baseUrl() {
28+
return "https://api.harpa.ai/api/v1";
29+
},
30+
_makeRequest({
31+
$ = this, path, ...opts
32+
}) {
33+
return axios($, {
34+
url: `${this._baseUrl()}${path}`,
35+
headers: {
36+
"Authorization": `Bearer ${this.$auth.api_key}`,
37+
"Content-type": "application/json",
38+
},
39+
...opts,
40+
});
41+
},
42+
sendAction(opts = {}) {
43+
return this._makeRequest({
44+
method: "POST",
45+
path: "/grid",
46+
...opts,
47+
});
948
},
1049
},
1150
};

components/harpa_ai/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/harpa_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream HARPA AI Components",
55
"main": "harpa_ai.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)