@farming-labs/svelte 0.1.36 → 0.1.38

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/content.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * extracts frontmatter, and builds a navigation tree compatible
6
6
  * with @farming-labs/docs DocsConfig.
7
7
  */
8
- import type { OrderingItem } from "@farming-labs/docs";
8
+ import { type OrderingItem, type ResolvedDocsRelatedLink } from "@farming-labs/docs";
9
9
  export interface PageNode {
10
10
  type: "page";
11
11
  name: string;
@@ -30,11 +30,14 @@ export interface ContentPage {
30
30
  url: string;
31
31
  title: string;
32
32
  description?: string;
33
+ related?: ResolvedDocsRelatedLink[];
33
34
  icon?: string;
34
35
  content: string;
35
36
  rawContent: string;
36
37
  agentContent?: string;
37
38
  agentRawContent?: string;
39
+ agentFallbackContent?: string;
40
+ agentFallbackRawContent?: string;
38
41
  }
39
42
  /**
40
43
  * Scan a content directory and return all docs pages.
package/dist/content.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import fs from "node:fs";
9
9
  import path from "node:path";
10
10
  import matter from "gray-matter";
11
+ import { normalizeDocsRelated, resolveDocsAgentMdxContent, } from "@farming-labs/docs";
11
12
  /**
12
13
  * Scan a content directory and return all docs pages.
13
14
  * Expects a flat or nested structure of `.md` files:
@@ -35,6 +36,9 @@ export function loadDocsContent(contentDir, entry = "docs") {
35
36
  continue;
36
37
  const raw = fs.readFileSync(full, "utf-8");
37
38
  const { data, content } = matter(raw);
39
+ const humanRawContent = resolveDocsAgentMdxContent(content, "human");
40
+ const pageAgentRawContent = resolveDocsAgentMdxContent(content, "agent");
41
+ const related = normalizeDocsRelated(data.related);
38
42
  const baseName = name.replace(/\.(md|mdx|svx)$/, "");
39
43
  const isIndex = baseName === "index" || baseName === "page" || baseName === "+page";
40
44
  const slug = isIndex ? slugParts.join("/") : [...slugParts, baseName].join("/");
@@ -47,9 +51,16 @@ export function loadDocsContent(contentDir, entry = "docs") {
47
51
  url,
48
52
  title,
49
53
  description: data.description,
54
+ ...(related.length > 0 ? { related } : {}),
50
55
  icon: data.icon,
51
- content: stripMarkdown(content),
52
- rawContent: content,
56
+ content: stripMarkdown(humanRawContent),
57
+ rawContent: humanRawContent,
58
+ ...(pageAgentRawContent !== humanRawContent
59
+ ? {
60
+ agentFallbackContent: stripMarkdown(pageAgentRawContent),
61
+ agentFallbackRawContent: pageAgentRawContent,
62
+ }
63
+ : {}),
53
64
  ...agentDoc,
54
65
  });
55
66
  }
@@ -8,7 +8,7 @@
8
8
  * - Callouts / admonitions (GitHub `[!NOTE]` and `**Note:**` styles)
9
9
  * - Tables, lists, inline formatting, headings with anchor IDs
10
10
  */
11
- import type { DocsTheme } from "@farming-labs/docs";
11
+ import { type DocsTheme } from "@farming-labs/docs";
12
12
  interface RenderMarkdownOptions {
13
13
  theme?: DocsTheme;
14
14
  }
package/dist/markdown.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * - Callouts / admonitions (GitHub `[!NOTE]` and `**Note:**` styles)
9
9
  * - Tables, lists, inline formatting, headings with anchor IDs
10
10
  */
11
+ import { resolveDocsAgentMdxContent } from "@farming-labs/docs";
11
12
  import { createHighlighter } from "shiki";
12
13
  let highlighterPromise;
13
14
  function getHighlighter() {
@@ -242,7 +243,7 @@ export async function renderMarkdown(content, options = {}) {
242
243
  if (!content)
243
244
  return "";
244
245
  const hl = await getHighlighter();
245
- let result = content;
246
+ let result = resolveDocsAgentMdxContent(content, "human");
246
247
  // ── Tabs blocks: <Tabs items={[...]}> ... </Tabs> ──
247
248
  const tabsBlocks = [];
248
249
  result = result.replace(/<Tabs\s+items=\{?\[([^\]]+)\]\}?>([\s\S]*?)<\/Tabs>/g, (_, itemsStr, body) => {
package/dist/server.js CHANGED
@@ -30,8 +30,8 @@
30
30
  import fs from "node:fs";
31
31
  import path from "node:path";
32
32
  import matter from "gray-matter";
33
- import { performDocsSearch, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLocale, resolveDocsPath, } from "@farming-labs/docs";
34
- import { createDocsMcpHttpHandler } from "@farming-labs/docs/server";
33
+ import { buildDocsAgentDiscoverySpec, findDocsMarkdownPage, isDocsAgentDiscoveryRequest, normalizeDocsRelated, performDocsSearch, renderDocsMarkdownDocument, resolveDocsAgentMdxContent, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtFormat, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsPath, } from "@farming-labs/docs";
34
+ import { createDocsMcpHttpHandler, resolveDocsMcpConfig } from "@farming-labs/docs/server";
35
35
  import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
36
36
  import { renderMarkdown } from "./markdown.js";
37
37
  export { createSvelteApiReference } from "./api-reference.js";
@@ -252,6 +252,9 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
252
252
  const slug = isIdx ? segments.join("/") : [...segments, base].join("/");
253
253
  const url = slug ? `/${entry}/${slug}` : `/${entry}`;
254
254
  const { data, content } = matter(raw);
255
+ const humanRawContent = resolveDocsAgentMdxContent(content, "human");
256
+ const pageAgentRawContent = resolveDocsAgentMdxContent(content, "agent");
257
+ const related = normalizeDocsRelated(data.related);
255
258
  const agentDoc = isIdx ? readAgentDocFromMap(contentMap, dirPrefix, slug) : undefined;
256
259
  const title = data.title ?? base.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
257
260
  pages.push({
@@ -259,9 +262,16 @@ function searchIndexFromMap(contentMap, dirPrefix, entry) {
259
262
  url,
260
263
  title,
261
264
  description: data.description,
265
+ ...(related.length > 0 ? { related } : {}),
262
266
  icon: data.icon,
263
- content: stripMarkdownText(content),
264
- rawContent: content,
267
+ content: stripMarkdownText(humanRawContent),
268
+ rawContent: humanRawContent,
269
+ ...(pageAgentRawContent !== humanRawContent
270
+ ? {
271
+ agentFallbackContent: stripMarkdownText(pageAgentRawContent),
272
+ agentFallbackRawContent: pageAgentRawContent,
273
+ }
274
+ : {}),
265
275
  ...agentDoc,
266
276
  });
267
277
  }
@@ -447,7 +457,8 @@ export function createDocsServer(config = {}) {
447
457
  });
448
458
  }
449
459
  const { data, content } = matter(raw);
450
- const html = await renderMarkdown(content, { theme: config.theme });
460
+ const humanRawContent = resolveDocsAgentMdxContent(content, "human");
461
+ const html = await renderMarkdown(humanRawContent, { theme: config.theme });
451
462
  const currentUrl = isIndex ? `/${entry}` : `/${entry}/${slug}`;
452
463
  const currentIndex = flatPages.findIndex((p) => p.url === currentUrl);
453
464
  const previousPage = currentIndex > 0 ? flatPages[currentIndex - 1] : null;
@@ -512,6 +523,11 @@ export function createDocsServer(config = {}) {
512
523
  const llmsBaseUrl = typeof llmsTxtConfig === "object" ? (llmsTxtConfig.baseUrl ?? "") : "";
513
524
  const llmsTitle = typeof llmsTxtConfig === "object" ? (llmsTxtConfig.siteTitle ?? llmsSiteTitle) : llmsSiteTitle;
514
525
  const llmsDesc = typeof llmsTxtConfig === "object" ? llmsTxtConfig.siteDescription : undefined;
526
+ const llmsEnabled = llmsTxtConfig !== false &&
527
+ !(llmsTxtConfig && typeof llmsTxtConfig === "object" && llmsTxtConfig.enabled === false);
528
+ const mcpConfig = resolveDocsMcpConfig(config.mcp, {
529
+ defaultName: llmsTitle,
530
+ });
515
531
  const llmsCache = new Map();
516
532
  function getLlmsContent(ctx) {
517
533
  const key = ctx.locale ?? "__default__";
@@ -548,13 +564,70 @@ export function createDocsServer(config = {}) {
548
564
  return locale;
549
565
  return i18n.defaultLocale;
550
566
  }
567
+ function getMarkdownDocument(ctx, requestedPath) {
568
+ const page = findDocsMarkdownPage(entry, getSearchIndex(ctx), requestedPath);
569
+ return page ? renderDocsMarkdownDocument(page) : null;
570
+ }
551
571
  // ─── GET /api/docs?query=… | ?format=llms | ?format=llms-full ──
552
572
  async function GET(event) {
553
573
  const ctx = resolveContextFromRequest(event.request);
554
- const format = event.url.searchParams.get("format");
555
- if (format === "llms" || format === "llms-full") {
574
+ if (isDocsAgentDiscoveryRequest(event.url)) {
575
+ return new Response(JSON.stringify(buildDocsAgentDiscoverySpec({
576
+ origin: event.url.origin,
577
+ entry,
578
+ i18n,
579
+ search: config.search,
580
+ mcp: mcpConfig,
581
+ llms: {
582
+ enabled: llmsEnabled,
583
+ baseUrl: llmsBaseUrl || undefined,
584
+ siteTitle: llmsTitle,
585
+ siteDescription: llmsDesc,
586
+ },
587
+ markdown: {
588
+ acceptHeader: false,
589
+ },
590
+ }), null, 2), {
591
+ headers: {
592
+ "Content-Type": "application/json; charset=utf-8",
593
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
594
+ "X-Robots-Tag": "noindex",
595
+ },
596
+ });
597
+ }
598
+ const markdownRequest = resolveDocsMarkdownRequest(entry, event.url, event.request);
599
+ if (markdownRequest) {
600
+ const document = getMarkdownDocument(ctx, markdownRequest.requestedPath);
601
+ if (!document) {
602
+ return new Response("Not Found", {
603
+ status: 404,
604
+ headers: {
605
+ "Content-Type": "text/plain; charset=utf-8",
606
+ "X-Robots-Tag": "noindex",
607
+ },
608
+ });
609
+ }
610
+ return new Response(document, {
611
+ headers: {
612
+ "Content-Type": "text/markdown; charset=utf-8",
613
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
614
+ "X-Robots-Tag": "noindex",
615
+ },
616
+ });
617
+ }
618
+ const llmsFormat = resolveDocsLlmsTxtFormat(event.url);
619
+ if (llmsFormat === "llms" || llmsFormat === "llms-full") {
620
+ if (!llmsEnabled) {
621
+ return new Response("Not Found", {
622
+ status: 404,
623
+ headers: {
624
+ "Content-Type": "text/plain; charset=utf-8",
625
+ "X-Robots-Tag": "noindex",
626
+ },
627
+ });
628
+ }
556
629
  const llmsContent = getLlmsContent(ctx);
557
- return new Response(format === "llms-full" ? llmsContent.llmsFullTxt : llmsContent.llmsTxt, {
630
+ return new Response(llmsFormat === "llms-full" ? llmsContent.llmsFullTxt : llmsContent.llmsTxt, {
558
631
  headers: {
559
632
  "Content-Type": "text/plain; charset=utf-8",
560
633
  "Cache-Control": "public, max-age=3600",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/svelte",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
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.1.36"
59
+ "@farming-labs/docs": "0.1.38"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@farming-labs/docs": "*"