From 1f0f84c1915759c155896a471e420013252afddd Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 28 Oct 2024 11:59:08 -0400 Subject: [PATCH] refactor(actions): refactor createActionTool to use request executor pattern --- api/server/services/ActionService.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/server/services/ActionService.js b/api/server/services/ActionService.js index da69548b43d..6bca75b9895 100644 --- a/api/server/services/ActionService.js +++ b/api/server/services/ActionService.js @@ -119,18 +119,24 @@ async function loadActionSets(searchParams) { * @param {string | undefined} [params.name] - The name of the tool. * @param {string | undefined} [params.description] - The description for the tool. * @param {import('zod').ZodTypeAny | undefined} [params.zodSchema] - The Zod schema for tool input validation/definition - * @returns { Promsie unknown}> } An object with `_call` method to execute the tool input. + * @returns { Promise unknown}> } An object with `_call` method to execute the tool input. */ async function createActionTool({ action, requestBuilder, zodSchema, name, description }) { action.metadata = await decryptMetadata(action.metadata); /** @type {(toolInput: Object | string) => Promise} */ const _call = async (toolInput) => { try { - requestBuilder.setParams(toolInput); + const executor = requestBuilder.createExecutor(); + + // Chain the operations + const preparedExecutor = executor.setParams(toolInput); + if (action.metadata.auth && action.metadata.auth.type !== AuthTypeEnum.None) { - await requestBuilder.setAuth(action.metadata); + await preparedExecutor.setAuth(action.metadata); } - const res = await requestBuilder.execute(); + + const res = await preparedExecutor.execute(); + if (typeof res.data === 'object') { return JSON.stringify(res.data); }