@composio/vercel 0.1.3-alpha.0 → 0.1.4-alpha.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 +217 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# @composio/vercel
|
|
2
|
+
|
|
3
|
+
The Vercel AI SDK toolset for Composio SDK, providing seamless integration with Vercel's AI SDK and tools.
|
|
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
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @composio/vercel
|
|
18
|
+
# or
|
|
19
|
+
yarn add @composio/vercel
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @composio/vercel
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Composio } from '@composio/core';
|
|
28
|
+
import { VercelToolset } from '@composio/vercel';
|
|
29
|
+
|
|
30
|
+
// Initialize Composio with Vercel toolset
|
|
31
|
+
const composio = new Composio({
|
|
32
|
+
apiKey: 'your-composio-api-key',
|
|
33
|
+
toolset: new VercelToolset(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Get available tools
|
|
37
|
+
const tools = await composio.tools.get('user123', {
|
|
38
|
+
apps: ['gmail', 'googlecalendar'],
|
|
39
|
+
limit: 10,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Get a specific tool
|
|
43
|
+
const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage Examples
|
|
47
|
+
|
|
48
|
+
### Basic Chat Completion with Streaming
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { Composio } from '@composio/core';
|
|
52
|
+
import { VercelToolset } from '@composio/vercel';
|
|
53
|
+
import { useChat } from 'ai/react';
|
|
54
|
+
|
|
55
|
+
// Initialize Composio with Vercel toolset
|
|
56
|
+
const composio = new Composio({
|
|
57
|
+
apiKey: process.env.COMPOSIO_API_KEY,
|
|
58
|
+
toolset: new VercelToolset()
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// In your React component
|
|
62
|
+
function ChatComponent() {
|
|
63
|
+
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
|
64
|
+
api: '/api/chat',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
{messages.map(m => (
|
|
70
|
+
<div key={m.id}>
|
|
71
|
+
{m.role === 'user' ? 'User: ' : 'AI: '}
|
|
72
|
+
{m.content}
|
|
73
|
+
</div>
|
|
74
|
+
))}
|
|
75
|
+
|
|
76
|
+
<form onSubmit={handleSubmit}>
|
|
77
|
+
<input
|
|
78
|
+
value={input}
|
|
79
|
+
onChange={handleInputChange}
|
|
80
|
+
placeholder="Say something..."
|
|
81
|
+
/>
|
|
82
|
+
<button type="submit">Send</button>
|
|
83
|
+
</form>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// In your API route (e.g. app/api/chat/route.ts)
|
|
89
|
+
import { streamText } from 'ai';
|
|
90
|
+
import { openai } from '@ai-sdk/openai';
|
|
91
|
+
|
|
92
|
+
export async function POST(req: Request) {
|
|
93
|
+
const { messages } = await req.json();
|
|
94
|
+
const tools = await composio.tools.get('user123', {
|
|
95
|
+
apps: ['gmail'],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const result = streamText({
|
|
99
|
+
model: openai('gpt-4'),
|
|
100
|
+
messages,
|
|
101
|
+
tools,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return result.toDataStreamResponse();
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Tool Execution with Streaming
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { Composio } from '@composio/core';
|
|
112
|
+
import { VercelToolset } from '@composio/vercel';
|
|
113
|
+
import { streamText } from 'ai';
|
|
114
|
+
|
|
115
|
+
const composio = new Composio({
|
|
116
|
+
apiKey: process.env.COMPOSIO_API_KEY,
|
|
117
|
+
toolset: new VercelToolset(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Example API route that handles tool execution
|
|
121
|
+
export async function POST(req: Request) {
|
|
122
|
+
const { messages } = await req.json();
|
|
123
|
+
const tools = await composio.tools.get('user123', {
|
|
124
|
+
apps: ['gmail', 'googlecalendar'],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const stream = streamText({
|
|
128
|
+
model: openai('gpt-4'),
|
|
129
|
+
messages,
|
|
130
|
+
tools,
|
|
131
|
+
callbacks: {
|
|
132
|
+
onToolCall: async tool => {
|
|
133
|
+
// Execute the tool and return result
|
|
134
|
+
return await composio.toolset.executeToolCall(tool);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return stream.toDataStreamResponse();
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Structured Output with Streaming
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { Composio } from '@composio/core';
|
|
147
|
+
import { VercelToolset } from '@composio/vercel';
|
|
148
|
+
import { streamObject } from 'ai';
|
|
149
|
+
|
|
150
|
+
const composio = new Composio({
|
|
151
|
+
apiKey: process.env.COMPOSIO_API_KEY,
|
|
152
|
+
toolset: new VercelToolset(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Example API route that returns structured data
|
|
156
|
+
export async function POST(req: Request) {
|
|
157
|
+
const { messages } = await req.json();
|
|
158
|
+
const tools = await composio.tools.get('user123', {
|
|
159
|
+
apps: ['gmail'],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const stream = streamObject({
|
|
163
|
+
model: openai('gpt-4'),
|
|
164
|
+
messages,
|
|
165
|
+
tools,
|
|
166
|
+
schema: {
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: {
|
|
169
|
+
name: { type: 'string' },
|
|
170
|
+
age: { type: 'number' },
|
|
171
|
+
interests: { type: 'array', items: { type: 'string' } },
|
|
172
|
+
},
|
|
173
|
+
required: ['name', 'age', 'interests'],
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return stream.toDataStreamResponse();
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## API Reference
|
|
182
|
+
|
|
183
|
+
### VercelToolset Class
|
|
184
|
+
|
|
185
|
+
The `VercelToolset` class extends `BaseComposioToolset` and provides Vercel AI SDK-specific functionality.
|
|
186
|
+
|
|
187
|
+
#### Methods
|
|
188
|
+
|
|
189
|
+
##### `executeToolCall(tool: ToolCall): Promise<string>`
|
|
190
|
+
|
|
191
|
+
Executes a tool call and returns the result.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const result = await toolset.executeToolCall(toolCall);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
##### `handleToolCalls(stream: AIStream): AsyncGenerator<AIStreamEvent>`
|
|
198
|
+
|
|
199
|
+
Handles tool calls from a stream and yields events.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
for await (const event of toolset.handleToolCalls(stream)) {
|
|
203
|
+
// Handle events
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Contributing
|
|
208
|
+
|
|
209
|
+
We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
ISC License
|
|
214
|
+
|
|
215
|
+
## Support
|
|
216
|
+
|
|
217
|
+
For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/vercel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"packageManager": "pnpm@10.8.0",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@composio/core": "^0.1.
|
|
32
|
+
"@composio/core": "^0.1.3-alpha.0",
|
|
33
33
|
"ai": "^4.3.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@composio/core": "0.1.
|
|
36
|
+
"@composio/core": "0.1.4-alpha.0",
|
|
37
37
|
"tsup": "^8.4.0",
|
|
38
38
|
"typescript": "^5.8.3"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "7f90a422e9451b6147a3bc77ca7fe381905d6a57"
|
|
41
41
|
}
|