@farming-labs/theme 0.1.17 → 0.1.18
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 +59 -8
- package/dist/mdx.d.mts +5 -1
- package/dist/mdx.mjs +5 -1
- package/package.json +2 -2
package/dist/docs-api.mjs
CHANGED
|
@@ -274,8 +274,54 @@ function stripCommentsAndStrings(content) {
|
|
|
274
274
|
}
|
|
275
275
|
return result;
|
|
276
276
|
}
|
|
277
|
-
function
|
|
278
|
-
const
|
|
277
|
+
function resolveAgentMdxContent(content, audience) {
|
|
278
|
+
const lines = content.split("\n");
|
|
279
|
+
const output = [];
|
|
280
|
+
let fenceMarker = null;
|
|
281
|
+
let agentDepth = 0;
|
|
282
|
+
for (const line of lines) {
|
|
283
|
+
const trimmed = line.trim();
|
|
284
|
+
const fenceMatch = trimmed.match(/^(`{3,}|~{3,})/);
|
|
285
|
+
if (fenceMatch) {
|
|
286
|
+
if (!fenceMarker) fenceMarker = fenceMatch[1];
|
|
287
|
+
else if (trimmed.startsWith(fenceMarker)) fenceMarker = null;
|
|
288
|
+
if (audience === "agent" || agentDepth === 0) output.push(line);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (!fenceMarker) {
|
|
292
|
+
if (/^<Agent(?:\s[^>]*)?\/>$/.test(trimmed)) continue;
|
|
293
|
+
const singleLineMatch = line.match(/^(\s*)<Agent(?:\s[^>]*)?>([\s\S]*?)<\/Agent>\s*$/);
|
|
294
|
+
if (singleLineMatch) {
|
|
295
|
+
if (audience === "agent" && singleLineMatch[2]) output.push(`${singleLineMatch[1]}${singleLineMatch[2]}`);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (line.match(/^(\s*)<Agent(?:\s[^>]*)?>\s*$/)) {
|
|
299
|
+
agentDepth += 1;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
const openWithContentMatch = line.match(/^(\s*)<Agent(?:\s[^>]*)?>(.*)$/);
|
|
303
|
+
if (openWithContentMatch) {
|
|
304
|
+
agentDepth += 1;
|
|
305
|
+
if (audience === "agent" && openWithContentMatch[2]) output.push(`${openWithContentMatch[1]}${openWithContentMatch[2]}`);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const closeWithContentMatch = line.match(/^(.*)<\/Agent>\s*$/);
|
|
309
|
+
if (closeWithContentMatch && agentDepth > 0) {
|
|
310
|
+
if (audience === "agent" && closeWithContentMatch[1]) output.push(closeWithContentMatch[1]);
|
|
311
|
+
agentDepth = Math.max(0, agentDepth - 1);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (/^<\/Agent>\s*$/.test(trimmed) && agentDepth > 0) {
|
|
315
|
+
agentDepth = Math.max(0, agentDepth - 1);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (agentDepth > 0 && audience === "human") continue;
|
|
320
|
+
output.push(line);
|
|
321
|
+
}
|
|
322
|
+
return output.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
323
|
+
}
|
|
324
|
+
function stripMdx(content) {
|
|
279
325
|
return content.replace(/^(import|export)\s.*$/gm, "").replace(/<[^>]+\/>/g, "").replace(/<\/?[A-Z][^>]*>/g, "").replace(/<\/?[a-z][^>]*>/g, "").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/(\*{1,3}|_{1,3})(.*?)\1/g, "$2").replace(/```[\s\S]*?```/g, "").replace(/`([^`]+)`/g, "$1").replace(/^>\s+/gm, "").replace(/^[-*_]{3,}\s*$/gm, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
280
326
|
}
|
|
281
327
|
function scanDocsDir(docsDir, entry, locale, excludedDirs = []) {
|
|
@@ -296,14 +342,17 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = []) {
|
|
|
296
342
|
const { data } = matter(raw);
|
|
297
343
|
const title = data.title || slugParts[slugParts.length - 1]?.replace(/-/g, " ") || "Documentation";
|
|
298
344
|
const description = data.description;
|
|
299
|
-
const { content:
|
|
300
|
-
const
|
|
345
|
+
const { content: fileContent } = matter(raw);
|
|
346
|
+
const rawContent = resolveAgentMdxContent(fileContent, "human");
|
|
347
|
+
const agentRawContent = resolveAgentMdxContent(fileContent, "agent");
|
|
348
|
+
const content = stripMdx(rawContent);
|
|
301
349
|
const url = withLangInUrl(slugParts.length === 0 ? `/${entry}` : `/${entry}/${slugParts.join("/")}`, locale);
|
|
302
350
|
indexes.push({
|
|
303
351
|
title,
|
|
304
352
|
description,
|
|
305
353
|
content,
|
|
306
354
|
rawContent,
|
|
355
|
+
agentFallbackRawContent: agentRawContent !== rawContent ? agentRawContent : void 0,
|
|
307
356
|
url,
|
|
308
357
|
locale
|
|
309
358
|
});
|
|
@@ -346,12 +395,13 @@ function scanChangelogDir(changelogDir, entryPath, changelogPath, locale) {
|
|
|
346
395
|
const pagePath = path.join(entryDir, "page.mdx");
|
|
347
396
|
if (!fs.existsSync(pagePath)) continue;
|
|
348
397
|
try {
|
|
349
|
-
const
|
|
350
|
-
const { data, content: rawContent } = matter(raw);
|
|
398
|
+
const { data, content: fileContent } = matter(fs.readFileSync(pagePath, "utf-8"));
|
|
351
399
|
if (data.draft === true) continue;
|
|
352
400
|
const title = data.title || name.replace(/-/g, " ");
|
|
353
401
|
const description = data.description;
|
|
354
|
-
const
|
|
402
|
+
const rawContent = resolveAgentMdxContent(fileContent, "human");
|
|
403
|
+
const agentRawContent = resolveAgentMdxContent(fileContent, "agent");
|
|
404
|
+
const content = stripMdx(rawContent);
|
|
355
405
|
const url = withLangInUrl(`/${entryPath}/${changelogPath}/${name}`, locale);
|
|
356
406
|
const tags = Array.isArray(data.tags) ? data.tags.filter((value) => typeof value === "string") : void 0;
|
|
357
407
|
indexes.push({
|
|
@@ -359,6 +409,7 @@ function scanChangelogDir(changelogDir, entryPath, changelogPath, locale) {
|
|
|
359
409
|
description,
|
|
360
410
|
content,
|
|
361
411
|
rawContent,
|
|
412
|
+
agentFallbackRawContent: agentRawContent !== rawContent ? agentRawContent : void 0,
|
|
362
413
|
url,
|
|
363
414
|
locale,
|
|
364
415
|
type: "changelog",
|
|
@@ -397,7 +448,7 @@ function renderMarkdownDocument(page) {
|
|
|
397
448
|
if ("agentRawContent" in page && page.agentRawContent !== void 0) return page.agentRawContent;
|
|
398
449
|
const lines = [`# ${page.title}`, `URL: ${page.url}`];
|
|
399
450
|
if (page.description) lines.push(`Description: ${page.description}`);
|
|
400
|
-
lines.push("", page.rawContent ?? page.content);
|
|
451
|
+
lines.push("", page.agentFallbackRawContent ?? page.rawContent ?? page.content);
|
|
401
452
|
return lines.join("\n");
|
|
402
453
|
}
|
|
403
454
|
const DEFAULT_SYSTEM_PROMPT = `You are a helpful documentation assistant. Answer questions based on the provided documentation context. Be concise and accurate. If the answer is not in the context, say so honestly. Use markdown formatting for code examples and links.`;
|
package/dist/mdx.d.mts
CHANGED
|
@@ -13,9 +13,13 @@ import * as fumadocs_ui_components_callout0 from "fumadocs-ui/components/callout
|
|
|
13
13
|
declare function Table(props: React.ComponentPropsWithoutRef<"table">): React.DetailedReactHTMLElement<{
|
|
14
14
|
className: string;
|
|
15
15
|
}, HTMLElement>;
|
|
16
|
+
declare function Agent(_props: {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}): null;
|
|
16
19
|
declare const extendedMdxComponents: {
|
|
17
20
|
img: typeof MDXImg;
|
|
18
21
|
table: typeof Table;
|
|
22
|
+
Agent: typeof Agent;
|
|
19
23
|
HoverLink: typeof HoverLink;
|
|
20
24
|
Tab: typeof Tab;
|
|
21
25
|
Tabs: typeof Tabs;
|
|
@@ -46,4 +50,4 @@ interface GetMDXComponentsOptions {
|
|
|
46
50
|
}
|
|
47
51
|
declare function getMDXComponents<T extends Record<string, unknown> = Record<string, unknown>>(overrides?: T, options?: GetMDXComponentsOptions): typeof extendedMdxComponents & T;
|
|
48
52
|
//#endregion
|
|
49
|
-
export { GetMDXComponentsOptions, HoverLink, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
|
53
|
+
export { Agent, GetMDXComponentsOptions, HoverLink, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
package/dist/mdx.mjs
CHANGED
|
@@ -27,10 +27,14 @@ import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
|
27
27
|
function Table(props) {
|
|
28
28
|
return React.createElement("div", { className: "fd-table-wrapper relative overflow-auto prose-no-margin my-6" }, React.createElement("table", props));
|
|
29
29
|
}
|
|
30
|
+
function Agent(_props) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
30
33
|
const extendedMdxComponents = {
|
|
31
34
|
...defaultMdxComponents,
|
|
32
35
|
img: MDXImg,
|
|
33
36
|
table: Table,
|
|
37
|
+
Agent,
|
|
34
38
|
HoverLink,
|
|
35
39
|
Tab,
|
|
36
40
|
Tabs
|
|
@@ -80,4 +84,4 @@ function getMDXComponents(overrides, options) {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
//#endregion
|
|
83
|
-
export { HoverLink, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
|
87
|
+
export { Agent, HoverLink, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"tsdown": "^0.20.3",
|
|
134
134
|
"typescript": "^5.9.3",
|
|
135
135
|
"vitest": "^3.2.4",
|
|
136
|
-
"@farming-labs/docs": "0.1.
|
|
136
|
+
"@farming-labs/docs": "0.1.18"
|
|
137
137
|
},
|
|
138
138
|
"peerDependencies": {
|
|
139
139
|
"@farming-labs/docs": ">=0.0.1",
|