@farming-labs/next 0.1.30 → 0.1.33

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/config.mjs +59 -12
  2. package/package.json +3 -3
package/dist/config.mjs CHANGED
@@ -147,7 +147,15 @@ const FILE_EXTS = [
147
147
  const INTERNAL_DOCS_CONFIG_ALIAS = "@farming-labs/next-internal-docs-config";
148
148
  const NEXT_PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
149
149
  const DEFAULT_AGENT_SPEC_ROUTE = "/api/docs/agent/spec";
150
+ const DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE = "/.well-known/agent";
151
+ const DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE = "/.well-known/agent.json";
150
152
  const DEFAULT_AGENT_FEEDBACK_ROUTE = "/api/docs/agent/feedback";
153
+ const DEFAULT_MCP_ROUTE = "/api/docs/mcp";
154
+ const DEFAULT_MCP_PUBLIC_ROUTE = "/mcp";
155
+ const DEFAULT_LLMS_TXT_ROUTE = "/llms.txt";
156
+ const DEFAULT_LLMS_FULL_TXT_ROUTE = "/llms-full.txt";
157
+ const DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE = "/.well-known/llms.txt";
158
+ const DEFAULT_LLMS_FULL_TXT_WELL_KNOWN_ROUTE = "/.well-known/llms-full.txt";
151
159
  const MARKDOWN_ACCEPT_HEADER_VALUE = [
152
160
  "(?:^|.*,\\s*)",
153
161
  "text/markdown",
@@ -630,11 +638,11 @@ function readMcpConfig(root) {
630
638
  const content = readFileSync(configPath, "utf-8");
631
639
  if (content.match(/mcp\s*:\s*false/)) return {
632
640
  enabled: false,
633
- route: "/api/docs/mcp"
641
+ route: DEFAULT_MCP_ROUTE
634
642
  };
635
643
  if (content.match(/mcp\s*:\s*true/)) return {
636
644
  enabled: true,
637
- route: "/api/docs/mcp"
645
+ route: DEFAULT_MCP_ROUTE
638
646
  };
639
647
  const block = extractObjectLiteral(content, "mcp");
640
648
  if (!block) continue;
@@ -642,23 +650,23 @@ function readMcpConfig(root) {
642
650
  const routeMatch = block.match(/route\s*:\s*["']([^"']+)["']/);
643
651
  return {
644
652
  enabled: enabledMatch ? enabledMatch[1] !== "false" : true,
645
- route: normalizeRoutePath(routeMatch?.[1] ?? "/api/docs/mcp")
653
+ route: normalizeRoutePath(routeMatch?.[1] ?? DEFAULT_MCP_ROUTE)
646
654
  };
647
655
  } catch {
648
656
  return {
649
657
  enabled: true,
650
- route: "/api/docs/mcp"
658
+ route: DEFAULT_MCP_ROUTE
651
659
  };
652
660
  }
653
661
  }
654
662
  return {
655
663
  enabled: true,
656
- route: "/api/docs/mcp"
664
+ route: DEFAULT_MCP_ROUTE
657
665
  };
658
666
  }
659
667
  function normalizeRoutePath(route) {
660
668
  const normalized = `/${route}`.replace(/\/+/g, "/");
661
- return normalized !== "/" ? normalized.replace(/\/+$/, "") : "/api/docs/mcp";
669
+ return normalized !== "/" ? normalized.replace(/\/+$/, "") : DEFAULT_MCP_ROUTE;
662
670
  }
663
671
  function normalizeAgentFeedbackRoute(route, fallback = DEFAULT_AGENT_FEEDBACK_ROUTE) {
664
672
  if (!route || route.trim().length === 0) return fallback;
@@ -730,9 +738,46 @@ function buildDocsMarkdownRewrites(entry) {
730
738
  ];
731
739
  }
732
740
  function buildAgentSpecRewrites() {
741
+ return [
742
+ {
743
+ source: DEFAULT_AGENT_SPEC_ROUTE,
744
+ destination: "/api/docs?agent=spec"
745
+ },
746
+ {
747
+ source: DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE,
748
+ destination: "/api/docs?agent=spec"
749
+ },
750
+ {
751
+ source: DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE,
752
+ destination: "/api/docs?agent=spec"
753
+ }
754
+ ];
755
+ }
756
+ function buildLlmsTxtRewrites() {
757
+ return [
758
+ {
759
+ source: DEFAULT_LLMS_TXT_ROUTE,
760
+ destination: "/api/docs?format=llms"
761
+ },
762
+ {
763
+ source: DEFAULT_LLMS_FULL_TXT_ROUTE,
764
+ destination: "/api/docs?format=llms-full"
765
+ },
766
+ {
767
+ source: DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE,
768
+ destination: "/api/docs?format=llms"
769
+ },
770
+ {
771
+ source: DEFAULT_LLMS_FULL_TXT_WELL_KNOWN_ROUTE,
772
+ destination: "/api/docs?format=llms-full"
773
+ }
774
+ ];
775
+ }
776
+ function buildMcpRewrites(config) {
777
+ if (!config.enabled || config.route === DEFAULT_MCP_PUBLIC_ROUTE) return [];
733
778
  return [{
734
- source: DEFAULT_AGENT_SPEC_ROUTE,
735
- destination: "/api/docs?agent=spec"
779
+ source: DEFAULT_MCP_PUBLIC_ROUTE,
780
+ destination: config.route
736
781
  }];
737
782
  }
738
783
  function buildAgentFeedbackRewrites(config) {
@@ -756,9 +801,11 @@ function dedupeRewrites(rewrites) {
756
801
  }
757
802
  return result;
758
803
  }
759
- function mergeDocsMarkdownRewrites(entry, agentFeedback, result) {
804
+ function mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, result) {
760
805
  const autoRewrites = [
761
806
  ...buildAgentSpecRewrites(),
807
+ ...buildMcpRewrites(mcp),
808
+ ...buildLlmsTxtRewrites(),
762
809
  ...buildDocsMarkdownRewrites(entry),
763
810
  ...buildAgentFeedbackRewrites(agentFeedback)
764
811
  ];
@@ -797,7 +844,7 @@ function withDocs(nextConfig = {}) {
797
844
  }
798
845
  const mcp = readMcpConfig(root);
799
846
  const docsMcpRouteDir = join(root, appDir, "api", "docs", "mcp");
800
- if (mcp.enabled && mcp.route === "/api/docs/mcp" && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
847
+ if (mcp.enabled && mcp.route === DEFAULT_MCP_ROUTE && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
801
848
  mkdirSync(docsMcpRouteDir, { recursive: true });
802
849
  writeFileSync(join(docsMcpRouteDir, "route.ts"), DOCS_MCP_ROUTE_TEMPLATE);
803
850
  }
@@ -948,13 +995,13 @@ function withDocs(nextConfig = {}) {
948
995
  if (!isStaticExport) {
949
996
  const existingRewrites = nextConfig.rewrites;
950
997
  nextConfig.rewrites = async () => {
951
- return mergeDocsMarkdownRewrites(entry, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
998
+ return mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
952
999
  };
953
1000
  }
954
1001
  nextConfig.outputFileTracingIncludes = {
955
1002
  ...existingTracingIncludes,
956
1003
  "/api/docs": [...new Set([...existingTracingIncludes["/api/docs"] ?? [], docsTraceGlob])],
957
- "/api/docs/mcp": [...new Set([...existingTracingIncludes["/api/docs/mcp"] ?? [], docsTraceGlob])]
1004
+ [DEFAULT_MCP_ROUTE]: [...new Set([...existingTracingIncludes[DEFAULT_MCP_ROUTE] ?? [], docsTraceGlob])]
958
1005
  };
959
1006
  return withMDX(nextConfig);
960
1007
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/next",
3
- "version": "0.1.30",
3
+ "version": "0.1.33",
4
4
  "description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
5
5
  "keywords": [
6
6
  "docs",
@@ -95,8 +95,8 @@
95
95
  "tsdown": "^0.20.3",
96
96
  "typescript": "^5.9.3",
97
97
  "vitest": "^3.2.4",
98
- "@farming-labs/docs": "0.1.30",
99
- "@farming-labs/theme": "0.1.30"
98
+ "@farming-labs/docs": "0.1.33",
99
+ "@farming-labs/theme": "0.1.33"
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@farming-labs/docs": ">=0.0.1",