@composio/openai-agents 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,172 @@
1
+ import { BaseAgenticProvider } from "@composio/core";
2
+ import { tool } from "@openai/agents";
3
+
4
+ //#region src/index.ts
5
+ /**
6
+ * OpenAI Agents Provider
7
+ * To be used with the @openai/agents package
8
+ *
9
+ * Author: Musthaq Ahamad <musthaq@composio.dev>
10
+ * Reference: https://openai.github.io/openai-agents-js/
11
+ *
12
+ * This provider provides a set of tools for interacting with OpenAI's Agents API.
13
+ *
14
+ * @packageDocumentation
15
+ * @module providers/openai-agents
16
+ */
17
+ var OpenAIAgentsProvider = class extends BaseAgenticProvider {
18
+ name = "openai-agents";
19
+ strict;
20
+ /**
21
+ * Creates a new instance of the OpenAIAgentsProvider.
22
+ *
23
+ * This provider enables integration with the @openai/agents package,
24
+ * allowing Composio tools to be used with OpenAI Agents.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Initialize the OpenAIAgentsProvider
29
+ * const provider = new OpenAIAgentsProvider();
30
+ *
31
+ * // Use with Composio
32
+ * const composio = new Composio({
33
+ * apiKey: 'your-api-key',
34
+ * provider: new OpenAIAgentsProvider()
35
+ * });
36
+ *
37
+ * // Use the provider to wrap tools for @openai/agents
38
+ * const agentTools = provider.wrapTools(composioTools, composio.tools.execute);
39
+ * ```
40
+ */
41
+ constructor(options) {
42
+ super();
43
+ this.strict = options?.strict ?? false;
44
+ }
45
+ /**
46
+ * Transform MCP URL response into Anthropic-specific format.
47
+ * By default, Anthropic uses the standard format (same as default),
48
+ * but this method is here to show providers can customize if needed.
49
+ *
50
+ * @param data - The MCP URL response data
51
+ * @returns Standard MCP server response format
52
+ */
53
+ wrapMcpServerResponse(data) {
54
+ return data.map((item) => ({
55
+ url: new URL(item.url),
56
+ name: item.name
57
+ }));
58
+ }
59
+ /**
60
+ * Wraps a Composio tool in a OpenAI Agents tool format.
61
+ *
62
+ * This method transforms a Composio tool definition into the format
63
+ * expected by @openai/agents for function calling.
64
+ *
65
+ * @param {ComposioTool} composioTool - The Composio tool to wrap
66
+ * @param {ExecuteToolFn} executeTool - Function to execute the tool
67
+ * @returns {OpenAIAgentsTool} The wrapped OpenAI Agents tool
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Wrap a single tool for use with Vercel AI SDK
72
+ * const composioTool = {
73
+ * slug: 'SEARCH_TOOL',
74
+ * description: 'Search for information',
75
+ * inputParameters: {
76
+ * type: 'object',
77
+ * properties: {
78
+ * query: { type: 'string' }
79
+ * },
80
+ * required: ['query']
81
+ * }
82
+ * };
83
+ *
84
+ * // Create a Vercel tool using the provider
85
+ * const vercelTool = provider.wrapTool(
86
+ * composioTool,
87
+ * composio.tools.execute
88
+ * );
89
+ *
90
+ * // Use with Vercel AI SDK
91
+ * import { StreamingTextResponse, Message } from 'ai';
92
+ * import { OpenAI } from 'openai';
93
+ *
94
+ * export async function POST(req: Request) {
95
+ * const { messages } = await req.json();
96
+ * const openai = new OpenAI();
97
+ *
98
+ * const response = await openai.chat.completions.create({
99
+ * model: 'gpt-4',
100
+ * messages,
101
+ * tools: [vercelTool]
102
+ * });
103
+ *
104
+ * return new StreamingTextResponse(response.choices[0].message);
105
+ * }
106
+ * ```
107
+ */
108
+ wrapTool(composioTool, executeTool) {
109
+ return tool({
110
+ name: composioTool.slug,
111
+ description: composioTool.description ?? "",
112
+ parameters: {
113
+ type: "object",
114
+ properties: composioTool.inputParameters?.properties || {},
115
+ required: composioTool.inputParameters?.required || [],
116
+ additionalProperties: true
117
+ },
118
+ strict: false,
119
+ execute: async (params) => {
120
+ const input = typeof params === "string" ? JSON.parse(params) : params;
121
+ return await executeTool(composioTool.slug, input);
122
+ }
123
+ });
124
+ }
125
+ /**
126
+ * Wraps a list of Composio tools as a OpenAI Agents tool collection.
127
+ *
128
+ * This method transforms multiple Composio tool definitions into the format
129
+ * expected by OpenAI Agents for function calling, organizing them
130
+ * into a dictionary keyed by tool slug.
131
+ *
132
+ * @param {ComposioTool[]} tools - Array of Composio tools to wrap
133
+ * @param {ExecuteToolFn} executeTool - Function to execute the tools
134
+ * @returns {OpenAIAgentsToolCollection} Dictionary of wrapped tools in OpenAI Agents format
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Get OpenAI Agents tools from Composio
139
+ * const composio = new Composio({
140
+ * apiKey: 'your-api-key',
141
+ * provider: new OpenAIAgentsProvider()
142
+ * });
143
+ *
144
+ * const tools = await composio.tools.get('default', {
145
+ * toolkits: ['github'],
146
+ * });
147
+ *
148
+ * import { OpenAI } from '@openai/agents';
149
+ *
150
+ * export async function POST(req: Request) {
151
+ * const { messages } = await req.json();
152
+ * const openai = new OpenAI();
153
+ *
154
+ * const response = await openai.chat.completions.create({
155
+ * model: 'gpt-4',
156
+ * messages,
157
+ * tools: openaiAgentsTools
158
+ * });
159
+ *
160
+ * return new StreamingTextResponse(response.choices[0].message);
161
+ * }
162
+ * ```
163
+ */
164
+ wrapTools(tools, executeTool) {
165
+ return tools.map((tool$1) => {
166
+ return this.wrapTool(tool$1, executeTool);
167
+ });
168
+ }
169
+ };
170
+
171
+ //#endregion
172
+ export { OpenAIAgentsProvider };
package/package.json CHANGED
@@ -1,17 +1,25 @@
1
1
  {
2
2
  "name": "@composio/openai-agents",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "",
5
- "main": "dist/index.js",
6
- "type": "module",
5
+ "main": "dist/index.mjs",
7
6
  "publishConfig": {
8
7
  "access": "public"
9
8
  },
10
9
  "exports": {
11
10
  ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
- "require": "./dist/index.cjs"
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ },
19
+ "default": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
15
23
  }
16
24
  },
17
25
  "files": [
@@ -22,23 +30,23 @@
22
30
  "author": "",
23
31
  "license": "ISC",
24
32
  "peerDependencies": {
25
- "@composio/core": "0.4.0",
33
+ "@composio/core": "0.5.1",
26
34
  "@openai/agents": "^0.1.3",
27
35
  "zod": "^4.1.0"
28
36
  },
29
37
  "devDependencies": {
30
38
  "@openai/agents": "^0.1.3",
31
- "tsup": "^8.5.0",
39
+ "tsdown": "^0.18.4",
32
40
  "typescript": "^5.9.2",
33
41
  "zod": "^4.1.0",
34
42
  "vitest": "^3.2.4",
35
- "@composio/core": "0.4.0"
43
+ "@composio/core": "0.5.1"
36
44
  },
37
45
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
38
46
  "scripts": {
39
47
  "clean": "git clean -xdf node_modules",
40
- "build": "tsup",
48
+ "build": "tsdown",
41
49
  "test": "vitest run"
42
50
  },
43
- "types": "dist/index.d.ts"
51
+ "types": "dist/index.d.mts"
44
52
  }
package/dist/index.d.ts DELETED
@@ -1,146 +0,0 @@
1
- import { BaseAgenticProvider, McpServerGetResponse, McpUrlResponse, Tool as Tool$1, ExecuteToolFn } from '@composio/core';
2
- import { Tool } from '@openai/agents';
3
-
4
- /**
5
- * OpenAI Agents Provider
6
- * To be used with the @openai/agents package
7
- *
8
- * Author: Musthaq Ahamad <musthaq@composio.dev>
9
- * Reference: https://openai.github.io/openai-agents-js/
10
- *
11
- * This provider provides a set of tools for interacting with OpenAI's Agents API.
12
- *
13
- * @packageDocumentation
14
- * @module providers/openai-agents
15
- */
16
-
17
- type OpenAIAgentsToolCollection = Array<Tool>;
18
- declare class OpenAIAgentsProvider extends BaseAgenticProvider<OpenAIAgentsToolCollection, Tool, McpServerGetResponse> {
19
- readonly name = "openai-agents";
20
- private strict;
21
- /**
22
- * Creates a new instance of the OpenAIAgentsProvider.
23
- *
24
- * This provider enables integration with the @openai/agents package,
25
- * allowing Composio tools to be used with OpenAI Agents.
26
- *
27
- * @example
28
- * ```typescript
29
- * // Initialize the OpenAIAgentsProvider
30
- * const provider = new OpenAIAgentsProvider();
31
- *
32
- * // Use with Composio
33
- * const composio = new Composio({
34
- * apiKey: 'your-api-key',
35
- * provider: new OpenAIAgentsProvider()
36
- * });
37
- *
38
- * // Use the provider to wrap tools for @openai/agents
39
- * const agentTools = provider.wrapTools(composioTools, composio.tools.execute);
40
- * ```
41
- */
42
- constructor(options?: {
43
- strict?: boolean;
44
- });
45
- /**
46
- * Transform MCP URL response into Anthropic-specific format.
47
- * By default, Anthropic uses the standard format (same as default),
48
- * but this method is here to show providers can customize if needed.
49
- *
50
- * @param data - The MCP URL response data
51
- * @returns Standard MCP server response format
52
- */
53
- wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
54
- /**
55
- * Wraps a Composio tool in a OpenAI Agents tool format.
56
- *
57
- * This method transforms a Composio tool definition into the format
58
- * expected by @openai/agents for function calling.
59
- *
60
- * @param {ComposioTool} composioTool - The Composio tool to wrap
61
- * @param {ExecuteToolFn} executeTool - Function to execute the tool
62
- * @returns {OpenAIAgentsTool} The wrapped OpenAI Agents tool
63
- *
64
- * @example
65
- * ```typescript
66
- * // Wrap a single tool for use with Vercel AI SDK
67
- * const composioTool = {
68
- * slug: 'SEARCH_TOOL',
69
- * description: 'Search for information',
70
- * inputParameters: {
71
- * type: 'object',
72
- * properties: {
73
- * query: { type: 'string' }
74
- * },
75
- * required: ['query']
76
- * }
77
- * };
78
- *
79
- * // Create a Vercel tool using the provider
80
- * const vercelTool = provider.wrapTool(
81
- * composioTool,
82
- * composio.tools.execute
83
- * );
84
- *
85
- * // Use with Vercel AI SDK
86
- * import { StreamingTextResponse, Message } from 'ai';
87
- * import { OpenAI } from 'openai';
88
- *
89
- * export async function POST(req: Request) {
90
- * const { messages } = await req.json();
91
- * const openai = new OpenAI();
92
- *
93
- * const response = await openai.chat.completions.create({
94
- * model: 'gpt-4',
95
- * messages,
96
- * tools: [vercelTool]
97
- * });
98
- *
99
- * return new StreamingTextResponse(response.choices[0].message);
100
- * }
101
- * ```
102
- */
103
- wrapTool(composioTool: Tool$1, executeTool: ExecuteToolFn): Tool;
104
- /**
105
- * Wraps a list of Composio tools as a OpenAI Agents tool collection.
106
- *
107
- * This method transforms multiple Composio tool definitions into the format
108
- * expected by OpenAI Agents for function calling, organizing them
109
- * into a dictionary keyed by tool slug.
110
- *
111
- * @param {ComposioTool[]} tools - Array of Composio tools to wrap
112
- * @param {ExecuteToolFn} executeTool - Function to execute the tools
113
- * @returns {OpenAIAgentsToolCollection} Dictionary of wrapped tools in OpenAI Agents format
114
- *
115
- * @example
116
- * ```typescript
117
- * // Get OpenAI Agents tools from Composio
118
- * const composio = new Composio({
119
- * apiKey: 'your-api-key',
120
- * provider: new OpenAIAgentsProvider()
121
- * });
122
- *
123
- * const tools = await composio.tools.get('default', {
124
- * toolkits: ['github'],
125
- * });
126
- *
127
- * import { OpenAI } from '@openai/agents';
128
- *
129
- * export async function POST(req: Request) {
130
- * const { messages } = await req.json();
131
- * const openai = new OpenAI();
132
- *
133
- * const response = await openai.chat.completions.create({
134
- * model: 'gpt-4',
135
- * messages,
136
- * tools: openaiAgentsTools
137
- * });
138
- *
139
- * return new StreamingTextResponse(response.choices[0].message);
140
- * }
141
- * ```
142
- */
143
- wrapTools(tools: Tool$1[], executeTool: ExecuteToolFn): OpenAIAgentsToolCollection;
144
- }
145
-
146
- export { OpenAIAgentsProvider };
package/dist/index.js DELETED
@@ -1,161 +0,0 @@
1
- // src/index.ts
2
- import {
3
- BaseAgenticProvider
4
- } from "@composio/core";
5
- import { tool as createOpenAIAgentTool } from "@openai/agents";
6
- var OpenAIAgentsProvider = class extends BaseAgenticProvider {
7
- name = "openai-agents";
8
- strict;
9
- /**
10
- * Creates a new instance of the OpenAIAgentsProvider.
11
- *
12
- * This provider enables integration with the @openai/agents package,
13
- * allowing Composio tools to be used with OpenAI Agents.
14
- *
15
- * @example
16
- * ```typescript
17
- * // Initialize the OpenAIAgentsProvider
18
- * const provider = new OpenAIAgentsProvider();
19
- *
20
- * // Use with Composio
21
- * const composio = new Composio({
22
- * apiKey: 'your-api-key',
23
- * provider: new OpenAIAgentsProvider()
24
- * });
25
- *
26
- * // Use the provider to wrap tools for @openai/agents
27
- * const agentTools = provider.wrapTools(composioTools, composio.tools.execute);
28
- * ```
29
- */
30
- constructor(options) {
31
- super();
32
- this.strict = options?.strict ?? false;
33
- }
34
- /**
35
- * Transform MCP URL response into Anthropic-specific format.
36
- * By default, Anthropic uses the standard format (same as default),
37
- * but this method is here to show providers can customize if needed.
38
- *
39
- * @param data - The MCP URL response data
40
- * @returns Standard MCP server response format
41
- */
42
- wrapMcpServerResponse(data) {
43
- return data.map((item) => ({
44
- url: new URL(item.url),
45
- name: item.name
46
- }));
47
- }
48
- /**
49
- * Wraps a Composio tool in a OpenAI Agents tool format.
50
- *
51
- * This method transforms a Composio tool definition into the format
52
- * expected by @openai/agents for function calling.
53
- *
54
- * @param {ComposioTool} composioTool - The Composio tool to wrap
55
- * @param {ExecuteToolFn} executeTool - Function to execute the tool
56
- * @returns {OpenAIAgentsTool} The wrapped OpenAI Agents tool
57
- *
58
- * @example
59
- * ```typescript
60
- * // Wrap a single tool for use with Vercel AI SDK
61
- * const composioTool = {
62
- * slug: 'SEARCH_TOOL',
63
- * description: 'Search for information',
64
- * inputParameters: {
65
- * type: 'object',
66
- * properties: {
67
- * query: { type: 'string' }
68
- * },
69
- * required: ['query']
70
- * }
71
- * };
72
- *
73
- * // Create a Vercel tool using the provider
74
- * const vercelTool = provider.wrapTool(
75
- * composioTool,
76
- * composio.tools.execute
77
- * );
78
- *
79
- * // Use with Vercel AI SDK
80
- * import { StreamingTextResponse, Message } from 'ai';
81
- * import { OpenAI } from 'openai';
82
- *
83
- * export async function POST(req: Request) {
84
- * const { messages } = await req.json();
85
- * const openai = new OpenAI();
86
- *
87
- * const response = await openai.chat.completions.create({
88
- * model: 'gpt-4',
89
- * messages,
90
- * tools: [vercelTool]
91
- * });
92
- *
93
- * return new StreamingTextResponse(response.choices[0].message);
94
- * }
95
- * ```
96
- */
97
- wrapTool(composioTool, executeTool) {
98
- return createOpenAIAgentTool({
99
- name: composioTool.slug,
100
- description: composioTool.description ?? "",
101
- parameters: {
102
- type: "object",
103
- properties: composioTool.inputParameters?.properties || {},
104
- required: composioTool.inputParameters?.required || [],
105
- additionalProperties: true
106
- },
107
- strict: false,
108
- execute: async (params) => {
109
- const input = typeof params === "string" ? JSON.parse(params) : params;
110
- return await executeTool(composioTool.slug, input);
111
- }
112
- });
113
- }
114
- /**
115
- * Wraps a list of Composio tools as a OpenAI Agents tool collection.
116
- *
117
- * This method transforms multiple Composio tool definitions into the format
118
- * expected by OpenAI Agents for function calling, organizing them
119
- * into a dictionary keyed by tool slug.
120
- *
121
- * @param {ComposioTool[]} tools - Array of Composio tools to wrap
122
- * @param {ExecuteToolFn} executeTool - Function to execute the tools
123
- * @returns {OpenAIAgentsToolCollection} Dictionary of wrapped tools in OpenAI Agents format
124
- *
125
- * @example
126
- * ```typescript
127
- * // Get OpenAI Agents tools from Composio
128
- * const composio = new Composio({
129
- * apiKey: 'your-api-key',
130
- * provider: new OpenAIAgentsProvider()
131
- * });
132
- *
133
- * const tools = await composio.tools.get('default', {
134
- * toolkits: ['github'],
135
- * });
136
- *
137
- * import { OpenAI } from '@openai/agents';
138
- *
139
- * export async function POST(req: Request) {
140
- * const { messages } = await req.json();
141
- * const openai = new OpenAI();
142
- *
143
- * const response = await openai.chat.completions.create({
144
- * model: 'gpt-4',
145
- * messages,
146
- * tools: openaiAgentsTools
147
- * });
148
- *
149
- * return new StreamingTextResponse(response.choices[0].message);
150
- * }
151
- * ```
152
- */
153
- wrapTools(tools, executeTool) {
154
- return tools.map((tool) => {
155
- return this.wrapTool(tool, executeTool);
156
- });
157
- }
158
- };
159
- export {
160
- OpenAIAgentsProvider
161
- };