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
Cleanup modifiers
haxzie6f8da6f8e9e6
diff --git a/examples/pre-processors/src/index.ts b/examples/pre-processors/src/index.tsindex 357c292eb..05ab8969d 100644--- a/examples/pre-processors/src/index.ts+++ b/examples/pre-processors/src/index.ts@@ -8,6 +8,12 @@ const composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,});+const tools = await composio.getTools(+ {+ toolkitSlug: 'HACKERNEWS',+ },+ {}+);// Local modifiersconst tool = await composio.getToolBySlug('HACKERNEWS_GET_USER', {schema: (toolSlug, toolSchema) => {@@ -26,19 +32,6 @@ composio.toolset.handleToolCall({}, '', {return toolExecuteParams;},});-// global modifiers, with toolslug as helper-composio.useTransformToolSchema('HACKERNEWS_GET_USER', toolSchema => {- toolSchema.inputParameters = {};- return toolSchema;-});--// global modifiers-composio.useTransformToolSchema((toolSlug, toolSchema) => {- if (toolSlug === 'HACKERNEWS_GET_USER') {- toolSchema.inputParameters = {};- }- return toolSchema;-});/*** Agentic toolset@@ -48,7 +41,7 @@ const vercelComposio = new Composio({toolset: new VercelToolset(),});-const tools = await vercelComposio.getTools(+const verceltools = await vercelComposio.getTools({toolkitSlug: 'HACKERNEWS',},@@ -67,3 +60,4 @@ const tools = await vercelComposio.getTools(},});+console.log(verceltools);diff --git a/examples/vercel/src/index.ts b/examples/vercel/src/index.tsindex 079de3db4..c067b0eed 100644--- a/examples/vercel/src/index.ts+++ b/examples/vercel/src/index.ts@@ -1,58 +1,58 @@-import { Composio } from "@composio/core";-import { generateText } from "ai";-import { openai } from "@ai-sdk/openai";-import { VercelToolset } from "@composio/vercel";+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()+ apiKey: process.env.COMPOSIO_API_KEY,+ toolset: new VercelToolset(),});-const hackerNewsTool = await composio.toolset.getToolBySlug("HACKERNEWS_GET_FRONTPAGE");+const hackerNewsTool = await composio.toolset.getToolBySlug('HACKERNEWS_GET_FRONTPAGE');const MessageRoles = {- USER: "user",- ASSISTANT: "assistant",- TOOL: "tool"+ USER: 'user',+ ASSISTANT: 'assistant',+ TOOL: 'tool',} as const;-type MessageRole = typeof MessageRoles[keyof typeof MessageRoles];+type MessageRole = (typeof MessageRoles)[keyof typeof MessageRoles];type Message = { role: MessageRole; content: string | any };-const messages: Message[] = [{+const messages: Message[] = [+ {role: MessageRoles.USER,- content: "Summarize the front page of HackerNews"-}];+ content: 'Summarize the front page of HackerNews',+ },+];const chatCompletion = async () => {+ const { text, toolCalls, toolResults } = await generateText({+ model: openai('gpt-4o-mini'),+ tools: { ['HACKERNEWS_GET_FRONTPAGE']: hackerNewsTool },+ messages,+ });++ if (toolResults.length > 0 && toolCalls.length > 0) {+ toolCalls.forEach(async toolCall => {+ console.log(`Executing tool call: ${toolCall.toolName}`);+ });++ messages.push({+ role: MessageRoles.ASSISTANT,+ content: toolCalls,+ });- const { text, toolCalls, toolResults } = await generateText({- model: openai("gpt-4o-mini"),- tools: { ["HACKERNEWS_GET_FRONTPAGE"]: hackerNewsTool },- messages,+ messages.push({+ role: MessageRoles.TOOL,+ content: toolResults,});- if (toolResults.length > 0 && toolCalls.length > 0) {- toolCalls.forEach(async (toolCall) => {- console.log(`Executing tool call: ${toolCall.toolName}`);- });-- messages.push({- role: MessageRoles.ASSISTANT,- content: toolCalls,- })-- messages.push({- role: MessageRoles.TOOL,- content: toolResults,- })--- await chatCompletion();- } else {- messages.push({ role: MessageRoles.ASSISTANT, content: text })- console.log(`Assistant: ${text}\n`)- }-}--chatCompletion();\ No newline at end of file+ await chatCompletion();+ } else {+ messages.push({ role: MessageRoles.ASSISTANT, content: text });+ console.log(`Assistant: ${text}\n`);+ }+};++chatCompletion();diff --git a/packages/core/src/composio.ts b/packages/core/src/composio.tsindex 5ae614b5a..5cc175080 100644--- a/packages/core/src/composio.ts+++ b/packages/core/src/composio.ts@@ -4,11 +4,11 @@ import { Toolkits } from './models/Toolkits';import { Triggers } from './models/Triggers';import { AuthConfigs } from './models/AuthConfigs';import { ConnectedAccounts } from './models/ConnectedAccounts';-import { BaseAgenticToolset, BaseNonAgenticToolset } from './toolset/BaseToolset';+import { BaseComposioToolset } from './toolset/BaseToolset';import { Telemetry } from './telemetry/Telemetry';import { BaseTelemetryTransport } from './telemetry/TelemetryTransport';import type { TelemetryMetadata } from './types/telemetry.types';-import type { ModifiersParams } from './types/modifiers.types';+import type { ToolsetModifierType } from './types/modifiers.types';import type { ToolListParams } from './types/tool.types';import { getSDKConfig } from './utils/sdk';import logger from './utils/logger';@@ -16,39 +16,24 @@ 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- | BaseAgenticToolset<unknown, unknown>- | BaseNonAgenticToolset<unknown, unknown> = OpenAIToolset,-> = {- apiKey?: string;- baseURL?: string;- allowTracking?: boolean;- allowTracing?: boolean;- toolset?: TToolset;- userId?: string;- connectedAccountIds?: Record<string, string>;- telemetryTransport?: BaseTelemetryTransport;-};-type ToolsetModifierType<- T extends BaseAgenticToolset<unknown, unknown> | BaseNonAgenticToolset<unknown, unknown>,-> =- T extends BaseAgenticToolset<unknown, unknown>- ? ModifiersParams- : Pick<ModifiersParams, 'schema'>;+export type ComposioConfig<TToolset extends BaseComposioToolset<unknown, unknown> = OpenAIToolset> =+ {+ apiKey?: string;+ baseURL?: string;+ allowTracking?: boolean;+ allowTracing?: boolean;+ toolset?: TToolset;+ userId?: string;+ connectedAccountIds?: Record<string, string>;+ telemetryTransport?: BaseTelemetryTransport;+ };/*** This is the core class for Composio.* It is used to initialize the Composio SDK and provide a global configuration.*/-export class Composio<- TToolset extends- | BaseAgenticToolset<unknown, unknown>- | BaseNonAgenticToolset<unknown, unknown> = OpenAIToolset,-> {+export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = OpenAIToolset> {private readonly DEFAULT_USER_ID = 'default';/*** The Composio API client.@@ -81,22 +66,6 @@ export class Composio<// connected accountsconnectedAccounts: ConnectedAccounts;createConnectedAccount: ConnectedAccounts['createConnectedAccount'];- // global modifiers- modifiers: Modifiers;- useBeforeToolExecute: Modifiers['useBeforeToolExecute'];- useAfterToolExecute: Modifiers['useAfterToolExecute'];- useTransformToolSchema: Modifiers['useTransformToolSchema'];- // toolset modifiers- getToolBySlug!: <T extends TToolset>(- slug: string,- modifiers?: ToolsetModifierType<T>- ) => Promise<ReturnType<T['getToolBySlug']>>;- getTools!: <T extends TToolset>(- params?: ToolListParams,- modifiers?: ToolsetModifierType<T>- ) => Promise<ReturnType<T['getTools']>>;- // getToolBySlug: TToolset['getToolBySlug'];- // getTools: TToolset['getTools'];/*** @param {Object} config Configuration for the Composio SDK.@@ -151,34 +120,10 @@ export class Composio<*/this.toolset = (config.toolset ?? new OpenAIToolset()) as TToolset;this.toolset.setComposio(this);-- this.getToolBySlug = (async <T extends TToolset>(- slug: string,- modifiers?: ToolsetModifierType<T>- ) => {- return this.toolset.getToolBySlug(slug, modifiers as ToolsetModifierType<TToolset>);- }) as typeof this.getToolBySlug;-- this.getTools = (async <T extends TToolset>(- params?: ToolListParams,- modifiers?: ToolsetModifierType<T>- ) => {- return this.toolset.getTools(params, modifiers as ToolsetModifierType<TToolset>);- }) as typeof this.getTools;-- /**- * 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.modifiers);+ this.tools = new Tools(this.client);this.toolkits = new Toolkits(this.client);this.triggers = new Triggers(this.client);this.authConfigs = new AuthConfigs(this.client);@@ -221,7 +166,6 @@ export class Composio<*/this.telemetry.instrumentTelemetry(this);this.telemetry.instrumentTelemetry(this.tools);- this.telemetry.instrumentTelemetry(this.modifiers);this.telemetry.instrumentTelemetry(this.toolkits);this.telemetry.instrumentTelemetry(this.triggers);this.telemetry.instrumentTelemetry(this.authConfigs);@@ -248,4 +192,30 @@ export class Composio<}return this.client;}++ /**+ * Fetch all the tools from Composio.+ * @param {ToolListParams} params Parameters to fetch the tools.+ * @param {ToolsetModifierType<TToolset>} modifiers Modifiers to apply to the tools.+ * @returns {Promise<ReturnType<TToolset['getTools']>>} The tools from the toolset.+ */+ getTools<T extends TToolset>(+ params?: ToolListParams,+ modifiers?: ToolsetModifierType<T>+ ): Promise<ReturnType<T['getTools']>> {+ return this.toolset.getTools(params, modifiers) as Promise<ReturnType<T['getTools']>>;+ }++ /**+ * Fetch a tool from Composio by its slug.+ * @param {string} slug slug of the tool+ * @param {ToolsetModifierType<TToolset>} modifiers to be applied to the tool+ * @returns {Promise<ReturnType<TToolset['getToolBySlug']>>} The tool from the toolset.+ */+ getToolBySlug<T extends TToolset>(+ slug: string,+ modifiers?: ToolsetModifierType<T>+ ): Promise<ReturnType<T['getToolBySlug']>> {+ return this.toolset.getToolBySlug(slug, modifiers) as Promise<ReturnType<T['getToolBySlug']>>;+ }}diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex f07ea2964..e15b4f549 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -7,11 +7,10 @@ export { BaseTelemetryTransport } from './telemetry/TelemetryTransport';export { jsonSchemaToModel } from './utils/jsonSchema';export { Tool, ToolListParams, ToolListParamsSchema } from './types/tool.types';export { Toolset } from './types/toolset.types';-// Type exportsexport type {ModifiersParams,TransformToolSchemaModifier,- BeforeToolExecuteModifer,+ BeforeToolExecuteModifier,AfterToolExecuteModifier,} from './types/modifiers.types';diff --git a/packages/core/src/models/Modifiers.ts b/packages/core/src/models/Modifiers.tsdeleted file mode 100644index 55d27db2d..000000000--- a/packages/core/src/models/Modifiers.ts+++ /dev/null@@ -1,193 +0,0 @@-/**- * @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,- GlobalAfterToolExecuteModifier,- GlobalBeforeToolExecuteModifier,- GlobalTransformToolSchemaModifier,- TransformToolSchemaModifier,-} from '../types/modifiers.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 {- private beforeToolExecuteModifiers: Map<string, Set<BeforeToolExecuteModifer>> = new Map();- private globalBeforeToolExecuteModifiers: Set<GlobalBeforeToolExecuteModifier> = new Set();- private afterToolExecuteModifiers: Map<string, Set<AfterToolExecuteModifier>> = new Map();- private globalAfterToolExecuteModifiers: Set<GlobalAfterToolExecuteModifier> = new Set();- private transformToolSchemaModifiers: Map<string, Set<TransformToolSchemaModifier>> = new Map();- private globalTransformToolSchemaModifiers: Set<GlobalTransformToolSchemaModifier> = new Set();-- constructor() {}-- /**- * Function signature for modifying the tool execution parameters.- * We support two ways to register modifiers:- * 1. useBeforeToolExecute(globalModifier: GlobalBeforeToolExecuteModifier): void- * 2. useBeforeToolExecute(toolSlug: string, modifier: BeforeToolExecuteModifer): void- */- useBeforeToolExecute(globalModifier: GlobalBeforeToolExecuteModifier): void;- useBeforeToolExecute(toolSlug: string, modifier: BeforeToolExecuteModifer): void;- /**- * Method to modify the tool schema before it is executed.- * We provide two methods to register modifiers:- * 1. useBeforeToolExecute(modifier: GlobalBeforeToolExecuteModifier): void- * 2. useBeforeToolExecute(toolSlug: string, modifier: BeforeToolExecuteModifer): void- * @param {string} toolSlug slug of the tool to be modified- * @param modifier function to modify the tool execution parameters- */- useBeforeToolExecute(- arg1: string | GlobalBeforeToolExecuteModifier,- modifier?: BeforeToolExecuteModifer- ): void {- if (typeof arg1 === 'string' && modifier) {- const toolSlug = arg1;- if (!this.beforeToolExecuteModifiers.has(toolSlug)) {- this.beforeToolExecuteModifiers.set(toolSlug, new Set());- }- this.beforeToolExecuteModifiers.get(toolSlug)?.add(modifier);- } else if (typeof arg1 === 'function') {- const globalModifier = arg1;- this.globalBeforeToolExecuteModifiers.add(globalModifier);- }- }-- /**- * 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 {- // Apply global modifiers- let modifiedToolExecuteParams = { ...toolExecuteParams };- for (const globalModifier of this.globalBeforeToolExecuteModifiers) {- modifiedToolExecuteParams = globalModifier(toolSlug, modifiedToolExecuteParams);- }- // Apply tool-specific modifiers- const modifiers = this.beforeToolExecuteModifiers.get(toolSlug);- if (modifiers) {- for (const modifier of modifiers) {- modifiedToolExecuteParams = modifier(modifiedToolExecuteParams);- }- }- return modifiedToolExecuteParams;- }-- /**- * Function signature for modifying the tool execution response.- */- useAfterToolExecute(globalModifier: GlobalAfterToolExecuteModifier): void;- useAfterToolExecute(toolSlug: string, modifier: AfterToolExecuteModifier): void;-- /**- * 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(- arg1: string | GlobalAfterToolExecuteModifier,- modifier?: AfterToolExecuteModifier- ) {- if (typeof arg1 === 'string' && modifier) {- const toolSlug = arg1;- if (!this.afterToolExecuteModifiers.has(toolSlug)) {- this.afterToolExecuteModifiers.set(toolSlug, new Set());- }- this.afterToolExecuteModifiers.get(toolSlug)?.add(modifier);- } else if (typeof arg1 === 'function') {- const globalModifier = arg1;- this.globalAfterToolExecuteModifiers.add(globalModifier);- }- }-- /**- * 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 {- // Apply global modifiers- let modifiedToolExecuteResponse = { ...toolExecuteResponse };- for (const globalModifier of this.globalAfterToolExecuteModifiers) {- modifiedToolExecuteResponse = globalModifier(toolSlug, modifiedToolExecuteResponse);- }- // Apply tool-specific modifiers- const modifiers = this.afterToolExecuteModifiers.get(toolSlug);- if (modifiers) {- for (const modifier of modifiers) {- modifiedToolExecuteResponse = modifier(modifiedToolExecuteResponse);- }- }- return modifiedToolExecuteResponse;- }-- /**- * Function signatures for modifying the tool schema.- * We support two ways to register modifiers:- * 1. useTransformToolSchema(globalModifier: GlobalTransformToolSchemaModifier): void- * 2. useTransformToolSchema(toolSlug: string, modifier: TransformToolSchemaModifier): void- */- useTransformToolSchema(globalModifier: GlobalTransformToolSchemaModifier): void;- useTransformToolSchema(toolSlug: string, modifier: TransformToolSchemaModifier): void;- /**- * 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(- arg1: string | GlobalTransformToolSchemaModifier,- modifier?: TransformToolSchemaModifier- ) {- if (typeof arg1 === 'string' && modifier) {- const toolSlug = arg1;- if (!this.transformToolSchemaModifiers.has(toolSlug)) {- this.transformToolSchemaModifiers.set(toolSlug, new Set());- }- this.transformToolSchemaModifiers.get(toolSlug)?.add(modifier);- } else if (typeof arg1 === 'function') {- const globalModifier = arg1;- this.globalTransformToolSchemaModifiers.add(globalModifier);- }- }-- /**- * 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 {- // Apply global modifiers- let modifiedToolSchema = { ...toolSchema };- for (const globalModifier of this.globalTransformToolSchemaModifiers) {- modifiedToolSchema = globalModifier(toolSlug, modifiedToolSchema);- }- // Apply tool-specific modifiers- const modifiers = this.transformToolSchemaModifiers.get(toolSlug);- if (modifiers) {- for (const modifier of modifiers) {- modifiedToolSchema = modifier(modifiedToolSchema);- }- }- return modifiedToolSchema;- }-}diff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.tsindex 570857cb1..d0023db92 100644--- a/packages/core/src/models/Tools.ts+++ b/packages/core/src/models/Tools.ts@@ -6,6 +6,7 @@ import {ToolExecuteResponse,ToolList,ToolSchema,+ ToolExecuteResponseSchema,} from '../types/tool.types';import {ToolGetInputParams,@@ -16,14 +17,11 @@ import {ToolRetrieveEnumResponse,ToolRetrieveResponse,ToolListResponse as ComposioToolListResponse,+ ToolExecuteResponse as ComposioToolExecuteResponse,} from '@composio/client/resources/tools';-import { Modifiers } from './Modifiers';import { CustomTools } from './CustomTools';import { CustomToolOptions } from '../types/customTool.types';-import {- ExecuteToolModifiersParams,- GlobalTransformToolSchemaModifier,-} from '../types/modifiers.types';+import { ExecuteToolModifiersParams, TransformToolSchemaModifier } from '../types/modifiers.types';/*** This class is used to manage tools in the Composio SDK.@@ -31,12 +29,10 @@ import {*/export class Tools {private client: ComposioClient;- private modifiers: Modifiers;- private customTools: CustomTools;+ customTools: CustomTools;- constructor(client: ComposioClient, modifiers: Modifiers) {+ constructor(client: ComposioClient) {this.client = client;- this.modifiers = modifiers || new Modifiers();this.customTools = new CustomTools(client);}@@ -50,6 +46,16 @@ export class Tools {});}+ private transformToolExecuteResponse(response: ComposioToolExecuteResponse): ToolExecuteResponse {+ return ToolExecuteResponseSchema.parse({+ data: response.data,+ error: response.error,+ successful: response.successful,+ logId: response.log_id,+ sessionInfo: response.session_info,+ });+ }+/*** Lists all tools available in the Composio SDK as well as custom tools.* This method fetches the tools from the Composio API and wraps them using the toolset.@@ -57,7 +63,7 @@ export class Tools {*/async getTools(query: ToolListParams = {},- modifier?: GlobalTransformToolSchemaModifier+ modifier?: TransformToolSchemaModifier): Promise<ToolList> {const queryParams = ToolListParamsSchema.safeParse(query);if (queryParams.error) {@@ -79,18 +85,7 @@ export class Tools {toolSlugs: queryParams.data.toolSlugs,});- const composioToolList = [- ...tools.items.map(tool => this.transformToolCases(tool)),- ...customTools,- ];-- let modifiedTools = composioToolList.map(tool => {- return this.modifiers.applyTransformToolSchema(tool.slug, {- ...tool,- inputParameters: tool.inputParameters,- outputParameters: tool.outputParameters,- });- });+ let modifiedTools = [...tools.items.map(tool => this.transformToolCases(tool)), ...customTools];// apply local modifiers if they are providedif (modifier) {@@ -111,7 +106,7 @@ export class Tools {* @param slug The ID of the tool to be retrieved* @returns {Promise<Tool>} The tool*/- async getToolBySlug(slug: string, modifier?: GlobalTransformToolSchemaModifier): Promise<Tool> {+ async getToolBySlug(slug: string, modifier?: TransformToolSchemaModifier): Promise<Tool> {// check if the tool is a custom toolconst customTool = await this.customTools.getCustomToolBySlug(slug);if (customTool) {@@ -123,18 +118,16 @@ export class Tools {throw new Error(`Tool with slug ${slug} not found`);}// change the case of the tool to camel case- const casedTool = this.transformToolCases(tool);- // apply the global modifiers- let modifiedTool = this.modifiers.applyTransformToolSchema(slug, casedTool);+ let modifiedToool = this.transformToolCases(tool);// apply local modifiers if they are providedif (modifier) {if (typeof modifier === 'function') {- modifiedTool = modifier(slug, modifiedTool);+ modifiedToool = modifier(slug, modifiedToool);} else {throw new Error('Invalid schema modifier. Not a function.');}}- return modifiedTool;+ return modifiedToool;}/**@@ -151,35 +144,26 @@ export class Tools {body: ToolExecuteParams,modifiers?: ExecuteToolModifiersParams): Promise<ToolExecuteResponse> {- // before tool execute modifier, apply all the global modifiers- let modifiedBody = this.modifiers.applyBeforeToolExecute(slug, body);-// apply local modifiers if they are providedif (modifiers && modifiers.beforeToolExecute) {if (typeof modifiers.beforeToolExecute === 'function') {- modifiedBody = modifiers.beforeToolExecute(slug, modifiedBody);+ body = modifiers.beforeToolExecute(slug, body);} else {throw new Error('Invalid beforeToolExecute modifier. Not a function.');}}let result = await this.client.tools.execute(slug, {- allow_tracing: modifiedBody.allowTracing,- connected_account_id: modifiedBody.connectedAccountId,- custom_auth_params: modifiedBody.customAuthParams,- arguments: modifiedBody.arguments,- entity_id: modifiedBody.userId,- version: modifiedBody.version,- text: modifiedBody.text,- });- // apply gloafter tool execute modifier- result = this.modifiers.applyAfterToolExecute(slug, {- data: result.data,- error: result.error,- successful: result.successful,- logId: result.log_id,- sessionInfo: result.session_info,+ allow_tracing: body.allowTracing,+ connected_account_id: body.connectedAccountId,+ custom_auth_params: body.customAuthParams,+ arguments: body.arguments,+ entity_id: body.userId,+ version: body.version,+ text: body.text,});+ // apply transformations to the response+ result = this.transformToolExecuteResponse(result);// apply local modifiers if they are providedif (modifiers && modifiers.afterToolExecute) {diff --git a/packages/core/src/toolset/BaseToolset.ts b/packages/core/src/toolset/BaseToolset.tsindex 5e3314818..d696a018f 100644--- a/packages/core/src/toolset/BaseToolset.ts+++ b/packages/core/src/toolset/BaseToolset.ts@@ -25,7 +25,7 @@ export abstract class BaseNonAgenticToolset<TToolCollection, TTool>abstract getToolBySlug(slug: string, modifiers?: Pick<ModifiersParams, 'schema'>): Promise<TTool>;- abstract _wrapTool(tool: Tool): TTool;+ abstract wrapTool(tool: Tool): TTool;protected getComposio(): Composio<BaseComposioToolset<TToolCollection, TTool>> {if (!this.composio) {@@ -56,7 +56,7 @@ export abstract class BaseAgenticToolset<TToolCollection, TTool>abstract getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<TTool>;- abstract _wrapTool(tool: Tool): TTool;+ abstract wrapTool(tool: Tool): TTool;protected getComposio(): Composio<BaseComposioToolset<TToolCollection, TTool>> {if (!this.composio) {diff --git a/packages/core/src/toolset/ComposioToolset.ts b/packages/core/src/toolset/ComposioToolset.tsindex cc1221640..0d83436c7 100644--- a/packages/core/src/toolset/ComposioToolset.ts+++ b/packages/core/src/toolset/ComposioToolset.ts@@ -19,13 +19,13 @@ export class ComposioToolset extends BaseNonAgenticToolset<Array<CustomTool>, Cusuper();}- _wrapTool = (tool: Tool): CustomTool => {+ wrapTool = (tool: Tool): CustomTool => {return tool as CustomTool;};async getTools(params?: ToolListParams): Promise<Array<CustomTool>> {const tools = await this.getComposio().tools.getTools(params);- return tools?.map(tool => this._wrapTool(tool as Tool)) ?? [];+ return tools?.map(tool => this.wrapTool(tool as Tool)) ?? [];}async getToolBySlug(@@ -33,7 +33,7 @@ export class ComposioToolset extends BaseNonAgenticToolset<Array<CustomTool>, Cumodifiers?: Pick<ModifiersParams, 'schema'>): Promise<CustomTool> {const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);- return this._wrapTool(tool as Tool);+ return this.wrapTool(tool as Tool);}async test() {}diff --git a/packages/core/src/toolset/OpenAIToolset.ts b/packages/core/src/toolset/OpenAIToolset.tsindex 8c0e56877..351bdc5a1 100644--- a/packages/core/src/toolset/OpenAIToolset.ts+++ b/packages/core/src/toolset/OpenAIToolset.ts@@ -12,7 +12,11 @@ import { Stream } from 'openai/streaming';import { BaseNonAgenticToolset } from './BaseToolset';import { Tool, ToolListParams } from '../types/tool.types';import logger from '../utils/logger';-import { ExecuteToolModifiersParams, ModifiersParams } from '../types/modifiers.types';+import {+ ExecuteToolModifiersParams,+ ModifiersParams,+ SchemaModifiersParams,+} from '../types/modifiers.types';export type OpenAiTool = OpenAI.ChatCompletionTool;export type OpenAiToolCollection = Array<OpenAiTool>;@@ -23,7 +27,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O* @param tool - The tool to wrap.* @returns The wrapped tool.*/- override _wrapTool = (tool: Tool): OpenAiTool => {+ override wrapTool = (tool: Tool): OpenAiTool => {const formattedSchema: OpenAI.FunctionDefinition = {name: tool.slug,description: tool.description,@@ -43,18 +47,15 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O*/async getTools(params?: ToolListParams,- modifiers?: Pick<ModifiersParams, 'schema'>+ modifiers?: SchemaModifiersParams): Promise<OpenAiToolCollection> {const tools = await this.getComposio()?.tools.getTools(params, modifiers?.schema);- return tools?.map(tool => this._wrapTool(tool as Tool)) ?? [];+ return tools?.map(tool => this.wrapTool(tool as Tool)) ?? [];}- async getToolBySlug(- slug: string,- modifiers?: Pick<ModifiersParams, 'schema'>- ): Promise<OpenAiTool> {+ async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<OpenAiTool> {const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);- return this._wrapTool(tool);+ return this.wrapTool(tool);}/**diff --git a/packages/core/src/types/modifiers.types.ts b/packages/core/src/types/modifiers.types.tsindex b73d08789..0e4b06ecb 100644--- a/packages/core/src/types/modifiers.types.ts+++ b/packages/core/src/types/modifiers.types.ts@@ -1,33 +1,56 @@+import { BaseAgenticToolset, BaseComposioToolset } from '../toolset/BaseToolset';import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';-export type BeforeToolExecuteModifer = (toolExecuteParams: ToolExecuteParams) => ToolExecuteParams;-export type GlobalBeforeToolExecuteModifier = (+/**+ * Modifier for altering the tool execute params+ * Called before the tool execute call+ */+export type BeforeToolExecuteModifier = (toolSlug: string,toolExecuteParams: ToolExecuteParams) => ToolExecuteParams;++/**+ * Modifier for altering the tool execute response+ * Called after the tool execute call+ */export type AfterToolExecuteModifier = (- toolExecuteResponse: ToolExecuteResponse-) => ToolExecuteResponse;-export type GlobalAfterToolExecuteModifier = (toolSlug: string,toolExecuteResponse: ToolExecuteResponse) => ToolExecuteResponse;-export type TransformToolSchemaModifier = (toolSchemModifier: Tool) => Tool;-export type GlobalTransformToolSchemaModifier = (toolSlug: string, toolSchema: Tool) => Tool;+/**+ * Modifier for altering the tool schema+ * Called after the tool schema is retrieved+ */+export type TransformToolSchemaModifier = (toolSlug: string, toolSchema: Tool) => Tool;++/**+ * Modifiers for the toolset+ * This is used by Agentic toolsets+ */export type ModifiersParams = {- beforeToolExecute?: GlobalBeforeToolExecuteModifier;- afterToolExecute?: GlobalAfterToolExecuteModifier;- schema?: GlobalTransformToolSchemaModifier;+ beforeToolExecute?: BeforeToolExecuteModifier;+ afterToolExecute?: AfterToolExecuteModifier;+ schema?: TransformToolSchemaModifier;};-export type ExecuteToolModifiersParams = {- beforeToolExecute?: GlobalBeforeToolExecuteModifier;- afterToolExecute?: GlobalAfterToolExecuteModifier;+/**+ * Modifiers for the tool schema+ * This is used by Non-Agentic toolsets+ */+export type SchemaModifiersParams = {+ schema?: TransformToolSchemaModifier;};-export type SingleToolModifiersParams = {- beforeToolExecute?: BeforeToolExecuteModifer;+/**+ * Modifiers for the tool execution+ * This is used by execute call and handleToolCall of Non-Agentic toolsets+ */+export type ExecuteToolModifiersParams = {+ beforeToolExecute?: BeforeToolExecuteModifier;afterToolExecute?: AfterToolExecuteModifier;- schema?: TransformToolSchemaModifier;};++export type ToolsetModifierType<T extends BaseComposioToolset<unknown, unknown>> =+ T extends BaseAgenticToolset<unknown, unknown> ? ModifiersParams : SchemaModifiersParams;diff --git a/packages/core/src/types/toolset.types.ts b/packages/core/src/types/toolset.types.tsindex 9decbeeef..062132179 100644--- a/packages/core/src/types/toolset.types.ts+++ b/packages/core/src/types/toolset.types.ts@@ -1,3 +1,4 @@+import { Composio } from '../composio';import { Tool, ToolListParams } from './tool.types';/**@@ -5,8 +6,8 @@ import { Tool, ToolListParams } from './tool.types';* This class is used to create a base toolset by implementing this class.* This class also extends InstrumentedInstance, so that the telemetry can be instrumented for the toolset.*/-export interface Toolset<TTool = Tool, TToolCollection = TTool[]> {- _wrapTool: (tool: Tool) => TTool;+export interface Toolset<TTool, TToolCollection> {+ wrapTool: (tool: Tool) => TTool;getTools: (params?: ToolListParams) => Promise<TToolCollection>;}diff --git a/packages/toolsets/cloudflare/src/index.ts b/packages/toolsets/cloudflare/src/index.tsindex 40d66c270..85c9badeb 100644--- a/packages/toolsets/cloudflare/src/index.ts+++ b/packages/toolsets/cloudflare/src/index.ts@@ -13,7 +13,7 @@ import { AiTextGenerationToolInput } from '@cloudflare/workers-types';import { BaseNonAgenticToolset, Tool, ToolListParams } from '@composio/core';import {ExecuteToolModifiersParams,- ModifiersParams,+ SchemaModifiersParams,} from 'packages/core/src/types/modifiers.types';type AiToolCollection = Record<string, AiTextGenerationToolInput>;@@ -28,7 +28,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<* @param tool - The tool to wrap.* @returns The wrapped tool.*/- _wrapTool(tool: Tool): AiTextGenerationToolInput {+ wrapTool(tool: Tool): AiTextGenerationToolInput {const formattedSchema: AiTextGenerationToolInput['function'] = {name: tool.slug!,description: tool.description!,@@ -57,7 +57,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<*/override async getTools(query?: ToolListParams,- modifiers?: Pick<ModifiersParams, 'schema'>+ modifiers?: SchemaModifiersParams): Promise<AiToolCollection> {if (!this.getComposio()) {throw new Error('Client not set');@@ -67,7 +67,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<return tools.reduce((tools, tool) => ({...tools,- [tool.slug]: this._wrapTool(tool),+ [tool.slug]: this.wrapTool(tool),}),{});@@ -75,13 +75,13 @@ export class CloudflareToolset extends BaseNonAgenticToolset<override async getToolBySlug(slug: string,- modifiers?: Pick<ModifiersParams, 'schema'>+ modifiers?: SchemaModifiersParams): Promise<AiTextGenerationToolInput> {if (!this.getComposio()) {throw new Error('Client not set');}const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);- return this._wrapTool(tool);+ return this.wrapTool(tool);}/**diff --git a/packages/toolsets/cloudflare/tsconfig.json b/packages/toolsets/cloudflare/tsconfig.jsonindex 70ad99946..a05651a3a 100644--- a/packages/toolsets/cloudflare/tsconfig.json+++ b/packages/toolsets/cloudflare/tsconfig.json@@ -9,7 +9,8 @@"strict": true,"esModuleInterop": true,"moduleResolution": "node",- "skipLibCheck": true+ "skipLibCheck": true,+ "resolveJsonModule": true},"include": ["src"]}diff --git a/packages/toolsets/langchain/src/index.ts b/packages/toolsets/langchain/src/index.tsindex e3443ff2b..2eae4f0ce 100644--- a/packages/toolsets/langchain/src/index.ts+++ b/packages/toolsets/langchain/src/index.ts@@ -24,7 +24,7 @@ export class LangchainToolset extends BaseAgenticToolset<* @param tool - The tool to wrap.* @returns The wrapped tool.*/- _wrapTool(tool: Tool, modifiers?: ModifiersParams): DynamicStructuredTool {+ wrapTool(tool: Tool, modifiers?: ModifiersParams): DynamicStructuredTool {const toolName = tool.slug;const description = tool.description;const appName = tool.toolkit?.name?.toLowerCase();@@ -71,7 +71,7 @@ export class LangchainToolset extends BaseAgenticToolset<modifiers?: ModifiersParams): Promise<LangChainToolCollection> {const tools = await this.getComposio()?.tools.getTools(params, modifiers?.schema);- return tools?.map(tool => this._wrapTool(tool, modifiers)) ?? [];+ return tools?.map(tool => this.wrapTool(tool, modifiers)) ?? [];}override async getToolBySlug(@@ -79,6 +79,6 @@ export class LangchainToolset extends BaseAgenticToolset<modifiers?: ModifiersParams): Promise<DynamicStructuredTool> {const tool = await this.getComposio()?.tools.getToolBySlug(slug, modifiers?.schema);- return this._wrapTool(tool as Tool, modifiers);+ return this.wrapTool(tool as Tool, modifiers);}}diff --git a/packages/toolsets/langchain/tsconfig.json b/packages/toolsets/langchain/tsconfig.jsonindex 70ad99946..a05651a3a 100644--- a/packages/toolsets/langchain/tsconfig.json+++ b/packages/toolsets/langchain/tsconfig.json@@ -9,7 +9,8 @@"strict": true,"esModuleInterop": true,"moduleResolution": "node",- "skipLibCheck": true+ "skipLibCheck": true,+ "resolveJsonModule": true},"include": ["src"]}diff --git a/packages/toolsets/vercel/src/index.ts b/packages/toolsets/vercel/src/index.tsindex e0354133b..fcebcb793 100644--- a/packages/toolsets/vercel/src/index.ts+++ b/packages/toolsets/vercel/src/index.ts@@ -39,7 +39,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Vercreturn tools.reduce((tools, tool) => ({...tools,- [tool.slug]: this._wrapTool(tool as ComposioTool, modifiers),+ [tool.slug]: this.wrapTool(tool as ComposioTool, modifiers),}),{});@@ -47,7 +47,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Vercoverride async getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<VercelTool> {const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);- return this._wrapTool(tool as ComposioTool, modifiers);+ return this.wrapTool(tool as ComposioTool, modifiers);}/**@@ -82,7 +82,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Vercreturn JSON.stringify(results);}- _wrapTool(composioTool: ComposioTool, modifiers?: ExecuteToolModifiersParams): VercelTool {+ wrapTool(composioTool: ComposioTool, modifiers?: ExecuteToolModifiersParams): VercelTool {return tool({description: composioTool.description,parameters: jsonSchema(composioTool.inputParameters ?? {}),diff --git a/packages/toolsets/vercel/tsconfig.json b/packages/toolsets/vercel/tsconfig.jsonindex 70ad99946..a05651a3a 100644--- a/packages/toolsets/vercel/tsconfig.json+++ b/packages/toolsets/vercel/tsconfig.json@@ -9,7 +9,8 @@"strict": true,"esModuleInterop": true,"moduleResolution": "node",- "skipLibCheck": true+ "skipLibCheck": true,+ "resolveJsonModule": true},"include": ["src"]}