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
Improved TSDoc/JSDoc Documentation with Examples (#19)
devin-ai-integration[bot]f1442026e129
diff --git a/.changeset/five-ties-tell.md b/.changeset/five-ties-tell.mdnew file mode 100644index 000000000..f1d5dba14--- /dev/null+++ b/.changeset/five-ties-tell.md@@ -0,0 +1,12 @@+---+'@composio/cloudflare': patch+'@composio/anthropic': patch+'@composio/langchain': patch+'@composio/google': patch+'@composio/vercel': patch+'@composio/core': patch+'@composio/mastra': patch+'@composio/openai': patch+---++Update tsdocs across all the functionsdiff --git a/packages/core/src/composio.ts b/packages/core/src/composio.tsindex b9ce07f28..2d7c62561 100644--- a/packages/core/src/composio.ts+++ b/packages/core/src/composio.ts@@ -56,13 +56,36 @@ export class Composio<TProvider extends BaseComposioProvider<unknown, unknown> =connectedAccounts: ConnectedAccounts;/**- * @param {Object} config Configuration for the Composio SDK.- * @param {string} config.apiKey The API key for the Composio SDK.- * @param {string} config.baseURL The base URL for the Composio SDK.- * @param {string} config.runtime The runtime for the Composio SDK.- * @param {boolean} config.allowTracking Whether to allow analytics / tracking. Defaults to true.- * @param {boolean} config.allowTracing Whether to allow tracing. Defaults to true.- * @param {TProvider} config.provider The provider to use for this Composio instance.+ * Creates a new instance of the Composio SDK.+ *+ * The constructor initializes the SDK with the provided configuration options,+ * sets up the API client, and initializes all core models (tools, toolkits, etc.).+ *+ * @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK+ * @param {string} [config.apiKey] - The API key for authenticating with the Composio API+ * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)+ * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics+ * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging+ * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)+ * @param {BaseTelemetryTransport} [config.telemetryTransport] - Custom telemetry transport implementation+ *+ * @example+ * ```typescript+ * // Initialize with default configuration+ * const composio = new Composio();+ *+ * // Initialize with custom API key and base URL+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * baseURL: 'https://api.composio.dev'+ * });+ *+ * // Initialize with custom provider+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new CustomProvider()+ * });+ * ```*/constructor(config?: ComposioConfig<TProvider>) {const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(diff --git a/packages/core/src/models/ConnectedAccounts.ts b/packages/core/src/models/ConnectedAccounts.tsindex 3feb5f89a..4498b6636 100644--- a/packages/core/src/models/ConnectedAccounts.ts+++ b/packages/core/src/models/ConnectedAccounts.ts@@ -279,8 +279,21 @@ export class ConnectedAccounts {* Update the status of a connected account* @param {string} nanoid - Unique identifier of the connected account* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status- * @param {RequestOptions} options - Request options* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details+ *+ * @example+ * ```typescript+ * // Enable a connected account+ * const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {+ * enabled: true+ * });+ *+ * // Disable a connected account with a reason+ * const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {+ * enabled: false,+ * reason: 'Token expired'+ * });+ * ```*/async updateStatus(nanoid: string,@@ -292,8 +305,14 @@ export class ConnectedAccounts {/*** Enable a connected account* @param {string} nanoid - Unique identifier of the connected account- * @param {RequestOptions} options - Request options* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details+ *+ * @example+ * ```typescript+ * // Enable a previously disabled connected account+ * const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');+ * console.log(enabledAccount.isDisabled); // false+ * ```*/async enable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse> {return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });@@ -302,8 +321,20 @@ export class ConnectedAccounts {/*** Disable a connected account* @param {string} nanoid - Unique identifier of the connected account- * @param {RequestOptions} options - Request options* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details+ *+ * @example+ * ```typescript+ * // Disable a connected account+ * const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');+ * console.log(disabledAccount.isDisabled); // true+ *+ * // You can also use updateStatus with a reason+ * // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {+ * // enabled: false,+ * // reason: 'No longer needed'+ * // });+ * ```*/async disable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse> {return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });diff --git a/packages/core/src/models/CustomTools.ts b/packages/core/src/models/CustomTools.tsindex 5790606d9..492862543 100644--- a/packages/core/src/models/CustomTools.ts+++ b/packages/core/src/models/CustomTools.ts@@ -44,6 +44,26 @@ export class CustomTools {* This is just an in memory registry and is not persisted.* @param {CustomToolOptions} toolOptions CustomToolOptions* @returns {Tool} The tool created+ *+ * @example+ * ```typescript+ * // Create a custom tool with input parameters+ * const customTool = await composio.customTools.createTool({+ * name: 'My Custom Tool',+ * description: 'A tool that performs a custom operation',+ * slug: 'MY_CUSTOM_TOOL',+ * inputParams: z.object({+ * query: z.string().describe('The search query'),+ * limit: z.number().optional().describe('Maximum number of results')+ * }),+ * execute: async (input, authCredentials, executeToolRequest) => {+ * // Custom implementation logic+ * return {+ * data: { results: ['result1', 'result2'] }+ * };+ * }+ * });+ * ```*/async createTool(toolOptions: CustomToolOptions): Promise<Tool> {const { slug, execute, inputParams, name, description } = toolOptions;@@ -87,6 +107,17 @@ export class CustomTools {* Get all the custom tools from the registry.* @param {string[]} param0.toolSlugs The slugs of the tools to get* @returns {ToolList} The list of tools+ *+ * @example+ * ```typescript+ * // Get all custom tools+ * const allTools = await composio.customTools.getCustomTools({});+ *+ * // Get specific custom tools by slug+ * const specificTools = await composio.customTools.getCustomTools({+ * toolSlugs: ['MY_CUSTOM_TOOL', 'ANOTHER_CUSTOM_TOOL']+ * });+ * ```*/async getCustomTools({ toolSlugs }: { toolSlugs?: string[] }): Promise<ToolList> {const tools: Tool[] = [];@@ -111,6 +142,17 @@ export class CustomTools {* Get a custom tool by slug from the registry.* @param {string} slug The slug of the tool to get* @returns {Tool} The tool+ *+ * @example+ * ```typescript+ * // Get a specific custom tool by its slug+ * const myTool = await composio.customTools.getCustomToolBySlug('MY_CUSTOM_TOOL');+ * if (myTool) {+ * console.log(`Found tool: ${myTool.name}`);+ * } else {+ * console.log('Tool not found');+ * }+ * ```*/async getCustomToolBySlug(slug: string): Promise<Tool | undefined> {if (!slug) {diff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.tsindex 7ac3d80c0..a28568e7b 100644--- a/packages/core/src/models/Tools.ts+++ b/packages/core/src/models/Tools.ts@@ -642,9 +642,16 @@ export class Tools</*** Fetches the list of all available tools in the Composio SDK.*- * This method is mostly used by the CLI to get the list of tools.+ * This method is mostly used by the CLI to get the list of tools.* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.- * @returns {string} - The list of all available tools as a string+ * @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata+ *+ * @example+ * ```typescript+ * // Get all available tools as an enum+ * const toolsEnum = await composio.tools.getToolsEnum();+ * console.log(toolsEnum.items);+ * ```*/async getToolsEnum(): Promise<ToolRetrieveEnumResponse> {return this.client.tools.retrieveEnum();@@ -657,16 +664,43 @@ export class Tools<** @param {string} slug - The ID of the tool to find input for* @param {ToolGetInputParams} body - The parameters to be passed to the tool- * @returns+ * @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool+ *+ * @example+ * ```typescript+ * // Get input parameters for a specific tool+ * const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {+ * userId: 'default'+ * });+ * console.log(inputParams.schema);+ * ```*/async getInput(slug: string, body: ToolGetInputParams): Promise<ToolGetInputResponse> {return this.client.tools.getInput(slug, body);}/**- * Proxies a custom request to a toolkit/integration- * @param body- * @returns+ * Proxies a custom request to a toolkit/integration.+ *+ * This method allows sending custom requests to a specific toolkit or integration+ * when you need more flexibility than the standard tool execution methods provide.+ *+ * @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data+ * @returns {Promise<ToolProxyResponse>} The response from the proxied request+ *+ * @example+ * ```typescript+ * // Send a custom request to a toolkit+ * const response = await composio.tools.proxyExecute({+ * toolkitSlug: 'github',+ * userId: 'default',+ * data: {+ * endpoint: '/repos/owner/repo/issues',+ * method: 'GET'+ * }+ * });+ * console.log(response.data);+ * ```*/async proxyExecute(body: ToolProxyParams): Promise<ToolProxyResponse> {return this.client.tools.proxy(body);diff --git a/packages/core/src/provider/OpenAIProvider.ts b/packages/core/src/provider/OpenAIProvider.tsindex 3508a3dba..d9c3eca8b 100644--- a/packages/core/src/provider/OpenAIProvider.ts+++ b/packages/core/src/provider/OpenAIProvider.ts@@ -19,11 +19,57 @@ export type OpenAiTool = OpenAI.ChatCompletionTool;export type OpenAiToolCollection = Array<OpenAiTool>;export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection, OpenAiTool> {readonly name = 'openai';+/**- * Absract method to wrap a tool in the provider.- * This method is implemented by the provider.- * @param tool - The tool to wrap.- * @returns The wrapped tool.+ * Creates a new instance of the OpenAIProvider.+ *+ * This is the default provider for the Composio SDK and is automatically+ * available without additional installation.+ *+ * @example+ * ```typescript+ * // The OpenAIProvider is used by default when initializing Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key'+ * });+ *+ * // You can also explicitly specify it+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new OpenAIProvider()+ * });+ * ```+ */+ constructor() {+ super();+ }++ /**+ * Wraps a Composio tool in the OpenAI function calling format.+ *+ * This method transforms a Composio tool definition into the format+ * expected by OpenAI's function calling API.+ *+ * @param tool - The Composio tool to wrap+ * @returns The wrapped tool in OpenAI format+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with OpenAI+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * };+ *+ * const openAITool = provider.wrapTool(composioTool);+ * ```*/override wrapTool = (tool: Tool): OpenAiTool => {const formattedSchema: OpenAI.FunctionDefinition = {@@ -37,15 +83,79 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,};};+ /**+ * Wraps multiple Composio tools in the OpenAI function calling format.+ *+ * This method transforms a list of Composio tools into the format+ * expected by OpenAI's function calling API.+ *+ * @param tools - Array of Composio tools to wrap+ * @returns Array of wrapped tools in OpenAI format+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with OpenAI+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * }+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * }+ * }+ * }+ * ];+ *+ * const openAITools = provider.wrapTools(composioTools);+ * ```+ */override wrapTools = (tools: Tool[]): OpenAiToolCollection => {return tools.map(tool => this.wrapTool(tool));};/**- * Execute a tool call.- * @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool to execute.- * @param {string} userId - The user id.- * @returns {Promise<string>} The result of the tool call.+ * Executes a tool call from OpenAI's chat completion.+ *+ * This method processes a tool call from OpenAI's chat completion API,+ * executes the corresponding Composio tool, and returns the result.+ *+ * @param {string} userId - The user ID for authentication and tracking+ * @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI+ * @param {ExecuteToolFnOptions} [options] - Optional execution options+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers+ * @returns {Promise<string>} The result of the tool call as a JSON string+ *+ * @example+ * ```typescript+ * // Execute a tool call from OpenAI+ * const toolCall = {+ * id: 'call_abc123',+ * type: 'function',+ * function: {+ * name: 'SEARCH_TOOL',+ * arguments: '{"query":"composio documentation"}'+ * }+ * };+ *+ * const result = await provider.executeToolCall(+ * 'user123',+ * toolCall,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ * console.log(JSON.parse(result));+ * ```*/async executeToolCall(userId: string,@@ -64,11 +174,46 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,}/**- * Handle the tool call from the assistant.+ * Handles tool calls from OpenAI's chat completion response.*- * @param {OpenAI.ChatCompletion} chatCompletion - The chat completion object.- * @param {string} userId - The user id.- * @returns {Promise<string[]>} The results of the tool call.+ * This method processes tool calls from an OpenAI chat completion response,+ * executes each tool call, and returns the results.+ *+ * @param {string} userId - The user ID for authentication and tracking+ * @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI+ * @param {ExecuteToolFnOptions} [options] - Optional execution options+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers+ * @returns {Promise<string[]>} Array of tool execution results as JSON strings+ *+ * @example+ * ```typescript+ * // Handle tool calls from a chat completion response+ * const chatCompletion = {+ * choices: [+ * {+ * message: {+ * tool_calls: [+ * {+ * id: 'call_abc123',+ * type: 'function',+ * function: {+ * name: 'SEARCH_TOOL',+ * arguments: '{"query":"composio documentation"}'+ * }+ * }+ * ]+ * }+ * }+ * ]+ * };+ *+ * const results = await provider.handleToolCalls(+ * 'user123',+ * chatCompletion,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ * console.log(results); // Array of tool execution results+ * ```*/async handleToolCalls(userId: string,@@ -88,11 +233,51 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,}/**- * Handles all the tool calls from the assistant.+ * Handles all the tool calls from the OpenAI Assistant API.+ *+ * This method processes tool calls from an OpenAI Assistant run,+ * executes each tool call, and returns the tool outputs for submission.*- * @param {OpenAI.Beta.Threads.Run} run - The run object.- * @param {string} userId - The user id.- * @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} The tool outputs.+ * @param {string} userId - The user ID for authentication and tracking+ * @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls+ * @param {ExecuteToolFnOptions} [options] - Optional execution options+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers+ * @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission+ *+ * @example+ * ```typescript+ * // Handle tool calls from an OpenAI Assistant run+ * const run = {+ * id: 'run_abc123',+ * required_action: {+ * submit_tool_outputs: {+ * tool_calls: [+ * {+ * id: 'call_xyz789',+ * type: 'function',+ * function: {+ * name: 'SEARCH_TOOL',+ * arguments: '{"query":"composio documentation"}'+ * }+ * }+ * ]+ * }+ * }+ * };+ *+ * const toolOutputs = await provider.handleAssistantMessage(+ * 'user123',+ * run,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Submit tool outputs back to OpenAI+ * await openai.beta.threads.runs.submitToolOutputs(+ * thread.id,+ * run.id,+ * { tool_outputs: toolOutputs }+ * );+ * ```*/async handleAssistantMessage(userId: string,@@ -128,11 +313,43 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,/*** Waits for the assistant stream and handles the tool calls.*- * @param {OpenAI} client - The OpenAI client.- * @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The run stream.- * @param {OpenAI.Beta.Threads.Thread} thread - The thread object.- * @param {string} userId - The user id.- * @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} The run stream.+ * This method processes an OpenAI Assistant stream, handles any tool calls+ * that require action, and yields each event from the stream. It's designed+ * for streaming Assistant responses while handling tool calls in real-time.+ *+ * @param {string} userId - The user ID for authentication and tracking+ * @param {OpenAI} client - The OpenAI client instance+ * @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream+ * @param {OpenAI.Beta.Threads.Thread} thread - The thread object+ * @param {ExecuteToolFnOptions} [options] - Optional execution options+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers+ * @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events+ *+ * @example+ * ```typescript+ * // Process an OpenAI Assistant stream with tool calls+ * const thread = await openai.beta.threads.create();+ * const runStream = openai.beta.threads.runs.stream(thread.id, {+ * assistant_id: 'asst_abc123',+ * tools: provider.wrapTools(composioTools)+ * });+ *+ * // Process the stream and handle tool calls+ * const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(+ * 'user123',+ * openai,+ * runStream,+ * thread,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Consume the stream events+ * for await (const event of streamProcessor) {+ * if (event.event === 'thread.message.delta') {+ * console.log(event.data.delta.content);+ * }+ * }+ * ```*/async *waitAndHandleAssistantStreamToolCalls(userId: string,@@ -212,11 +429,45 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,/*** Waits for the assistant tool calls and handles them.*- * @param {OpenAI} client - The OpenAI client.- * @param {OpenAI.Beta.Threads.Run} run - The run object.- * @param {OpenAI.Beta.Threads.Thread} thread - The thread object.- * @param {string} userId - The user id.- * @returns {Promise<OpenAI.Beta.Threads.Run>} The run object.+ * This method polls an OpenAI Assistant run until it completes or requires action,+ * handles any tool calls, and returns the final run object. It's designed for+ * non-streaming Assistant interactions.+ *+ * @param {string} userId - The user ID for authentication and tracking+ * @param {OpenAI} client - The OpenAI client instance+ * @param {OpenAI.Beta.Threads.Run} run - The initial run object+ * @param {OpenAI.Beta.Threads.Thread} thread - The thread object+ * @param {ExecuteToolFnOptions} [options] - Optional execution options+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers+ * @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion+ *+ * @example+ * ```typescript+ * // Process an OpenAI Assistant run with tool calls+ * const thread = await openai.beta.threads.create();+ * await openai.beta.threads.messages.create(thread.id, {+ * role: 'user',+ * content: 'Find information about Composio'+ * });+ *+ * let run = await openai.beta.threads.runs.create(thread.id, {+ * assistant_id: 'asst_abc123',+ * tools: provider.wrapTools(composioTools)+ * });+ *+ * // Wait for the run to complete, handling any tool calls+ * run = await provider.waitAndHandleAssistantToolCalls(+ * 'user123',+ * openai,+ * run,+ * thread,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Get the final messages after run completion+ * const messages = await openai.beta.threads.messages.list(thread.id);+ * console.log(messages.data[0].content);+ * ```*/async waitAndHandleAssistantToolCalls(userId: string,diff --git a/packages/providers/anthropic/src/index.ts b/packages/providers/anthropic/src/index.tsindex d68f1715c..3aa0ed3cb 100644--- a/packages/providers/anthropic/src/index.ts+++ b/packages/providers/anthropic/src/index.ts@@ -51,6 +51,31 @@ export class AnthropicProvider extends BaseNonAgenticProvider<readonly name = 'anthropic';private chacheTools: boolean = false;+ /**+ * Creates a new instance of the AnthropicProvider.+ *+ * @param {Object} [options] - Configuration options for the provider+ * @param {boolean} [options.cacheTools=false] - Whether to cache tools using Anthropic's ephemeral cache+ *+ * @example+ * ```typescript+ * // Initialize with default settings (no caching)+ * const provider = new AnthropicProvider();+ *+ * // Initialize with tool caching enabled+ * const providerWithCaching = new AnthropicProvider({+ * cacheTools: true+ * });+ *+ * // Use with Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new AnthropicProvider({+ * cacheTools: true+ * })+ * });+ * ```+ */constructor(options?: { cacheTools?: boolean }) {super();this.chacheTools = options?.cacheTools ?? false;@@ -58,9 +83,31 @@ export class AnthropicProvider extends BaseNonAgenticProvider<}/**- * Wrap a tool in the Anthropic format.- * @param tool - The tool to wrap.- * @returns The wrapped tool in Anthropic format.+ * Wraps a Composio tool in the Anthropic format.+ *+ * This method transforms a Composio tool definition into the format+ * expected by Anthropic's Claude API for tool use.+ *+ * @param tool - The Composio tool to wrap+ * @returns The wrapped tool in Anthropic format+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with Anthropic+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * };+ *+ * const anthropicTool = provider.wrapTool(composioTool);+ * ```*/override wrapTool(tool: ComposioTool): AnthropicTool {return {@@ -76,21 +123,78 @@ export class AnthropicProvider extends BaseNonAgenticProvider<}/**- * Wrap a list of tools in the Anthropic format.- * @param tools - The tools to wrap.- * @returns The wrapped tools in Anthropic format.+ * Wraps a list of Composio tools in the Anthropic format.+ *+ * This method transforms multiple Composio tool definitions into the format+ * expected by Anthropic's Claude API for tool use.+ *+ * @param tools - Array of Composio tools to wrap+ * @returns Array of wrapped tools in Anthropic format+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with Anthropic+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * }+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * }+ * }+ * }+ * ];+ *+ * const anthropicTools = provider.wrapTools(composioTools);+ * ```*/override wrapTools(tools: ComposioTool[]): AnthropicToolCollection {return tools.map(tool => this.wrapTool(tool));}/**- * Execute a tool call from Anthropic.- * @param userId - The user ID+ * Executes a tool call from Anthropic's Claude API.+ *+ * This method processes a tool call from Anthropic's Claude API,+ * executes the corresponding Composio tool, and returns the result.+ *+ * @param userId - The user ID for authentication and tracking* @param toolUse - The tool use object from Anthropic* @param options - Additional options for tool execution* @param modifiers - Modifiers for tool execution- * @returns The result of the tool execution as a string+ * @returns The result of the tool execution as a JSON string+ *+ * @example+ * ```typescript+ * // Execute a tool call from Anthropic+ * const toolUse = {+ * type: 'tool_use',+ * id: 'tu_abc123',+ * name: 'SEARCH_TOOL',+ * input: {+ * query: 'composio documentation'+ * }+ * };+ *+ * const result = await provider.executeToolCall(+ * 'user123',+ * toolUse,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ * console.log(JSON.parse(result));+ * ```*/async executeToolCall(userId: string,@@ -109,12 +213,44 @@ export class AnthropicProvider extends BaseNonAgenticProvider<}/**- * Handle tool calls from Anthropic's message response- * @param userId - The user ID+ * Handles tool calls from Anthropic's message response.+ *+ * This method processes tool calls from an Anthropic message response,+ * extracts the tool use blocks, executes each tool call, and returns the results.+ *+ * @param userId - The user ID for authentication and tracking* @param message - The message response from Anthropic* @param options - Additional options for tool execution* @param modifiers - Modifiers for tool execution- * @returns Array of tool execution results+ * @returns Array of tool execution results as JSON strings+ *+ * @example+ * ```typescript+ * // Handle tool calls from an Anthropic message response+ * const anthropic = new Anthropic({ apiKey: 'your-anthropic-api-key' });+ *+ * const message = await anthropic.messages.create({+ * model: 'claude-3-opus-20240229',+ * max_tokens: 1024,+ * tools: provider.wrapTools(composioTools),+ * messages: [+ * {+ * role: 'user',+ * content: 'Search for information about Composio'+ * }+ * ]+ * });+ *+ * // Process any tool calls in the response+ * const results = await provider.handleToolCalls(+ * 'user123',+ * message,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Use the results to continue the conversation+ * console.log(results);+ * ```*/async handleToolCalls(userId: string,diff --git a/packages/providers/cloudflare/src/index.ts b/packages/providers/cloudflare/src/index.tsindex d7f6b5298..5d8095460 100644--- a/packages/providers/cloudflare/src/index.ts+++ b/packages/providers/cloudflare/src/index.ts@@ -26,6 +26,56 @@ export class CloudflareProvider extends BaseNonAgenticProvider<> {readonly name = 'cloudflare';+ /**+ * Creates a new instance of the CloudflareProvider.+ *+ * This provider enables integration with Cloudflare AI,+ * allowing Composio tools to be used with Cloudflare Workers AI.+ *+ * @example+ * ```typescript+ *+ * // Use with Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new CloudflareProvider()+ * });+ *+ * // Use the provider to wrap tools for Cloudflare AI+ * const cloudflareTools = provider.wrapTools(composioTools);+ * ```+ */+ constructor() {+ super();+ }++ /**+ * Wraps a Composio tool in the Cloudflare AI format.+ *+ * This method transforms a Composio tool definition into the format+ * expected by Cloudflare's AI API for function calling.+ *+ * @param tool - The Composio tool to wrap+ * @returns The wrapped tool in Cloudflare AI format+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with Cloudflare AI+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string', description: 'Search query' }+ * },+ * required: ['query']+ * }+ * };+ *+ * const cloudflareTool = provider.wrapTool(composioTool);+ * ```+ */wrapTool(tool: Tool): AiTextGenerationToolInput {const formattedSchema: AiTextGenerationToolInput['function'] = {name: tool.slug!,@@ -48,6 +98,56 @@ export class CloudflareProvider extends BaseNonAgenticProvider<return cloudflareTool;}+ /**+ * Wraps a list of Composio tools in the Cloudflare AI format.+ *+ * This method transforms multiple Composio tool definitions into the format+ * expected by Cloudflare's AI API for function calling, organizing them+ * into a dictionary keyed by tool slug.+ *+ * @param tools - Array of Composio tools to wrap+ * @returns Dictionary of wrapped tools in Cloudflare AI format+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with Cloudflare AI+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * },+ * required: ['location']+ * }+ * }+ * ];+ *+ * const cloudflareTools = provider.wrapTools(composioTools);+ *+ * // Use with Cloudflare Workers AI+ * // In your Cloudflare Worker:+ * const ai = new Ai(env.AI);+ *+ * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {+ * messages: [{ role: 'user', content: 'How is the weather in New York?' }],+ * tools: cloudflareTools+ * });+ * ```+ */wrapTools(tools: Tool[]): AiToolCollection {return tools.reduce((acc, tool) => ({@@ -59,10 +159,50 @@ export class CloudflareProvider extends BaseNonAgenticProvider<}/**- * Execute a tool call.- * @param tool - The tool to execute.- * @param userId - The user id.- * @returns The results of the tool call.+ * Executes a tool call from Cloudflare AI.+ *+ * This method processes a function call from Cloudflare's AI API,+ * executes the corresponding Composio tool, and returns the result.+ *+ * @param userId - The user ID for authentication and tracking+ * @param tool - The tool call object with name and arguments+ * @param options - Optional execution options like connected account ID+ * @param modifiers - Optional execution modifiers for tool behavior+ * @returns The result of the tool execution as a JSON string+ *+ * @example+ * ```typescript+ * // Execute a tool call from Cloudflare AI+ * const toolCall = {+ * name: 'SEARCH_TOOL',+ * arguments: {+ * query: 'composio documentation'+ * }+ * };+ *+ * const result = await provider.executeToolCall(+ * 'user123',+ * toolCall,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Parse the result and use it in your application+ * const searchResults = JSON.parse(result);+ * console.log(searchResults);+ *+ * // You can also use the result to continue the conversation+ * // In your Cloudflare Worker:+ * const ai = new Ai(env.AI);+ *+ * await ai.run('@cf/meta/llama-3-8b-instruct', {+ * messages: [+ * { role: 'user', content: 'Search for Composio' },+ * { role: 'assistant', content: '', tool_calls: [{ name: 'SEARCH_TOOL', arguments: JSON.stringify({ query: 'composio documentation' }) }] },+ * { role: 'tool', tool_call_id: '1', content: result }+ * ],+ * tools: cloudflareTools+ * });+ * ```*/async executeToolCall(userId: string,diff --git a/packages/providers/google/src/index.ts b/packages/providers/google/src/index.tsindex 78d48a73f..94c87cce2 100644--- a/packages/providers/google/src/index.ts+++ b/packages/providers/google/src/index.ts@@ -44,9 +44,64 @@ export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollecreadonly name = 'google';/**- * Wrap a Composio tool in the Google GenAI function declaration format.- * @param tool - The Composio tool to wrap.- * @returns The wrapped tool in Google GenAI format.+ * Creates a new instance of the GoogleProvider.+ *+ * This provider enables integration with Google's GenAI API,+ * supporting both the Gemini Developer API and Vertex AI implementations.+ *+ * @example+ * ```typescript+ * // Initialize the Google provider+ * const provider = new GoogleProvider();+ *+ * // Use with Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new GoogleProvider()+ * });+ *+ * // Use the provider to wrap tools for Google GenAI+ * const googleTools = provider.wrapTools(composioTools);+ * ```+ */+ constructor() {+ super();+ }++ /**+ * Wraps a Composio tool in the Google GenAI function declaration format.+ *+ * This method transforms a Composio tool definition into the format+ * expected by Google's GenAI API for function calling.+ *+ * @param tool - The Composio tool to wrap+ * @returns The wrapped tool in Google GenAI format+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with Google GenAI+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * };+ *+ * const googleTool = provider.wrapTool(composioTool);+ * // Use with Google GenAI SDK+ * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');+ * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });+ *+ * const result = await model.generateContent({+ * contents: [{ role: 'user', parts: [{ text: 'Search for Composio' }] }],+ * tools: [googleTool]+ * });+ * ```*/wrapTool(tool: Tool): GoogleTool {return {@@ -62,21 +117,101 @@ export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollec}/**- * Wrap a list of Composio tools in the Google GenAI function declaration format.- * @param tools - The Composio tools to wrap.- * @returns The wrapped tools in Google GenAI format.+ * Wraps a list of Composio tools in the Google GenAI function declaration format.+ *+ * This method transforms multiple Composio tool definitions into the format+ * expected by Google's GenAI API for function calling.+ *+ * @param tools - Array of Composio tools to wrap+ * @returns Array of wrapped tools in Google GenAI format+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with Google GenAI+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * },+ * required: ['location']+ * }+ * }+ * ];+ *+ * const googleTools = provider.wrapTools(composioTools);+ *+ * // Use with Google GenAI SDK+ * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');+ * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });+ *+ * const result = await model.generateContent({+ * contents: [{ role: 'user', parts: [{ text: 'How is the weather in New York?' }] }],+ * tools: googleTools+ * });+ * ```*/wrapTools(tools: Tool[]): GoogleGenAIToolCollection {return tools.map(tool => this.wrapTool(tool));}/**- * Execute a tool call from Google GenAI.- * @param userId - The user id.- * @param tool - The Google GenAI function call to execute.- * @param options - Optional execution options.- * @param modifiers - Optional execution modifiers.- * @returns The result of the tool call as a JSON string.+ * Executes a tool call from Google GenAI.+ *+ * This method processes a function call from Google's GenAI API,+ * executes the corresponding Composio tool, and returns the result.+ *+ * @param userId - The user ID for authentication and tracking+ * @param tool - The Google GenAI function call to execute+ * @param options - Optional execution options like connected account ID+ * @param modifiers - Optional execution modifiers for tool behavior+ * @returns The result of the tool execution as a JSON string+ *+ * @example+ * ```typescript+ * // Execute a tool call from Google GenAI+ * const functionCall = {+ * name: 'SEARCH_TOOL',+ * args: {+ * query: 'composio documentation'+ * }+ * };+ *+ * const result = await provider.executeToolCall(+ * 'user123',+ * functionCall,+ * { connectedAccountId: 'conn_xyz456' }+ * );+ *+ * // Parse the result and use it in your application+ * const searchResults = JSON.parse(result);+ * console.log(searchResults);+ *+ * // You can also use the result to continue the conversation+ * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');+ * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });+ *+ * await model.generateContent({+ * contents: [+ * { role: 'user', parts: [{ text: 'Search for Composio' }] },+ * { role: 'model', parts: [{ functionResponse: { name: 'SEARCH_TOOL', response: result } }] }+ * ]+ * });+ * ```*/async executeToolCall(userId: string,diff --git a/packages/providers/langchain/src/index.ts b/packages/providers/langchain/src/index.tsindex 3eb2131bf..550dff45c 100644--- a/packages/providers/langchain/src/index.ts+++ b/packages/providers/langchain/src/index.ts@@ -18,11 +18,83 @@ export class LangchainProvider extends BaseAgenticProvider<DynamicStructuredTool> {readonly name = 'langchain';+/**- * Abstract method to wrap a tool in the provider.- * This method is implemented by the provider.- * @param tool - The tool to wrap.- * @returns The wrapped tool.+ * Creates a new instance of the LangchainProvider.+ *+ * This provider enables integration with the Langchain framework,+ * allowing Composio tools to be used with Langchain agents and chains.+ *+ * @example+ * ```typescript+ * // Initialize the Langchain provider+ * const provider = new LangchainProvider();+ *+ * // Use with Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new LangchainProvider()+ * });+ *+ * // Use the provider to wrap tools for Langchain+ * const langchainTools = provider.wrapTools(composioTools, composio.tools.execute);+ * ```+ */+ constructor() {+ super();+ }++ /**+ * Wraps a Composio tool in the Langchain DynamicStructuredTool format.+ *+ * This method transforms a Composio tool definition into a Langchain+ * DynamicStructuredTool that can be used with Langchain agents and chains.+ *+ * @param tool - The Composio tool to wrap+ * @param executeTool - Function to execute the tool+ * @returns The wrapped tool as a Langchain DynamicStructuredTool+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with Langchain+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * toolkit: { name: 'search_toolkit' },+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * };+ *+ * // Create a Langchain tool using the provider+ * const langchainTool = provider.wrapTool(+ * composioTool,+ * composio.tools.execute+ * );+ *+ * // Use with Langchain+ * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';+ * import { ChatOpenAI } from '@langchain/openai';+ *+ * const model = new ChatOpenAI({ temperature: 0 });+ * const agent = await createOpenAIFunctionsAgent({+ * llm: model,+ * tools: [langchainTool]+ * });+ *+ * const executor = new AgentExecutor({+ * agent,+ * tools: [langchainTool]+ * });+ *+ * const result = await executor.invoke({+ * input: "Search for information about Composio"+ * });+ * ```*/wrapTool(tool: Tool, executeTool: ExecuteToolFn): DynamicStructuredTool {const toolName = tool.slug;@@ -47,6 +119,68 @@ export class LangchainProvider extends BaseAgenticProvider<});}+ /**+ * Wraps a list of Composio tools in the Langchain DynamicStructuredTool format.+ *+ * This method transforms multiple Composio tool definitions into Langchain+ * DynamicStructuredTools that can be used with Langchain agents and chains.+ *+ * @param tools - Array of Composio tools to wrap+ * @param executeTool - Function to execute the tools+ * @returns Array of wrapped tools as Langchain DynamicStructuredTools+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with Langchain+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * toolkit: { name: 'search_toolkit' },+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * toolkit: { name: 'weather_toolkit' },+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * },+ * required: ['location']+ * }+ * }+ * ];+ *+ * // Create Langchain tools using the provider+ * const langchainTools = provider.wrapTools(+ * composioTools,+ * composio.tools.execute+ * );+ *+ * // Use with Langchain+ * import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';+ * import { ChatOpenAI } from '@langchain/openai';+ *+ * const model = new ChatOpenAI({ temperature: 0 });+ * const agent = await createOpenAIFunctionsAgent({+ * llm: model,+ * tools: langchainTools+ * });+ *+ * const executor = new AgentExecutor({+ * agent,+ * tools: langchainTools+ * });+ * ```+ */wrapTools(tools: Tool[], executeTool: ExecuteToolFn): LangChainToolCollection {return tools.map(tool => this.wrapTool(tool, executeTool));}diff --git a/packages/providers/vercel/src/index.ts b/packages/providers/vercel/src/index.tsindex db634cc94..ffc089b80 100644--- a/packages/providers/vercel/src/index.ts+++ b/packages/providers/vercel/src/index.ts@@ -19,9 +19,78 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Vereadonly name = 'vercel';/**- * Wrap a Composio tool in a Vercel tool.- * @param {ComposioTool} composioTool - The Composio tool to wrap.- * @returns {VercelTool} The wrapped Vercel tool.+ * Creates a new instance of the VercelProvider.+ *+ * This provider enables integration with the Vercel AI SDK,+ * allowing Composio tools to be used with Vercel AI applications.+ *+ * @example+ * ```typescript+ * // Initialize the Vercel provider+ * const provider = new VercelProvider();+ *+ * // Use with Composio+ * const composio = new Composio({+ * apiKey: 'your-api-key',+ * provider: new VercelProvider()+ * });+ *+ * // Use the provider to wrap tools for Vercel AI SDK+ * const vercelTools = provider.wrapTools(composioTools, composio.tools.execute);+ * ```+ */+ constructor() {+ super();+ }++ /**+ * Wraps a Composio tool in a Vercel AI SDK tool format.+ *+ * This method transforms a Composio tool definition into the format+ * expected by Vercel's AI SDK for function calling.+ *+ * @param {ComposioTool} composioTool - The Composio tool to wrap+ * @param {ExecuteToolFn} executeTool - Function to execute the tool+ * @returns {VercelTool} The wrapped Vercel tool+ *+ * @example+ * ```typescript+ * // Wrap a single tool for use with Vercel AI SDK+ * const composioTool = {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * };+ *+ * // Create a Vercel tool using the provider+ * const vercelTool = provider.wrapTool(+ * composioTool,+ * composio.tools.execute+ * );+ *+ * // Use with Vercel AI SDK+ * import { StreamingTextResponse, Message } from 'ai';+ * import { OpenAI } from 'openai';+ *+ * export async function POST(req: Request) {+ * const { messages } = await req.json();+ * const openai = new OpenAI();+ *+ * const response = await openai.chat.completions.create({+ * model: 'gpt-4',+ * messages,+ * tools: [vercelTool]+ * });+ *+ * return new StreamingTextResponse(response.choices[0].message);+ * }+ * ```*/wrapTool(composioTool: ComposioTool, executeTool: ExecuteToolFn): VercelTool {return tool({@@ -35,9 +104,67 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Ve}/**- * Wrap a list of Composio tools as a Vercel tool collection.- * @param {ComposioTool[]} tools - The list of Composio tools to wrap.- * @returns {VercelToolCollection} The wrapped Vercel tool collection.+ * Wraps a list of Composio tools as a Vercel AI SDK tool collection.+ *+ * This method transforms multiple Composio tool definitions into the format+ * expected by Vercel's AI SDK for function calling, organizing them+ * into a dictionary keyed by tool slug.+ *+ * @param {ComposioTool[]} tools - Array of Composio tools to wrap+ * @param {ExecuteToolFn} executeTool - Function to execute the tools+ * @returns {VercelToolCollection} Dictionary of wrapped tools in Vercel AI SDK format+ *+ * @example+ * ```typescript+ * // Wrap multiple tools for use with Vercel AI SDK+ * const composioTools = [+ * {+ * slug: 'SEARCH_TOOL',+ * description: 'Search for information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * query: { type: 'string' }+ * },+ * required: ['query']+ * }+ * },+ * {+ * slug: 'WEATHER_TOOL',+ * description: 'Get weather information',+ * inputParameters: {+ * type: 'object',+ * properties: {+ * location: { type: 'string' }+ * },+ * required: ['location']+ * }+ * }+ * ];+ *+ * // Create Vercel tools using the provider+ * const vercelTools = provider.wrapTools(+ * composioTools,+ * composio.tools.execute+ * );+ *+ * // Use with Vercel AI SDK in a Next.js API route+ * import { StreamingTextResponse } from 'ai';+ * import { OpenAI } from 'openai';+ *+ * export async function POST(req: Request) {+ * const { messages } = await req.json();+ * const openai = new OpenAI();+ *+ * const response = await openai.chat.completions.create({+ * model: 'gpt-4',+ * messages,+ * tools: Object.values(vercelTools)+ * });+ *+ * return new StreamingTextResponse(response.choices[0].message);+ * }+ * ```*/wrapTools(tools: ComposioTool[], executeTool: ExecuteToolFn): VercelToolCollection {return tools.reduce((acc, tool) => {