@farming-labs/theme 0.2.117 → 0.2.118
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs-api.d.mts +1 -0
- package/dist/docs-api.mjs +384 -130
- package/dist/docs-layout.mjs +330 -72
- package/dist/get-app-dir.mjs +9 -1
- package/package.json +2 -2
package/dist/docs-api.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import { BoundedRouteCache } from "./bounded-route-cache.mjs";
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import matter from "gray-matter";
|
|
7
|
-
import { DEFAULT_A2A_AGENT_CARD_ROUTE, DEFAULT_AGENT_SKILLS_ARCHIVE_ROUTE_PATTERN, DEFAULT_AGENT_SKILLS_INDEX_ROUTE, DEFAULT_AGENT_SKILLS_ROUTE_PREFIX, DEFAULT_API_CATALOG_ROUTE, DEFAULT_LEGACY_SKILLS_INDEX_ROUTE, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DOCS_AGENT_MANIFEST_FORMAT, DOCS_AGENT_MANIFEST_SCHEMA_URI, DOCS_AGENT_MANIFEST_VERSION, DOCS_CONTENT_CHANGES_FORMAT, DOCS_CONTENT_CHANGES_RESPONSE_VALUE, DOCS_MARKDOWN_SECTION_INDEX_FORMAT, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, buildDocsSearchFacets, compactDocsAgentDiscoverySpec, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCacheableResponse, createDocsContentChangeFeed, createDocsContentChangesHttpResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsContentChangesRequest, isDocsDiagnosticsRequest, normalizeDocsOkfTrustMetadataInput, normalizeDocsRelated, normalizePageAgentFrontmatter, performDocsSearch, performDocsSearchWithMetadata, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsContentChangesConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, resolveDocsRetrievalLastModified, resolveDocsSearchAudience, resolveDocsSearchError, resolveDocsSearchRequest, resolveDocsSitemapConfig, resolveDocsStandardsDiscoveryRequest, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent, stripGeneratedAgentProvenance, withDocsOpenApiOperationCounts } from "@farming-labs/docs";
|
|
8
|
-
import { buildApiReferenceOpenApiDocumentAsync, buildApiReferenceOperationPagesAsync, createApiReferenceOperationMarkdownResponse, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveConfiguredAgentSkills, resolveDocsMcpConfig } from "@farming-labs/docs/
|
|
7
|
+
import { DEFAULT_A2A_AGENT_CARD_ROUTE, DEFAULT_AGENT_SKILLS_ARCHIVE_ROUTE_PATTERN, DEFAULT_AGENT_SKILLS_INDEX_ROUTE, DEFAULT_AGENT_SKILLS_ROUTE_PREFIX, DEFAULT_API_CATALOG_ROUTE, DEFAULT_LEGACY_SKILLS_INDEX_ROUTE, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DOCS_AGENT_MANIFEST_FORMAT, DOCS_AGENT_MANIFEST_SCHEMA_URI, DOCS_AGENT_MANIFEST_VERSION, DOCS_CONTENT_CHANGES_FORMAT, DOCS_CONTENT_CHANGES_RESPONSE_VALUE, DOCS_MARKDOWN_SECTION_INDEX_FORMAT, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, buildDocsSearchFacets, compactDocsAgentDiscoverySpec, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCacheableResponse, createDocsContentChangeFeed, createDocsContentChangesHttpResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsContentChangesRequest, isDocsDiagnosticsRequest, normalizeDocsOkfTrustMetadataInput, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, performDocsSearchWithMetadata, readDocsJsonBody, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsContentChangesConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, resolveDocsRetrievalLastModified, resolveDocsSearchAudience, resolveDocsSearchError, resolveDocsSearchRequest, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsStandardsDiscoveryRequest, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent, stripGeneratedAgentProvenance, withDocsOpenApiOperationCounts } from "@farming-labs/docs";
|
|
8
|
+
import { buildApiReferenceOpenApiDocumentAsync, buildApiReferenceOperationPagesAsync, createApiReferenceOperationMarkdownResponse, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveConfiguredAgentSkills, resolveDocsMcpConfig } from "@farming-labs/docs/runtime";
|
|
9
9
|
|
|
10
10
|
//#region src/docs-api.ts
|
|
11
11
|
/**
|
|
@@ -46,6 +46,17 @@ const DEFAULT_MCP_PUBLIC_ROUTE = "/mcp";
|
|
|
46
46
|
const DEFAULT_MCP_WELL_KNOWN_ROUTE = "/.well-known/mcp";
|
|
47
47
|
const DEFAULT_LLMS_TXT_ROUTE = "/llms.txt";
|
|
48
48
|
const DEFAULT_LLMS_FULL_TXT_ROUTE = "/llms-full.txt";
|
|
49
|
+
function withSitemapLastModified(page, manifest) {
|
|
50
|
+
const lastmod = resolveDocsSitemapPageLastmod(manifest, page.url);
|
|
51
|
+
if (!lastmod) return page;
|
|
52
|
+
const lastModified = `${lastmod}T00:00:00.000Z`;
|
|
53
|
+
const hasExplicitAgentSource = page.agentRawContent !== void 0 || page.agentContent !== void 0;
|
|
54
|
+
return {
|
|
55
|
+
...page,
|
|
56
|
+
lastModified,
|
|
57
|
+
...hasExplicitAgentSource ? { agentLastModified: lastModified } : {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
49
60
|
const DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE = "/.well-known/llms.txt";
|
|
50
61
|
const DEFAULT_LLMS_FULL_TXT_WELL_KNOWN_ROUTE = "/.well-known/llms-full.txt";
|
|
51
62
|
const DEFAULT_SKILL_MD_ROUTE = "/skill.md";
|
|
@@ -544,42 +555,6 @@ function buildAgentSpec({ origin, entry, apiRoute, apiCatalog, i18n, search, con
|
|
|
544
555
|
function isPlainObject(value) {
|
|
545
556
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
546
557
|
}
|
|
547
|
-
function normalizeAgentFeedbackContext(value) {
|
|
548
|
-
if (!isPlainObject(value)) return void 0;
|
|
549
|
-
const context = {};
|
|
550
|
-
if (typeof value.page === "string") context.page = value.page;
|
|
551
|
-
if (typeof value.url === "string") context.url = value.url;
|
|
552
|
-
if (typeof value.slug === "string") context.slug = value.slug;
|
|
553
|
-
if (typeof value.locale === "string") context.locale = value.locale;
|
|
554
|
-
if (typeof value.source === "string") context.source = value.source;
|
|
555
|
-
return Object.keys(context).length > 0 ? context : void 0;
|
|
556
|
-
}
|
|
557
|
-
async function parseAgentFeedbackData(request) {
|
|
558
|
-
let body;
|
|
559
|
-
try {
|
|
560
|
-
body = await request.json();
|
|
561
|
-
} catch {
|
|
562
|
-
return {
|
|
563
|
-
ok: false,
|
|
564
|
-
response: Response.json({ error: "Agent feedback body must be valid JSON" }, { status: 400 })
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
if (!isPlainObject(body)) return {
|
|
568
|
-
ok: false,
|
|
569
|
-
response: Response.json({ error: "Agent feedback body must be an object" }, { status: 400 })
|
|
570
|
-
};
|
|
571
|
-
if (!isPlainObject(body.payload)) return {
|
|
572
|
-
ok: false,
|
|
573
|
-
response: Response.json({ error: "Agent feedback body must include a payload object" }, { status: 400 })
|
|
574
|
-
};
|
|
575
|
-
return {
|
|
576
|
-
ok: true,
|
|
577
|
-
data: {
|
|
578
|
-
context: normalizeAgentFeedbackContext(body.context),
|
|
579
|
-
payload: body.payload
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
558
|
function buildAgentFeedbackAnalyticsProperties(data, options = {}) {
|
|
584
559
|
const payloadKeys = Object.keys(data.payload);
|
|
585
560
|
const context = data.context;
|
|
@@ -656,9 +631,20 @@ function validateAgentFeedbackPayload(value, schema, valuePath = "payload") {
|
|
|
656
631
|
}
|
|
657
632
|
function readEntry(root) {
|
|
658
633
|
for (const ext of FILE_EXTS) {
|
|
659
|
-
const configPath = path.join(
|
|
660
|
-
|
|
661
|
-
|
|
634
|
+
const configPath = path.join(
|
|
635
|
+
/* turbopackIgnore: true */
|
|
636
|
+
root,
|
|
637
|
+
`docs.config.${ext}`
|
|
638
|
+
);
|
|
639
|
+
if (fs.existsSync(
|
|
640
|
+
/* turbopackIgnore: true */
|
|
641
|
+
configPath
|
|
642
|
+
)) try {
|
|
643
|
+
const match = fs.readFileSync(
|
|
644
|
+
/* turbopackIgnore: true */
|
|
645
|
+
configPath,
|
|
646
|
+
"utf-8"
|
|
647
|
+
).match(/entry\s*:\s*["']([^"']+)["']/);
|
|
662
648
|
if (match) return match[1];
|
|
663
649
|
} catch {}
|
|
664
650
|
}
|
|
@@ -666,10 +652,21 @@ function readEntry(root) {
|
|
|
666
652
|
}
|
|
667
653
|
function readI18nConfig(root) {
|
|
668
654
|
for (const ext of FILE_EXTS) {
|
|
669
|
-
const configPath = path.join(
|
|
670
|
-
|
|
655
|
+
const configPath = path.join(
|
|
656
|
+
/* turbopackIgnore: true */
|
|
657
|
+
root,
|
|
658
|
+
`docs.config.${ext}`
|
|
659
|
+
);
|
|
660
|
+
if (!fs.existsSync(
|
|
661
|
+
/* turbopackIgnore: true */
|
|
662
|
+
configPath
|
|
663
|
+
)) continue;
|
|
671
664
|
try {
|
|
672
|
-
const content = fs.readFileSync(
|
|
665
|
+
const content = fs.readFileSync(
|
|
666
|
+
/* turbopackIgnore: true */
|
|
667
|
+
configPath,
|
|
668
|
+
"utf-8"
|
|
669
|
+
);
|
|
673
670
|
if (!content.includes("i18n")) continue;
|
|
674
671
|
const localesMatch = content.match(/i18n\s*:\s*\{[\s\S]*?locales\s*:\s*\[([^\]]+)\]/);
|
|
675
672
|
if (!localesMatch) continue;
|
|
@@ -689,9 +686,20 @@ function readI18nConfig(root) {
|
|
|
689
686
|
*/
|
|
690
687
|
function readAIConfig(root) {
|
|
691
688
|
for (const ext of FILE_EXTS) {
|
|
692
|
-
const configPath = path.join(
|
|
693
|
-
|
|
694
|
-
|
|
689
|
+
const configPath = path.join(
|
|
690
|
+
/* turbopackIgnore: true */
|
|
691
|
+
root,
|
|
692
|
+
`docs.config.${ext}`
|
|
693
|
+
);
|
|
694
|
+
if (fs.existsSync(
|
|
695
|
+
/* turbopackIgnore: true */
|
|
696
|
+
configPath
|
|
697
|
+
)) try {
|
|
698
|
+
const content = fs.readFileSync(
|
|
699
|
+
/* turbopackIgnore: true */
|
|
700
|
+
configPath,
|
|
701
|
+
"utf-8"
|
|
702
|
+
);
|
|
695
703
|
if (!content.includes("ai:") && !content.includes("ai :")) return {};
|
|
696
704
|
const enabledMatch = content.match(/ai\s*:\s*\{[^}]*enabled\s*:\s*(true|false)/s);
|
|
697
705
|
if (enabledMatch && enabledMatch[1] === "false") return {};
|
|
@@ -724,10 +732,21 @@ function readAIConfig(root) {
|
|
|
724
732
|
}
|
|
725
733
|
function readCloudConfig(root) {
|
|
726
734
|
for (const ext of FILE_EXTS) {
|
|
727
|
-
const configPath = path.join(
|
|
728
|
-
|
|
735
|
+
const configPath = path.join(
|
|
736
|
+
/* turbopackIgnore: true */
|
|
737
|
+
root,
|
|
738
|
+
`docs.config.${ext}`
|
|
739
|
+
);
|
|
740
|
+
if (!fs.existsSync(
|
|
741
|
+
/* turbopackIgnore: true */
|
|
742
|
+
configPath
|
|
743
|
+
)) continue;
|
|
729
744
|
try {
|
|
730
|
-
const content = fs.readFileSync(
|
|
745
|
+
const content = fs.readFileSync(
|
|
746
|
+
/* turbopackIgnore: true */
|
|
747
|
+
configPath,
|
|
748
|
+
"utf-8"
|
|
749
|
+
);
|
|
731
750
|
const sanitized = stripCommentsAndStrings(content);
|
|
732
751
|
const configObject = extractRootConfigObject(content, sanitized);
|
|
733
752
|
const cloudBlock = extractObjectLiteral(configObject?.content ?? content, configObject?.sanitized ?? sanitized, "cloud");
|
|
@@ -747,10 +766,21 @@ const MCP_RUNTIME_SECURITY_CONFIG_ERROR = "MCP security is configured in docs.co
|
|
|
747
766
|
var McpRuntimeSecurityConfigError = class extends Error {};
|
|
748
767
|
function readMcpConfig(root, options = {}) {
|
|
749
768
|
for (const ext of FILE_EXTS) {
|
|
750
|
-
const configPath = path.join(
|
|
751
|
-
|
|
769
|
+
const configPath = path.join(
|
|
770
|
+
/* turbopackIgnore: true */
|
|
771
|
+
root,
|
|
772
|
+
`docs.config.${ext}`
|
|
773
|
+
);
|
|
774
|
+
if (!fs.existsSync(
|
|
775
|
+
/* turbopackIgnore: true */
|
|
776
|
+
configPath
|
|
777
|
+
)) continue;
|
|
752
778
|
try {
|
|
753
|
-
const content = fs.readFileSync(
|
|
779
|
+
const content = fs.readFileSync(
|
|
780
|
+
/* turbopackIgnore: true */
|
|
781
|
+
configPath,
|
|
782
|
+
"utf-8"
|
|
783
|
+
);
|
|
754
784
|
const sanitized = stripCommentsAndStrings(content);
|
|
755
785
|
const configObject = extractRootConfigObject(content, sanitized);
|
|
756
786
|
const scopedContent = configObject?.content ?? content;
|
|
@@ -957,25 +987,46 @@ function stripMdx(content) {
|
|
|
957
987
|
return content.replace(/^(import|export)\s.*$/gm, "").replace(/<[^>]+\/>/g, "").replace(/<\/?[A-Z][^>]*>/g, "").replace(/<\/?[a-z][^>]*>/g, "").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/(\*{1,3}|_{1,3})(.*?)\1/g, "$2").replace(/```[\s\S]*?```/g, "").replace(/`([^`]+)`/g, "$1").replace(/^>\s+/gm, "").replace(/^[-*_]{3,}\s*$/gm, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
958
988
|
}
|
|
959
989
|
function resolveDocsSearchPageSource(dir) {
|
|
960
|
-
return ["page.mdx", "page.md"].map((fileName) => path.join(
|
|
990
|
+
return ["page.mdx", "page.md"].map((fileName) => path.join(
|
|
991
|
+
/* turbopackIgnore: true */
|
|
992
|
+
dir,
|
|
993
|
+
fileName
|
|
994
|
+
)).find((candidate) => fs.existsSync(
|
|
995
|
+
/* turbopackIgnore: true */
|
|
996
|
+
candidate
|
|
997
|
+
));
|
|
961
998
|
}
|
|
962
999
|
function hasVisibleDescendantDocsSearchPage(dir) {
|
|
963
1000
|
let entries;
|
|
964
1001
|
try {
|
|
965
|
-
entries = fs.readdirSync(
|
|
1002
|
+
entries = fs.readdirSync(
|
|
1003
|
+
/* turbopackIgnore: true */
|
|
1004
|
+
dir
|
|
1005
|
+
);
|
|
966
1006
|
} catch {
|
|
967
1007
|
return false;
|
|
968
1008
|
}
|
|
969
1009
|
for (const name of entries.sort()) {
|
|
970
|
-
const full = path.join(
|
|
1010
|
+
const full = path.join(
|
|
1011
|
+
/* turbopackIgnore: true */
|
|
1012
|
+
dir,
|
|
1013
|
+
name
|
|
1014
|
+
);
|
|
971
1015
|
try {
|
|
972
|
-
if (!fs.statSync(
|
|
1016
|
+
if (!fs.statSync(
|
|
1017
|
+
/* turbopackIgnore: true */
|
|
1018
|
+
full
|
|
1019
|
+
).isDirectory()) continue;
|
|
973
1020
|
} catch {
|
|
974
1021
|
continue;
|
|
975
1022
|
}
|
|
976
1023
|
const pageSource = resolveDocsSearchPageSource(full);
|
|
977
1024
|
if (pageSource) try {
|
|
978
|
-
const data = matter(fs.readFileSync(
|
|
1025
|
+
const data = matter(fs.readFileSync(
|
|
1026
|
+
/* turbopackIgnore: true */
|
|
1027
|
+
pageSource,
|
|
1028
|
+
"utf-8"
|
|
1029
|
+
)).data;
|
|
979
1030
|
const hiddenFolderIndex = resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden";
|
|
980
1031
|
if (data.hidden !== true && !hiddenFolderIndex) return true;
|
|
981
1032
|
} catch {
|
|
@@ -989,22 +1040,40 @@ function isHiddenFolderIndexPageDir(dir) {
|
|
|
989
1040
|
const pageSource = resolveDocsSearchPageSource(dir);
|
|
990
1041
|
if (!pageSource) return false;
|
|
991
1042
|
try {
|
|
992
|
-
const data = matter(fs.readFileSync(
|
|
1043
|
+
const data = matter(fs.readFileSync(
|
|
1044
|
+
/* turbopackIgnore: true */
|
|
1045
|
+
pageSource,
|
|
1046
|
+
"utf-8"
|
|
1047
|
+
)).data;
|
|
993
1048
|
return resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden" && hasVisibleDescendantDocsSearchPage(dir);
|
|
994
1049
|
} catch {
|
|
995
1050
|
return false;
|
|
996
1051
|
}
|
|
997
1052
|
}
|
|
998
1053
|
function readAudienceAgentDoc(dir) {
|
|
999
|
-
const agentPath = path.join(
|
|
1000
|
-
|
|
1054
|
+
const agentPath = path.join(
|
|
1055
|
+
/* turbopackIgnore: true */
|
|
1056
|
+
dir,
|
|
1057
|
+
"agent.md"
|
|
1058
|
+
);
|
|
1059
|
+
if (!fs.existsSync(
|
|
1060
|
+
/* turbopackIgnore: true */
|
|
1061
|
+
agentPath
|
|
1062
|
+
)) return void 0;
|
|
1001
1063
|
try {
|
|
1002
|
-
const { content } = matter(stripGeneratedAgentProvenance(fs.readFileSync(
|
|
1064
|
+
const { content } = matter(stripGeneratedAgentProvenance(fs.readFileSync(
|
|
1065
|
+
/* turbopackIgnore: true */
|
|
1066
|
+
agentPath,
|
|
1067
|
+
"utf-8"
|
|
1068
|
+
)));
|
|
1003
1069
|
const agentRawContent = resolveDocsAudienceMdxContent(content, "agent");
|
|
1004
1070
|
return {
|
|
1005
1071
|
agentContent: stripMdx(agentRawContent),
|
|
1006
1072
|
agentRawContent,
|
|
1007
|
-
agentLastModified: fs.statSync(
|
|
1073
|
+
agentLastModified: fs.statSync(
|
|
1074
|
+
/* turbopackIgnore: true */
|
|
1075
|
+
agentPath
|
|
1076
|
+
).mtime.toISOString()
|
|
1008
1077
|
};
|
|
1009
1078
|
} catch {
|
|
1010
1079
|
return;
|
|
@@ -1017,18 +1086,28 @@ function normalizeFrontmatterLastmod(value) {
|
|
|
1017
1086
|
function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/${normalizePathSegment(entry) || "docs"}`) {
|
|
1018
1087
|
const indexes = [];
|
|
1019
1088
|
function isExcluded(dir) {
|
|
1020
|
-
const resolved = path.resolve(
|
|
1089
|
+
const resolved = path.resolve(
|
|
1090
|
+
/* turbopackIgnore: true */
|
|
1091
|
+
dir
|
|
1092
|
+
);
|
|
1021
1093
|
return excludedDirs.some((excluded) => {
|
|
1022
1094
|
const relative = path.relative(excluded, resolved);
|
|
1023
1095
|
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
1024
1096
|
});
|
|
1025
1097
|
}
|
|
1026
1098
|
function scan(dir, slugParts) {
|
|
1027
|
-
if (!fs.existsSync(
|
|
1099
|
+
if (!fs.existsSync(
|
|
1100
|
+
/* turbopackIgnore: true */
|
|
1101
|
+
dir
|
|
1102
|
+
)) return;
|
|
1028
1103
|
if (isExcluded(dir)) return;
|
|
1029
1104
|
const pageSource = resolveDocsSearchPageSource(dir);
|
|
1030
1105
|
if (pageSource) try {
|
|
1031
|
-
const raw = fs.readFileSync(
|
|
1106
|
+
const raw = fs.readFileSync(
|
|
1107
|
+
/* turbopackIgnore: true */
|
|
1108
|
+
pageSource,
|
|
1109
|
+
"utf-8"
|
|
1110
|
+
);
|
|
1032
1111
|
const { data } = matter(raw);
|
|
1033
1112
|
if (resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden" && hasVisibleDescendantDocsSearchPage(dir)) {} else {
|
|
1034
1113
|
const title = data.title || slugParts[slugParts.length - 1]?.replace(/-/g, " ") || "Documentation";
|
|
@@ -1054,7 +1133,10 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
|
|
|
1054
1133
|
url,
|
|
1055
1134
|
sourcePath: pageSource.replace(/\\/g, "/"),
|
|
1056
1135
|
lastmod: normalizeFrontmatterLastmod(data.lastmod),
|
|
1057
|
-
lastModified: fs.statSync(
|
|
1136
|
+
lastModified: fs.statSync(
|
|
1137
|
+
/* turbopackIgnore: true */
|
|
1138
|
+
pageSource
|
|
1139
|
+
).mtime.toISOString(),
|
|
1058
1140
|
locale,
|
|
1059
1141
|
framework,
|
|
1060
1142
|
version,
|
|
@@ -1065,14 +1147,24 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
|
|
|
1065
1147
|
} catch {}
|
|
1066
1148
|
let entries;
|
|
1067
1149
|
try {
|
|
1068
|
-
entries = fs.readdirSync(
|
|
1150
|
+
entries = fs.readdirSync(
|
|
1151
|
+
/* turbopackIgnore: true */
|
|
1152
|
+
dir
|
|
1153
|
+
);
|
|
1069
1154
|
} catch {
|
|
1070
1155
|
return;
|
|
1071
1156
|
}
|
|
1072
1157
|
for (const name of entries.sort()) {
|
|
1073
|
-
const full = path.join(
|
|
1158
|
+
const full = path.join(
|
|
1159
|
+
/* turbopackIgnore: true */
|
|
1160
|
+
dir,
|
|
1161
|
+
name
|
|
1162
|
+
);
|
|
1074
1163
|
try {
|
|
1075
|
-
if (fs.statSync(
|
|
1164
|
+
if (fs.statSync(
|
|
1165
|
+
/* turbopackIgnore: true */
|
|
1166
|
+
full
|
|
1167
|
+
).isDirectory()) scan(full, [...slugParts, name]);
|
|
1076
1168
|
} catch {}
|
|
1077
1169
|
}
|
|
1078
1170
|
}
|
|
@@ -1080,28 +1172,55 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
|
|
|
1080
1172
|
return resolveRelatedForSearchPages(indexes);
|
|
1081
1173
|
}
|
|
1082
1174
|
function scanChangelogDir(changelogDir, entryPath, changelogPath, locale, publicPath = `/${normalizePathSegment(entryPath) || "docs"}`) {
|
|
1083
|
-
if (!fs.existsSync(
|
|
1175
|
+
if (!fs.existsSync(
|
|
1176
|
+
/* turbopackIgnore: true */
|
|
1177
|
+
changelogDir
|
|
1178
|
+
)) return [];
|
|
1084
1179
|
const indexes = [];
|
|
1085
1180
|
let entries;
|
|
1086
1181
|
try {
|
|
1087
|
-
entries = fs.readdirSync(
|
|
1182
|
+
entries = fs.readdirSync(
|
|
1183
|
+
/* turbopackIgnore: true */
|
|
1184
|
+
changelogDir
|
|
1185
|
+
).sort().reverse();
|
|
1088
1186
|
} catch {
|
|
1089
1187
|
return indexes;
|
|
1090
1188
|
}
|
|
1091
1189
|
for (const name of entries) {
|
|
1092
1190
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
|
|
1093
|
-
const entryDir = path.join(
|
|
1191
|
+
const entryDir = path.join(
|
|
1192
|
+
/* turbopackIgnore: true */
|
|
1193
|
+
changelogDir,
|
|
1194
|
+
name
|
|
1195
|
+
);
|
|
1094
1196
|
let isDirectory = false;
|
|
1095
1197
|
try {
|
|
1096
|
-
isDirectory = fs.existsSync(
|
|
1198
|
+
isDirectory = fs.existsSync(
|
|
1199
|
+
/* turbopackIgnore: true */
|
|
1200
|
+
entryDir
|
|
1201
|
+
) && fs.statSync(
|
|
1202
|
+
/* turbopackIgnore: true */
|
|
1203
|
+
entryDir
|
|
1204
|
+
).isDirectory();
|
|
1097
1205
|
} catch {
|
|
1098
1206
|
continue;
|
|
1099
1207
|
}
|
|
1100
1208
|
if (!isDirectory) continue;
|
|
1101
|
-
const pagePath = path.join(
|
|
1102
|
-
|
|
1209
|
+
const pagePath = path.join(
|
|
1210
|
+
/* turbopackIgnore: true */
|
|
1211
|
+
entryDir,
|
|
1212
|
+
"page.mdx"
|
|
1213
|
+
);
|
|
1214
|
+
if (!fs.existsSync(
|
|
1215
|
+
/* turbopackIgnore: true */
|
|
1216
|
+
pagePath
|
|
1217
|
+
)) continue;
|
|
1103
1218
|
try {
|
|
1104
|
-
const { data, content: fileContent } = matter(fs.readFileSync(
|
|
1219
|
+
const { data, content: fileContent } = matter(fs.readFileSync(
|
|
1220
|
+
/* turbopackIgnore: true */
|
|
1221
|
+
pagePath,
|
|
1222
|
+
"utf-8"
|
|
1223
|
+
));
|
|
1105
1224
|
if (data.draft === true) continue;
|
|
1106
1225
|
const title = data.title || name.replace(/-/g, " ");
|
|
1107
1226
|
const description = data.description;
|
|
@@ -1123,7 +1242,10 @@ function scanChangelogDir(changelogDir, entryPath, changelogPath, locale, public
|
|
|
1123
1242
|
url,
|
|
1124
1243
|
sourcePath: pagePath.replace(/\\/g, "/"),
|
|
1125
1244
|
lastmod: normalizeFrontmatterLastmod(data.lastmod),
|
|
1126
|
-
lastModified: fs.statSync(
|
|
1245
|
+
lastModified: fs.statSync(
|
|
1246
|
+
/* turbopackIgnore: true */
|
|
1247
|
+
pagePath
|
|
1248
|
+
).mtime.toISOString(),
|
|
1127
1249
|
locale,
|
|
1128
1250
|
type: "changelog",
|
|
1129
1251
|
version: typeof data.version === "string" ? data.version : void 0,
|
|
@@ -1276,10 +1398,21 @@ function withPublicDocsUrl(page, ctx) {
|
|
|
1276
1398
|
}
|
|
1277
1399
|
function readDocsPath(root) {
|
|
1278
1400
|
for (const ext of FILE_EXTS) {
|
|
1279
|
-
const configPath = path.join(
|
|
1280
|
-
|
|
1401
|
+
const configPath = path.join(
|
|
1402
|
+
/* turbopackIgnore: true */
|
|
1403
|
+
root,
|
|
1404
|
+
`docs.config.${ext}`
|
|
1405
|
+
);
|
|
1406
|
+
if (!fs.existsSync(
|
|
1407
|
+
/* turbopackIgnore: true */
|
|
1408
|
+
configPath
|
|
1409
|
+
)) continue;
|
|
1281
1410
|
try {
|
|
1282
|
-
const match = fs.readFileSync(
|
|
1411
|
+
const match = fs.readFileSync(
|
|
1412
|
+
/* turbopackIgnore: true */
|
|
1413
|
+
configPath,
|
|
1414
|
+
"utf-8"
|
|
1415
|
+
).match(/docsPath\s*:\s*["']([^"']*)["']/);
|
|
1283
1416
|
if (match) return match[1];
|
|
1284
1417
|
} catch {}
|
|
1285
1418
|
}
|
|
@@ -1459,9 +1592,16 @@ function createRootDocumentReader(rootDir, fileNames, preloadedDocuments) {
|
|
|
1459
1592
|
let cached;
|
|
1460
1593
|
return function readRootDocument() {
|
|
1461
1594
|
for (const fileName of fileNames) {
|
|
1462
|
-
const candidate = path.join(
|
|
1595
|
+
const candidate = path.join(
|
|
1596
|
+
/* turbopackIgnore: true */
|
|
1597
|
+
rootDir,
|
|
1598
|
+
fileName
|
|
1599
|
+
);
|
|
1463
1600
|
try {
|
|
1464
|
-
const stats = fs.statSync(
|
|
1601
|
+
const stats = fs.statSync(
|
|
1602
|
+
/* turbopackIgnore: true */
|
|
1603
|
+
candidate
|
|
1604
|
+
);
|
|
1465
1605
|
if (!stats.isFile()) continue;
|
|
1466
1606
|
const signature = [
|
|
1467
1607
|
stats.dev,
|
|
@@ -1471,7 +1611,11 @@ function createRootDocumentReader(rootDir, fileNames, preloadedDocuments) {
|
|
|
1471
1611
|
stats.ctimeMs
|
|
1472
1612
|
].join(":");
|
|
1473
1613
|
if (cached?.path === candidate && cached.signature === signature) return cached.content;
|
|
1474
|
-
const content = fs.readFileSync(
|
|
1614
|
+
const content = fs.readFileSync(
|
|
1615
|
+
/* turbopackIgnore: true */
|
|
1616
|
+
candidate,
|
|
1617
|
+
"utf-8"
|
|
1618
|
+
);
|
|
1475
1619
|
cached = {
|
|
1476
1620
|
path: candidate,
|
|
1477
1621
|
signature,
|
|
@@ -1723,10 +1867,9 @@ async function handleAskAI(request, indexes, aiConfig, cloudConfig, search, anal
|
|
|
1723
1867
|
path: url.pathname
|
|
1724
1868
|
}
|
|
1725
1869
|
});
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
} catch {
|
|
1870
|
+
const parsedBody = await readDocsJsonBody(request);
|
|
1871
|
+
if (!parsedBody.ok) {
|
|
1872
|
+
const status = parsedBody.reason === "request_too_large" ? 413 : 400;
|
|
1730
1873
|
await emitDocsAnalyticsEvent(analytics, {
|
|
1731
1874
|
type: "api_ai_error",
|
|
1732
1875
|
source: "server",
|
|
@@ -1735,13 +1878,20 @@ async function handleAskAI(request, indexes, aiConfig, cloudConfig, search, anal
|
|
|
1735
1878
|
locale: analyticsContext.locale,
|
|
1736
1879
|
properties: {
|
|
1737
1880
|
...requestAnalyticsProperties,
|
|
1738
|
-
reason:
|
|
1881
|
+
reason: parsedBody.reason,
|
|
1739
1882
|
durationMs: Math.max(0, Date.now() - requestStartedAt)
|
|
1740
1883
|
}
|
|
1741
1884
|
});
|
|
1742
|
-
await emitRunError(
|
|
1743
|
-
return Response.json({
|
|
1744
|
-
|
|
1885
|
+
await emitRunError(parsedBody.reason, { status });
|
|
1886
|
+
return Response.json({
|
|
1887
|
+
error: parsedBody.reason === "request_too_large" ? `Request body exceeds the ${parsedBody.maxBodyBytes} byte limit` : "Invalid JSON body. Expected { messages: [...] }",
|
|
1888
|
+
...parsedBody.reason === "request_too_large" ? {
|
|
1889
|
+
code: parsedBody.reason,
|
|
1890
|
+
maxBodyBytes: parsedBody.maxBodyBytes
|
|
1891
|
+
} : {}
|
|
1892
|
+
}, { status });
|
|
1893
|
+
}
|
|
1894
|
+
const body = parsedBody.value;
|
|
1745
1895
|
const messages = body.messages;
|
|
1746
1896
|
const shouldStreamResponse = body.stream !== false && (request.headers.get("accept")?.toLowerCase().includes("text/event-stream") ?? true);
|
|
1747
1897
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
@@ -2401,9 +2551,20 @@ async function handleAskAI(request, indexes, aiConfig, cloudConfig, search, anal
|
|
|
2401
2551
|
}
|
|
2402
2552
|
function readLlmsTxtConfig(root) {
|
|
2403
2553
|
for (const ext of FILE_EXTS) {
|
|
2404
|
-
const configPath = path.join(
|
|
2405
|
-
|
|
2406
|
-
|
|
2554
|
+
const configPath = path.join(
|
|
2555
|
+
/* turbopackIgnore: true */
|
|
2556
|
+
root,
|
|
2557
|
+
`docs.config.${ext}`
|
|
2558
|
+
);
|
|
2559
|
+
if (fs.existsSync(
|
|
2560
|
+
/* turbopackIgnore: true */
|
|
2561
|
+
configPath
|
|
2562
|
+
)) try {
|
|
2563
|
+
const content = fs.readFileSync(
|
|
2564
|
+
/* turbopackIgnore: true */
|
|
2565
|
+
configPath,
|
|
2566
|
+
"utf-8"
|
|
2567
|
+
);
|
|
2407
2568
|
const sanitized = stripCommentsAndStrings(content);
|
|
2408
2569
|
const configObject = extractRootConfigObject(content, sanitized);
|
|
2409
2570
|
const scopedContent = configObject?.content ?? content;
|
|
@@ -2452,10 +2613,21 @@ function resolveLlmsTxtConfig(input, fallback) {
|
|
|
2452
2613
|
}
|
|
2453
2614
|
function readSitemapConfig(root) {
|
|
2454
2615
|
for (const ext of FILE_EXTS) {
|
|
2455
|
-
const configPath = path.join(
|
|
2456
|
-
|
|
2616
|
+
const configPath = path.join(
|
|
2617
|
+
/* turbopackIgnore: true */
|
|
2618
|
+
root,
|
|
2619
|
+
`docs.config.${ext}`
|
|
2620
|
+
);
|
|
2621
|
+
if (!fs.existsSync(
|
|
2622
|
+
/* turbopackIgnore: true */
|
|
2623
|
+
configPath
|
|
2624
|
+
)) continue;
|
|
2457
2625
|
try {
|
|
2458
|
-
const content = fs.readFileSync(
|
|
2626
|
+
const content = fs.readFileSync(
|
|
2627
|
+
/* turbopackIgnore: true */
|
|
2628
|
+
configPath,
|
|
2629
|
+
"utf-8"
|
|
2630
|
+
);
|
|
2459
2631
|
if (!content.includes("sitemap")) return void 0;
|
|
2460
2632
|
if (/sitemap\s*:\s*false/.test(content)) return false;
|
|
2461
2633
|
if (/sitemap\s*:\s*true/.test(content)) return true;
|
|
@@ -2477,10 +2649,21 @@ function readSitemapConfig(root) {
|
|
|
2477
2649
|
}
|
|
2478
2650
|
function readRobotsConfig(root) {
|
|
2479
2651
|
for (const ext of FILE_EXTS) {
|
|
2480
|
-
const configPath = path.join(
|
|
2481
|
-
|
|
2652
|
+
const configPath = path.join(
|
|
2653
|
+
/* turbopackIgnore: true */
|
|
2654
|
+
root,
|
|
2655
|
+
`docs.config.${ext}`
|
|
2656
|
+
);
|
|
2657
|
+
if (!fs.existsSync(
|
|
2658
|
+
/* turbopackIgnore: true */
|
|
2659
|
+
configPath
|
|
2660
|
+
)) continue;
|
|
2482
2661
|
try {
|
|
2483
|
-
const content = fs.readFileSync(
|
|
2662
|
+
const content = fs.readFileSync(
|
|
2663
|
+
/* turbopackIgnore: true */
|
|
2664
|
+
configPath,
|
|
2665
|
+
"utf-8"
|
|
2666
|
+
);
|
|
2484
2667
|
if (!content.includes("robots")) return void 0;
|
|
2485
2668
|
if (/robots\s*:\s*false/.test(content)) return false;
|
|
2486
2669
|
if (/robots\s*:\s*true/.test(content)) return true;
|
|
@@ -2502,10 +2685,21 @@ function readRobotsConfig(root) {
|
|
|
2502
2685
|
}
|
|
2503
2686
|
function readApiReferenceConfig(root) {
|
|
2504
2687
|
for (const ext of FILE_EXTS) {
|
|
2505
|
-
const configPath = path.join(
|
|
2506
|
-
|
|
2688
|
+
const configPath = path.join(
|
|
2689
|
+
/* turbopackIgnore: true */
|
|
2690
|
+
root,
|
|
2691
|
+
`docs.config.${ext}`
|
|
2692
|
+
);
|
|
2693
|
+
if (!fs.existsSync(
|
|
2694
|
+
/* turbopackIgnore: true */
|
|
2695
|
+
configPath
|
|
2696
|
+
)) continue;
|
|
2507
2697
|
try {
|
|
2508
|
-
const content = fs.readFileSync(
|
|
2698
|
+
const content = fs.readFileSync(
|
|
2699
|
+
/* turbopackIgnore: true */
|
|
2700
|
+
configPath,
|
|
2701
|
+
"utf-8"
|
|
2702
|
+
);
|
|
2509
2703
|
if (!content.includes("apiReference")) return void 0;
|
|
2510
2704
|
if (/apiReference\s*:\s*false/.test(content)) return false;
|
|
2511
2705
|
if (/apiReference\s*:\s*true/.test(content)) return true;
|
|
@@ -2575,7 +2769,11 @@ function createDocsAPI(options) {
|
|
|
2575
2769
|
const analytics = options?.analytics;
|
|
2576
2770
|
const observability = options?.observability;
|
|
2577
2771
|
const appDir = getNextAppDir(root);
|
|
2578
|
-
const contentDir = options?.contentDir ?? path.join(
|
|
2772
|
+
const contentDir = options?.contentDir ?? path.join(
|
|
2773
|
+
/* turbopackIgnore: true */
|
|
2774
|
+
appDir,
|
|
2775
|
+
entry
|
|
2776
|
+
);
|
|
2579
2777
|
const changelogConfig = resolveChangelogConfig(options?.changelog);
|
|
2580
2778
|
const agentFeedbackConfig = resolveAgentFeedbackConfig(options?.feedback);
|
|
2581
2779
|
const i18nConfig = options?.i18n ?? readI18nConfig(root);
|
|
@@ -2594,6 +2792,7 @@ function createDocsAPI(options) {
|
|
|
2594
2792
|
const llmsConfig = resolveLlmsTxtConfig(options?.llmsTxt, readLlmsTxtConfig(root));
|
|
2595
2793
|
const apiCatalogEnabled = options?.apiCatalog ?? llmsConfig.apiCatalog ?? true;
|
|
2596
2794
|
const sitemapConfig = options?.sitemap ?? readSitemapConfig(root);
|
|
2795
|
+
const sitemapManifest = readDocsSitemapManifest(root, sitemapConfig);
|
|
2597
2796
|
const robotsConfig = options?.robots ?? readRobotsConfig(root);
|
|
2598
2797
|
const markdownMetadataBaseUrl = resolveDocsMetadataBaseUrl({
|
|
2599
2798
|
...options,
|
|
@@ -2682,21 +2881,57 @@ function createDocsAPI(options) {
|
|
|
2682
2881
|
}
|
|
2683
2882
|
function resolveDocsDirCandidates(locale) {
|
|
2684
2883
|
const relativeCandidates = /* @__PURE__ */ new Set();
|
|
2685
|
-
if (path.isAbsolute(contentDir)) return [locale ? path.join(
|
|
2884
|
+
if (path.isAbsolute(contentDir)) return [locale ? path.join(
|
|
2885
|
+
/* turbopackIgnore: true */
|
|
2886
|
+
contentDir,
|
|
2887
|
+
locale
|
|
2888
|
+
) : contentDir];
|
|
2686
2889
|
relativeCandidates.add(contentDir);
|
|
2687
|
-
relativeCandidates.add(path.join(
|
|
2688
|
-
|
|
2890
|
+
relativeCandidates.add(path.join(
|
|
2891
|
+
"app",
|
|
2892
|
+
/* turbopackIgnore: true */
|
|
2893
|
+
entry
|
|
2894
|
+
));
|
|
2895
|
+
relativeCandidates.add(path.join(
|
|
2896
|
+
"src",
|
|
2897
|
+
"app",
|
|
2898
|
+
/* turbopackIgnore: true */
|
|
2899
|
+
entry
|
|
2900
|
+
));
|
|
2689
2901
|
const rootCandidates = new Set([root]);
|
|
2690
2902
|
rootCandidates.add(process.cwd());
|
|
2691
|
-
if (path.basename(root) === "server") rootCandidates.add(path.resolve(
|
|
2903
|
+
if (path.basename(root) === "server") rootCandidates.add(path.resolve(
|
|
2904
|
+
/* turbopackIgnore: true */
|
|
2905
|
+
root,
|
|
2906
|
+
"..",
|
|
2907
|
+
".."
|
|
2908
|
+
));
|
|
2692
2909
|
else {
|
|
2693
|
-
rootCandidates.add(path.join(
|
|
2694
|
-
|
|
2910
|
+
rootCandidates.add(path.join(
|
|
2911
|
+
/* turbopackIgnore: true */
|
|
2912
|
+
root,
|
|
2913
|
+
".next",
|
|
2914
|
+
"server"
|
|
2915
|
+
));
|
|
2916
|
+
rootCandidates.add(path.join(
|
|
2917
|
+
/* turbopackIgnore: true */
|
|
2918
|
+
root,
|
|
2919
|
+
".next-build",
|
|
2920
|
+
"server"
|
|
2921
|
+
));
|
|
2695
2922
|
}
|
|
2696
2923
|
const resolved = /* @__PURE__ */ new Set();
|
|
2697
2924
|
for (const base of rootCandidates) for (const relative of relativeCandidates) {
|
|
2698
|
-
const candidate = path.join(
|
|
2699
|
-
|
|
2925
|
+
const candidate = path.join(
|
|
2926
|
+
/* turbopackIgnore: true */
|
|
2927
|
+
base,
|
|
2928
|
+
relative
|
|
2929
|
+
);
|
|
2930
|
+
resolved.add(locale ? path.join(
|
|
2931
|
+
/* turbopackIgnore: true */
|
|
2932
|
+
candidate,
|
|
2933
|
+
locale
|
|
2934
|
+
) : candidate);
|
|
2700
2935
|
}
|
|
2701
2936
|
return [...resolved];
|
|
2702
2937
|
}
|
|
@@ -2714,7 +2949,11 @@ function createDocsAPI(options) {
|
|
|
2714
2949
|
function resolveChangelogDirCandidates(docsDirs) {
|
|
2715
2950
|
if (!changelogConfig.enabled) return [];
|
|
2716
2951
|
if (path.isAbsolute(changelogConfig.contentDir)) return [changelogConfig.contentDir];
|
|
2717
|
-
return docsDirs.map((docsDir) => path.join(
|
|
2952
|
+
return docsDirs.map((docsDir) => path.join(
|
|
2953
|
+
/* turbopackIgnore: true */
|
|
2954
|
+
docsDir,
|
|
2955
|
+
changelogConfig.contentDir
|
|
2956
|
+
));
|
|
2718
2957
|
}
|
|
2719
2958
|
function isWithinDir(candidate, target) {
|
|
2720
2959
|
const relative = path.relative(target, candidate);
|
|
@@ -2762,8 +3001,9 @@ function createDocsAPI(options) {
|
|
|
2762
3001
|
const changelogPages = ctx.changelogDirs.flatMap((dir) => scanChangelogDir(dir, ctx.entryPath, changelogConfig.path, ctx.locale, ctx.publicPath));
|
|
2763
3002
|
next = [...next, ...changelogPages];
|
|
2764
3003
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
3004
|
+
const timestamped = next.map((page) => withSitemapLastModified(page, sitemapManifest));
|
|
3005
|
+
indexesByLocale.set(key, timestamped);
|
|
3006
|
+
return timestamped;
|
|
2767
3007
|
}
|
|
2768
3008
|
function getApiOperationSearchPages(ctx, baseUrl) {
|
|
2769
3009
|
const key = `${ctx.locale ?? "__default__"}\0${baseUrl}`;
|
|
@@ -2795,9 +3035,14 @@ function createDocsAPI(options) {
|
|
|
2795
3035
|
const normalizedPublicRequest = normalizePublicRequestedMarkdownPath(ctx, requestedPath);
|
|
2796
3036
|
const normalizedEntry = `/${normalizePathSegment(ctx.entryPath)}`;
|
|
2797
3037
|
const relativeSlug = normalizedRequest === normalizedEntry ? "" : normalizedRequest.slice(normalizedEntry.length).replace(/^\/+/, "");
|
|
2798
|
-
for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(
|
|
3038
|
+
for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(
|
|
3039
|
+
/* turbopackIgnore: true */
|
|
3040
|
+
docsDir,
|
|
3041
|
+
...relativeSlug.split("/")
|
|
3042
|
+
) : docsDir)) return null;
|
|
2799
3043
|
for (const source of getMarkdownSources(ctx)) {
|
|
2800
|
-
const
|
|
3044
|
+
const resolvedPage = findDocsMcpPage(ctx.entryPath, await source.getPages(), requestedPath);
|
|
3045
|
+
const page = resolvedPage ? withSitemapLastModified(resolvedPage, sitemapManifest) : void 0;
|
|
2801
3046
|
if (page) return {
|
|
2802
3047
|
document: renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
|
|
2803
3048
|
llmsEnabled: llmsConfig.enabled,
|
|
@@ -3134,7 +3379,7 @@ function createDocsAPI(options) {
|
|
|
3134
3379
|
siteTitle: llmsConfig.siteTitle ?? "Documentation",
|
|
3135
3380
|
baseUrl: llmsConfig.baseUrl ?? url.origin,
|
|
3136
3381
|
pages: getIndexes(ctx),
|
|
3137
|
-
manifest:
|
|
3382
|
+
manifest: sitemapManifest
|
|
3138
3383
|
});
|
|
3139
3384
|
if (sitemapResponse) return sitemapResponse;
|
|
3140
3385
|
const operationMarkdownResponse = await createApiReferenceOperationMarkdownResponse(apiReferenceDocsConfig, {
|
|
@@ -3363,7 +3608,7 @@ function createDocsAPI(options) {
|
|
|
3363
3608
|
status: 405,
|
|
3364
3609
|
headers: { Allow: "GET" }
|
|
3365
3610
|
});
|
|
3366
|
-
const parsed = await
|
|
3611
|
+
const parsed = await parseDocsAgentFeedbackData(request);
|
|
3367
3612
|
if (!parsed.ok) {
|
|
3368
3613
|
await emitDocsAnalyticsEvent(analytics, {
|
|
3369
3614
|
type: "agent_feedback_error",
|
|
@@ -3373,7 +3618,7 @@ function createDocsAPI(options) {
|
|
|
3373
3618
|
properties: {
|
|
3374
3619
|
...requestAnalyticsProperties,
|
|
3375
3620
|
feedbackKind: "agent",
|
|
3376
|
-
reason: "invalid_body"
|
|
3621
|
+
reason: parsed.response.status === 413 ? "request_too_large" : "invalid_body"
|
|
3377
3622
|
}
|
|
3378
3623
|
});
|
|
3379
3624
|
return parsed.response;
|
|
@@ -3482,8 +3727,13 @@ function createDocsMCPAPI(options = {}) {
|
|
|
3482
3727
|
const readRootSkillDocument = createRootDocumentReader(rootDir, ["skill.md"], options._preloadedRootDocuments);
|
|
3483
3728
|
const entry = options.entry ?? readEntry(rootDir);
|
|
3484
3729
|
const appDir = getNextAppDir(rootDir);
|
|
3485
|
-
const contentDir = options.contentDir ?? path.join(
|
|
3730
|
+
const contentDir = options.contentDir ?? path.join(
|
|
3731
|
+
/* turbopackIgnore: true */
|
|
3732
|
+
appDir,
|
|
3733
|
+
entry
|
|
3734
|
+
);
|
|
3486
3735
|
const mcpConfig = options.mcp ?? readMcpConfig(rootDir, { rejectRuntimeSecurity: true });
|
|
3736
|
+
const sitemapManifest = readDocsSitemapManifest(rootDir, options.sitemap ?? readSitemapConfig(rootDir));
|
|
3487
3737
|
const contentChangeFeed = createDocsContentChangeFeed(options.agent?.contentChanges);
|
|
3488
3738
|
const navTitle = typeof options.nav?.title === "string" && options.nav.title.trim().length > 0 ? options.nav.title : "Documentation";
|
|
3489
3739
|
let configuredAgentSkills;
|
|
@@ -3491,15 +3741,19 @@ function createDocsMCPAPI(options = {}) {
|
|
|
3491
3741
|
if (!configuredAgentSkills) configuredAgentSkills = Array.isArray(options._preloadedAgentSkills) ? Promise.resolve([...options._preloadedAgentSkills]) : resolveConfiguredAgentSkills(options.agent?.skills, { rootDir });
|
|
3492
3742
|
return configuredAgentSkills;
|
|
3493
3743
|
}
|
|
3744
|
+
const filesystemSource = createFilesystemDocsMcpSource({
|
|
3745
|
+
rootDir,
|
|
3746
|
+
entry,
|
|
3747
|
+
contentDir,
|
|
3748
|
+
siteTitle: navTitle,
|
|
3749
|
+
baseUrl: options.baseUrl?.trim() || resolveDocsMetadataBaseUrl(options) || void 0,
|
|
3750
|
+
ordering: options.ordering
|
|
3751
|
+
});
|
|
3494
3752
|
const source = {
|
|
3495
|
-
...
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
siteTitle: navTitle,
|
|
3500
|
-
baseUrl: options.baseUrl?.trim() || resolveDocsMetadataBaseUrl(options) || void 0,
|
|
3501
|
-
ordering: options.ordering
|
|
3502
|
-
}),
|
|
3753
|
+
...filesystemSource,
|
|
3754
|
+
async getPages() {
|
|
3755
|
+
return (await filesystemSource.getPages()).map((page) => withSitemapLastModified(page, sitemapManifest));
|
|
3756
|
+
},
|
|
3503
3757
|
async getSkills() {
|
|
3504
3758
|
const configured = await getConfiguredAgentSkills();
|
|
3505
3759
|
return [await resolveDocsPublishedAgentSkill({
|