6
import { PageActions } from '@/components/page-actions';
7
import { readFile } from 'fs/promises';
8
import { join } from 'path';
9
+import { unified } from 'unified';
10
+import remarkParse from 'remark-parse';
11
+import remarkRehype from 'remark-rehype';
12
+import { toHtml } from 'hast-util-to-html';
13
import type { Metadata } from 'next';
14
import type { Toolkit, Tool, Trigger } from '@/types/toolkit';
15
+import type { FaqItem } from '@/components/toolkits/faq-section';
16
import { processSchema, toolFromApi } from '@/lib/toolkit-schema';
17
18
const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
100
}
101
}
102
103
+function markdownToHtml(md: string): string {
104
+ const tree = unified().use(remarkParse).parse(md);
105
+ const hast = unified().use(remarkRehype).runSync(tree);
106
+ return toHtml(hast);
107
+}
108
+
109
+async function readToolkitFaq(slug: string): Promise<FaqItem[] | null> {
110
+ const filePath = join(process.cwd(), 'content/toolkit-faq', `${slug}.md`);
111
+ let content: string;
112
+ try {
113
+ content = await readFile(filePath, 'utf-8');
114
+ } catch {
115
+ return null;
116
+ }
117
+
118
+ const items: FaqItem[] = [];
119
+ const sections = content.split(/^## /m).filter(Boolean);
120
+ for (const section of sections) {
121
+ const newlineIdx = section.indexOf('\n');
122
+ if (newlineIdx === -1) continue;
123
+ const question = section.slice(0, newlineIdx).trim();
124
+ const answerMd = section.slice(newlineIdx + 1).trim();
125
+ if (question && answerMd) {
126
+ items.push({ question, answer: markdownToHtml(answerMd) });
127
+ }
128
+ }
129
+ return items.length > 0 ? items : null;
130
+}
131
+
132
async function getToolkits(): Promise<Toolkit[]> {
133
const filePath = join(process.cwd(), 'public/data/toolkits.json');
134
249
const toolkit = toolkits.find((t) => t.slug === toolkitSlug);
250
251
if (toolkit) {
218
- // Fetch detailed tool and trigger info from API (includes input/output params)
219
- const [detailedTools, detailedTriggers] = await Promise.all([
252
+ // Fetch detailed tool/trigger info and FAQ content in parallel
253
+ const [detailedTools, detailedTriggers, faq] = await Promise.all([
254
fetchDetailedTools(toolkitSlug, toolkit.version),
255
fetchDetailedTriggers(toolkitSlug, toolkit.version),
256
+ readToolkitFaq(toolkitSlug),
257
]);
258
259
// Use detailed data if fetch succeeded, otherwise fall back to static data
266
tools={tools}
267
triggers={triggers}
268
path={`/toolkits/${toolkit.slug}`}
269
+ faq={faq}
270
/>
271
);
272
}