Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions src/lib/llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,65 @@ export function getPagesForLLMSection(pages: LLMPageLike[], section?: string) {
);
}

function getExamplePathForSection(section: string): string {
const examples: Record<string, string> = {
ios: "/docs/ios/guides/advanced/game-controller-support.md",
android: "/docs/android/guides/advanced/game-controller-support.md",
flutter: "/docs/flutter/guides/advanced/game-controller-support.md",
expo: "/docs/expo/guides/advanced/game-controller-support.md",
"react-native": "/docs/react-native/guides/advanced/game-controller-support.md",
dashboard: "/docs/dashboard/dashboard-settings/overview-settings-apple-search-ads.md",
integrations: "/docs/integrations/amplitude.md",
"web-checkout": "/docs/web-checkout/overview.md",
};
return examples[section] ?? "/docs/android/guides/advanced/game-controller-support.md";
}

export function buildLLMSummaryTextFromPages(pages: LLMPageLike[], section?: string) {
const config = getLLMSectionConfig(section);
const title = config ? `${config.label} Documentation` : "Documentation";
const title = config ? `${config.label} Documentation` : "Superwall Documentation";
const lines: string[] = [`# ${title}`, ""];

// Add Superwall description
lines.push(
"Superwall is a platform for remotely configuring and A/B testing mobile app paywalls — no app update required. It provides SDKs for iOS, Android, Flutter, Expo, and React Native, plus a dashboard for managing paywall presentation, experiments, and subscription analytics.",
"",
);

// Add markdown mirror instructions
const examplePath = config
? getExamplePathForSection(section!)
: "/docs/android/guides/advanced/game-controller-support.md";
lines.push(
"Curl the pages below to read docs for each page. You can request markdown files by appending .md to a route, for example:",
"",
`- https://superwall.com${examplePath}`,
"",
"Note: Doc URLs return a 307 redirect. Always use `curl -sL` (follow redirects) when fetching them.",
"",
);

// Add links to all sections
if (!config) {
// Top-level: list all platform-specific docs
lines.push("## Platform-specific docs", "");
for (const [key, val] of Object.entries(llmsSectionConfigs)) {
lines.push(`- [${val.label} Documentation](/docs/llms-${key}.txt)`);
}
lines.push("", "## All Pages", "");
} else {
// Section-specific: link back to top-level + list other sections
lines.push("## Other sections", "");
lines.push("- [All Documentation](/docs/llms.txt)");
for (const [key, val] of Object.entries(llmsSectionConfigs)) {
if (key !== section) {
lines.push(`- [${val.label} Documentation](/docs/llms-${key}.txt)`);
}
}
lines.push("");
}

// Page listing
for (const page of getPagesForLLMSection(pages, section)) {
const description = page.data.description ? `: ${page.data.description}` : "";
lines.push(`- [${page.data.title}](${page.url})${description}`);
Expand All @@ -75,9 +129,13 @@ export async function buildLLMSummaryText(section?: string) {
}

export async function buildLLMFullText(section?: string) {
const config = getLLMSectionConfig(section);
const title = config ? `${config.label} Documentation` : "Superwall Documentation";
const { source, getLLMText } = await import("@/lib/source");
const scanned = await Promise.all(getPagesForLLMSection(source.getPages(), section).map(getLLMText));
return scanned.join("\n\n");
const scanned = await Promise.all(
getPagesForLLMSection(source.getPages(), section).map(getLLMText),
);
return `# ${title}\n\n${scanned.join("\n\n")}`;
}

export function buildLLMResponse(body: string) {
Expand Down
Loading