@farming-labs/svelte 0.2.63 → 0.2.65
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/README.md +2 -2
- package/dist/server.d.ts +2 -1
- package/dist/server.js +103 -59
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,13 +42,13 @@ const contentFiles = import.meta.glob("/docs/**/*.{md,mdx,svx}", {
|
|
|
42
42
|
eager: true,
|
|
43
43
|
}) as Record<string, string>;
|
|
44
44
|
|
|
45
|
-
export const { load, GET, POST, MCP } = createDocsServer({
|
|
45
|
+
export const { load, GET, HEAD, POST, MCP } = createDocsServer({
|
|
46
46
|
...config,
|
|
47
47
|
_preloadedContent: contentFiles,
|
|
48
48
|
});
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
Re-export `load` from the docs `+layout.server.ts` and `GET`/`POST` from the docs API route. Use
|
|
51
|
+
Re-export `load` from the docs `+layout.server.ts` and `GET`/`HEAD`/`POST` from the docs API route. Use
|
|
52
52
|
`DocsLayout` and `DocsContent` from `@farming-labs/svelte-theme` for presentation. The CLI
|
|
53
53
|
generates all of these files, including public agent and MCP forwarding.
|
|
54
54
|
|
package/dist/server.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* query: "?raw", import: "default", eager: true,
|
|
17
17
|
* }) as Record<string, string>;
|
|
18
18
|
*
|
|
19
|
-
* export const { load, GET, POST } = createDocsServer({
|
|
19
|
+
* export const { load, GET, HEAD, POST, MCP } = createDocsServer({
|
|
20
20
|
* ...config,
|
|
21
21
|
* _preloadedContent: contentFiles,
|
|
22
22
|
* });
|
|
@@ -58,6 +58,7 @@ export interface DocsServer {
|
|
|
58
58
|
structuredData: string;
|
|
59
59
|
}>;
|
|
60
60
|
GET: (event: RequestEvent) => Promise<Response>;
|
|
61
|
+
HEAD: (event: RequestEvent) => Promise<Response>;
|
|
61
62
|
POST: (event: RequestEvent) => Promise<Response>;
|
|
62
63
|
MCP: DocsMcpHttpHandlers;
|
|
63
64
|
}
|
package/dist/server.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* query: "?raw", import: "default", eager: true,
|
|
17
17
|
* }) as Record<string, string>;
|
|
18
18
|
*
|
|
19
|
-
* export const { load, GET, POST } = createDocsServer({
|
|
19
|
+
* export const { load, GET, HEAD, POST, MCP } = createDocsServer({
|
|
20
20
|
* ...config,
|
|
21
21
|
* _preloadedContent: contentFiles,
|
|
22
22
|
* });
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
import fs from "node:fs";
|
|
31
31
|
import path from "node:path";
|
|
32
32
|
import matter from "gray-matter";
|
|
33
|
-
import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, buildDocsConfigMap, buildDocsDiagnostics, createDocsStandardsDiscoveryResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, getDocsDiscoveryLinkHeader, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest,
|
|
33
|
+
import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, buildDocsConfigMap, buildDocsDiagnostics, createDocsStandardsDiscoveryResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, getDocsDiscoveryLinkHeader, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAudienceMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveDocsSearchAudience, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsRequestApiRoute, resolveDocsPublishedAgentSkill, resolveDocsStandardsDiscoveryRequest, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
34
34
|
import { buildApiReferenceOpenApiDocumentAsync, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, isDocsCloudAskAIProvider, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig, resolveConfiguredAgentSkills, serializeDocsIconRegistry, serializeOpenDocsProviders, } from "@farming-labs/docs/server";
|
|
35
35
|
import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
|
|
36
36
|
import { renderMarkdown } from "./markdown.js";
|
|
@@ -405,9 +405,13 @@ export function createDocsServer(config = {}) {
|
|
|
405
405
|
const observability = config.observability;
|
|
406
406
|
const contentDirBase = config.contentDir ?? entry;
|
|
407
407
|
const rootDir = path.resolve(config.rootDir ?? process.cwd());
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
408
|
+
let publishedAgentSkills;
|
|
409
|
+
function getPublishedAgentSkills() {
|
|
410
|
+
publishedAgentSkills ??= Array.isArray(config._preloadedAgentSkills)
|
|
411
|
+
? Promise.resolve(config._preloadedAgentSkills)
|
|
412
|
+
: resolveConfiguredAgentSkills(config.agent?.skills, { rootDir });
|
|
413
|
+
return publishedAgentSkills;
|
|
414
|
+
}
|
|
411
415
|
const i18n = resolveDocsI18n(config.i18n);
|
|
412
416
|
const githubRaw = config.github;
|
|
413
417
|
const github = typeof githubRaw === "string" ? { url: githubRaw } : (githubRaw ?? null);
|
|
@@ -713,10 +717,56 @@ export function createDocsServer(config = {}) {
|
|
|
713
717
|
}
|
|
714
718
|
: null;
|
|
715
719
|
}
|
|
720
|
+
function createDiscoveryOptions(origin, apiRoute) {
|
|
721
|
+
return {
|
|
722
|
+
origin,
|
|
723
|
+
entry,
|
|
724
|
+
apiRoute,
|
|
725
|
+
docsPath: config.docsPath,
|
|
726
|
+
apiCatalog: apiCatalogEnabled,
|
|
727
|
+
i18n,
|
|
728
|
+
search: config.search,
|
|
729
|
+
mcp: mcpConfig,
|
|
730
|
+
feedback: agentFeedbackDiscovery,
|
|
731
|
+
llms: {
|
|
732
|
+
enabled: llmsEnabled,
|
|
733
|
+
apiCatalog: apiCatalogEnabled,
|
|
734
|
+
baseUrl: llmsBaseUrl || undefined,
|
|
735
|
+
siteTitle: llmsTitle,
|
|
736
|
+
siteDescription: llmsDesc,
|
|
737
|
+
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
738
|
+
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
739
|
+
},
|
|
740
|
+
sitemap: config.sitemap,
|
|
741
|
+
robots: config.robots,
|
|
742
|
+
openapi: openapiDiscovery,
|
|
743
|
+
markdown: {
|
|
744
|
+
acceptHeader: true,
|
|
745
|
+
},
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
async function resolveStandardsResponse(request, url, discoveryOptions) {
|
|
749
|
+
const resolved = resolveDocsStandardsDiscoveryRequest(url, {
|
|
750
|
+
apiRoute: discoveryOptions.apiRoute,
|
|
751
|
+
});
|
|
752
|
+
if (!resolved)
|
|
753
|
+
return null;
|
|
754
|
+
const method = request.method.toUpperCase();
|
|
755
|
+
const needsSkill = (method === "GET" || method === "HEAD") && resolved.kind !== "api-catalog";
|
|
756
|
+
return createDocsStandardsDiscoveryResponse({
|
|
757
|
+
request,
|
|
758
|
+
...discoveryOptions,
|
|
759
|
+
preferredSkillDocument: needsSkill ? readRootSkillDocument(preloaded, rootDir) : null,
|
|
760
|
+
fallbackSkillDocument: needsSkill ? renderDocsSkillDocument(discoveryOptions) : "",
|
|
761
|
+
publishedSkills: needsSkill ? await getPublishedAgentSkills() : [],
|
|
762
|
+
agentCard: config.agent?.a2a,
|
|
763
|
+
});
|
|
764
|
+
}
|
|
716
765
|
// ─── GET /api/docs?query=… | ?format=llms | ?format=llms-full ──
|
|
717
766
|
async function GET(event) {
|
|
718
767
|
trackTelemetryRequest(event.request);
|
|
719
768
|
const ctx = resolveContextFromRequest(event.request);
|
|
769
|
+
const isHeadRequest = event.request.method.toUpperCase() === "HEAD";
|
|
720
770
|
const requestApiRoute = resolveDocsRequestApiRoute(event.url, configuredApiRoute);
|
|
721
771
|
if (isDocsConfigRequest(event.url)) {
|
|
722
772
|
return new Response(JSON.stringify(buildDocsConfigMap(config), null, 2), {
|
|
@@ -745,56 +795,24 @@ export function createDocsServer(config = {}) {
|
|
|
745
795
|
});
|
|
746
796
|
}
|
|
747
797
|
const discoveryApiRoute = requestApiRoute;
|
|
748
|
-
const discoveryOptions =
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
docsPath: config.docsPath,
|
|
753
|
-
apiCatalog: apiCatalogEnabled,
|
|
754
|
-
i18n,
|
|
755
|
-
search: config.search,
|
|
756
|
-
mcp: mcpConfig,
|
|
757
|
-
feedback: agentFeedbackDiscovery,
|
|
758
|
-
llms: {
|
|
759
|
-
enabled: llmsEnabled,
|
|
760
|
-
apiCatalog: apiCatalogEnabled,
|
|
761
|
-
baseUrl: llmsBaseUrl || undefined,
|
|
762
|
-
siteTitle: llmsTitle,
|
|
763
|
-
siteDescription: llmsDesc,
|
|
764
|
-
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
765
|
-
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
766
|
-
},
|
|
767
|
-
sitemap: config.sitemap,
|
|
768
|
-
robots: config.robots,
|
|
769
|
-
openapi: openapiDiscovery,
|
|
770
|
-
markdown: {
|
|
771
|
-
acceptHeader: true,
|
|
772
|
-
},
|
|
773
|
-
};
|
|
774
|
-
if (isDocsStandardsDiscoveryRequest(event.url, { apiRoute: discoveryApiRoute })) {
|
|
775
|
-
const standardsDiscoveryResponse = await createDocsStandardsDiscoveryResponse({
|
|
776
|
-
request: event.request,
|
|
777
|
-
...discoveryOptions,
|
|
778
|
-
preferredSkillDocument: readRootSkillDocument(preloaded, rootDir),
|
|
779
|
-
fallbackSkillDocument: renderDocsSkillDocument(discoveryOptions),
|
|
780
|
-
publishedSkills: await publishedAgentSkills,
|
|
781
|
-
agentCard: config.agent?.a2a,
|
|
782
|
-
});
|
|
783
|
-
if (standardsDiscoveryResponse)
|
|
784
|
-
return standardsDiscoveryResponse;
|
|
785
|
-
}
|
|
798
|
+
const discoveryOptions = createDiscoveryOptions(event.url.origin, discoveryApiRoute);
|
|
799
|
+
const standardsDiscoveryResponse = await resolveStandardsResponse(event.request, event.url, discoveryOptions);
|
|
800
|
+
if (standardsDiscoveryResponse)
|
|
801
|
+
return standardsDiscoveryResponse;
|
|
786
802
|
if (isDocsAgentDiscoveryRequest(event.url, { apiRoute: discoveryApiRoute })) {
|
|
787
|
-
return new Response(
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
803
|
+
return new Response(isHeadRequest
|
|
804
|
+
? null
|
|
805
|
+
: JSON.stringify(buildDocsAgentDiscoverySpec({
|
|
806
|
+
...discoveryOptions,
|
|
807
|
+
publishedSkills: [
|
|
808
|
+
await resolveDocsPublishedAgentSkill({
|
|
809
|
+
preferredDocument: readRootSkillDocument(preloaded, rootDir),
|
|
810
|
+
fallbackDocument: renderDocsSkillDocument(discoveryOptions),
|
|
811
|
+
}),
|
|
812
|
+
...(await getPublishedAgentSkills()),
|
|
813
|
+
],
|
|
814
|
+
agentCard: config.agent?.a2a,
|
|
815
|
+
}), null, 2), {
|
|
798
816
|
headers: {
|
|
799
817
|
"Content-Type": "application/json; charset=utf-8",
|
|
800
818
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
@@ -813,6 +831,15 @@ export function createDocsServer(config = {}) {
|
|
|
813
831
|
},
|
|
814
832
|
});
|
|
815
833
|
}
|
|
834
|
+
if (isHeadRequest) {
|
|
835
|
+
return new Response(null, {
|
|
836
|
+
headers: {
|
|
837
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
838
|
+
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
839
|
+
"X-Robots-Tag": "noindex",
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
}
|
|
816
843
|
const document = await buildApiReferenceOpenApiDocumentAsync(config, {
|
|
817
844
|
framework: "sveltekit",
|
|
818
845
|
rootDir,
|
|
@@ -837,7 +864,7 @@ export function createDocsServer(config = {}) {
|
|
|
837
864
|
},
|
|
838
865
|
});
|
|
839
866
|
}
|
|
840
|
-
return new Response(JSON.stringify(agentFeedbackConfig.schema, null, 2), {
|
|
867
|
+
return new Response(isHeadRequest ? null : JSON.stringify(agentFeedbackConfig.schema, null, 2), {
|
|
841
868
|
headers: {
|
|
842
869
|
"Content-Type": "application/schema+json; charset=utf-8",
|
|
843
870
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
@@ -847,7 +874,10 @@ export function createDocsServer(config = {}) {
|
|
|
847
874
|
}
|
|
848
875
|
if (isDocsAgentsRequest(event.url, { apiRoute: discoveryApiRoute }) ||
|
|
849
876
|
resolveDocsAgentsFormat(event.url) === "agents") {
|
|
850
|
-
return new Response(
|
|
877
|
+
return new Response(isHeadRequest
|
|
878
|
+
? null
|
|
879
|
+
: (readRootAgentsDocument(preloaded, rootDir) ??
|
|
880
|
+
renderDocsAgentsDocument(discoveryOptions)), {
|
|
851
881
|
headers: {
|
|
852
882
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
853
883
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
@@ -858,7 +888,10 @@ export function createDocsServer(config = {}) {
|
|
|
858
888
|
}
|
|
859
889
|
if (isDocsSkillRequest(event.url, { apiRoute: discoveryApiRoute }) ||
|
|
860
890
|
resolveDocsSkillFormat(event.url) === "skill") {
|
|
861
|
-
return new Response(
|
|
891
|
+
return new Response(isHeadRequest
|
|
892
|
+
? null
|
|
893
|
+
: (readRootSkillDocument(preloaded, rootDir) ??
|
|
894
|
+
renderDocsSkillDocument(discoveryOptions)), {
|
|
862
895
|
headers: {
|
|
863
896
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
864
897
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
@@ -1018,6 +1051,9 @@ export function createDocsServer(config = {}) {
|
|
|
1018
1051
|
async function POST(event) {
|
|
1019
1052
|
trackTelemetryRequest(event.request);
|
|
1020
1053
|
const requestUrl = new URL(event.request.url);
|
|
1054
|
+
const standardsDiscoveryResponse = await resolveStandardsResponse(event.request, requestUrl, createDiscoveryOptions(requestUrl.origin, resolveDocsRequestApiRoute(requestUrl, configuredApiRoute)));
|
|
1055
|
+
if (standardsDiscoveryResponse)
|
|
1056
|
+
return standardsDiscoveryResponse;
|
|
1021
1057
|
const agentFeedbackRequest = resolveDocsAgentFeedbackRequest(requestUrl, agentFeedbackConfig);
|
|
1022
1058
|
if (agentFeedbackRequest) {
|
|
1023
1059
|
if (agentFeedbackRequest.kind === "schema") {
|
|
@@ -1566,7 +1602,7 @@ export function createDocsServer(config = {}) {
|
|
|
1566
1602
|
preferredDocument: readRootSkillDocument(preloaded, rootDir),
|
|
1567
1603
|
fallbackDocument: renderDocsSkillDocument(skillOptions),
|
|
1568
1604
|
});
|
|
1569
|
-
return [rootSkill, ...(await
|
|
1605
|
+
return [rootSkill, ...(await getPublishedAgentSkills())];
|
|
1570
1606
|
},
|
|
1571
1607
|
},
|
|
1572
1608
|
mcp: config.mcp,
|
|
@@ -1576,5 +1612,13 @@ export function createDocsServer(config = {}) {
|
|
|
1576
1612
|
observability,
|
|
1577
1613
|
defaultName: mcpSiteTitle,
|
|
1578
1614
|
});
|
|
1579
|
-
|
|
1615
|
+
async function HEAD(event) {
|
|
1616
|
+
const response = await GET(event);
|
|
1617
|
+
return new Response(null, {
|
|
1618
|
+
status: response.status,
|
|
1619
|
+
statusText: response.statusText,
|
|
1620
|
+
headers: response.headers,
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
return { load, GET, HEAD, POST, MCP };
|
|
1580
1624
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.65",
|
|
4
4
|
"description": "SvelteKit adapter for @farming-labs/docs — content loading and navigation utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^22.10.0",
|
|
58
58
|
"typescript": "^5.9.3",
|
|
59
|
-
"@farming-labs/docs": "0.2.
|
|
59
|
+
"@farming-labs/docs": "0.2.65"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@farming-labs/docs": "*"
|