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
refactor(core): address review comments — rename API, add Zod validation
Dhawal Upadhyay3388afcc9b4d
diff --git a/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs b/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjsindex 16dbaf605..647561fa4 100644--- a/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs+++ b/ts/e2e-tests/runtimes/node/custom-tools/fixtures/index.mjs@@ -7,7 +7,7 @@* Requires COMPOSIO_API_KEY in environment.*/import { Composio } from '@composio/core';-import { CustomTool } from '@composio/core/experimental';+import { createCustomTool } from '@composio/core/experimental';import { z } from 'zod/v3';const apiKey = process.env.COMPOSIO_API_KEY;@@ -18,7 +18,7 @@ if (!apiKey) {// ── Define custom tools ──────────────────────────────────────-const getUserContext = CustomTool({+const getUserContext = createCustomTool({slug: 'GET_USER_CONTEXT',name: 'Get user context',description: 'Retrieve user preferences and history',@@ -30,7 +30,7 @@ const getUserContext = CustomTool({},});-const enrichedSearch = CustomTool({+const enrichedSearch = createCustomTool({slug: 'ENRICHED_SEARCH',name: 'Enriched search',description: 'Search and enrich results with user context',@@ -45,7 +45,7 @@ const enrichedSearch = CustomTool({},});-const throwingTool = CustomTool({+const throwingTool = createCustomTool({slug: 'THROWING_TOOL',name: 'Throwing tool',description: 'A tool that always throws an error',@@ -56,7 +56,7 @@ const throwingTool = CustomTool({});// Tool with strict numeric schema — for Zod validation failure test-const strictTool = CustomTool({+const strictTool = createCustomTool({slug: 'STRICT_TOOL',name: 'Strict tool',description: 'Tool with strict numeric input',@@ -69,7 +69,7 @@ const strictTool = CustomTool({});// Tool that chains into a remote tool via SessionContext.execute()-const weatherChain = CustomTool({+const weatherChain = createCustomTool({slug: 'WEATHER_CHAIN',name: 'Weather chain',description: 'Fetches weather via remote tool and enriches with local context',diff --git a/ts/packages/core/src/experimental/index.ts b/ts/packages/core/src/experimental/index.tsindex e526e9a3f..8f45f80f8 100644--- a/ts/packages/core/src/experimental/index.ts+++ b/ts/packages/core/src/experimental/index.ts@@ -7,11 +7,10 @@*/// Custom local tools-export { CustomTool } from '../models/CustomTool';-export { SessionContextImpl } from '../models/SessionContext';+export { createCustomTool } from '../models/CustomTool';export type {- CustomToolHandle,- NewCustomToolOptions,+ CustomTool,+ CreateCustomToolParams,CustomToolExecuteFn,SessionContext,} from '../types/customTool.types';diff --git a/ts/packages/core/src/index.ts b/ts/packages/core/src/index.tsindex cc1183d5d..911b8dd60 100644--- a/ts/packages/core/src/index.ts+++ b/ts/packages/core/src/index.ts@@ -12,8 +12,7 @@ export { RemoteFile } from './models/RemoteFile';export { createConnectionRequest } from './models/ConnectionRequest';export { ToolRouterSession } from './models/ToolRouterSession';/** @experimental Create custom local tools — also available from '@composio/core/experimental' */-export { CustomTool } from './models/CustomTool';-export { SessionContextImpl } from './models/SessionContext';+export { createCustomTool } from './models/CustomTool';export * from './types/provider.types';export * from './types/customTool.types';export * from './types/tool.types';diff --git a/ts/packages/core/src/models/CustomTool.ts b/ts/packages/core/src/models/CustomTool.tsindex 5016afa3f..c13d44431 100644--- a/ts/packages/core/src/models/CustomTool.ts+++ b/ts/packages/core/src/models/CustomTool.ts@@ -3,9 +3,9 @@** Usage:* ```typescript- * import { CustomTool } from '@composio/core/experimental';+ * import { createCustomTool } from '@composio/core/experimental';*- * const myTool = CustomTool({+ * const myTool = createCustomTool({* slug: 'GET_USER_CONTEXT',* name: 'Get user context',* description: 'Retrieve what we know about a user',@@ -16,14 +16,15 @@*/import * as zodToJsonSchema from 'zod-to-json-schema';import { z } from 'zod/v3';-import type {- NewCustomToolOptions,- CustomToolHandle,- CustomToolExecuteFn,- LocalToolsMap,- LocalToolsMapEntry,- LocalToolDefinition,- InputParamsSchema,+import {+ CreateCustomToolBaseSchema,+ type CreateCustomToolParams,+ type CustomTool,+ type CustomToolExecuteFn,+ type LocalToolsMap,+ type LocalToolsMapEntry,+ type LocalToolDefinition,+ type InputParamsSchema,} from '../types/customTool.types';/** Prefix applied by the backend to local tool slugs for disambiguation. */@@ -32,7 +33,7 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';/*** Create a custom local tool for use in tool router sessions.*- * The returned handle is a lightweight reference containing the tool's metadata+ * The returned object is a lightweight reference containing the tool's metadata* and execute function. Pass it to `composio.create(userId, { customTools: [...] })`* to bind it to a session.*@@ -40,11 +41,11 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';* The SDK wraps it into the standard response format internally.** @param options - Tool definition including slug, schema, and execute function- * @returns A CustomToolHandle to pass to session creation+ * @returns A CustomTool to pass to session creation** @example No-auth tool (no session needed)* ```typescript- * const getUserContext = CustomTool({+ * const getUserContext = createCustomTool({* slug: 'GET_USER_CONTEXT',* name: 'Get user context',* description: 'Retrieve user preferences and history',@@ -56,9 +57,9 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';* });* ```*- * @example No-auth tool using session to call other tools+ * @example Tool using session to call other tools* ```typescript- * const enrichedSearch = CustomTool({+ * const enrichedSearch = createCustomTool({* slug: 'ENRICHED_SEARCH',* name: 'Enriched search',* description: 'Search and enrich results with user context',@@ -70,13 +71,13 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';* });* ```*- * @example Auth tool with connectedToolkit (requires Composio connection)+ * @example Auth tool with toolkit (requires Composio connection)* ```typescript- * const getAdAccounts = CustomTool({+ * const getAdAccounts = createCustomTool({* slug: 'GET_AD_ACCOUNTS',* name: 'Get ad accounts',* description: 'Get Meta ad account IDs for the authenticated user',- * connectedToolkit: 'meta_ads',+ * toolkit: 'meta_ads',* inputParams: z.object({ fields: z.string().default('id,name') }),* execute: async (input, session) => {* const result = await session.execute('META_ADS_GET_AD_ACCOUNTS', {@@ -87,32 +88,22 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';* });* ```*/-export function CustomTool<T extends z.ZodType>(- options: NewCustomToolOptions<T>-): CustomToolHandle {- const { slug, name, description, inputParams, execute, connectedToolkit } = options;+export function createCustomTool<T extends z.ZodType>(+ options: CreateCustomToolParams<T>+): CustomTool {+ // Validate string/scalar fields via Zod schema+ const validated = CreateCustomToolBaseSchema.parse(options);- if (!slug) {- throw new Error('CustomTool: slug is required');+ // Manual checks for fields Zod can't validate+ if (!options.inputParams) {+ throw new Error('createCustomTool: inputParams is required');}- if (slug.toUpperCase().startsWith(LOCAL_TOOL_PREFIX)) {- throw new Error(- `CustomTool: slug must not start with "${LOCAL_TOOL_PREFIX}" — this prefix is reserved for internal routing.`- );- }- if (!name) {- throw new Error('CustomTool: name is required');- }- if (!description) {- throw new Error('CustomTool: description is required');- }- if (!inputParams) {- throw new Error('CustomTool: inputParams is required');- }- if (typeof execute !== 'function') {- throw new Error('CustomTool: execute must be a function');+ if (typeof options.execute !== 'function') {+ throw new Error('createCustomTool: execute must be a function');}+ const { inputParams, execute } = options;+// Convert Zod schema → JSON Schema (reuses same pattern as legacy CustomTools.createTool)const paramsSchema = zodToJsonSchema.default(inputParams, {name: 'input',@@ -126,10 +117,10 @@ export function CustomTool<T extends z.ZodType>(};return {- slug,- name,- description,- connectedToolkit,+ slug: validated.slug,+ name: validated.name,+ description: validated.description,+ toolkit: validated.toolkit,inputSchema,inputParams,execute: execute as CustomToolExecuteFn<z.ZodType>,@@ -137,24 +128,24 @@ export function CustomTool<T extends z.ZodType>(}/**- * Build a LocalToolsMap from an array of handles.+ * Build a LocalToolsMap from an array of custom tools.* Used internally by ToolRouter.create() to construct the per-session routing map.** @internal- * @param handles - The custom tool handles to include in the session+ * @param tools - The custom tools to include in the session* @returns Maps for O(1) lookup by both prefixed and original slug* @throws If duplicate slugs are detected*/-export function buildLocalToolsMap(handles: CustomToolHandle[]): LocalToolsMap {+export function buildLocalToolsMap(tools: CustomTool[]): LocalToolsMap {const byPrefixed = new Map<string, LocalToolsMapEntry>();const byOriginal = new Map<string, LocalToolsMapEntry>();- for (const handle of handles) {+ for (const handle of tools) {const upperSlug = handle.slug.toUpperCase();const prefixedSlug = `${LOCAL_TOOL_PREFIX}${upperSlug}`;if (byOriginal.has(upperSlug)) {- throw new Error(`CustomTool: duplicate slug "${handle.slug}"`);+ throw new Error(`createCustomTool: duplicate slug "${handle.slug}"`);}const entry: LocalToolsMapEntry = { handle, prefixedSlug };@@ -166,20 +157,20 @@ export function buildLocalToolsMap(handles: CustomToolHandle[]): LocalToolsMap {}/**- * Serialize custom tool handles into the format expected by the backend session creation API.+ * Serialize custom tools into the format expected by the backend session creation API.** @internal- * @param handles - The custom tool handles to serialize+ * @param tools - The custom tools to serialize* @returns Array of LocalToolDefinition for the API payload*/export function serializeLocalTools(- handles: CustomToolHandle[]+ tools: CustomTool[]): LocalToolDefinition[] {- return handles.map(handle => ({+ return tools.map(handle => ({slug: handle.slug,name: handle.name,description: handle.description,input_schema: handle.inputSchema,- ...(handle.connectedToolkit ? { toolkit: handle.connectedToolkit } : {}),+ ...(handle.toolkit ? { toolkit: handle.toolkit } : {}),}));}diff --git a/ts/packages/core/src/types/customTool.types.ts b/ts/packages/core/src/types/customTool.types.tsindex 9bf3a8dcc..804401983 100644--- a/ts/packages/core/src/types/customTool.types.ts+++ b/ts/packages/core/src/types/customTool.types.ts@@ -59,7 +59,7 @@ export interface ExecuteMetadata {}// ────────────────────────────────────────────────────────────────-// New custom tool types (for tool router integration via CustomTool())+// New custom tool types (for tool router integration via createCustomTool())// ────────────────────────────────────────────────────────────────/**@@ -74,7 +74,10 @@ export interface SessionContext {toolSlug: string,arguments_: Record<string, unknown>): Promise<SdkToolExecuteResponse>;- /** Proxy API calls through Composio's auth layer (resolved from session) */+ /**+ * Proxy API calls through Composio's auth layer (resolved from session).+ * @todo Not yet implemented — pending backend session-scoped proxy endpoint.+ */proxyExecute(params: ToolProxyParams): Promise<SdkToolExecuteResponse>;}@@ -91,38 +94,52 @@ export type CustomToolExecuteFn<T extends z.ZodType> = (session: SessionContext) => Promise<Record<string, unknown>>;-/** Options for creating a custom local tool via `CustomTool()`. */-export type NewCustomToolOptions<T extends z.ZodType> = {- /** Unique slug identifier (e.g. 'GET_USER_CONTEXT') */- slug: string;- /** Human-readable name */- name: string;- /** Description — required for search indexing */- description: string;- /** Zod schema for input parameters */- inputParams: T;+/**+ * Zod schema for validating the string/scalar fields of createCustomTool() options.+ * Used internally for validation — inputParams and execute are checked manually.+ */+export const CreateCustomToolBaseSchema = z.object({+ slug: z+ .string()+ .min(1, 'createCustomTool: slug is required')+ .refine(s => !s.toUpperCase().startsWith('LOCAL_'), {+ message:+ 'createCustomTool: slug must not start with "LOCAL_" — this prefix is reserved for internal routing.',+ }),+ name: z.string().min(1, 'createCustomTool: name is required'),+ description: z.string().min(1, 'createCustomTool: description is required'),/**- * Composio toolkit slug requiring an active connection (e.g. 'meta_ads').- * If not provided, the tool does not need Composio auth.+ * Composio toolkit slug that this tool requires an active connection for.+ * Set this to the toolkit whose auth your tool needs (e.g. `'meta_ads'`, `'gmail'`).+ * Leave empty for tools that don't need any Composio-managed authentication.*/- connectedToolkit?: string;+ toolkit: z.string().optional(),+});++/** Options for creating a custom local tool via `createCustomTool()`. */+export type CreateCustomToolParams<T extends z.ZodType> = z.infer<+ typeof CreateCustomToolBaseSchema+> & {+ /** Zod schema for input parameters */+ inputParams: T;/** The function that executes the tool */execute: CustomToolExecuteFn<T>;};/**- * Handle returned from `CustomTool()`.+ * Custom tool definition returned from `createCustomTool()`.* Pass to `composio.create(userId, { customTools: [...] })` to bind to a session.*/-export interface CustomToolHandle {+export interface CustomTool {readonly slug: string;readonly name: string;readonly description: string;/**- * Composio toolkit slug requiring an active connection.- * Undefined means the tool does not need Composio auth.+ * Composio toolkit slug that this tool requires an active connection for.+ * Set this to the toolkit whose auth your tool needs (e.g. `'meta_ads'`, `'gmail'`).+ * Undefined means the tool doesn't need any Composio-managed authentication.*/- readonly connectedToolkit?: string;+ readonly toolkit?: string;readonly inputSchema: Record<string, unknown>;/** @internal Original Zod schema — used for runtime input validation (defaults, coercions, transforms) */readonly inputParams: z.ZodType;@@ -136,13 +153,12 @@ export interface LocalToolDefinition {name: string;description: string;input_schema: Record<string, unknown>;- /** Maps connectedToolkit → toolkit in the backend payload */toolkit?: string;}/** @internal Entry in the per-session local tools routing map. */export type LocalToolsMapEntry = {- handle: CustomToolHandle;+ handle: CustomTool;prefixedSlug: string;};diff --git a/ts/packages/core/src/types/toolRouter.types.ts b/ts/packages/core/src/types/toolRouter.types.tsindex 6664970f0..29520ba0c 100644--- a/ts/packages/core/src/types/toolRouter.types.ts+++ b/ts/packages/core/src/types/toolRouter.types.ts@@ -3,7 +3,7 @@ import type { BaseComposioProvider } from '../provider/BaseProvider';import { SessionMetaToolOptions } from './modifiers.types';import { ConnectionRequest } from './connectionRequest.types';import type { ToolRouterSessionFilesMount } from '../models/ToolRouterSessionFileMount';-import type { CustomToolHandle } from './customTool.types';+import type { CustomTool } from './customTool.types';export const MCPServerTypeSchema = z.enum(['http', 'sse']);export type MCPServerType = z.infer<typeof MCPServerTypeSchema>;@@ -217,7 +217,7 @@ export const ToolRouterCreateSessionConfigSchema = z.optional().describe('Experimental features configuration - not stable, may be modified or removed'),customTools: z- .array(z.custom<CustomToolHandle>())+ .array(z.custom<CustomTool>()).optional().describe('Custom local tools to include in this session. Created via CustomTool() from @composio/core/experimental.'@@ -440,6 +440,8 @@ export interface Session<search: ToolRouterSessionSearchFn;/** Execute a tool within the session */execute: ToolRouterSessionExecuteFn;+ /** Get provider-wrapped local custom tools for MCP flows */+ localTools: () => Promise<ReturnType<TProvider['wrapTools']>>;/** Experimental features (files, assistive prompt, etc.) */experimental: SessionExperimental;}diff --git a/ts/packages/core/test/models/customTool.test.ts b/ts/packages/core/test/models/customTool.test.tsindex 08ccccdc8..4e6b28e52 100644--- a/ts/packages/core/test/models/customTool.test.ts+++ b/ts/packages/core/test/models/customTool.test.ts@@ -1,14 +1,14 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { z } from 'zod/v3';-import { CustomTool, buildLocalToolsMap, serializeLocalTools, LOCAL_TOOL_PREFIX } from '../../src/models/CustomTool';+import { createCustomTool, buildLocalToolsMap, serializeLocalTools, LOCAL_TOOL_PREFIX } from '../../src/models/CustomTool';import { SessionContextImpl } from '../../src/models/SessionContext';-import type { CustomToolHandle, SessionContext } from '../../src/types/customTool.types';+import type { CustomTool, SessionContext } from '../../src/types/customTool.types';// ────────────────────────────────────────────────────────────────-// CustomTool() factory+// createCustomTool() factory// ────────────────────────────────────────────────────────────────-describe('CustomTool', () => {+describe('createCustomTool', () => {const baseOptions = {slug: 'GET_USER_CONTEXT',name: 'Get user context',@@ -19,31 +19,31 @@ describe('CustomTool', () => {execute: vi.fn().mockResolvedValue({ result: 'ok' }),};- it('should return a valid handle with correct fields', () => {- const handle = CustomTool(baseOptions);+ it('should return a valid tool with correct fields', () => {+ const tool = createCustomTool(baseOptions);- expect(handle.slug).toBe('GET_USER_CONTEXT');- expect(handle.name).toBe('Get user context');- expect(handle.description).toBe('Retrieve what we know about a user');- expect(handle.connectedToolkit).toBeUndefined();- expect(handle.execute).toBe(baseOptions.execute);- expect(handle.inputSchema).toMatchObject({+ expect(tool.slug).toBe('GET_USER_CONTEXT');+ expect(tool.name).toBe('Get user context');+ expect(tool.description).toBe('Retrieve what we know about a user');+ expect(tool.toolkit).toBeUndefined();+ expect(tool.execute).toBe(baseOptions.execute);+ expect(tool.inputSchema).toMatchObject({type: 'object',properties: {category: { type: 'string', description: 'The category' },},required: ['category'],});- expect(handle.inputParams).toBe(baseOptions.inputParams);+ expect(tool.inputParams).toBe(baseOptions.inputParams);});- it('should include connectedToolkit when provided', () => {- const handle = CustomTool({ ...baseOptions, connectedToolkit: 'meta_ads' });- expect(handle.connectedToolkit).toBe('meta_ads');+ it('should include toolkit when provided', () => {+ const tool = createCustomTool({ ...baseOptions, toolkit: 'meta_ads' });+ expect(tool.toolkit).toBe('meta_ads');});it('should convert Zod schema with optional fields correctly', () => {- const handle = CustomTool({+ const tool = createCustomTool({...baseOptions,inputParams: z.object({required_field: z.string(),@@ -51,7 +51,7 @@ describe('CustomTool', () => {}),});- expect(handle.inputSchema).toMatchObject({+ expect(tool.inputSchema).toMatchObject({type: 'object',properties: {required_field: { type: 'string' },@@ -62,14 +62,14 @@ describe('CustomTool', () => {});it('should convert Zod schema with defaults correctly', () => {- const handle = CustomTool({+ const tool = createCustomTool({...baseOptions,inputParams: z.object({category: z.string().default('all'),}),});- expect(handle.inputSchema).toMatchObject({+ expect(tool.inputSchema).toMatchObject({type: 'object',properties: {category: expect.objectContaining({ type: 'string' }),@@ -79,39 +79,39 @@ describe('CustomTool', () => {describe('validation', () => {it('should throw if slug is missing', () => {- expect(() => CustomTool({ ...baseOptions, slug: '' })).toThrow('slug is required');+ expect(() => createCustomTool({ ...baseOptions, slug: '' })).toThrow('slug is required');});it('should throw if slug starts with LOCAL_ prefix', () => {- expect(() => CustomTool({ ...baseOptions, slug: 'LOCAL_MY_TOOL' })).toThrow(- 'must not start with "LOCAL_"'+ expect(() => createCustomTool({ ...baseOptions, slug: 'LOCAL_MY_TOOL' })).toThrow(+ /LOCAL_/);});it('should throw if slug starts with local_ prefix (case-insensitive)', () => {- expect(() => CustomTool({ ...baseOptions, slug: 'local_something' })).toThrow(- 'must not start with "LOCAL_"'+ expect(() => createCustomTool({ ...baseOptions, slug: 'local_something' })).toThrow(+ /LOCAL_/);});it('should throw if name is missing', () => {- expect(() => CustomTool({ ...baseOptions, name: '' })).toThrow('name is required');+ expect(() => createCustomTool({ ...baseOptions, name: '' })).toThrow('name is required');});it('should throw if description is missing', () => {- expect(() => CustomTool({ ...baseOptions, description: '' })).toThrow(+ expect(() => createCustomTool({ ...baseOptions, description: '' })).toThrow('description is required');});it('should throw if inputParams is missing', () => {- expect(() => CustomTool({ ...baseOptions, inputParams: null as any })).toThrow(+ expect(() => createCustomTool({ ...baseOptions, inputParams: null as any })).toThrow('inputParams is required');});it('should throw if execute is not a function', () => {- expect(() => CustomTool({ ...baseOptions, execute: 'not-fn' as any })).toThrow(+ expect(() => createCustomTool({ ...baseOptions, execute: 'not-fn' as any })).toThrow('execute must be a function');});@@ -121,13 +121,13 @@ describe('CustomTool', () => {it('should allow no-session execute (input only)', async () => {const noSessionExecute = vi.fn().mockResolvedValue({ result: 42 });- const handle = CustomTool({+ const tool = createCustomTool({...baseOptions,execute: noSessionExecute,});// Call without session — JS ignores extra params- const result = await handle.execute({ category: 'test' } as any);+ const result = await tool.execute({ category: 'test' } as any);expect(result.result).toBe(42);expect(noSessionExecute).toHaveBeenCalledWith({ category: 'test' });});@@ -135,7 +135,7 @@ describe('CustomTool', () => {it('should allow session-based execute (input + session)', async () => {const sessionExecute = vi.fn().mockResolvedValue({ userId: 'u1' });- const handle = CustomTool({+ const tool = createCustomTool({...baseOptions,execute: sessionExecute,});@@ -146,7 +146,7 @@ describe('CustomTool', () => {proxyExecute: vi.fn(),};- const result = await handle.execute({ category: 'test' }, mockSession);+ const result = await tool.execute({ category: 'test' }, mockSession);expect(result.userId).toBe('u1');expect(sessionExecute).toHaveBeenCalledWith({ category: 'test' }, mockSession);});@@ -158,7 +158,7 @@ describe('CustomTool', () => {// ────────────────────────────────────────────────────────────────describe('buildLocalToolsMap', () => {- const makeHandle = (slug: string): CustomToolHandle => ({+ const makeTool = (slug: string): CustomTool => ({slug,name: `Tool ${slug}`,description: `Description for ${slug}`,@@ -168,8 +168,8 @@ describe('buildLocalToolsMap', () => {});it('should create maps with both prefixed and original slug keys', () => {- const handles = [makeHandle('MY_TOOL'), makeHandle('OTHER_TOOL')];- const map = buildLocalToolsMap(handles);+ const tools = [makeTool('MY_TOOL'), makeTool('OTHER_TOOL')];+ const map = buildLocalToolsMap(tools);expect(map.byPrefixed.size).toBe(2);expect(map.byOriginal.size).toBe(2);@@ -184,16 +184,16 @@ describe('buildLocalToolsMap', () => {});it('should handle case-insensitive slugs (uppercased internally)', () => {- const handle = makeHandle('my_tool');- const map = buildLocalToolsMap([handle]);+ const tool = makeTool('my_tool');+ const map = buildLocalToolsMap([tool]);expect(map.byOriginal.has('MY_TOOL')).toBe(true);expect(map.byPrefixed.has('LOCAL_MY_TOOL')).toBe(true);});it('should throw on duplicate slugs', () => {- const handles = [makeHandle('DUPE'), makeHandle('DUPE')];- expect(() => buildLocalToolsMap(handles)).toThrow('duplicate slug "DUPE"');+ const tools = [makeTool('DUPE'), makeTool('DUPE')];+ expect(() => buildLocalToolsMap(tools)).toThrow('duplicate slug "DUPE"');});});@@ -203,18 +203,18 @@ describe('buildLocalToolsMap', () => {// ────────────────────────────────────────────────────────────────describe('serializeLocalTools', () => {- it('should serialize handles into backend format', () => {- const handle: CustomToolHandle = {+ it('should serialize tools into backend format', () => {+ const tool: CustomTool = {slug: 'GET_DATA',name: 'Get Data',description: 'Gets some data',- connectedToolkit: 'my_toolkit',+ toolkit: 'my_toolkit',inputSchema: { type: 'object', properties: { id: { type: 'string' } } },inputParams: z.object({ id: z.string() }),execute: vi.fn(),};- const result = serializeLocalTools([handle]);+ const result = serializeLocalTools([tool]);expect(result).toEqual([{@@ -227,8 +227,8 @@ describe('serializeLocalTools', () => {]);});- it('should omit toolkit when connectedToolkit not provided', () => {- const handle: CustomToolHandle = {+ it('should omit toolkit when not provided', () => {+ const tool: CustomTool = {slug: 'NO_TOOLKIT',name: 'No Toolkit',description: 'No toolkit tool',@@ -237,7 +237,7 @@ describe('serializeLocalTools', () => {execute: vi.fn(),};- const result = serializeLocalTools([handle]);+ const result = serializeLocalTools([tool]);expect(result[0]).not.toHaveProperty('toolkit');});});diff --git a/ts/packages/core/test/models/customToolRouting.test.ts b/ts/packages/core/test/models/customToolRouting.test.tsindex d11accbc2..1ccf9bf1d 100644--- a/ts/packages/core/test/models/customToolRouting.test.ts+++ b/ts/packages/core/test/models/customToolRouting.test.ts@@ -2,11 +2,11 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import { z } from 'zod/v3';import { ToolRouter } from '../../src/models/ToolRouter';import { ToolRouterSession } from '../../src/models/ToolRouterSession';-import { CustomTool, buildLocalToolsMap } from '../../src/models/CustomTool';+import { createCustomTool, buildLocalToolsMap } from '../../src/models/CustomTool';import { MockProvider } from '../utils/mocks/provider.mock';import ComposioClient from '@composio/client';import { Tools } from '../../src/models/Tools';-import type { CustomToolHandle } from '../../src/types/customTool.types';+import type { CustomTool } from '../../src/types/customTool.types';// Mock telemetryvi.mock('../../src/telemetry/Telemetry', () => ({@@ -65,7 +65,7 @@ const createMockClient = () => ({// Execute returns data directly (simplified API)const localExecute = vi.fn().mockResolvedValue({ local_result: true });-const customToolHandle = CustomTool({+const customToolHandle = createCustomTool({slug: 'GET_USER_CONTEXT',name: 'Get user context',description: 'Retrieve user preferences',@@ -77,11 +77,11 @@ const sessionExecute = vi.fn().mockImplementation(async (input: any, session: anuserId: session.userId,}));-const sessionToolHandle = CustomTool({+const sessionToolHandle = createCustomTool({slug: 'GET_AD_ACCOUNTS',name: 'Get ad accounts',description: 'Get ad account IDs',- connectedToolkit: 'meta_ads',+ toolkit: 'meta_ads',inputParams: z.object({ fields: z.string() }),execute: sessionExecute,});@@ -91,7 +91,7 @@ const sessionToolHandle = CustomTool({const createSessionWithProvider = (client: ReturnType<typeof createMockClient>,provider: MockProvider,- customTools: CustomToolHandle[]+ customTools: CustomTool[]) => {return new ToolRouterSession(client as unknown as ComposioClient,@@ -146,7 +146,7 @@ describe('ToolRouter.create() with customTools', () => {]);});- it('should include toolkit in local_tools when connectedToolkit is present', async () => {+ it('should include toolkit in local_tools when toolkit is present', async () => {await router.create('user_1', {customTools: [sessionToolHandle],});@@ -182,7 +182,7 @@ describe('ToolRouterSession execution routing', () => {const createSession = (client: ReturnType<typeof createMockClient>,- customTools: CustomToolHandle[] = []+ customTools: CustomTool[] = []) => {const localToolsMap = customTools.length ? buildLocalToolsMap(customTools) : undefined;@@ -282,7 +282,7 @@ describe('ToolRouterSession execution routing', () => {return { inner_result: inner.data };});- const chainedTool = CustomTool({+ const chainedTool = createCustomTool({slug: 'CHAINED_TOOL',name: 'Chained',description: 'Calls another tool',@@ -303,7 +303,7 @@ describe('ToolRouterSession execution routing', () => {describe('session.execute() — error handling', () => {it('should catch errors thrown by execute function and return error response', async () => {- const throwingTool = CustomTool({+ const throwingTool = createCustomTool({slug: 'THROWING_TOOL',name: 'Throwing',description: 'Throws an error',@@ -325,7 +325,7 @@ describe('ToolRouterSession execution routing', () => {category: input.category,}));- const toolWithDefaults = CustomTool({+ const toolWithDefaults = createCustomTool({slug: 'DEFAULTS_TOOL',name: 'Defaults',description: 'Tool with default values',@@ -345,7 +345,7 @@ describe('ToolRouterSession execution routing', () => {});it('should return validation error for invalid input', async () => {- const strictTool = CustomTool({+ const strictTool = createCustomTool({slug: 'STRICT_TOOL',name: 'Strict',description: 'Tool with strict input',@@ -361,7 +361,7 @@ describe('ToolRouterSession execution routing', () => {});it('should handle non-Error throws gracefully', async () => {- const throwingTool = CustomTool({+ const throwingTool = createCustomTool({slug: 'STRING_THROW',name: 'String throw',description: 'Throws a string',@@ -479,7 +479,7 @@ describe('ToolRouterSession execution routing', () => {/** Helper: set up provider + session + capture executeFn + get latest Tools mock */const setupMultiExecute = async (client: ReturnType<typeof createMockClient>,- customTools: CustomToolHandle[]+ customTools: CustomTool[]) => {const provider = new MockProvider();captureExecuteFn(provider);@@ -585,7 +585,7 @@ describe('ToolRouterSession execution routing', () => {});it('should still succeed when one local tool errors in a mixed batch', async () => {- const throwingHandle = CustomTool({+ const throwingHandle = createCustomTool({slug: 'MIXED_THROWER',name: 'Throws in batch',description: 'Throws',@@ -670,7 +670,7 @@ describe('ToolRouterSession execution routing', () => {// Track call timing to verify parallelismconst callOrder: string[] = [];- const slowLocalHandle = CustomTool({+ const slowLocalHandle = createCustomTool({slug: 'SLOW_LOCAL',name: 'Slow local',description: 'Slow',