@devries-cameron20 / composio-1 / commits / 5e379ee47
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.

refactor(docs): deduplicate processParams in LLM route using shared helpers

Replace the local processParams function and inline schema extraction with processSchema and toolFromApi from @/lib/toolkit-schema. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmithamallesh committed Feb 5, 2026 at 22:19 UTC 5e379ee473cbd1d1ada1bd5f2c32c7f69e0ef913
1 file changed +11 -62
docs/app/llms.mdx/[[...slug]]/route.ts
+11 -62
@@ -14,6 +14,7 @@ import { notFound } from 'next/navigation';
14 import { readFile } from 'fs/promises';
15 import { join } from 'path';
16 import type { Toolkit, Tool, Trigger, ParameterSchema } from '@/types/toolkit';
17 +import { processSchema, toolFromApi } from '@/lib/toolkit-schema';
18
19 export const revalidate = false;
20
@@ -21,29 +22,6 @@ const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/
22 const API_KEY = process.env.COMPOSIO_API_KEY;
23 const API_FETCH_LIMIT = 1000; // Note: Toolkits with more items will be truncated
24
24 -/**
25 - * Process raw parameter properties into typed ParameterSchema records.
26 - * Adds required flag based on the requiredList from JSON Schema.
27 - */
28 -function processParams(
29 - props: unknown,
30 - requiredList: string[]
31 -): Record<string, ParameterSchema> | undefined {
32 - if (!props || typeof props !== 'object') return undefined;
33 -
34 - const result: Record<string, ParameterSchema> = {};
35 - for (const [key, value] of Object.entries(props)) {
36 - if (typeof value === 'object' && value !== null) {
37 - result[key] = {
38 - ...(value as ParameterSchema),
39 - // Explicitly set required based on JSON Schema required array
40 - required: requiredList.includes(key),
41 - };
42 - }
43 - }
44 - return Object.keys(result).length > 0 ? result : undefined;
45 -}
46 -
25 // Fetch detailed tool info from Composio API
26 async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
27 if (!API_KEY) {
@@ -81,26 +59,7 @@ async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
59 }
60
61 // eslint-disable-next-line @typescript-eslint/no-explicit-any
84 - return items.filter((tool: any) => tool && typeof tool === 'object').map((tool: any) => {
85 - const inputSchema = tool.input_parameters || tool.parameters;
86 - const outputSchema = tool.output_parameters || tool.response;
87 -
88 - const inputProps = inputSchema?.properties || inputSchema;
89 - const inputRequired = inputSchema?.required || [];
90 - const outputProps = outputSchema?.properties || outputSchema;
91 - const outputRequired = outputSchema?.required || [];
92 -
93 - return {
94 - slug: tool.slug || '',
95 - name: tool.name || tool.display_name || tool.slug || '',
96 - description: tool.description || '',
97 - input_parameters: processParams(inputProps, inputRequired),
98 - output_parameters: processParams(outputProps, outputRequired),
99 - scopes: tool.scopes,
100 - tags: tool.tags,
101 - is_deprecated: tool.is_deprecated || false,
102 - };
103 - });
62 + return items.filter((tool: any) => tool && typeof tool === 'object').map(toolFromApi);
63 } catch {
64 return null;
65 }
@@ -143,25 +102,15 @@ async function fetchDetailedTriggers(toolkitSlug: string): Promise<Trigger[] | n
102 }
103
104 // eslint-disable-next-line @typescript-eslint/no-explicit-any
146 - return items.filter((trigger: any) => trigger && typeof trigger === 'object').map((trigger: any) => {
147 - const configSchema = trigger.config;
148 - const payloadSchema = trigger.payload;
149 -
150 - const configProps = configSchema?.properties || configSchema;
151 - const configRequired = configSchema?.required || [];
152 - const payloadProps = payloadSchema?.properties || payloadSchema;
153 - const payloadRequired = payloadSchema?.required || [];
154 -
155 - return {
156 - slug: trigger.slug || '',
157 - name: trigger.name || trigger.display_name || trigger.slug || '',
158 - description: trigger.description || '',
159 - type: trigger.type,
160 - config: processParams(configProps, configRequired),
161 - payload: processParams(payloadProps, payloadRequired),
162 - instructions: trigger.instructions,
163 - };
164 - });
105 + return items.filter((trigger: any) => trigger && typeof trigger === 'object').map((trigger: any) => ({
106 + slug: trigger.slug || '',
107 + name: trigger.name || trigger.display_name || trigger.slug || '',
108 + description: trigger.description || '',
109 + type: trigger.type,
110 + config: processSchema(trigger.config),
111 + payload: processSchema(trigger.payload),
112 + instructions: trigger.instructions,
113 + }));
114 } catch {
115 return null;
116 }