Skip to content

Commit 3a6e335

Browse files
committed
Include api references in the llms files
1 parent b868700 commit 3a6e335

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

.github/workflows/deploy.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ name: Deploy
22
run-name: Deploy to ${{ github.ref_name == 'master' && 'the production website' || 'a preview website' }}
33

44
on:
5-
pull_request:
6-
paths:
7-
- "docs/**"
8-
- "static/**"
9-
- "src/**"
10-
- "package-lock.json"
5+
# pull_request:
6+
# paths:
7+
# - "docs/**"
8+
# - "static/**"
9+
# - "src/**"
10+
# - "package-lock.json"
1111
push:
1212
branches:
1313
- master

.github/workflows/lint.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ jobs:
5353
separator: ","
5454

5555
- name: Print changed files
56-
if: steps.changed-mdx-files.outputs.any_changed == 'true'
57-
run: echo ${{ steps.changed-mdx-files.outputs.all_changed_files }}
56+
# if: steps.changed-mdx-files.outputs.any_changed == 'true'
57+
run: |
58+
echo ${{ steps.changed-mdx-files.outputs.all_changed_files }}
59+
echo ${{ steps.changed-mdx-files.outputs.any_changed }}
5860
5961
# - name: Check code snippets for ${{ matrix.language }}
6062
# working-directory: ./scripts/code-type-checking/${{ matrix.language }}

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Test
22

33
on:
44
workflow_dispatch:
5-
pull_request:
6-
paths:
7-
- "docs/**"
5+
# pull_request:
6+
# paths:
7+
# - "docs/**"
88

99
jobs:
1010
write-code-blocks:

src/plugins/generateLllmsFullTxt.ts

+40-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "fs";
2+
import type { OpenAPIV3 } from "@scalar/openapi-types";
23
import path from "path";
34
import matter from "gray-matter";
45
import { getAllMdxFiles } from "./utils/getAllMdxFiles";
@@ -153,7 +154,7 @@ function removeReferences(content: string): string {
153154
return lines.join("\n").trim();
154155
}
155156

156-
async function parseMdxContent(filePath: string): Promise<string> {
157+
async function parseMdxContent(filePath: string, usePageTitle = false): Promise<string> {
157158
const mdxContent = await fs.promises.readFile(filePath, "utf8");
158159
const { content } = matter(mdxContent);
159160
const imports: Array<{ name: string; module: string }> = await extractImportStatements(content);
@@ -223,8 +224,8 @@ async function parseMdxContent(filePath: string): Promise<string> {
223224
const { title, content: contentWithoutTitle } = extractMainTitle(processedContent);
224225
const filePathWithoutExtension = filePath.replace(/\.[^/.]+$/, "");
225226
const [, relativePath] = filePathWithoutExtension.split("/docs").filter(Boolean);
226-
const url = `https://supertokens.com/docs/${relativePath}`;
227-
const parsedTitle = buildTitle(title, filePath);
227+
const url = `https://supertokens.com/docs${relativePath}`;
228+
const parsedTitle = usePageTitle ? title : buildTitle(title, filePath);
228229
processedContent = `
229230
# ${parsedTitle}
230231
Source: ${url}
@@ -275,6 +276,28 @@ function buildTitle(currentTitle: string, filePath: string): string {
275276
return `${title} ${currentTitle}`;
276277
}
277278

279+
async function generateApiReferenceText(apiName: "cdi" | "fdi") {
280+
const apiReference = JSON.parse(await fs.promises.readFile(`./static/${apiName}.json`, "utf8")) as OpenAPIV3.Document;
281+
const apiReferenceMapping = JSON.parse(
282+
await fs.promises.readFile(`./static/${apiName}-mapping.json`, "utf8"),
283+
) as OpenAPIV3.Document;
284+
285+
let text = ``;
286+
for (const route in apiReference.paths) {
287+
for (const method in apiReference.paths[route]) {
288+
const operation = apiReference.paths[route][method];
289+
const mapping = apiReferenceMapping[operation.operationId];
290+
if (operation.deprecated) continue;
291+
if (!mapping) continue;
292+
const title = operation.summary || route;
293+
const pathWithoutExtension = mapping.filePath.replace(/\.[^/.]+$/, "");
294+
const url = `https://supertokens.com/docs/references${pathWithoutExtension}`;
295+
text = `${text}\n\n## ${title}\nSource: ${url}\nEndpoint: ${method.toUpperCase()} ${route}`;
296+
}
297+
}
298+
return text;
299+
}
300+
278301
export default function createLLMFullFile(context) {
279302
return {
280303
name: "generate-llms-full-txt",
@@ -314,10 +337,22 @@ export default function createLLMFullFile(context) {
314337
return { files: filesWithoutReferences };
315338
},
316339
postBuild: async ({ content, outDir, routes }) => {
317-
const llmsFullTxt = (await Promise.all(content.files.map((file) => parseMdxContent(file.path)))).join("\n\n");
340+
let llmsFullTxt = (await Promise.all(content.files.map((file) => parseMdxContent(file.path)))).join("\n\n");
341+
342+
const fdiIntro = await parseMdxContent("./docs/references/fdi/introduction.mdx", true);
343+
const cdiIntro = await parseMdxContent("./docs/references/cdi/introduction.mdx", true);
344+
const fdiReferenceFullTxt = await generateApiReferenceText("fdi");
345+
const cdiReferenceFullTxt = await generateApiReferenceText("cdi");
346+
347+
llmsFullTxt = `${llmsFullTxt}
348+
${fdiIntro}
349+
${fdiReferenceFullTxt}
350+
\n\n
351+
${cdiIntro}
352+
${cdiReferenceFullTxt}
353+
`;
318354

319355
fs.writeFileSync(path.join(outDir, "llms-full.txt"), llmsFullTxt);
320356
},
321357
};
322358
}
323-

src/plugins/generateLllmsTxt.ts

-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ ${buildContent(content.files.filter((file) => file.path.includes("/platform-conf
157157
${buildContent(content.files.filter((file) => file.path.includes("/references")))}
158158
159159
160-
161160
`;
162161

163162
fs.writeFileSync(path.join(outDir, "llms.txt"), llmsTxt);

static/fdi-mapping.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"passwordlessEmailExistsDepr": {
102102
"frontmatter": {
103103
"sidebar_position": 3,
104-
"sidebar_label": "get Check email exists (deprecated) (deprecated)",
104+
"sidebar_label": "get Check email exists (deprecated)",
105105
"title": "Check email exists (deprecated)",
106106
"description": "Check if an email exists\nNote that there is an invisible character at the end of the path, this was to avoid a conflict with the OpenAPI spec.\n"
107107
},
@@ -123,7 +123,7 @@
123123
"passwordlessPhoneNumberExistsDepr": {
124124
"frontmatter": {
125125
"sidebar_position": 4,
126-
"sidebar_label": "get Check phone exists (deprecated) (deprecated)",
126+
"sidebar_label": "get Check phone exists (deprecated)",
127127
"title": "Check phone exists (deprecated)",
128128
"description": "Check if a phone number exists\n"
129129
},
@@ -189,7 +189,7 @@
189189
"emailExistsDepr": {
190190
"frontmatter": {
191191
"sidebar_position": 2,
192-
"sidebar_label": "get Check email exists (deprecated) (deprecated)",
192+
"sidebar_label": "get Check email exists (deprecated)",
193193
"title": "Check email exists (deprecated)",
194194
"description": "Check if an email exists\n"
195195
},
@@ -538,4 +538,5 @@
538538
"method": "get",
539539
"filePath": "/fdi/webauthn/get-webauthn-email-exists.mdx"
540540
}
541-
}
541+
}
542+

0 commit comments

Comments
 (0)