@farming-labs/theme 0.1.129 → 0.1.131

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.
Files changed (2) hide show
  1. package/dist/docs-api.mjs +50 -22
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -3,7 +3,7 @@ import { getNextAppDir } from "./get-app-dir.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import matter from "gray-matter";
6
- import { DEFAULT_SITEMAP_MD_DOCS_ROUTE, buildDocsAskAIContext, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsRobotsResponse, createDocsSitemapResponse, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, getDocsLlmsTxtMaxCharsIssue, getDocsMarkdownVaryHeader, hasDocsMarkdownSignatureAgent, normalizeDocsRelated, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownNotFound, renderDocsRelatedMarkdownLines, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsSitemapConfig, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent } from "@farming-labs/docs";
6
+ import { DEFAULT_SITEMAP_MD_DOCS_ROUTE, buildDocsAskAIContext, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsRobotsResponse, createDocsSitemapResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, getDocsLlmsTxtMaxCharsIssue, getDocsMarkdownVaryHeader, hasDocsMarkdownSignatureAgent, normalizeDocsRelated, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownDocument, renderDocsMarkdownNotFound, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMarkdownRecovery, resolveDocsSitemapConfig, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent } from "@farming-labs/docs";
7
7
  import { buildApiReferenceOpenApiDocumentAsync, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig } from "@farming-labs/docs/server";
8
8
 
9
9
  //#region src/docs-api.ts
@@ -992,6 +992,13 @@ function acceptsMarkdown(request) {
992
992
  return Number.isFinite(quality) ? quality > 0 : true;
993
993
  });
994
994
  }
995
+ function resolveMarkdownHeaderDelivery(request) {
996
+ if (hasDocsMarkdownSignatureAgent(request)) return "signature_agent";
997
+ if (acceptsMarkdown(request)) return "accept_header";
998
+ const agentDetection = detectDocsMarkdownAgentRequest(request);
999
+ if (!agentDetection.detected) return null;
1000
+ return agentDetection.method === "heuristic" ? "heuristic" : "user_agent";
1001
+ }
995
1002
  function resolveMarkdownRequest(entry, url, request) {
996
1003
  if (url.searchParams.get("format")?.trim() === "markdown") return {
997
1004
  requestedPath: url.searchParams.get("path")?.trim() ?? "",
@@ -1008,9 +1015,9 @@ function resolveMarkdownRequest(entry, url, request) {
1008
1015
  requestedPath: pathname.slice(slugPrefix.length, -3),
1009
1016
  delivery: "md_route"
1010
1017
  };
1011
- const hasSignatureAgent = hasDocsMarkdownSignatureAgent(request);
1012
- if (acceptsMarkdown(request) || hasSignatureAgent) {
1013
- const delivery = hasSignatureAgent ? "signature_agent" : "accept_header";
1018
+ const headerDelivery = resolveMarkdownHeaderDelivery(request);
1019
+ if (headerDelivery) {
1020
+ const delivery = headerDelivery;
1014
1021
  if (pathname === normalizedEntry) return {
1015
1022
  requestedPath: "",
1016
1023
  delivery
@@ -1078,9 +1085,9 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
1078
1085
  requestedPath: pathname.slice(1, -3),
1079
1086
  delivery: "md_route"
1080
1087
  };
1081
- const hasSignatureAgent = hasDocsMarkdownSignatureAgent(request);
1082
- if (acceptsMarkdown(request) || hasSignatureAgent) {
1083
- const delivery = hasSignatureAgent ? "signature_agent" : "accept_header";
1088
+ const headerDelivery = resolveMarkdownHeaderDelivery(request);
1089
+ if (headerDelivery) {
1090
+ const delivery = headerDelivery;
1084
1091
  return {
1085
1092
  requestedPath: pathname === "/" ? "" : pathname.slice(1),
1086
1093
  delivery
@@ -1097,9 +1104,9 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
1097
1104
  requestedPath: pathname.slice(slugPrefix.length, -3),
1098
1105
  delivery: "md_route"
1099
1106
  };
1100
- const hasSignatureAgent = hasDocsMarkdownSignatureAgent(request);
1101
- if (acceptsMarkdown(request) || hasSignatureAgent) {
1102
- const delivery = hasSignatureAgent ? "signature_agent" : "accept_header";
1107
+ const headerDelivery = resolveMarkdownHeaderDelivery(request);
1108
+ if (headerDelivery) {
1109
+ const delivery = headerDelivery;
1103
1110
  if (pathname === docsPath) return {
1104
1111
  requestedPath: "",
1105
1112
  delivery
@@ -1112,14 +1119,10 @@ function resolvePublicMarkdownRequest(entry, docsPath, url, request) {
1112
1119
  return null;
1113
1120
  }
1114
1121
  function renderMarkdownDocument(page, options = {}) {
1115
- if ("agentRawContent" in page && page.agentRawContent !== void 0) return page.agentRawContent;
1116
- const relatedLines = renderDocsRelatedMarkdownLines(page.related);
1117
- const lines = [`# ${page.title}`, `URL: ${page.url}`];
1118
- if (options.llmsEnabled !== false) lines.push("LLM index: /llms.txt");
1119
- if (page.description) lines.push(`Description: ${page.description}`);
1120
- lines.push(...relatedLines);
1121
- lines.push("", page.agentFallbackRawContent ?? page.rawContent ?? page.content);
1122
- return lines.join("\n");
1122
+ return renderDocsMarkdownDocument(page, {
1123
+ llms: options.llmsEnabled !== false,
1124
+ sitemap: options.sitemap
1125
+ });
1123
1126
  }
1124
1127
  function renderSkillDocument({ origin, entry, search, mcp, feedback, llms, sitemap, robots, openapi }) {
1125
1128
  const normalizedEntry = normalizePathSegment(entry) || "docs";
@@ -2020,15 +2023,24 @@ function createDocsAPI(options) {
2020
2023
  for (const docsDir of ctx.docsDirs) if (isHiddenFolderIndexPageDir(relativeSlug ? path.join(docsDir, ...relativeSlug.split("/")) : docsDir)) return null;
2021
2024
  for (const source of getMarkdownSources(ctx)) {
2022
2025
  const page = findDocsMcpPage(ctx.entryPath, await source.getPages(), requestedPath);
2023
- if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), { llmsEnabled: llmsConfig.enabled });
2026
+ if (page) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
2027
+ llmsEnabled: llmsConfig.enabled,
2028
+ sitemap: sitemapConfig
2029
+ });
2024
2030
  }
2025
2031
  const fallbackPage = getIndexes(ctx).find((page) => {
2026
2032
  const pageUrl = normalizeUrlPath(page.url);
2027
2033
  return pageUrl === normalizedRequest || pageUrl === normalizedPublicRequest;
2028
2034
  });
2029
- if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), { llmsEnabled: llmsConfig.enabled });
2035
+ if (fallbackPage) return renderMarkdownDocument(withPublicDocsUrl(fallbackPage, ctx), {
2036
+ llmsEnabled: llmsConfig.enabled,
2037
+ sitemap: sitemapConfig
2038
+ });
2030
2039
  const requestedSlug = normalizePublicDocsSlug(ctx, normalizedPublicRequest);
2031
- for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), { llmsEnabled: llmsConfig.enabled });
2040
+ for (const page of getIndexes(ctx)) if (normalizePublicDocsSlug(ctx, page.url) === requestedSlug) return renderMarkdownDocument(withPublicDocsUrl(page, ctx), {
2041
+ llmsEnabled: llmsConfig.enabled,
2042
+ sitemap: sitemapConfig
2043
+ });
2032
2044
  return null;
2033
2045
  }
2034
2046
  function getLlmsContent(ctx) {
@@ -2193,6 +2205,13 @@ function createDocsAPI(options) {
2193
2205
  requestedPath: markdownRequest.requestedPath
2194
2206
  });
2195
2207
  if (!document) {
2208
+ const recoveryPages = getIndexes(ctx).map((page) => withPublicDocsUrl(page, ctx));
2209
+ const recovery = resolveDocsMarkdownRecovery({
2210
+ entry,
2211
+ requestedPath: markdownRequest.requestedPath,
2212
+ pages: recoveryPages,
2213
+ sitemap: sitemapConfig
2214
+ });
2196
2215
  await emitDocsAnalyticsEvent(analytics, {
2197
2216
  type: "agent_read",
2198
2217
  source: "server",
@@ -2217,12 +2236,21 @@ function createDocsAPI(options) {
2217
2236
  found: false
2218
2237
  }
2219
2238
  });
2239
+ if (recovery.redirect) return new Response(null, {
2240
+ status: 307,
2241
+ headers: {
2242
+ Location: new URL(recovery.redirect.markdownUrl, url.origin).toString(),
2243
+ ...varyHeader ? { Vary: varyHeader } : {},
2244
+ "X-Robots-Tag": "noindex"
2245
+ }
2246
+ });
2220
2247
  return new Response(renderDocsMarkdownNotFound({
2221
2248
  entry,
2222
2249
  requestedPath: markdownRequest.requestedPath,
2250
+ pages: recoveryPages,
2223
2251
  sitemap: sitemapConfig
2224
2252
  }), {
2225
- status: 404,
2253
+ status: 200,
2226
2254
  headers: {
2227
2255
  "Content-Type": "text/markdown; charset=utf-8",
2228
2256
  ...varyHeader ? { Vary: varyHeader } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.129",
3
+ "version": "0.1.131",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -139,7 +139,7 @@
139
139
  "tsdown": "^0.20.3",
140
140
  "typescript": "^5.9.3",
141
141
  "vitest": "^3.2.4",
142
- "@farming-labs/docs": "0.1.129"
142
+ "@farming-labs/docs": "0.1.131"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "@farming-labs/docs": ">=0.0.1",