@composio/vercel 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,207 +1,192 @@
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 ai = require("ai");
19
3
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- VercelProvider: () => VercelProvider
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_core = require("@composio/core");
27
- var import_ai = require("ai");
28
- var VercelProvider = class extends import_core.BaseAgenticProvider {
29
- name = "vercel";
30
- strict;
31
- /**
32
- * Creates a new instance of the VercelProvider.
33
- *
34
- * This provider enables integration with the Vercel AI SDK,
35
- * allowing Composio tools to be used with Vercel AI applications.
36
- *
37
- * @example
38
- * ```typescript
39
- * // Initialize the Vercel provider
40
- * const provider = new VercelProvider();
41
- *
42
- * // Use with Composio
43
- * const composio = new Composio({
44
- * apiKey: 'your-api-key',
45
- * provider: new VercelProvider()
46
- * });
47
- *
48
- * // Use the provider to wrap tools for Vercel AI SDK
49
- * const vercelTools = provider.wrapTools(composioTools, composio.tools.execute);
50
- * ```
51
- */
52
- constructor({ strict = false } = {}) {
53
- super();
54
- this.strict = strict;
55
- }
56
- /**
57
- * Wraps a Composio tool in a Vercel AI SDK tool format.
58
- *
59
- * This method transforms a Composio tool definition into the format
60
- * expected by Vercel's AI SDK for function calling.
61
- *
62
- * @param {ComposioTool} composioTool - The Composio tool to wrap
63
- * @param {ExecuteToolFn} executeTool - Function to execute the tool
64
- * @returns {VercelTool} The wrapped Vercel tool
65
- *
66
- * @example
67
- * ```typescript
68
- * // Wrap a single tool for use with Vercel AI SDK
69
- * const composioTool = {
70
- * slug: 'SEARCH_TOOL',
71
- * description: 'Search for information',
72
- * inputParameters: {
73
- * type: 'object',
74
- * properties: {
75
- * query: { type: 'string' }
76
- * },
77
- * required: ['query']
78
- * }
79
- * };
80
- *
81
- * // Create a Vercel tool using the provider
82
- * const vercelTool = provider.wrapTool(
83
- * composioTool,
84
- * composio.tools.execute
85
- * );
86
- *
87
- * // Use with Vercel AI SDK
88
- * import { StreamingTextResponse, Message } from 'ai';
89
- * import { OpenAI } from 'openai';
90
- *
91
- * export async function POST(req: Request) {
92
- * const { messages } = await req.json();
93
- * const openai = new OpenAI();
94
- *
95
- * const response = await openai.chat.completions.create({
96
- * model: 'gpt-4',
97
- * messages,
98
- * tools: [vercelTool]
99
- * });
100
- *
101
- * return new StreamingTextResponse(response.choices[0].message);
102
- * }
103
- * ```
104
- */
105
- wrapTool(composioTool, executeTool) {
106
- const inputParams = composioTool.inputParameters;
107
- const parameters = this.strict && inputParams?.type === "object" ? (0, import_core.removeNonRequiredProperties)(
108
- inputParams
109
- ) : inputParams ?? {};
110
- const inputParametersSchema = (0, import_core.jsonSchemaToZodSchema)(parameters);
111
- return (0, import_ai.tool)({
112
- description: composioTool.description,
113
- inputSchema: inputParametersSchema,
114
- execute: async (params) => {
115
- const input = typeof params === "string" ? JSON.parse(params) : params;
116
- return await executeTool(composioTool.slug, input);
117
- }
118
- });
119
- }
120
- /**
121
- * Wraps a list of Composio tools as a Vercel AI SDK tool collection.
122
- *
123
- * This method transforms multiple Composio tool definitions into the format
124
- * expected by Vercel's AI SDK for function calling, organizing them
125
- * into a dictionary keyed by tool slug.
126
- *
127
- * @param {ComposioTool[]} tools - Array of Composio tools to wrap
128
- * @param {ExecuteToolFn} executeTool - Function to execute the tools
129
- * @returns {VercelToolCollection} Dictionary of wrapped tools in Vercel AI SDK format
130
- *
131
- * @example
132
- * ```typescript
133
- * // Wrap multiple tools for use with Vercel AI SDK
134
- * const composioTools = [
135
- * {
136
- * slug: 'SEARCH_TOOL',
137
- * description: 'Search for information',
138
- * inputParameters: {
139
- * type: 'object',
140
- * properties: {
141
- * query: { type: 'string' }
142
- * },
143
- * required: ['query']
144
- * }
145
- * },
146
- * {
147
- * slug: 'WEATHER_TOOL',
148
- * description: 'Get weather information',
149
- * inputParameters: {
150
- * type: 'object',
151
- * properties: {
152
- * location: { type: 'string' }
153
- * },
154
- * required: ['location']
155
- * }
156
- * }
157
- * ];
158
- *
159
- * // Create Vercel tools using the provider
160
- * const vercelTools = provider.wrapTools(
161
- * composioTools,
162
- * composio.tools.execute
163
- * );
164
- *
165
- * // Use with Vercel AI SDK in a Next.js API route
166
- * import { StreamingTextResponse } from 'ai';
167
- * import { OpenAI } from 'openai';
168
- *
169
- * export async function POST(req: Request) {
170
- * const { messages } = await req.json();
171
- * const openai = new OpenAI();
172
- *
173
- * const response = await openai.chat.completions.create({
174
- * model: 'gpt-4',
175
- * messages,
176
- * tools: Object.values(vercelTools)
177
- * });
178
- *
179
- * return new StreamingTextResponse(response.choices[0].message);
180
- * }
181
- * ```
182
- */
183
- wrapTools(tools, executeTool) {
184
- return tools.reduce((acc, tool2) => {
185
- acc[tool2.slug] = this.wrapTool(tool2, executeTool);
186
- return acc;
187
- }, {});
188
- }
189
- /**
190
- * Transform MCP URL response into Anthropic-specific format.
191
- * By default, Anthropic uses the standard format (same as default),
192
- * but this method is here to show providers can customize if needed.
193
- *
194
- * @param data - The MCP URL response data
195
- * @returns Standard MCP server response format
196
- */
197
- wrapMcpServerResponse(data) {
198
- return data.map((item) => ({
199
- url: new URL(item.url),
200
- name: item.name
201
- }));
202
- }
4
+ //#region src/index.ts
5
+ /**
6
+ * Vercel AI Provider
7
+ * To be used with the Vercel AI SDK
8
+ *
9
+ * Author: Musthaq Ahamad <musthaq@composio.dev>
10
+ * Legacy Reference: https://github.com/ComposioHQ/composio/blob/master/js/src/frameworks/vercel.ts
11
+ *
12
+ * This provider provides a set of tools for interacting with Vercel AI SDK.
13
+ *
14
+ * @packageDocumentation
15
+ * @module providers/vercel
16
+ */
17
+ var VercelProvider = class extends _composio_core.BaseAgenticProvider {
18
+ name = "vercel";
19
+ strict;
20
+ /**
21
+ * Creates a new instance of the VercelProvider.
22
+ *
23
+ * This provider enables integration with the Vercel AI SDK,
24
+ * allowing Composio tools to be used with Vercel AI applications.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Initialize the Vercel provider
29
+ * const provider = new VercelProvider();
30
+ *
31
+ * // Use with Composio
32
+ * const composio = new Composio({
33
+ * apiKey: 'your-api-key',
34
+ * provider: new VercelProvider()
35
+ * });
36
+ *
37
+ * // Use the provider to wrap tools for Vercel AI SDK
38
+ * const vercelTools = provider.wrapTools(composioTools, composio.tools.execute);
39
+ * ```
40
+ */
41
+ constructor({ strict = false } = {}) {
42
+ super();
43
+ this.strict = strict;
44
+ }
45
+ /**
46
+ * Wraps a Composio tool in a Vercel AI SDK tool format.
47
+ *
48
+ * This method transforms a Composio tool definition into the format
49
+ * expected by Vercel's AI SDK for function calling.
50
+ *
51
+ * @param {ComposioTool} composioTool - The Composio tool to wrap
52
+ * @param {ExecuteToolFn} executeTool - Function to execute the tool
53
+ * @returns {VercelTool} The wrapped Vercel tool
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Wrap a single tool for use with Vercel AI SDK
58
+ * const composioTool = {
59
+ * slug: 'SEARCH_TOOL',
60
+ * description: 'Search for information',
61
+ * inputParameters: {
62
+ * type: 'object',
63
+ * properties: {
64
+ * query: { type: 'string' }
65
+ * },
66
+ * required: ['query']
67
+ * }
68
+ * };
69
+ *
70
+ * // Create a Vercel tool using the provider
71
+ * const vercelTool = provider.wrapTool(
72
+ * composioTool,
73
+ * composio.tools.execute
74
+ * );
75
+ *
76
+ * // Use with Vercel AI SDK
77
+ * import { StreamingTextResponse, Message } from 'ai';
78
+ * import { OpenAI } from 'openai';
79
+ *
80
+ * export async function POST(req: Request) {
81
+ * const { messages } = await req.json();
82
+ * const openai = new OpenAI();
83
+ *
84
+ * const response = await openai.chat.completions.create({
85
+ * model: 'gpt-4',
86
+ * messages,
87
+ * tools: [vercelTool]
88
+ * });
89
+ *
90
+ * return new StreamingTextResponse(response.choices[0].message);
91
+ * }
92
+ * ```
93
+ */
94
+ wrapTool(composioTool, executeTool) {
95
+ const inputParams = composioTool.inputParameters;
96
+ const inputParametersSchema = (0, _composio_core.jsonSchemaToZodSchema)(this.strict && inputParams?.type === "object" ? (0, _composio_core.removeNonRequiredProperties)(inputParams) : inputParams ?? {});
97
+ return (0, ai.tool)({
98
+ description: composioTool.description,
99
+ inputSchema: inputParametersSchema,
100
+ execute: async (params) => {
101
+ const input = typeof params === "string" ? JSON.parse(params) : params;
102
+ return await executeTool(composioTool.slug, input);
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * Wraps a list of Composio tools as a Vercel AI SDK tool collection.
108
+ *
109
+ * This method transforms multiple Composio tool definitions into the format
110
+ * expected by Vercel's AI SDK for function calling, organizing them
111
+ * into a dictionary keyed by tool slug.
112
+ *
113
+ * @param {ComposioTool[]} tools - Array of Composio tools to wrap
114
+ * @param {ExecuteToolFn} executeTool - Function to execute the tools
115
+ * @returns {VercelToolCollection} Dictionary of wrapped tools in Vercel AI SDK format
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Wrap multiple tools for use with Vercel AI SDK
120
+ * const composioTools = [
121
+ * {
122
+ * slug: 'SEARCH_TOOL',
123
+ * description: 'Search for information',
124
+ * inputParameters: {
125
+ * type: 'object',
126
+ * properties: {
127
+ * query: { type: 'string' }
128
+ * },
129
+ * required: ['query']
130
+ * }
131
+ * },
132
+ * {
133
+ * slug: 'WEATHER_TOOL',
134
+ * description: 'Get weather information',
135
+ * inputParameters: {
136
+ * type: 'object',
137
+ * properties: {
138
+ * location: { type: 'string' }
139
+ * },
140
+ * required: ['location']
141
+ * }
142
+ * }
143
+ * ];
144
+ *
145
+ * // Create Vercel tools using the provider
146
+ * const vercelTools = provider.wrapTools(
147
+ * composioTools,
148
+ * composio.tools.execute
149
+ * );
150
+ *
151
+ * // Use with Vercel AI SDK in a Next.js API route
152
+ * import { StreamingTextResponse } from 'ai';
153
+ * import { OpenAI } from 'openai';
154
+ *
155
+ * export async function POST(req: Request) {
156
+ * const { messages } = await req.json();
157
+ * const openai = new OpenAI();
158
+ *
159
+ * const response = await openai.chat.completions.create({
160
+ * model: 'gpt-4',
161
+ * messages,
162
+ * tools: Object.values(vercelTools)
163
+ * });
164
+ *
165
+ * return new StreamingTextResponse(response.choices[0].message);
166
+ * }
167
+ * ```
168
+ */
169
+ wrapTools(tools, executeTool) {
170
+ return tools.reduce((acc, tool$1) => {
171
+ acc[tool$1.slug] = this.wrapTool(tool$1, executeTool);
172
+ return acc;
173
+ }, {});
174
+ }
175
+ /**
176
+ * Transform MCP URL response into Anthropic-specific format.
177
+ * By default, Anthropic uses the standard format (same as default),
178
+ * but this method is here to show providers can customize if needed.
179
+ *
180
+ * @param data - The MCP URL response data
181
+ * @returns Standard MCP server response format
182
+ */
183
+ wrapMcpServerResponse(data) {
184
+ return data.map((item) => ({
185
+ url: new URL(item.url),
186
+ name: item.name
187
+ }));
188
+ }
203
189
  };
204
- // Annotate the CommonJS export names for ESM import in node:
205
- 0 && (module.exports = {
206
- VercelProvider
207
- });
190
+
191
+ //#endregion
192
+ exports.VercelProvider = VercelProvider;