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, 06:00 UTC
| 1 | /** |
| 2 | * E2E fixture: session.toolkits() cursor pagination. |
| 3 | * |
| 4 | * Reproduces PLEN-1886: if the SDK silently drops the `cursor` input, |
| 5 | * page 2 will equal page 1 and the overlap assertion throws. |
| 6 | * |
| 7 | * Uses the global toolkit catalog (no `toolkits` filter on session create), |
| 8 | * so this works against any Composio project. |
| 9 | * |
| 10 | * Requires COMPOSIO_API_KEY in environment. |
| 11 | */ |
| 12 | import { Composio } from '@composio/core'; |
| 13 | |
| 14 | const apiKey = process.env.COMPOSIO_API_KEY; |
| 15 | if (!apiKey) { |
| 16 | console.error('COMPOSIO_API_KEY is required'); |
| 17 | process.exit(1); |
| 18 | } |
| 19 | |
| 20 | const composio = new Composio({ apiKey }); |
| 21 | |
| 22 | async function main() { |
| 23 | const userId = `e2e-tool-router-pagination-${Date.now()}`; |
| 24 | const session = await composio.create(userId); |
| 25 | |
| 26 | const page1 = await session.toolkits({ limit: 2 }); |
| 27 | if (page1.items.length !== 2) { |
| 28 | throw new Error(`expected 2 items on page 1, got ${page1.items.length}`); |
| 29 | } |
| 30 | if (!page1.cursor) { |
| 31 | throw new Error('expected page 1 to return a cursor — catalog should have > 2 toolkits'); |
| 32 | } |
| 33 | console.log('PAGE1_OK'); |
| 34 | |
| 35 | const page2 = await session.toolkits({ limit: 2, cursor: page1.cursor }); |
| 36 | if (page2.items.length === 0) { |
| 37 | throw new Error('expected page 2 to return items'); |
| 38 | } |
| 39 | console.log('PAGE2_OK'); |
| 40 | |
| 41 | const page1Slugs = new Set(page1.items.map(t => t.slug)); |
| 42 | const overlap = page2.items.filter(t => page1Slugs.has(t.slug)).map(t => t.slug); |
| 43 | if (overlap.length > 0) { |
| 44 | throw new Error(`pagination did not advance — page 2 overlaps page 1 on: ${overlap.join(', ')}`); |
| 45 | } |
| 46 | console.log('ADVANCED_OK'); |
| 47 | |
| 48 | console.log('ALL_OK'); |
| 49 | } |
| 50 | |
| 51 | main().catch(err => { |
| 52 | console.log('ERROR:', err?.message || err); |
| 53 | process.exit(1); |
| 54 | }); |