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 | * Deterministic smoke test for the Mastra example. |
| 3 | * |
| 4 | * A live integration signal: it exercises the provider tool-wrapping and Tool |
| 5 | * Router session paths end-to-end against a real backend (staging in CI) using |
| 6 | * the unauthenticated HACKERNEWS toolkit, proving the wrapping does not throw |
| 7 | * and returns usable tools. |
| 8 | * |
| 9 | * It intentionally does NOT re-check schema shape. The schema-conversion |
| 10 | * invariants behind the historical regressions — |
| 11 | * - ComposioHQ/composio#2109 (Mastra zod->json serialization crash) |
| 12 | * - ComposioHQ/composio#3307 (dangling $ref when $defs is dropped) |
| 13 | * - mastra-ai/mastra#13909 (already-JSON-Schema tools crash serialization) |
| 14 | * are owned and regression-tested deterministically in the provider itself |
| 15 | * (ts/packages/providers/mastra/test/{mastra-dangling-defs,mastra-ref}.test.ts), |
| 16 | * which run per-PR and blocking with no secrets. Duplicating that here against a |
| 17 | * live toolkit that never emits the pathological schema would only add flake. |
| 18 | * |
| 19 | * It needs only COMPOSIO_API_KEY (no LLM key) so it is cheap and non-flaky. |
| 20 | * When COMPOSIO_API_KEY is absent (e.g. fork PRs) it skips cleanly. |
| 21 | * |
| 22 | * Run: bun ts/examples/mastra/src/smoke.ts |
| 23 | */ |
| 24 | import { Composio } from '@composio/core'; |
| 25 | import { MastraProvider } from '@composio/mastra'; |
| 26 | import 'dotenv/config'; |
| 27 | |
| 28 | const TOOLKIT = 'hackernews'; |
| 29 | const USER_ID = 'examples-smoke'; |
| 30 | |
| 31 | function assert(condition: unknown, message: string): asserts condition { |
| 32 | if (!condition) throw new Error(`SMOKE FAIL: ${message}`); |
| 33 | } |
| 34 | |
| 35 | if (!process.env.COMPOSIO_API_KEY) { |
| 36 | console.log('⏭️ COMPOSIO_API_KEY not set — skipping Mastra smoke.'); |
| 37 | process.exit(0); |
| 38 | } |
| 39 | |
| 40 | console.log(`Backend: ${process.env.COMPOSIO_BASE_URL ?? '(default/production)'}`); |
| 41 | |
| 42 | const composio = new Composio({ |
| 43 | apiKey: process.env.COMPOSIO_API_KEY, |
| 44 | provider: new MastraProvider(), |
| 45 | }); |
| 46 | |
| 47 | // 1. Direct tools: provider wrapping must not throw and must produce tools. |
| 48 | const wrapped = await composio.tools.get(USER_ID, { toolkits: [TOOLKIT] }); |
| 49 | const wrappedSlugs = Object.keys(wrapped); |
| 50 | assert(wrappedSlugs.length > 0, `mastra direct wrapping returned 0 tools for ${TOOLKIT}`); |
| 51 | for (const [slug, tool] of Object.entries(wrapped)) { |
| 52 | assert( |
| 53 | (tool as { inputSchema?: unknown }).inputSchema != null, |
| 54 | `mastra tool ${slug} has no inputSchema after wrapping` |
| 55 | ); |
| 56 | // Serializing the wrapped schema must not throw (guards the crash-on-serialize path). |
| 57 | JSON.stringify((tool as { inputSchema?: unknown }).inputSchema); |
| 58 | } |
| 59 | console.log(` ✓ direct wrapping: ${wrappedSlugs.length} tools`); |
| 60 | |
| 61 | // 2. Tool Router: the v1-canonical session path must return router tools. |
| 62 | const session = await composio.sessions.create(USER_ID, { toolkits: [TOOLKIT] }); |
| 63 | const sessionTools = await session.tools(); |
| 64 | const sessionSlugs = Object.keys(sessionTools); |
| 65 | assert(sessionSlugs.length > 0, 'mastra session.tools() returned 0 tools'); |
| 66 | console.log(` ✓ tool-router session: ${sessionSlugs.length} tools`); |
| 67 | |
| 68 | console.log('\n✅ Mastra smoke passed.'); |