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 23, 03:00 UTC
Update examples in readme.md
haxzie committed
May 15, 2025 at 17:15 UTC
e9d6756538b2078a47daa5ae51f597761d1037cf
4 files changed
+743
-95
packages/toolsets/cloudflare/README.md
new
+166
@@ -0,0 +1,166 @@
1
+# @composio/cloudflare
2
+
3
+The Cloudflare AI toolset for Composio SDK, providing seamless integration with Cloudflare's AI capabilities and Workers AI.
4
+
5
+## Features
6
+
7
+- **Workers AI Integration**: Seamless integration with Cloudflare Workers AI
8
+- **Streaming Support**: First-class support for streaming responses
9
+- **Model Support**: Support for all Cloudflare AI models (@cf/meta/llama-2-7b-chat-int8, etc.)
10
+- **Edge Deployment**: Deploy and run AI models at the edge
11
+- **Tool Execution**: Execute tools with proper parameter handling
12
+- **Type Safety**: Full TypeScript support with proper type definitions
13
+
14
+## Installation
15
+
16
+```bash
17
+npm install @composio/cloudflare
18
+# or
19
+yarn add @composio/cloudflare
20
+# or
21
+pnpm add @composio/cloudflare
22
+```
23
+
24
+## Quick Start
25
+
26
+```typescript
27
+import { Composio } from '@composio/core';
28
+import { CloudflareToolset } from '@composio/cloudflare';
29
+
30
+// Initialize Composio with Cloudflare toolset
31
+const composio = new Composio({
32
+ apiKey: 'your-composio-api-key',
33
+ toolset: new CloudflareToolset({
34
+ accountId: 'your-cloudflare-account-id',
35
+ apiToken: 'your-cloudflare-api-token',
36
+ }),
37
+});
38
+
39
+// Get available tools
40
+const tools = await composio.tools.get('user123', {
41
+ apps: ['gmail', 'googlecalendar'],
42
+ limit: 10,
43
+});
44
+```
45
+
46
+## Usage Examples
47
+
48
+### Basic Chat Completion with Streaming
49
+
50
+```typescript
51
+import { Composio } from '@composio/core';
52
+import { CloudflareToolset } from '@composio/cloudflare';
53
+import { Ai } from '@cloudflare/ai';
54
+
55
+// Initialize Composio
56
+const composio = new Composio({
57
+ apiKey: process.env.COMPOSIO_API_KEY,
58
+ toolset: new CloudflareToolset(),
59
+});
60
+
61
+// In your Worker
62
+export default {
63
+ async fetch(request: Request, env: Env, ctx: ExecutionContext) {
64
+ const ai = new Ai(env.AI);
65
+ const tools = await composio.tools.get('user123', {
66
+ apps: ['gmail'],
67
+ });
68
+
69
+ const messages = [
70
+ { role: 'system', content: 'You are a helpful assistant.' },
71
+ { role: 'user', content: 'What can you do?' },
72
+ ];
73
+
74
+ const stream = await ai.run('@cf/meta/llama-2-7b-chat-int8', {
75
+ messages,
76
+ tools,
77
+ stream: true,
78
+ });
79
+
80
+ return new Response(stream, {
81
+ headers: {
82
+ 'content-type': 'text/event-stream',
83
+ },
84
+ });
85
+ },
86
+};
87
+```
88
+
89
+### Multi-Modal Example
90
+
91
+```typescript
92
+import { Composio } from '@composio/core';
93
+import { CloudflareToolset } from '@composio/cloudflare';
94
+import { Ai } from '@cloudflare/ai';
95
+
96
+// Initialize Composio
97
+const composio = new Composio({
98
+ apiKey: process.env.COMPOSIO_API_KEY,
99
+ toolset: new CloudflareToolset(),
100
+});
101
+
102
+// In your Worker
103
+export default {
104
+ async fetch(request: Request, env: Env, ctx: ExecutionContext) {
105
+ const ai = new Ai(env.AI);
106
+ const tools = await composio.tools.get('user123', {
107
+ apps: ['gmail'],
108
+ });
109
+
110
+ // Image analysis
111
+ const imageResponse = await ai.run('@cf/microsoft/resnet-50', {
112
+ image: await request.arrayBuffer(),
113
+ });
114
+
115
+ // Use image analysis in chat
116
+ const messages = [
117
+ { role: 'system', content: 'You are a helpful assistant.' },
118
+ {
119
+ role: 'user',
120
+ content: 'What do you see in this image?',
121
+ context: { image_analysis: imageResponse },
122
+ },
123
+ ];
124
+
125
+ const stream = await ai.run('@cf/meta/llama-2-7b-chat-int8', {
126
+ messages,
127
+ tools,
128
+ stream: true,
129
+ });
130
+
131
+ return new Response(stream, {
132
+ headers: {
133
+ 'content-type': 'text/event-stream',
134
+ },
135
+ });
136
+ },
137
+};
138
+```
139
+
140
+## API Reference
141
+
142
+### CloudflareToolset Class
143
+
144
+The `CloudflareToolset` class extends `BaseComposioToolset` and provides Cloudflare-specific functionality.
145
+
146
+#### Methods
147
+
148
+##### `executeToolCall(tool: ToolCall): Promise<string>`
149
+
150
+Executes a tool call and returns the result.
151
+
152
+```typescript
153
+const result = await composio.toolset.executeToolCall(toolCall);
154
+```
155
+
156
+## Contributing
157
+
158
+We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
159
+
160
+## License
161
+
162
+ISC License
163
+
164
+## Support
165
+
166
+For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
packages/toolsets/langchain/README.md
new
+215
@@ -0,0 +1,215 @@
1
+# @composio/langchain
2
+
3
+The LangChain toolset for Composio SDK, providing seamless integration with LangChain's ecosystem and tools.
4
+
5
+## Features
6
+
7
+- **LangChain Integration**: Seamless integration with LangChain's ecosystem
8
+- **LCEL Support**: Full support for LangChain Expression Language (LCEL)
9
+- **Streaming Support**: First-class support for streaming responses
10
+- **Tool Execution**: Execute LangChain tools with proper parameter handling
11
+- **Chain Integration**: Work with LangChain chains and agents
12
+- **Type Safety**: Full TypeScript support with proper type definitions
13
+
14
+## Installation
15
+
16
+```bash
17
+npm install @composio/langchain
18
+# or
19
+yarn add @composio/langchain
20
+# or
21
+pnpm add @composio/langchain
22
+```
23
+
24
+## Quick Start
25
+
26
+```typescript
27
+import { Composio } from '@composio/core';
28
+import { LangChainToolset } from '@composio/langchain';
29
+
30
+// Initialize Composio with LangChain toolset
31
+const composio = new Composio({
32
+ apiKey: 'your-composio-api-key',
33
+ toolset: new LangChainToolset(),
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 Chain with Streaming
49
+
50
+```typescript
51
+import { Composio } from '@composio/core';
52
+import { LangChainToolset } from '@composio/langchain';
53
+import { ChatPromptTemplate } from '@langchain/core/prompts';
54
+import { StringOutputParser } from '@langchain/core/output_parsers';
55
+import { ChatOpenAI } from '@langchain/openai';
56
+
57
+const composio = new Composio({
58
+ apiKey: process.env.COMPOSIO_API_KEY,
59
+ toolset: new LangChainToolset(),
60
+});
61
+
62
+// Get tools for the chain
63
+const tools = await composio.tools.get('user123', {
64
+ apps: ['gmail'],
65
+ limit: 10,
66
+});
67
+
68
+const model = new ChatOpenAI({
69
+ modelName: 'gpt-4',
70
+ streaming: true,
71
+});
72
+
73
+const prompt = ChatPromptTemplate.fromTemplate('Tell me a joke about {topic}');
74
+const parser = new StringOutputParser();
75
+
76
+const chain = prompt.pipe(model).pipe(parser);
77
+
78
+// Stream the response
79
+const stream = await chain.stream({
80
+ topic: 'programming',
81
+});
82
+
83
+for await (const chunk of stream) {
84
+ console.log(chunk);
85
+}
86
+```
87
+
88
+### Tool Execution with Streaming Events
89
+
90
+```typescript
91
+import { Composio } from '@composio/core';
92
+import { LangChainToolset } from '@composio/langchain';
93
+import { ChatPromptTemplate } from '@langchain/core/prompts';
94
+import { JsonOutputParser } from '@langchain/core/output_parsers';
95
+import { ChatOpenAI } from '@langchain/openai';
96
+
97
+const composio = new Composio({
98
+ apiKey: process.env.COMPOSIO_API_KEY,
99
+ toolset: new LangChainToolset(),
100
+});
101
+
102
+// Get tools for the chain
103
+const tools = await composio.tools.get('user123', {
104
+ apps: ['gmail'],
105
+});
106
+
107
+const model = new ChatOpenAI({
108
+ modelName: 'gpt-4',
109
+ streaming: true,
110
+});
111
+
112
+const chain = model.pipe(new JsonOutputParser());
113
+const eventStream = await chain.streamEvents(
114
+ `Output a list of the countries france, spain and japan and their populations in JSON format.`,
115
+ { version: 'v2' }
116
+);
117
+
118
+for await (const event of eventStream) {
119
+ const eventType = event.event;
120
+ if (eventType === 'on_chat_model_stream') {
121
+ console.log(`Chat model chunk: ${event.data.chunk.content}`);
122
+ } else if (eventType === 'on_parser_stream') {
123
+ console.log(`Parser chunk: ${JSON.stringify(event.data.chunk)}`);
124
+ }
125
+}
126
+```
127
+
128
+### RAG Application Example
129
+
130
+```typescript
131
+import { Composio } from '@composio/core';
132
+import { LangChainToolset } from '@composio/langchain';
133
+import { ChatPromptTemplate } from '@langchain/core/prompts';
134
+import { StringOutputParser } from '@langchain/core/output_parsers';
135
+import { MemoryVectorStore } from 'langchain/vectorstores/memory';
136
+import { OpenAIEmbeddings } from '@langchain/openai';
137
+import { ChatOpenAI } from '@langchain/openai';
138
+import { RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables';
139
+
140
+const composio = new Composio({
141
+ apiKey: process.env.COMPOSIO_API_KEY,
142
+ toolset: new LangChainToolset(),
143
+});
144
+
145
+// Get tools for the chain
146
+const tools = await composio.tools.get('user123', {
147
+ apps: ['gmail'],
148
+});
149
+
150
+// Setup vector store and retriever
151
+const vectorstore = await MemoryVectorStore.fromTexts(
152
+ ['some text', 'more text'],
153
+ [{ id: 1 }, { id: 2 }],
154
+ new OpenAIEmbeddings()
155
+);
156
+
157
+const retriever = vectorstore.asRetriever();
158
+
159
+// Create RAG chain
160
+const template = `Answer the question based only on the following context:
161
+{context}
162
+
163
+Question: {question}`;
164
+
165
+const prompt = ChatPromptTemplate.fromTemplate(template);
166
+const model = new ChatOpenAI({
167
+ modelName: 'gpt-4',
168
+ streaming: true,
169
+});
170
+
171
+const chain = RunnableSequence.from([
172
+ {
173
+ context: retriever.pipe(formatDocs),
174
+ question: new RunnablePassthrough(),
175
+ },
176
+ prompt,
177
+ model,
178
+ new StringOutputParser(),
179
+]);
180
+
181
+// Stream the response
182
+const stream = await chain.stream('What is the answer?');
183
+
184
+for await (const chunk of stream) {
185
+ console.log(chunk);
186
+}
187
+```
188
+
189
+## API Reference
190
+
191
+### LangChainToolset Class
192
+
193
+The `LangChainToolset` class extends `BaseComposioToolset` and provides LangChain-specific functionality.
194
+
195
+#### Methods
196
+
197
+##### `executeToolCall(tool: Tool): Promise<string>`
198
+
199
+Executes a LangChain tool call and returns the result.
200
+
201
+```typescript
202
+const result = await toolset.executeToolCall(tool);
203
+```
204
+
205
+## Contributing
206
+
207
+We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
208
+
209
+## License
210
+
211
+ISC License
212
+
213
+## Support
214
+
215
+For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
packages/toolsets/openai/README.md
+145
-95
@@ -1,14 +1,15 @@
1
# @composio/openai
2
3
-The OpenAI toolset for Composio SDK, providing seamless integration with OpenAI's API and tools.
3
+The OpenAI toolset for Composio SDK, providing seamless integration with OpenAI's models and function calling capabilities.
4
5
## Features
6
7
-- **OpenAI Tool Integration**: Seamlessly integrate OpenAI tools with Composio
8
-- **Tool Execution**: Execute OpenAI tools with proper parameter handling
9
-- **Stream Support**: Handle streaming responses from OpenAI
10
-- **Assistant Integration**: Work with OpenAI Assistants and their tool calls
11
-- **Thread Management**: Manage OpenAI threads and runs
7
+- **OpenAI Integration**: Seamless integration with OpenAI's models
8
+- **Streaming Support**: First-class support for streaming responses
9
+- **Function Calling**: Support for OpenAI's function calling feature
10
+- **Tool Execution**: Execute tools with proper parameter handling
11
+- **Type Safety**: Full TypeScript support with proper type definitions
12
+- **Model Support**: Support for all OpenAI models (GPT-4, GPT-3.5-turbo, etc.)
13
14
## Installation
15
@@ -29,64 +30,103 @@ import { OpenAIToolset } from '@composio/openai';
30
// Initialize Composio with OpenAI toolset
31
const composio = new Composio({
32
apiKey: 'your-composio-api-key',
32
- toolset: new OpenAIToolset()
33
+ toolset: new OpenAIToolset(),
34
});
35
35
-// Get available tools in OpenAI format
36
-const tools = await composio.getTools();
36
+// Get available tools
37
+const tools = await composio.tools.get('user123', {
38
+ apps: ['gmail', 'googlecalendar'],
39
+ limit: 10,
40
+});
41
38
-// Execute a tool call
39
-const result = await composio.toolset.executeToolCall(toolCall, 'user-id');
42
+// Get a specific tool
43
+const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
44
```
45
42
-## API Reference
46
+## Usage Examples
47
44
-### OpenAIToolset Class
45
-
46
-The `OpenAIToolset` class extends `BaseComposioToolset` and provides OpenAI-specific functionality.
47
-
48
-#### Methods
49
-
50
-##### `executeToolCall(tool: OpenAI.ChatCompletionMessageToolCall, userId?: string): Promise<string>`
51
-Executes a tool call from OpenAI and returns the result.
48
+### Basic Chat Completion with Streaming
49
50
```typescript
54
-const result = await toolset.executeToolCall(toolCall, 'user-id');
55
-```
51
+import { Composio } from '@composio/core';
52
+import { OpenAIToolset } from '@composio/openai';
53
+import OpenAI from 'openai';
54
57
-##### `handleToolCall(chatCompletion: OpenAI.ChatCompletion, userId?: string): Promise<string[]>`
58
-Handles tool calls from a chat completion.
55
+const composio = new Composio({
56
+ apiKey: process.env.COMPOSIO_API_KEY,
57
+ toolset: new OpenAIToolset(),
58
+});
59
60
-```typescript
61
-const outputs = await toolset.handleToolCall(chatCompletion, 'user-id');
60
+// Example API route
61
+export async function POST(req: Request) {
62
+ const { messages } = await req.json();
63
+ const tools = await composio.tools.get('user123', {
64
+ apps: ['gmail'],
65
+ });
66
+
67
+ const stream = await openai.chat.completions.create({
68
+ model: 'gpt-4',
69
+ messages,
70
+ tools,
71
+ stream: true,
72
+ });
73
+
74
+ return new Response(stream, {
75
+ headers: {
76
+ 'content-type': 'text/event-stream',
77
+ },
78
+ });
79
+}
80
```
81
64
-##### `handleAssistantMessage(run: OpenAI.Beta.Threads.Run, userId?: string): Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>`
65
-Handles tool calls from an assistant message.
82
+### Tool Execution with Streaming
83
84
```typescript
68
-const toolOutputs = await toolset.handleAssistantMessage(run, 'user-id');
69
-```
85
+import { Composio } from '@composio/core';
86
+import { OpenAIToolset } from '@composio/openai';
87
+import OpenAI from 'openai';
88
71
-##### `waitAndHandleAssistantStreamToolCalls(client: OpenAI, runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>, thread: OpenAI.Beta.Threads.Thread, userId?: string): AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>`
72
-Waits for and handles tool calls from an assistant stream.
89
+const composio = new Composio({
90
+ apiKey: process.env.COMPOSIO_API_KEY,
91
+ toolset: new OpenAIToolset(),
92
+});
93
74
-```typescript
75
-for await (const event of toolset.waitAndHandleAssistantStreamToolCalls(client, runStream, thread, 'user-id')) {
76
- // Handle events
94
+// Example API route that handles tool execution
95
+export async function POST(req: Request) {
96
+ const { messages } = await req.json();
97
+ const tools = await composio.tools.get('user123', {
98
+ apps: ['gmail', 'googlecalendar'],
99
+ });
100
+
101
+ const stream = await openai.chat.completions.create({
102
+ model: 'gpt-4',
103
+ messages,
104
+ tools,
105
+ tool_choice: 'auto',
106
+ stream: true,
107
+ });
108
+
109
+ const chunks = [];
110
+ for await (const chunk of stream) {
111
+ if (chunk.choices[0]?.delta?.tool_calls) {
112
+ const toolCall = chunk.choices[0].delta.tool_calls[0];
113
+ const result = await composio.toolset.executeToolCall(toolCall);
114
+ // Handle tool execution result
115
+ chunks.push(result);
116
+ } else {
117
+ chunks.push(chunk.choices[0]?.delta?.content || '');
118
+ }
119
+ }
120
+
121
+ return new Response(chunks.join(''), {
122
+ headers: {
123
+ 'content-type': 'text/plain',
124
+ },
125
+ });
126
}
127
```
128
80
-##### `waitAndHandleAssistantToolCalls(client: OpenAI, run: OpenAI.Beta.Threads.Run, thread: OpenAI.Beta.Threads.Thread, userId?: string): Promise<OpenAI.Beta.Threads.Run>`
81
-Waits for and handles tool calls from an assistant.
82
-
83
-```typescript
84
-const finalRun = await toolset.waitAndHandleAssistantToolCalls(client, run, thread, 'user-id');
85
-```
86
-
87
-## Examples
88
-
89
-### Basic Tool Execution
129
+### JSON Mode Example
130
131
```typescript
132
import { Composio } from '@composio/core';
@@ -94,35 +134,29 @@ import { OpenAIToolset } from '@composio/openai';
134
import OpenAI from 'openai';
135
136
const composio = new Composio({
97
- apiKey: 'your-composio-api-key',
98
- toolset: new OpenAIToolset()
99
-});
100
-
101
-const openai = new OpenAI({
102
- apiKey: 'your-openai-api-key'
137
+ apiKey: process.env.COMPOSIO_API_KEY,
138
+ toolset: new OpenAIToolset(),
139
});
140
105
-// Get available tools
106
-const tools = await composio.getTools();
107
-
108
-// Create a chat completion with tools
109
-const completion = await openai.chat.completions.create({
110
- model: 'gpt-4',
111
- messages: [{ role: 'user', content: 'What can you do?' }],
112
- tools: tools
113
-});
114
-
115
-// Handle tool calls
116
-if (completion.choices[0].message.tool_calls) {
117
- const result = await composio.toolset.executeToolCall(
118
- completion.choices[0].message.tool_calls[0],
119
- 'user-id'
120
- );
121
- console.log(result);
141
+// Example API route that returns JSON
142
+export async function POST(req: Request) {
143
+ const { messages } = await req.json();
144
+ const tools = await composio.tools.get('user123', {
145
+ apps: ['gmail'],
146
+ });
147
+
148
+ const completion = await openai.chat.completions.create({
149
+ model: 'gpt-4',
150
+ messages,
151
+ tools,
152
+ response_format: { type: 'json_object' },
153
+ });
154
+
155
+ return Response.json(JSON.parse(completion.choices[0].message.content || '{}'));
156
}
157
```
158
125
-### Working with Assistants
159
+### Vision Example
160
161
```typescript
162
import { Composio } from '@composio/core';
@@ -130,37 +164,53 @@ import { OpenAIToolset } from '@composio/openai';
164
import OpenAI from 'openai';
165
166
const composio = new Composio({
133
- apiKey: 'your-composio-api-key',
134
- toolset: new OpenAIToolset()
167
+ apiKey: process.env.COMPOSIO_API_KEY,
168
+ toolset: new OpenAIToolset(),
169
});
170
137
-const openai = new OpenAI({
138
- apiKey: 'your-openai-api-key'
139
-});
171
+// Example API route that handles image analysis
172
+export async function POST(req: Request) {
173
+ const { messages, image } = await req.json();
174
+ const tools = await composio.tools.get('user123', {
175
+ apps: ['gmail'],
176
+ });
177
+
178
+ const completion = await openai.chat.completions.create({
179
+ model: 'gpt-4-vision-preview',
180
+ messages: [
181
+ ...messages,
182
+ {
183
+ role: 'user',
184
+ content: [
185
+ { type: 'text', text: 'What do you see in this image?' },
186
+ { type: 'image_url', image_url: image },
187
+ ],
188
+ },
189
+ ],
190
+ tools,
191
+ max_tokens: 500,
192
+ });
193
+
194
+ return Response.json({
195
+ content: completion.choices[0].message.content,
196
+ });
197
+}
198
+```
199
141
-// Create an assistant with tools
142
-const assistant = await openai.beta.assistants.create({
143
- name: 'Composio Assistant',
144
- instructions: 'You are a helpful assistant that can use Composio tools.',
145
- model: 'gpt-4',
146
- tools: await composio.getTools()
147
-});
200
+## API Reference
201
149
-// Create a thread
150
-const thread = await openai.beta.threads.create();
202
+### OpenAIToolset Class
203
152
-// Create a run
153
-const run = await openai.beta.threads.runs.create(thread.id, {
154
- assistant_id: assistant.id
155
-});
204
+The `OpenAIToolset` class extends `BaseComposioToolset` and provides OpenAI-specific functionality.
205
+
206
+#### Methods
207
157
-// Wait for and handle tool calls
158
-const finalRun = await composio.toolset.waitAndHandleAssistantToolCalls(
159
- openai,
160
- run,
161
- thread,
162
- 'user-id'
163
-);
208
+##### `executeToolCall(tool: ToolCall): Promise<string>`
209
+
210
+Executes a tool call and returns the result.
211
+
212
+```typescript
213
+const result = await toolset.executeToolCall(toolCall);
214
```
215
216
## Contributing
@@ -173,4 +223,4 @@ ISC License
223
224
## Support
225
176
-For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
\ No newline at end of file
226
+For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
packages/toolsets/vercel/README.md
new
+217
@@ -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).