@farming-labs/theme 0.2.61 → 0.2.63

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.
@@ -1,4 +1,4 @@
1
- import { ChangelogConfig, DocsAnalyticsConfig, DocsAskAIMcpConfig, DocsConfig, DocsI18nConfig, DocsMcpConfig, DocsObservabilityConfig, DocsRobotsConfig, DocsSearchConfig, DocsSitemapConfig, DocsTelemetryConfig, FeedbackConfig, LlmsTxtConfig, OrderingItem } from "@farming-labs/docs";
1
+ import { ChangelogConfig, DocsAnalyticsConfig, DocsAskAIMcpConfig, DocsConfig, DocsI18nConfig, DocsMcpConfig, DocsObservabilityConfig, DocsPublishedAgentSkill, DocsRobotsConfig, DocsSearchConfig, DocsSitemapConfig, DocsTelemetryConfig, FeedbackConfig, LlmsTxtConfig, OrderingItem } from "@farming-labs/docs";
2
2
 
3
3
  //#region src/docs-api.d.ts
4
4
  interface AIProviderConfig {
@@ -80,6 +80,8 @@ interface DocsAPIOptions {
80
80
  metadata?: DocsConfig["metadata"];
81
81
  /** Reusable skill publication and optional real A2A service metadata. */
82
82
  agent?: DocsConfig["agent"];
83
+ /** @internal Build-time Agent Skills snapshot supplied by framework adapters. */
84
+ _preloadedAgentSkills?: readonly DocsPublishedAgentSkill[];
83
85
  }
84
86
  interface DocsMCPAPIOptions {
85
87
  rootDir?: string;
@@ -95,6 +97,8 @@ interface DocsMCPAPIOptions {
95
97
  telemetry?: boolean | DocsTelemetryConfig;
96
98
  observability?: boolean | DocsObservabilityConfig;
97
99
  agent?: DocsConfig["agent"];
100
+ /** @internal Build-time Agent Skills snapshot supplied by framework adapters. */
101
+ _preloadedAgentSkills?: readonly DocsPublishedAgentSkill[];
98
102
  }
99
103
  type LlmsTxtOptions = LlmsTxtConfig;
100
104
  /**
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, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsDiagnosticsRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, 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, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsDiagnosticsRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, performDocsSearch, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, resolveDocsSearchAudience, resolveDocsSitemapConfig, resolveDocsStandardsDiscoveryRequest, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent, stripGeneratedAgentProvenance } from "@farming-labs/docs";
8
8
  import { buildApiReferenceOpenApiDocumentAsync, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveConfiguredAgentSkills, resolveDocsMcpConfig } from "@farming-labs/docs/server";
9
9
 
10
10
  //#region src/docs-api.ts
@@ -393,9 +393,13 @@ function buildAgentSpec({ origin, entry, apiRoute, apiCatalog, i18n, search, mcp
393
393
  search: {
394
394
  enabled: searchEnabled,
395
395
  endpoint: `${apiRoute}?query={query}`,
396
+ agentEndpoint: `${apiRoute}?query={query}&audience=agent`,
396
397
  method: "GET",
397
398
  queryParam: "query",
398
- localeParam: "lang"
399
+ localeParam: "lang",
400
+ audienceParam: "audience",
401
+ defaultAudience: "human",
402
+ supportedAudiences: ["human", "agent"]
399
403
  },
400
404
  agents: {
401
405
  enabled: true,
@@ -1278,7 +1282,7 @@ function renderSkillDocument({ origin, entry, apiRoute, apiCatalog, search, mcp,
1278
1282
  lines.push("", "## When To Use", "Use this skill when you need to read or implement against this documentation site.", "", "## Start Here", `- Fetch ${DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE}; fall back to ${DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE} or ${agentSpecRoute}.`);
1279
1283
  if (apiCatalog) lines.push(`- Fetch ${DEFAULT_API_CATALOG_ROUTE} for the standards-based API catalog.`);
1280
1284
  lines.push(`- Fetch ${DEFAULT_AGENT_SKILLS_INDEX_ROUTE} to discover the published site skill and verify its SHA-256 digest.`, `- Fetch /${normalizedEntry}.md for the root docs page.`, `- Fetch /${normalizedEntry}/{slug}.md for page-specific context.`, "- You can also request text/markdown from normal page URLs.");
1281
- if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query} when you do not know the page.`);
1285
+ if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent when you do not know the page.`);
1282
1286
  if (openapi.enabled && openapiUrl) lines.push(`- Fetch ${openapiUrl} for the machine-readable OpenAPI schema before scraping API reference pages.`);
1283
1287
  if (llms.enabled) {
1284
1288
  lines.push(`- Use ${DEFAULT_LLMS_TXT_ROUTE} for a compact docs index.`, `- Use ${DEFAULT_LLMS_FULL_TXT_ROUTE} for full markdown context.`);
@@ -1343,7 +1347,7 @@ function renderAgentsDocument({ origin, entry, apiRoute, apiCatalog, search, mcp
1343
1347
  if (sitemapConfig.xml.enabled) lines.push(`- Use ${sitemapConfig.xml.route} for canonical URLs and freshness metadata.`);
1344
1348
  }
1345
1349
  if (robotsEnabled) lines.push(`- Check ${DEFAULT_ROBOTS_TXT_ROUTE} before crawling broadly.`);
1346
- if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query} when the route is unknown.`);
1350
+ if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent when the route is unknown.`);
1347
1351
  if (openapi.enabled && openapiUrl) lines.push(`- Fetch ${openapiUrl} before scraping API reference pages; prefer schemas over prose.`);
1348
1352
  if (mcp.enabled) lines.push(`- Use MCP at ${DEFAULT_MCP_PUBLIC_ROUTE} or ${DEFAULT_MCP_WELL_KNOWN_ROUTE} when your environment supports MCP tools.`);
1349
1353
  if (feedback.enabled) lines.push(`- Read ${feedback.schemaRoute} before posting feedback to ${feedback.route}.`);
@@ -2459,7 +2463,11 @@ function generateLlmsTxt(indexes, options) {
2459
2463
  */
2460
2464
  function createDocsAPI(options) {
2461
2465
  const root = options?.rootDir ?? process.cwd();
2462
- const publishedAgentSkills = resolveConfiguredAgentSkills(options?.agent?.skills, { rootDir: root });
2466
+ let publishedAgentSkills;
2467
+ function getPublishedAgentSkills() {
2468
+ if (!publishedAgentSkills) publishedAgentSkills = Array.isArray(options?._preloadedAgentSkills) ? Promise.resolve([...options._preloadedAgentSkills]) : resolveConfiguredAgentSkills(options?.agent?.skills, { rootDir: root });
2469
+ return publishedAgentSkills;
2470
+ }
2463
2471
  const entry = options?.entry ?? readEntry(root);
2464
2472
  const docsPath = normalizeDocsPublicPath(options?.docsPath ?? readDocsPath(root), entry);
2465
2473
  const analytics = options?.analytics;
@@ -2739,7 +2747,7 @@ function createDocsAPI(options) {
2739
2747
  request,
2740
2748
  preferredSkillDocument: needsSkill ? readRootSkillDocument(root) : null,
2741
2749
  fallbackSkillDocument,
2742
- publishedSkills: await publishedAgentSkills,
2750
+ publishedSkills: needsSkill ? await getPublishedAgentSkills() : [],
2743
2751
  agentCard: options?.agent?.a2a,
2744
2752
  origin: url.origin,
2745
2753
  entry,
@@ -2835,7 +2843,7 @@ function createDocsAPI(options) {
2835
2843
  robots: robotsConfig,
2836
2844
  openapi: openapiDiscovery
2837
2845
  })
2838
- }), ...await publishedAgentSkills],
2846
+ }), ...await getPublishedAgentSkills()],
2839
2847
  agentCard: options?.agent?.a2a
2840
2848
  }), { headers: {
2841
2849
  "Cache-Control": "public, max-age=0, s-maxage=3600",
@@ -3113,13 +3121,16 @@ function createDocsAPI(options) {
3113
3121
  const query = url.searchParams.get("query")?.trim();
3114
3122
  if (!query) return new Response(JSON.stringify([]), { headers: { "Content-Type": "application/json" } });
3115
3123
  const searchStartedAt = Date.now();
3124
+ const audience = resolveDocsSearchAudience(url.searchParams.get("audience"));
3116
3125
  const results = await performDocsSearch({
3117
3126
  pages: getIndexes(ctx),
3118
3127
  query,
3119
3128
  search: resolveSearchRequestConfig(searchConfig, request.url),
3129
+ audience,
3120
3130
  locale: ctx.locale,
3121
3131
  pathname: url.searchParams.get("pathname") ?? void 0,
3122
- siteTitle: llmsConfig.siteTitle ?? "Documentation"
3132
+ siteTitle: llmsConfig.siteTitle ?? "Documentation",
3133
+ baseUrl: markdownMetadataBaseUrl || url.origin
3123
3134
  });
3124
3135
  await emitDocsAnalyticsEvent(analytics, {
3125
3136
  type: "api_search",
@@ -3131,6 +3142,7 @@ function createDocsAPI(options) {
3131
3142
  properties: {
3132
3143
  ...requestAnalyticsProperties,
3133
3144
  queryLength: query.length,
3145
+ audience,
3134
3146
  resultCount: results.length,
3135
3147
  pathname: url.searchParams.get("pathname") ?? void 0,
3136
3148
  durationMs: Math.max(0, Date.now() - searchStartedAt)
@@ -3267,6 +3279,11 @@ function createDocsMCPAPI(options = {}) {
3267
3279
  const contentDir = options.contentDir ?? path.join(appDir, entry);
3268
3280
  const mcpConfig = options.mcp ?? readMcpConfig(rootDir, { rejectRuntimeSecurity: true });
3269
3281
  const navTitle = typeof options.nav?.title === "string" && options.nav.title.trim().length > 0 ? options.nav.title : "Documentation";
3282
+ let configuredAgentSkills;
3283
+ function getConfiguredAgentSkills() {
3284
+ if (!configuredAgentSkills) configuredAgentSkills = Array.isArray(options._preloadedAgentSkills) ? Promise.resolve([...options._preloadedAgentSkills]) : resolveConfiguredAgentSkills(options.agent?.skills, { rootDir });
3285
+ return configuredAgentSkills;
3286
+ }
3270
3287
  const handlers = createDocsMcpHttpHandler({
3271
3288
  source: {
3272
3289
  ...createFilesystemDocsMcpSource({
@@ -3277,7 +3294,7 @@ function createDocsMCPAPI(options = {}) {
3277
3294
  ordering: options.ordering
3278
3295
  }),
3279
3296
  async getSkills() {
3280
- const configured = await resolveConfiguredAgentSkills(options.agent?.skills, { rootDir });
3297
+ const configured = await getConfiguredAgentSkills();
3281
3298
  return [await resolveDocsPublishedAgentSkill({
3282
3299
  preferredDocument: readRootSkillDocument(rootDir),
3283
3300
  fallbackDocument: `---\nname: docs\ndescription: Use the project documentation through MCP resources and tools.\n---\n\n# Documentation\n`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.61",
3
+ "version": "0.2.63",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -146,7 +146,7 @@
146
146
  "tsdown": "^0.20.3",
147
147
  "typescript": "^5.9.3",
148
148
  "vitest": "^4.1.8",
149
- "@farming-labs/docs": "0.2.61"
149
+ "@farming-labs/docs": "0.2.63"
150
150
  },
151
151
  "peerDependencies": {
152
152
  "@farming-labs/docs": ">=0.0.1",