Files
wehub-resource-sync e30e75b5d4
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
Changesets / Create Version PR (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

71 lines
2.0 KiB
TypeScript

import { BASE_URL } from "./constants";
type LLMIndexPage = {
url: string;
slugs: string[];
data: {
title: string;
description?: string | undefined;
};
};
function addPageToSection(
map: Map<string, string[]>,
section: string,
page: LLMIndexPage,
) {
const list = map.get(section) ?? [];
const markdownUrl = `${BASE_URL}${page.url}.md`;
const description = page.data.description
? `: ${page.data.description.slice(0, 120)}`
: "";
list.push(`- [${page.data.title}](${markdownUrl})${description}`);
map.set(section, list);
}
export function buildLLMSIndex(
docsPages: LLMIndexPage[],
examplesPages: LLMIndexPage[],
) {
const lines: string[] = [];
lines.push("# assistant-ui");
lines.push("");
lines.push("> React components for AI chat interfaces");
lines.push("");
lines.push("## LLM Documentation Files");
lines.push("");
lines.push(
`- [Full documentation](${BASE_URL}/llms-full.txt): all docs and examples pages rendered into one large text file.`,
);
lines.push(
"- Per-page markdown: append `.md` to any docs page URL. `.mdx` is kept as a backwards-compatible alias for agents that request source-style URLs. For example, `/docs/installation.md` and `/docs/installation.mdx` both return markdown for `/docs/installation`.",
);
lines.push(
"- Markdown by Accept header: requesting a docs or examples page with `Accept: text/markdown` also returns that page's markdown.",
);
lines.push(
"- Use the index below to choose a specific page. Remove the `.md` or `.mdx` suffix to open the human-readable docs page.",
);
lines.push("");
lines.push("## Table of Contents");
const map = new Map<string, string[]>();
for (const page of docsPages) {
addPageToSection(map, page.slugs[0] || "root", page);
}
for (const page of examplesPages) {
addPageToSection(map, "examples", page);
}
for (const [key, value] of map) {
lines.push("");
lines.push(`### ${key}`);
lines.push("");
lines.push(value.join("\n"));
}
return lines.join("\n");
}