@farming-labs/theme 0.1.1-beta.4 → 0.1.2

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.
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/colorful/index.d.ts
2
4
  declare const ColorfulUIDefaults: {
3
5
  colors: {
@@ -75,6 +77,6 @@ declare const ColorfulUIDefaults: {
75
77
  };
76
78
  };
77
79
  };
78
- declare const colorful: any;
80
+ declare const colorful: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
79
81
  //#endregion
80
82
  export { ColorfulUIDefaults, colorful };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/concrete/index.d.ts
2
4
  declare const ConcreteUIDefaults: {
3
5
  colors: {
@@ -83,6 +85,6 @@ declare const ConcreteUIDefaults: {
83
85
  };
84
86
  };
85
87
  };
86
- declare const concrete: any;
88
+ declare const concrete: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
87
89
  //#endregion
88
90
  export { ConcreteUIDefaults, concrete };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/darkbold/index.d.ts
2
4
  declare const DarkBoldUIDefaults: {
3
5
  colors: {
@@ -77,6 +79,6 @@ declare const DarkBoldUIDefaults: {
77
79
  };
78
80
  };
79
81
  };
80
- declare const darkbold: any;
82
+ declare const darkbold: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
81
83
  //#endregion
82
84
  export { DarkBoldUIDefaults, darkbold };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/darksharp/index.d.ts
2
4
  /**
3
5
  * Darksharp fumadocs theme preset — all-black, sharp edges, zero-radius look.
@@ -110,6 +112,6 @@ declare const DarksharpUIDefaults: {
110
112
  * export default defineDocs({ theme: darksharp() });
111
113
  * ```
112
114
  */
113
- declare const darksharp: any;
115
+ declare const darksharp: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
114
116
  //#endregion
115
117
  export { DarksharpUIDefaults, darksharp };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/default/index.d.ts
2
4
  /**
3
5
  * Default fumadocs theme preset — neutral colors, standard radius.
@@ -109,6 +111,6 @@ declare const DefaultUIDefaults: {
109
111
  * export default defineDocs({ theme: fumadocs({ ui: { colors: { primary: "#22c55e" } } }) });
110
112
  * ```
111
113
  */
112
- declare const fumadocs: any;
114
+ declare const fumadocs: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
113
115
  //#endregion
114
116
  export { DefaultUIDefaults, fumadocs };
@@ -1,4 +1,4 @@
1
- import { DocsI18nConfig } from "@farming-labs/docs";
1
+ import { DocsI18nConfig, DocsMcpConfig, OrderingItem } from "@farming-labs/docs";
2
2
 
3
3
  //#region src/docs-api.d.ts
4
4
  interface AIProviderConfig {
@@ -35,6 +35,16 @@ interface DocsAPIOptions {
35
35
  /** i18n config (optional) */
36
36
  i18n?: DocsI18nConfig;
37
37
  }
38
+ interface DocsMCPAPIOptions {
39
+ rootDir?: string;
40
+ entry?: string;
41
+ contentDir?: string;
42
+ nav?: {
43
+ title?: unknown;
44
+ };
45
+ ordering?: "alphabetical" | "numeric" | OrderingItem[];
46
+ mcp?: boolean | DocsMcpConfig;
47
+ }
38
48
  /**
39
49
  * Create a unified docs API route handler.
40
50
  *
@@ -66,5 +76,15 @@ declare function createDocsAPI(options?: DocsAPIOptions): {
66
76
  */
67
77
  POST(request: Request): Promise<Response>;
68
78
  };
79
+ /**
80
+ * Create MCP route handlers for `/api/docs/mcp`.
81
+ *
82
+ * Returns `{ GET, POST, DELETE }` for use in a Next.js route handler.
83
+ */
84
+ declare function createDocsMCPAPI(options?: DocsMCPAPIOptions): {
85
+ GET(request: Request): Promise<Response>;
86
+ POST(request: Request): Promise<Response>;
87
+ DELETE(request: Request): Promise<Response>;
88
+ };
69
89
  //#endregion
70
- export { createDocsAPI };
90
+ export { createDocsAPI, createDocsMCPAPI };
package/dist/docs-api.mjs CHANGED
@@ -5,6 +5,7 @@ import fs from "node:fs";
5
5
  import path from "node:path";
6
6
  import matter from "gray-matter";
7
7
  import { createSearchAPI } from "fumadocs-core/search/server";
8
+ import { createDocsMcpHttpHandler, createFilesystemDocsMcpSource } from "@farming-labs/docs/server";
8
9
 
9
10
  //#region src/docs-api.ts
10
11
  /**
@@ -90,6 +91,190 @@ function readAIConfig(root) {
90
91
  }
91
92
  return {};
92
93
  }
94
+ function readMcpConfig(root) {
95
+ for (const ext of FILE_EXTS) {
96
+ const configPath = path.join(root, `docs.config.${ext}`);
97
+ if (!fs.existsSync(configPath)) continue;
98
+ try {
99
+ const content = fs.readFileSync(configPath, "utf-8");
100
+ const sanitized = stripCommentsAndStrings(content);
101
+ const configObject = extractRootConfigObject(content, sanitized);
102
+ const scopedContent = configObject?.content ?? content;
103
+ const scopedSanitized = configObject?.sanitized ?? sanitized;
104
+ const booleanValue = readTopLevelBoolean(scopedSanitized, "mcp");
105
+ if (booleanValue !== void 0) return booleanValue;
106
+ const block = extractObjectLiteral(scopedContent, scopedSanitized, "mcp");
107
+ if (!block) continue;
108
+ return {
109
+ enabled: readBooleanFromBlock(block, "enabled"),
110
+ route: readStringFromBlock(block, "route"),
111
+ name: readStringFromBlock(block, "name"),
112
+ version: readStringFromBlock(block, "version"),
113
+ tools: {
114
+ listPages: readBooleanFromBlock(block, "listPages"),
115
+ readPage: readBooleanFromBlock(block, "readPage"),
116
+ searchDocs: readBooleanFromBlock(block, "searchDocs"),
117
+ getNavigation: readBooleanFromBlock(block, "getNavigation")
118
+ }
119
+ };
120
+ } catch {}
121
+ }
122
+ }
123
+ function readStringFromBlock(block, key) {
124
+ return block.match(new RegExp(`${key}\\s*:\\s*["']([^"']+)["']`))?.[1];
125
+ }
126
+ function readBooleanFromBlock(block, key) {
127
+ const match = block.match(new RegExp(`${key}\\s*:\\s*(true|false)`));
128
+ return match ? match[1] === "true" : void 0;
129
+ }
130
+ function extractObjectLiteral(content, sanitized, key) {
131
+ const keyIndex = findTopLevelPropertyIndex(sanitized, key);
132
+ if (keyIndex === -1) return void 0;
133
+ const colonIndex = sanitized.indexOf(":", keyIndex + key.length);
134
+ if (colonIndex === -1) return void 0;
135
+ const braceStart = sanitized.indexOf("{", colonIndex);
136
+ if (braceStart === -1) return void 0;
137
+ let depth = 0;
138
+ for (let index = braceStart; index < sanitized.length; index += 1) {
139
+ const char = sanitized[index];
140
+ if (char === "{") {
141
+ depth += 1;
142
+ continue;
143
+ }
144
+ if (char !== "}") continue;
145
+ depth -= 1;
146
+ if (depth === 0) return content.slice(braceStart + 1, index);
147
+ }
148
+ }
149
+ function readTopLevelBoolean(content, key) {
150
+ const keyIndex = findTopLevelPropertyIndex(content, key);
151
+ if (keyIndex === -1) return void 0;
152
+ const match = content.slice(keyIndex + key.length).match(/^\s*:\s*(true|false)\b/);
153
+ if (!match) return void 0;
154
+ return match[1] === "true";
155
+ }
156
+ function findTopLevelPropertyIndex(content, key) {
157
+ let depth = 0;
158
+ for (let index = 0; index < content.length; index += 1) {
159
+ const char = content[index];
160
+ if (char === "{") {
161
+ depth += 1;
162
+ continue;
163
+ }
164
+ if (char === "}") {
165
+ depth = Math.max(0, depth - 1);
166
+ continue;
167
+ }
168
+ if (depth !== 0) continue;
169
+ if (!content.startsWith(key, index)) continue;
170
+ const previous = index === 0 ? "" : content[index - 1];
171
+ if (previous && /[\w$]/.test(previous)) continue;
172
+ const next = content[index + key.length] ?? "";
173
+ if (next && /[\w$]/.test(next)) continue;
174
+ if (!content.slice(index + key.length).match(/^\s*:/)) continue;
175
+ return index;
176
+ }
177
+ return -1;
178
+ }
179
+ function extractRootConfigObject(content, sanitized) {
180
+ const defineDocsIndex = sanitized.indexOf("defineDocs");
181
+ const exportDefaultIndex = sanitized.indexOf("export default");
182
+ let braceStart = -1;
183
+ if (defineDocsIndex !== -1) {
184
+ const parenIndex = sanitized.indexOf("(", defineDocsIndex);
185
+ if (parenIndex !== -1) braceStart = sanitized.indexOf("{", parenIndex);
186
+ }
187
+ if (braceStart === -1 && exportDefaultIndex !== -1) braceStart = sanitized.indexOf("{", exportDefaultIndex);
188
+ if (braceStart === -1) return void 0;
189
+ let depth = 0;
190
+ for (let index = braceStart; index < sanitized.length; index += 1) {
191
+ const char = sanitized[index];
192
+ if (char === "{") {
193
+ depth += 1;
194
+ continue;
195
+ }
196
+ if (char !== "}") continue;
197
+ depth -= 1;
198
+ if (depth === 0) return {
199
+ content: content.slice(braceStart + 1, index),
200
+ sanitized: sanitized.slice(braceStart + 1, index)
201
+ };
202
+ }
203
+ }
204
+ function stripCommentsAndStrings(content) {
205
+ let result = "";
206
+ let index = 0;
207
+ let state = "normal";
208
+ while (index < content.length) {
209
+ const char = content[index];
210
+ const next = content[index + 1];
211
+ if (state === "lineComment") {
212
+ if (char === "\n") {
213
+ state = "normal";
214
+ result += "\n";
215
+ } else result += " ";
216
+ index += 1;
217
+ continue;
218
+ }
219
+ if (state === "blockComment") {
220
+ if (char === "*" && next === "/") {
221
+ result += " ";
222
+ index += 2;
223
+ state = "normal";
224
+ } else {
225
+ result += char === "\n" ? "\n" : " ";
226
+ index += 1;
227
+ }
228
+ continue;
229
+ }
230
+ if (state === "singleQuote" || state === "doubleQuote" || state === "template") {
231
+ const quote = state === "singleQuote" ? "'" : state === "doubleQuote" ? "\"" : "`";
232
+ if (char === "\\") {
233
+ result += " ";
234
+ if (next) result += next === "\n" ? "\n" : " ";
235
+ index += 2;
236
+ continue;
237
+ }
238
+ result += char === "\n" ? "\n" : " ";
239
+ if (char === quote) state = "normal";
240
+ index += 1;
241
+ continue;
242
+ }
243
+ if (char === "/" && next === "/") {
244
+ result += " ";
245
+ index += 2;
246
+ state = "lineComment";
247
+ continue;
248
+ }
249
+ if (char === "/" && next === "*") {
250
+ result += " ";
251
+ index += 2;
252
+ state = "blockComment";
253
+ continue;
254
+ }
255
+ if (char === "'") {
256
+ result += " ";
257
+ index += 1;
258
+ state = "singleQuote";
259
+ continue;
260
+ }
261
+ if (char === "\"") {
262
+ result += " ";
263
+ index += 1;
264
+ state = "doubleQuote";
265
+ continue;
266
+ }
267
+ if (char === "`") {
268
+ result += " ";
269
+ index += 1;
270
+ state = "template";
271
+ continue;
272
+ }
273
+ result += char;
274
+ index += 1;
275
+ }
276
+ return result;
277
+ }
93
278
  function stripMdx(raw) {
94
279
  const { content } = matter(raw);
95
280
  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();
@@ -353,6 +538,40 @@ function createDocsAPI(options) {
353
538
  }
354
539
  };
355
540
  }
541
+ /**
542
+ * Create MCP route handlers for `/api/docs/mcp`.
543
+ *
544
+ * Returns `{ GET, POST, DELETE }` for use in a Next.js route handler.
545
+ */
546
+ function createDocsMCPAPI(options = {}) {
547
+ const rootDir = options.rootDir ?? process.cwd();
548
+ const entry = options.entry ?? readEntry(rootDir);
549
+ const appDir = getNextAppDir(rootDir);
550
+ const contentDir = options.contentDir ?? path.join(appDir, entry);
551
+ const navTitle = typeof options.nav?.title === "string" && options.nav.title.trim().length > 0 ? options.nav.title : "Documentation";
552
+ const handlers = createDocsMcpHttpHandler({
553
+ source: createFilesystemDocsMcpSource({
554
+ rootDir,
555
+ entry,
556
+ contentDir,
557
+ siteTitle: navTitle,
558
+ ordering: options.ordering
559
+ }),
560
+ mcp: options.mcp ?? readMcpConfig(rootDir),
561
+ defaultName: navTitle
562
+ });
563
+ return {
564
+ GET(request) {
565
+ return handlers.GET({ request });
566
+ },
567
+ POST(request) {
568
+ return handlers.POST({ request });
569
+ },
570
+ DELETE(request) {
571
+ return handlers.DELETE({ request });
572
+ }
573
+ };
574
+ }
356
575
 
357
576
  //#endregion
358
- export { createDocsAPI };
577
+ export { createDocsAPI, createDocsMCPAPI };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/greentree/index.d.ts
2
4
  declare const GreenTreeUIDefaults: {
3
5
  colors: {
@@ -77,6 +79,6 @@ declare const GreenTreeUIDefaults: {
77
79
  };
78
80
  };
79
81
  };
80
- declare const greentree: any;
82
+ declare const greentree: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
81
83
  //#endregion
82
84
  export { GreenTreeUIDefaults, greentree };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/hardline/index.d.ts
2
4
  declare const HardlineUIDefaults: {
3
5
  colors: {
@@ -81,6 +83,6 @@ declare const HardlineUIDefaults: {
81
83
  };
82
84
  };
83
85
  };
84
- declare const hardline: any;
86
+ declare const hardline: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
85
87
  //#endregion
86
88
  export { HardlineUIDefaults, hardline };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/pixel-border/index.d.ts
2
4
  /**
3
5
  * Pixel-border UI defaults — better-auth inspired, clean dark UI.
@@ -85,6 +87,6 @@ declare const PixelBorderUIDefaults: {
85
87
  * export default defineDocs({ theme: pixelBorder() });
86
88
  * ```
87
89
  */
88
- declare const pixelBorder: any;
90
+ declare const pixelBorder: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
89
91
  //#endregion
90
92
  export { PixelBorderUIDefaults, pixelBorder };
@@ -1,3 +1,5 @@
1
+ import * as _farming_labs_docs0 from "@farming-labs/docs";
2
+
1
3
  //#region src/shiny/index.d.ts
2
4
  declare const ShinyUIDefaults: {
3
5
  colors: {
@@ -76,6 +78,6 @@ declare const ShinyUIDefaults: {
76
78
  };
77
79
  };
78
80
  };
79
- declare const shiny: any;
81
+ declare const shiny: (overrides?: Partial<_farming_labs_docs0.DocsTheme>) => _farming_labs_docs0.DocsTheme;
80
82
  //#endregion
81
83
  export { ShinyUIDefaults, shiny };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.1-beta.4",
3
+ "version": "0.1.2",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -127,7 +127,7 @@
127
127
  "tsdown": "^0.20.3",
128
128
  "typescript": "^5.9.3",
129
129
  "vitest": "^3.2.4",
130
- "@farming-labs/docs": "0.1.1-beta.4"
130
+ "@farming-labs/docs": "0.1.2"
131
131
  },
132
132
  "peerDependencies": {
133
133
  "@farming-labs/docs": ">=0.0.1",