import { BaseNonAgenticProvider, ExecuteToolFnOptions, ExecuteToolModifiers, McpUrlResponse, OpenAIProvider, Tool } from "@composio/core"; import { OpenAI } from "openai"; //#region src/OpenAIResponsesProvider.d.ts type OpenAiTool = OpenAI.Responses.FunctionTool; type OpenAiMcpTool = OpenAI.Responses.Tool.Mcp; type OpenAiToolCollection = Array; type OpenAIResponsesProviderOptions = { /** * Whether to use strict mode for function calls * @default false */ strict?: boolean; }; /** * OpenAI-specific MCP server response format */ declare class OpenAIResponsesProvider extends BaseNonAgenticProvider { readonly name = "openai"; private strict; /** * Creates a new instance of the OpenAIProvider. * * This is the default provider for the Composio SDK and is automatically * available without additional installation. * * @param {OpenAIResponsesProviderOptions} [options] - Optional provider options * @returns {OpenAIResponsesProvider} The OpenAIResponsesProvider instance * * @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 OpenAIResponsesProvider({ * strict: true // Optional, default is false * }) * }); * ``` */ constructor(options?: OpenAIResponsesProviderOptions); /** * Transform MCP URL response into OpenAI Responses-specific format. * OpenAI Responses uses a custom format with type, server_label, server_url, and require_approval fields. * * @param data - The MCP URL response data * @param serverName - Name of the MCP server * @returns OpenAI-specific MCP server response format */ wrapMcpServerResponse(data: McpUrlResponse): OpenAiMcpTool[]; /** * 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); * ``` */ wrapTool(tool: Tool): OpenAiTool; /** * 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); * ``` */ wrapTools: (tools: Tool[]) => OpenAiToolCollection; /** * 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} 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)); * ``` */ executeToolCall(userId: string, tool: OpenAI.Responses.ResponseFunctionToolCall, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise; /** * Handles tool calls from OpenAI's response. * * This method processes tool calls from an OpenAI response, * executes each tool call, and returns the results. * * @param {string} userId - The user ID for authentication and tracking * @param {OpenAI.ChatCompletion} chatCompletion - The response from OpenAI * @param {ExecuteToolFnOptions} [options] - Optional execution options * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers * @returns {Promise} Array of tool execution results as JSON strings * * @example * ```typescript * // Handle tool calls from a response * const response = await openai.responses.create({ * model: 'gpt-4o-2024-11-20', * input: 'What is the capital of France?', * tools: await composio.tools.get(composioTools) * }); * * const inputItems = await composio.provider.handleToolCalls( * 'user123', * response.output * ); * console.log(inputItems); // Array of tool execution results * * // Submit tool outputs back to OpenAI * const response = await openai.responses.create({ * model: 'gpt-4o-2024-11-20', * input: inputItems, * tools: await composio.tools.get(composioTools), * }); * ``` * ``` */ handleToolCalls(userId: string, toolCalls: OpenAI.Responses.ResponseOutputItem[], options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise; /** * Handles all the tool calls from the OpenAI Responses API. * * This method processes tool calls from an OpenAI Responses request, * executes each tool call, and returns the tool outputs for submission. * * @param {string} userId - The user ID for authentication and tracking * @param {OpenAI.Responses.Response} response - The Responses request object containing tool calls * @param {ExecuteToolFnOptions} [options] - Optional execution options * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers * @returns {Promise} Array of tool outputs for submission * * @example * ```typescript * // Handle tool calls from an OpenAI response * const response = await openai.responses.create({ * model: 'gpt-4o-2024-11-20', * input: 'What is the capital of France?', * tools: await composio.tools.get(composioTools), * tool_choice: 'auto', * }); * * const inputItems = await composio.provider.handleResponse('default', response); * * // Submit tool outputs back to OpenAI * const response = await openai.responses.create({ * model: 'gpt-4o-2024-11-20', * input: inputItems, * tools: await composio.tools.get(composioTools), * }); * ``` */ handleResponse(userId: string, response: OpenAI.Responses.Response, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise; } //#endregion export { OpenAIProvider, OpenAIResponsesProvider };