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