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 22, 10:45 UTC
refactor(docs): extract shared toolkit schema processing into lib/toolkit-schema
Deduplicates processParams/processApiSchema/toolFromApi that were duplicated across the server page and client toolkit-detail component. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sushmithamallesh committed
Feb 5, 2026 at 21:02 UTC
b890e2d9583f8e13580ae9b6c1e024ac767c0ede
3 files changed
+55
-73
docs/app/(home)/toolkits/[[...slug]]/page.tsx
+1
-45
@@ -8,55 +8,11 @@ import { readFile } from 'fs/promises';
8
import { join } from 'path';
9
import type { Metadata } from 'next';
10
import type { Toolkit, Tool, Trigger } from '@/types/toolkit';
11
+import { processParams, toolFromApi } from '@/lib/toolkit-schema';
12
13
const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
14
const API_KEY = process.env.COMPOSIO_API_KEY;
15
15
-// Add required flag to each property based on the required array
16
-// Preserves nested properties/items for object and array types
17
-function processParams(props: any, requiredList: string[]): Record<string, any> | undefined {
18
- if (!props || typeof props !== 'object') return undefined;
19
- const result: Record<string, any> = {};
20
- for (const [key, value] of Object.entries(props)) {
21
- if (typeof value === 'object' && value !== null) {
22
- const param = value as any;
23
- result[key] = {
24
- type: param.type,
25
- description: param.description,
26
- default: param.default,
27
- example: param.example,
28
- enum: param.enum,
29
- required: requiredList.includes(key),
30
- ...(param.properties ? { properties: param.properties } : {}),
31
- ...(param.required ? { requiredFields: param.required } : {}),
32
- ...(param.items ? { items: param.items } : {}),
33
- };
34
- }
35
- }
36
- return Object.keys(result).length > 0 ? result : undefined;
37
-}
38
-
39
-function toolFromApi(tool: any): Tool {
40
- const inputSchema = tool.input_parameters || tool.parameters;
41
- const outputSchema = tool.output_parameters || tool.response;
42
-
43
- const inputProps = inputSchema?.properties || inputSchema;
44
- const inputRequired = inputSchema?.required || [];
45
- const outputProps = outputSchema?.properties || outputSchema;
46
- const outputRequired = outputSchema?.required || [];
47
-
48
- return {
49
- slug: tool.slug || '',
50
- name: tool.name || tool.display_name || tool.slug || '',
51
- description: tool.description || '',
52
- input_parameters: processParams(inputProps, inputRequired),
53
- output_parameters: processParams(outputProps, outputRequired),
54
- scopes: tool.scopes || undefined,
55
- tags: tool.tags || undefined,
56
- is_deprecated: tool.is_deprecated || false,
57
- };
58
-}
59
-
16
// Fetch detailed tool info from Composio API (server-side only)
17
// Returns null on failure, empty array if toolkit has no tools
18
async function fetchDetailedTools(toolkitSlug: string, version?: string | null): Promise<Tool[] | null> {
docs/components/toolkits/toolkit-detail.tsx
+3
-28
@@ -5,6 +5,7 @@ import Link from 'next/link';
5
import { ExternalLink, Search, Copy, Check, ChevronDown, ChevronRight, ArrowLeft } from 'lucide-react';
6
import { TypeTable } from 'fumadocs-ui/components/type-table';
7
import type { Toolkit, Tool, Trigger, ParameterSchema } from '@/types/toolkit';
8
+import { processSchema } from '@/lib/toolkit-schema';
9
import { PageActions } from '@/components/page-actions';
10
import { AuthDetailsSection } from '@/components/toolkits/auth-details-section';
11
@@ -105,32 +106,6 @@ function paramsToTypeTable(params: Record<string, ParameterSchema>): Record<stri
106
return result;
107
}
108
108
-// Process raw API schema into ParameterSchema records
109
-function processApiSchema(schema: any): Record<string, ParameterSchema> | undefined {
110
- if (!schema) return undefined;
111
- const props = schema.properties || schema;
112
- const required = schema.required || [];
113
- if (!props || typeof props !== 'object') return undefined;
114
-
115
- const result: Record<string, ParameterSchema> = {};
116
- for (const [key, value] of Object.entries(props)) {
117
- if (typeof value === 'object' && value !== null) {
118
- const param = value as any;
119
- result[key] = {
120
- type: param.type,
121
- description: param.description,
122
- default: param.default,
123
- example: param.example,
124
- enum: param.enum,
125
- required: required.includes(key),
126
- ...(param.properties ? { properties: param.properties } : {}),
127
- ...(param.required ? { requiredFields: param.required } : {}),
128
- ...(param.items ? { items: param.items } : {}),
129
- };
130
- }
131
- }
132
- return Object.keys(result).length > 0 ? result : undefined;
133
-}
109
110
// Check if item is a Tool with parameters
111
function isTool(item: Tool | Trigger): item is Tool {
@@ -171,8 +146,8 @@ function ToolItem({ item, toolkitVersion }: { item: Tool | Trigger; toolkitVersi
146
if (res.ok) {
147
const data = await res.json();
148
setDetailedParams({
174
- input: processApiSchema(data.input_parameters),
175
- output: processApiSchema(data.output_parameters),
149
+ input: processSchema(data.input_parameters),
150
+ output: processSchema(data.output_parameters),
151
});
152
}
153
} catch {
docs/lib/toolkit-schema.ts
new
+51
@@ -0,0 +1,51 @@
1
+import type { ParameterSchema, Tool } from '@/types/toolkit';
2
+
3
+// Add required flag to each property based on the required array
4
+// Preserves nested properties/items for object and array types
5
+export function processParams(props: any, requiredList: string[]): Record<string, ParameterSchema> | undefined {
6
+ if (!props || typeof props !== 'object') return undefined;
7
+ const result: Record<string, ParameterSchema> = {};
8
+ for (const [key, value] of Object.entries(props)) {
9
+ if (typeof value === 'object' && value !== null) {
10
+ const param = value as any;
11
+ result[key] = {
12
+ type: param.type,
13
+ description: param.description,
14
+ default: param.default,
15
+ example: param.example,
16
+ enum: param.enum,
17
+ required: requiredList.includes(key),
18
+ ...(param.properties ? { properties: param.properties } : {}),
19
+ ...(param.required ? { requiredFields: param.required } : {}),
20
+ ...(param.items ? { items: param.items } : {}),
21
+ };
22
+ }
23
+ }
24
+ return Object.keys(result).length > 0 ? result : undefined;
25
+}
26
+
27
+// Process a raw JSON Schema (with top-level properties + required) into ParameterSchema records
28
+export function processSchema(schema: any): Record<string, ParameterSchema> | undefined {
29
+ if (!schema) return undefined;
30
+ const props = schema.properties || schema;
31
+ const required = schema.required || [];
32
+ if (!props || typeof props !== 'object') return undefined;
33
+ return processParams(props, required);
34
+}
35
+
36
+// Convert a raw API tool object into our Tool type
37
+export function toolFromApi(tool: any): Tool {
38
+ const inputSchema = tool.input_parameters || tool.parameters;
39
+ const outputSchema = tool.output_parameters || tool.response;
40
+
41
+ return {
42
+ slug: tool.slug || '',
43
+ name: tool.name || tool.display_name || tool.slug || '',
44
+ description: tool.description || '',
45
+ input_parameters: processSchema(inputSchema),
46
+ output_parameters: processSchema(outputSchema),
47
+ scopes: tool.scopes || undefined,
48
+ tags: tool.tags || undefined,
49
+ is_deprecated: tool.is_deprecated || false,
50
+ };
51
+}