@composio/openai-agents 0.3.4 → 0.5.0

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.cjs CHANGED
@@ -1,184 +1,172 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ let _composio_core = require("@composio/core");
2
+ let _openai_agents = require("@openai/agents");
19
3
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- OpenAIAgentsProvider: () => OpenAIAgentsProvider
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_core = require("@composio/core");
27
- var import_agents = require("@openai/agents");
28
- var OpenAIAgentsProvider = class extends import_core.BaseAgenticProvider {
29
- name = "openai-agents";
30
- strict;
31
- /**
32
- * Creates a new instance of the OpenAIAgentsProvider.
33
- *
34
- * This provider enables integration with the @openai/agents package,
35
- * allowing Composio tools to be used with OpenAI Agents.
36
- *
37
- * @example
38
- * ```typescript
39
- * // Initialize the OpenAIAgentsProvider
40
- * const provider = new OpenAIAgentsProvider();
41
- *
42
- * // Use with Composio
43
- * const composio = new Composio({
44
- * apiKey: 'your-api-key',
45
- * provider: new OpenAIAgentsProvider()
46
- * });
47
- *
48
- * // Use the provider to wrap tools for @openai/agents
49
- * const agentTools = provider.wrapTools(composioTools, composio.tools.execute);
50
- * ```
51
- */
52
- constructor(options) {
53
- super();
54
- this.strict = options?.strict ?? false;
55
- }
56
- /**
57
- * Transform MCP URL response into Anthropic-specific format.
58
- * By default, Anthropic uses the standard format (same as default),
59
- * but this method is here to show providers can customize if needed.
60
- *
61
- * @param data - The MCP URL response data
62
- * @returns Standard MCP server response format
63
- */
64
- wrapMcpServerResponse(data) {
65
- return data.map((item) => ({
66
- url: new URL(item.url),
67
- name: item.name
68
- }));
69
- }
70
- /**
71
- * Wraps a Composio tool in a OpenAI Agents tool format.
72
- *
73
- * This method transforms a Composio tool definition into the format
74
- * expected by @openai/agents for function calling.
75
- *
76
- * @param {ComposioTool} composioTool - The Composio tool to wrap
77
- * @param {ExecuteToolFn} executeTool - Function to execute the tool
78
- * @returns {OpenAIAgentsTool} The wrapped OpenAI Agents tool
79
- *
80
- * @example
81
- * ```typescript
82
- * // Wrap a single tool for use with Vercel AI SDK
83
- * const composioTool = {
84
- * slug: 'SEARCH_TOOL',
85
- * description: 'Search for information',
86
- * inputParameters: {
87
- * type: 'object',
88
- * properties: {
89
- * query: { type: 'string' }
90
- * },
91
- * required: ['query']
92
- * }
93
- * };
94
- *
95
- * // Create a Vercel tool using the provider
96
- * const vercelTool = provider.wrapTool(
97
- * composioTool,
98
- * composio.tools.execute
99
- * );
100
- *
101
- * // Use with Vercel AI SDK
102
- * import { StreamingTextResponse, Message } from 'ai';
103
- * import { OpenAI } from 'openai';
104
- *
105
- * export async function POST(req: Request) {
106
- * const { messages } = await req.json();
107
- * const openai = new OpenAI();
108
- *
109
- * const response = await openai.chat.completions.create({
110
- * model: 'gpt-4',
111
- * messages,
112
- * tools: [vercelTool]
113
- * });
114
- *
115
- * return new StreamingTextResponse(response.choices[0].message);
116
- * }
117
- * ```
118
- */
119
- wrapTool(composioTool, executeTool) {
120
- return (0, import_agents.tool)({
121
- name: composioTool.slug,
122
- description: composioTool.description ?? "",
123
- parameters: {
124
- type: "object",
125
- properties: composioTool.inputParameters?.properties || {},
126
- required: composioTool.inputParameters?.required || [],
127
- additionalProperties: true
128
- },
129
- strict: false,
130
- execute: async (params) => {
131
- const input = typeof params === "string" ? JSON.parse(params) : params;
132
- return await executeTool(composioTool.slug, input);
133
- }
134
- });
135
- }
136
- /**
137
- * Wraps a list of Composio tools as a OpenAI Agents tool collection.
138
- *
139
- * This method transforms multiple Composio tool definitions into the format
140
- * expected by OpenAI Agents for function calling, organizing them
141
- * into a dictionary keyed by tool slug.
142
- *
143
- * @param {ComposioTool[]} tools - Array of Composio tools to wrap
144
- * @param {ExecuteToolFn} executeTool - Function to execute the tools
145
- * @returns {OpenAIAgentsToolCollection} Dictionary of wrapped tools in OpenAI Agents format
146
- *
147
- * @example
148
- * ```typescript
149
- * // Get OpenAI Agents tools from Composio
150
- * const composio = new Composio({
151
- * apiKey: 'your-api-key',
152
- * provider: new OpenAIAgentsProvider()
153
- * });
154
- *
155
- * const tools = await composio.tools.get('default', {
156
- * toolkits: ['github'],
157
- * });
158
- *
159
- * import { OpenAI } from '@openai/agents';
160
- *
161
- * export async function POST(req: Request) {
162
- * const { messages } = await req.json();
163
- * const openai = new OpenAI();
164
- *
165
- * const response = await openai.chat.completions.create({
166
- * model: 'gpt-4',
167
- * messages,
168
- * tools: openaiAgentsTools
169
- * });
170
- *
171
- * return new StreamingTextResponse(response.choices[0].message);
172
- * }
173
- * ```
174
- */
175
- wrapTools(tools, executeTool) {
176
- return tools.map((tool) => {
177
- return this.wrapTool(tool, executeTool);
178
- });
179
- }
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 _composio_core.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 (0, _openai_agents.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) => {
166
+ return this.wrapTool(tool, executeTool);
167
+ });
168
+ }
180
169
  };
181
- // Annotate the CommonJS export names for ESM import in node:
182
- 0 && (module.exports = {
183
- OpenAIAgentsProvider
184
- });
170
+
171
+ //#endregion
172
+ exports.OpenAIAgentsProvider = OpenAIAgentsProvider;