@devries-cameron20 / composio Mirror · read-only / commits / 7545287e2
Fork 0

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, 14:45 UTC

fix(docs): render live toolkits on snapshot miss

jkomyno committed Aug 25, 2026 at 03:33 UTC 7545287e21ea7c06cf7581817431473dce06dada
4 files changed +122 -3
docs/app/(home)/toolkits/[[...slug]]/page.tsx
+7 -3
@@ -8,7 +8,8 @@ import { PageActions } from '@/components/page-actions';
8 import { EditOnGitHub } from '@/components/edit-on-github';
9 import { readFile } from 'fs/promises';
10 import { join } from 'path';
11 -import { getAllToolkits, getToolkitBySlug } from '@/lib/toolkit-data';
11 +import { getAllToolkits } from '@/lib/toolkit-data';
12 +import { resolveToolkit } from '@/lib/toolkit-resolution';
13 import { unified } from 'unified';
14 import remarkParse from 'remark-parse';
15 import remarkRehype from 'remark-rehype';
@@ -21,6 +22,9 @@ import { apiToolListSchema, apiTriggerListSchema } from '@/lib/toolkit-schema';
22 const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
23 const API_KEY = process.env.COMPOSIO_API_KEY;
24
25 +// Snapshot misses are resolved from production on demand.
26 +export const dynamicParams = true;
27 +
28 // Fetch detailed tool info from Composio API (server-side only)
29 // Returns null on failure, empty array if toolkit has no tools
30 async function fetchDetailedTools(
@@ -177,7 +181,7 @@ export async function generateMetadata({
181
182 // Check JSON toolkit
183 if (slug.length === 1) {
180 - const toolkit = await getToolkitBySlug(slug[0]);
184 + const toolkit = await resolveToolkit(slug[0]);
185 if (toolkit) {
186 const title = `${toolkit.name?.trim() || toolkit.slug} - Composio Toolkit`;
187 const description = `Build an AI agent that connects to ${toolkit.name?.trim() || toolkit.slug} using Composio. ${toolkit.description}`;
@@ -230,7 +234,7 @@ export default async function ToolkitsPage({ params }: { params: Promise<{ slug?
234 // Check JSON toolkit
235 if (slug.length === 1) {
236 const toolkitSlug = slug[0];
233 - const toolkit = await getToolkitBySlug(toolkitSlug);
237 + const toolkit = await resolveToolkit(toolkitSlug);
238
239 if (toolkit) {
240 // Fetch detailed tool/trigger info and FAQ content in parallel
docs/lib/toolkit-resolution.ts new
+10
@@ -0,0 +1,10 @@
1 +import { fetchToolkitFromProduction } from '@/lib/toolkit-api';
2 +import { getToolkitBySlug } from '@/lib/toolkit-data';
3 +import type { Toolkit } from '@/types/toolkit';
4 +
5 +export async function resolveToolkit(slug: string): Promise<Toolkit | null> {
6 + const snapshotToolkit = await getToolkitBySlug(slug);
7 + if (snapshotToolkit) return snapshotToolkit;
8 +
9 + return fetchToolkitFromProduction(slug);
10 +}
docs/tests/integration/toolkit-fallback.test.ts new
+36
@@ -0,0 +1,36 @@
1 +import { describe, expect, test } from 'bun:test';
2 +import { fetchPage } from './helpers';
3 +
4 +const LIVE_ONLY_TOOLKIT_SLUG = '7shifts';
5 +
6 +describe('toolkit snapshot fallback', () => {
7 + test('renders a toolkit from the committed snapshot', async () => {
8 + const response = await fetchPage('/toolkits/github');
9 + const html = await response.text();
10 +
11 + expect(response.status).toBe(200);
12 + expect(response.headers.get('content-type')).toContain('text/html');
13 + expect(html.toLowerCase()).toContain('github');
14 + });
15 +
16 + test('returns 404 for a nonsense toolkit slug', async () => {
17 + const response = await fetchPage('/toolkits/__definitely-not-a-toolkit__');
18 +
19 + expect(response.status).toBe(404);
20 + });
21 +
22 + if (process.env.COMPOSIO_API_KEY) {
23 + test('renders fallback content and metadata for a production-only toolkit', async () => {
24 + const response = await fetchPage(`/toolkits/${LIVE_ONLY_TOOLKIT_SLUG}`);
25 + const html = await response.text();
26 +
27 + expect(response.status).toBe(200);
28 + expect(html.toLowerCase()).toContain('7shifts');
29 + expect(html).toMatch(/<title>[^<]*7shifts[^<]*Composio Toolkit[^<]*<\/title>/i);
30 + expect(html).toContain(`<link rel="canonical" href="/toolkits/${LIVE_ONLY_TOOLKIT_SLUG}"`);
31 + expect(html).not.toContain('<title>Toolkit Not Found');
32 + });
33 + } else {
34 + test.skip('production-only fallback requires COMPOSIO_API_KEY', () => {});
35 + }
36 +});
docs/tests/static/toolkit-fallback.test.ts new
+69
@@ -0,0 +1,69 @@
1 +import { beforeAll, beforeEach, describe, expect, mock, test } from 'bun:test';
2 +import type { Toolkit } from '../../types/toolkit';
3 +
4 +const snapshotToolkit: Toolkit = {
5 + slug: 'github',
6 + name: 'GitHub',
7 + logo: 'https://logos.composio.dev/api/github',
8 + description: 'GitHub snapshot description',
9 + category: 'developer tools',
10 + authSchemes: ['OAUTH2'],
11 + composioManagedAuthSchemes: ['OAUTH2'],
12 + toolCount: 10,
13 + triggerCount: 2,
14 + version: '20260817_00',
15 + tools: [],
16 + triggers: [],
17 +};
18 +
19 +const liveToolkit: Toolkit = {
20 + ...snapshotToolkit,
21 + slug: 'live-only',
22 + name: 'Live Only',
23 + description: 'Production fallback description',
24 + version: null,
25 +};
26 +
27 +const getToolkitBySlug = mock(async (_slug: string): Promise<Toolkit | null> => null);
28 +const fetchToolkitFromProduction = mock(
29 + async (_slug: string): Promise<Toolkit | null> => null
30 +);
31 +
32 +mock.module('@/lib/toolkit-data', () => ({ getToolkitBySlug }));
33 +mock.module('@/lib/toolkit-api', () => ({ fetchToolkitFromProduction }));
34 +
35 +let resolveToolkit: typeof import('../../lib/toolkit-resolution').resolveToolkit;
36 +
37 +beforeAll(async () => {
38 + ({ resolveToolkit } = await import('../../lib/toolkit-resolution'));
39 +});
40 +
41 +beforeEach(() => {
42 + getToolkitBySlug.mockReset();
43 + fetchToolkitFromProduction.mockReset();
44 +});
45 +
46 +describe('resolveToolkit', () => {
47 + test('returns a snapshot hit without calling production', async () => {
48 + getToolkitBySlug.mockResolvedValue(snapshotToolkit);
49 +
50 + expect(await resolveToolkit('github')).toEqual(snapshotToolkit);
51 + expect(getToolkitBySlug).toHaveBeenCalledWith('github');
52 + expect(fetchToolkitFromProduction).not.toHaveBeenCalled();
53 + });
54 +
55 + test('returns a production toolkit after a snapshot miss', async () => {
56 + getToolkitBySlug.mockResolvedValue(null);
57 + fetchToolkitFromProduction.mockResolvedValue(liveToolkit);
58 +
59 + expect(await resolveToolkit('live-only')).toEqual(liveToolkit);
60 + expect(fetchToolkitFromProduction).toHaveBeenCalledWith('live-only');
61 + });
62 +
63 + test('returns null when both snapshot and production miss', async () => {
64 + getToolkitBySlug.mockResolvedValue(null);
65 + fetchToolkitFromProduction.mockResolvedValue(null);
66 +
67 + expect(await resolveToolkit('__definitely-not-a-toolkit__')).toBeNull();
68 + });
69 +});