From 66dfe57f320588fecc280df59930e117cfc3e395 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Fri, 25 Apr 2025 10:48:12 -0300 Subject: [PATCH] Added actions --- .../summarize-document/summarize-document.mjs | 57 +++++++ .../common/constants.mjs | 153 ++++++++++++++++++ .../universal_summarizer_by_kagi.app.mjs | 66 +++++++- pnpm-lock.yaml | 3 +- 4 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 components/universal_summarizer_by_kagi/actions/summarize-document/summarize-document.mjs create mode 100644 components/universal_summarizer_by_kagi/common/constants.mjs diff --git a/components/universal_summarizer_by_kagi/actions/summarize-document/summarize-document.mjs b/components/universal_summarizer_by_kagi/actions/summarize-document/summarize-document.mjs new file mode 100644 index 0000000000000..48203c2babc7b --- /dev/null +++ b/components/universal_summarizer_by_kagi/actions/summarize-document/summarize-document.mjs @@ -0,0 +1,57 @@ +import app from "../../universal_summarizer_by_kagi.app.mjs"; + +export default { + key: "universal_summarizer_by_kagi-summarize-document", + name: "Summarize Document", + description: "Summarizes the content of a URL. [See the documentation](https://help.kagi.com/kagi/api/summarizer.html#summarize-document)", + version: "0.0.1", + type: "action", + props: { + app, + url: { + propDefinition: [ + app, + "url", + ], + }, + engine: { + propDefinition: [ + app, + "engine", + ], + }, + summaryType: { + propDefinition: [ + app, + "summaryType", + ], + }, + targetLanguage: { + propDefinition: [ + app, + "targetLanguage", + ], + }, + cache: { + propDefinition: [ + app, + "cache", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.summarizeDocument({ + $, + params: { + url: this.url, + engine: this.engine, + summary_type: this.summaryType, + target_language: this.targetLanguage, + cache: this.cache, + }, + }); + $.export("$summary", "Successfully summarized the content of the URL"); + return response; + }, +}; diff --git a/components/universal_summarizer_by_kagi/common/constants.mjs b/components/universal_summarizer_by_kagi/common/constants.mjs new file mode 100644 index 0000000000000..ab8a4777b04cc --- /dev/null +++ b/components/universal_summarizer_by_kagi/common/constants.mjs @@ -0,0 +1,153 @@ +export default { + SUMMARY_TYPES: + [ + { + label: "summary (default) – Paragraph(s) of summary prose", + value: "summary", + }, + { + label: "takeaway – Bulleted list of key points", + value: "takeaway", + }, + ], + LANGUAGE_OPTIONS: [ + { + label: "Bulgarian", + value: "BG", + }, + { + label: "Czech", + value: "CS", + }, + { + label: "Danish", + value: "DA", + }, + { + label: "German", + value: "DE", + }, + { + label: "Greek", + value: "EL", + }, + { + label: "English", + value: "EN", + }, + { + label: "Spanish", + value: "ES", + }, + { + label: "Estonian", + value: "ET", + }, + { + label: "Finnish", + value: "FI", + }, + { + label: "French", + value: "FR", + }, + { + label: "Hungarian", + value: "HU", + }, + { + label: "Indonesian", + value: "ID", + }, + { + label: "Italian", + value: "IT", + }, + { + label: "Japanese", + value: "JA", + }, + { + label: "Korean", + value: "KO", + }, + { + label: "Lithuanian", + value: "LT", + }, + { + label: "Latvian", + value: "LV", + }, + { + label: "Norwegian", + value: "NB", + }, + { + label: "Dutch", + value: "NL", + }, + { + label: "Polish", + value: "PL", + }, + { + label: "Portuguese", + value: "PT", + }, + { + label: "Romanian", + value: "RO", + }, + { + label: "Russian", + value: "RU", + }, + { + label: "Slovak", + value: "SK", + }, + { + label: "Slovenian", + value: "SL", + }, + { + label: "Swedish", + value: "SV", + }, + { + label: "Turkish", + value: "TR", + }, + { + label: "Ukrainian", + value: "UK", + }, + { + label: "Chinese (simplified)", + value: "ZH", + }, + { + label: "Chinese (traditional)", + value: "ZH-HANT", + }, + ], + ENGINE_OPTIONS: [ + { + label: "Friendly, descriptive, fast summary", + value: "cecil", + }, + { + label: "Formal, technical, analytical summary", + value: "agnes", + }, + { + label: "Same as Agnes (Soon-to-be-deprecated)", + value: "daphne", + }, + { + label: "Enterprise-grade, best-in-class summary", + value: "muriel", + }, + ], +}; diff --git a/components/universal_summarizer_by_kagi/universal_summarizer_by_kagi.app.mjs b/components/universal_summarizer_by_kagi/universal_summarizer_by_kagi.app.mjs index 9c79fcd3d71f8..66e70e6c325da 100644 --- a/components/universal_summarizer_by_kagi/universal_summarizer_by_kagi.app.mjs +++ b/components/universal_summarizer_by_kagi/universal_summarizer_by_kagi.app.mjs @@ -1,11 +1,69 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "universal_summarizer_by_kagi", - propDefinitions: {}, + propDefinitions: { + url: { + type: "string", + label: "URL", + description: "A URL to a document to summarize", + }, + engine: { + type: "string", + label: "Summarization Engine", + description: "Select the summarization engine", + options: constants.ENGINE_OPTIONS, + optional: true, + }, + summaryType: { + type: "string", + label: "Summary Type", + description: "Type of summary output", + options: constants.SUMMARY_TYPES, + optional: true, + }, + targetLanguage: { + type: "string", + label: "Target Language", + description: "Desired output language", + options: constants.LANGUAGE_OPTIONS, + optional: true, + }, + cache: { + type: "boolean", + label: "Cache", + description: "Whether to allow cached requests & responses. Default is true", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://kagi.com/api/v0"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bot ${this.$auth.api_key}`, + ...headers, + }, + }); + }, + + async summarizeDocument(args = {}) { + return this._makeRequest({ + path: "/summarize", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81abb60212716..bab048f7c7046 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -550,8 +550,7 @@ importers: specifier: ^4.0.0 version: 4.0.1 - components/airpinpoint: - specifiers: {} + components/airpinpoint: {} components/airplane: dependencies: