@farming-labs/theme 0.2.71 → 0.2.72
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.
- package/dist/docs-api.mjs +48 -9
- 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_MARKDOWN_SECTION_INDEX_FORMAT, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, 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";
|
|
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_MARKDOWN_SECTION_INDEX_FORMAT, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsDiagnosticsRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, performDocsSearch, performDocsSearchWithMetadata, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, resolveDocsSearchAudience, resolveDocsSearchFilters, 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
|
|
@@ -405,10 +405,27 @@ function buildAgentSpec({ origin, entry, apiRoute, apiCatalog, i18n, search, mcp
|
|
|
405
405
|
enabled: searchEnabled,
|
|
406
406
|
endpoint: `${apiRoute}?query={query}`,
|
|
407
407
|
agentEndpoint: `${apiRoute}?query={query}&audience=agent`,
|
|
408
|
+
structuredAgentEndpoint: `${apiRoute}?query={query}&audience=agent&response=structured`,
|
|
408
409
|
method: "GET",
|
|
409
410
|
queryParam: "query",
|
|
410
411
|
localeParam: "lang",
|
|
411
412
|
audienceParam: "audience",
|
|
413
|
+
responseParam: "response",
|
|
414
|
+
structuredResponseValue: "structured",
|
|
415
|
+
responseFormat: "docs-search.v1",
|
|
416
|
+
filterParams: {
|
|
417
|
+
framework: "framework",
|
|
418
|
+
version: "version",
|
|
419
|
+
package: "package",
|
|
420
|
+
tags: "tags"
|
|
421
|
+
},
|
|
422
|
+
repeatedFilterParams: [
|
|
423
|
+
"framework",
|
|
424
|
+
"version",
|
|
425
|
+
"package",
|
|
426
|
+
"tags"
|
|
427
|
+
],
|
|
428
|
+
warningsField: "warnings",
|
|
412
429
|
defaultAudience: "human",
|
|
413
430
|
supportedAudiences: ["human", "agent"]
|
|
414
431
|
},
|
|
@@ -978,6 +995,9 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
|
|
|
978
995
|
if (resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden" && hasVisibleDescendantDocsSearchPage(dir)) {} else {
|
|
979
996
|
const title = data.title || slugParts[slugParts.length - 1]?.replace(/-/g, " ") || "Documentation";
|
|
980
997
|
const description = data.description;
|
|
998
|
+
const framework = typeof data.framework === "string" ? data.framework : void 0;
|
|
999
|
+
const version = typeof data.version === "string" ? data.version : void 0;
|
|
1000
|
+
const tags = Array.isArray(data.tags) ? data.tags.filter((value) => typeof value === "string") : void 0;
|
|
981
1001
|
const { content: fileContent } = matter(raw);
|
|
982
1002
|
const rawContent = resolveDocsAudienceMdxContent(fileContent, "human");
|
|
983
1003
|
const agentRawContent = resolveDocsAudienceMdxContent(fileContent, "agent");
|
|
@@ -996,6 +1016,9 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
|
|
|
996
1016
|
sourcePath: pageSource.replace(/\\/g, "/"),
|
|
997
1017
|
lastModified: fs.statSync(pageSource).mtime.toISOString(),
|
|
998
1018
|
locale,
|
|
1019
|
+
framework,
|
|
1020
|
+
version,
|
|
1021
|
+
tags,
|
|
999
1022
|
...agentDoc
|
|
1000
1023
|
});
|
|
1001
1024
|
}
|
|
@@ -1293,7 +1316,7 @@ function renderSkillDocument({ origin, entry, apiRoute, apiCatalog, search, mcp,
|
|
|
1293
1316
|
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}.`);
|
|
1294
1317
|
if (apiCatalog) lines.push(`- Fetch ${DEFAULT_API_CATALOG_ROUTE} for the standards-based API catalog.`);
|
|
1295
1318
|
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.`, `- Fetch /${normalizedEntry}/{slug}.md?sections to list section IDs and size estimates before requesting ?section={id}.`, "- You can also request text/markdown from normal page URLs.");
|
|
1296
|
-
if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent when you do not know the page.`);
|
|
1319
|
+
if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent&response=structured when you do not know the page; add framework, version, package, or repeated tags filters when scope matters.`);
|
|
1297
1320
|
if (openapi.enabled && openapiUrl) lines.push(`- Fetch ${openapiUrl} for the machine-readable OpenAPI schema before scraping API reference pages.`);
|
|
1298
1321
|
if (llms.enabled) {
|
|
1299
1322
|
lines.push(`- Use ${DEFAULT_LLMS_TXT_ROUTE} for a compact docs index.`, `- Use ${DEFAULT_LLMS_FULL_TXT_ROUTE} for full markdown context.`);
|
|
@@ -1358,7 +1381,7 @@ function renderAgentsDocument({ origin, entry, apiRoute, apiCatalog, search, mcp
|
|
|
1358
1381
|
if (sitemapConfig.xml.enabled) lines.push(`- Use ${sitemapConfig.xml.route} for canonical URLs and freshness metadata.`);
|
|
1359
1382
|
}
|
|
1360
1383
|
if (robotsEnabled) lines.push(`- Check ${DEFAULT_ROBOTS_TXT_ROUTE} before crawling broadly.`);
|
|
1361
|
-
if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent when the route is unknown.`);
|
|
1384
|
+
if (searchEnabled) lines.push(`- Search with ${apiRoute}?query={query}&audience=agent&response=structured when the route is unknown; add framework, version, package, or repeated tags filters when scope matters.`);
|
|
1362
1385
|
if (openapi.enabled && openapiUrl) lines.push(`- Fetch ${openapiUrl} before scraping API reference pages; prefer schemas over prose.`);
|
|
1363
1386
|
if (mcp.enabled) lines.push(`- Use MCP at ${DEFAULT_MCP_PUBLIC_ROUTE} or ${DEFAULT_MCP_WELL_KNOWN_ROUTE} when your environment supports MCP tools.`);
|
|
1364
1387
|
if (feedback.enabled) lines.push(`- Read ${feedback.schemaRoute} before posting feedback to ${feedback.route}.`);
|
|
@@ -3131,19 +3154,35 @@ function createDocsAPI(options) {
|
|
|
3131
3154
|
} });
|
|
3132
3155
|
}
|
|
3133
3156
|
const query = url.searchParams.get("query")?.trim();
|
|
3134
|
-
if (!query) return new Response(JSON.stringify([]), { headers: { "Content-Type": "application/json" } });
|
|
3135
|
-
const searchStartedAt = Date.now();
|
|
3136
3157
|
const audience = resolveDocsSearchAudience(url.searchParams.get("audience"));
|
|
3137
|
-
const
|
|
3158
|
+
const filters = resolveDocsSearchFilters(url.searchParams);
|
|
3159
|
+
const structured = url.searchParams.get("response") === "structured";
|
|
3160
|
+
if (!query) {
|
|
3161
|
+
const searchResponse = structured ? {
|
|
3162
|
+
format: "docs-search.v1",
|
|
3163
|
+
query: "",
|
|
3164
|
+
audience,
|
|
3165
|
+
filters,
|
|
3166
|
+
resultCount: 0,
|
|
3167
|
+
results: [],
|
|
3168
|
+
warnings: []
|
|
3169
|
+
} : [];
|
|
3170
|
+
return new Response(JSON.stringify(searchResponse), { headers: { "Content-Type": "application/json" } });
|
|
3171
|
+
}
|
|
3172
|
+
const searchStartedAt = Date.now();
|
|
3173
|
+
const searchOptions = {
|
|
3138
3174
|
pages: getIndexes(ctx),
|
|
3139
3175
|
query,
|
|
3140
3176
|
search: resolveSearchRequestConfig(searchConfig, request.url),
|
|
3141
3177
|
audience,
|
|
3178
|
+
filters,
|
|
3142
3179
|
locale: ctx.locale,
|
|
3143
3180
|
pathname: url.searchParams.get("pathname") ?? void 0,
|
|
3144
3181
|
siteTitle: llmsConfig.siteTitle ?? "Documentation",
|
|
3145
3182
|
baseUrl: markdownMetadataBaseUrl || url.origin
|
|
3146
|
-
}
|
|
3183
|
+
};
|
|
3184
|
+
const searchResponse = structured ? await performDocsSearchWithMetadata(searchOptions) : await performDocsSearch(searchOptions);
|
|
3185
|
+
const resultCount = Array.isArray(searchResponse) ? searchResponse.length : searchResponse.resultCount;
|
|
3147
3186
|
await emitDocsAnalyticsEvent(analytics, {
|
|
3148
3187
|
type: "api_search",
|
|
3149
3188
|
source: "server",
|
|
@@ -3155,12 +3194,12 @@ function createDocsAPI(options) {
|
|
|
3155
3194
|
...requestAnalyticsProperties,
|
|
3156
3195
|
queryLength: query.length,
|
|
3157
3196
|
audience,
|
|
3158
|
-
resultCount
|
|
3197
|
+
resultCount,
|
|
3159
3198
|
pathname: url.searchParams.get("pathname") ?? void 0,
|
|
3160
3199
|
durationMs: Math.max(0, Date.now() - searchStartedAt)
|
|
3161
3200
|
}
|
|
3162
3201
|
});
|
|
3163
|
-
return new Response(JSON.stringify(
|
|
3202
|
+
return new Response(JSON.stringify(searchResponse), { headers: { "Content-Type": "application/json" } });
|
|
3164
3203
|
},
|
|
3165
3204
|
async POST(request) {
|
|
3166
3205
|
trackTelemetryRequest(request);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.72",
|
|
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.
|
|
151
|
+
"@farming-labs/docs": "0.2.72"
|
|
152
152
|
},
|
|
153
153
|
"peerDependencies": {
|
|
154
154
|
"@farming-labs/docs": ">=0.0.1",
|