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 21, 04:45 UTC
| 1 | /** |
| 2 | * File-handling Example |
| 3 | * |
| 4 | * This example demonstrates how to use Composio SDK for file-handling. |
| 5 | * |
| 6 | * Prerequisites: |
| 7 | * 1. Set up your COMPOSIO_API_KEY in the .env file |
| 8 | * 3. Run the example: pnpm start |
| 9 | */ |
| 10 | |
| 11 | import { Composio } from '@composio/core'; |
| 12 | import 'dotenv/config'; |
| 13 | import path from 'path'; |
| 14 | |
| 15 | /** |
| 16 | * Initialize Composio. |
| 17 | * |
| 18 | * `dangerouslyAllowAutoUploadDownloadFiles: true` enables the SDK to read local |
| 19 | * files from disk during tool execution. When that flag is on, local paths are |
| 20 | * restricted to the directories listed in `fileUploadDirs`. Passing a value |
| 21 | * REPLACES the default `[~/.composio/temp]` — include it if you want staged |
| 22 | * uploads to keep working. Pass `false` (or `[]`) to reject every local path |
| 23 | * while still allowing URLs and `File`/`Blob` objects. |
| 24 | * |
| 25 | * `fileDownloadDir` controls where files in tool responses (`s3url` fields) are |
| 26 | * written. Defaults to `~/.composio/files`. |
| 27 | */ |
| 28 | const composio = new Composio({ |
| 29 | apiKey: process.env.COMPOSIO_API_KEY, |
| 30 | dangerouslyAllowAutoUploadDownloadFiles: true, |
| 31 | fileUploadDirs: [path.join(__dirname, '..'), '~/.composio/temp'], |
| 32 | fileDownloadDir: path.join(__dirname, '..', '.composio-downloads'), |
| 33 | }); |
| 34 | |
| 35 | /** |
| 36 | * Main function to run the example |
| 37 | */ |
| 38 | async function main() { |
| 39 | try { |
| 40 | console.log('🚀 Starting File-handling Example...'); |
| 41 | |
| 42 | // Get available tools |
| 43 | const tools = await composio.tools.get('default', 'GMAIL_SEND_EMAIL'); |
| 44 | |
| 45 | console.log(`✅ Found ${tools.length} tools`); |
| 46 | |
| 47 | const filePath = path.join(__dirname, '..', 'pepe-silvia.png'); |
| 48 | console.log(`Sending file from ${filePath}`); |
| 49 | |
| 50 | const result = await composio.tools.execute('GMAIL_SEND_EMAIL', { |
| 51 | userId: 'default', |
| 52 | arguments: { |
| 53 | attachment: filePath, |
| 54 | recipient_email: 'musthaq@composio.dev', |
| 55 | user_id: 'me', |
| 56 | body: 'Hello, this is a test email with a file attachment.', |
| 57 | subject: 'Test Email with Attachment', |
| 58 | }, |
| 59 | }); |
| 60 | |
| 61 | console.log(result); |
| 62 | } catch (error) { |
| 63 | console.error('❌ Error running example:', error); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Run the example |
| 68 | main().catch(console.error); |