Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
tsx 161 lines 6.24 KB
Raw
1 'use client';
2
3 import { useState } from 'react';
4 import type { MetaTool, MetaToolParameter, MetaToolSchema } from '@/lib/meta-tools-data';
5 import {
6 Collapsible,
7 CollapsibleContent,
8 CollapsibleTrigger,
9 } from 'fumadocs-ui/components/ui/collapsible';
10 import { cn } from '@/lib/utils';
11 import { ChevronDown, ChevronRight } from 'lucide-react';
12
13 const TAG_LABELS: Record<string, { label: string; className: string }> = {
14 readOnlyHint: {
15 label: 'Read-only',
16 className: 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 border-emerald-500/20',
17 },
18 destructiveHint: {
19 label: 'Destructive',
20 className: 'bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20',
21 },
22 important: {
23 label: 'Important',
24 className: 'bg-amber-500/10 text-amber-700 dark:text-amber-400 border-amber-500/20',
25 },
26 };
27
28 function TagBadge({ tag }: { tag: string }) {
29 const info = TAG_LABELS[tag];
30 if (!info) return null;
31 return (
32 <span className={cn('inline-flex items-center rounded-md border px-2 py-0.5 text-xs font-medium', info.className)}>
33 {info.label}
34 </span>
35 );
36 }
37
38 function ParameterRow({ name, param, isLast, showRequired = true, isRequired = false }: { name: string; param: MetaToolParameter; isLast: boolean; showRequired?: boolean; isRequired?: boolean }) {
39 const hasNested = Object.keys(param.properties).length > 0;
40 const nestedSchema = hasNested ? param : param.items;
41 const nestedCount = nestedSchema ? Object.keys(nestedSchema.properties).length : 0;
42 const [isOpen, setIsOpen] = useState(false);
43
44 return (
45 <div className={cn(!isLast && 'border-b border-fd-border')}>
46 <div className="py-3">
47 <div className="flex flex-wrap items-center gap-2">
48 <code className="text-sm font-semibold font-mono text-fd-foreground">{name}</code>
49 <span className="text-xs font-mono text-fd-muted-foreground">{param.typeLabel}</span>
50 {showRequired && isRequired && (
51 <span className="text-xs font-medium text-red-500 dark:text-red-400">Required</span>
52 )}
53 {param.defaultLabel !== null && (
54 <span className="text-xs text-fd-muted-foreground">
55 Default: <code className="rounded border border-fd-border px-1 py-0.5 text-xs">{param.defaultLabel}</code>
56 </span>
57 )}
58 </div>
59 {param.description && (
60 <p className="mt-1.5 text-sm text-fd-muted-foreground leading-relaxed">
61 {param.description}
62 </p>
63 )}
64 {param.enum.length > 0 && (
65 <div className="mt-2">
66 <span className="text-xs text-fd-muted-foreground">Possible values: </span>
67 <span className="inline-flex flex-wrap gap-1 mt-0.5">
68 {param.enum.map((v) => (
69 <code key={v} className="rounded border border-fd-border px-1.5 py-0.5 text-xs font-mono text-fd-muted-foreground">
70 {v}
71 </code>
72 ))}
73 </span>
74 </div>
75 )}
76 {nestedSchema && nestedCount > 0 && (
77 <Collapsible open={isOpen} onOpenChange={setIsOpen} className="mt-2">
78 <CollapsibleTrigger className="flex items-center gap-1 text-xs text-fd-muted-foreground hover:text-fd-foreground font-medium transition-colors">
79 {isOpen ? <ChevronDown className="h-3 w-3" /> : <ChevronRight className="h-3 w-3" />}
80 {hasNested ? `Show ${nestedCount} properties` : `Show ${nestedCount} item properties`}
81 </CollapsibleTrigger>
82 <CollapsibleContent>
83 <div className="mt-2 pl-3 border-l-2 border-fd-border">
84 <ParameterList
85 parameters={nestedSchema.properties}
86 requiredFields={nestedSchema.required}
87 showRequired={showRequired}
88 />
89 </div>
90 </CollapsibleContent>
91 </Collapsible>
92 )}
93 </div>
94 </div>
95 );
96 }
97
98 function ParameterList({ parameters, requiredFields = [], showRequired = true }: { parameters: Record<string, MetaToolParameter>; requiredFields?: string[]; showRequired?: boolean }) {
99 const entries = Object.entries(parameters);
100 return (
101 <div>
102 {entries.map(([name, param], idx) => (
103 <ParameterRow key={name} name={name} param={param} isLast={idx === entries.length - 1} showRequired={showRequired} isRequired={requiredFields.includes(name)} />
104 ))}
105 </div>
106 );
107 }
108
109 function SchemaSection({ title, schema, showRequired = true }: { title: string; schema: MetaToolSchema; showRequired?: boolean }) {
110 const properties = schema.properties;
111 const entries = Object.entries(properties);
112
113 if (entries.length === 0) return null;
114
115 return (
116 <div>
117 <h2 className="text-base font-semibold text-fd-foreground mb-3">{title}</h2>
118 <div className="rounded-lg border border-fd-border bg-fd-card">
119 <div className="px-4">
120 <ParameterList parameters={properties} requiredFields={schema.required} showRequired={showRequired} />
121 </div>
122 </div>
123 </div>
124 );
125 }
126
127 export function MetaToolDetail({ tool }: { tool: MetaTool }) {
128 return (
129 <div className="space-y-6">
130 {/* Header */}
131 <div className="space-y-3">
132 <div className="flex flex-wrap items-center gap-2">
133 <code className="text-sm font-mono text-fd-muted-foreground">{tool.slug}</code>
134 {tool.tags.map((tag) => (
135 <TagBadge key={tag} tag={tag} />
136 ))}
137 </div>
138 {tool.summary && (
139 <p className="text-base text-fd-foreground leading-relaxed">{tool.summary}</p>
140 )}
141 </div>
142
143 {/* When to use it */}
144 {tool.whenToUse && (
145 <div className="rounded-lg border border-fd-border bg-fd-card p-4">
146 <h2 className="text-base font-semibold text-fd-foreground mb-1.5">When to use it</h2>
147 <p className="text-sm text-fd-muted-foreground leading-relaxed">{tool.whenToUse}</p>
148 {tool.usageNote && (
149 <p className="mt-2 text-sm text-fd-muted-foreground leading-relaxed">{tool.usageNote}</p>
150 )}
151 </div>
152 )}
153
154 {/* Input parameters */}
155 <SchemaSection title="Input parameters" schema={tool.inputParameters} />
156
157 {/* Response */}
158 <SchemaSection title="Response" schema={tool.responseSchema} showRequired={false} />
159 </div>
160 );
161 }