@farming-labs/next 0.1.20 → 0.1.22

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 +60 -6
  2. package/package.json +3 -3
package/dist/config.mjs CHANGED
@@ -75,6 +75,7 @@ export const { GET, POST } = createDocsAPI({
75
75
  contentDir: docsConfig.contentDir,
76
76
  i18n: docsConfig.i18n,
77
77
  changelog: docsConfig.changelog,
78
+ feedback: docsConfig.feedback,
78
79
  search: docsConfig.search,
79
80
  ai: docsConfig.ai,
80
81
  });
@@ -144,6 +145,7 @@ const FILE_EXTS = [
144
145
  ];
145
146
  const INTERNAL_DOCS_CONFIG_ALIAS = "@farming-labs/next-internal-docs-config";
146
147
  const NEXT_PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
148
+ const DEFAULT_AGENT_FEEDBACK_ROUTE = "/api/docs/agent/feedback";
147
149
  function resolvePackageAlias(packageName, fallbacks = []) {
148
150
  return [join(NEXT_PACKAGE_ROOT, "node_modules", packageName), ...fallbacks.map((value) => join(NEXT_PACKAGE_ROOT, value))].find((value) => existsSync(value));
149
151
  }
@@ -648,6 +650,47 @@ function normalizeRoutePath(route) {
648
650
  const normalized = `/${route}`.replace(/\/+/g, "/");
649
651
  return normalized !== "/" ? normalized.replace(/\/+$/, "") : "/api/docs/mcp";
650
652
  }
653
+ function normalizeAgentFeedbackRoute(route, fallback = DEFAULT_AGENT_FEEDBACK_ROUTE) {
654
+ if (!route || route.trim().length === 0) return fallback;
655
+ const normalized = `/${route}`.replace(/\/+/g, "/");
656
+ return normalized !== "/" ? normalized.replace(/\/+$/, "") : fallback;
657
+ }
658
+ function readAgentFeedbackConfig(root) {
659
+ const defaultRoute = normalizeAgentFeedbackRoute();
660
+ const disabled = {
661
+ enabled: false,
662
+ route: defaultRoute,
663
+ schemaRoute: `${defaultRoute}/schema`
664
+ };
665
+ for (const ext of FILE_EXTS) {
666
+ const configPath = join(root, `docs.config.${ext}`);
667
+ if (!existsSync(configPath)) continue;
668
+ try {
669
+ const feedbackBlock = extractObjectLiteral(readFileSync(configPath, "utf-8"), "feedback");
670
+ if (!feedbackBlock) continue;
671
+ if (feedbackBlock.match(/agent\s*:\s*false/)) return disabled;
672
+ if (feedbackBlock.match(/agent\s*:\s*true/)) return {
673
+ enabled: true,
674
+ route: defaultRoute,
675
+ schemaRoute: `${defaultRoute}/schema`
676
+ };
677
+ const agentBlock = extractObjectLiteral(feedbackBlock, "agent");
678
+ if (!agentBlock) continue;
679
+ const enabledMatch = agentBlock.match(/enabled\s*:\s*(true|false)/);
680
+ const routeMatch = agentBlock.match(/route\s*:\s*["']([^"']+)["']/);
681
+ const schemaRouteMatch = agentBlock.match(/schemaRoute\s*:\s*["']([^"']+)["']/);
682
+ const route = normalizeAgentFeedbackRoute(routeMatch?.[1], defaultRoute);
683
+ return {
684
+ enabled: enabledMatch ? enabledMatch[1] !== "false" : true,
685
+ route,
686
+ schemaRoute: normalizeAgentFeedbackRoute(schemaRouteMatch?.[1], `${route}/schema`)
687
+ };
688
+ } catch {
689
+ return disabled;
690
+ }
691
+ }
692
+ return disabled;
693
+ }
651
694
  function buildDocsMarkdownRewrites(entry) {
652
695
  const normalizedEntry = entry.replace(/^\/+|\/+$/g, "") || "docs";
653
696
  return [{
@@ -658,6 +701,16 @@ function buildDocsMarkdownRewrites(entry) {
658
701
  destination: "/api/docs?format=markdown&path=:slug*"
659
702
  }];
660
703
  }
704
+ function buildAgentFeedbackRewrites(config) {
705
+ if (!config.enabled) return [];
706
+ return [{
707
+ source: config.route,
708
+ destination: "/api/docs?feedback=agent"
709
+ }, {
710
+ source: config.schemaRoute,
711
+ destination: "/api/docs?feedback=agent&schema=1"
712
+ }];
713
+ }
661
714
  function dedupeRewrites(rewrites) {
662
715
  const seen = /* @__PURE__ */ new Set();
663
716
  const result = [];
@@ -669,12 +722,12 @@ function dedupeRewrites(rewrites) {
669
722
  }
670
723
  return result;
671
724
  }
672
- function mergeDocsMarkdownRewrites(entry, result) {
673
- const docsMarkdownRewrites = buildDocsMarkdownRewrites(entry);
674
- if (!result) return [...docsMarkdownRewrites];
675
- if (Array.isArray(result)) return dedupeRewrites([...docsMarkdownRewrites, ...result]);
725
+ function mergeDocsMarkdownRewrites(entry, agentFeedback, result) {
726
+ const autoRewrites = [...buildDocsMarkdownRewrites(entry), ...buildAgentFeedbackRewrites(agentFeedback)];
727
+ if (!result) return [...autoRewrites];
728
+ if (Array.isArray(result)) return dedupeRewrites([...autoRewrites, ...result]);
676
729
  return {
677
- beforeFiles: dedupeRewrites([...docsMarkdownRewrites, ...result.beforeFiles ?? []]),
730
+ beforeFiles: dedupeRewrites([...autoRewrites, ...result.beforeFiles ?? []]),
678
731
  afterFiles: result.afterFiles ?? [],
679
732
  fallback: result.fallback ?? []
680
733
  };
@@ -684,6 +737,7 @@ function withDocs(nextConfig = {}) {
684
737
  const workspaceRoot = findDocsWorkspaceRoot(root);
685
738
  const docsConfigPath = readDocsConfigPath(root);
686
739
  const docsConfigAbsolutePath = join(root, docsConfigPath);
740
+ const agentFeedback = readAgentFeedbackConfig(root);
687
741
  const docsConfigRelativeAlias = docsConfigPath.startsWith("./") || docsConfigPath.startsWith("../") ? docsConfigPath : `./${docsConfigPath}`;
688
742
  if (!hasFile(root, "mdx-components")) writeFileSync(join(root, "mdx-components.tsx"), MDX_COMPONENTS_TEMPLATE);
689
743
  const entry = readDocsEntry(root);
@@ -853,7 +907,7 @@ function withDocs(nextConfig = {}) {
853
907
  if (!isStaticExport) {
854
908
  const existingRewrites = nextConfig.rewrites;
855
909
  nextConfig.rewrites = async () => {
856
- return mergeDocsMarkdownRewrites(entry, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
910
+ return mergeDocsMarkdownRewrites(entry, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
857
911
  };
858
912
  }
859
913
  nextConfig.outputFileTracingIncludes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/next",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
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.20",
99
- "@farming-labs/theme": "0.1.20"
98
+ "@farming-labs/docs": "0.1.22",
99
+ "@farming-labs/theme": "0.1.22"
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@farming-labs/docs": ">=0.0.1",