@composio/vercel 0.11.0 → 0.11.2-beta.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/README.md +28 -214
- package/dist/index.d.mts +1 -4
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -1,244 +1,58 @@
|
|
|
1
1
|
# @composio/vercel
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Vercel AI SDK Integration**: Seamless integration with Vercel's AI SDK
|
|
8
|
-
- **Streaming Support**: First-class support for streaming responses
|
|
9
|
-
- **Model Agnostic**: Works with any model supported by Vercel AI SDK (OpenAI, Anthropic, etc.)
|
|
10
|
-
- **UI Components**: Integration with Vercel's React components for chat interfaces
|
|
11
|
-
- **Tool Execution**: Execute tools with proper parameter handling and streaming
|
|
12
|
-
- **Type Safety**: Full TypeScript support with proper type definitions
|
|
3
|
+
Composio provider for the [Vercel AI SDK](https://sdk.vercel.ai) (`ai`). It converts Composio tools into the AI SDK's tool format with built-in execution: each wrapped tool carries its own `execute` function, so the AI SDK runs tool calls for you without a manual agentic loop.
|
|
13
4
|
|
|
14
5
|
## Installation
|
|
15
6
|
|
|
16
7
|
```bash
|
|
17
|
-
npm install @composio/vercel ai
|
|
18
|
-
# or
|
|
19
|
-
yarn add @composio/vercel ai
|
|
20
|
-
# or
|
|
21
|
-
pnpm add @composio/vercel ai
|
|
8
|
+
npm install @composio/core @composio/vercel ai @ai-sdk/anthropic
|
|
22
9
|
```
|
|
23
10
|
|
|
24
|
-
|
|
11
|
+
`@ai-sdk/anthropic` powers the example below; swap in any AI SDK model package.
|
|
25
12
|
|
|
26
|
-
|
|
13
|
+
Set two environment variables:
|
|
27
14
|
|
|
28
|
-
- `COMPOSIO_API_KEY
|
|
15
|
+
- `COMPOSIO_API_KEY` from the [Composio dashboard](https://dashboard.composio.dev/settings)
|
|
16
|
+
- `ANTHROPIC_API_KEY` from [Anthropic](https://console.anthropic.com/settings/keys) (or the key for your chosen model provider)
|
|
29
17
|
|
|
30
|
-
|
|
18
|
+
## Quickstart
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
- `ANTHROPIC_API_KEY`: Your Anthropic API key (if using Anthropic)
|
|
34
|
-
- `GEMINI_API_KEY`: Your Google AI API key (if using Gemini)
|
|
35
|
-
|
|
36
|
-
## Quick Start
|
|
20
|
+
Create a session for your user, pass its tools to the AI SDK, and cap the run with `stopWhen`:
|
|
37
21
|
|
|
38
22
|
```typescript
|
|
23
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
39
24
|
import { Composio } from '@composio/core';
|
|
40
25
|
import { VercelProvider } from '@composio/vercel';
|
|
26
|
+
import { generateText, stepCountIs } from 'ai';
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
const composio = new Composio({
|
|
44
|
-
apiKey: 'your-composio-api-key',
|
|
45
|
-
provider: new VercelProvider(),
|
|
46
|
-
});
|
|
28
|
+
const composio = new Composio({ provider: new VercelProvider() });
|
|
47
29
|
|
|
48
|
-
//
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
limit: 10,
|
|
52
|
-
});
|
|
30
|
+
// Each session is scoped to one of your users
|
|
31
|
+
const session = await composio.create('user_123');
|
|
32
|
+
const tools = await session.tools();
|
|
53
33
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
const { text } = await generateText({
|
|
35
|
+
model: anthropic('claude-sonnet-4-6'),
|
|
36
|
+
tools,
|
|
37
|
+
prompt: 'Summarize my emails from today',
|
|
38
|
+
stopWhen: stepCountIs(10),
|
|
58
39
|
});
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
|
|
41
|
+
console.log(text);
|
|
62
42
|
```
|
|
63
43
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Check out our complete example implementations:
|
|
44
|
+
For multi-turn conversations, store `session.sessionId` and reuse it with `composio.use(sessionId)` instead of creating a new session each turn.
|
|
67
45
|
|
|
68
|
-
|
|
46
|
+
## Strict mode
|
|
69
47
|
|
|
70
|
-
|
|
48
|
+
Some models reject tool schemas that contain optional parameters. Pass `strict: true` to drop every non-required property from each tool's input schema before it reaches the AI SDK:
|
|
71
49
|
|
|
72
50
|
```typescript
|
|
73
|
-
|
|
74
|
-
import { VercelProvider } from '@composio/vercel';
|
|
75
|
-
import { useChat } from 'ai/react';
|
|
76
|
-
|
|
77
|
-
// Initialize Composio with Vercel provider
|
|
78
|
-
const composio = new Composio({
|
|
79
|
-
apiKey: process.env.COMPOSIO_API_KEY,
|
|
80
|
-
provider: new VercelProvider()
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// In your React component
|
|
84
|
-
function ChatComponent() {
|
|
85
|
-
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
|
86
|
-
api: '/api/chat',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<div>
|
|
91
|
-
{messages.map(m => (
|
|
92
|
-
<div key={m.id}>
|
|
93
|
-
{m.role === 'user' ? 'User: ' : 'AI: '}
|
|
94
|
-
{m.content}
|
|
95
|
-
</div>
|
|
96
|
-
))}
|
|
97
|
-
|
|
98
|
-
<form onSubmit={handleSubmit}>
|
|
99
|
-
<input
|
|
100
|
-
value={input}
|
|
101
|
-
onChange={handleInputChange}
|
|
102
|
-
placeholder="Say something..."
|
|
103
|
-
/>
|
|
104
|
-
<button type="submit">Send</button>
|
|
105
|
-
</form>
|
|
106
|
-
</div>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// In your API route (e.g. app/api/chat/route.ts)
|
|
111
|
-
import { streamText } from 'ai';
|
|
112
|
-
import { openai } from '@ai-sdk/openai';
|
|
113
|
-
|
|
114
|
-
export async function POST(req: Request) {
|
|
115
|
-
const { messages } = await req.json();
|
|
116
|
-
const tools = await composio.tools.get('user123', {
|
|
117
|
-
toolkits: ['gmail'],
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const result = streamText({
|
|
121
|
-
model: openai('gpt-4'),
|
|
122
|
-
messages,
|
|
123
|
-
tools,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
return result.toDataStreamResponse();
|
|
127
|
-
}
|
|
51
|
+
const composio = new Composio({ provider: new VercelProvider({ strict: true }) });
|
|
128
52
|
```
|
|
129
53
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import { Composio } from '@composio/core';
|
|
134
|
-
import { VercelProvider } from '@composio/vercel';
|
|
135
|
-
import { streamText } from 'ai';
|
|
136
|
-
|
|
137
|
-
const composio = new Composio({
|
|
138
|
-
apiKey: process.env.COMPOSIO_API_KEY,
|
|
139
|
-
provider: new VercelProvider(),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Example API route that handles tool execution
|
|
143
|
-
export async function POST(req: Request) {
|
|
144
|
-
const { messages } = await req.json();
|
|
145
|
-
const tools = await composio.tools.get('user123', {
|
|
146
|
-
toolkits: ['gmail', 'googlecalendar'],
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const stream = streamText({
|
|
150
|
-
model: openai('gpt-4'),
|
|
151
|
-
messages,
|
|
152
|
-
tools,
|
|
153
|
-
callbacks: {
|
|
154
|
-
onToolCall: async tool => {
|
|
155
|
-
// Execute the tool and return result
|
|
156
|
-
return await composio.provider.executeToolCall(tool);
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
return stream.toDataStreamResponse();
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Provider Configuration
|
|
166
|
-
|
|
167
|
-
The Vercel provider can be configured with various options:
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
const provider = new VercelProvider({
|
|
171
|
-
// Default model configuration
|
|
172
|
-
model: openai('gpt-4'),
|
|
173
|
-
// Custom execution modifiers
|
|
174
|
-
modifiers: {
|
|
175
|
-
beforeExecute: params => {
|
|
176
|
-
// Transform parameters before execution
|
|
177
|
-
return params;
|
|
178
|
-
},
|
|
179
|
-
afterExecute: response => {
|
|
180
|
-
// Transform response after execution
|
|
181
|
-
return response;
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Strict Mode
|
|
188
|
-
|
|
189
|
-
When using tools with Vercel AI SDK, you might need to ensure that all tool parameters are marked as required. This is because Vercel AI SDK's function calling implementation requires all fields to be marked as required. You can enable strict mode when fetching tools to automatically remove all non-required properties from both input and output parameters:
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
// Get tools with strict mode enabled
|
|
193
|
-
const tools = await composio.tools.get('user123', {
|
|
194
|
-
toolkits: ['gmail', 'googlecalendar'],
|
|
195
|
-
strict: true, // This will remove all non-required properties from tool parameters
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// Use these tools with Vercel AI SDK
|
|
199
|
-
const stream = streamText({
|
|
200
|
-
model: openai('gpt-4'),
|
|
201
|
-
messages,
|
|
202
|
-
tools, // These tools will only have required parameters
|
|
203
|
-
});
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
For more information about strict mode in function calling, see [OpenAI's documentation](https://platform.openai.com/docs/guides/function-calling#strict-mode).
|
|
207
|
-
|
|
208
|
-
## API Reference
|
|
209
|
-
|
|
210
|
-
### VercelProvider Class
|
|
211
|
-
|
|
212
|
-
The `VercelProvider` class extends `BaseComposioProvider` and provides Vercel AI SDK-specific functionality.
|
|
213
|
-
|
|
214
|
-
#### Methods
|
|
215
|
-
|
|
216
|
-
##### `executeToolCall(tool: ToolCall): Promise<string>`
|
|
217
|
-
|
|
218
|
-
Executes a tool call and returns the result.
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
const result = await provider.executeToolCall(toolCall);
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
##### `handleToolCalls(stream: AIStream): AsyncGenerator<AIStreamEvent>`
|
|
225
|
-
|
|
226
|
-
Handles tool calls from a stream and yields events.
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
for await (const event of provider.handleToolCalls(stream)) {
|
|
230
|
-
// Handle events
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Contributing
|
|
235
|
-
|
|
236
|
-
We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
|
|
237
|
-
|
|
238
|
-
## License
|
|
239
|
-
|
|
240
|
-
ISC License
|
|
241
|
-
|
|
242
|
-
## Support
|
|
54
|
+
## Links
|
|
243
55
|
|
|
244
|
-
|
|
56
|
+
- [Vercel AI SDK provider docs](https://docs.composio.dev/docs/providers/vercel)
|
|
57
|
+
- [Composio quickstart](https://docs.composio.dev/docs/quickstart)
|
|
58
|
+
- [Composio documentation](https://docs.composio.dev)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseAgenticProvider, ExecuteToolFn, McpServerGetResponse, McpUrlResponse, Tool } from "@composio/core";
|
|
2
2
|
import { Tool as Tool$1, ToolSet } from "ai";
|
|
3
|
-
|
|
4
3
|
//#region src/index.d.ts
|
|
5
4
|
type VercelToolCollection = ToolSet;
|
|
6
5
|
declare class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Tool$1, McpServerGetResponse> {
|
|
@@ -27,9 +26,7 @@ declare class VercelProvider extends BaseAgenticProvider<VercelToolCollection, T
|
|
|
27
26
|
* const vercelTools = provider.wrapTools(composioTools, composio.tools.execute);
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
constructor({
|
|
31
|
-
strict
|
|
32
|
-
}?: {
|
|
29
|
+
constructor({ strict }?: {
|
|
33
30
|
strict?: boolean;
|
|
34
31
|
});
|
|
35
32
|
/**
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/vercel",
|
|
3
|
-
"version": "0.11.0",
|
|
3
|
+
"version": "0.11.2-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.22.3"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "https://github.com/ComposioHQ/composio.git",
|
|
@@ -12,7 +15,7 @@
|
|
|
12
15
|
"bugs": {
|
|
13
16
|
"url": "https://github.com/ComposioHQ/composio/issues"
|
|
14
17
|
},
|
|
15
|
-
"homepage": "https://github.com/ComposioHQ/composio/tree/
|
|
18
|
+
"homepage": "https://github.com/ComposioHQ/composio/tree/next/ts/packages/providers/vercel#readme",
|
|
16
19
|
"publishConfig": {
|
|
17
20
|
"access": "public"
|
|
18
21
|
},
|
|
@@ -30,16 +33,16 @@
|
|
|
30
33
|
"author": "",
|
|
31
34
|
"license": "ISC",
|
|
32
35
|
"peerDependencies": {
|
|
33
|
-
"@composio/core": ">=0.
|
|
36
|
+
"@composio/core": ">=1.0.0-beta.0 <2.0.0",
|
|
34
37
|
"ai": "^6.0.0 || ^7.0.0"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"ai": "^
|
|
38
|
-
"tsdown": "^0.22.
|
|
39
|
-
"typescript": "^
|
|
40
|
-
"vitest": "^4.1.
|
|
40
|
+
"ai": "^7.0.70",
|
|
41
|
+
"tsdown": "^0.22.14",
|
|
42
|
+
"typescript": "^7.0.2",
|
|
43
|
+
"vitest": "^4.1.11",
|
|
41
44
|
"zod": "^4.4.3",
|
|
42
|
-
"@composio/core": "0.
|
|
45
|
+
"@composio/core": "1.0.0-beta.0"
|
|
43
46
|
},
|
|
44
47
|
"gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
|
|
45
48
|
"scripts": {
|