@farming-labs/theme 0.2.84 → 0.2.87

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 +132 -117
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -4,7 +4,7 @@ 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, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsContentChangeFeed, createDocsContentChangesHttpResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsContentChangesRequest, isDocsDiagnosticsRequest, 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 } 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, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCacheableResponse, createDocsContentChangeFeed, createDocsContentChangesHttpResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsContentChangesRequest, isDocsDiagnosticsRequest, 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 } from "@farming-labs/docs";
8
8
  import { buildApiReferenceOpenApiDocumentAsync, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceOpenApiDiscovery, resolveConfiguredAgentSkills, resolveDocsMcpConfig } from "@farming-labs/docs/server";
9
9
 
10
10
  //#region src/docs-api.ts
@@ -1441,25 +1441,36 @@ function renderAgentsDocument({ origin, entry, apiRoute, apiCatalog, search, con
1441
1441
  lines.push("", "## Framework Maintenance", "- For @farming-labs/docs projects, keep the framework package current before debugging missing agent surfaces.", "", "```sh", "npx @farming-labs/docs@latest upgrade --latest", "```", "", "- For framework setup, configuration, CLI, Ask AI, page actions, or theme work, install the reusable Skills pack:", "", "```sh", "npx skills add farming-labs/docs", "```");
1442
1442
  return lines.join("\n");
1443
1443
  }
1444
- function readRootSkillDocument(rootDir) {
1445
- const candidate = path.join(rootDir, "skill.md");
1446
- try {
1447
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return fs.readFileSync(candidate, "utf-8");
1448
- } catch {
1449
- return null;
1450
- }
1451
- return null;
1452
- }
1453
- function readRootAgentsDocument(rootDir) {
1454
- for (const fileName of ["AGENTS.md", "AGENT.md"]) {
1455
- const candidate = path.join(rootDir, fileName);
1456
- try {
1457
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return fs.readFileSync(candidate, "utf-8");
1458
- } catch {
1459
- continue;
1444
+ function createRootDocumentReader(rootDir, fileNames) {
1445
+ let cached;
1446
+ return function readRootDocument() {
1447
+ for (const fileName of fileNames) {
1448
+ const candidate = path.join(rootDir, fileName);
1449
+ try {
1450
+ const stats = fs.statSync(candidate);
1451
+ if (!stats.isFile()) continue;
1452
+ const signature = [
1453
+ stats.dev,
1454
+ stats.ino,
1455
+ stats.size,
1456
+ stats.mtimeMs,
1457
+ stats.ctimeMs
1458
+ ].join(":");
1459
+ if (cached?.path === candidate && cached.signature === signature) return cached.content;
1460
+ const content = fs.readFileSync(candidate, "utf-8");
1461
+ cached = {
1462
+ path: candidate,
1463
+ signature,
1464
+ content
1465
+ };
1466
+ return content;
1467
+ } catch {
1468
+ continue;
1469
+ }
1460
1470
  }
1461
- }
1462
- return null;
1471
+ cached = void 0;
1472
+ return null;
1473
+ };
1463
1474
  }
1464
1475
  function compactSkillText(value) {
1465
1476
  return value.replace(/\s+/g, " ").trim();
@@ -2534,6 +2545,8 @@ function generateLlmsTxt(indexes, options) {
2534
2545
  */
2535
2546
  function createDocsAPI(options) {
2536
2547
  const root = options?.rootDir ?? process.cwd();
2548
+ const readRootSkillDocument = createRootDocumentReader(root, ["skill.md"]);
2549
+ const readRootAgentsDocument = createRootDocumentReader(root, ["AGENTS.md", "AGENT.md"]);
2537
2550
  let publishedAgentSkills;
2538
2551
  function getPublishedAgentSkills() {
2539
2552
  if (!publishedAgentSkills) publishedAgentSkills = Array.isArray(options?._preloadedAgentSkills) ? Promise.resolve([...options._preloadedAgentSkills]) : resolveConfiguredAgentSkills(options?.agent?.skills, { rootDir: root });
@@ -2711,6 +2724,8 @@ function createDocsAPI(options) {
2711
2724
  }
2712
2725
  const indexesByLocale = /* @__PURE__ */ new Map();
2713
2726
  const llmsCache = new BoundedRouteCache(MAX_LLMS_CACHE_ROUTES_PER_LOCALE);
2727
+ const generatedAgentsCache = new BoundedRouteCache(MAX_LLMS_CACHE_ROUTES_PER_LOCALE);
2728
+ const generatedSkillCache = new BoundedRouteCache(MAX_LLMS_CACHE_ROUTES_PER_LOCALE);
2714
2729
  const markdownSourcesByLocale = /* @__PURE__ */ new Map();
2715
2730
  function getIndexes(ctx) {
2716
2731
  const key = ctx.locale ?? "__default__";
@@ -2799,14 +2814,33 @@ function createDocsAPI(options) {
2799
2814
  llmsCache.set(ctx.locale, apiRoute, next);
2800
2815
  return next;
2801
2816
  }
2802
- async function resolveStandardsResponse(request, url) {
2803
- const apiRoute = resolveDocsRequestApiRoute(url, configuredApiRouteInput);
2804
- const resolved = resolveDocsStandardsDiscoveryRequest(url, { apiRoute });
2805
- if (!resolved) return null;
2806
- const method = request.method.toUpperCase();
2807
- const needsSkill = (method === "GET" || method === "HEAD") && resolved.kind !== "api-catalog";
2808
- const fallbackSkillDocument = needsSkill ? renderSkillDocument({
2809
- origin: url.origin,
2817
+ function getGeneratedAgentsDocument(origin, apiRoute) {
2818
+ const cacheKey = `${origin}\0${apiRoute}`;
2819
+ const cached = generatedAgentsCache.get(void 0, cacheKey);
2820
+ if (cached) return cached;
2821
+ const next = renderAgentsDocument({
2822
+ origin,
2823
+ entry,
2824
+ apiRoute,
2825
+ apiCatalog: apiCatalogEnabled,
2826
+ search: searchConfig,
2827
+ contentChanges: contentChangesConfig.enabled,
2828
+ mcp: mcpConfig,
2829
+ feedback: agentFeedbackConfig,
2830
+ llms: llmsConfig,
2831
+ sitemap: sitemapConfig,
2832
+ robots: robotsConfig,
2833
+ openapi: openapiDiscovery
2834
+ });
2835
+ generatedAgentsCache.set(void 0, cacheKey, next);
2836
+ return next;
2837
+ }
2838
+ function getGeneratedSkillDocument(origin, apiRoute) {
2839
+ const cacheKey = `${origin}\0${apiRoute}`;
2840
+ const cached = generatedSkillCache.get(void 0, cacheKey);
2841
+ if (cached) return cached;
2842
+ const next = renderSkillDocument({
2843
+ origin,
2810
2844
  entry,
2811
2845
  apiRoute,
2812
2846
  apiCatalog: apiCatalogEnabled,
@@ -2819,10 +2853,20 @@ function createDocsAPI(options) {
2819
2853
  sitemap: sitemapConfig,
2820
2854
  robots: robotsConfig,
2821
2855
  openapi: openapiDiscovery
2822
- }) : "";
2856
+ });
2857
+ generatedSkillCache.set(void 0, cacheKey, next);
2858
+ return next;
2859
+ }
2860
+ async function resolveStandardsResponse(request, url) {
2861
+ const apiRoute = resolveDocsRequestApiRoute(url, configuredApiRouteInput);
2862
+ const resolved = resolveDocsStandardsDiscoveryRequest(url, { apiRoute });
2863
+ if (!resolved) return null;
2864
+ const method = request.method.toUpperCase();
2865
+ const needsSkill = (method === "GET" || method === "HEAD") && resolved.kind !== "api-catalog";
2866
+ const fallbackSkillDocument = needsSkill ? getGeneratedSkillDocument(url.origin, apiRoute) : "";
2823
2867
  return createDocsStandardsDiscoveryResponse({
2824
2868
  request,
2825
- preferredSkillDocument: needsSkill ? readRootSkillDocument(root) : null,
2869
+ preferredSkillDocument: needsSkill ? readRootSkillDocument() : null,
2826
2870
  fallbackSkillDocument,
2827
2871
  publishedSkills: needsSkill ? await getPublishedAgentSkills() : [],
2828
2872
  agentCard: options?.agent?.a2a,
@@ -2886,50 +2930,35 @@ function createDocsAPI(options) {
2886
2930
  method: requestMethod
2887
2931
  }
2888
2932
  });
2889
- if (isHeadRequest) return new Response(null, { headers: {
2890
- "Content-Type": "application/json",
2891
- "Cache-Control": "public, max-age=0, s-maxage=3600",
2892
- Link: agentManifestLinkHeader,
2893
- "X-Robots-Tag": "noindex"
2894
- } });
2895
- return Response.json(buildAgentSpec({
2896
- origin: url.origin,
2897
- entry,
2898
- apiRoute: requestApiRoute,
2899
- apiCatalog: apiCatalogEnabled,
2900
- i18n,
2901
- search: searchConfig,
2902
- contentChanges: contentChangesConfig.enabled,
2903
- mcp: mcpConfig,
2904
- feedback: agentFeedbackConfig,
2905
- llms: llmsConfig,
2906
- sitemap: sitemapConfig,
2907
- robots: robotsConfig,
2908
- openapi: openapiDiscovery,
2909
- publishedSkills: [await resolveDocsPublishedAgentSkill({
2910
- preferredDocument: readRootSkillDocument(root),
2911
- fallbackDocument: renderSkillDocument({
2912
- origin: url.origin,
2913
- entry,
2914
- apiRoute: requestApiRoute,
2915
- apiCatalog: apiCatalogEnabled,
2916
- i18n,
2917
- search: searchConfig,
2918
- contentChanges: contentChangesConfig.enabled,
2919
- mcp: mcpConfig,
2920
- feedback: agentFeedbackConfig,
2921
- llms: llmsConfig,
2922
- sitemap: sitemapConfig,
2923
- robots: robotsConfig,
2924
- openapi: openapiDiscovery
2925
- })
2926
- }), ...await getPublishedAgentSkills()],
2927
- agentCard: options?.agent?.a2a
2928
- }), { headers: {
2929
- "Cache-Control": "public, max-age=0, s-maxage=3600",
2930
- Link: agentManifestLinkHeader,
2931
- "X-Robots-Tag": "noindex"
2932
- } });
2933
+ return createDocsCacheableResponse({
2934
+ request,
2935
+ content: `${JSON.stringify(buildAgentSpec({
2936
+ origin: url.origin,
2937
+ entry,
2938
+ apiRoute: requestApiRoute,
2939
+ apiCatalog: apiCatalogEnabled,
2940
+ i18n,
2941
+ search: searchConfig,
2942
+ contentChanges: contentChangesConfig.enabled,
2943
+ mcp: mcpConfig,
2944
+ feedback: agentFeedbackConfig,
2945
+ llms: llmsConfig,
2946
+ sitemap: sitemapConfig,
2947
+ robots: robotsConfig,
2948
+ openapi: openapiDiscovery,
2949
+ publishedSkills: [await resolveDocsPublishedAgentSkill({
2950
+ preferredDocument: readRootSkillDocument(),
2951
+ fallbackDocument: getGeneratedSkillDocument(url.origin, requestApiRoute)
2952
+ }), ...await getPublishedAgentSkills()],
2953
+ agentCard: options?.agent?.a2a
2954
+ }), null, 2)}\n`,
2955
+ headers: {
2956
+ "Content-Type": "application/json; charset=utf-8",
2957
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
2958
+ Link: agentManifestLinkHeader,
2959
+ "X-Robots-Tag": "noindex"
2960
+ }
2961
+ });
2933
2962
  }
2934
2963
  if (isDocsContentChangesRequest(url)) {
2935
2964
  if (!contentChangesConfig.enabled) return new Response("Not Found", {
@@ -3007,25 +3036,16 @@ function createDocsAPI(options) {
3007
3036
  method: requestMethod
3008
3037
  }
3009
3038
  });
3010
- return new Response(isHeadRequest ? null : readRootAgentsDocument(root) ?? renderAgentsDocument({
3011
- origin: url.origin,
3012
- entry,
3013
- apiRoute: requestApiRoute,
3014
- apiCatalog: apiCatalogEnabled,
3015
- search: searchConfig,
3016
- contentChanges: contentChangesConfig.enabled,
3017
- mcp: mcpConfig,
3018
- feedback: agentFeedbackConfig,
3019
- llms: llmsConfig,
3020
- sitemap: sitemapConfig,
3021
- robots: robotsConfig,
3022
- openapi: openapiDiscovery
3023
- }), { headers: {
3024
- "Content-Type": "text/markdown; charset=utf-8",
3025
- "Cache-Control": "public, max-age=0, s-maxage=3600",
3026
- Link: discoveryLinkHeader,
3027
- "X-Robots-Tag": "noindex"
3028
- } });
3039
+ return createDocsCacheableResponse({
3040
+ request,
3041
+ content: readRootAgentsDocument() ?? getGeneratedAgentsDocument(url.origin, requestApiRoute),
3042
+ headers: {
3043
+ "Content-Type": "text/markdown; charset=utf-8",
3044
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
3045
+ Link: discoveryLinkHeader,
3046
+ "X-Robots-Tag": "noindex"
3047
+ }
3048
+ });
3029
3049
  }
3030
3050
  if (resolveSkillRequest(url)) {
3031
3051
  await emitDocsAnalyticsEvent(analytics, {
@@ -3039,26 +3059,16 @@ function createDocsAPI(options) {
3039
3059
  method: requestMethod
3040
3060
  }
3041
3061
  });
3042
- return new Response(isHeadRequest ? null : readRootSkillDocument(root) ?? renderSkillDocument({
3043
- origin: url.origin,
3044
- entry,
3045
- apiRoute: requestApiRoute,
3046
- apiCatalog: apiCatalogEnabled,
3047
- i18n,
3048
- search: searchConfig,
3049
- contentChanges: contentChangesConfig.enabled,
3050
- mcp: mcpConfig,
3051
- feedback: agentFeedbackConfig,
3052
- llms: llmsConfig,
3053
- sitemap: sitemapConfig,
3054
- robots: robotsConfig,
3055
- openapi: openapiDiscovery
3056
- }), { headers: {
3057
- "Content-Type": "text/markdown; charset=utf-8",
3058
- "Cache-Control": "public, max-age=0, s-maxage=3600",
3059
- Link: discoveryLinkHeader,
3060
- "X-Robots-Tag": "noindex"
3061
- } });
3062
+ return createDocsCacheableResponse({
3063
+ request,
3064
+ content: readRootSkillDocument() ?? getGeneratedSkillDocument(url.origin, requestApiRoute),
3065
+ headers: {
3066
+ "Content-Type": "text/markdown; charset=utf-8",
3067
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
3068
+ Link: discoveryLinkHeader,
3069
+ "X-Robots-Tag": "noindex"
3070
+ }
3071
+ });
3062
3072
  }
3063
3073
  const robotsResponse = createDocsRobotsResponse({
3064
3074
  agentCard: Boolean(options?.agent?.a2a),
@@ -3212,10 +3222,14 @@ function createDocsAPI(options) {
3212
3222
  contentLength: selected.content.length
3213
3223
  }
3214
3224
  });
3215
- return new Response(selected.content, { headers: {
3216
- "Content-Type": "text/plain; charset=utf-8",
3217
- "Cache-Control": "public, max-age=3600"
3218
- } });
3225
+ return createDocsCacheableResponse({
3226
+ request,
3227
+ content: selected.content,
3228
+ headers: {
3229
+ "Content-Type": "text/plain; charset=utf-8",
3230
+ "Cache-Control": "public, max-age=3600"
3231
+ }
3232
+ });
3219
3233
  }
3220
3234
  const query = url.searchParams.get("query")?.trim();
3221
3235
  const audience = resolveDocsSearchAudience(url.searchParams.get("audience"));
@@ -3402,6 +3416,7 @@ function createDocsAPI(options) {
3402
3416
  */
3403
3417
  function createDocsMCPAPI(options = {}) {
3404
3418
  const rootDir = options.rootDir ?? process.cwd();
3419
+ const readRootSkillDocument = createRootDocumentReader(rootDir, ["skill.md"]);
3405
3420
  const entry = options.entry ?? readEntry(rootDir);
3406
3421
  const appDir = getNextAppDir(rootDir);
3407
3422
  const contentDir = options.contentDir ?? path.join(appDir, entry);
@@ -3426,7 +3441,7 @@ function createDocsMCPAPI(options = {}) {
3426
3441
  async getSkills() {
3427
3442
  const configured = await getConfiguredAgentSkills();
3428
3443
  return [await resolveDocsPublishedAgentSkill({
3429
- preferredDocument: readRootSkillDocument(rootDir),
3444
+ preferredDocument: readRootSkillDocument(),
3430
3445
  fallbackDocument: `---\nname: docs\ndescription: Use the project documentation through MCP resources and tools.\n---\n\n# Documentation\n`
3431
3446
  }), ...configured];
3432
3447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.84",
3
+ "version": "0.2.87",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -148,7 +148,7 @@
148
148
  "tsdown": "^0.20.3",
149
149
  "typescript": "^5.9.3",
150
150
  "vitest": "^4.1.8",
151
- "@farming-labs/docs": "0.2.84"
151
+ "@farming-labs/docs": "0.2.87"
152
152
  },
153
153
  "peerDependencies": {
154
154
  "@farming-labs/docs": ">=0.0.1",