From 27df7e5f9eab96d2fa9d1975c4df2c0016621a77 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 2 Jan 2025 12:40:36 +0530 Subject: [PATCH] fix: type typo and getTools w custom action (#1121) --- js/examples/e2e/demo.mjs | 22 +++++++++++++++------- js/examples/e2e/demo.ts | 27 ++++++++++++++++++++------- js/src/frameworks/langchain.spec.ts | 4 ++++ js/src/frameworks/langchain.ts | 2 +- js/src/sdk/actionRegistry.ts | 2 +- js/src/sdk/base.toolset.ts | 6 +++--- js/src/sdk/models/actions.ts | 4 ++-- js/src/types/base_toolset.ts | 4 ++-- 8 files changed, 48 insertions(+), 23 deletions(-) diff --git a/js/examples/e2e/demo.mjs b/js/examples/e2e/demo.mjs index f2604c7b844..d9292f31a76 100644 --- a/js/examples/e2e/demo.mjs +++ b/js/examples/e2e/demo.mjs @@ -1,24 +1,32 @@ import { Composio, LangchainToolSet } from "composio-core"; import { z } from "zod"; -const toolset = new LangchainToolSet(); +const toolset = new LangchainToolSet({}); (async() => { console.log("Creating action"); + try { await toolset.createAction({ actionName: "helloWorld", description: "This is a test action for handling hello world", - params: z.object({ + inputParams: z.object({ name: z.string().optional() }), callback: async (params) => { const { name } = params; - return `Hello ${name || "World"} from the function`; + return { + successful: true, + data: { + name: name || "World" + } + } } }); - console.log("Tools are registered", await toolset.getTools({actions: ["helloWorld"]})); - // Sending params to the action - const result = await toolset.executeAction("helloWorld", { name: "Alice" }, {}); - console.log("Action result:", result); + console.log("Tools are registered", await toolset.getTools({ + actions: ["helloWorld"] + })); + } catch (error) { + console.error("Error creating action", error); + } })(); \ No newline at end of file diff --git a/js/examples/e2e/demo.ts b/js/examples/e2e/demo.ts index aa1e8f73415..f6006455e30 100644 --- a/js/examples/e2e/demo.ts +++ b/js/examples/e2e/demo.ts @@ -1,19 +1,32 @@ - import { Composio, LangchainToolSet } from "composio-core"; +import { z } from "zod"; const toolset = new LangchainToolSet(); (async() => { console.log("Creating action"); + try { await toolset.createAction({ actionName: "helloWorld", description: "This is a test action for handling hello world", - callback: async () => { - return "Hello World from the function"; + inputParams: z.object({ + name: z.string().optional() + }), + callback: async (params) => { + const { name } = params; + return { + successful: true, + data: { + name: name || "World" + } + } } }); - console.log("Tools are registered", toolset.getTools()); -}) - - + console.log("Tools are registered", await toolset.getTools({ + actions: ["helloWorld"] + })); + } catch (error) { + console.error("Error creating action", error); + } +})(); \ No newline at end of file diff --git a/js/src/frameworks/langchain.spec.ts b/js/src/frameworks/langchain.spec.ts index bc9852b21e1..3de2c63adb6 100644 --- a/js/src/frameworks/langchain.spec.ts +++ b/js/src/frameworks/langchain.spec.ts @@ -60,6 +60,10 @@ describe("Apps class tests", () => { }, }); + langchainToolSet.getTools({ + actions: ["starRepositoryCustomAction"], + }); + const actionOuput = await langchainToolSet.executeAction({ action: "starRepositoryCustomAction", params: { diff --git a/js/src/frameworks/langchain.ts b/js/src/frameworks/langchain.ts index 4eeae1ecc7a..3d0eca25609 100644 --- a/js/src/frameworks/langchain.ts +++ b/js/src/frameworks/langchain.ts @@ -69,7 +69,7 @@ export class LangchainToolSet extends BaseComposioToolSet { } async getTools( - filters: z.infer, + filters: z.infer = {}, entityId: Optional = null ): Promise> { TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, { diff --git a/js/src/sdk/actionRegistry.ts b/js/src/sdk/actionRegistry.ts index 1d01e5b7193..3d13ab6b537 100644 --- a/js/src/sdk/actionRegistry.ts +++ b/js/src/sdk/actionRegistry.ts @@ -135,7 +135,7 @@ export class ActionRegistry { throw new Error(`Action with name ${name} could not be retrieved`); } - const { callback, toolName } = action.metadata; + const { callback, toolName } = action.metadata || {}; let authCredentials = {}; if (toolName) { const entity = await this.client.getEntity(metadata.entityId); diff --git a/js/src/sdk/base.toolset.ts b/js/src/sdk/base.toolset.ts index e8455d185ea..f953bc7325c 100644 --- a/js/src/sdk/base.toolset.ts +++ b/js/src/sdk/base.toolset.ts @@ -141,15 +141,15 @@ export class ComposioToolSet { const toolsWithCustomActions = ( await this.userActionRegistry.getAllActions() ).filter((action) => { - const { actionName, toolName } = action.metadata; + const { name: actionName, toolName } = action.metadata || {}; return ( (!filters.actions || filters.actions.some( - (name) => name.toLowerCase() === actionName!.toLowerCase() + (name) => name.toLowerCase() === actionName?.toLowerCase() )) && (!filters.apps || filters.apps.some( - (name) => name.toLowerCase() === toolName!.toLowerCase() + (name) => name.toLowerCase() === toolName?.toLowerCase() )) && (!filters.tags || filters.tags.some((tag) => tag.toLowerCase() === "custom")) diff --git a/js/src/sdk/models/actions.ts b/js/src/sdk/models/actions.ts index 6c585196471..231594dee67 100644 --- a/js/src/sdk/models/actions.ts +++ b/js/src/sdk/models/actions.ts @@ -26,7 +26,7 @@ import { BackendClient } from "./backendClient"; export type ActionListParams = z.infer; export type HeaderSingleParameters = z.infer; export type CustomAuth = z.infer; -export type ActionxExecuteParam = z.infer; +export type ActionExecuteParam = z.infer; export type ActionItemParam = z.infer; export type FindActionEnumsByUseCaseParam = z.infer< typeof ZFindActionEnumsByUseCaseParams @@ -142,7 +142,7 @@ export class Actions { * @returns {Promise} A promise that resolves to the execution status and response data. * @throws {ComposioError} If the request fails. */ - async execute(data: ActionxExecuteParam): Promise { + async execute(data: ActionExecuteParam): Promise { TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, { method: "execute", file: this.fileName, diff --git a/js/src/types/base_toolset.ts b/js/src/types/base_toolset.ts index 20fc6244854..8b61568e297 100644 --- a/js/src/types/base_toolset.ts +++ b/js/src/types/base_toolset.ts @@ -24,8 +24,8 @@ export const ZRawActionSchema = z.object({ }), response: z.record(z.any()), metadata: z.object({ - actionName: z.string(), - toolName: z.string(), + name: z.string(), + toolName: z.string().optional(), }), });