Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Add preprocessor hooks
haxzie1107dd593b11
diff --git a/examples/langchain/src/index.ts b/examples/langchain/src/index.tsindex 6cc7b9b17..fbe8acb32 100644--- a/examples/langchain/src/index.ts+++ b/examples/langchain/src/index.ts@@ -11,3 +11,6 @@ const composio = new Composio({const tools = await composio.getTools();console.log(tools);+++diff --git a/examples/openai/src/index.ts b/examples/openai/src/index.tsindex 293ca4efc..0ae9d454e 100644--- a/examples/openai/src/index.ts+++ b/examples/openai/src/index.ts@@ -11,9 +11,10 @@ const composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,});+// Fetch all the tools from the Composio API// these tools are automatically typed and wrapped with the OpenAI Toolset-const tool = await composio.getTool('HACKERNEWS_GET_USER');+const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER');const task = "Fetch the details of the user 'haxzie'";diff --git a/examples/vercel/package.json b/examples/vercel/package.jsonindex 84bc1eee8..f6d2b7674 100644--- a/examples/vercel/package.json+++ b/examples/vercel/package.json@@ -14,7 +14,7 @@"dependencies": {"@ai-sdk/openai": "^1.3.16","@composio/core": "workspace:*",- "@composio/vercel": "workspace:0.1.0-rc.1",+ "@composio/vercel": "workspace:*","ai": "^4.3.8"},"devDependencies": {diff --git a/examples/vercel/src/example.ts b/examples/vercel/src/example.tsnew file mode 100644index 000000000..c58683e5b--- /dev/null+++ b/examples/vercel/src/example.ts@@ -0,0 +1,40 @@+import { Composio } from "@composio/core";+import { generateText } from "ai";+import { openai } from "@ai-sdk/openai";+import { VercelToolset } from "@composio/vercel";++const composio = new Composio({+ apiKey: process.env.COMPOSIO_API_KEY,+ toolset: new VercelToolset(),+ userId: process.env.COMPOSIO_USER_ID, // pass the user at the global level+});++++/**+ * For tools that have manual execute, we need to pass userId while executing the tool+ */+// @ts-ignore+const result = composio.toolset.handleToolCall(tool, { userId: process.env.COMPOSIO_USER_ID });++/**+ * For tools that have auto execute, we have to pass userId (required)+ */+const tools = await composio.getTools({+ // @ts-ignore+ filters: {},+ userId: process.env.COMPOSIO_USER_ID, // this is mandatory+ connectedAccountId: process.env.COMPOSIO_CONNECTED_ACCOUNT_ID, // this is optional+});+++/**+ * If the user wants to change the userId for a specifically fetched tool+ */+// @ts-ignore+const tool = await composio.wrapTool(+ // @ts-ignore+ hackerNewsTool,+ { userId: process.env.COMPOSIO_USER_ID }+);+diff --git a/examples/vercel/src/index.ts b/examples/vercel/src/index.tsindex 27e8dcd72..079de3db4 100644--- a/examples/vercel/src/index.ts+++ b/examples/vercel/src/index.ts@@ -8,7 +8,7 @@ const composio = new Composio({toolset: new VercelToolset()});-const hackerNewsTool = await composio.toolset.getTool("HACKERNEWS_GET_FRONTPAGE");+const hackerNewsTool = await composio.toolset.getToolBySlug("HACKERNEWS_GET_FRONTPAGE");const MessageRoles = {USER: "user",diff --git a/packages/core/src/composio.ts b/packages/core/src/composio.tsindex bd4fcc872..f05954e07 100644--- a/packages/core/src/composio.ts+++ b/packages/core/src/composio.ts@@ -16,6 +16,7 @@ import { IS_DEVELOPMENT_OR_CI } from './utils/constants';import { checkForLatestVersionFromNPM } from './utils/version';import { OpenAIToolset } from './toolset/OpenAIToolset';import { version } from '../package.json';+import { Modifiers } from './models/Modifiers';export type ComposioConfig<TToolset extends BaseComposioToolset<unknown, unknown> = OpenAIToolset> ={@@ -66,6 +67,10 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = Otoolset: TToolset;authConfigs: AuthConfigs;connectedAccounts: ConnectedAccounts;+ modifiers: Modifiers;+ useBeforeToolExecute: Modifiers['useBeforeToolExecute'];+ useAfterToolExecute: Modifiers['useAfterToolExecute'];+ useTransformToolSchema: Modifiers['useTransformToolSchema'];/*** @param {Object} config Configuration for the Composio SDK.@@ -121,10 +126,19 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = Othis.toolset = (config.toolset ?? new ComposioToolset()) as TToolset;this.toolset.setClient(this);+ /**+ * Modifiers are used to modify the tools and toolkits.+ * Initialize the modifiers into global scope.+ */+ this.modifiers = new Modifiers();+ this.useBeforeToolExecute = this.modifiers.useBeforeToolExecute;+ this.useAfterToolExecute = this.modifiers.useAfterToolExecute;+ this.useTransformToolSchema = this.modifiers.useTransformToolSchema;+/*** Initialize all the models with composio client.*/- this.tools = new Tools(this.client);+ this.tools = new Tools(this.client, this.modifiers);this.toolkits = new Toolkits(this.client);this.triggers = new Triggers(this.client);this.authConfigs = new AuthConfigs(this.client);@@ -195,8 +209,8 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O* Generic function to get all the tools* @returns {Promise<ReturnType<TToolset["getTool"]>>} Promise with list of tools*/- async getTool(slug: string): Promise<ReturnType<TToolset['getTool']>> {- return this.toolset.getTool(slug) as Promise<ReturnType<TToolset['getTool']>>;+ async getToolBySlug(slug: string): Promise<ReturnType<TToolset['getToolBySlug']>> {+ return this.toolset.getToolBySlug(slug) as Promise<ReturnType<TToolset['getToolBySlug']>>;}/**diff --git a/packages/core/src/models/Modifiers.ts b/packages/core/src/models/Modifiers.tsnew file mode 100644index 000000000..b8f7d43dc--- /dev/null+++ b/packages/core/src/models/Modifiers.ts@@ -0,0 +1,110 @@+/**+ * @fileoverview Modifiers class for Composio SDK, used to manage tool execution modifiers.+ *+ * @author Musthaq Ahamad <[email protected]>+ * @date 2025-05-05+ * @module Modifiers+ */+import { AfterToolExecuteModifier, BeforeToolExecuteModifer, TransformToolSchemaModifier } from "../types/modifiers.types";+import { InstrumentedInstance } from "../types/telemetry.types";+import { Tool, ToolExecuteParams, ToolExecuteResponse } from "../types/tool.types";++/**+ * Modifiers class+ *+ * This class is used to manage the modifiers for the tools in the Composio SDK.+ * It provides methods to add before and after execution modifiers, as well as schema transformation modifiers.+ */+export class Modifiers implements InstrumentedInstance {+ readonly FILE_NAME: string = 'core/models/Modifiers.ts';+ private beforeToolExecuteModifiers: Map<string, Set<BeforeToolExecuteModifer>> = new Map();+ private afterToolExecuteModifiers: Map<string, Set<AfterToolExecuteModifier>> = new Map();+ private transformToolSchemaModifiers: Map<string, Set<TransformToolSchemaModifier>> = new Map();++ constructor() {}++ /**+ * Method to modify the tool schema before it is executed.+ * @param {string} toolSlug slug of the tool to be modified+ * @param modifier function to modify the tool execution parameters+ */+ useBeforeToolExecute(toolSlug: string, modifier: BeforeToolExecuteModifer) {+ if (!this.beforeToolExecuteModifiers.has(toolSlug)) {+ this.beforeToolExecuteModifiers.set(toolSlug, new Set());+ }+ this.beforeToolExecuteModifiers.get(toolSlug)?.add(modifier);+ }++ /**+ * Method to apply the before tool execute modifiers.+ * @param {string} toolSlug slug of the tool to be modified+ * @param {ToolExecuteParams} toolExecuteParams parameters to be passed to the tool+ * @returns {ToolExecuteParams} modified parameters+ */+ applyBeforeToolExecute(toolSlug: string, toolExecuteParams: ToolExecuteParams): ToolExecuteParams {+ const modifiers = this.beforeToolExecuteModifiers.get(toolSlug);+ if (modifiers) {+ for (const modifier of modifiers) {+ toolExecuteParams = modifier(toolSlug, toolExecuteParams);+ }+ }+ return toolExecuteParams;+ }+++ /**+ * Method to modify the tool schema after it is executed.+ * @param {string} toolSlug slug of the tool to be modified+ * @param modifier function to modify the tool execution response+ */+ useAfterToolExecute(toolSlug: string, modifier: AfterToolExecuteModifier) {+ if (!this.afterToolExecuteModifiers.has(toolSlug)) {+ this.afterToolExecuteModifiers.set(toolSlug, new Set());+ }+ this.afterToolExecuteModifiers.get(toolSlug)?.add(modifier);+ }++ /**+ * Method to apply the after tool execute modifiers.+ * @param {string} toolSlug slug of the tool to be modified+ * @param {ToolExecuteResponse} toolExecuteResponse response from the tool execution+ * @returns {ToolExecuteResponse} modified response+ */+ applyAfterToolExecute(toolSlug: string, toolExecuteResponse: ToolExecuteResponse): ToolExecuteResponse {+ const modifiers = this.afterToolExecuteModifiers.get(toolSlug);+ if (modifiers) {+ for (const modifier of modifiers) {+ toolExecuteResponse = modifier(toolSlug, toolExecuteResponse);+ }+ }+ return toolExecuteResponse;+ }++ /**+ * Method to register modifiers for the tool schema.+ * @param {string} toolSlug slug of the tool to be modified+ * @param modifier function to modify the tool schema+ */+ useTransformToolSchema(toolSlug: string, modifier:TransformToolSchemaModifier) {+ if (!this.transformToolSchemaModifiers.has(toolSlug)) {+ this.transformToolSchemaModifiers.set(toolSlug, new Set());+ }+ this.transformToolSchemaModifiers.get(toolSlug)?.add(modifier);+ }++ /**+ * Method to apply the transform tool schema modifiers.+ * @param toolSlug slug of the tool to be modified+ * @param toolSchema schema of the tool to be modified+ * @returns {Tool}+ */+ applyTransformToolSchema(toolSlug: string, toolSchema: Tool): Tool {+ const modifiers = this.transformToolSchemaModifiers.get(toolSlug);+ if (modifiers) {+ for (const modifier of modifiers) {+ toolSchema = modifier(toolSlug, toolSchema);+ }+ }+ return toolSchema;+ }+}\ No newline at end of filediff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.tsindex 81cd6d3f7..2c67854a5 100644--- a/packages/core/src/models/Tools.ts+++ b/packages/core/src/models/Tools.ts@@ -1,27 +1,27 @@-import ComposioClient from "@composio/client";-import { Tool } from "../types/tool.types";+import ComposioClient from '@composio/client';+import { Tool, ToolExecuteParams, ToolExecuteResponse } from '../types/tool.types';import {- ToolExecuteParams,- ToolExecuteResponse,ToolGetInputParams,ToolGetInputResponse,ToolListParams,ToolListResponse,ToolRetrieveEnumResponse,-} from "@composio/client/resources/tools";-import { InstrumentedInstance } from "../types/telemetry.types";-+} from '@composio/client/resources/tools';+import { InstrumentedInstance } from '../types/telemetry.types';+import { Modifiers } from './Modifiers';/*** This class is used to manage tools in the Composio SDK.* It provides methods to list, get, and execute tools.*/export class Tools implements InstrumentedInstance {- readonly FILE_NAME: string = "core/models/Tools.ts";+ readonly FILE_NAME: string = 'core/models/Tools.ts';private client: ComposioClient;-- constructor(client: ComposioClient) {+ private modifiers: Modifiers;++ constructor(client: ComposioClient, modifiers?: Modifiers) {this.client = client;+ this.modifiers = modifiers || new Modifiers();}/**@@ -29,16 +29,16 @@ export class Tools implements InstrumentedInstance {* This method fetches the tools from the Composio API and wraps them using the toolset.* @returns {Tools[]>} List of tools*/- async list(query: ToolListParams = {}): Promise<ToolListResponse> {- const tools = await this.client.tools.list(query);- if (!tools) {- return {- items: [],- next_cursor: null,- total_pages: 0,- };- }- return tools;+ async getTools(query: ToolListParams = {}): Promise<ToolListResponse> {+ const tools = await this.client.tools.list(query);+ if (!tools) {+ return {+ items: [],+ next_cursor: null,+ total_pages: 0,+ };+ }+ return tools;}/**@@ -46,8 +46,13 @@ export class Tools implements InstrumentedInstance {* @param slug The ID of the tool to be retrieved* @returns {Promise<Tool>} The tool*/- async get(slug: string): Promise<Tool> {- return this.client.tools.retrieve(slug);+ async getToolBySlug(slug: string): Promise<Tool> {+ const tool = await this.client.tools.retrieve(slug);+ if (!tool) {+ throw new Error(`Tool with slug ${slug} not found`);+ }+ const modifiedTool = this.modifiers.applyTransformToolSchema(slug, tool);+ return modifiedTool;}/**@@ -59,11 +64,11 @@ export class Tools implements InstrumentedInstance {* @param {ToolExecuteParams} body - The parameters to be passed to the tool* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution*/- async execute(- slug: string,- body: ToolExecuteParams- ): Promise<ToolExecuteResponse> {- return this.client.tools.execute(slug, body);+ async execute(slug: string, body: ToolExecuteParams): Promise<ToolExecuteResponse> {+ const modifiedBody = this.modifiers.applyBeforeToolExecute(slug, body);+ const result = await this.client.tools.execute(slug, modifiedBody);+ const modifiedResult = this.modifiers.applyAfterToolExecute(slug, result);+ return modifiedResult;}/**@@ -86,10 +91,7 @@ export class Tools implements InstrumentedInstance {* @param {ToolGetInputParams} body - The parameters to be passed to the tool* @returns*/- async getInput(- slug: string,- body: ToolGetInputParams- ): Promise<ToolGetInputResponse> {+ async getInput(slug: string, body: ToolGetInputParams): Promise<ToolGetInputResponse> {return this.client.tools.getInput(slug, body);}}diff --git a/packages/core/src/toolset/BaseToolset.ts b/packages/core/src/toolset/BaseToolset.tsindex b3113e7e7..4ca242f24 100644--- a/packages/core/src/toolset/BaseToolset.ts+++ b/packages/core/src/toolset/BaseToolset.ts@@ -1,6 +1,7 @@import type { Toolset } from '../types/toolset.types';-import type { Tool, ToolListParams } from '../types/tool.types';+import type { CustomAuthParams, Tool, ToolListParams } from '../types/tool.types';import type { Composio } from '../composio';+import { ComposioError } from '../utils/error';/*** Base toolset implementation with proper generic defaults@@ -40,9 +41,9 @@ export abstract class BaseComposioToolset<TToolCollection, TTool>* @param slug - The slug of the tool.* @returns The tool.*/- async getTool(slug: string): Promise<TTool> {- const tool = await this.client?.tools.get(slug);- return this._wrapTool(tool as Tool);+ async getToolBySlug(slug: string): Promise<TTool> {+ const tool = await this.getComposioClient().tools.getToolBySlug(slug);+ return this._wrapTool(tool);}/**@@ -53,14 +54,53 @@ export abstract class BaseComposioToolset<TToolCollection, TTool>abstract _wrapTool(tool: Tool): TTool;/**- * Ensure the client is initialized.- * This is automatically done by the Composio class.+ * Execute an action*/- protected ensureClient(): void {+ async execute({+ toolSlug,+ params,+ entityId,+ connectedAccountId,+ text,+ customAuthParams,+ }: {+ toolSlug: string;+ params: Record<string, unknown>;+ entityId?: string;+ connectedAccountId?: string;+ text?: string;+ customAuthParams?: CustomAuthParams;+ }) {+ const tool = await this.client?.tools.getToolBySlug(toolSlug);++ if (!tool) {+ throw new ComposioError(`Tool with slug ${toolSlug} not found`);+ }++ try {+ const result = await this.getComposioClient().tools.execute(toolSlug, {+ arguments: params,+ userId: entityId,+ connectedAccountId: connectedAccountId,+ text: text,+ customAuthParams: customAuthParams,+ });+ return result;+ } catch (error) {+ throw new ComposioError(`Error executing tool ${toolSlug}: ${error}`);+ }+ }++ /**+ * Get the Composio client.+ * @returns The Composio client.+ */+ protected getComposioClient(): Composio<this> {if (!this.client) {throw new Error('Client not initialized. Make sure the toolset is properly initialized with Composio.');}+ return this.client;}}diff --git a/packages/core/src/toolset/ComposioToolset.ts b/packages/core/src/toolset/ComposioToolset.tsindex 626c1b840..7cc074e3f 100644--- a/packages/core/src/toolset/ComposioToolset.ts+++ b/packages/core/src/toolset/ComposioToolset.ts@@ -19,7 +19,7 @@ export class ComposioToolset extends BaseComposioToolset<Array<CustomTool>, Cust};async getTools(params?: ToolListParams): Promise<Array<CustomTool>> {- const tools = await this.client?.tools.list(params);+ const tools = await this.client?.tools.getTools(params);return tools?.items.map((tool) => this._wrapTool(tool as Tool)) ?? [];}diff --git a/packages/core/src/toolset/OpenAIToolset.ts b/packages/core/src/toolset/OpenAIToolset.tsindex 56356da7e..f11ddd77d 100644--- a/packages/core/src/toolset/OpenAIToolset.ts+++ b/packages/core/src/toolset/OpenAIToolset.ts@@ -43,7 +43,7 @@ export class OpenAIToolset extends BaseComposioToolset<OpenAiToolCollection, Ope* @returns The tools.*/async getTools(params?: ToolListParams): Promise<OpenAiToolCollection> {- const tools = await this.client?.tools.list(params);+ const tools = await this.client?.tools.getTools(params);return tools?.items.map((tool) => this._wrapTool(tool as Tool)) ?? [];}@@ -65,18 +65,18 @@ export class OpenAIToolset extends BaseComposioToolset<OpenAiToolCollection, Ope/*** @TODO: This is redundant, we should be able to get the tool name from the tool call*/- const toolSchema = await this.client.tools.get(tool.function.name);- const appName = toolSchema?.toolkit?.name.toLowerCase();- const connectedAccountId = this.client.getConnectedAccountId(appName);-+ const toolSchema = await this.client.tools.getToolBySlug(tool.function.name);+ const appSlug = toolSchema?.toolkit?.slug.toLowerCase();+ if (!appSlug) {+ throw new Error("App slug not found");+ }+ const connectedAccountId = this.client.getConnectedAccountId(appSlug);const payload = {entity_id: userId ?? this.client.userId,connected_account_id: connectedAccountId,arguments: JSON.parse(tool.function.arguments),}-const results = await this.client.tools.execute(toolSchema.slug, payload);-return JSON.stringify(results);}diff --git a/packages/core/src/toolset/ToolsRegistry.ts b/packages/core/src/toolset/ToolsRegistry.tsnew file mode 100644index 000000000..5c47ca54c--- /dev/null+++ b/packages/core/src/toolset/ToolsRegistry.ts@@ -0,0 +1,50 @@+import { Tool, ToolSchema } from '../types/tool.types';++/**+ * TOOLS REGISTRY+ *+ * This singlton class is used to register user provided tools in the toolset.+ *+ *+ */+export class ToolsRegistry {+ private tools: Map<string, Tool> = new Map<string, Tool>();++ constructor() {}++ /**+ * Create a tool in the registry.+ * @param {Tool} tool - The tool to create.+ * @returns {Tool} The created tool.+ */+ createTool(tool: Tool): Tool {+ try {+ const parsedTool = ToolSchema.parse(tool);+ const lowerCaseSlug = parsedTool.slug.toLowerCase();+ this.tools.set(lowerCaseSlug, parsedTool);+ return parsedTool;+ } catch (error) {+ throw new Error(`Failed to create tool ${tool.slug}: ${error}`);+ }+ }++ /**+ * Get a tool from the registry.+ * @param {string} slug - The slug of the tool.+ * @returns {Tool | undefined} The tool.+ */+ getToolBySlug(slug: string): Tool | undefined {+ const lowerCaseSlug = slug.toLowerCase();+ return this.tools.get(lowerCaseSlug);+ }++ /**+ * Get all the tools from the registry.+ * @returns {Tool[]} The tools.+ */+ getTools(): Tool[] {+ return Array.from(this.tools.values());+ }+}++export const toolsRegistry = new ToolsRegistry();diff --git a/packages/core/src/types/modifiers.types.ts b/packages/core/src/types/modifiers.types.tsnew file mode 100644index 000000000..cd8206c8f--- /dev/null+++ b/packages/core/src/types/modifiers.types.ts@@ -0,0 +1,5 @@+import { ToolExecuteParams, ToolExecuteResponse, Tool } from "./tool.types";++export type BeforeToolExecuteModifer = (toolSlug: string, toolExecuteParams: ToolExecuteParams) => ToolExecuteParams;+export type AfterToolExecuteModifier = (toolSlug: string, toolExecuteResponse: ToolExecuteResponse) => ToolExecuteResponse;+export type TransformToolSchemaModifier = (toolSlug: string, toolSchemModifier: Tool) => Tool;\ No newline at end of filediff --git a/packages/core/src/types/tool.types.ts b/packages/core/src/types/tool.types.tsindex f7b3d868e..dd750d7e6 100644--- a/packages/core/src/types/tool.types.ts+++ b/packages/core/src/types/tool.types.ts@@ -1,23 +1,111 @@-import { ToolRetrieveResponse } from '@composio/client/resources/tools';import { z } from 'zod';-export type Tool = ToolRetrieveResponse;+/**+ * Toolkit is the collection of tools,+ * A toolkit can be thought of as an app which provides a set of tools/actions/triggers.+ *+ * eg. Google Toolkit, which provides tools like Google Search, Google Maps, Google Translate, etc.+ */+export const ToolkitSchema = z.object({+ slug: z.string().describe('The slug of the toolkit'),+ name: z.string().describe('The name of the toolkit'),+ logo: z.string().describe('The logo of the toolkit'),+});+export type Toolkit = z.infer<typeof ToolkitSchema>;-export interface BaseTool {- name: string;- description?: string;- input_parameters?: Record<string, unknown>;- output_parameters?: Record<string, unknown>;-}+/**+ * Tool is a single action that can be performed by a toolkit.+ * Tool is simlar to an action that an app can perform.+ *+ * eg. Google Search, Google Maps, Google Translate, etc.+ */+export const ToolSchema = z.object({+ slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),+ name: z.string().describe(`The name of the tool. eg. "Google Search"`),+ description: z.string().optional().describe('The description of the tool'),+ input_parameters: z+ .record(z.string(), z.unknown())+ .optional()+ .describe('The input parameters of the tool'),+ output_parameters: z+ .record(z.string(), z.unknown())+ .optional()+ .describe('The output parameters of the tool'),+ tags: z.optional(z.array(z.string())).describe('The tags of the tool. eg: Important').default([]),+ toolkit: z.optional(ToolkitSchema).describe('The toolkit of the tool'),+ version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"'),+});+export type Tool = z.infer<typeof ToolSchema>;+/**+ * BaseTool is the base type for all tools.+ */+export const BaseToolSchema = z.object({+ name: z.string().describe('The name of the tool'),+ description: z.string().optional().describe('The description of the tool'),+ inpputParameters: z+ .record(z.string(), z.unknown())+ .optional()+ .describe('The input parameters of the tool'),+ outputParameters: z+ .record(z.string(), z.unknown())+ .optional()+ .describe('The output parameters of the tool'),+});+export type BaseTool = z.infer<typeof BaseToolSchema>;export type ToolType<T extends BaseTool> = T;+/**+ * ToolListParams is the parameters for the list of tools.+ */export const ToolListParamsSchema = z.object({cursor: z.string().optional(),important: z.string().optional(),limit: z.string().optional(),search: z.string().optional(),- toolkit_slug: z.string().optional(),+ toolkitSlug: z.string().optional(),});-export type ToolListParams = z.infer<typeof ToolListParamsSchema>;++/**+ * CustomAuthParams is the parameters for the custom authentication.+ */+export const CustomAuthParamsSchema = z.object({+ baseURL: z.string().optional(),+ body: z.record(z.string(), z.unknown()).optional(),+ parameters: z.array(+ z.object({+ in: z.enum(['query', 'header']),+ name: z.string(),+ value: z.union([z.string(), z.number()]),+ })+ ),+});+export type CustomAuthParams = z.infer<typeof CustomAuthParamsSchema>;++/**+ * ToolExecuteParams is the parameters for the tool execution.+ */+export const ToolExecuteParamsSchema = z.object({+ allowTracing: z.boolean().optional(),+ connectedAccountId: z.string().optional(),+ customAuthParams: CustomAuthParamsSchema.optional(),+ arguments: z.record(z.string(), z.unknown()).optional(),+ userId: z.string().optional(),+ version: z.string().optional(),+ text: z.string().optional(),+});+export type ToolExecuteParams = z.infer<typeof ToolExecuteParamsSchema>;+++/**+ * ToolResponse Schema+ */+export const ToolExecuteResponseSchema = z.object({+ data: z.record(z.string(), z.unknown()),+ error: z.string().nullable(),+ successful: z.boolean(),+ log_id: z.string().optional(),+ session_info: z.unknown().optional(),+});+export type ToolExecuteResponse = z.infer<typeof ToolExecuteResponseSchema>;\ No newline at end of filediff --git a/packages/core/src/types/toolset.types.ts b/packages/core/src/types/toolset.types.tsindex 2cab867a8..ac23017aa 100644--- a/packages/core/src/types/toolset.types.ts+++ b/packages/core/src/types/toolset.types.ts@@ -1,5 +1,5 @@-import { InstrumentedInstance } from "./telemetry.types";-import { Tool, BaseTool, ToolListParams } from "./tool.types";+import { InstrumentedInstance } from './telemetry.types';+import { Tool, BaseTool, ToolListParams } from './tool.types';/*** Base toolset implementation, which needs to be implemented by the extended class.@@ -11,12 +11,13 @@ export interface Toolset<TTool = BaseTool, TToolCollection = TTool[]> extends IngetTools: (params?: ToolListParams) => Promise<TToolCollection>;}-/*** This type is used to infer the wrapped tool type from the toolset.* It checks if the toolset has a method `_wrapTool` and infers the return type.*/export type WrappedTool<TToolset> = TToolset extends {_wrapTool: (tool: Tool) => infer TTool;-} ? TTool : never;+}+ ? TTool+ : never;diff --git a/packages/core/src/utils/error.ts b/packages/core/src/utils/error.tsnew file mode 100644index 000000000..189e3eae9--- /dev/null+++ b/packages/core/src/utils/error.ts@@ -0,0 +1,44 @@+import { ZodError } from 'zod';++export class ComposioError extends Error {+ private error: Error;++ constructor(messageOrError: string | unknown, error?: unknown) {+ let message: string;+ let err: Error;++ if (error instanceof ZodError) {+ const formattedMessage = error.errors+ .map(e => `Path: ${e.path.join('.') || '(root)'} - ${e.message}`)+ .join('; ');+ message = `${messageOrError}: ${formattedMessage}`;+ err = error;+ } else {+ message = typeof messageOrError === 'string' ? messageOrError : String(messageOrError);+ err = error as Error;+ }++ super(message);+ this.error = err;++ // Capture the stack trace of the caller+ if (Error.captureStackTrace) {+ Error.captureStackTrace(this, ComposioError);+ }+ }++ /**+ * Static method to handle Zod errors.+ * If the provided error is a ZodError, it formats the error message and returns a new ComposioError.+ * Otherwise, it returns a new ComposioError with the original message and error.+ */+ static fromZodError(message: string, error: unknown): ComposioError {+ if (error instanceof ZodError) {+ const formattedMessage = error.errors+ .map(e => `Path: ${e.path.join('.') || '(root)'} - ${e.message}`)+ .join('; ');+ return new ComposioError(`${message}: ${formattedMessage}`, error);+ }+ return new ComposioError(message, error as Error);+ }+}diff --git a/packages/toolsets/vercel/package.json b/packages/toolsets/vercel/package.jsonindex cf8542349..c907c9bb3 100644--- a/packages/toolsets/vercel/package.json+++ b/packages/toolsets/vercel/package.json@@ -33,7 +33,7 @@"typescript": "^5.8.3"},"dependencies": {- "@composio/core": "^0.1.0-rc.1",+ "@composio/core": "workspace:*","ai": "^4.3.8"}}diff --git a/packages/toolsets/vercel/src/index.ts b/packages/toolsets/vercel/src/index.tsindex d3ee5a590..24f9d440b 100644--- a/packages/toolsets/vercel/src/index.ts+++ b/packages/toolsets/vercel/src/index.ts@@ -70,7 +70,7 @@ export class VercelToolset extends BaseComposioToolset<VercelToolCollection, Ver_wrapTool(composioTool: ComposioTool): VercelTool {return tool({description: composioTool.description,- parameters: jsonSchema(composioTool.input_parameters),+ parameters: jsonSchema(composioTool.input_parameters ?? {}),execute: async params => {return await this.executeToolCall({diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f1c61c075..3aa3f226f 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -74,7 +74,7 @@ importers:specifier: workspace:*version: link:../../packages/core'@composio/vercel':- specifier: workspace:0.1.0-rc.1+ specifier: workspace:*version: link:../../packages/toolsets/vercelai:specifier: ^4.3.8@@ -163,8 +163,8 @@ importers:packages/toolsets/vercel:dependencies:'@composio/core':- specifier: ^0.1.0-rc.1- version: 0.1.0-rc.3+ specifier: workspace:0.1.0-rc.5+ version: link:../../coreai:specifier: ^4.3.8version: 4.3.8([email protected])([email protected])