diff --git a/components/harpa_ai/actions/run-ai-command/run-ai-command.mjs b/components/harpa_ai/actions/run-ai-command/run-ai-command.mjs new file mode 100644 index 0000000000000..bd0f1688e91bf --- /dev/null +++ b/components/harpa_ai/actions/run-ai-command/run-ai-command.mjs @@ -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; + }, +}; diff --git a/components/harpa_ai/actions/scrape-web-page/scrape-web-page.mjs b/components/harpa_ai/actions/scrape-web-page/scrape-web-page.mjs new file mode 100644 index 0000000000000..b30e4bff6072c --- /dev/null +++ b/components/harpa_ai/actions/scrape-web-page/scrape-web-page.mjs @@ -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; + }, +}; diff --git a/components/harpa_ai/actions/search-the-web/search-the-web.mjs b/components/harpa_ai/actions/search-the-web/search-the-web.mjs new file mode 100644 index 0000000000000..6f88c5338a0bf --- /dev/null +++ b/components/harpa_ai/actions/search-the-web/search-the-web.mjs @@ -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; + }, +}; diff --git a/components/harpa_ai/common/utils.mjs b/components/harpa_ai/common/utils.mjs new file mode 100644 index 0000000000000..9fdc004c18f32 --- /dev/null +++ b/components/harpa_ai/common/utils.mjs @@ -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; +}; diff --git a/components/harpa_ai/harpa_ai.app.mjs b/components/harpa_ai/harpa_ai.app.mjs index 216e965a8924b..39f8f1e7e1e4c 100644 --- a/components/harpa_ai/harpa_ai.app.mjs +++ b/components/harpa_ai/harpa_ai.app.mjs @@ -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, + }); }, }, }; diff --git a/components/harpa_ai/package.json b/components/harpa_ai/package.json index 54b0426b8b7e1..333aa4ac4f070 100644 --- a/components/harpa_ai/package.json +++ b/components/harpa_ai/package.json @@ -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": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 54e837ca350be..fb61e73803170 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -715,8 +715,7 @@ importers: components/alt_text_generator_ai: {} - components/alt_text_lab: - specifiers: {} + components/alt_text_lab: {} components/alteryx_analytics_cloud: {} @@ -6067,7 +6066,11 @@ importers: components/harmonic: {} - components/harpa_ai: {} + components/harpa_ai: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/harry_potter_api: dependencies: @@ -10162,8 +10165,7 @@ importers: specifier: ^6.11.1 version: 6.13.1 - components/pingback: - specifiers: {} + components/pingback: {} components/pingbell: dependencies: @@ -29923,22 +29925,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}