diff --git a/components/griptape/actions/create-assistant/create-assistant.mjs b/components/griptape/actions/create-assistant/create-assistant.mjs new file mode 100644 index 0000000000000..f0320ecde3ba9 --- /dev/null +++ b/components/griptape/actions/create-assistant/create-assistant.mjs @@ -0,0 +1,105 @@ +import app from "../../griptape.app.mjs"; + +export default { + key: "griptape-create-assistant", + name: "Create Assistant", + description: "Creates a new assistant in Griptape. [See the documentation](https://docs.griptape.ai/stable/griptape-cloud/api/api-reference/#/Assistants/CreateAssistant)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + input: { + propDefinition: [ + app, + "input", + ], + }, + knowledgeBaseIds: { + type: "string[]", + label: "Knowledge Base IDs", + description: "The knowledge base IDs of the assistant", + optional: true, + propDefinition: [ + app, + "knowledgeBaseId", + ], + }, + rulesetIds: { + type: "string[]", + label: "Ruleset IDs", + description: "The ruleset IDs of the assistant", + optional: true, + propDefinition: [ + app, + "rulesetId", + ], + }, + structureIds: { + type: "string[]", + label: "Structure IDs", + description: "The structure IDs of the assistant", + optional: true, + propDefinition: [ + app, + "structureId", + ], + }, + toolIds: { + type: "string[]", + label: "Tool IDs", + description: "The tool IDs of the assistant", + optional: true, + propDefinition: [ + app, + "toolId", + ], + }, + }, + methods: { + createAssistant(args = {}) { + return this.app.post({ + path: "/assistants", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createAssistant, + name, + description, + input, + knowledgeBaseIds, + rulesetIds, + structureIds, + toolIds, + } = this; + + const response = await createAssistant({ + $, + data: { + name, + description, + input, + knowledge_base_ids: knowledgeBaseIds, + ruleset_ids: rulesetIds, + structure_ids: structureIds, + tool_ids: toolIds, + }, + }); + $.export("$summary", `Successfully created a new assistant with ID \`${response.assistant_id}\`.`); + return response; + }, +}; diff --git a/components/griptape/actions/delete-assistant/delete-assistant.mjs b/components/griptape/actions/delete-assistant/delete-assistant.mjs new file mode 100644 index 0000000000000..49430c9d06a47 --- /dev/null +++ b/components/griptape/actions/delete-assistant/delete-assistant.mjs @@ -0,0 +1,43 @@ +import app from "../../griptape.app.mjs"; + +export default { + key: "griptape-delete-assistant", + name: "Delete Assistant", + description: "Deletes an existing assistant. [See the documentation](https://docs.griptape.ai/stable/griptape-cloud/api/api-reference/#/Assistants/DeleteAssistant).", + version: "0.0.1", + type: "action", + props: { + app, + assistantId: { + propDefinition: [ + app, + "assistantId", + ], + }, + }, + methods: { + deleteAssistant({ + assistantId, ...args + } = {}) { + return this.app.delete({ + path: `/assistants/${assistantId}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + deleteAssistant, + assistantId, + } = this; + + await deleteAssistant({ + $, + assistantId, + }); + $.export("$summary", "Successfully deleted assistant"); + return { + success: true, + }; + }, +}; diff --git a/components/griptape/actions/update-assistant/update-assistant.mjs b/components/griptape/actions/update-assistant/update-assistant.mjs new file mode 100644 index 0000000000000..7b82444bcab93 --- /dev/null +++ b/components/griptape/actions/update-assistant/update-assistant.mjs @@ -0,0 +1,117 @@ +import app from "../../griptape.app.mjs"; + +export default { + key: "griptape-update-assistant", + name: "Update Assistant", + description: "Updates an existing assistant. [See the documentation](https://docs.griptape.ai/stable/griptape-cloud/api/api-reference/#/Assistants/UpdateAssistant).", + version: "0.0.1", + type: "action", + props: { + app, + assistantId: { + propDefinition: [ + app, + "assistantId", + ], + }, + name: { + optional: true, + propDefinition: [ + app, + "name", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + input: { + optional: true, + propDefinition: [ + app, + "input", + ], + }, + knowledgeBaseIds: { + type: "string[]", + label: "Knowledge Base IDs", + description: "The knowledge base IDs of the assistant", + optional: true, + propDefinition: [ + app, + "knowledgeBaseId", + ], + }, + rulesetIds: { + type: "string[]", + label: "Ruleset IDs", + description: "The ruleset IDs of the assistant", + optional: true, + propDefinition: [ + app, + "rulesetId", + ], + }, + structureIds: { + type: "string[]", + label: "Structure IDs", + description: "The structure IDs of the assistant", + optional: true, + propDefinition: [ + app, + "structureId", + ], + }, + toolIds: { + type: "string[]", + label: "Tool IDs", + description: "The tool IDs of the assistant", + optional: true, + propDefinition: [ + app, + "toolId", + ], + }, + }, + methods: { + updateAssistant({ + assistantId, ...args + } = {}) { + return this.app.patch({ + path: `/assistants/${assistantId}`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + updateAssistant, + assistantId, + name, + description, + input, + knowledgeBaseIds, + rulesetIds, + structureIds, + toolIds, + } = this; + + const response = await updateAssistant({ + $, + assistantId, + data: { + name, + description, + input, + knowledge_base_ids: knowledgeBaseIds, + ruleset_ids: rulesetIds, + structure_ids: structureIds, + tool_ids: toolIds, + }, + }); + $.export("$summary", `Successfully updated assistant with ID \`${response.assistant_id}\`.`); + return response; + }, +}; diff --git a/components/griptape/griptape.app.mjs b/components/griptape/griptape.app.mjs index e22b5bb97d96e..234d2d9757082 100644 --- a/components/griptape/griptape.app.mjs +++ b/components/griptape/griptape.app.mjs @@ -1,11 +1,188 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "griptape", - propDefinitions: {}, + propDefinitions: { + name: { + type: "string", + label: "Name", + description: "The name of the assistant", + }, + description: { + type: "string", + label: "Description", + description: "The description of the assistant", + optional: true, + }, + input: { + type: "string", + label: "Input", + description: "The input of the assistant", + }, + knowledgeBaseId: { + type: "string", + label: "Knowledge Base ID", + description: "The ID of the knowledge base", + async options({ page }) { + const { knowledge_bases: knowledgeBases } = await this.listKnowledgeBases({ + params: { + page, + }, + }); + return knowledgeBases.map(({ + knowledge_base_id: value, + name: label, + }) => ({ + label, + value, + })); + }, + }, + rulesetId: { + type: "string", + label: "Ruleset ID", + description: "The ID of the ruleset", + async options({ page }) { + const { rulesets } = await this.listRulesets({ + params: { + page, + }, + }); + return rulesets.map(({ + ruleset_id: value, + name: label, + }) => ({ + label, + value, + })); + }, + }, + structureId: { + type: "string", + label: "Structure ID", + description: "The ID of the structure", + async options({ page }) { + const { structures } = await this.listStructures({ + params: { + page, + }, + }); + return structures.map(({ + structure_id: value, + name: label, + }) => ({ + label, + value, + })); + }, + }, + toolId: { + type: "string", + label: "Tool ID", + description: "The ID of the tool", + async options({ page }) { + const { tools } = await this.listTools({ + params: { + page, + }, + }); + return tools.map(({ + tool_id: value, + name: label, + }) => ({ + label, + value, + })); + }, + }, + assistantId: { + type: "string", + label: "Assistant ID", + description: "The ID of the assistant you want to update or delete.", + async options({ page }) { + const { assistants } = await this.listAssistants({ + params: { + page, + }, + }); + return assistants.map(({ + assistant_id: value, + name: label, + }) => ({ + label, + value, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://cloud.griptape.ai/api${path}`; + }, + getHeaders(headers) { + return { + Authorization: `Bearer ${this.$auth.api_key}`, + Accept: "application/json", + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + patch(args = {}) { + return this._makeRequest({ + method: "PATCH", + ...args, + }); + }, + delete(args = {}) { + return this._makeRequest({ + method: "DELETE", + ...args, + }); + }, + listKnowledgeBases(args = {}) { + return this._makeRequest({ + path: "/knowledge-bases", + ...args, + }); + }, + listRulesets(args = {}) { + return this._makeRequest({ + path: "/rulesets", + ...args, + }); + }, + listStructures(args = {}) { + return this._makeRequest({ + path: "/structures", + ...args, + }); + }, + listTools(args = {}) { + return this._makeRequest({ + path: "/tools", + ...args, + }); + }, + listAssistants(args = {}) { + return this._makeRequest({ + path: "/assistants", + ...args, + }); }, }, }; diff --git a/components/griptape/package.json b/components/griptape/package.json index af53254878cbd..f06eecc57353c 100644 --- a/components/griptape/package.json +++ b/components/griptape/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/griptape", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Griptape Components", "main": "griptape.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf88c0d8585ab..5686f969dc699 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5569,7 +5569,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/griptape: {} + components/griptape: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/grist: dependencies: @@ -34022,8 +34026,6 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) - transitivePeerDependencies: - - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: