@farming-labs/docs 0.1.59 → 0.1.62
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/{agent-CCznWtjf.mjs → agent-COwO6Q6N.mjs} +2 -1
- package/dist/{agent-3gfGIRgr.mjs → agent-LSYzB5MK.mjs} +3 -3
- package/dist/cli/index.mjs +26 -8
- package/dist/dev-VD41gGZC.mjs +1289 -0
- package/dist/{doctor-_pzgvY8k.mjs → doctor-CfGThtMI.mjs} +4 -4
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/init-CcgI3D7-.mjs +1162 -0
- package/dist/{mcp-DSCLcG0O.mjs → mcp-BANLcwQ0.mjs} +1 -1
- package/dist/mcp.d.mts +2 -1
- package/dist/mcp.mjs +120 -10
- package/dist/{prompt-utils-CbtKaiIU.mjs → prompt-utils-8nmFLQVH.mjs} +82 -6
- package/dist/{search-DFCYC33M.mjs → search-DVyHOFlo.mjs} +2 -2
- package/dist/{search-Cu_pxL8o.mjs → search-Ds3jiS2n.mjs} +50 -1
- package/dist/search-HlwTDHCK.d.mts +31 -0
- package/dist/server.d.mts +3 -3
- package/dist/server.mjs +3 -3
- package/dist/{init-C1tsFxXo.mjs → templates-2M1vfnf-.mjs} +5 -1164
- package/dist/{types-bAjvrTGU.d.mts → types-DfiAeeHu.d.mts} +56 -1
- package/dist/{upgrade-a185_G5A.mjs → upgrade-CA_OE7wL.mjs} +1 -1
- package/package.json +1 -1
- package/dist/search-DWkWwsU5.d.mts +0 -21
- /package/dist/{utils-CpTFbAiS.mjs → utils-DSMXVnEu.mjs} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./prompt-utils-
|
|
1
|
+
import "./prompt-utils-8nmFLQVH.mjs";
|
|
2
2
|
import { createFilesystemDocsMcpSource, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
|
|
3
3
|
import "./server.mjs";
|
|
4
4
|
import { c as readNavTitle, f as resolveDocsConfigPath, n as extractObjectLiteral, o as readBooleanProperty, p as resolveDocsContentDir, u as readStringProperty } from "./config-Si-yUfM_.mjs";
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { N as DocsSearchConfig, Z as OrderingItem, m as DocsAnalyticsConfig, w as DocsMcpConfig, z as DocsSearchSourcePage } from "./types-DfiAeeHu.mjs";
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
@@ -68,6 +68,7 @@ interface CreateDocsMcpServerOptions {
|
|
|
68
68
|
source: DocsMcpSource;
|
|
69
69
|
mcp?: boolean | DocsMcpConfig;
|
|
70
70
|
search?: boolean | DocsSearchConfig;
|
|
71
|
+
analytics?: boolean | DocsAnalyticsConfig;
|
|
71
72
|
defaultName?: string;
|
|
72
73
|
defaultVersion?: string;
|
|
73
74
|
}
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as renderDocsRelatedMarkdownLines, g as normalizeDocsRelated, h as stripGeneratedAgentProvenance, s as performDocsSearch } from "./search-
|
|
1
|
+
import { _ as renderDocsRelatedMarkdownLines, g as normalizeDocsRelated, h as stripGeneratedAgentProvenance, s as performDocsSearch, v as emitDocsAnalyticsEvent } from "./search-Ds3jiS2n.mjs";
|
|
2
2
|
import matter from "gray-matter";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
@@ -84,6 +84,12 @@ function createFilesystemDocsMcpSource(options = {}) {
|
|
|
84
84
|
getNavigation
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
+
function nowMs() {
|
|
88
|
+
return Date.now();
|
|
89
|
+
}
|
|
90
|
+
function durationMs(startedAt) {
|
|
91
|
+
return Math.max(0, Date.now() - startedAt);
|
|
92
|
+
}
|
|
87
93
|
async function createDocsMcpServer(options) {
|
|
88
94
|
const resolved = resolveDocsMcpConfig(options.mcp, {
|
|
89
95
|
defaultName: options.defaultName ?? options.source.siteTitle ?? DEFAULT_MCP_NAME,
|
|
@@ -123,7 +129,18 @@ async function createDocsMcpServer(options) {
|
|
|
123
129
|
inputSchema: listPagesInputSchema,
|
|
124
130
|
annotations: { readOnlyHint: true }
|
|
125
131
|
}, async ({ locale }) => {
|
|
132
|
+
const startedAt = nowMs();
|
|
126
133
|
const pages = toPageSummaries(dedupePages(await options.source.getPages(locale)));
|
|
134
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
135
|
+
type: "mcp_tool",
|
|
136
|
+
source: "mcp",
|
|
137
|
+
locale,
|
|
138
|
+
properties: {
|
|
139
|
+
tool: "list_pages",
|
|
140
|
+
resultCount: pages.length,
|
|
141
|
+
durationMs: durationMs(startedAt)
|
|
142
|
+
}
|
|
143
|
+
});
|
|
127
144
|
return { content: [{
|
|
128
145
|
type: "text",
|
|
129
146
|
text: JSON.stringify({ pages }, null, 2)
|
|
@@ -135,9 +152,20 @@ async function createDocsMcpServer(options) {
|
|
|
135
152
|
inputSchema: getNavigationInputSchema,
|
|
136
153
|
annotations: { readOnlyHint: true }
|
|
137
154
|
}, async ({ locale }) => {
|
|
155
|
+
const startedAt = nowMs();
|
|
156
|
+
const tree = await options.source.getNavigation(locale);
|
|
157
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
158
|
+
type: "mcp_tool",
|
|
159
|
+
source: "mcp",
|
|
160
|
+
locale,
|
|
161
|
+
properties: {
|
|
162
|
+
tool: "get_navigation",
|
|
163
|
+
durationMs: durationMs(startedAt)
|
|
164
|
+
}
|
|
165
|
+
});
|
|
138
166
|
return { content: [{
|
|
139
167
|
type: "text",
|
|
140
|
-
text: renderNavigationTree(
|
|
168
|
+
text: renderNavigationTree(tree)
|
|
141
169
|
}] };
|
|
142
170
|
});
|
|
143
171
|
if (resolved.tools.searchDocs) server.registerTool("search_docs", {
|
|
@@ -146,6 +174,7 @@ async function createDocsMcpServer(options) {
|
|
|
146
174
|
inputSchema: searchDocsInputSchema,
|
|
147
175
|
annotations: { readOnlyHint: true }
|
|
148
176
|
}, async ({ query, limit, locale }) => {
|
|
177
|
+
const startedAt = nowMs();
|
|
149
178
|
const results = await performDocsSearch({
|
|
150
179
|
pages: toSearchSourcePages(dedupePages(await options.source.getPages(locale))),
|
|
151
180
|
query,
|
|
@@ -154,6 +183,19 @@ async function createDocsMcpServer(options) {
|
|
|
154
183
|
siteTitle: options.source.siteTitle,
|
|
155
184
|
limit: limit ?? 10
|
|
156
185
|
});
|
|
186
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
187
|
+
type: "mcp_tool",
|
|
188
|
+
source: "mcp",
|
|
189
|
+
locale,
|
|
190
|
+
input: { query },
|
|
191
|
+
properties: {
|
|
192
|
+
tool: "search_docs",
|
|
193
|
+
queryLength: query.length,
|
|
194
|
+
limit: limit ?? 10,
|
|
195
|
+
resultCount: results.length,
|
|
196
|
+
durationMs: durationMs(startedAt)
|
|
197
|
+
}
|
|
198
|
+
});
|
|
157
199
|
return { content: [{
|
|
158
200
|
type: "text",
|
|
159
201
|
text: JSON.stringify({ results }, null, 2)
|
|
@@ -165,17 +207,73 @@ async function createDocsMcpServer(options) {
|
|
|
165
207
|
inputSchema: readPageInputSchema,
|
|
166
208
|
annotations: { readOnlyHint: true }
|
|
167
209
|
}, async ({ path: requestedPath, locale }) => {
|
|
210
|
+
const startedAt = nowMs();
|
|
168
211
|
const page = findDocsPage(dedupePages(await options.source.getPages(locale)), requestedPath, options.source.entry);
|
|
169
|
-
if (!page)
|
|
170
|
-
|
|
171
|
-
type: "
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
212
|
+
if (!page) {
|
|
213
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
214
|
+
type: "agent_read",
|
|
215
|
+
source: "mcp",
|
|
216
|
+
locale,
|
|
217
|
+
properties: {
|
|
218
|
+
delivery: "mcp_tool",
|
|
219
|
+
tool: "read_page",
|
|
220
|
+
requestedPath,
|
|
221
|
+
found: false,
|
|
222
|
+
durationMs: durationMs(startedAt)
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
226
|
+
type: "mcp_tool",
|
|
227
|
+
source: "mcp",
|
|
228
|
+
locale,
|
|
229
|
+
properties: {
|
|
230
|
+
tool: "read_page",
|
|
231
|
+
path: requestedPath,
|
|
232
|
+
found: false,
|
|
233
|
+
durationMs: durationMs(startedAt)
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
content: [{
|
|
238
|
+
type: "text",
|
|
239
|
+
text: JSON.stringify({ error: `No docs page matched "${requestedPath}".` }, null, 2)
|
|
240
|
+
}],
|
|
241
|
+
isError: true
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const document = renderPageDocument(page);
|
|
245
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
246
|
+
type: "agent_read",
|
|
247
|
+
source: "mcp",
|
|
248
|
+
locale,
|
|
249
|
+
path: page.url,
|
|
250
|
+
properties: {
|
|
251
|
+
delivery: "mcp_tool",
|
|
252
|
+
tool: "read_page",
|
|
253
|
+
requestedPath,
|
|
254
|
+
slug: page.slug,
|
|
255
|
+
found: true,
|
|
256
|
+
contentLength: document.length,
|
|
257
|
+
durationMs: durationMs(startedAt)
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
261
|
+
type: "mcp_tool",
|
|
262
|
+
source: "mcp",
|
|
263
|
+
locale,
|
|
264
|
+
path: page.url,
|
|
265
|
+
properties: {
|
|
266
|
+
tool: "read_page",
|
|
267
|
+
requestedPath,
|
|
268
|
+
slug: page.slug,
|
|
269
|
+
found: true,
|
|
270
|
+
contentLength: document.length,
|
|
271
|
+
durationMs: durationMs(startedAt)
|
|
272
|
+
}
|
|
273
|
+
});
|
|
176
274
|
return { content: [{
|
|
177
275
|
type: "text",
|
|
178
|
-
text:
|
|
276
|
+
text: document
|
|
179
277
|
}] };
|
|
180
278
|
});
|
|
181
279
|
return server;
|
|
@@ -213,6 +311,7 @@ function createDocsMcpHttpHandler(options) {
|
|
|
213
311
|
};
|
|
214
312
|
}
|
|
215
313
|
async function handle(request) {
|
|
314
|
+
const url = new URL(request.url);
|
|
216
315
|
const method = request.method.toUpperCase();
|
|
217
316
|
const sessionId = request.headers.get("mcp-session-id") ?? request.headers.get("Mcp-Session-Id");
|
|
218
317
|
const existing = sessionId ? sessions.get(sessionId) : void 0;
|
|
@@ -223,6 +322,17 @@ function createDocsMcpHttpHandler(options) {
|
|
|
223
322
|
parsedBody = void 0;
|
|
224
323
|
}
|
|
225
324
|
const initializeRequest = method === "POST" && parsedBody && isInitializeRequest(parsedBody);
|
|
325
|
+
await emitDocsAnalyticsEvent(options.analytics, {
|
|
326
|
+
type: "mcp_request",
|
|
327
|
+
source: "mcp",
|
|
328
|
+
url: request.url,
|
|
329
|
+
path: url.pathname,
|
|
330
|
+
properties: {
|
|
331
|
+
method,
|
|
332
|
+
hasSession: Boolean(existing),
|
|
333
|
+
initialize: Boolean(initializeRequest)
|
|
334
|
+
}
|
|
335
|
+
});
|
|
226
336
|
if (!existing) {
|
|
227
337
|
if (!initializeRequest) return createJsonErrorResponse(method === "DELETE" ? 404 : 400, "MCP session not initialized. Start with an initialize request against this endpoint.");
|
|
228
338
|
return (await createSession()).transport.handleRequest(request, parsedBody === void 0 ? void 0 : { parsedBody });
|
|
@@ -61,6 +61,9 @@ function normalizeRemoteSpecUrl(value) {
|
|
|
61
61
|
if (!trimmed) return void 0;
|
|
62
62
|
return trimmed;
|
|
63
63
|
}
|
|
64
|
+
function isRequestRelativeSpecUrl(value) {
|
|
65
|
+
return typeof value === "string" && value.startsWith("/");
|
|
66
|
+
}
|
|
64
67
|
function buildApiReferencePageTitle(config, title = "API Reference") {
|
|
65
68
|
const template = config.metadata?.titleTemplate;
|
|
66
69
|
if (!template) return title;
|
|
@@ -426,18 +429,18 @@ function relativeLuminance([r, g, b]) {
|
|
|
426
429
|
function buildApiReferenceOpenApiDocument(config, options) {
|
|
427
430
|
if (resolveApiReferenceConfig(config.apiReference).specUrl) return buildUnavailableOpenApiDocument(config, `Remote OpenAPI specs require the async API reference builder. Use the framework route helper or buildApiReferenceOpenApiDocumentAsync().`);
|
|
428
431
|
const routes = buildApiReferenceRoutes(config, options);
|
|
429
|
-
return buildOpenApiDocumentFromRoutes(config, options.framework, routes);
|
|
432
|
+
return buildOpenApiDocumentFromRoutes(config, options.framework, routes, options.baseUrl);
|
|
430
433
|
}
|
|
431
434
|
async function buildApiReferenceOpenApiDocumentAsync(config, options) {
|
|
432
435
|
const apiReference = resolveApiReferenceConfig(config.apiReference);
|
|
433
436
|
if (!apiReference.specUrl) return buildApiReferenceOpenApiDocument(config, options);
|
|
434
437
|
try {
|
|
435
|
-
return normalizeRemoteOpenApiDocument(await fetchRemoteOpenApiDocument(apiReference.specUrl, options.baseUrl), config);
|
|
438
|
+
return normalizeRemoteOpenApiDocument(await fetchRemoteOpenApiDocument(apiReference.specUrl, options.baseUrl), config, options.baseUrl);
|
|
436
439
|
} catch (error) {
|
|
437
440
|
return buildUnavailableOpenApiDocument(config, `Unable to load the remote OpenAPI JSON. ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
438
441
|
}
|
|
439
442
|
}
|
|
440
|
-
function buildOpenApiDocumentFromRoutes(config, framework, routes) {
|
|
443
|
+
function buildOpenApiDocumentFromRoutes(config, framework, routes, baseUrl) {
|
|
441
444
|
const tags = Array.from(new Set(routes.map((route) => route.tag))).map((name) => ({
|
|
442
445
|
name,
|
|
443
446
|
description: `${name} endpoints`
|
|
@@ -449,7 +452,7 @@ function buildOpenApiDocumentFromRoutes(config, framework, routes) {
|
|
|
449
452
|
description: config.metadata?.description ?? `Generated API reference for ${framework}.`,
|
|
450
453
|
version: "0.0.0"
|
|
451
454
|
},
|
|
452
|
-
servers: [{ url: "/" }],
|
|
455
|
+
servers: [{ url: baseUrl ?? "/" }],
|
|
453
456
|
tags,
|
|
454
457
|
paths: buildOpenApiPaths(routes)
|
|
455
458
|
};
|
|
@@ -504,8 +507,12 @@ async function fetchRemoteOpenApiDocument(specUrl, baseUrl) {
|
|
|
504
507
|
if (!("openapi" in parsed) && !("swagger" in parsed)) throw new Error("The remote JSON does not look like an OpenAPI document.");
|
|
505
508
|
return parsed;
|
|
506
509
|
}
|
|
507
|
-
function normalizeRemoteOpenApiDocument(document, config) {
|
|
510
|
+
function normalizeRemoteOpenApiDocument(document, config, baseUrl) {
|
|
511
|
+
const apiReference = resolveApiReferenceConfig(config.apiReference);
|
|
508
512
|
const info = document.info && typeof document.info === "object" && !Array.isArray(document.info) ? document.info : {};
|
|
513
|
+
const normalizedPaths = normalizeRemoteOpenApiPaths(document.paths);
|
|
514
|
+
const normalizedTags = normalizeRemoteOpenApiTags(document.tags, normalizedPaths);
|
|
515
|
+
const normalizedServers = isRequestRelativeSpecUrl(apiReference.specUrl) ? [{ url: baseUrl ?? "/" }] : document.servers;
|
|
509
516
|
return {
|
|
510
517
|
...document,
|
|
511
518
|
info: {
|
|
@@ -513,9 +520,78 @@ function normalizeRemoteOpenApiDocument(document, config) {
|
|
|
513
520
|
version: "0.0.0",
|
|
514
521
|
...info,
|
|
515
522
|
description: typeof info.description === "string" && info.description.trim() ? info.description : config.metadata?.description
|
|
516
|
-
}
|
|
523
|
+
},
|
|
524
|
+
servers: normalizedServers,
|
|
525
|
+
paths: normalizedPaths,
|
|
526
|
+
tags: normalizedTags
|
|
517
527
|
};
|
|
518
528
|
}
|
|
529
|
+
function normalizeRemoteOpenApiPaths(value) {
|
|
530
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
531
|
+
const paths = value;
|
|
532
|
+
const normalized = {};
|
|
533
|
+
for (const [routePath, pathItem] of Object.entries(paths)) {
|
|
534
|
+
if (!pathItem || typeof pathItem !== "object" || Array.isArray(pathItem)) continue;
|
|
535
|
+
const normalizedPathItem = { ...pathItem };
|
|
536
|
+
for (const method of [
|
|
537
|
+
"get",
|
|
538
|
+
"post",
|
|
539
|
+
"put",
|
|
540
|
+
"patch",
|
|
541
|
+
"delete",
|
|
542
|
+
"options",
|
|
543
|
+
"head"
|
|
544
|
+
]) {
|
|
545
|
+
const operation = normalizedPathItem[method];
|
|
546
|
+
if (!operation || typeof operation !== "object" || Array.isArray(operation)) continue;
|
|
547
|
+
const operationRecord = operation;
|
|
548
|
+
const tags = Array.isArray(operationRecord.tags) ? operationRecord.tags.filter((tag) => typeof tag === "string" && tag.trim().length > 0) : [];
|
|
549
|
+
normalizedPathItem[method] = {
|
|
550
|
+
...operationRecord,
|
|
551
|
+
tags: tags.length > 0 ? tags : [inferRemoteOpenApiTag(routePath)]
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
normalized[routePath] = normalizedPathItem;
|
|
555
|
+
}
|
|
556
|
+
return normalized;
|
|
557
|
+
}
|
|
558
|
+
function inferRemoteOpenApiTag(routePath) {
|
|
559
|
+
return humanizeSegment(routePath.split("/").filter(Boolean).find((value) => !value.startsWith("{")) ?? "general");
|
|
560
|
+
}
|
|
561
|
+
function normalizeRemoteOpenApiTags(value, paths) {
|
|
562
|
+
const existingTags = Array.isArray(value) ? value.filter((tag) => !!tag && typeof tag === "object") : [];
|
|
563
|
+
const tagsByName = /* @__PURE__ */ new Map();
|
|
564
|
+
for (const tag of existingTags) {
|
|
565
|
+
const name = typeof tag.name === "string" && tag.name.trim() ? tag.name.trim() : void 0;
|
|
566
|
+
if (!name) continue;
|
|
567
|
+
tagsByName.set(name, tag);
|
|
568
|
+
}
|
|
569
|
+
if (paths) for (const pathItem of Object.values(paths)) for (const method of [
|
|
570
|
+
"get",
|
|
571
|
+
"post",
|
|
572
|
+
"put",
|
|
573
|
+
"patch",
|
|
574
|
+
"delete",
|
|
575
|
+
"options",
|
|
576
|
+
"head"
|
|
577
|
+
]) {
|
|
578
|
+
const operation = pathItem[method];
|
|
579
|
+
if (!operation || typeof operation !== "object" || Array.isArray(operation)) continue;
|
|
580
|
+
const tags = Array.isArray(operation.tags) ? operation.tags : [];
|
|
581
|
+
for (const tag of tags) {
|
|
582
|
+
if (typeof tag !== "string" || !tag.trim()) continue;
|
|
583
|
+
if (!tagsByName.has(tag)) tagsByName.set(tag, {
|
|
584
|
+
name: tag,
|
|
585
|
+
description: `${tag} endpoints`
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (tagsByName.size === 0) return [{
|
|
590
|
+
name: "General",
|
|
591
|
+
description: "General endpoints"
|
|
592
|
+
}];
|
|
593
|
+
return Array.from(tagsByName.values());
|
|
594
|
+
}
|
|
519
595
|
function buildUnavailableOpenApiDocument(config, description) {
|
|
520
596
|
return {
|
|
521
597
|
openapi: "3.1.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, t as buildDocsSearchDocuments } from "./search-
|
|
2
|
-
import "./prompt-utils-
|
|
1
|
+
import { n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, t as buildDocsSearchDocuments } from "./search-Ds3jiS2n.mjs";
|
|
2
|
+
import "./prompt-utils-8nmFLQVH.mjs";
|
|
3
3
|
import { createFilesystemDocsMcpSource } from "./mcp.mjs";
|
|
4
4
|
import "./server.mjs";
|
|
5
5
|
import { a as loadProjectEnv, d as readTopLevelStringProperty, f as resolveDocsConfigPath, p as resolveDocsContentDir } from "./config-Si-yUfM_.mjs";
|
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
//#region src/analytics.ts
|
|
2
|
+
function resolveConsoleLevel(value, hasEventHandler) {
|
|
3
|
+
if (value === false) return false;
|
|
4
|
+
if (value === true) return "info";
|
|
5
|
+
if (value === "log" || value === "info" || value === "debug") return value;
|
|
6
|
+
return hasEventHandler ? false : "info";
|
|
7
|
+
}
|
|
8
|
+
function resolveDocsAnalyticsConfig(analytics) {
|
|
9
|
+
if (!analytics) return {
|
|
10
|
+
enabled: false,
|
|
11
|
+
console: false,
|
|
12
|
+
includeInputs: false
|
|
13
|
+
};
|
|
14
|
+
if (analytics === true) return {
|
|
15
|
+
enabled: true,
|
|
16
|
+
console: "info",
|
|
17
|
+
includeInputs: false
|
|
18
|
+
};
|
|
19
|
+
const hasEventHandler = typeof analytics.onEvent === "function";
|
|
20
|
+
return {
|
|
21
|
+
enabled: analytics.enabled !== false,
|
|
22
|
+
console: resolveConsoleLevel(analytics.console, hasEventHandler),
|
|
23
|
+
includeInputs: analytics.includeInputs === true,
|
|
24
|
+
onEvent: analytics.onEvent
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function normalizeAnalyticsEvent(event, config) {
|
|
28
|
+
const normalized = {
|
|
29
|
+
...event,
|
|
30
|
+
source: event.source ?? "server",
|
|
31
|
+
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
32
|
+
};
|
|
33
|
+
if (!config.includeInputs && normalized.input) delete normalized.input;
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
async function emitDocsAnalyticsEvent(analytics, event) {
|
|
37
|
+
const resolved = resolveDocsAnalyticsConfig(analytics);
|
|
38
|
+
if (!resolved.enabled) return;
|
|
39
|
+
const normalized = normalizeAnalyticsEvent(event, resolved);
|
|
40
|
+
if (resolved.console) (console[resolved.console] ?? console.info).call(console, "[farming-labs:analytics]", normalized);
|
|
41
|
+
if (!resolved.onEvent) return;
|
|
42
|
+
try {
|
|
43
|
+
await resolved.onEvent(normalized);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (resolved.console !== false) console.warn("[farming-labs:analytics] onEvent failed", error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
1
50
|
//#region src/related.ts
|
|
2
51
|
function normalizeDocsRelated(value) {
|
|
3
52
|
if (!Array.isArray(value)) return [];
|
|
@@ -793,4 +842,4 @@ function createCustomSearchAdapter(adapter) {
|
|
|
793
842
|
}
|
|
794
843
|
|
|
795
844
|
//#endregion
|
|
796
|
-
export { renderDocsRelatedMarkdownLines as _, createSimpleSearchAdapter as a, resolveSearchRequestConfig as c, hashGeneratedAgentContent as d, normalizeGeneratedAgentContent as f, normalizeDocsRelated as g, stripGeneratedAgentProvenance as h, createMcpSearchAdapter as i, GENERATED_AGENT_PROVENANCE_MARKER as l, serializeGeneratedAgentDocument as m, createAlgoliaSearchAdapter as n, createTypesenseSearchAdapter as o, parseGeneratedAgentDocument as p, createCustomSearchAdapter as r, performDocsSearch as s, buildDocsSearchDocuments as t, GENERATED_AGENT_PROVENANCE_VERSION as u };
|
|
845
|
+
export { renderDocsRelatedMarkdownLines as _, createSimpleSearchAdapter as a, resolveSearchRequestConfig as c, hashGeneratedAgentContent as d, normalizeGeneratedAgentContent as f, normalizeDocsRelated as g, stripGeneratedAgentProvenance as h, createMcpSearchAdapter as i, GENERATED_AGENT_PROVENANCE_MARKER as l, serializeGeneratedAgentDocument as m, createAlgoliaSearchAdapter as n, createTypesenseSearchAdapter as o, parseGeneratedAgentDocument as p, createCustomSearchAdapter as r, performDocsSearch as s, buildDocsSearchDocuments as t, GENERATED_AGENT_PROVENANCE_VERSION as u, emitDocsAnalyticsEvent as v, resolveDocsAnalyticsConfig as y };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { K as McpDocsSearchConfig, L as DocsSearchResult, M as DocsSearchChunkingConfig, N as DocsSearchConfig, P as DocsSearchDocument, d as CustomDocsSearchConfig, g as DocsAnalyticsEventInput, h as DocsAnalyticsEvent, j as DocsSearchAdapterFactory, k as DocsSearchAdapter, m as DocsAnalyticsConfig, mt as TypesenseDocsSearchConfig, r as AlgoliaDocsSearchConfig, z as DocsSearchSourcePage } from "./types-DfiAeeHu.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/analytics.d.ts
|
|
4
|
+
interface ResolvedDocsAnalyticsConfig {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
console: false | "log" | "info" | "debug";
|
|
7
|
+
includeInputs: boolean;
|
|
8
|
+
onEvent?: (event: DocsAnalyticsEvent) => void | Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
declare function resolveDocsAnalyticsConfig(analytics?: boolean | DocsAnalyticsConfig): ResolvedDocsAnalyticsConfig;
|
|
11
|
+
declare function emitDocsAnalyticsEvent(analytics: boolean | DocsAnalyticsConfig | undefined, event: DocsAnalyticsEventInput): Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/search.d.ts
|
|
14
|
+
declare function buildDocsSearchDocuments(pages: DocsSearchSourcePage[], chunking?: DocsSearchChunkingConfig): DocsSearchDocument[];
|
|
15
|
+
declare function createSimpleSearchAdapter(): DocsSearchAdapter;
|
|
16
|
+
declare function createTypesenseSearchAdapter(config: TypesenseDocsSearchConfig): DocsSearchAdapter;
|
|
17
|
+
declare function resolveSearchRequestConfig(search: boolean | DocsSearchConfig | undefined, requestUrl?: string): boolean | DocsSearchConfig | undefined;
|
|
18
|
+
declare function createMcpSearchAdapter(config: McpDocsSearchConfig): DocsSearchAdapter;
|
|
19
|
+
declare function createAlgoliaSearchAdapter(config: AlgoliaDocsSearchConfig): DocsSearchAdapter;
|
|
20
|
+
declare function performDocsSearch(options: {
|
|
21
|
+
pages: DocsSearchSourcePage[];
|
|
22
|
+
query: string;
|
|
23
|
+
search?: boolean | DocsSearchConfig;
|
|
24
|
+
locale?: string;
|
|
25
|
+
pathname?: string;
|
|
26
|
+
siteTitle?: string;
|
|
27
|
+
limit?: number;
|
|
28
|
+
}): Promise<DocsSearchResult[]>;
|
|
29
|
+
declare function createCustomSearchAdapter(adapter: DocsSearchAdapter | DocsSearchAdapterFactory): CustomDocsSearchConfig;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createSimpleSearchAdapter as a, resolveSearchRequestConfig as c, resolveDocsAnalyticsConfig as d, createMcpSearchAdapter as i, ResolvedDocsAnalyticsConfig as l, createAlgoliaSearchAdapter as n, createTypesenseSearchAdapter as o, createCustomSearchAdapter as r, performDocsSearch as s, buildDocsSearchDocuments as t, emitDocsAnalyticsEvent as u };
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as DocsSearchQuery,
|
|
1
|
+
import { A as DocsSearchAdapterContext, I as DocsSearchQuery, K as McpDocsSearchConfig, L as DocsSearchResult, N as DocsSearchConfig, P as DocsSearchDocument, Y as OpenDocsProvider, a as ApiReferenceRenderer, b as DocsConfig, g as DocsAnalyticsEventInput, h as DocsAnalyticsEvent, j as DocsSearchAdapterFactory, k as DocsSearchAdapter, m as DocsAnalyticsConfig, z as DocsSearchSourcePage } from "./types-DfiAeeHu.mjs";
|
|
2
|
+
import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, d as resolveDocsAnalyticsConfig, i as createMcpSearchAdapter, l as ResolvedDocsAnalyticsConfig, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments, u as emitDocsAnalyticsEvent } from "./search-HlwTDHCK.mjs";
|
|
2
3
|
import { DocsMcpHttpHandlers, DocsMcpNavigationNode, DocsMcpNavigationTree, DocsMcpPage, DocsMcpResolvedConfig, DocsMcpSource, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
|
|
3
|
-
import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, i as createMcpSearchAdapter, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments } from "./search-DWkWwsU5.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/api-reference.d.ts
|
|
6
6
|
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD";
|
|
@@ -63,4 +63,4 @@ declare function parsePromptStringArray(value: unknown): string[] | undefined;
|
|
|
63
63
|
declare function resolvePromptProviderChoices(availableProviders?: PromptProviderInput[], preferredNames?: string[]): PromptProviderChoice[];
|
|
64
64
|
declare function sanitizePromptText(text: string): string;
|
|
65
65
|
//#endregion
|
|
66
|
-
export { type ApiReferenceFramework, type ApiReferenceRenderer, type ApiReferenceRoute, DEFAULT_PROMPT_PROVIDER_TEMPLATES, type DocsMcpHttpHandlers, type DocsMcpNavigationNode, type DocsMcpNavigationTree, type DocsMcpPage, type DocsMcpResolvedConfig, type DocsMcpSource, type DocsSearchAdapter, type DocsSearchAdapterContext, type DocsSearchAdapterFactory, type DocsSearchConfig, type DocsSearchDocument, type DocsSearchQuery, type DocsSearchResult, type DocsSearchSourcePage, type McpDocsSearchConfig, type PromptAction, type PromptProviderChoice, type ResolvedApiReferenceConfig, type SerializedOpenDocsProvider, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsSearchDocuments, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, resolveApiReferenceConfig, resolveApiReferenceRenderer, resolveDocsMcpConfig, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProviders };
|
|
66
|
+
export { type ApiReferenceFramework, type ApiReferenceRenderer, type ApiReferenceRoute, DEFAULT_PROMPT_PROVIDER_TEMPLATES, type DocsAnalyticsConfig, type DocsAnalyticsEvent, type DocsAnalyticsEventInput, type DocsMcpHttpHandlers, type DocsMcpNavigationNode, type DocsMcpNavigationTree, type DocsMcpPage, type DocsMcpResolvedConfig, type DocsMcpSource, type DocsSearchAdapter, type DocsSearchAdapterContext, type DocsSearchAdapterFactory, type DocsSearchConfig, type DocsSearchDocument, type DocsSearchQuery, type DocsSearchResult, type DocsSearchSourcePage, type McpDocsSearchConfig, type PromptAction, type PromptProviderChoice, type ResolvedApiReferenceConfig, type ResolvedDocsAnalyticsConfig, type SerializedOpenDocsProvider, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsSearchDocuments, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAnalyticsEvent, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, resolveApiReferenceConfig, resolveApiReferenceRenderer, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProviders };
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, i as createMcpSearchAdapter, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments } from "./search-
|
|
2
|
-
import { a as sanitizePromptText, c as serializeOpenDocsProviders, d as buildApiReferenceOpenApiDocument, f as buildApiReferenceOpenApiDocumentAsync, g as resolveApiReferenceRenderer, h as resolveApiReferenceConfig, i as resolvePromptProviderChoices, l as buildApiReferenceHtmlDocument, m as buildApiReferenceScalarCss, n as normalizePromptProviderName, o as serializeDocsIcon, p as buildApiReferencePageTitle, r as parsePromptStringArray, s as serializeDocsIconRegistry, t as DEFAULT_PROMPT_PROVIDER_TEMPLATES, u as buildApiReferenceHtmlDocumentAsync } from "./prompt-utils-
|
|
1
|
+
import { a as createSimpleSearchAdapter, c as resolveSearchRequestConfig, i as createMcpSearchAdapter, n as createAlgoliaSearchAdapter, o as createTypesenseSearchAdapter, r as createCustomSearchAdapter, s as performDocsSearch, t as buildDocsSearchDocuments, v as emitDocsAnalyticsEvent, y as resolveDocsAnalyticsConfig } from "./search-Ds3jiS2n.mjs";
|
|
2
|
+
import { a as sanitizePromptText, c as serializeOpenDocsProviders, d as buildApiReferenceOpenApiDocument, f as buildApiReferenceOpenApiDocumentAsync, g as resolveApiReferenceRenderer, h as resolveApiReferenceConfig, i as resolvePromptProviderChoices, l as buildApiReferenceHtmlDocument, m as buildApiReferenceScalarCss, n as normalizePromptProviderName, o as serializeDocsIcon, p as buildApiReferencePageTitle, r as parsePromptStringArray, s as serializeDocsIconRegistry, t as DEFAULT_PROMPT_PROVIDER_TEMPLATES, u as buildApiReferenceHtmlDocumentAsync } from "./prompt-utils-8nmFLQVH.mjs";
|
|
3
3
|
import { createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
|
|
4
4
|
|
|
5
|
-
export { DEFAULT_PROMPT_PROVIDER_TEMPLATES, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsSearchDocuments, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, resolveApiReferenceConfig, resolveApiReferenceRenderer, resolveDocsMcpConfig, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProviders };
|
|
5
|
+
export { DEFAULT_PROMPT_PROVIDER_TEMPLATES, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsSearchDocuments, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAnalyticsEvent, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, resolveApiReferenceConfig, resolveApiReferenceRenderer, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProviders };
|