8
formatDate,
9
getLLMText,
10
mdxToCleanMarkdown,
11
+ type LLMPage,
12
} from '@/lib/source';
13
import { dereferenceDocument } from '@/lib/openapi-deref';
14
import { notFound } from 'next/navigation';
18
import { getAllMetaTools, getMetaToolBySlug } from '@/lib/meta-tools-data';
19
import type { MetaTool, MetaToolParameter } from '@/lib/meta-tools-data';
20
import type { Toolkit, Tool, Trigger, ParameterSchema } from '@/types/toolkit';
20
-import { processSchema, toolFromApi } from '@/lib/toolkit-schema';
21
+import { apiToolListSchema, apiTriggerListSchema } from '@/lib/toolkit-schema';
22
+import { z } from 'zod';
23
24
export const revalidate = false;
25
50
return null;
51
}
52
51
- const data = await response.json();
52
- if (!data || typeof data !== 'object') {
53
+ const parsed = apiToolListSchema.safeParse(await response.json());
54
+ if (!parsed.success) {
55
console.warn(`[LLM Markdown] Invalid API response format for toolkit ${toolkitSlug}`);
56
return null;
57
}
58
57
- const rawItems = data.items || data;
58
- const items = Array.isArray(rawItems) ? rawItems : [];
59
-
60
- if (items.length >= API_FETCH_LIMIT) {
61
- console.warn(`[LLM Markdown] Toolkit ${toolkitSlug} has ${items.length}+ tools, results may be truncated`);
59
+ if (parsed.data.length >= API_FETCH_LIMIT) {
60
+ console.warn(
61
+ `[LLM Markdown] Toolkit ${toolkitSlug} has ${parsed.data.length}+ tools, results may be truncated`
62
+ );
63
}
64
64
- return items.filter((tool: any) => tool && typeof tool === 'object').map(toolFromApi);
65
+ return parsed.data;
66
} catch {
67
return null;
68
}
87
);
88
89
if (!response.ok) {
89
- console.warn(`[LLM Markdown] Failed to fetch triggers for ${toolkitSlug}: ${response.status}`);
90
+ console.warn(
91
+ `[LLM Markdown] Failed to fetch triggers for ${toolkitSlug}: ${response.status}`
92
+ );
93
return null;
94
}
95
93
- const data = await response.json();
94
- if (!data || typeof data !== 'object') {
96
+ const parsed = apiTriggerListSchema.safeParse(await response.json());
97
+ if (!parsed.success) {
98
console.warn(`[LLM Markdown] Invalid API response format for triggers ${toolkitSlug}`);
99
return null;
100
}
101
99
- const rawItems = data.items || data;
100
- const items = Array.isArray(rawItems) ? rawItems : [];
101
-
102
- if (items.length >= API_FETCH_LIMIT) {
103
- console.warn(`[LLM Markdown] Toolkit ${toolkitSlug} has ${items.length}+ triggers, results may be truncated`);
102
+ if (parsed.data.length >= API_FETCH_LIMIT) {
103
+ console.warn(
104
+ `[LLM Markdown] Toolkit ${toolkitSlug} has ${parsed.data.length}+ triggers, results may be truncated`
105
+ );
106
}
107
106
- return items.filter((trigger: any) => trigger && typeof trigger === 'object').map((trigger: any) => ({
107
- slug: trigger.slug || '',
108
- name: trigger.name || trigger.display_name || trigger.slug || '',
109
- description: trigger.description || '',
110
- type: trigger.type,
111
- config: processSchema(trigger.config),
112
- payload: processSchema(trigger.payload),
113
- instructions: trigger.instructions,
114
- }));
108
+ return parsed.data;
109
} catch {
110
return null;
111
}
182
};
183
}
184
185
+// Fumadocs page data is untyped across the mixed sources this route serves, so
186
+// each candidate page is parsed once against the shape its renderer needs.
187
+const openAPIPageSchema = z.object({
188
+ url: z.string(),
189
+ data: z.object({
190
+ title: z.string(),
191
+ description: z.string().optional().catch(undefined),
192
+ getOpenAPIPageProps: z.custom<OpenAPIPageData['getOpenAPIPageProps']>(
193
+ value => typeof value === 'function'
194
+ ),
195
+ }),
196
+});
197
+
198
+const llmPageSchema: z.ZodType<LLMPage> = z.object({
199
+ url: z.string(),
200
+ data: z.object({
201
+ title: z.string(),
202
+ description: z.string().optional().catch(undefined),
203
+ getText: z
204
+ .custom<NonNullable<LLMPage['data']['getText']>>(value => typeof value === 'function')
205
+ .optional()
206
+ .catch(undefined),
207
+ legacy: z.boolean().optional().catch(undefined),
208
+ written: z.string().optional().catch(undefined),
209
+ llmGuardrails: z.enum(['direct-execution', 'none']).optional().catch(undefined),
210
+ }),
211
+});
212
+
213
+const degradedPageSchema = z.object({
214
+ url: z.unknown().optional(),
215
+ data: z
216
+ .object({
217
+ title: z.unknown().optional(),
218
+ description: z.unknown().optional(),
219
+ })
220
+ .catch({}),
221
+});
222
+
223
+export function degradedPageToMarkdown(value: unknown): string | null {
224
+ const parsed = degradedPageSchema.safeParse(value);
225
+ if (!parsed.success) return null;
226
+
227
+ const title = parsed.data.data.title || 'Documentation';
228
+ const description = parsed.data.data.description || '';
229
+ const url = parsed.data.url || '';
230
+ return `# ${String(title)} (${String(url)})\n\n${String(description)}`;
231
+}
232
+
233
// Generate sample value for a schema
234
function generateSampleValue(schema: OpenAPISchema, depth = 0): unknown {
235
if (depth > 3) return '...'; // Prevent infinite recursion
284
* tracks recursion because `allOf` expands without increasing indentation. An
285
* ellipsis is emitted when either value exceeds `maxDepth`.
286
*/
245
-function renderSchema(
246
- schema: OpenAPISchema,
247
- indent = 0,
248
- maxDepth = 4,
249
- depth = 0
250
-): string[] {
287
+function renderSchema(schema: OpenAPISchema, indent = 0, maxDepth = 4, depth = 0): string[] {
288
if (indent > maxDepth || depth > maxDepth) {
289
return [' '.repeat(indent) + '- ...'];
290
}
293
const prefix = ' '.repeat(indent);
294
const required = schema.required || [];
295
259
- if (schema.type === 'object' && (schema.properties || (schema.additionalProperties && typeof schema.additionalProperties === 'object'))) {
296
+ if (
297
+ schema.type === 'object' &&
298
+ (schema.properties ||
299
+ (schema.additionalProperties && typeof schema.additionalProperties === 'object'))
300
+ ) {
301
if (schema.properties) {
302
for (const [name, prop] of Object.entries(schema.properties)) {
303
const isRequired = required.includes(name);
308
lines.push(`${prefix}- \`${name}\` (${typeStr})${reqMark}${desc}`);
309
310
// Recurse for nested objects/arrays
270
- if (prop.type === 'object' && (prop.properties || (prop.additionalProperties && typeof prop.additionalProperties === 'object'))) {
311
+ if (
312
+ prop.type === 'object' &&
313
+ (prop.properties ||
314
+ (prop.additionalProperties && typeof prop.additionalProperties === 'object'))
315
+ ) {
316
lines.push(...renderSchema(prop, indent + 1, maxDepth, depth + 1));
272
- } else if (prop.type === 'array' && prop.items?.type === 'object' && (prop.items.properties || (prop.items.additionalProperties && typeof prop.items.additionalProperties === 'object'))) {
317
+ } else if (
318
+ prop.type === 'array' &&
319
+ prop.items?.type === 'object' &&
320
+ (prop.items.properties ||
321
+ (prop.items.additionalProperties &&
322
+ typeof prop.items.additionalProperties === 'object'))
323
+ ) {
324
lines.push(`${prefix} - Array items:`);
325
lines.push(...renderSchema(prop.items, indent + 2, maxDepth, depth + 1));
326
}
333
const typeStr = getTypeString(ap);
334
const desc = ap.description ? `: ${ap.description}` : '';
335
lines.push(`${prefix}- \`[key: string]\` (${typeStr})${desc}`);
285
- if (ap.type === 'object' && (ap.properties || (ap.additionalProperties && typeof ap.additionalProperties === 'object'))) {
336
+ if (
337
+ ap.type === 'object' &&
338
+ (ap.properties || (ap.additionalProperties && typeof ap.additionalProperties === 'object'))
339
+ ) {
340
lines.push(...renderSchema(ap, indent + 1, maxDepth, depth + 1));
287
- } else if (ap.type === 'array' && ap.items?.type === 'object' && (ap.items.properties || (ap.items.additionalProperties && typeof ap.items.additionalProperties === 'object'))) {
341
+ } else if (
342
+ ap.type === 'array' &&
343
+ ap.items?.type === 'object' &&
344
+ (ap.items.properties ||
345
+ (ap.items.additionalProperties && typeof ap.items.additionalProperties === 'object'))
346
+ ) {
347
lines.push(`${prefix} - Array items:`);
348
lines.push(...renderSchema(ap.items, indent + 2, maxDepth, depth + 1));
349
}
377
if (depth > maxDepth) return '...';
378
379
if (schema.enum) {
321
- return `enum: ${schema.enum.slice(0, 3).map(e => `"${e}"`).join(' | ')}${schema.enum.length > 3 ? ' | ...' : ''}`;
380
+ return `enum: ${schema.enum
381
+ .slice(0, 3)
382
+ .map(e => `"${e}"`)
383
+ .join(' | ')}${schema.enum.length > 3 ? ' | ...' : ''}`;
384
}
385
if (schema.type === 'array' && schema.items) {
386
return `array<${getTypeString(schema.items, depth + 1, maxDepth)}>`;
432
}
433
434
// Convert OpenAPI page to comprehensive markdown
373
-export async function openapiPageToMarkdown(
374
- page: { url: string; data: OpenAPIPageData }
375
-): Promise<string> {
435
+export async function openapiPageToMarkdown(page: {
436
+ url: string;
437
+ data: OpenAPIPageData;
438
+}): Promise<string> {
439
const { title, description } = page.data;
440
const props = page.data.getOpenAPIPageProps();
441
443
const spec = dereferenceDocument(props.payload.bundled);
444
const paths = spec.paths as Record<string, Record<string, OpenAPIOperation>> | undefined;
445
const webhooks = spec.webhooks as Record<string, Record<string, OpenAPIOperation>> | undefined;
383
- const securitySchemes = (spec.components as Record<string, unknown>)?.securitySchemes as Record<string, OpenAPISecurityScheme> | undefined;
446
+ const securitySchemes = (spec.components as Record<string, unknown>)?.securitySchemes as
447
+ Record<string, OpenAPISecurityScheme> | undefined;
448
const servers = spec.servers as Array<{ url: string; description?: string }> | undefined;
449
const baseUrl = servers?.[0]?.url || 'https://backend.composio.dev';
450
628
629
// Map URL prefixes to their sources
630
// Note: 'reference' is handled specially below with async getReferenceSource()
567
-const sources = [
631
+interface PageSource {
632
+ getPage(slugs: string[] | undefined): unknown;
633
+}
634
+
635
+const sources: Array<{ prefix: string; source: PageSource }> = [
636
{ prefix: 'docs', source },
637
{ prefix: 'examples', source: examplesSource },
638
{ prefix: 'toolkits', source: toolkitsSource },
683
* Multiple entries on the same date are combined into one document.
684
*/
685
async function changelogToMarkdown(dateStr: string): Promise<string | null> {
618
- const matchingEntries = changelogEntries.filter(
619
- (entry) => entry.date === dateStr
620
- );
686
+ const matchingEntries = changelogEntries.filter(entry => entry.date === dateStr);
687
688
if (matchingEntries.length === 0) {
689
return null;
767
}
768
769
// Generate markdown from toolkit with detailed tools and triggers
704
-function toolkitToMarkdown(toolkit: Toolkit, detailedTools?: Tool[], detailedTriggers?: Trigger[], faqMarkdown?: string | null): string {
770
+function toolkitToMarkdown(
771
+ toolkit: Toolkit,
772
+ detailedTools?: Tool[],
773
+ detailedTriggers?: Trigger[],
774
+ faqMarkdown?: string | null
775
+): string {
776
const tools = detailedTools || toolkit.tools;
777
const triggers = detailedTriggers || toolkit.triggers;
778
784
`- **Category:** ${toolkit.category || 'Uncategorized'}`,
785
`- **Auth:** ${toolkit.authSchemes.join(', ') || 'None'}`,
786
`- **Composio Managed App Available?** ${
716
- toolkit.authSchemes?.some((s) => s.toUpperCase().includes('OAUTH'))
717
- ? (toolkit.composioManagedAuthSchemes && toolkit.composioManagedAuthSchemes.length > 0
718
- ? 'Yes'
719
- : 'No')
787
+ toolkit.authSchemes?.some(s => s.toUpperCase().includes('OAUTH'))
788
+ ? toolkit.composioManagedAuthSchemes && toolkit.composioManagedAuthSchemes.length > 0
789
+ ? 'Yes'
790
+ : 'No'
791
: 'N/A'
792
}`,
793
`- **Tools:** ${toolkit.toolCount}`,
865
const toolkits = await getAllToolkits();
866
867
// Only include OAuth toolkits
797
- const oauthToolkits = toolkits.filter((t) =>
798
- t.authSchemes?.some((s) => s.toUpperCase().includes('OAUTH'))
868
+ const oauthToolkits = toolkits.filter(t =>
869
+ t.authSchemes?.some(s => s.toUpperCase().includes('OAUTH'))
870
);
871
872
const managed = oauthToolkits
802
- .filter((t) => t.composioManagedAuthSchemes && t.composioManagedAuthSchemes.length > 0)
873
+ .filter(t => t.composioManagedAuthSchemes && t.composioManagedAuthSchemes.length > 0)
874
.sort((a, b) => (a.name?.trim() || '').localeCompare(b.name?.trim() || ''));
875
876
const unmanaged = oauthToolkits
806
- .filter((t) => !t.composioManagedAuthSchemes || t.composioManagedAuthSchemes.length === 0)
877
+ .filter(t => !t.composioManagedAuthSchemes || t.composioManagedAuthSchemes.length === 0)
878
.sort((a, b) => (a.name?.trim() || '').localeCompare(b.name?.trim() || ''));
879
880
const lines: string[] = [
898
];
899
900
for (const t of managed) {
830
- lines.push(`| [${t.name?.trim() || t.slug}](/toolkits/${t.slug}.md) | \`${t.slug.toUpperCase()}\` |`);
901
+ lines.push(
902
+ `| [${t.name?.trim() || t.slug}](/toolkits/${t.slug}.md) | \`${t.slug.toUpperCase()}\` |`
903
+ );
904
}
905
906
lines.push('');
910
lines.push('|---------|------|');
911
912
for (const t of unmanaged) {
840
- lines.push(`| [${t.name?.trim() || t.slug}](/toolkits/${t.slug}.md) | \`${t.slug.toUpperCase()}\` |`);
913
+ lines.push(
914
+ `| [${t.name?.trim() || t.slug}](/toolkits/${t.slug}.md) | \`${t.slug.toUpperCase()}\` |`
915
+ );
916
}
917
918
return lines.join('\n');
944
for (const toolkit of sorted) {
945
const name = toolkit.name?.trim() || toolkit.slug;
946
const auth = toolkit.authSchemes?.join(', ') || 'None';
872
- const hasOAuth = toolkit.authSchemes?.some((s) => s.toUpperCase().includes('OAUTH'));
947
+ const hasOAuth = toolkit.authSchemes?.some(s => s.toUpperCase().includes('OAUTH'));
948
const managedApp = hasOAuth
874
- ? (toolkit.composioManagedAuthSchemes && toolkit.composioManagedAuthSchemes.length > 0 ? 'Yes' : 'No')
949
+ ? toolkit.composioManagedAuthSchemes && toolkit.composioManagedAuthSchemes.length > 0
950
+ ? 'Yes'
951
+ : 'No'
952
: '—';
953
lines.push(
954
`| [${name}](/toolkits/${toolkit.slug}.md) | \`${toolkit.slug.toUpperCase()}\` | ${toolkit.toolCount} | ${toolkit.triggerCount} | ${auth} | ${managedApp} |`
956
}
957
958
lines.push('', '## Toolkit Details', '');
882
- lines.push('For detailed information about each toolkit including all tools and triggers, visit the individual toolkit pages listed above.');
959
+ lines.push(
960
+ 'For detailed information about each toolkit including all tools and triggers, visit the individual toolkit pages listed above.'
961
+ );
962
963
return lines.join('\n');
964
}
965
887
-const LLM_FOOTER = '\n\n---\n\n📚 **More documentation:** [View all docs](https://docs.composio.dev/llms.txt) | [Glossary](https://docs.composio.dev/llms.mdx/reference/glossary) | [Examples](https://docs.composio.dev/llms.mdx/examples) | [API Reference](https://docs.composio.dev/llms.mdx/reference)';
966
+const LLM_FOOTER =
967
+ '\n\n---\n\n📚 **More documentation:** [View all docs](https://docs.composio.dev/llms.txt) | [Glossary](https://docs.composio.dev/llms.mdx/reference/glossary) | [Examples](https://docs.composio.dev/llms.mdx/examples) | [API Reference](https://docs.composio.dev/llms.mdx/reference)';
968
969
// Render meta tool parameters as markdown
890
-function renderMetaToolParams(properties: Record<string, MetaToolParameter>, requiredFields: string[] = [], indent = 0): string[] {
970
+function renderMetaToolParams(
971
+ properties: Record<string, MetaToolParameter>,
972
+ requiredFields: string[] = [],
973
+ indent = 0
974
+): string[] {
975
const lines: string[] = [];
976
const prefix = ' '.repeat(indent);
977
978
for (const [name, param] of Object.entries(properties)) {
895
- const typeStr = param.type === 'array' && param.items && typeof param.items === 'object' && (param.items as Record<string, unknown>).type
896
- ? `array<${(param.items as Record<string, unknown>).type}>`
897
- : param.type;
979
+ const typeStr =
980
+ param.type === 'array' &&
981
+ param.items &&
982
+ typeof param.items === 'object' &&
983
+ (param.items as Record<string, unknown>).type
984
+ ? `array<${(param.items as Record<string, unknown>).type}>`
985
+ : param.type;
986
const reqMark = requiredFields.includes(name) ? ' *(required)*' : '';
987
const desc = param.description
988
? `: ${param.description.replace(/\*\*/g, '').replace(/__/g, '').replace(/\n+/g, ' ').trim()}`
989
: '';
902
- const defaultStr = param.default !== undefined && param.default !== null && param.default !== ''
903
- ? ` (default: \`${String(param.default)}\`)`
904
- : '';
905
- const enumStr = param.enum && param.enum.length > 0
906
- ? ` — values: ${param.enum.map(v => `\`${v}\``).join(', ')}`
907
- : '';
990
+ const defaultStr =
991
+ param.default !== undefined && param.default !== null && param.default !== ''
992
+ ? ` (default: \`${String(param.default)}\`)`
993
+ : '';
994
+ const enumStr =
995
+ param.enum && param.enum.length > 0
996
+ ? ` — values: ${param.enum.map(v => `\`${v}\``).join(', ')}`
997
+ : '';
998
999
lines.push(`${prefix}- \`${name}\` (${typeStr})${reqMark}${desc}${defaultStr}${enumStr}`);
1000
1003
lines.push(...renderMetaToolParams(param.properties, nestedRequired, indent + 1));
1004
}
1005
916
- const items = param.items && typeof param.items === 'object' ? param.items as Record<string, unknown> : null;
917
- if (items?.properties && typeof items.properties === 'object' && Object.keys(items.properties as object).length > 0) {
918
- const itemsRequired = Array.isArray(items.required) ? items.required as string[] : [];
1006
+ const items =
1007
+ param.items && typeof param.items === 'object'
1008
+ ? (param.items as Record<string, unknown>)
1009
+ : null;
1010
+ if (
1011
+ items?.properties &&
1012
+ typeof items.properties === 'object' &&
1013
+ Object.keys(items.properties as object).length > 0
1014
+ ) {
1015
+ const itemsRequired = Array.isArray(items.required) ? (items.required as string[]) : [];
1016
lines.push(`${prefix} - Array items:`);
920
- lines.push(...renderMetaToolParams(items.properties as Record<string, MetaToolParameter>, itemsRequired, indent + 2));
1017
+ lines.push(
1018
+ ...renderMetaToolParams(
1019
+ items.properties as Record<string, MetaToolParameter>,
1020
+ itemsRequired,
1021
+ indent + 2
1022
+ )
1023
+ );
1024
}
1025
}
1026
1029
1030
// Generate markdown for a single meta tool
1031
function metaToolToMarkdown(tool: MetaTool): string {
929
- const lines: string[] = [
930
- `# ${tool.displayName}`,
931
- '',
932
- `**Slug:** \`${tool.slug}\``,
933
- ];
1032
+ const lines: string[] = [`# ${tool.displayName}`, '', `**Slug:** \`${tool.slug}\``];
1033
1034
if (tool.tags.length > 0) {
1035
lines.push(`**Tags:** ${tool.tags.join(', ')}`);
1067
1068
for (const tool of tools) {
1069
const tags = tool.tags.length > 0 ? tool.tags.join(', ') : '—';
971
- lines.push(`| [\`${tool.slug}\`](/toolkits/meta-tools/${tool.slug.toLowerCase().replace('composio_', '')}.md) | ${tags} |`);
1070
+ lines.push(
1071
+ `| [\`${tool.slug}\`](/toolkits/meta-tools/${tool.slug.toLowerCase().replace('composio_', '')}.md) | ${tags} |`
1072
+ );
1073
}
1074
1075
return lines.join('\n') + LLM_FOOTER;
1076
}
1077
977
-export async function GET(
978
- _req: Request,
979
- { params }: { params: Promise<{ slug?: string[] }> }
980
-) {
1078
+export async function GET(_req: Request, { params }: { params: Promise<{ slug?: string[] }> }) {
1079
try {
1080
const { slug = [] } = await params;
1081
const [prefix, ...rest] = slug;
1156
}
1157
1158
// Handle 'reference' specially - uses async getReferenceSource() for OpenAPI pages
1061
- let pageSource: any;
1159
+ let pageSource: PageSource;
1160
if (prefix === 'reference') {
1161
try {
1162
pageSource = await getReferenceSource();
1167
pageSource = referenceSource;
1168
}
1169
} else {
1072
- const match = sources.find((s) => s.prefix === prefix);
1170
+ const match = sources.find(s => s.prefix === prefix);
1171
if (!match) notFound();
1172
pageSource = match.source;
1173
}
1183
1184
if (page) {
1185
// Check if this is an OpenAPI page
1088
- if ('getOpenAPIPageProps' in page.data) {
1186
+ const openapiPage = openAPIPageSchema.safeParse(page);
1187
+ if (openapiPage.success) {
1188
try {
1090
- const markdown = await openapiPageToMarkdown(
1091
- page as unknown as { url: string; data: OpenAPIPageData }
1092
- );
1189
+ const markdown = await openapiPageToMarkdown(openapiPage.data);
1190
return new Response(markdown, {
1191
headers: {
1192
'Content-Type': 'text/markdown; charset=utf-8',
1194
});
1195
} catch (e) {
1196
console.error('Error generating OpenAPI markdown:', e);
1100
- const title = page.data?.title || 'API Reference';
1101
- const description = page.data?.description || '';
1102
- return new Response(
1103
- `# ${title}\n\n${description}`,
1104
- {
1105
- headers: {
1106
- 'Content-Type': 'text/markdown; charset=utf-8',
1107
- },
1108
- }
1109
- );
1197
+ const title = openapiPage.data.data.title || 'API Reference';
1198
+ const description = openapiPage.data.data.description || '';
1199
+ return new Response(`# ${title}\n\n${description}`, {
1200
+ headers: {
1201
+ 'Content-Type': 'text/markdown; charset=utf-8',
1202
+ },
1203
+ });
1204
}
1205
}
1206
1207
// Regular MDX page
1114
- try {
1115
- return new Response(await getLLMText(page as any), {
1208
+ const llmPage = llmPageSchema.safeParse(page);
1209
+ if (llmPage.success) {
1210
+ try {
1211
+ return new Response(await getLLMText(llmPage.data), {
1212
+ headers: {
1213
+ 'Content-Type': 'text/markdown; charset=utf-8',
1214
+ },
1215
+ });
1216
+ } catch (e) {
1217
+ console.error('Error generating LLM text:', e);
1218
+ const title = llmPage.data.data.title || 'Documentation';
1219
+ const description = llmPage.data.data.description || '';
1220
+ return new Response(`# ${title} (${llmPage.data.url})\n\n${description}`, {
1221
+ headers: {
1222
+ 'Content-Type': 'text/markdown; charset=utf-8',
1223
+ },
1224
+ });
1225
+ }
1226
+ }
1227
+
1228
+ const degradedMarkdown = degradedPageToMarkdown(page);
1229
+ if (degradedMarkdown !== null) {
1230
+ return new Response(degradedMarkdown, {
1231
headers: {
1232
'Content-Type': 'text/markdown; charset=utf-8',
1233
},
1234
});
1120
- } catch (e) {
1121
- console.error('Error generating LLM text:', e);
1122
- const title = page.data?.title || 'Documentation';
1123
- const description = page.data?.description || '';
1124
- return new Response(
1125
- `# ${title} (${page.url || ''})\n\n${description}`,
1126
- {
1127
- headers: {
1128
- 'Content-Type': 'text/markdown; charset=utf-8',
1129
- },
1130
- }
1131
- );
1235
}
1236
}
1237
1269
throw e;
1270
}
1271
console.error('Unexpected error in llms.mdx route:', e);
1169
- return new Response(
1170
- `# Error\n\nAn error occurred while generating the markdown content.`,
1171
- {
1172
- status: 500,
1173
- headers: {
1174
- 'Content-Type': 'text/markdown; charset=utf-8',
1175
- },
1176
- }
1177
- );
1272
+ return new Response(`# Error\n\nAn error occurred while generating the markdown content.`, {
1273
+ status: 500,
1274
+ headers: {
1275
+ 'Content-Type': 'text/markdown; charset=utf-8',
1276
+ },
1277
+ });
1278
}
1279
}