Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * E2E test worker for @composio/core platform compatibility. |
| 3 | * Tests that the platform module correctly resolves to the workerd implementation |
| 4 | * and that basic Composio SDK operations work without runtime errors. |
| 5 | */ |
| 6 | import { Composio } from '@composio/core'; |
| 7 | import { Hono } from 'hono'; |
| 8 | |
| 9 | type Bindings = { |
| 10 | COMPOSIO_API_KEY: string; |
| 11 | COMPOSIO_BASE_URL: string; |
| 12 | }; |
| 13 | |
| 14 | const app = new Hono<{ Bindings: Bindings }>(); |
| 15 | |
| 16 | /** |
| 17 | * Default route - lists available test endpoints |
| 18 | */ |
| 19 | app.get('/', c => { |
| 20 | return c.json({ |
| 21 | message: 'Composio Core Platform E2E Test Worker', |
| 22 | endpoints: ['/test/import', '/test/files/upload', '/test/files/download', '/test/hackernews'], |
| 23 | }); |
| 24 | }); |
| 25 | |
| 26 | /** |
| 27 | * Test: Basic import and instantiation |
| 28 | * Tests that @composio/core can be imported without runtime errors |
| 29 | * and the platform module resolves to workerd.ts in this environment |
| 30 | */ |
| 31 | app.get('/test/import', c => { |
| 32 | try { |
| 33 | const composio = new Composio({ |
| 34 | apiKey: 'test-api-key', // Dummy key for instantiation test |
| 35 | }); |
| 36 | |
| 37 | return c.json({ |
| 38 | success: true, |
| 39 | message: 'Composio SDK imported and instantiated successfully', |
| 40 | hasProvider: typeof composio.provider !== 'undefined', |
| 41 | hasTools: typeof composio.tools !== 'undefined', |
| 42 | }); |
| 43 | } catch (error) { |
| 44 | return c.json( |
| 45 | { |
| 46 | success: false, |
| 47 | error: error instanceof Error ? error.message : String(error), |
| 48 | stack: error instanceof Error ? error.stack : undefined, |
| 49 | }, |
| 50 | { status: 500 } |
| 51 | ); |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | /** |
| 56 | * Test: Files upload operation (should fail in Cloudflare Workers) |
| 57 | * Tests that files.upload() throws an appropriate error in edge runtimes |
| 58 | */ |
| 59 | app.get('/test/files/upload', async c => { |
| 60 | try { |
| 61 | const composio = new Composio({ |
| 62 | apiKey: c.env.COMPOSIO_API_KEY, |
| 63 | baseURL: c.env.COMPOSIO_BASE_URL, |
| 64 | }); |
| 65 | |
| 66 | // Attempt to call files.upload - should throw an error |
| 67 | await composio.files.upload({ |
| 68 | file: 'https://example.com/test.pdf', |
| 69 | toolSlug: 'test-tool', |
| 70 | toolkitSlug: 'test-toolkit', |
| 71 | }); |
| 72 | |
| 73 | // If we get here, the test failed - upload should have thrown |
| 74 | return c.json( |
| 75 | { |
| 76 | success: false, |
| 77 | error: 'Expected files.upload() to throw an error in Cloudflare Workers, but it did not', |
| 78 | }, |
| 79 | { status: 500 } |
| 80 | ); |
| 81 | } catch (error) { |
| 82 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 83 | const isExpectedError = errorMessage.includes('not supported in Cloudflare Workers'); |
| 84 | |
| 85 | return c.json({ |
| 86 | success: isExpectedError, |
| 87 | message: isExpectedError |
| 88 | ? 'files.upload() correctly throws an error in Cloudflare Workers' |
| 89 | : 'files.upload() threw an unexpected error', |
| 90 | error: errorMessage, |
| 91 | }); |
| 92 | } |
| 93 | }); |
| 94 | |
| 95 | /** |
| 96 | * Test: Files download operation (should fail in Cloudflare Workers) |
| 97 | * Tests that files.download() throws an appropriate error in edge runtimes |
| 98 | */ |
| 99 | app.get('/test/files/download', async c => { |
| 100 | try { |
| 101 | const composio = new Composio({ |
| 102 | apiKey: c.env.COMPOSIO_API_KEY, |
| 103 | baseURL: c.env.COMPOSIO_BASE_URL, |
| 104 | }); |
| 105 | |
| 106 | // Attempt to call files.download - should throw an error |
| 107 | await composio.files.download({ |
| 108 | s3Url: 'https://s3.example.com/test.pdf', |
| 109 | toolSlug: 'test-tool', |
| 110 | mimeType: 'application/pdf', |
| 111 | }); |
| 112 | |
| 113 | // If we get here, the test failed - download should have thrown |
| 114 | return c.json( |
| 115 | { |
| 116 | success: false, |
| 117 | error: 'Expected files.download() to throw an error in Cloudflare Workers, but it did not', |
| 118 | }, |
| 119 | { status: 500 } |
| 120 | ); |
| 121 | } catch (error) { |
| 122 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 123 | const isExpectedError = errorMessage.includes('not supported in Cloudflare Workers'); |
| 124 | |
| 125 | return c.json({ |
| 126 | success: isExpectedError, |
| 127 | message: isExpectedError |
| 128 | ? 'files.download() correctly throws an error in Cloudflare Workers' |
| 129 | : 'files.download() threw an unexpected error', |
| 130 | error: errorMessage, |
| 131 | }); |
| 132 | } |
| 133 | }); |
| 134 | |
| 135 | /** |
| 136 | * Test: Hackernews user lookup |
| 137 | * Tests that we can resolve who the 'pg' user is from Hackernews |
| 138 | * using the HACKERNEWS_GET_USER tool |
| 139 | */ |
| 140 | app.get('/test/hackernews', async c => { |
| 141 | try { |
| 142 | const composio = new Composio({ |
| 143 | apiKey: c.env.COMPOSIO_API_KEY, |
| 144 | baseURL: c.env.COMPOSIO_BASE_URL, |
| 145 | }); |
| 146 | |
| 147 | const userDetails = await composio.tools.execute('HACKERNEWS_GET_USER', { |
| 148 | arguments: { |
| 149 | username: 'pg', |
| 150 | }, |
| 151 | userId: 'default', |
| 152 | dangerouslySkipVersionCheck: true, |
| 153 | }); |
| 154 | |
| 155 | return c.json({ |
| 156 | success: true, |
| 157 | message: 'Successfully fetched HackerNews user pg', |
| 158 | data: userDetails.data, |
| 159 | }); |
| 160 | } catch (error) { |
| 161 | return c.json( |
| 162 | { |
| 163 | success: false, |
| 164 | error: error instanceof Error ? error.message : String(error), |
| 165 | stack: error instanceof Error ? error.stack : undefined, |
| 166 | }, |
| 167 | { status: 500 } |
| 168 | ); |
| 169 | } |
| 170 | }); |
| 171 | |
| 172 | export default app; |