1
+// Use direct imports from collections to avoid top-level await in lib/source.ts.
2
+import { createHash } from 'node:crypto';
3
+import { existsSync, readdirSync, readFileSync } from 'node:fs';
4
+import { join, relative } from 'node:path';
5
+import { docs, reference, cookbooks, toolkits } from 'fumadocs-mdx:collections/server';
6
+import { loader, multiple } from 'fumadocs-core/source';
7
+import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';
8
+import { openapiSource, openapiPlugin } from 'fumadocs-openapi/server';
9
+import type { AdvancedIndex } from 'fumadocs-core/search/server';
10
+import type { BaseIndex } from 'fumadocs-core/search/algolia';
11
+import { openapi } from '@/lib/openapi';
12
+import { mdxToCleanMarkdown } from '@/lib/source';
13
+import { getAllToolkitsSync } from '@/lib/toolkit-data';
14
+
15
+export const ALGOLIA_DEFAULT_APP_ID = '62HI9PQZ1L';
16
+export const ALGOLIA_DEFAULT_INDEX_NAME = 'docs_composio_dev_62hi9pqz1l_pages';
17
+
18
+const MAX_CHUNK_CHARS = 3_800;
19
+const MAX_CHUNK_BYTES = 9_000;
20
+const MAX_TOOL_ALIAS_ITEMS = 80;
21
+const MAX_TOOL_ALIAS_BYTES = 2_500;
22
+
23
+// Create loaders directly here to avoid the problematic lib/source.ts import in the
24
+// fallback route. This route is intentionally still Fumadocs/Orama-backed for local
25
+// development when Algolia env vars aren't configured.
26
+const docsSource = loader({
27
+ baseUrl: '/docs',
28
+ source: docs.toFumadocsSource(),
29
+ plugins: [lucideIconsPlugin()],
30
+});
31
+
32
+const cookbooksSource = loader({
33
+ baseUrl: '/cookbooks',
34
+ source: cookbooks.toFumadocsSource(),
35
+ plugins: [lucideIconsPlugin()],
36
+});
37
+
38
+const toolkitsSource = loader({
39
+ baseUrl: '/toolkits',
40
+ source: toolkits.toFumadocsSource(),
41
+ plugins: [lucideIconsPlugin()],
42
+});
43
+
44
+type SearchIndex = AdvancedIndex & {
45
+ keywords?: string[];
46
+};
47
+
48
+export type AlgoliaDocsRecord = BaseIndex & {
49
+ objectID: string;
50
+ description?: string;
51
+ keywords?: string[];
52
+ slug?: string;
53
+ headings?: string[];
54
+ tool_names?: string[];
55
+ tool_slugs?: string[];
56
+ type: string;
57
+ lang: string;
58
+ page_rank: number;
59
+ toolkit_popularity: number;
60
+ section_rank: number;
61
+ position: number;
62
+ depth: number;
63
+ tags?: string[];
64
+};
65
+
66
+function getFrontmatter(source: string): string {
67
+ return source.match(/^---\n([\s\S]*?)\n---/)?.[1] ?? '';
68
+}
69
+
70
+function getFrontmatterValue(frontmatter: string, key: string): string | undefined {
71
+ const match = frontmatter.match(new RegExp(`^${key}:\\s*(?:"([^"]*)"|'([^']*)'|(.+))$`, 'm'));
72
+ const value = match?.[1] ?? match?.[2] ?? match?.[3];
73
+ return value?.trim();
74
+}
75
+
76
+function getFrontmatterList(frontmatter: string, key: string): string[] {
77
+ const raw = getFrontmatterValue(frontmatter, key);
78
+ if (!raw) return [];
79
+
80
+ if (raw.startsWith('[') && raw.endsWith(']')) {
81
+ return raw
82
+ .slice(1, -1)
83
+ .split(',')
84
+ .map((value) => value.trim().replace(/^['"]|['"]$/g, ''))
85
+ .filter(Boolean);
86
+ }
87
+
88
+ return [raw];
89
+}
90
+
91
+function listContentFiles(dir: string): string[] {
92
+ if (!existsSync(dir)) return [];
93
+
94
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
95
+ const path = join(dir, entry.name);
96
+ if (entry.isDirectory()) return listContentFiles(path);
97
+ if (entry.isFile() && /\.mdx?$/.test(entry.name)) return [path];
98
+ return [];
99
+ });
100
+}
101
+
102
+function slugify(value: string): string {
103
+ return value
104
+ .toLowerCase()
105
+ .trim()
106
+ .replace(/[<>]/g, '')
107
+ .replace(/[`*_~\[\]()]/g, '')
108
+ .replace(/&[a-z]+;/g, '')
109
+ .replace(/[^\w\s-]/g, '')
110
+ .replace(/\s+/g, '-')
111
+ .replace(/-+/g, '-')
112
+ .replace(/^-|-$/g, '');
113
+}
114
+
115
+function uniqueSlug(value: string, seen: Map<string, number>): string {
116
+ const base = slugify(value) || 'section';
117
+ const count = seen.get(base) ?? 0;
118
+ seen.set(base, count + 1);
119
+ return count === 0 ? base : `${base}-${count + 1}`;
120
+}
121
+
122
+function splitIntoChunks(text: string): string[] {
123
+ const paragraphs = text
124
+ .split(/\n{2,}/)
125
+ .map((paragraph) => paragraph.trim())
126
+ .filter(Boolean);
127
+
128
+ const chunks: string[] = [];
129
+ let current = '';
130
+
131
+ const pushCurrent = () => {
132
+ const trimmed = current.trim();
133
+ if (trimmed) chunks.push(trimmed);
134
+ current = '';
135
+ };
136
+
137
+ for (const paragraph of paragraphs) {
138
+ const next = current ? `${current}\n\n${paragraph}` : paragraph;
139
+ if (next.length <= MAX_CHUNK_CHARS && Buffer.byteLength(next, 'utf8') <= MAX_CHUNK_BYTES) {
140
+ current = next;
141
+ continue;
142
+ }
143
+
144
+ pushCurrent();
145
+
146
+ if (paragraph.length <= MAX_CHUNK_CHARS && Buffer.byteLength(paragraph, 'utf8') <= MAX_CHUNK_BYTES) {
147
+ current = paragraph;
148
+ continue;
149
+ }
150
+
151
+ for (let i = 0; i < paragraph.length; i += MAX_CHUNK_CHARS) {
152
+ chunks.push(paragraph.slice(i, i + MAX_CHUNK_CHARS).trim());
153
+ }
154
+ }
155
+
156
+ pushCurrent();
157
+ return chunks;
158
+}
159
+
160
+function contentHash(value: string): string {
161
+ return createHash('sha1').update(value).digest('hex').slice(0, 10);
162
+}
163
+
164
+function urlFromContentPath(path: string): { url: string; type: string } | undefined {
165
+ const rel = relative(join(process.cwd(), 'content'), path).replace(/\\/g, '/');
166
+ const withoutExt = rel.replace(/\.mdx?$/, '');
167
+ const parts = withoutExt.split('/');
168
+ const collection = parts.shift();
169
+ if (!collection) return undefined;
170
+
171
+ if (collection === 'docs') {
172
+ return { url: `/docs/${parts.join('/')}`.replace(/\/index$/, ''), type: 'docs' };
173
+ }
174
+ if (collection === 'cookbooks') {
175
+ return { url: `/cookbooks/${parts.join('/')}`.replace(/\/index$/, ''), type: 'cookbooks' };
176
+ }
177
+ if (collection === 'reference') {
178
+ const url = `/reference/${parts.join('/')}`.replace(/\/index$/, '');
179
+ return { url, type: url.startsWith('/reference/v3') ? 'v3-reference' : 'reference' };
180
+ }
181
+ if (collection === 'toolkits') {
182
+ if (parts[0] === 'faq') return undefined;
183
+ return { url: `/toolkits/${parts.join('/')}`.replace(/\/index$/, ''), type: 'toolkits' };
184
+ }
185
+ if (collection === 'changelog') return undefined;
186
+
187
+ return undefined;
188
+}
189
+
190
+function slugTokens(url: string): string {
191
+ return url
192
+ .split(/[/-]/)
193
+ .map((part) => part.replace(/[_#?=&.]/g, ' '))
194
+ .join(' ')
195
+ .replace(/\s+/g, ' ')
196
+ .trim();
197
+}
198
+
199
+const typeLabels: Record<string, string> = {
200
+ docs: 'Docs',
201
+ cookbooks: 'Cookbook',
202
+ reference: 'Reference',
203
+ 'v3-reference': 'Legacy v3 Reference',
204
+ toolkits: 'Toolkit',
205
+ changelog: 'Changelog',
206
+ 'api-reference': 'API Reference',
207
+};
208
+
209
+function titleizeSlug(value: string): string {
210
+ return value
211
+ .split('-')
212
+ .filter(Boolean)
213
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
214
+ .join(' ')
215
+ .replace(/\bApi\b/g, 'API')
216
+ .replace(/\bMcp\b/g, 'MCP')
217
+ .replace(/\bSdk\b/g, 'SDK')
218
+ .replace(/\bOauth\b/g, 'OAuth');
219
+}
220
+
221
+function breadcrumbsForUrl(url: string, type: string): string[] {
222
+ const label = typeLabels[type] ?? titleizeSlug(type);
223
+
224
+ if (type === 'toolkits' || type === 'cookbooks' || type === 'changelog') {
225
+ return [label];
226
+ }
227
+
228
+ const parts = url.split('/').filter(Boolean);
229
+ const parentParts = parts.slice(1, -1);
230
+ return [label, ...parentParts.map(titleizeSlug)].filter(Boolean);
231
+}
232
+
233
+const TOOLKIT_POPULARITY_OVERRIDES: Record<string, number> = {
234
+ gmail: 1_000,
235
+ github: 980,
236
+ slack: 960,
237
+ googledrive: 940,
238
+ googlecalendar: 930,
239
+ notion: 920,
240
+ linear: 900,
241
+ jira: 890,
242
+ hubspot: 860,
243
+ salesforce: 850,
244
+ resend: 650,
245
+ zoho_mail: 520,
246
+ mailchimp: 500,
247
+ sendgrid: 480,
248
+ mailsoftly: 260,
249
+};
250
+
251
+function getToolkitSlugFromUrl(url: string): string | null {
252
+ return url.match(/^\/toolkits\/([^/#?]+)/)?.[1] ?? null;
253
+}
254
+
255
+function toolkitPopularity(url: string, type: string): number {
256
+ if (type !== 'toolkits') return 0;
257
+
258
+ const slug = getToolkitSlugFromUrl(url);
259
+ if (!slug) return 0;
260
+
261
+ const toolkit = toolkitBySlug.get(slug);
262
+ const override = TOOLKIT_POPULARITY_OVERRIDES[slug] ?? 0;
263
+ const managedAuthBoost = toolkit?.composioManagedAuthSchemes?.length ? 120 : 0;
264
+ const authBoost = toolkit?.authSchemes?.includes('OAUTH2') ? 40 : 0;
265
+ const triggerBoost = Math.min((toolkit?.triggerCount ?? 0) * 10, 80);
266
+ const toolCountBoost = Math.min((toolkit?.toolCount ?? 0), 100);
267
+
268
+ return override + managedAuthBoost + authBoost + triggerBoost + toolCountBoost;
269
+}
270
+
271
+function pageRank(url: string, type: string): number {
272
+ // Prefer conceptual docs over generated/reference material when textual
273
+ // relevance is otherwise close. Toolkit aliases can still win earlier via
274
+ // searchableAttributes when the query matches a tool name/slug exactly.
275
+ if (type === 'docs') {
276
+ if (url === '/docs' || url === '/docs/') return 2_400;
277
+ if (url.includes('/quickstart')) return 2_300;
278
+ if (url.includes('/authentication')) return 2_220;
279
+ if (url.includes('/tools-and-toolkits')) return 2_180;
280
+ if (url.includes('/configuring-sessions')) return 2_120;
281
+ return 2_000;
282
+ }
283
+
284
+ if (type === 'cookbooks') return 1_500;
285
+ if (type === 'toolkits') return 1_250;
286
+ // Current v3.1 reference should be available, but conceptual docs should
287
+ // win whenever both match. Legacy v3 reference is only a last-resort result.
288
+ if (type === 'reference') return 650;
289
+ if (type === 'api-reference') return 560;
290
+ if (type === 'v3-reference') return 25;
291
+ if (type === 'changelog') return 300;
292
+ return 400;
293
+}
294
+
295
+function recordsFromMarkdownPage(input: {
296
+ url: string;
297
+ type: string;
298
+ title: string;
299
+ description?: string;
300
+ keywords?: string[];
301
+ markdown: string;
302
+ breadcrumbs?: string[];
303
+ tags?: string[];
304
+ toolNames?: string[];
305
+ toolSlugs?: string[];
306
+}): AlgoliaDocsRecord[] {
307
+ const clean = mdxToCleanMarkdown(input.markdown);
308
+ const lines = clean.split('\n');
309
+ const headingSlugs = new Map<string, number>();
310
+ const headings: string[] = [];
311
+ const sections: Array<{ heading?: string; section_id?: string; depth: number; text: string; position: number }> = [];
312
+ let currentHeading: string | undefined;
313
+ let currentSectionId: string | undefined;
314
+ let currentDepth = 0;
315
+ let currentLines: string[] = [];
316
+ let sectionPosition = 0;
317
+
318
+ const flush = () => {
319
+ const text = currentLines.join('\n').trim();
320
+ if (!text) return;
321
+ sections.push({
322
+ heading: currentHeading,
323
+ section_id: currentSectionId,
324
+ depth: currentDepth,
325
+ text,
326
+ position: sectionPosition++,
327
+ });
328
+ currentLines = [];
329
+ };
330
+
331
+ for (const line of lines) {
332
+ const match = line.match(/^(#{1,6})\s+(.+)$/);
333
+ if (match) {
334
+ flush();
335
+ const depth = match[1].length;
336
+ const heading = match[2].trim();
337
+ currentHeading = heading;
338
+ currentSectionId = uniqueSlug(heading, headingSlugs);
339
+ currentDepth = depth;
340
+ headings.push(heading);
341
+ currentLines.push(line);
342
+ continue;
343
+ }
344
+
345
+ currentLines.push(line);
346
+ }
347
+ flush();
348
+
349
+ const fallbackText = clean.trim() || [input.title, input.description, ...(input.keywords ?? [])].filter(Boolean).join('\n');
350
+ if (sections.length === 0 && fallbackText) {
351
+ sections.push({ text: fallbackText, position: 0, depth: 0 });
352
+ }
353
+
354
+ let recordPosition = 0;
355
+ return sections.flatMap((section) => {
356
+ const chunks = splitIntoChunks(section.text);
357
+ return chunks.map((chunk, chunkIndex) => {
358
+ const sectionPart = section.section_id ?? 'overview';
359
+ const objectID = `${input.url}__${sectionPart}__${chunkIndex}__${contentHash(chunk)}`;
360
+ const sectionRank = Math.max(10, 120 - section.depth * 12 - chunkIndex * 2);
361
+
362
+ const position = recordPosition++;
363
+ const includeToolkitAliases = input.type === 'toolkits' && position === 0;
364
+
365
+ return {
366
+ objectID,
367
+ title: input.title,
368
+ description: input.description,
369
+ breadcrumbs: input.breadcrumbs,
370
+ url: input.url,
371
+ page_id: input.url,
372
+ section: section.heading,
373
+ section_id: section.section_id,
374
+ content: chunk,
375
+ keywords: input.keywords,
376
+ slug: slugTokens(input.url),
377
+ headings,
378
+ tool_names: includeToolkitAliases ? input.toolNames : undefined,
379
+ tool_slugs: includeToolkitAliases ? input.toolSlugs : undefined,
380
+ type: input.type,
381
+ lang: 'en',
382
+ tags: input.tags,
383
+ page_rank: pageRank(input.url, input.type),
384
+ toolkit_popularity: toolkitPopularity(input.url, input.type),
385
+ section_rank: sectionRank,
386
+ position,
387
+ depth: section.depth,
388
+ } satisfies AlgoliaDocsRecord;
389
+ });
390
+ });
391
+}
392
+
393
+const toolkitBySlug = new Map(getAllToolkitsSync().map((toolkit) => [toolkit.slug, toolkit]));
394
+
395
+function limitToolkitAliases(values: string[]): string[] {
396
+ const aliases: string[] = [];
397
+ let bytes = 0;
398
+
399
+ for (const value of values) {
400
+ const trimmed = value.trim();
401
+ if (!trimmed) continue;
402
+
403
+ const nextBytes = Buffer.byteLength(JSON.stringify(trimmed), 'utf8');
404
+ if (aliases.length >= MAX_TOOL_ALIAS_ITEMS || bytes + nextBytes > MAX_TOOL_ALIAS_BYTES) break;
405
+
406
+ aliases.push(trimmed);
407
+ bytes += nextBytes;
408
+ }
409
+
410
+ return aliases;
411
+}
412
+
413
+function getToolkitSearchFields(slug: string): Pick<Parameters<typeof recordsFromMarkdownPage>[0], 'toolNames' | 'toolSlugs' | 'tags'> {
414
+ const toolkit = toolkitBySlug.get(slug);
415
+ if (!toolkit) return {};
416
+
417
+ return {
418
+ toolNames: limitToolkitAliases(toolkit.tools.map((tool) => tool.name).filter(Boolean)),
419
+ toolSlugs: limitToolkitAliases(toolkit.tools.map((tool) => tool.slug).filter(Boolean)),
420
+ tags: [toolkit.category].filter(Boolean) as string[],
421
+ };
422
+}
423
+
424
+function getFilesystemRecords(): AlgoliaDocsRecord[] {
425
+ const contentDir = join(process.cwd(), 'content');
426
+ return listContentFiles(contentDir).flatMap((file) => {
427
+ const route = urlFromContentPath(file);
428
+ if (!route) return [];
429
+
430
+ const source = readFileSync(file, 'utf8');
431
+ const frontmatter = getFrontmatter(source);
432
+ const title = getFrontmatterValue(frontmatter, 'title');
433
+ if (!title) return [];
434
+
435
+ const toolkitFields = route.type === 'toolkits'
436
+ ? getToolkitSearchFields(route.url.replace(/^\/toolkits\//, ''))
437
+ : {};
438
+
439
+ return recordsFromMarkdownPage({
440
+ url: route.url,
441
+ type: route.type,
442
+ title,
443
+ description: getFrontmatterValue(frontmatter, 'description'),
444
+ keywords: getFrontmatterList(frontmatter, 'keywords'),
445
+ markdown: source,
446
+ breadcrumbs: breadcrumbsForUrl(route.url, route.type),
447
+ ...toolkitFields,
448
+ });
449
+ });
450
+}
451
+
452
+// Dynamic toolkit entries from toolkits.json. We include a compact sample of tool
453
+// names/slugs so queries like "gmail send email" can still find the Gmail toolkit
454
+// page without indexing the full tool catalog as noisy giant records.
455
+const mdxToolkitSlugs = new Set(
456
+ toolkitsSource.getPages().map((page) => page.slugs.join('/')),
457
+);
458
+
459
+const dynamicToolkitIndexes = getAllToolkitsSync()
460
+ .filter((toolkit) => !mdxToolkitSlugs.has(toolkit.slug))
461
+ .map((toolkit) => ({
462
+ id: `/toolkits/${toolkit.slug}`,
463
+ title: toolkit.name,
464
+ description: toolkit.description,
465
+ url: `/toolkits/${toolkit.slug}`,
466
+ structuredData: { headings: [], contents: [] },
467
+ keywords: [toolkit.slug, toolkit.category].filter(Boolean) as string[],
468
+ } satisfies SearchIndex));
469
+
470
+function getDynamicToolkitRecords(): AlgoliaDocsRecord[] {
471
+ return getAllToolkitsSync()
472
+ .filter((toolkit) => !mdxToolkitSlugs.has(toolkit.slug))
473
+ .flatMap((toolkit) => {
474
+ const toolsText = (toolkit.tools ?? [])
475
+ .slice(0, 60)
476
+ .map((tool) => `${tool.slug ?? ''} ${tool.name ?? ''}`)
477
+ .join('\n');
478
+
479
+ return recordsFromMarkdownPage({
480
+ url: `/toolkits/${toolkit.slug}`,
481
+ type: 'toolkits',
482
+ title: toolkit.name,
483
+ description: toolkit.description,
484
+ keywords: [toolkit.slug, toolkit.category].filter(Boolean) as string[],
485
+ markdown: `# ${toolkit.name}\n\n${toolkit.description ?? ''}\n\n## Available tools\n\n${toolsText}`,
486
+ breadcrumbs: breadcrumbsForUrl(`/toolkits/${toolkit.slug}`, 'toolkits'),
487
+ ...getToolkitSearchFields(toolkit.slug),
488
+ });
489
+ });
490
+}
491
+
492
+function getChangelogIndexes(): SearchIndex[] {
493
+ const changelogDir = join(process.cwd(), 'content/changelog');
494
+ if (!existsSync(changelogDir)) return [];
495
+
496
+ return readdirSync(changelogDir)
497
+ .filter((file) => file.endsWith('.mdx'))
498
+ .flatMap((file) => {
499
+ const source = readFileSync(join(changelogDir, file), 'utf8');
500
+ const frontmatter = getFrontmatter(source);
501
+ const date = getFrontmatterValue(frontmatter, 'date');
502
+ const title = getFrontmatterValue(frontmatter, 'title');
503
+ if (!date || !title) return [];
504
+
505
+ const url = `/docs/changelog/${date.replace(/-/g, '/')}`;
506
+
507
+ return [{
508
+ id: `${url}#${title}`,
509
+ title,
510
+ description: getFrontmatterValue(frontmatter, 'description') ?? '',
511
+ url,
512
+ structuredData: { headings: [], contents: [] },
513
+ keywords: ['changelog'],
514
+ } satisfies SearchIndex];
515
+ });
516
+}
517
+
518
+function getChangelogRecords(): AlgoliaDocsRecord[] {
519
+ const changelogDir = join(process.cwd(), 'content/changelog');
520
+ if (!existsSync(changelogDir)) return [];
521
+
522
+ return readdirSync(changelogDir)
523
+ .filter((file) => file.endsWith('.mdx'))
524
+ .flatMap((file) => {
525
+ const source = readFileSync(join(changelogDir, file), 'utf8');
526
+ const frontmatter = getFrontmatter(source);
527
+ const date = getFrontmatterValue(frontmatter, 'date');
528
+ const title = getFrontmatterValue(frontmatter, 'title');
529
+ if (!date || !title) return [];
530
+
531
+ return recordsFromMarkdownPage({
532
+ url: `/docs/changelog/${date.replace(/-/g, '/')}`,
533
+ type: 'changelog',
534
+ title,
535
+ description: getFrontmatterValue(frontmatter, 'description'),
536
+ keywords: ['changelog', date],
537
+ markdown: source,
538
+ breadcrumbs: breadcrumbsForUrl(`/docs/changelog/${date.replace(/-/g, '/')}`, 'changelog'),
539
+ });
540
+ });
541
+}
542
+
543
+export async function getDocsSearchIndexes(): Promise<SearchIndex[]> {
544
+ // Load OpenAPI pages and build full reference source.
545
+ const openapiPages = await openapiSource(openapi, {
546
+ groupBy: 'tag',
547
+ baseDir: 'api-reference',
548
+ });
549
+
550
+ const fullReferenceSource = loader({
551
+ baseUrl: '/reference',
552
+ source: multiple({
553
+ mdx: reference.toFumadocsSource(),
554
+ openapi: openapiPages,
555
+ }),
556
+ plugins: [lucideIconsPlugin(), openapiPlugin()],
557
+ });
558
+
559
+ const mdxIndexes = [
560
+ ...docsSource.getPages(),
561
+ ...cookbooksSource.getPages(),
562
+ ...toolkitsSource.getPages(),
563
+ ...fullReferenceSource.getPages(),
564
+ ].map((page) => ({
565
+ id: page.url,
566
+ title: page.data.title ?? 'Untitled',
567
+ description: page.data.description,
568
+ url: page.url,
569
+ structuredData: page.data.structuredData,
570
+ keywords: 'keywords' in page.data ? (page.data.keywords as string[]) : undefined,
571
+ } satisfies SearchIndex));
572
+
573
+ return [...mdxIndexes, ...dynamicToolkitIndexes, ...getChangelogIndexes()];
574
+}
575
+
576
+async function getOpenApiRecords(): Promise<AlgoliaDocsRecord[]> {
577
+ const openapiPages = await openapiSource(openapi, {
578
+ groupBy: 'tag',
579
+ baseDir: 'api-reference',
580
+ });
581
+
582
+ const openapiOnlySource = loader({
583
+ baseUrl: '/reference',
584
+ source: openapiPages,
585
+ plugins: [lucideIconsPlugin(), openapiPlugin()],
586
+ });
587
+
588
+ return openapiOnlySource.getPages().flatMap((page) => {
589
+ const contents = [
590
+ page.data.description,
591
+ ...(page.data.structuredData?.headings ?? []).map((heading) => heading.content),
592
+ ...(page.data.structuredData?.contents ?? []).map((content) => content.content),
593
+ ].filter(Boolean).join('\n\n');
594
+
595
+ return recordsFromMarkdownPage({
596
+ url: page.url,
597
+ type: 'api-reference',
598
+ title: page.data.title ?? 'Untitled',
599
+ description: page.data.description,
600
+ markdown: `# ${page.data.title ?? 'Untitled'}\n\n${contents}`,
601
+ breadcrumbs: breadcrumbsForUrl(page.url, 'api-reference'),
602
+ });
603
+ });
604
+}
605
+
606
+export async function getAlgoliaSearchDocuments(): Promise<AlgoliaDocsRecord[]> {
607
+ const records = [
608
+ ...getFilesystemRecords(),
609
+ ...getDynamicToolkitRecords(),
610
+ ...getChangelogRecords(),
611
+ ...await getOpenApiRecords(),
612
+ ];
613
+
614
+ const deduped = new Map<string, AlgoliaDocsRecord>();
615
+ for (const record of records) deduped.set(record.objectID, record);
616
+
617
+ return Array.from(deduped.values());
618
+}