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 | import { z } from 'zod'; |
| 2 | import { createComposioClient, listToolkits } from './composio-api'; |
| 3 | import { isPublicToolkitSlug } from './public-toolkit-policy'; |
| 4 | |
| 5 | const toolkitsSchema = z.array(z.object({ |
| 6 | slug: z.string().min(1), |
| 7 | instant: z.object({ supported: z.boolean() }).nullish(), |
| 8 | })); |
| 9 | |
| 10 | /** |
| 11 | * Reduces a complete /toolkits listing to its public Instant-supported slugs. |
| 12 | * Throws when no toolkit carries eligibility, which means the listing is not |
| 13 | * eligibility-aware rather than that no toolkit qualifies. |
| 14 | */ |
| 15 | export function instantToolkitSlugs(items: unknown[]): string[] { |
| 16 | const toolkits = toolkitsSchema.parse(items); |
| 17 | if (!toolkits.some(toolkit => toolkit.instant != null)) throw new Error('Toolkit eligibility missing'); |
| 18 | const slugs = toolkits |
| 19 | .filter(toolkit => toolkit.instant?.supported === true) |
| 20 | .map(toolkit => toolkit.slug.toLowerCase()) |
| 21 | .filter(isPublicToolkitSlug); |
| 22 | return [...new Set(slugs)]; |
| 23 | } |
| 24 | |
| 25 | // Called only by the server route. Never return partial pages as a complete list. |
| 26 | export async function fetchInstantToolkitSlugs(apiKey: string, fetcher?: typeof fetch): Promise<string[]> { |
| 27 | const client = createComposioClient(apiKey, { revalidate: 300, fetch: fetcher }); |
| 28 | return instantToolkitSlugs(await listToolkits(client, { signal: AbortSignal.timeout(15000) })); |
| 29 | } |