@devries-cameron20 / composio Mirror · read-only / commits / 69cb3d246
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 20:45 UTC

Add support for vercel AI SDK v5 (#1860)

Musthaq Ahamad committed Aug 19, 2025 at 14:48 UTC 69cb3d246c573ec10000de4f419fc72ca6d9265b
8 files changed +145 -66
.changeset/swift-tools-unite.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/vercel': minor
3 +---
4 +
5 +Add support for ai-sdk v5
pnpm-lock.yaml
+44 -19
@@ -116,7 +116,7 @@ importers:
116 version: 4.3.16(react@18.3.1)(zod@3.25.67)
117 composio-core:
118 specifier: ^0.5.39
119 - version: 0.5.39(@ai-sdk/openai@2.0.10(zod@3.25.67))(@cloudflare/workers-types@4.20250619.0)(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(@langchain/openai@0.5.13(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(ws@8.18.2))(ai@4.3.16(react@18.3.1)(zod@3.25.67))(langchain@0.3.28(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(axios@1.10.0)(openai@4.104.0(ws@8.18.2)(zod@3.25.67))(ws@8.18.2))(openai@4.104.0(ws@8.18.2)(zod@3.25.67))
119 + version: 0.5.39(@ai-sdk/openai@2.0.16(zod@3.25.67))(@cloudflare/workers-types@4.20250619.0)(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(@langchain/openai@0.5.13(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(ws@8.18.2))(ai@4.3.16(react@18.3.1)(zod@3.25.67))(langchain@0.3.28(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(axios@1.10.0)(openai@4.104.0(ws@8.18.2)(zod@3.25.67))(ws@8.18.2))(openai@4.104.0(ws@8.18.2)(zod@3.25.67))
120 hono:
121 specifier: ^4.7.11
122 version: 4.8.0
@@ -502,8 +502,8 @@ importers:
502 ts/examples/vercel:
503 dependencies:
504 '@ai-sdk/openai':
505 - specifier: ^1.3.16
506 - version: 1.3.22(zod@3.25.67)
505 + specifier: ^2.0.16
506 + version: 2.0.16(zod@3.25.67)
507 '@composio/core':
508 specifier: workspace:*
509 version: link:../../packages/core
@@ -511,8 +511,8 @@ importers:
511 specifier: workspace:*
512 version: link:../../packages/providers/vercel
513 ai:
514 - specifier: ^4.3.8
515 - version: 4.3.16(react@18.3.1)(zod@3.25.67)
514 + specifier: ^5.0.16
515 + version: 5.0.16(zod@3.25.67)
516 dotenv:
517 specifier: ^16.5.0
518 version: 16.5.0
@@ -823,14 +823,13 @@ importers:
823 version: 3.2.4(@types/node@24.0.3)(@vitest/ui@3.2.4)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
824
825 ts/packages/providers/vercel:
826 - dependencies:
827 - ai:
828 - specifier: ^4.3.8
829 - version: 4.3.16(react@18.3.1)(zod@3.25.67)
826 devDependencies:
827 '@composio/core':
828 specifier: workspace:*
829 version: link:../../core
830 + ai:
831 + specifier: ^5.0.16
832 + version: 5.0.16(zod@3.25.67)
833 tsup:
834 specifier: ^8.4.0
835 version: 8.5.0(jiti@1.21.7)(postcss@8.5.6)(tsx@4.20.3)(typescript@5.8.3)(yaml@2.8.0)
@@ -872,14 +871,20 @@ packages:
871 peerDependencies:
872 zod: ^3.0.0
873
874 + '@ai-sdk/gateway@1.0.8':
875 + resolution: {integrity: sha512-yiHYz0bAHEvhL+fSUBI2dNmyj0LOI8zw5qrYpa4gp1ojPgZq/7T1WXoIWRmVdjQwvT4PzSmRKLtbMPfz+umgfw==}
876 + engines: {node: '>=18'}
877 + peerDependencies:
878 + zod: ^3.25.76 || ^4
879 +
880 '@ai-sdk/openai@1.3.22':
881 resolution: {integrity: sha512-QwA+2EkG0QyjVR+7h6FE7iOu2ivNqAVMm9UJZkVxxTk5OIq5fFJDTEI/zICEMuHImTTXR2JjsL6EirJ28Jc4cw==}
882 engines: {node: '>=18'}
883 peerDependencies:
884 zod: ^3.0.0
885
881 - '@ai-sdk/openai@2.0.10':
882 - resolution: {integrity: sha512-vnB6Jk2Qb245fajaWjG3q6N0QQy/uej7kZ0QR9xxq09x++3Tx/UPOcgAKMhFFA2fnuGpkFSRKoiDCyp/E3RARQ==}
886 + '@ai-sdk/openai@2.0.16':
887 + resolution: {integrity: sha512-Boe715q4SkSJedFfAtbP0yuo8DmF9iYElAaDH2g4YgqJqqkskIJJx4hlCYGMMk1eMesRrB2NqZvtOeyTZ/u4fA==}
888 engines: {node: '>=18'}
889 peerDependencies:
890 zod: ^3.25.76 || ^4
@@ -890,8 +895,8 @@ packages:
895 peerDependencies:
896 zod: ^3.23.8
897
893 - '@ai-sdk/provider-utils@3.0.1':
894 - resolution: {integrity: sha512-/iP1sKc6UdJgGH98OCly7sWJKv+J9G47PnTjIj40IJMUQKwDrUMyf7zOOfRtPwSuNifYhSoJQ4s1WltI65gJ/g==}
898 + '@ai-sdk/provider-utils@3.0.4':
899 + resolution: {integrity: sha512-/3Z6lfUp8r+ewFd9yzHkCmPlMOJUXup2Sx3aoUyrdXLhOmAfHRl6Z4lDbIdV0uvw/QYoBcVLJnvXN7ncYeS3uQ==}
900 engines: {node: '>=18'}
901 peerDependencies:
902 zod: ^3.25.76 || ^4
@@ -3964,6 +3969,12 @@ packages:
3969 react:
3970 optional: true
3971
3972 + ai@5.0.16:
3973 + resolution: {integrity: sha512-shrrGo0i1cd3y8+/W9KpnRexqUpOgQ6Qj0yccKr4fQz4lMP6yKejNxAkOyaUYOqkM0OYovAYa6kyNxzZNdEUOw==}
3974 + engines: {node: '>=18'}
3975 + peerDependencies:
3976 + zod: ^3.25.76 || ^4
3977 +
3978 ajv@6.12.6:
3979 resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==}
3980
@@ -7145,16 +7156,22 @@ snapshots:
7156 '@ai-sdk/provider-utils': 2.2.8(zod@3.25.67)
7157 zod: 3.25.67
7158
7159 + '@ai-sdk/gateway@1.0.8(zod@3.25.67)':
7160 + dependencies:
7161 + '@ai-sdk/provider': 2.0.0
7162 + '@ai-sdk/provider-utils': 3.0.4(zod@3.25.67)
7163 + zod: 3.25.67
7164 +
7165 '@ai-sdk/openai@1.3.22(zod@3.25.67)':
7166 dependencies:
7167 '@ai-sdk/provider': 1.1.3
7168 '@ai-sdk/provider-utils': 2.2.8(zod@3.25.67)
7169 zod: 3.25.67
7170
7154 - '@ai-sdk/openai@2.0.10(zod@3.25.67)':
7171 + '@ai-sdk/openai@2.0.16(zod@3.25.67)':
7172 dependencies:
7173 '@ai-sdk/provider': 2.0.0
7157 - '@ai-sdk/provider-utils': 3.0.1(zod@3.25.67)
7174 + '@ai-sdk/provider-utils': 3.0.4(zod@3.25.67)
7175 zod: 3.25.67
7176
7177 '@ai-sdk/provider-utils@2.2.8(zod@3.25.67)':
@@ -7164,7 +7181,7 @@ snapshots:
7181 secure-json-parse: 2.7.0
7182 zod: 3.25.67
7183
7167 - '@ai-sdk/provider-utils@3.0.1(zod@3.25.67)':
7184 + '@ai-sdk/provider-utils@3.0.4(zod@3.25.67)':
7185 dependencies:
7186 '@ai-sdk/provider': 2.0.0
7187 '@standard-schema/spec': 1.0.0
@@ -8013,7 +8030,7 @@ snapshots:
8030 dependencies:
8031 '@effect/experimental': 0.49.2(@effect/platform@0.85.2(effect@3.16.16))(effect@3.16.16)
8032 '@effect/platform': 0.85.2(effect@3.16.16)
8016 - '@opentelemetry/semantic-conventions': 1.34.0
8033 + '@opentelemetry/semantic-conventions': 1.36.0
8034 effect: 3.16.16
8035 uuid: 11.1.0
8036
@@ -11200,6 +11217,14 @@ snapshots:
11217 optionalDependencies:
11218 react: 18.3.1
11219
11220 + ai@5.0.16(zod@3.25.67):
11221 + dependencies:
11222 + '@ai-sdk/gateway': 1.0.8(zod@3.25.67)
11223 + '@ai-sdk/provider': 2.0.0
11224 + '@ai-sdk/provider-utils': 3.0.4(zod@3.25.67)
11225 + '@opentelemetry/api': 1.9.0
11226 + zod: 3.25.67
11227 +
11228 ajv@6.12.6:
11229 dependencies:
11230 fast-deep-equal: 3.1.3
@@ -11537,9 +11562,9 @@ snapshots:
11562 has-own-prop: 2.0.0
11563 repeat-string: 1.6.1
11564
11540 - composio-core@0.5.39(@ai-sdk/openai@2.0.10(zod@3.25.67))(@cloudflare/workers-types@4.20250619.0)(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(@langchain/openai@0.5.13(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(ws@8.18.2))(ai@4.3.16(react@18.3.1)(zod@3.25.67))(langchain@0.3.28(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(axios@1.10.0)(openai@4.104.0(ws@8.18.2)(zod@3.25.67))(ws@8.18.2))(openai@4.104.0(ws@8.18.2)(zod@3.25.67)):
11565 + composio-core@0.5.39(@ai-sdk/openai@2.0.16(zod@3.25.67))(@cloudflare/workers-types@4.20250619.0)(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(@langchain/openai@0.5.13(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(ws@8.18.2))(ai@4.3.16(react@18.3.1)(zod@3.25.67))(langchain@0.3.28(@langchain/core@0.3.63(openai@4.104.0(ws@8.18.2)(zod@3.25.67)))(axios@1.10.0)(openai@4.104.0(ws@8.18.2)(zod@3.25.67))(ws@8.18.2))(openai@4.104.0(ws@8.18.2)(zod@3.25.67)):
11566 dependencies:
11542 - '@ai-sdk/openai': 2.0.10(zod@3.25.67)
11567 + '@ai-sdk/openai': 2.0.16(zod@3.25.67)
11568 '@cloudflare/workers-types': 4.20250619.0
11569 '@composio/mcp': 1.0.3-0
11570 '@hey-api/client-axios': 0.2.12(axios@1.10.0)
ts/examples/vercel/package.json
+4 -3
@@ -7,6 +7,7 @@
7 "scripts": {
8 "clean": "git clean -xdf node_modules",
9 "start": "bun src/index.ts",
10 + "start:stream": "bun src/stream.ts",
11 "test": "echo \"Error: no test specified\" && exit 1"
12 },
13 "keywords": [],
@@ -14,14 +15,14 @@
15 "license": "ISC",
16 "packageManager": "pnpm@10.8.0",
17 "dependencies": {
17 - "@ai-sdk/openai": "^1.3.16",
18 + "@ai-sdk/openai": "^2.0.16",
19 "@composio/core": "workspace:*",
20 "@composio/vercel": "workspace:*",
20 - "ai": "^4.3.8",
21 + "ai": "^5.0.16",
22 "dotenv": "^16.5.0"
23 },
24 "devDependencies": {
25 "@types/bun": "^1.2.9",
26 "typescript": "^5.8.3"
27 }
27 -}
28 +}
\ No newline at end of file
ts/examples/vercel/src/index.ts
+19 -32
@@ -1,5 +1,5 @@
1 import { Composio } from '@composio/core';
2 -import { generateText, CoreMessage } from 'ai';
2 +import { generateText, CoreMessage, ModelMessage, stepCountIs } from 'ai';
3 import { openai } from '@ai-sdk/openai';
4 import { VercelProvider } from '@composio/vercel';
5 import dotenv from 'dotenv';
@@ -19,45 +19,32 @@ const composio = new Composio({
19 * Alternatively, you can use the `composio.getToolBySlug` method
20 */
21 async function run() {
22 - const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
22 + const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE', {
23 + beforeExecute: ({ params, toolSlug }) => {
24 + console.log(`🔄 Executing ${toolSlug} with params:`, { params });
25 + return params;
26 + },
27 + afterExecute: ({ result }) => {
28 + console.log(`✅ Executed ${tools.slug} with result:`);
29 + return result;
30 + }
31 + });
32
24 - const messages: CoreMessage[] = [
33 + const messages: ModelMessage[] = [
34 {
35 role: MessageRoles.USER,
36 content: 'Summarize the front page of HackerNews',
37 },
38 ];
39
31 - const chatCompletion = async () => {
32 - const { text, toolCalls, toolResults } = await generateText({
33 - model: openai('gpt-4o-mini'),
34 - tools: tools,
35 - messages,
36 - });
37 -
38 - if (toolResults.length > 0 && toolCalls.length > 0) {
39 - toolCalls.forEach(async toolCall => {
40 - console.log(`Executing tool call: ${toolCall.toolName}`);
41 - });
42 -
43 - messages.push({
44 - role: MessageRoles.ASSISTANT,
45 - content: toolCalls,
46 - });
47 -
48 - messages.push({
49 - role: MessageRoles.TOOL,
50 - content: toolResults,
51 - });
52 -
53 - await chatCompletion();
54 - } else {
55 - messages.push({ role: MessageRoles.ASSISTANT, content: text });
56 - console.log(`Assistant: ${text}\n`);
57 - }
58 - };
40 + const { text } = await generateText({
41 + model: openai('gpt-4o-mini'),
42 + tools: tools,
43 + messages,
44 + stopWhen: stepCountIs(5)
45 + });
46
60 - chatCompletion();
47 + console.log(text);
48 }
49
50 run();
ts/examples/vercel/src/stream.ts new
+52
@@ -0,0 +1,52 @@
1 +import { Composio } from '@composio/core';
2 +import { generateText, ModelMessage, stepCountIs, streamText } from 'ai';
3 +import { openai } from '@ai-sdk/openai';
4 +import { VercelProvider } from '@composio/vercel';
5 +import dotenv from 'dotenv';
6 +import { MessageRoles } from './types';
7 +dotenv.config();
8 +
9 +/**
10 + * Initialize the Composio SDK with the Vercel provider
11 + */
12 +const composio = new Composio({
13 + apiKey: process.env.COMPOSIO_API_KEY,
14 + provider: new VercelProvider(),
15 +});
16 +
17 +/**
18 + * Get the hacker news tool
19 + * Alternatively, you can use the `composio.getToolBySlug` method
20 + */
21 +async function run() {
22 + const tools = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE', {
23 + beforeExecute: ({ params, toolSlug }) => {
24 + console.log(`🔄 Executing ${toolSlug} with params:`, { params });
25 + return params;
26 + },
27 + afterExecute: ({ result, toolSlug }) => {
28 + console.log(`✅ Executed ${toolSlug} with result:`);
29 + return result;
30 + },
31 + });
32 +
33 + const messages: ModelMessage[] = [
34 + {
35 + role: MessageRoles.USER,
36 + content: 'Summarize the front page of HackerNews',
37 + },
38 + ];
39 +
40 + const stream = await streamText({
41 + model: openai('gpt-4o-mini'),
42 + tools: tools,
43 + messages,
44 + stopWhen: stepCountIs(5),
45 + });
46 +
47 + for await (const textPart of stream.textStream) {
48 + process.stdout.write(textPart);
49 + }
50 +}
51 +
52 +run();
ts/packages/providers/vercel/package.json
+3 -2
@@ -31,13 +31,14 @@
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 "@composio/core": "0.1.44",
34 - "ai": "^4.3.8"
34 + "ai": "^5.0.16"
35 },
36 "devDependencies": {
37 "@composio/core": "workspace:*",
38 "tsup": "^8.4.0",
39 "typescript": "^5.8.3",
40 - "vitest": "^3.1.4"
40 + "vitest": "^3.1.4",
41 + "ai": "^5.0.16"
42 },
43 "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064"
44 }
ts/packages/providers/vercel/src/index.ts
+5 -2
@@ -17,9 +17,10 @@ import {
17 McpUrlResponse,
18 McpServerGetResponse,
19 removeNonRequiredProperties,
20 + jsonSchemaToZodSchema,
21 } from '@composio/core';
22 import type { Tool as VercelTool } from 'ai';
22 -import { jsonSchema, tool } from 'ai';
23 +import { tool } from 'ai';
24
25 export type VercelToolCollection = Record<string, VercelTool>;
26 export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, VercelTool> {
@@ -114,9 +115,11 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Ve
115 )
116 : (inputParams ?? {});
117
118 + const inputParametersSchema = jsonSchemaToZodSchema(parameters);
119 +
120 return tool({
121 description: composioTool.description,
119 - parameters: jsonSchema(parameters),
122 + inputSchema: inputParametersSchema,
123 execute: async params => {
124 const input = typeof params === 'string' ? JSON.parse(params) : params;
125 return await executeTool(composioTool.slug, input);
ts/packages/providers/vercel/test/vercel.test.ts
+13 -8
@@ -1,12 +1,12 @@
1 import { describe, it, expect, vi, beforeEach } from 'vitest';
2 import { VercelProvider } from '../src';
3 import { Tool } from '@composio/core';
4 -import { jsonSchema, tool } from 'ai';
4 +import { tool } from 'ai';
5
6 // Define an interface for our mocked Vercel tool
7 interface MockedVercelTool {
8 description: string;
9 - parameters: any;
9 + inputSchema: any;
10 execute: Function;
11 _isMockedVercelTool: boolean;
12 }
@@ -80,11 +80,11 @@ describe('VercelProvider', () => {
80
81 expect(tool).toHaveBeenCalledWith({
82 description: mockTool.description,
83 - parameters: mockTool.inputParameters,
83 + inputSchema: expect.any(Object), // Now it's a Zod schema object
84 execute: expect.any(Function),
85 });
86
87 - expect(jsonSchema).toHaveBeenCalledWith(mockTool.inputParameters);
87 + // jsonSchema is no longer called since we use Zod schemas directly
88 expect(wrapped._isMockedVercelTool).toBe(true);
89 });
90
@@ -99,7 +99,12 @@ describe('VercelProvider', () => {
99 mockExecuteToolFn
100 ) as unknown as MockedVercelTool;
101
102 - expect(jsonSchema).toHaveBeenCalledWith({});
102 + // Verify that tool was called with an empty object converted to Zod schema
103 + expect(tool).toHaveBeenCalledWith({
104 + description: toolWithoutParams.description,
105 + inputSchema: expect.any(Object), // Should be a Zod schema for empty object
106 + execute: expect.any(Function),
107 + });
108 expect(wrapped._isMockedVercelTool).toBe(true);
109 });
110
@@ -144,12 +149,12 @@ describe('VercelProvider', () => {
149 expect(tool).toHaveBeenCalledTimes(2);
150 expect(tool).toHaveBeenCalledWith({
151 description: mockTool.description,
147 - parameters: mockTool.inputParameters,
152 + inputSchema: expect.any(Object), // Now it's a Zod schema object
153 execute: expect.any(Function),
154 });
155 expect(tool).toHaveBeenCalledWith({
156 description: anotherTool.description,
152 - parameters: anotherTool.inputParameters,
157 + inputSchema: expect.any(Object), // Now it's a Zod schema object
158 execute: expect.any(Function),
159 });
160 });
@@ -203,7 +208,7 @@ describe('VercelProvider', () => {
208
209 // Verify the wrapped tool has the expected structure
210 expect(wrapped).toHaveProperty('description');
206 - expect(wrapped).toHaveProperty('parameters');
211 + expect(wrapped).toHaveProperty('inputSchema'); // Changed from 'parameters' to 'inputSchema'
212 expect(wrapped).toHaveProperty('execute');
213
214 // The tool should be compatible with Vercel AI SDK's expected structure