@devries-cameron20 / composio-1 / commits / 24f1b70f2
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Rename modifiers

haxzie committed May 21, 2025 at 17:26 UTC 24f1b70f29edeeb0f58dfa94468f963f66066878
20 files changed +195 -192
docs/advanced/modifiers.md
+19 -19
@@ -22,7 +22,7 @@ const tools = await composio.tools.get(
22 toolkits: ['github'],
23 },
24 {
25 - modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
25 + modifySchema: (toolSlug, toolkitSlug, tool) => {
26 // Add a prefix to all tool descriptions
27 if (tool.description) {
28 tool.description = `[Enhanced] ${tool.description}`;
@@ -59,7 +59,7 @@ const result = await composio.tools.execute(
59 },
60 },
61 {
62 - beforeToolExecute: (toolSlug, toolkitSlug, params) => {
62 + beforeExecute: (toolSlug, toolkitSlug, params) => {
63 // Convert owner names to lowercase
64 if (params.arguments.owner) {
65 params.arguments.owner = params.arguments.owner.toLowerCase();
@@ -95,7 +95,7 @@ const result = await composio.tools.execute(
95 },
96 },
97 {
98 - afterToolExecute: (toolSlug, toolkitSlug, result) => {
98 + afterExecute: (toolSlug, toolkitSlug, result) => {
99 // Only when execution was successful
100 if (result.successful) {
101 // Filter out sensitive data
@@ -131,19 +131,19 @@ const tools = await composio.tools.get(
131 },
132 {
133 // Schema modifier
134 - modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
134 + modifySchema: (toolSlug, toolkitSlug, tool) => {
135 // Enhance tool schema
136 return tool;
137 },
138
139 // Before execution modifier
140 - beforeToolExecute: (toolSlug, toolkitSlug, params) => {
140 + beforeExecute: (toolSlug, toolkitSlug, params) => {
141 // Modify execution parameters
142 return params;
143 },
144
145 // After execution modifier
146 - afterToolExecute: (toolSlug, toolkitSlug, result) => {
146 + afterExecute: (toolSlug, toolkitSlug, result) => {
147 // Transform execution results
148 return result;
149 },
@@ -192,8 +192,8 @@ const result = await composio.tools.execute(
192 },
193 },
194 {
195 - beforeToolExecute: sanitizeInputs,
196 - afterToolExecute: addTimestamps,
195 + beforeExecute: sanitizeInputs,
196 + afterExecute: addTimestamps,
197 }
198 );
199 ```
@@ -253,8 +253,8 @@ try {
253 },
254 },
255 {
256 - beforeToolExecute: cacheModifier,
257 - afterToolExecute: cacheAfterModifier,
256 + beforeExecute: cacheModifier,
257 + afterExecute: cacheAfterModifier,
258 }
259 );
260
@@ -300,7 +300,7 @@ const tools = await composio.tools.get(
300 toolkits: ['custom-api'],
301 },
302 {
303 - beforeToolExecute: authModifier,
303 + beforeExecute: authModifier,
304 }
305 );
306 ```
@@ -362,7 +362,7 @@ const result = await composio.tools.execute(
362 },
363 },
364 {
365 - afterToolExecute: pipeModifiers(addMetadata, formatDates, removeNulls),
365 + afterExecute: pipeModifiers(addMetadata, formatDates, removeNulls),
366 }
367 );
368 ```
@@ -374,14 +374,14 @@ const result = await composio.tools.execute(
374 type TransformToolSchemaModifier = (toolSlug: string, toolkitSlug: string, tool: Tool) => Tool;
375
376 // Before Execution Modifier
377 -type BeforeToolExecuteModifier = (
377 +type beforeExecuteModifier = (
378 toolSlug: string,
379 toolkitSlug: string,
380 params: ToolExecuteParams
381 ) => ToolExecuteParams;
382
383 // After Execution Modifier
384 -type AfterToolExecuteModifier = (
384 +type afterExecuteModifier = (
385 toolSlug: string,
386 toolkitSlug: string,
387 result: ToolExecuteResponse
@@ -389,14 +389,14 @@ type AfterToolExecuteModifier = (
389
390 // Modifiers Object
391 interface ExecuteToolModifiers {
392 - beforeToolExecute?: BeforeToolExecuteModifier;
393 - afterToolExecute?: AfterToolExecuteModifier;
392 + beforeExecute?: beforeExecuteModifier;
393 + afterExecute?: afterExecuteModifier;
394 }
395
396 // Provider Options (includes schema modifier)
397 interface ProviderOptions<TProvider> {
398 - modifyToolSchema?: TransformToolSchemaModifier;
399 - beforeToolExecute?: BeforeToolExecuteModifier;
400 - afterToolExecute?: AfterToolExecuteModifier;
398 + modifySchema?: TransformToolSchemaModifier;
399 + beforeExecute?: beforeExecuteModifier;
400 + afterExecute?: afterExecuteModifier;
401 }
402 ```
docs/api/providers.md
+8 -8
@@ -102,8 +102,8 @@ const result = await openaiProvider.executeToolCall(
102 toolCall,
103 { connectedAccountId: 'conn_abc123' },
104 {
105 - beforeToolExecute: (toolSlug, toolkitSlug, params) => params,
106 - afterToolExecute: (toolSlug, toolkitSlug, result) => result,
105 + beforeExecute: (toolSlug, toolkitSlug, params) => params,
106 + afterExecute: (toolSlug, toolkitSlug, result) => result,
107 }
108 );
109 ```
@@ -262,8 +262,8 @@ interface ExecuteToolFnOptions {
262
263 ```typescript
264 interface ExecuteToolModifiers {
265 - beforeToolExecute?: BeforeToolExecuteModifier;
266 - afterToolExecute?: AfterToolExecuteModifier;
265 + beforeExecute?: beforeExecuteModifier;
266 + afterExecute?: afterExecuteModifier;
267 }
268 ```
269
@@ -273,20 +273,20 @@ interface ExecuteToolModifiers {
273 type TransformToolSchemaModifier = (toolSlug: string, toolkitSlug: string, tool: Tool) => Tool;
274 ```
275
276 -### BeforeToolExecuteModifier
276 +### beforeExecuteModifier
277
278 ```typescript
279 -type BeforeToolExecuteModifier = (
279 +type beforeExecuteModifier = (
280 toolSlug: string,
281 toolkitSlug: string,
282 params: ToolExecuteParams
283 ) => ToolExecuteParams;
284 ```
285
286 -### AfterToolExecuteModifier
286 +### afterExecuteModifier
287
288 ```typescript
289 -type AfterToolExecuteModifier = (
289 +type afterExecuteModifier = (
290 toolSlug: string,
291 toolkitSlug: string,
292 result: ToolExecuteResponse
docs/api/tools.md
+52 -45
@@ -12,13 +12,13 @@ Retrieves tools based on the provided filters.
12 // Get tools from a specific toolkit
13 const githubTools = await composio.tools.get('default', {
14 toolkits: ['github'],
15 - limit: 10
15 + limit: 10,
16 });
17
18 // Get tools with search
19 const searchTools = await composio.tools.get('default', {
20 search: 'user',
21 - important: true
21 + important: true,
22 });
23
24 // Get a specific tool by slug
@@ -26,10 +26,10 @@ const tool = await composio.tools.get('default', 'GITHUB_GET_REPO');
26
27 // Get a tool with schema modifications
28 const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
29 - modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
29 + modifySchema: (toolSlug, toolkitSlug, schema) => {
30 // Customize the tool schema
31 - return {...schema, description: 'Custom description'};
32 - }
31 + return { ...schema, description: 'Custom description' };
32 + },
33 });
34 ```
35
@@ -49,23 +49,27 @@ Executes a given tool with the provided parameters.
49 // Execute a Composio API tool
50 const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
51 userId: 'default',
52 - arguments: { userId: 'pg' }
52 + arguments: { userId: 'pg' },
53 });
54
55 // Execute with modifiers
56 -const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
57 - userId: 'default',
58 - arguments: { owner: 'composio', repo: 'sdk' }
59 -}, {
60 - beforeToolExecute: (toolSlug, toolkitSlug, params) => {
61 - // Modify params before execution
62 - return params;
56 +const result = await composio.tools.execute(
57 + 'GITHUB_GET_ISSUES',
58 + {
59 + userId: 'default',
60 + arguments: { owner: 'composio', repo: 'sdk' },
61 },
64 - afterToolExecute: (toolSlug, toolkitSlug, result) => {
65 - // Transform result after execution
66 - return result;
62 + {
63 + beforeExecute: (toolSlug, toolkitSlug, params) => {
64 + // Modify params before execution
65 + return params;
66 + },
67 + afterExecute: (toolSlug, toolkitSlug, result) => {
68 + // Transform result after execution
69 + return result;
70 + },
71 }
68 -});
72 +);
73 ```
74
75 **Parameters:**
@@ -77,6 +81,7 @@ const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
81 **Returns:** Promise<ToolExecuteResponse> - The response from the tool execution
82
83 **Throws:**
84 +
85 - `ComposioCustomToolsNotInitializedError`: If the CustomTools instance is not initialized
86 - `ComposioToolNotFoundError`: If the tool with the given slug is not found
87 - `ComposioToolExecutionError`: If there is an error during tool execution
@@ -94,19 +99,19 @@ const customTool = await composio.tools.createCustomTool({
99 param1: {
100 type: 'string',
101 description: 'First parameter',
97 - required: true
98 - }
102 + required: true,
103 + },
104 },
105 outputParameters: {
106 result: {
107 type: 'string',
103 - description: 'The result of the operation'
104 - }
108 + description: 'The result of the operation',
109 + },
110 },
111 handler: async (params, context) => {
112 // Custom logic here
113 return { data: { result: 'Success!' } };
109 - }
114 + },
115 });
116 ```
117
@@ -127,14 +132,16 @@ const tools = await composio.tools.getRawComposioTools('default');
132 // Get tools with filters
133 const githubTools = await composio.tools.getRawComposioTools('default', {
134 toolkits: ['github'],
130 - important: true
135 + important: true,
136 });
137
138 // Get tools with schema transformation
134 -const tools = await composio.tools.getRawComposioTools('default', {},
139 +const tools = await composio.tools.getRawComposioTools(
140 + 'default',
141 + {},
142 (toolSlug, toolkitSlug, tool) => {
143 // Add custom properties to tool schema
137 - return {...tool, customProperty: 'value'};
144 + return { ...tool, customProperty: 'value' };
145 }
146 );
147 ```
@@ -169,12 +176,12 @@ const tool = await composio.tools.getRawComposioToolBySlug('default', 'github');
176
177 ```typescript
178 interface ToolListParams {
172 - tools?: string[]; // List of tool slugs to filter by
173 - cursor?: string; // Pagination cursor
174 - important?: string; // Filter for important tools
175 - limit?: string; // Limit the number of results
176 - search?: string; // Search term
177 - toolkits?: string[]; // List of toolkit slugs to filter by
179 + tools?: string[]; // List of tool slugs to filter by
180 + cursor?: string; // Pagination cursor
181 + important?: string; // Filter for important tools
182 + limit?: string; // Limit the number of results
183 + search?: string; // Search term
184 + toolkits?: string[]; // List of toolkit slugs to filter by
185 }
186 ```
187
@@ -182,13 +189,13 @@ interface ToolListParams {
189
190 ```typescript
191 interface ToolExecuteParams {
185 - allowTracing?: boolean; // Enable/disable tracing
186 - connectedAccountId?: string; // Connected account ID
192 + allowTracing?: boolean; // Enable/disable tracing
193 + connectedAccountId?: string; // Connected account ID
194 customAuthParams?: CustomAuthParams; // Custom auth parameters
195 arguments?: Record<string, unknown>; // Tool arguments
189 - userId: string; // User ID
190 - version?: string; // Tool version
191 - text?: string; // Text input
196 + userId: string; // User ID
197 + version?: string; // Tool version
198 + text?: string; // Text input
199 }
200 ```
201
@@ -196,11 +203,11 @@ interface ToolExecuteParams {
203
204 ```typescript
205 interface ToolExecuteResponse {
199 - data: Record<string, unknown>; // Tool execution data
200 - error: string | null; // Error message (if any)
201 - successful: boolean; // Whether the execution was successful
202 - logId?: string; // Log ID for debugging
203 - sessionInfo?: unknown; // Session information
206 + data: Record<string, unknown>; // Tool execution data
207 + error: string | null; // Error message (if any)
208 + successful: boolean; // Whether the execution was successful
209 + logId?: string; // Log ID for debugging
210 + sessionInfo?: unknown; // Session information
211 }
212 ```
213
@@ -208,11 +215,11 @@ interface ToolExecuteResponse {
215
216 ```typescript
217 interface CustomToolOptions {
211 - name: string; // Name of the custom tool
212 - description: string; // Description of the custom tool
213 - slug: string; // Unique slug for the custom tool
218 + name: string; // Name of the custom tool
219 + description: string; // Description of the custom tool
220 + slug: string; // Unique slug for the custom tool
221 inputParameters: Record<string, unknown>; // Input parameters schema
222 outputParameters?: Record<string, unknown>; // Output parameters schema
223 handler: (params: ToolExecuteParams, context: ExecuteMetadata) => Promise<ToolExecuteResponse>; // Handler function
224 }
218 -```
\ No newline at end of file
225 +```
docs/providers/openai.md
+3 -3
@@ -285,7 +285,7 @@ const tools = await composio.tools.get(
285 },
286 {
287 // Modify tool schema
288 - modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
288 + modifySchema: (toolSlug, toolkitSlug, tool) => {
289 // Make tool descriptions more concise for OpenAI
290 if (tool.description && tool.description.length > 100) {
291 tool.description = tool.description.substring(0, 100) + '...';
@@ -294,13 +294,13 @@ const tools = await composio.tools.get(
294 },
295
296 // Modify parameters before execution
297 - beforeToolExecute: (toolSlug, toolkitSlug, params) => {
297 + beforeExecute: (toolSlug, toolkitSlug, params) => {
298 console.log(`Executing ${toolSlug} tool`);
299 return params;
300 },
301
302 // Transform results after execution
303 - afterToolExecute: (toolSlug, toolkitSlug, result) => {
303 + afterExecute: (toolSlug, toolkitSlug, result) => {
304 // Format the result data for better presentation
305 if (result.successful && toolSlug === 'GITHUB_GET_REPO') {
306 result.data = {
examples/modifiers/src/index.ts
+4 -4
@@ -10,7 +10,7 @@ const composio = new Composio({
10
11 const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {
12 // toolkit slug too
13 - modifyToolSchema: (toolSlug, toolkitSlug, toolSchema) => {
13 + modifySchema: (toolSlug, toolkitSlug, toolSchema) => {
14 if (toolSlug === 'HACKERNEWS_GET_USER') {
15 toolSchema = {
16 ...toolSchema,
@@ -44,15 +44,15 @@ const agenticTools = await vercel.tools.get(
44 // what is the type error i am getting here?
45 { tools: ['HACKERNEWS_GET_USER'] },
46 {
47 - afterToolExecute: (toolSlug, toolkitSlug, result) => {
47 + afterExecute: (toolSlug, toolkitSlug, result) => {
48 // modify the result
49 return result;
50 },
51 - beforeToolExecute: (toolSlug, toolkitSlug, params) => {
51 + beforeExecute: (toolSlug, toolkitSlug, params) => {
52 // modify the params
53 return params;
54 },
55 - modifyToolSchema: (toolSlug, toolkitSlug, toolSchema) => {
55 + modifySchema: (toolSlug, toolkitSlug, toolSchema) => {
56 // modify the tool schema
57 return toolSchema;
58 },
packages/core/README.md
+3 -3
@@ -70,7 +70,7 @@ Schema modifiers allow you to transform tool schemas before they are used:
70
71 ```typescript
72 const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
73 - modifyToolSchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
73 + modifySchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
74 ...tool,
75 description: 'Enhanced HackerNews search with additional features',
76 inputParameters: {
@@ -92,7 +92,7 @@ For agentic providers (like Vercel AI and Langchain), you can also modify tool e
92 ```typescript
93 const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
94 // Transform input before execution
95 - beforeToolExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
95 + beforeExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
96 ...params,
97 arguments: {
98 ...params.arguments,
@@ -101,7 +101,7 @@ const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
101 }),
102
103 // Transform output after execution
104 - afterToolExecute: (toolSlug: string, toolkitSlug: string, response: ToolExecuteResponse) => ({
104 + afterExecute: (toolSlug: string, toolkitSlug: string, response: ToolExecuteResponse) => ({
105 ...response,
106 data: {
107 ...response.data,
packages/core/src/index.ts
+2 -2
@@ -18,6 +18,6 @@ export type {
18 AgenticToolOptions,
19 ToolOptions,
20 TransformToolSchemaModifier,
21 - BeforeToolExecuteModifier,
22 - AfterToolExecuteModifier,
21 + beforeExecuteModifier,
22 + afterExecuteModifier,
23 } from './types/modifiers.types';
packages/core/src/models/Tools.ts
+21 -29
@@ -385,7 +385,7 @@ export class Tools<
385 *
386 * // Get a tool with schema modifications
387 * const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
388 - * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
388 + * modifySchema: (toolSlug, toolkitSlug, schema) => {
389 * // Customize the tool schema
390 * return {...schema, description: 'Custom description'};
391 * }
@@ -416,11 +416,11 @@ export class Tools<
416 const executeToolFn = this.createExecuteToolFn(userId, options as ExecuteToolModifiers);
417 // if the first argument is a string, get a single tool
418 if (typeof arg2 === 'string') {
419 - const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifyToolSchema);
419 + const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
420 return this.provider.wrapTools([tool], executeToolFn) as TToolCollection;
421 } else {
422 // if the first argument is an object, get a list of tools
423 - const tools = await this.getRawComposioTools(userId, arg2, options?.modifyToolSchema);
423 + const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
424 return this.provider.wrapTools(tools, executeToolFn) as TToolCollection;
425 }
426 }
@@ -460,13 +460,11 @@ export class Tools<
460 body: ToolExecuteParams,
461 modifiers?: ExecuteToolModifiers
462 ): Promise<ToolExecuteResponse> {
463 - if (modifiers?.beforeToolExecute) {
464 - if (typeof modifiers.beforeToolExecute === 'function') {
465 - body = modifiers.beforeToolExecute(tool.slug, 'unkown', body);
463 + if (modifiers?.beforeExecute) {
464 + if (typeof modifiers.beforeExecute === 'function') {
465 + body = modifiers.beforeExecute(tool.slug, 'unkown', body);
466 } else {
467 - throw new ComposioInvalidModifierError(
468 - 'Invalid beforeToolExecute modifier. Not a function.'
469 - );
467 + throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
468 }
469 }
470
@@ -475,13 +473,11 @@ export class Tools<
473 connectedAccountId: body.connectedAccountId,
474 });
475
478 - if (modifiers?.afterToolExecute) {
479 - if (typeof modifiers.afterToolExecute === 'function') {
480 - result = modifiers.afterToolExecute(tool.slug, 'unkown', result);
476 + if (modifiers?.afterExecute) {
477 + if (typeof modifiers.afterExecute === 'function') {
478 + result = modifiers.afterExecute(tool.slug, 'unkown', result);
479 } else {
482 - throw new ComposioInvalidModifierError(
483 - 'Invalid afterToolExecute modifier. Not a function.'
484 - );
480 + throw new ComposioInvalidModifierError('Invalid afterExecute modifier. Not a function.');
481 }
482 }
483
@@ -501,13 +497,11 @@ export class Tools<
497 body: ToolExecuteParams,
498 modifiers?: ExecuteToolModifiers
499 ): Promise<ToolExecuteResponse> {
504 - if (modifiers?.beforeToolExecute) {
505 - if (typeof modifiers.beforeToolExecute === 'function') {
506 - body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || 'unkown', body);
500 + if (modifiers?.beforeExecute) {
501 + if (typeof modifiers.beforeExecute === 'function') {
502 + body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug || 'unkown', body);
503 } else {
508 - throw new ComposioInvalidModifierError(
509 - 'Invalid beforeToolExecute modifier. Not a function.'
510 - );
504 + throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
505 }
506 }
507 // fetch connected accounts if doesn't exist
@@ -530,13 +524,11 @@ export class Tools<
524 result = this.transformToolExecuteResponse(result);
525
526 // apply local modifiers if they are provided
533 - if (modifiers?.afterToolExecute) {
534 - if (typeof modifiers.afterToolExecute === 'function') {
535 - result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || 'unkown', result);
527 + if (modifiers?.afterExecute) {
528 + if (typeof modifiers.afterExecute === 'function') {
529 + result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug || 'unkown', result);
530 } else {
537 - throw new ComposioInvalidModifierError(
538 - 'Invalid afterToolExecute modifier. Not a function.'
539 - );
531 + throw new ComposioInvalidModifierError('Invalid afterExecute modifier. Not a function.');
532 }
533 }
534 return result;
@@ -570,11 +562,11 @@ export class Tools<
562 * userId: 'default',
563 * arguments: { owner: 'composio', repo: 'sdk' }
564 * }, {
573 - * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
565 + * beforeExecute: (toolSlug, toolkitSlug, params) => {
566 * // Modify params before execution
567 * return params;
568 * },
577 - * afterToolExecute: (toolSlug, toolkitSlug, result) => {
569 + * afterExecute: (toolSlug, toolkitSlug, result) => {
570 * // Transform result after execution
571 * return result;
572 * }
packages/core/src/telemetry/Telemetry.ts
+4
@@ -121,6 +121,10 @@ export class TelemetryService {
121 * @returns
122 */
123 async sendTelemetry(payload: TelemetryPayload[]) {
124 + if (!this.transport) {
125 + return;
126 + }
127 +
128 const isTelemetryDisabled = getEnvVariable('TELEMETRY_DISABLED', 'false') === 'true';
129
130 if (isTelemetryDisabled) {
packages/core/src/types/modifiers.types.ts
+22 -22
@@ -19,7 +19,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
19 * @example
20 * ```typescript
21 * // Add authentication headers to all tool requests
22 - * const beforeToolExecute = (toolSlug, toolkitSlug, params) => {
22 + * const beforeExecute = (toolSlug, toolkitSlug, params) => {
23 * return {
24 * ...params,
25 * customAuthParams: {
@@ -33,7 +33,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
33 * };
34 *
35 * // Transform input parameters for a specific tool
36 - * const beforeToolExecute = (toolSlug, toolkitSlug, params) => {
36 + * const beforeExecute = (toolSlug, toolkitSlug, params) => {
37 * if (toolSlug === 'GITHUB_SEARCH_REPOS') {
38 * // Convert simple query to structured query format
39 * return {
@@ -48,7 +48,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
48 * };
49 * ```
50 */
51 -export type BeforeToolExecuteModifier = (
51 +export type beforeExecuteModifier = (
52 toolSlug: string,
53 toolkitSlug: string,
54 toolExecuteParams: ToolExecuteParams
@@ -72,7 +72,7 @@ export type BeforeToolExecuteModifier = (
72 * @example
73 * ```typescript
74 * // Transform the response data format
75 - * const afterToolExecute = (toolSlug, toolkitSlug, response) => {
75 + * const afterExecute = (toolSlug, toolkitSlug, response) => {
76 * if (toolSlug === 'GITHUB_LIST_REPOS' && response.successful) {
77 * // Transform the returned repos into a simpler format
78 * return {
@@ -90,7 +90,7 @@ export type BeforeToolExecuteModifier = (
90 * };
91 *
92 * // Add error handling with custom messages
93 - * const afterToolExecute = (toolSlug, toolkitSlug, response) => {
93 + * const afterExecute = (toolSlug, toolkitSlug, response) => {
94 * if (!response.successful) {
95 * return {
96 * ...response,
@@ -104,7 +104,7 @@ export type BeforeToolExecuteModifier = (
104 * };
105 * ```
106 */
107 -export type AfterToolExecuteModifier = (
107 +export type afterExecuteModifier = (
108 toolSlug: string,
109 toolkitSlug: string,
110 toolExecuteResponse: ToolExecuteResponse
@@ -128,7 +128,7 @@ export type AfterToolExecuteModifier = (
128 * @example
129 * ```typescript
130 * // Modify the input parameters for a specific tool
131 - * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
131 + * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
132 * if (toolSlug === 'HACKERNEWS_GET_USER') {
133 * return {
134 * ...toolSchema,
@@ -146,7 +146,7 @@ export type AfterToolExecuteModifier = (
146 * };
147 *
148 * // Add custom descriptions to all tools in a toolkit
149 - * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
149 + * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
150 * if (toolkitSlug === 'github') {
151 * return {
152 * ...toolSchema,
@@ -158,7 +158,7 @@ export type AfterToolExecuteModifier = (
158 * };
159 *
160 * // Simplify tool schemas for a specific consumer
161 - * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
161 + * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
162 * // Remove advanced or complex parameters
163 * const { complexParam1, complexParam2, ...simpleInputParams } = toolSchema.inputParameters;
164 *
@@ -187,7 +187,7 @@ export type TransformToolSchemaModifier = (
187 * const tools = await composio.tools.get('default', {
188 * toolkits: ['github']
189 * }, {
190 - * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
190 + * modifySchema: (toolSlug, toolkitSlug, schema) => {
191 * // Custom schema modifications
192 * return schema;
193 * }
@@ -199,7 +199,7 @@ export type ToolOptions = {
199 * Function to transform tool schemas before they're exposed to consumers.
200 * This allows customizing input/output parameters, descriptions, and other metadata.
201 */
202 - modifyToolSchema?: TransformToolSchemaModifier;
202 + modifySchema?: TransformToolSchemaModifier;
203 };
204
205 /**
@@ -216,11 +216,11 @@ export type ToolOptions = {
216 * userId: 'default',
217 * arguments: { owner: 'composio' }
218 * }, {
219 - * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
219 + * beforeExecute: (toolSlug, toolkitSlug, params) => {
220 * console.log(`Executing ${toolSlug} from ${toolkitSlug}`);
221 * return params;
222 * },
223 - * afterToolExecute: (toolSlug, toolkitSlug, response) => {
223 + * afterExecute: (toolSlug, toolkitSlug, response) => {
224 * if (response.successful) {
225 * console.log(`Successfully executed ${toolSlug}`);
226 * }
@@ -234,13 +234,13 @@ export type ExecuteToolModifiers = {
234 * Function to intercept and modify tool execution parameters before the tool is executed.
235 * This allows customizing the request based on tool-specific needs.
236 */
237 - beforeToolExecute?: BeforeToolExecuteModifier;
237 + beforeExecute?: beforeExecuteModifier;
238
239 /**
240 * Function to intercept and modify tool execution responses after the tool has executed.
241 * This allows transforming the response or implementing custom error handling.
242 */
243 - afterToolExecute?: AfterToolExecuteModifier;
243 + afterExecute?: afterExecuteModifier;
244 };
245
246 /**
@@ -254,7 +254,7 @@ export type ExecuteToolModifiers = {
254 * ```typescript
255 * // Configure agentic tools with schema and execution modifications
256 * const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
257 - * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
257 + * modifySchema: (toolSlug, toolkitSlug, schema) => {
258 * return {
259 * ...schema,
260 * description: `Enhanced ${toolSlug} for better context`
@@ -262,14 +262,14 @@ export type ExecuteToolModifiers = {
262 * },
263 *
264 * // Intercept before execution
265 - * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
265 + * beforeExecute: (toolSlug, toolkitSlug, params) => {
266 * // Add analytics tracking
267 * trackToolUsage(toolSlug);
268 * return params;
269 * },
270 *
271 * // Transform after execution
272 - * afterToolExecute: (toolSlug, toolkitSlug, response) => {
272 + * afterExecute: (toolSlug, toolkitSlug, response) => {
273 * // Log results and handle errors
274 * if (!response.successful) {
275 * logToolError(toolSlug, response.error);
@@ -293,7 +293,7 @@ export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
293 * ```typescript
294 * // With standard provider (non-agentic)
295 * const tools = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
296 - * modifyToolSchema: (toolSlug, toolkitSlug, schema) => schema
296 + * modifySchema: (toolSlug, toolkitSlug, schema) => schema
297 * });
298 *
299 * // With agentic provider (e.g., VercelProvider)
@@ -303,9 +303,9 @@ export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
303 * });
304 *
305 * const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
306 - * modifyToolSchema: (toolSlug, toolkitSlug, schema) => schema,
307 - * beforeToolExecute: (toolSlug, toolkitSlug, params) => params,
308 - * afterToolExecute: (toolSlug, toolkitSlug, response) => response
306 + * modifySchema: (toolSlug, toolkitSlug, schema) => schema,
307 + * beforeExecute: (toolSlug, toolkitSlug, params) => params,
308 + * afterExecute: (toolSlug, toolkitSlug, response) => response
309 * });
310 * ```
311 */
packages/core/test/provider/openai-provider.test.ts
+3 -3
@@ -124,15 +124,15 @@ describe('OpenAIProvider', () => {
124 },
125 };
126
127 - // Create a valid ExecuteToolModifiers object with beforeToolExecute and afterToolExecute functions
127 + // Create a valid ExecuteToolModifiers object with beforeExecute and afterExecute functions
128 const modifiers: ExecuteToolModifiers = {
129 - beforeToolExecute: vi.fn((toolSlug, toolkitSlug, params) => {
129 + beforeExecute: vi.fn((toolSlug, toolkitSlug, params) => {
130 return {
131 ...params,
132 allowTracing: true,
133 };
134 }),
135 - afterToolExecute: vi.fn((toolSlug, toolkitSlug, response) => {
135 + afterExecute: vi.fn((toolSlug, toolkitSlug, response) => {
136 return response;
137 }),
138 };
packages/core/test/provider/provider.test.ts
+4 -4
@@ -110,8 +110,8 @@ describe('BaseProvider', () => {
110 arguments: { query: 'test' },
111 };
112 const modifiers = {
113 - beforeToolExecute: vi.fn(x => x),
114 - afterToolExecute: vi.fn(x => x),
113 + beforeExecute: vi.fn(x => x),
114 + afterExecute: vi.fn(x => x),
115 };
116
117 const result = await nonAgenticProvider.executeTool(toolSlug, toolParams, modifiers);
@@ -209,8 +209,8 @@ describe('BaseProvider', () => {
209 arguments: { query: 'test' },
210 };
211 const modifiers = {
212 - beforeToolExecute: vi.fn(x => x),
213 - afterToolExecute: vi.fn(x => x),
212 + beforeExecute: vi.fn(x => x),
213 + afterExecute: vi.fn(x => x),
214 };
215
216 const result = await agenticProvider.executeTool(toolSlug, toolParams, modifiers);
packages/core/test/tools/modifiers.test.ts
+11 -11
@@ -62,24 +62,24 @@ describe('Tools Modifiers', () => {
62 });
63
64 describe('Execution Modifiers', () => {
65 - it('should apply beforeToolExecute modifier before executing a tool', async () => {
65 + it('should apply beforeExecute modifier before executing a tool', async () => {
66 const slug = 'COMPOSIO_TOOL';
67 const body = {
68 userId: 'test-user',
69 arguments: { limit: 5 },
70 };
71
72 - const { beforeToolExecute } = createExecutionModifiers({
72 + const { beforeExecute } = createExecutionModifiers({
73 beforeModifications: {
74 arguments: { limit: 10 },
75 },
76 });
77
78 await mockToolExecution(context.tools);
79 - await context.tools.execute(slug, body, { beforeToolExecute });
79 + await context.tools.execute(slug, body, { beforeExecute });
80
81 - expect(beforeToolExecute).toHaveBeenCalledTimes(1);
82 - expect(beforeToolExecute).toHaveBeenCalledWith(slug, expect.any(String), body);
81 + expect(beforeExecute).toHaveBeenCalledTimes(1);
82 + expect(beforeExecute).toHaveBeenCalledWith(slug, expect.any(String), body);
83 expect(mockClient.tools.execute).toHaveBeenCalledWith(
84 slug,
85 expect.objectContaining({
@@ -88,21 +88,21 @@ describe('Tools Modifiers', () => {
88 );
89 });
90
91 - it('should apply afterToolExecute modifier after executing a tool', async () => {
91 + it('should apply afterExecute modifier after executing a tool', async () => {
92 const slug = 'COMPOSIO_TOOL';
93 const body = { userId: 'test-user', arguments: {} };
94
95 - const { afterToolExecute } = createExecutionModifiers({
95 + const { afterExecute } = createExecutionModifiers({
96 afterModifications: {
97 data: { enhanced: true },
98 },
99 });
100
101 await mockToolExecution(context.tools);
102 - const result = await context.tools.execute(slug, body, { afterToolExecute });
102 + const result = await context.tools.execute(slug, body, { afterExecute });
103
104 - expect(afterToolExecute).toHaveBeenCalledTimes(1);
105 - expect(afterToolExecute).toHaveBeenCalledWith(
104 + expect(afterExecute).toHaveBeenCalledTimes(1);
105 + expect(afterExecute).toHaveBeenCalledWith(
106 slug,
107 expect.any(String),
108 expect.objectContaining({
@@ -134,7 +134,7 @@ describe('Tools Modifiers', () => {
134 const createExecuteToolFnSpy = vi.spyOn(context.tools as any, 'createExecuteToolFn');
135
136 await context.tools.get(userId, slug, {
137 - modifyToolSchema: schemaModifier,
137 + modifySchema: schemaModifier,
138 ...executionModifiers,
139 });
140
packages/core/test/tools/tools.test.ts
+1 -1
@@ -243,7 +243,7 @@ describe('Tools', () => {
243 toolMocks.transformedTool as unknown as Tool
244 );
245
246 - await context.tools.get(userId, slug, { modifyToolSchema: schemaModifier });
246 + await context.tools.get(userId, slug, { modifySchema: schemaModifier });
247
248 expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(userId, slug, schemaModifier);
249 });
packages/core/test/utils/toolExecuteUtils.ts
+2 -2
@@ -84,11 +84,11 @@ export const createExecutionModifiers = ({
84 afterModifications = {},
85 } = {}) => {
86 return {
87 - beforeToolExecute: vi.fn((toolSlug: string, toolkitSlug: string, params: any) => ({
87 + beforeExecute: vi.fn((toolSlug: string, toolkitSlug: string, params: any) => ({
88 ...params,
89 ...beforeModifications,
90 })),
91 - afterToolExecute: vi.fn((toolSlug: string, toolkitSlug: string, response: any) => ({
91 + afterExecute: vi.fn((toolSlug: string, toolkitSlug: string, response: any) => ({
92 ...response,
93 ...afterModifications,
94 })),
packages/providers/README.md
+24 -24
@@ -46,11 +46,11 @@ These providers support full modifier capabilities, making them suitable for com
46
47 1. **Schema Modifiers**: Transform tool schemas using `TransformToolSchemaModifier`
48 2. **Execution Modifiers**: Transform tool execution behavior
49 - - `beforeToolExecute`: Transform input parameters before execution
50 - - `afterToolExecute`: Transform output after execution
49 + - `beforeExecute`: Transform input parameters before execution
50 + - `afterExecute`: Transform output after execution
51 3. **Execute Modifiers**: Used during tool execution
52 - - `beforeToolExecute`: Transform input parameters
53 - - `afterToolExecute`: Transform output
52 + - `beforeExecute`: Transform input parameters
53 + - `afterExecute`: Transform output
54
55 Example implementation:
56
@@ -91,17 +91,17 @@ export class AgenticProvider extends BaseAgenticProvider {
91 ): Promise<ToolExecuteResponse> {
92 let executeParams = params;
93
94 - // Apply beforeToolExecute modifier if provided
95 - if (modifiers?.beforeToolExecute) {
96 - executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
94 + // Apply beforeExecute modifier if provided
95 + if (modifiers?.beforeExecute) {
96 + executeParams = modifiers.beforeExecute(tool.slug, executeParams);
97 }
98
99 // Execute the tool
100 const response = await this.client.executeTool(tool.slug, executeParams);
101
102 - // Apply afterToolExecute modifier if provided
103 - if (modifiers?.afterToolExecute) {
104 - return modifiers.afterToolExecute(tool.slug, response.data);
102 + // Apply afterExecute modifier if provided
103 + if (modifiers?.afterExecute) {
104 + return modifiers.afterExecute(tool.slug, response.data);
105 }
106
107 return response.data;
@@ -191,12 +191,12 @@ type TransformToolSchemaModifier = (toolSlug: string, tool: Tool) => Tool;
191 ```typescript
192 type ModifiersParams = {
193 schema?: TransformToolSchemaModifier;
194 - beforeToolExecute?: BeforeToolExecuteModifier;
195 - afterToolExecute?: AfterToolExecuteModifier;
194 + beforeExecute?: beforeExecuteModifier;
195 + afterExecute?: afterExecuteModifier;
196 };
197
198 -type BeforeToolExecuteModifier = (toolSlug: string, params: ToolExecuteParams) => ToolExecuteParams;
199 -type AfterToolExecuteModifier = (
198 +type beforeExecuteModifier = (toolSlug: string, params: ToolExecuteParams) => ToolExecuteParams;
199 +type afterExecuteModifier = (
200 toolSlug: string,
201 response: ToolExecuteResponse
202 ) => ToolExecuteResponse;
@@ -284,17 +284,17 @@ export class VercelProvider extends BaseAgenticProvider {
284 ): Promise<ToolExecuteResponse> {
285 let executeParams = params;
286
287 - // Apply beforeToolExecute modifier if provided
288 - if (modifiers?.beforeToolExecute) {
289 - executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
287 + // Apply beforeExecute modifier if provided
288 + if (modifiers?.beforeExecute) {
289 + executeParams = modifiers.beforeExecute(tool.slug, executeParams);
290 }
291
292 // Execute the tool
293 const response = await this.client.executeTool(tool.slug, executeParams);
294
295 - // Apply afterToolExecute modifier if provided
296 - if (modifiers?.afterToolExecute) {
297 - return modifiers.afterToolExecute(tool.slug, response.data);
295 + // Apply afterExecute modifier if provided
296 + if (modifiers?.afterExecute) {
297 + return modifiers.afterExecute(tool.slug, response.data);
298 }
299
300 return response.data;
@@ -359,14 +359,14 @@ const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
359 },
360 }),
361 // Execution modifiers
362 - beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
362 + beforeExecute: (toolSlug: string, params: ToolExecuteParams) => ({
363 ...params,
364 arguments: {
365 ...params.arguments,
366 limit: Math.min((params.arguments?.limit as number) || 10, 100),
367 },
368 }),
369 - afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
369 + afterExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
370 ...response,
371 data: {
372 ...response.data,
@@ -385,14 +385,14 @@ const result = await composio.provider.executeTool(
385 arguments: { query: 'AI', limit: 20 },
386 },
387 {
388 - beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
388 + beforeExecute: (toolSlug: string, params: ToolExecuteParams) => ({
389 ...params,
390 arguments: {
391 ...params.arguments,
392 limit: Math.min((params.arguments?.limit as number) || 10, 100),
393 },
394 }),
395 - afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
395 + afterExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
396 ...response,
397 data: {
398 ...response.data,
packages/providers/cloudflare/test/cloudflare.test.ts
+4 -4
@@ -240,8 +240,8 @@ describe('CloudflareProvider', () => {
240 };
241
242 const modifiers = {
243 - beforeToolExecute: vi.fn(params => params),
244 - afterToolExecute: vi.fn(response => response),
243 + beforeExecute: vi.fn(params => params),
244 + afterExecute: vi.fn(response => response),
245 };
246
247 await provider.executeToolCall(userId, toolCall, options, modifiers);
@@ -285,8 +285,8 @@ describe('CloudflareProvider', () => {
285 };
286
287 const modifiers = {
288 - beforeToolExecute: vi.fn(params => params),
289 - afterToolExecute: vi.fn(response => response),
288 + beforeExecute: vi.fn(params => params),
289 + afterExecute: vi.fn(response => response),
290 };
291
292 await provider.executeTool(toolSlug, toolParams, modifiers);
packages/providers/langchain/test/langchain.test.ts
+2 -2
@@ -212,8 +212,8 @@ describe('LangchainProvider', () => {
212 };
213
214 const modifiers = {
215 - beforeToolExecute: vi.fn(params => params),
216 - afterToolExecute: vi.fn(response => response),
215 + beforeExecute: vi.fn(params => params),
216 + afterExecute: vi.fn(response => response),
217 };
218
219 await provider.executeTool(toolSlug, toolParams, modifiers);
packages/providers/openai/test/openai.test.ts
+4 -4
@@ -214,8 +214,8 @@ describe('OpenAIProvider', () => {
214 };
215
216 const modifiers = {
217 - beforeToolExecute: vi.fn(params => params),
218 - afterToolExecute: vi.fn(response => response),
217 + beforeExecute: vi.fn(params => params),
218 + afterExecute: vi.fn(response => response),
219 };
220
221 await provider.executeToolCall(userId, toolCall, options, modifiers);
@@ -445,8 +445,8 @@ describe('OpenAIProvider', () => {
445 };
446
447 const modifiers = {
448 - beforeToolExecute: vi.fn(params => params),
449 - afterToolExecute: vi.fn(response => response),
448 + beforeExecute: vi.fn(params => params),
449 + afterExecute: vi.fn(response => response),
450 };
451
452 await provider.executeTool(toolSlug, toolParams, modifiers);
packages/providers/vercel/test/vercel.test.ts
+2 -2
@@ -187,8 +187,8 @@ describe('VercelProvider', () => {
187 };
188
189 const modifiers = {
190 - beforeToolExecute: vi.fn(params => params),
191 - afterToolExecute: vi.fn(response => response),
190 + beforeExecute: vi.fn(params => params),
191 + afterExecute: vi.fn(response => response),
192 };
193
194 await provider.executeTool(toolSlug, toolParams, modifiers);