@farming-labs/svelte 0.2.57 → 0.2.59
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/server.js +76 -79
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -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, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, getDocsLlmsTxtMaxCharsIssue, isDocsAgentDiscoveryRequest, isDocsAgentsRequest, isDocsConfigRequest, isDocsDiagnosticsRequest, isDocsSkillRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAudienceMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
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, isDocsStandardsDiscoveryRequest, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, renderDocsMarkdownDocument, renderDocsLlmsTxt, renderDocsAgentsDocument, renderDocsSkillDocument, readDocsSitemapManifestFromContentMap, stripGeneratedAgentProvenance, resolveDocsAudienceMdxContent, resolveDocsAgentFeedbackConfig, resolveDocsAgentFeedbackRequest, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsMetadataBaseUrl, resolveDocsRequestApiRoute, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSitemapPageLastmod, resolveDocsAgentsFormat, resolveDocsSkillFormat, inferDocsTelemetryAgentSurface, renderDocsPageStructuredDataJson, selectDocsLlmsTxtContent, validateDocsAgentFeedbackPayload, } from "@farming-labs/docs";
|
|
34
34
|
import { buildApiReferenceOpenApiDocumentAsync, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, isDocsCloudAskAIProvider, readDocsSitemapManifest, resolveApiReferenceConfig, resolveDocsMcpConfig, serializeDocsIconRegistry, serializeOpenDocsProviders, } from "@farming-labs/docs/server";
|
|
35
35
|
import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
|
|
36
36
|
import { renderMarkdown } from "./markdown.js";
|
|
@@ -45,6 +45,7 @@ function resolveApiReferenceOpenApiDiscovery(value) {
|
|
|
45
45
|
return {
|
|
46
46
|
enabled: true,
|
|
47
47
|
url: "/api/docs?format=openapi",
|
|
48
|
+
urlSource: "default",
|
|
48
49
|
source: apiReference.specUrl ? "configured" : "generated",
|
|
49
50
|
specUrl: apiReference.specUrl,
|
|
50
51
|
apiReferencePath: `/${apiReference.path}`,
|
|
@@ -639,6 +640,13 @@ export function createDocsServer(config = {}) {
|
|
|
639
640
|
const llmsDesc = typeof llmsTxtConfig === "object" ? llmsTxtConfig.siteDescription : undefined;
|
|
640
641
|
const llmsEnabled = llmsTxtConfig !== false &&
|
|
641
642
|
!(llmsTxtConfig && typeof llmsTxtConfig === "object" && llmsTxtConfig.enabled === false);
|
|
643
|
+
const apiCatalogEnabled = typeof llmsTxtConfig !== "object" || llmsTxtConfig.apiCatalog !== false;
|
|
644
|
+
const configuredApiRoute = typeof config.cloud?.apiRoute === "string" && config.cloud.apiRoute.trim()
|
|
645
|
+
? config.cloud.apiRoute
|
|
646
|
+
: undefined;
|
|
647
|
+
const discoveryLinkHeader = getDocsDiscoveryLinkHeader({
|
|
648
|
+
includeApiCatalog: apiCatalogEnabled,
|
|
649
|
+
});
|
|
642
650
|
const openapiDiscovery = resolveApiReferenceOpenApiDiscovery(config.apiReference);
|
|
643
651
|
const mcpConfig = resolveDocsMcpConfig(config.mcp, {
|
|
644
652
|
defaultName: llmsTitle,
|
|
@@ -668,20 +676,21 @@ export function createDocsServer(config = {}) {
|
|
|
668
676
|
surface,
|
|
669
677
|
});
|
|
670
678
|
}
|
|
671
|
-
function getLlmsContent(ctx) {
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
return cached;
|
|
679
|
+
function getLlmsContent(ctx, apiRoute) {
|
|
680
|
+
const cached = llmsCache.get(ctx.locale);
|
|
681
|
+
if (cached?.apiRoute === apiRoute)
|
|
682
|
+
return cached.content;
|
|
676
683
|
const next = renderDocsLlmsTxt(getSearchIndex(ctx), {
|
|
677
684
|
siteTitle: llmsTitle,
|
|
678
685
|
siteDescription: llmsDesc,
|
|
679
686
|
baseUrl: llmsBaseUrl,
|
|
687
|
+
apiRoute,
|
|
680
688
|
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
681
689
|
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
682
690
|
openapi: openapiDiscovery,
|
|
691
|
+
apiCatalog: apiCatalogEnabled,
|
|
683
692
|
});
|
|
684
|
-
llmsCache.set(
|
|
693
|
+
llmsCache.set(ctx.locale, { apiRoute, content: next });
|
|
685
694
|
return next;
|
|
686
695
|
}
|
|
687
696
|
function resolveLocaleForMcp(locale) {
|
|
@@ -704,6 +713,7 @@ export function createDocsServer(config = {}) {
|
|
|
704
713
|
async function GET(event) {
|
|
705
714
|
trackTelemetryRequest(event.request);
|
|
706
715
|
const ctx = resolveContextFromRequest(event.request);
|
|
716
|
+
const requestApiRoute = resolveDocsRequestApiRoute(event.url, configuredApiRoute);
|
|
707
717
|
if (isDocsConfigRequest(event.url)) {
|
|
708
718
|
return new Response(JSON.stringify(buildDocsConfigMap(config), null, 2), {
|
|
709
719
|
headers: {
|
|
@@ -717,6 +727,7 @@ export function createDocsServer(config = {}) {
|
|
|
717
727
|
return new Response(JSON.stringify(buildDocsDiagnostics(config, {
|
|
718
728
|
adapter: "sveltekit",
|
|
719
729
|
entry,
|
|
730
|
+
apiRoute: requestApiRoute,
|
|
720
731
|
i18n,
|
|
721
732
|
mcp: mcpConfig,
|
|
722
733
|
feedback: agentFeedbackDiscovery,
|
|
@@ -729,33 +740,50 @@ export function createDocsServer(config = {}) {
|
|
|
729
740
|
},
|
|
730
741
|
});
|
|
731
742
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
743
|
+
const discoveryApiRoute = requestApiRoute;
|
|
744
|
+
const discoveryOptions = {
|
|
745
|
+
origin: event.url.origin,
|
|
746
|
+
entry,
|
|
747
|
+
apiRoute: discoveryApiRoute,
|
|
748
|
+
docsPath: config.docsPath,
|
|
749
|
+
apiCatalog: apiCatalogEnabled,
|
|
750
|
+
i18n,
|
|
751
|
+
search: config.search,
|
|
752
|
+
mcp: mcpConfig,
|
|
753
|
+
feedback: agentFeedbackDiscovery,
|
|
754
|
+
llms: {
|
|
755
|
+
enabled: llmsEnabled,
|
|
756
|
+
apiCatalog: apiCatalogEnabled,
|
|
757
|
+
baseUrl: llmsBaseUrl || undefined,
|
|
758
|
+
siteTitle: llmsTitle,
|
|
759
|
+
siteDescription: llmsDesc,
|
|
760
|
+
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
761
|
+
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
762
|
+
},
|
|
763
|
+
sitemap: config.sitemap,
|
|
764
|
+
robots: config.robots,
|
|
765
|
+
openapi: openapiDiscovery,
|
|
766
|
+
markdown: {
|
|
767
|
+
acceptHeader: false,
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
if (isDocsStandardsDiscoveryRequest(event.url, { apiRoute: discoveryApiRoute })) {
|
|
771
|
+
const standardsDiscoveryResponse = await createDocsStandardsDiscoveryResponse({
|
|
772
|
+
request: event.request,
|
|
773
|
+
...discoveryOptions,
|
|
774
|
+
preferredSkillDocument: readRootSkillDocument(preloaded, rootDir),
|
|
775
|
+
fallbackSkillDocument: renderDocsSkillDocument(discoveryOptions),
|
|
776
|
+
});
|
|
777
|
+
if (standardsDiscoveryResponse)
|
|
778
|
+
return standardsDiscoveryResponse;
|
|
779
|
+
}
|
|
780
|
+
if (isDocsAgentDiscoveryRequest(event.url, { apiRoute: discoveryApiRoute })) {
|
|
781
|
+
return new Response(JSON.stringify(buildDocsAgentDiscoverySpec(discoveryOptions), null, 2), {
|
|
755
782
|
headers: {
|
|
756
783
|
"Content-Type": "application/json; charset=utf-8",
|
|
757
784
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
758
785
|
"X-Robots-Tag": "noindex",
|
|
786
|
+
Link: discoveryLinkHeader,
|
|
759
787
|
},
|
|
760
788
|
});
|
|
761
789
|
}
|
|
@@ -801,68 +829,31 @@ export function createDocsServer(config = {}) {
|
|
|
801
829
|
},
|
|
802
830
|
});
|
|
803
831
|
}
|
|
804
|
-
if (isDocsAgentsRequest(event.url
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
origin: event.url.origin,
|
|
808
|
-
entry,
|
|
809
|
-
search: config.search,
|
|
810
|
-
mcp: mcpConfig,
|
|
811
|
-
feedback: agentFeedbackDiscovery,
|
|
812
|
-
llms: {
|
|
813
|
-
enabled: llmsEnabled,
|
|
814
|
-
baseUrl: llmsBaseUrl || undefined,
|
|
815
|
-
siteTitle: llmsTitle,
|
|
816
|
-
siteDescription: llmsDesc,
|
|
817
|
-
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
818
|
-
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
819
|
-
},
|
|
820
|
-
sitemap: config.sitemap,
|
|
821
|
-
robots: config.robots,
|
|
822
|
-
openapi: openapiDiscovery,
|
|
823
|
-
markdown: {
|
|
824
|
-
acceptHeader: false,
|
|
825
|
-
},
|
|
826
|
-
}), {
|
|
832
|
+
if (isDocsAgentsRequest(event.url, { apiRoute: discoveryApiRoute }) ||
|
|
833
|
+
resolveDocsAgentsFormat(event.url) === "agents") {
|
|
834
|
+
return new Response(readRootAgentsDocument(preloaded, rootDir) ?? renderDocsAgentsDocument(discoveryOptions), {
|
|
827
835
|
headers: {
|
|
828
836
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
829
837
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
830
838
|
"X-Robots-Tag": "noindex",
|
|
839
|
+
Link: discoveryLinkHeader,
|
|
831
840
|
},
|
|
832
841
|
});
|
|
833
842
|
}
|
|
834
|
-
if (isDocsSkillRequest(event.url
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
origin: event.url.origin,
|
|
838
|
-
entry,
|
|
839
|
-
search: config.search,
|
|
840
|
-
mcp: mcpConfig,
|
|
841
|
-
feedback: agentFeedbackDiscovery,
|
|
842
|
-
llms: {
|
|
843
|
-
enabled: llmsEnabled,
|
|
844
|
-
baseUrl: llmsBaseUrl || undefined,
|
|
845
|
-
siteTitle: llmsTitle,
|
|
846
|
-
siteDescription: llmsDesc,
|
|
847
|
-
maxChars: typeof llmsTxtConfig === "object" ? llmsTxtConfig.maxChars : undefined,
|
|
848
|
-
sections: typeof llmsTxtConfig === "object" ? llmsTxtConfig.sections : undefined,
|
|
849
|
-
},
|
|
850
|
-
sitemap: config.sitemap,
|
|
851
|
-
robots: config.robots,
|
|
852
|
-
openapi: openapiDiscovery,
|
|
853
|
-
markdown: {
|
|
854
|
-
acceptHeader: false,
|
|
855
|
-
},
|
|
856
|
-
}), {
|
|
843
|
+
if (isDocsSkillRequest(event.url, { apiRoute: discoveryApiRoute }) ||
|
|
844
|
+
resolveDocsSkillFormat(event.url) === "skill") {
|
|
845
|
+
return new Response(readRootSkillDocument(preloaded, rootDir) ?? renderDocsSkillDocument(discoveryOptions), {
|
|
857
846
|
headers: {
|
|
858
847
|
"Content-Type": "text/markdown; charset=utf-8",
|
|
859
848
|
"Cache-Control": "public, max-age=0, s-maxage=3600",
|
|
860
849
|
"X-Robots-Tag": "noindex",
|
|
850
|
+
Link: discoveryLinkHeader,
|
|
861
851
|
},
|
|
862
852
|
});
|
|
863
853
|
}
|
|
864
854
|
const sitemapResponse = createDocsSitemapResponse({
|
|
865
855
|
request: event.request,
|
|
856
|
+
apiRoute: discoveryApiRoute,
|
|
866
857
|
sitemap: config.sitemap,
|
|
867
858
|
entry,
|
|
868
859
|
siteTitle: llmsTitle,
|
|
@@ -875,18 +866,22 @@ export function createDocsServer(config = {}) {
|
|
|
875
866
|
const robotsResponse = createDocsRobotsResponse({
|
|
876
867
|
request: event.request,
|
|
877
868
|
entry,
|
|
869
|
+
apiCatalog: apiCatalogEnabled,
|
|
878
870
|
sitemap: config.sitemap,
|
|
879
871
|
baseUrl: llmsBaseUrl || event.url.origin,
|
|
880
872
|
robots: config.robots,
|
|
881
873
|
});
|
|
882
874
|
if (robotsResponse)
|
|
883
875
|
return robotsResponse;
|
|
884
|
-
const markdownRequest = resolveDocsMarkdownRequest(entry, event.url, event.request
|
|
876
|
+
const markdownRequest = resolveDocsMarkdownRequest(entry, event.url, event.request, {
|
|
877
|
+
apiRoute: discoveryApiRoute,
|
|
878
|
+
});
|
|
885
879
|
if (markdownRequest) {
|
|
886
880
|
const markdownOrigin = markdownMetadataBaseUrl || event.url.origin;
|
|
887
881
|
const representation = getMarkdownRepresentation(ctx, markdownRequest.requestedPath, markdownOrigin);
|
|
888
882
|
return createDocsMarkdownResponse({
|
|
889
883
|
request: event.request,
|
|
884
|
+
apiRoute: discoveryApiRoute,
|
|
890
885
|
document: representation?.document ?? null,
|
|
891
886
|
entry,
|
|
892
887
|
requestedPath: markdownRequest.requestedPath,
|
|
@@ -897,7 +892,9 @@ export function createDocsServer(config = {}) {
|
|
|
897
892
|
sitemap: config.sitemap,
|
|
898
893
|
});
|
|
899
894
|
}
|
|
900
|
-
const llmsRequest = resolveDocsLlmsTxtRequest(event.url, llmsTxtConfig, entry
|
|
895
|
+
const llmsRequest = resolveDocsLlmsTxtRequest(event.url, llmsTxtConfig, entry, {
|
|
896
|
+
apiRoute: discoveryApiRoute,
|
|
897
|
+
});
|
|
901
898
|
if (llmsRequest) {
|
|
902
899
|
if (!llmsEnabled) {
|
|
903
900
|
return new Response("Not Found", {
|
|
@@ -908,7 +905,7 @@ export function createDocsServer(config = {}) {
|
|
|
908
905
|
},
|
|
909
906
|
});
|
|
910
907
|
}
|
|
911
|
-
const selected = selectDocsLlmsTxtContent(getLlmsContent(ctx), llmsRequest);
|
|
908
|
+
const selected = selectDocsLlmsTxtContent(getLlmsContent(ctx, requestApiRoute), llmsRequest);
|
|
912
909
|
if (!selected) {
|
|
913
910
|
return new Response("Not Found", {
|
|
914
911
|
status: 404,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.59",
|
|
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.59"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@farming-labs/docs": "*"
|