@farming-labs/docs 0.2.35 → 0.2.36

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.
@@ -2,7 +2,7 @@ import "./reading-time-CPAy1SWO.mjs";
2
2
  import "./search-CCLIVI86.mjs";
3
3
  import "./agent-B6szuz_8.mjs";
4
4
  import "./robots-CVoC0w0i.mjs";
5
- import "./sitemap-server-D39E3W5j.mjs";
5
+ import "./sitemap-server-BKS8ZcqC.mjs";
6
6
  import "./config-De5z-2LK.mjs";
7
7
  import { a as readPageTokenBudget, i as printAgentCompactHelp, n as inspectAgentCompactionState, o as scanDocsPageTargets, r as parseAgentCompactArgs, t as compactAgentDocs } from "./codeblocks-CZ4ksbeK.mjs";
8
8
 
@@ -1,6 +1,6 @@
1
1
  import "./search-CCLIVI86.mjs";
2
2
  import { $ as renderDocsAgentsDocument, C as DEFAULT_OPENAPI_SCHEMA_ROUTE, a as DEFAULT_AGENT_MD_ROUTE, it as resolveDocsAgentFeedbackConfig, n as DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE, o as DEFAULT_AGENT_MD_WELL_KNOWN_ROUTE, t as DEFAULT_AGENTS_MD_ROUTE } from "./agent-B6szuz_8.mjs";
3
- import { S as resolveApiReferenceConfig } from "./sitemap-server-D39E3W5j.mjs";
3
+ import { w as resolveApiReferenceConfig } from "./sitemap-server-BKS8ZcqC.mjs";
4
4
  import { resolveDocsMcpConfig } from "./mcp.mjs";
5
5
  import "./server.mjs";
6
6
  import { c as readNavTitle, f as readTopLevelStringProperty, i as loadDocsConfigModule, o as readBooleanProperty, p as resolveDocsConfigPath, t as extractNestedObjectLiteral, u as readStringProperty } from "./config-De5z-2LK.mjs";
@@ -138,10 +138,10 @@ async function main() {
138
138
  printCloudHelp();
139
139
  process.exit(1);
140
140
  } else if (parsedCommand.command === "mcp") {
141
- const { runMcp } = await import("../mcp-Dv249k-7.mjs");
141
+ const { runMcp } = await import("../mcp-ZHerPGdA.mjs");
142
142
  await runMcp(mcpOptions);
143
143
  } else if (parsedCommand.command === "agent" && subcommand === "compact") {
144
- const { compactAgentDocs, parseAgentCompactArgs, printAgentCompactHelp } = await import("../agent-zVlrE00k.mjs");
144
+ const { compactAgentDocs, parseAgentCompactArgs, printAgentCompactHelp } = await import("../agent-ClpV1v42.mjs");
145
145
  const agentCompactOptions = parseAgentCompactArgs(args.slice(2));
146
146
  if (agentCompactOptions.help) {
147
147
  printAgentCompactHelp();
@@ -151,11 +151,11 @@ async function main() {
151
151
  } else if (parsedCommand.command === "agent") {
152
152
  console.error(pc.red(`Unknown agent subcommand: ${subcommand ?? "(missing)"}`));
153
153
  console.error();
154
- const { printAgentCompactHelp } = await import("../agent-zVlrE00k.mjs");
154
+ const { printAgentCompactHelp } = await import("../agent-ClpV1v42.mjs");
155
155
  printAgentCompactHelp();
156
156
  process.exit(1);
157
157
  } else if (parsedCommand.command === "agents" && subcommand === "generate") {
158
- const { generateAgents, parseAgentsGenerateArgs, printAgentsGenerateHelp } = await import("../agents-hFMgXu-b.mjs");
158
+ const { generateAgents, parseAgentsGenerateArgs, printAgentsGenerateHelp } = await import("../agents-DYapIiBa.mjs");
159
159
  const agentsOptions = parseAgentsGenerateArgs(args.slice(2));
160
160
  if (agentsOptions.help) {
161
161
  printAgentsGenerateHelp();
@@ -165,11 +165,11 @@ async function main() {
165
165
  } else if (parsedCommand.command === "agents") {
166
166
  console.error(pc.red(`Unknown agents subcommand: ${subcommand ?? "(missing)"}`));
167
167
  console.error();
168
- const { printAgentsGenerateHelp } = await import("../agents-hFMgXu-b.mjs");
168
+ const { printAgentsGenerateHelp } = await import("../agents-DYapIiBa.mjs");
169
169
  printAgentsGenerateHelp();
170
170
  process.exit(1);
171
171
  } else if (parsedCommand.command === "doctor") {
172
- const { parseDoctorArgs, printDoctorHelp, runDoctor } = await import("../doctor-5gztwf8Q.mjs");
172
+ const { parseDoctorArgs, printDoctorHelp, runDoctor } = await import("../doctor-UyXx1j5A.mjs");
173
173
  const doctorOptions = parseDoctorArgs(args.slice(1));
174
174
  if (doctorOptions.help) {
175
175
  printDoctorHelp();
@@ -199,7 +199,7 @@ async function main() {
199
199
  printCodeBlocksValidateHelp();
200
200
  process.exit(1);
201
201
  } else if (parsedCommand.command === "search" && subcommand === "sync") {
202
- const { syncSearch } = await import("../search-CV7h1sFR.mjs");
202
+ const { syncSearch } = await import("../search-COEZQr_e.mjs");
203
203
  await syncSearch(searchSyncOptions);
204
204
  } else if (parsedCommand.command === "search") {
205
205
  console.error(pc.red(`Unknown search subcommand: ${subcommand ?? "(missing)"}`));
@@ -207,7 +207,7 @@ async function main() {
207
207
  printHelp();
208
208
  process.exit(1);
209
209
  } else if (parsedCommand.command === "sitemap" && subcommand === "generate") {
210
- const { generateSitemap, parseSitemapGenerateArgs, printSitemapGenerateHelp } = await import("../sitemap-Dy1DPejr.mjs");
210
+ const { generateSitemap, parseSitemapGenerateArgs, printSitemapGenerateHelp } = await import("../sitemap-ErRkKP-K.mjs");
211
211
  const sitemapOptions = parseSitemapGenerateArgs(args.slice(2));
212
212
  if (sitemapOptions.help) {
213
213
  printSitemapGenerateHelp();
@@ -217,7 +217,7 @@ async function main() {
217
217
  } else if (parsedCommand.command === "sitemap") {
218
218
  console.error(pc.red(`Unknown sitemap subcommand: ${subcommand ?? "(missing)"}`));
219
219
  console.error();
220
- const { printSitemapGenerateHelp } = await import("../sitemap-Dy1DPejr.mjs");
220
+ const { printSitemapGenerateHelp } = await import("../sitemap-ErRkKP-K.mjs");
221
221
  printSitemapGenerateHelp();
222
222
  process.exit(1);
223
223
  } else if (parsedCommand.command === "robots" && subcommand === "generate") {
@@ -2,7 +2,7 @@ import "./reading-time-CPAy1SWO.mjs";
2
2
  import "./search-CCLIVI86.mjs";
3
3
  import { Ct as DEFAULT_SITEMAP_XML_ROUTE, P as buildDocsMcpEndpointCandidates, S as DEFAULT_MCP_WELL_KNOWN_ROUTE, St as DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, T as DEFAULT_SKILL_MD_WELL_KNOWN_ROUTE, b as DEFAULT_MCP_PUBLIC_ROUTE, c as DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE, h as DEFAULT_LLMS_FULL_TXT_ROUTE, i as DEFAULT_AGENT_FEEDBACK_ROUTE, kt as resolveDocsSitemapConfig, l as DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE, n as DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE, t as DEFAULT_AGENTS_MD_ROUTE, v as DEFAULT_LLMS_TXT_ROUTE, w as DEFAULT_SKILL_MD_ROUTE, xt as DEFAULT_SITEMAP_MD_ROUTE } from "./agent-B6szuz_8.mjs";
4
4
  import { a as analyzeDocsRobotsTxt, n as DEFAULT_ROBOTS_TXT_ROUTE, u as resolveDocsRobotsConfig } from "./robots-CVoC0w0i.mjs";
5
- import "./sitemap-server-D39E3W5j.mjs";
5
+ import "./sitemap-server-BKS8ZcqC.mjs";
6
6
  import { createFilesystemDocsMcpSource, resolveDocsMcpConfig } from "./mcp.mjs";
7
7
  import "./server.mjs";
8
8
  import { a as loadProjectEnv, c as readNavTitle, f as readTopLevelStringProperty, i as loadDocsConfigModule, m as resolveDocsContentDir, o as readBooleanProperty, p as resolveDocsConfigPath, r as extractTopLevelConfigObject, t as extractNestedObjectLiteral } from "./config-De5z-2LK.mjs";
@@ -1,6 +1,6 @@
1
1
  import "./search-CCLIVI86.mjs";
2
2
  import "./agent-B6szuz_8.mjs";
3
- import "./sitemap-server-D39E3W5j.mjs";
3
+ import "./sitemap-server-BKS8ZcqC.mjs";
4
4
  import { createFilesystemDocsMcpSource, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
5
5
  import "./server.mjs";
6
6
  import { c as readNavTitle, m as resolveDocsContentDir, n as extractObjectLiteral, o as readBooleanProperty, p as resolveDocsConfigPath, u as readStringProperty } from "./config-De5z-2LK.mjs";
@@ -1,6 +1,6 @@
1
1
  import { n as buildDocsSearchDocuments, r as createAlgoliaSearchAdapter, s as createTypesenseSearchAdapter } from "./search-CCLIVI86.mjs";
2
2
  import "./agent-B6szuz_8.mjs";
3
- import "./sitemap-server-D39E3W5j.mjs";
3
+ import "./sitemap-server-BKS8ZcqC.mjs";
4
4
  import { createFilesystemDocsMcpSource } from "./mcp.mjs";
5
5
  import "./server.mjs";
6
6
  import { a as loadProjectEnv, f as readTopLevelStringProperty, m as resolveDocsContentDir, p as resolveDocsConfigPath } from "./config-De5z-2LK.mjs";
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as DocsObservabilityEvent, A as DocsAskAIMcpConfig, D as DocsAskAIFeedbackData, E as DocsAskAIFeedbackConfig, O as DocsAskAIFeedbackMessage, Q as DocsObservabilityConfig, Rt as McpDocsSearchConfig, W as DocsConfig, _ as DocsAgentTraceStatus, _t as DocsSearchQuery, a as ApiReferenceRenderer, at as DocsReviewRulesConfig, b as DocsAnalyticsEventInput, bt as DocsSearchSourcePage, dt as DocsSearchAdapterContext, et as DocsObservabilityEventInput, ft as DocsSearchAdapterFactory, g as DocsAgentTraceEventType, h as DocsAgentTraceEventInput, ht as DocsSearchDocument, it as DocsReviewConfig, k as DocsAskAIFeedbackValue, mt as DocsSearchConfig, rt as DocsReviewCiMode, ut as DocsSearchAdapter, v as DocsAnalyticsConfig, vt as DocsSearchResult, xt as DocsSitemapConfig, y as DocsAnalyticsEvent } from "./types-DKCNILor.mjs";
1
+ import { $ as DocsObservabilityEvent, A as DocsAskAIMcpConfig, D as DocsAskAIFeedbackData, E as DocsAskAIFeedbackConfig, M as DocsCloudConfig, O as DocsAskAIFeedbackMessage, Q as DocsObservabilityConfig, Rt as McpDocsSearchConfig, W as DocsConfig, _ as DocsAgentTraceStatus, _t as DocsSearchQuery, a as ApiReferenceRenderer, at as DocsReviewRulesConfig, b as DocsAnalyticsEventInput, bt as DocsSearchSourcePage, dt as DocsSearchAdapterContext, et as DocsObservabilityEventInput, ft as DocsSearchAdapterFactory, g as DocsAgentTraceEventType, h as DocsAgentTraceEventInput, ht as DocsSearchDocument, it as DocsReviewConfig, k as DocsAskAIFeedbackValue, mt as DocsSearchConfig, rt as DocsReviewCiMode, t as AIConfig, ut as DocsSearchAdapter, v as DocsAnalyticsConfig, vt as DocsSearchResult, xt as DocsSitemapConfig, y as DocsAnalyticsEvent } from "./types-DKCNILor.mjs";
2
2
  import { $ as createDocsAgentTraceId, A as resolveDocsSitemapRequest, B as normalizePromptProviderName, C as buildDocsSitemapManifest, D as renderDocsSitemapXml, E as renderDocsSitemapMarkdown, F as DEFAULT_PROMPT_PROVIDER_TEMPLATES, G as serializeDocsIconRegistry, H as resolvePromptProviderChoices, I as PromptAction, J as DOCS_AGENT_TRACE_EVENT_TYPES, K as serializeOpenDocsProvider, L as PromptProviderChoice, M as DEFAULT_OPEN_DOCS_PROMPT, N as DEFAULT_OPEN_DOCS_PROVIDER_IDS, O as resolveDocsSitemapConfig, P as DEFAULT_OPEN_DOCS_TARGET, Q as createDocsAgentTraceContext, R as SerializeOpenDocsProviderOptions, S as DocsSitemapResolvedConfig, T as readDocsSitemapManifestFromContentMap, U as sanitizePromptText, V as parsePromptStringArray, W as serializeDocsIcon, X as ResolvedDocsAnalyticsConfig, Y as DocsAgentTraceContext, Z as ResolvedDocsObservabilityConfig, _ as DEFAULT_SITEMAP_XML_ROUTE, a as createMcpSearchAdapter, at as resolveDocsObservabilityConfig, b as DocsSitemapManifestPage, c as formatDocsAskAIPackageHints, d as resolveAskAISearchRequestConfig, et as emitDocsAgentTraceEvent, f as resolveSearchRequestConfig, g as DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, h as DEFAULT_SITEMAP_MD_ROUTE, i as createCustomSearchAdapter, it as resolveDocsAnalyticsConfig, j as toDocsSitemapMarkdownUrl, k as resolveDocsSitemapPageLastmod, l as inferDocsAskAIPackageHints, m as DEFAULT_SITEMAP_MD_DOCS_ROUTE, n as buildDocsSearchDocuments, nt as emitDocsObservabilityEvent, o as createSimpleSearchAdapter, p as DEFAULT_SITEMAP_MANIFEST_PATH, q as serializeOpenDocsProviders, r as createAlgoliaSearchAdapter, rt as getDocsRequestAnalyticsProperties, s as createTypesenseSearchAdapter, t as buildDocsAskAIContext, tt as emitDocsAnalyticsEvent, u as performDocsSearch, v as DocsSitemapFormat, w as createDocsSitemapResponse, x as DocsSitemapPageInput, y as DocsSitemapManifest, z as SerializedOpenDocsProvider } from "./search-BEe1Gdu7.mjs";
3
3
  import { DocsMcpCodeExample, DocsMcpConfigSchema, DocsMcpConfigSchemaOption, DocsMcpDocsList, DocsMcpDocsPageSummary, DocsMcpDocsSection, DocsMcpHttpHandlers, DocsMcpNavigationNode, DocsMcpNavigationTree, DocsMcpPage, DocsMcpResolvedConfig, DocsMcpSource, createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
4
4
 
@@ -128,7 +128,27 @@ declare function buildDocsReviewWorkflowPathFilters(options: {
128
128
  configContent?: string;
129
129
  }): string[];
130
130
  //#endregion
131
+ //#region src/cloud-ask-ai.d.ts
132
+ interface DocsCloudAskAIConfig {
133
+ ai?: Pick<AIConfig, "docsUrl" | "enabled" | "provider" | "stream">;
134
+ analytics?: boolean | DocsAnalyticsConfig;
135
+ cloud?: DocsCloudConfig;
136
+ }
137
+ interface DocsCloudAskAIResponseOptions {
138
+ config?: DocsCloudAskAIConfig;
139
+ /**
140
+ * Runtime env map for frameworks that expose environment variables outside
141
+ * `process.env`, for example SvelteKit's `$env/dynamic/private`.
142
+ */
143
+ env?: Record<string, string | undefined>;
144
+ fetch?: typeof fetch;
145
+ publicBaseUrl?: string;
146
+ locale?: string;
147
+ }
148
+ declare function isDocsCloudAskAIProvider(config: Pick<AIConfig, "enabled" | "provider"> | undefined): boolean;
149
+ declare function createDocsCloudAskAIResponse(request: Request, options?: DocsCloudAskAIResponseOptions): Promise<Response>;
150
+ //#endregion
131
151
  //#region src/sitemap-server.d.ts
132
152
  declare function readDocsSitemapManifest(rootDir: string, sitemap?: boolean | DocsSitemapConfig): DocsSitemapManifest | null;
133
153
  //#endregion
134
- export { type ApiReferenceFramework, type ApiReferenceOpenApiDiscovery, type ApiReferenceRenderer, type ApiReferenceRoute, DEFAULT_API_REFERENCE_OPENAPI_ROUTE, DEFAULT_DOCS_REVIEW_SCORE_THRESHOLD, DEFAULT_DOCS_REVIEW_WORKFLOW_PATH, DEFAULT_OPEN_DOCS_PROMPT, DEFAULT_OPEN_DOCS_PROVIDER_IDS, DEFAULT_OPEN_DOCS_TARGET, DEFAULT_PROMPT_PROVIDER_TEMPLATES, DEFAULT_SITEMAP_MANIFEST_PATH, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DEFAULT_SITEMAP_MD_ROUTE, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, DEFAULT_SITEMAP_XML_ROUTE, DOCS_AGENT_TRACE_EVENT_TYPES, type DocsAgentTraceContext, type DocsAgentTraceEventInput, type DocsAgentTraceEventType, type DocsAgentTraceStatus, type DocsAnalyticsConfig, type DocsAnalyticsEvent, type DocsAnalyticsEventInput, type DocsAskAIFeedbackConfig, type DocsAskAIFeedbackData, type DocsAskAIFeedbackMessage, type DocsAskAIFeedbackValue, type DocsAskAIMcpConfig, type DocsMcpCodeExample, type DocsMcpConfigSchema, type DocsMcpConfigSchemaOption, type DocsMcpDocsList, type DocsMcpDocsPageSummary, type DocsMcpDocsSection, type DocsMcpHttpHandlers, type DocsMcpNavigationNode, type DocsMcpNavigationTree, type DocsMcpPage, type DocsMcpResolvedConfig, type DocsMcpSource, type DocsObservabilityConfig, type DocsObservabilityEvent, type DocsObservabilityEventInput, type DocsSearchAdapter, type DocsSearchAdapterContext, type DocsSearchAdapterFactory, type DocsSearchConfig, type DocsSearchDocument, type DocsSearchQuery, type DocsSearchResult, type DocsSearchSourcePage, type DocsSitemapFormat, type DocsSitemapManifest, type DocsSitemapManifestPage, type DocsSitemapPageInput, type DocsSitemapResolvedConfig, type McpDocsSearchConfig, type PromptAction, type PromptProviderChoice, type ResolvedApiReferenceConfig, type ResolvedDocsAnalyticsConfig, type ResolvedDocsObservabilityConfig, type ResolvedDocsReviewConfig, type SerializeOpenDocsProviderOptions, type SerializedOpenDocsProvider, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsAskAIContext, buildDocsReviewWorkflow, buildDocsReviewWorkflowPathFilters, buildDocsSearchDocuments, buildDocsSitemapManifest, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMcpHttpHandler, createDocsMcpServer, createDocsSitemapResponse, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsObservabilityEvent, ensureDocsReviewWorkflow, formatDocsAskAIPackageHints, getDocsRequestAnalyticsProperties, inferDocsAskAIPackageHints, isApiReferenceOpenApiRequest, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, readDocsReviewConfigFromSource, readDocsSitemapManifest, readDocsSitemapManifestFromContentMap, remarkCodeGroup, renderDocsSitemapMarkdown, renderDocsSitemapXml, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveApiReferenceRenderer, resolveAskAISearchRequestConfig, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolveDocsObservabilityConfig, resolveDocsReviewConfig, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsSitemapRequest, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProvider, serializeOpenDocsProviders, toDocsSitemapMarkdownUrl };
154
+ export { type ApiReferenceFramework, type ApiReferenceOpenApiDiscovery, type ApiReferenceRenderer, type ApiReferenceRoute, DEFAULT_API_REFERENCE_OPENAPI_ROUTE, DEFAULT_DOCS_REVIEW_SCORE_THRESHOLD, DEFAULT_DOCS_REVIEW_WORKFLOW_PATH, DEFAULT_OPEN_DOCS_PROMPT, DEFAULT_OPEN_DOCS_PROVIDER_IDS, DEFAULT_OPEN_DOCS_TARGET, DEFAULT_PROMPT_PROVIDER_TEMPLATES, DEFAULT_SITEMAP_MANIFEST_PATH, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DEFAULT_SITEMAP_MD_ROUTE, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, DEFAULT_SITEMAP_XML_ROUTE, DOCS_AGENT_TRACE_EVENT_TYPES, type DocsAgentTraceContext, type DocsAgentTraceEventInput, type DocsAgentTraceEventType, type DocsAgentTraceStatus, type DocsAnalyticsConfig, type DocsAnalyticsEvent, type DocsAnalyticsEventInput, type DocsAskAIFeedbackConfig, type DocsAskAIFeedbackData, type DocsAskAIFeedbackMessage, type DocsAskAIFeedbackValue, type DocsAskAIMcpConfig, type DocsCloudAskAIConfig, type DocsCloudAskAIResponseOptions, type DocsMcpCodeExample, type DocsMcpConfigSchema, type DocsMcpConfigSchemaOption, type DocsMcpDocsList, type DocsMcpDocsPageSummary, type DocsMcpDocsSection, type DocsMcpHttpHandlers, type DocsMcpNavigationNode, type DocsMcpNavigationTree, type DocsMcpPage, type DocsMcpResolvedConfig, type DocsMcpSource, type DocsObservabilityConfig, type DocsObservabilityEvent, type DocsObservabilityEventInput, type DocsSearchAdapter, type DocsSearchAdapterContext, type DocsSearchAdapterFactory, type DocsSearchConfig, type DocsSearchDocument, type DocsSearchQuery, type DocsSearchResult, type DocsSearchSourcePage, type DocsSitemapFormat, type DocsSitemapManifest, type DocsSitemapManifestPage, type DocsSitemapPageInput, type DocsSitemapResolvedConfig, type McpDocsSearchConfig, type PromptAction, type PromptProviderChoice, type ResolvedApiReferenceConfig, type ResolvedDocsAnalyticsConfig, type ResolvedDocsObservabilityConfig, type ResolvedDocsReviewConfig, type SerializeOpenDocsProviderOptions, type SerializedOpenDocsProvider, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsAskAIContext, buildDocsReviewWorkflow, buildDocsReviewWorkflowPathFilters, buildDocsSearchDocuments, buildDocsSitemapManifest, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, createDocsMcpServer, createDocsSitemapResponse, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsObservabilityEvent, ensureDocsReviewWorkflow, formatDocsAskAIPackageHints, getDocsRequestAnalyticsProperties, inferDocsAskAIPackageHints, isApiReferenceOpenApiRequest, isDocsCloudAskAIProvider, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, readDocsReviewConfigFromSource, readDocsSitemapManifest, readDocsSitemapManifestFromContentMap, remarkCodeGroup, renderDocsSitemapMarkdown, renderDocsSitemapXml, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveApiReferenceRenderer, resolveAskAISearchRequestConfig, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolveDocsObservabilityConfig, resolveDocsReviewConfig, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsSitemapRequest, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProvider, serializeOpenDocsProviders, toDocsSitemapMarkdownUrl };
package/dist/server.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { F as emitDocsAnalyticsEvent, I as emitDocsObservabilityEvent, L as getDocsRequestAnalyticsProperties, M as createDocsAgentTraceContext, N as createDocsAgentTraceId, P as emitDocsAgentTraceEvent, R as resolveDocsAnalyticsConfig, a as createMcpSearchAdapter, c as formatDocsAskAIPackageHints, d as resolveAskAISearchRequestConfig, f as resolveSearchRequestConfig, i as createCustomSearchAdapter, j as DOCS_AGENT_TRACE_EVENT_TYPES, l as inferDocsAskAIPackageHints, n as buildDocsSearchDocuments, o as createSimpleSearchAdapter, r as createAlgoliaSearchAdapter, s as createTypesenseSearchAdapter, t as buildDocsAskAIContext, u as performDocsSearch, z as resolveDocsObservabilityConfig } from "./search-CCLIVI86.mjs";
2
2
  import { At as resolveDocsSitemapPageLastmod, Ct as DEFAULT_SITEMAP_XML_ROUTE, Dt as renderDocsSitemapMarkdown, Et as readDocsSitemapManifestFromContentMap, Mt as toDocsSitemapMarkdownUrl, Ot as renderDocsSitemapXml, St as DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, Tt as createDocsSitemapResponse, bt as DEFAULT_SITEMAP_MD_DOCS_ROUTE, jt as resolveDocsSitemapRequest, kt as resolveDocsSitemapConfig, wt as buildDocsSitemapManifest, xt as DEFAULT_SITEMAP_MD_ROUTE, yt as DEFAULT_SITEMAP_MANIFEST_PATH } from "./agent-B6szuz_8.mjs";
3
- import { C as resolveApiReferenceOpenApiDiscovery, S as resolveApiReferenceConfig, T as remarkCodeGroup, _ as buildApiReferenceOpenApiDocument, a as DEFAULT_PROMPT_PROVIDER_TEMPLATES, b as buildApiReferenceScalarCss, c as resolvePromptProviderChoices, d as serializeDocsIconRegistry, f as serializeOpenDocsProvider, g as buildApiReferenceHtmlDocumentAsync, h as buildApiReferenceHtmlDocument, i as DEFAULT_OPEN_DOCS_TARGET, l as sanitizePromptText, m as DEFAULT_API_REFERENCE_OPENAPI_ROUTE, n as DEFAULT_OPEN_DOCS_PROMPT, o as normalizePromptProviderName, p as serializeOpenDocsProviders, r as DEFAULT_OPEN_DOCS_PROVIDER_IDS, s as parsePromptStringArray, t as readDocsSitemapManifest, u as serializeDocsIcon, v as buildApiReferenceOpenApiDocumentAsync, w as resolveApiReferenceRenderer, x as isApiReferenceOpenApiRequest, y as buildApiReferencePageTitle } from "./sitemap-server-D39E3W5j.mjs";
3
+ import { C as isApiReferenceOpenApiRequest, D as remarkCodeGroup, E as resolveApiReferenceRenderer, S as buildApiReferenceScalarCss, T as resolveApiReferenceOpenApiDiscovery, _ as buildApiReferenceHtmlDocument, a as DEFAULT_PROMPT_PROVIDER_TEMPLATES, b as buildApiReferenceOpenApiDocumentAsync, c as resolvePromptProviderChoices, d as serializeDocsIconRegistry, f as serializeOpenDocsProvider, g as DEFAULT_API_REFERENCE_OPENAPI_ROUTE, h as isDocsCloudAskAIProvider, i as DEFAULT_OPEN_DOCS_TARGET, l as sanitizePromptText, m as createDocsCloudAskAIResponse, n as DEFAULT_OPEN_DOCS_PROMPT, o as normalizePromptProviderName, p as serializeOpenDocsProviders, r as DEFAULT_OPEN_DOCS_PROVIDER_IDS, s as parsePromptStringArray, t as readDocsSitemapManifest, u as serializeDocsIcon, v as buildApiReferenceHtmlDocumentAsync, w as resolveApiReferenceConfig, x as buildApiReferencePageTitle, y as buildApiReferenceOpenApiDocument } from "./sitemap-server-BKS8ZcqC.mjs";
4
4
  import { a as ensureDocsReviewWorkflow, i as buildDocsReviewWorkflowPathFilters, n as DEFAULT_DOCS_REVIEW_WORKFLOW_PATH, o as readDocsReviewConfigFromSource, r as buildDocsReviewWorkflow, s as resolveDocsReviewConfig, t as DEFAULT_DOCS_REVIEW_SCORE_THRESHOLD } from "./review-CJD85JTm.mjs";
5
5
  import { createDocsMcpHttpHandler, createDocsMcpServer, createFilesystemDocsMcpSource, normalizeDocsMcpRoute, resolveDocsMcpConfig, runDocsMcpStdio } from "./mcp.mjs";
6
6
 
7
- export { DEFAULT_API_REFERENCE_OPENAPI_ROUTE, DEFAULT_DOCS_REVIEW_SCORE_THRESHOLD, DEFAULT_DOCS_REVIEW_WORKFLOW_PATH, DEFAULT_OPEN_DOCS_PROMPT, DEFAULT_OPEN_DOCS_PROVIDER_IDS, DEFAULT_OPEN_DOCS_TARGET, DEFAULT_PROMPT_PROVIDER_TEMPLATES, DEFAULT_SITEMAP_MANIFEST_PATH, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DEFAULT_SITEMAP_MD_ROUTE, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, DEFAULT_SITEMAP_XML_ROUTE, DOCS_AGENT_TRACE_EVENT_TYPES, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsAskAIContext, buildDocsReviewWorkflow, buildDocsReviewWorkflowPathFilters, buildDocsSearchDocuments, buildDocsSitemapManifest, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsMcpHttpHandler, createDocsMcpServer, createDocsSitemapResponse, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsObservabilityEvent, ensureDocsReviewWorkflow, formatDocsAskAIPackageHints, getDocsRequestAnalyticsProperties, inferDocsAskAIPackageHints, isApiReferenceOpenApiRequest, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, readDocsReviewConfigFromSource, readDocsSitemapManifest, readDocsSitemapManifestFromContentMap, remarkCodeGroup, renderDocsSitemapMarkdown, renderDocsSitemapXml, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveApiReferenceRenderer, resolveAskAISearchRequestConfig, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolveDocsObservabilityConfig, resolveDocsReviewConfig, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsSitemapRequest, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProvider, serializeOpenDocsProviders, toDocsSitemapMarkdownUrl };
7
+ export { DEFAULT_API_REFERENCE_OPENAPI_ROUTE, DEFAULT_DOCS_REVIEW_SCORE_THRESHOLD, DEFAULT_DOCS_REVIEW_WORKFLOW_PATH, DEFAULT_OPEN_DOCS_PROMPT, DEFAULT_OPEN_DOCS_PROVIDER_IDS, DEFAULT_OPEN_DOCS_TARGET, DEFAULT_PROMPT_PROVIDER_TEMPLATES, DEFAULT_SITEMAP_MANIFEST_PATH, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DEFAULT_SITEMAP_MD_ROUTE, DEFAULT_SITEMAP_MD_WELL_KNOWN_ROUTE, DEFAULT_SITEMAP_XML_ROUTE, DOCS_AGENT_TRACE_EVENT_TYPES, buildApiReferenceHtmlDocument, buildApiReferenceHtmlDocumentAsync, buildApiReferenceOpenApiDocument, buildApiReferenceOpenApiDocumentAsync, buildApiReferencePageTitle, buildApiReferenceScalarCss, buildDocsAskAIContext, buildDocsReviewWorkflow, buildDocsReviewWorkflowPathFilters, buildDocsSearchDocuments, buildDocsSitemapManifest, createAlgoliaSearchAdapter, createCustomSearchAdapter, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCloudAskAIResponse, createDocsMcpHttpHandler, createDocsMcpServer, createDocsSitemapResponse, createFilesystemDocsMcpSource, createMcpSearchAdapter, createSimpleSearchAdapter, createTypesenseSearchAdapter, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsObservabilityEvent, ensureDocsReviewWorkflow, formatDocsAskAIPackageHints, getDocsRequestAnalyticsProperties, inferDocsAskAIPackageHints, isApiReferenceOpenApiRequest, isDocsCloudAskAIProvider, normalizeDocsMcpRoute, normalizePromptProviderName, parsePromptStringArray, performDocsSearch, readDocsReviewConfigFromSource, readDocsSitemapManifest, readDocsSitemapManifestFromContentMap, remarkCodeGroup, renderDocsSitemapMarkdown, renderDocsSitemapXml, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveApiReferenceRenderer, resolveAskAISearchRequestConfig, resolveDocsAnalyticsConfig, resolveDocsMcpConfig, resolveDocsObservabilityConfig, resolveDocsReviewConfig, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsSitemapRequest, resolvePromptProviderChoices, resolveSearchRequestConfig, runDocsMcpStdio, sanitizePromptText, serializeDocsIcon, serializeDocsIconRegistry, serializeOpenDocsProvider, serializeOpenDocsProviders, toDocsSitemapMarkdownUrl };
@@ -1,6 +1,6 @@
1
1
  import "./search-CCLIVI86.mjs";
2
2
  import { Dt as renderDocsSitemapMarkdown, Ot as renderDocsSitemapXml, kt as resolveDocsSitemapConfig, wt as buildDocsSitemapManifest } from "./agent-B6szuz_8.mjs";
3
- import "./sitemap-server-D39E3W5j.mjs";
3
+ import "./sitemap-server-BKS8ZcqC.mjs";
4
4
  import { createFilesystemDocsMcpSource } from "./mcp.mjs";
5
5
  import "./server.mjs";
6
6
  import { c as readNavTitle, f as readTopLevelStringProperty, i as loadDocsConfigModule, m as resolveDocsContentDir, o as readBooleanProperty, p as resolveDocsConfigPath, t as extractNestedObjectLiteral, u as readStringProperty } from "./config-De5z-2LK.mjs";
@@ -1,3 +1,4 @@
1
+ import { F as emitDocsAnalyticsEvent } from "./search-CCLIVI86.mjs";
1
2
  import { kt as resolveDocsSitemapConfig } from "./agent-B6szuz_8.mjs";
2
3
  import { createRequire } from "node:module";
3
4
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
@@ -958,6 +959,378 @@ function humanizeSegment(value) {
958
959
  return value.replace(/^\{/, "").replace(/\}$/, "").replace(/^\[\[?\.{3}/, "").replace(/^\[/, "").replace(/\]\]?$/, "").replace(/^\$/, "").replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
959
960
  }
960
961
 
962
+ //#endregion
963
+ //#region src/cloud-ask-ai.ts
964
+ const DEFAULT_DOCS_CLOUD_API_BASE_URL = "https://api.farming-labs.dev";
965
+ const DEFAULT_DOCS_CLOUD_API_KEY_ENV = "DOCS_CLOUD_API_KEY";
966
+ const DOCS_CLOUD_PROJECT_ID_ENVS = [
967
+ "PUBLIC_DOCS_CLOUD_PROJECT_ID",
968
+ "DOCS_CLOUD_PROJECT_ID",
969
+ "NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID"
970
+ ];
971
+ const DOCS_CLOUD_API_BASE_URL_ENVS = [
972
+ "DOCS_CLOUD_API_BASE_URL",
973
+ "DOCS_CLOUD_API_URL",
974
+ "PUBLIC_DOCS_CLOUD_URL",
975
+ "NEXT_PUBLIC_DOCS_CLOUD_URL"
976
+ ];
977
+ const DOCS_CLOUD_FOOTER_GUARD_CHARS = 256;
978
+ const docsCloudRelevantDocsPattern = /\n{2,}(?:-{3,}|\*{3,}|_{3,})[ \t]*\n{1,3}(?:\*\*)?Relevant docs(?:\*\*)?[ \t]*/i;
979
+ function isPlainObject(value) {
980
+ return typeof value === "object" && value !== null && !Array.isArray(value);
981
+ }
982
+ function readEnv(name, env) {
983
+ const trimmed = (env?.[name] ?? (typeof process !== "undefined" ? process.env?.[name] : void 0))?.trim();
984
+ return trimmed ? trimmed : void 0;
985
+ }
986
+ function readFirstEnv(names, env) {
987
+ for (const name of names) {
988
+ const value = readEnv(name, env);
989
+ if (value) return value;
990
+ }
991
+ }
992
+ function resolveDocsCloudApiBaseUrl(env) {
993
+ return (readFirstEnv(DOCS_CLOUD_API_BASE_URL_ENVS, env) ?? DEFAULT_DOCS_CLOUD_API_BASE_URL).replace(/\/+$/, "");
994
+ }
995
+ function resolveDocsCloudProjectId(env) {
996
+ return readFirstEnv(DOCS_CLOUD_PROJECT_ID_ENVS, env);
997
+ }
998
+ function resolveDocsCloudApiKey(cloudConfig, env) {
999
+ const envName = cloudConfig?.apiKey?.env?.trim() || DEFAULT_DOCS_CLOUD_API_KEY_ENV;
1000
+ return {
1001
+ envName,
1002
+ apiKey: readEnv(envName, env)
1003
+ };
1004
+ }
1005
+ function jsonError(message, status) {
1006
+ return Response.json({ error: message }, { status });
1007
+ }
1008
+ function textFromMessageContent(content) {
1009
+ if (typeof content === "string") return content;
1010
+ if (!Array.isArray(content)) return "";
1011
+ return content.map((part) => {
1012
+ if (typeof part === "string") return part;
1013
+ if (!isPlainObject(part)) return "";
1014
+ if (typeof part.text === "string") return part.text;
1015
+ if (typeof part.content === "string") return part.content;
1016
+ return "";
1017
+ }).filter(Boolean).join("\n");
1018
+ }
1019
+ function lastUserQuestion(messages) {
1020
+ if (!Array.isArray(messages)) return "";
1021
+ return textFromMessageContent([...messages].reverse().find((message) => message?.role === "user")?.content).trim();
1022
+ }
1023
+ function resolveQuestion(body) {
1024
+ return typeof body.question === "string" && body.question.trim() ? body.question.trim() : lastUserQuestion(body.messages);
1025
+ }
1026
+ function shouldStreamResponse(request, body, aiConfig) {
1027
+ if (typeof body.stream === "boolean") return body.stream;
1028
+ if (aiConfig?.stream === false) return false;
1029
+ const accept = request.headers.get("accept")?.toLowerCase();
1030
+ return !accept || accept.includes("text/event-stream") || accept.includes("*/*");
1031
+ }
1032
+ function stripRelevantDocsFooter(content) {
1033
+ return content.replace(new RegExp(`${docsCloudRelevantDocsPattern.source}[\\s\\S]*$`, "i"), "").trimEnd();
1034
+ }
1035
+ function safeDocsCloudContent(content, final = false) {
1036
+ const footerStart = content.search(docsCloudRelevantDocsPattern);
1037
+ if (footerStart >= 0) return content.slice(0, footerStart).trimEnd();
1038
+ if (final) return stripRelevantDocsFooter(content);
1039
+ return content.slice(0, Math.max(0, content.length - DOCS_CLOUD_FOOTER_GUARD_CHARS));
1040
+ }
1041
+ function createOpenAICompatibleSseChunk(content) {
1042
+ return `data: ${JSON.stringify({ choices: [{ delta: { content } }] })}\n\n`;
1043
+ }
1044
+ function createOpenAICompatibleSseResponse(content) {
1045
+ const encoder = new TextEncoder();
1046
+ const stream = new ReadableStream({ start(controller) {
1047
+ if (content) controller.enqueue(encoder.encode(createOpenAICompatibleSseChunk(content)));
1048
+ controller.enqueue(encoder.encode("data: [DONE]\n\n"));
1049
+ controller.close();
1050
+ } });
1051
+ return new Response(stream, { headers: {
1052
+ "Content-Type": "text/event-stream",
1053
+ "Cache-Control": "no-cache, no-transform",
1054
+ Connection: "keep-alive"
1055
+ } });
1056
+ }
1057
+ function openAICompatibleDeltaContent(value) {
1058
+ if (!isPlainObject(value)) return void 0;
1059
+ const firstChoice = Array.isArray(value.choices) ? value.choices[0] : void 0;
1060
+ if (!isPlainObject(firstChoice) || !isPlainObject(firstChoice.delta)) return void 0;
1061
+ return typeof firstChoice.delta.content === "string" ? firstChoice.delta.content : void 0;
1062
+ }
1063
+ function docsCloudStreamContent(value) {
1064
+ if (typeof value === "string") return value;
1065
+ if (!isPlainObject(value)) return void 0;
1066
+ for (const key of [
1067
+ "content",
1068
+ "text",
1069
+ "answer",
1070
+ "delta"
1071
+ ]) {
1072
+ const content = value[key];
1073
+ if (typeof content === "string") return content;
1074
+ }
1075
+ }
1076
+ function docsCloudAnswerFromPayload(payload) {
1077
+ if (!isPlainObject(payload)) return "";
1078
+ for (const key of [
1079
+ "answer",
1080
+ "text",
1081
+ "content"
1082
+ ]) {
1083
+ const content = payload[key];
1084
+ if (typeof content === "string") return content;
1085
+ }
1086
+ return "";
1087
+ }
1088
+ function createCleanDocsCloudSseResponse(upstream) {
1089
+ if (!upstream.ok || !upstream.body) return new Response(upstream.body, {
1090
+ status: upstream.status,
1091
+ statusText: upstream.statusText,
1092
+ headers: {
1093
+ "Content-Type": upstream.headers.get("Content-Type") ?? "text/event-stream",
1094
+ "Cache-Control": upstream.headers.get("Cache-Control") ?? "no-cache, no-transform",
1095
+ Connection: upstream.headers.get("Connection") ?? "keep-alive"
1096
+ }
1097
+ });
1098
+ const decoder = new TextDecoder();
1099
+ const encoder = new TextEncoder();
1100
+ const stream = new ReadableStream({ async start(controller) {
1101
+ const reader = upstream.body.getReader();
1102
+ let buffer = "";
1103
+ let content = "";
1104
+ let emittedLength = 0;
1105
+ const enqueue = (chunk) => {
1106
+ controller.enqueue(encoder.encode(chunk));
1107
+ };
1108
+ const emitSafeContent = (final = false) => {
1109
+ const safeContent = safeDocsCloudContent(content, final);
1110
+ if (safeContent.length <= emittedLength) return;
1111
+ enqueue(createOpenAICompatibleSseChunk(safeContent.slice(emittedLength)));
1112
+ emittedLength = safeContent.length;
1113
+ };
1114
+ const flushEvent = (event) => {
1115
+ const data = event.split(/\r?\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).filter(Boolean).join("\n").trim();
1116
+ if (!data) return;
1117
+ if (data === "[DONE]") return;
1118
+ try {
1119
+ const parsed = JSON.parse(data);
1120
+ const delta = openAICompatibleDeltaContent(parsed) ?? docsCloudStreamContent(parsed);
1121
+ if (delta) {
1122
+ content += delta;
1123
+ emitSafeContent();
1124
+ }
1125
+ } catch {
1126
+ content += data;
1127
+ emitSafeContent();
1128
+ }
1129
+ };
1130
+ try {
1131
+ while (true) {
1132
+ const { value, done } = await reader.read();
1133
+ if (done) break;
1134
+ buffer += decoder.decode(value, { stream: true });
1135
+ const events = buffer.split(/\r?\n\r?\n/);
1136
+ buffer = events.pop() ?? "";
1137
+ for (const event of events) flushEvent(event);
1138
+ }
1139
+ buffer += decoder.decode();
1140
+ if (buffer.trim()) flushEvent(buffer);
1141
+ } catch {}
1142
+ emitSafeContent(true);
1143
+ enqueue("data: [DONE]\n\n");
1144
+ controller.close();
1145
+ } });
1146
+ return new Response(stream, {
1147
+ status: upstream.status,
1148
+ statusText: upstream.statusText,
1149
+ headers: {
1150
+ "Content-Type": "text/event-stream",
1151
+ "Cache-Control": upstream.headers.get("Cache-Control") ?? "no-cache, no-transform",
1152
+ Connection: upstream.headers.get("Connection") ?? "keep-alive"
1153
+ }
1154
+ });
1155
+ }
1156
+ function analyticsProperties(request) {
1157
+ const userAgent = request.headers.get("user-agent")?.trim();
1158
+ return userAgent ? { userAgent } : {};
1159
+ }
1160
+ function isDocsCloudAskAIProvider(config) {
1161
+ return config?.enabled === true && config.provider === "docs-cloud";
1162
+ }
1163
+ async function createDocsCloudAskAIResponse(request, options = {}) {
1164
+ const config = options.config;
1165
+ const aiConfig = config?.ai;
1166
+ const analytics = config?.analytics;
1167
+ const requestUrl = new URL(request.url);
1168
+ const requestStartedAt = Date.now();
1169
+ const requestProperties = analyticsProperties(request);
1170
+ let body;
1171
+ try {
1172
+ body = await request.json();
1173
+ } catch {
1174
+ await emitDocsAnalyticsEvent(analytics, {
1175
+ type: "api_ai_error",
1176
+ source: "server",
1177
+ url: request.url,
1178
+ path: requestUrl.pathname,
1179
+ locale: options.locale,
1180
+ properties: {
1181
+ ...requestProperties,
1182
+ reason: "invalid_json",
1183
+ provider: "docs-cloud",
1184
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1185
+ }
1186
+ });
1187
+ return jsonError("Invalid JSON body. Expected { messages: [...] }.", 400);
1188
+ }
1189
+ const question = resolveQuestion(body);
1190
+ const messages = Array.isArray(body.messages) ? body.messages : void 0;
1191
+ if (!question) {
1192
+ await emitDocsAnalyticsEvent(analytics, {
1193
+ type: "api_ai_error",
1194
+ source: "server",
1195
+ url: request.url,
1196
+ path: requestUrl.pathname,
1197
+ locale: options.locale,
1198
+ properties: {
1199
+ ...requestProperties,
1200
+ reason: "missing_user_message",
1201
+ provider: "docs-cloud",
1202
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1203
+ }
1204
+ });
1205
+ return jsonError("At least one user message is required.", 400);
1206
+ }
1207
+ const projectId = resolveDocsCloudProjectId(options.env);
1208
+ const { envName, apiKey } = resolveDocsCloudApiKey(config?.cloud, options.env);
1209
+ if (!projectId || !apiKey) {
1210
+ const reason = !projectId ? "missing_docs_cloud_project_id" : "missing_docs_cloud_api_key";
1211
+ await emitDocsAnalyticsEvent(analytics, {
1212
+ type: "api_ai_error",
1213
+ source: "server",
1214
+ url: request.url,
1215
+ path: requestUrl.pathname,
1216
+ locale: options.locale,
1217
+ input: { question },
1218
+ properties: {
1219
+ ...requestProperties,
1220
+ reason,
1221
+ provider: "docs-cloud",
1222
+ envName: !apiKey ? envName : void 0,
1223
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1224
+ }
1225
+ });
1226
+ return jsonError(!projectId ? `Docs Cloud Ask AI is missing ${DOCS_CLOUD_PROJECT_ID_ENVS.join(" or ")}. Add the project id to the deployment environment.` : `Docs Cloud Ask AI is missing ${envName}. Add it to the deployment environment.`, 500);
1227
+ }
1228
+ const stream = shouldStreamResponse(request, body, aiConfig);
1229
+ const apiBaseUrl = resolveDocsCloudApiBaseUrl(options.env);
1230
+ const publicBaseUrl = aiConfig?.docsUrl ?? options.publicBaseUrl ?? requestUrl.origin;
1231
+ const requestedModel = typeof body.model === "string" && body.model.trim() ? body.model.trim() : void 0;
1232
+ await emitDocsAnalyticsEvent(analytics, {
1233
+ type: "api_ai_request",
1234
+ source: "server",
1235
+ url: request.url,
1236
+ path: requestUrl.pathname,
1237
+ locale: options.locale,
1238
+ input: { question },
1239
+ properties: {
1240
+ ...requestProperties,
1241
+ provider: "docs-cloud",
1242
+ messageCount: messages?.length,
1243
+ questionLength: question.length,
1244
+ model: requestedModel ?? "docs-cloud"
1245
+ }
1246
+ });
1247
+ let upstream;
1248
+ try {
1249
+ upstream = await (options.fetch ?? fetch)(`${apiBaseUrl}/v1/projects/${encodeURIComponent(projectId)}/knowledge/ask`, {
1250
+ method: "POST",
1251
+ headers: {
1252
+ Accept: stream ? "text/event-stream, application/json" : "application/json",
1253
+ Authorization: `Bearer ${apiKey}`,
1254
+ "Content-Type": "application/json",
1255
+ "X-Docs-Cloud-Public-Base-Url": publicBaseUrl
1256
+ },
1257
+ body: JSON.stringify({
1258
+ messages,
1259
+ question,
1260
+ answerMode: "auto",
1261
+ answerStyle: "public",
1262
+ modelPreference: requestedModel,
1263
+ stream,
1264
+ publicBaseUrl
1265
+ })
1266
+ });
1267
+ } catch {
1268
+ await emitDocsAnalyticsEvent(analytics, {
1269
+ type: "api_ai_error",
1270
+ source: "server",
1271
+ url: request.url,
1272
+ path: requestUrl.pathname,
1273
+ locale: options.locale,
1274
+ input: { question },
1275
+ properties: {
1276
+ ...requestProperties,
1277
+ reason: "docs_cloud_fetch_error",
1278
+ provider: "docs-cloud",
1279
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1280
+ }
1281
+ });
1282
+ return jsonError("Docs Cloud Ask AI request failed.", 502);
1283
+ }
1284
+ if (!upstream.ok) {
1285
+ await upstream.text().catch(() => "");
1286
+ await emitDocsAnalyticsEvent(analytics, {
1287
+ type: "api_ai_error",
1288
+ source: "server",
1289
+ url: request.url,
1290
+ path: requestUrl.pathname,
1291
+ locale: options.locale,
1292
+ input: { question },
1293
+ properties: {
1294
+ ...requestProperties,
1295
+ reason: "docs_cloud_error",
1296
+ provider: "docs-cloud",
1297
+ status: upstream.status,
1298
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1299
+ }
1300
+ });
1301
+ return jsonError(`Docs Cloud Ask AI error (${upstream.status}).`, 502);
1302
+ }
1303
+ await emitDocsAnalyticsEvent(analytics, {
1304
+ type: "api_ai_response",
1305
+ source: "server",
1306
+ url: request.url,
1307
+ path: requestUrl.pathname,
1308
+ locale: options.locale,
1309
+ input: { question },
1310
+ properties: {
1311
+ ...requestProperties,
1312
+ provider: "docs-cloud",
1313
+ status: upstream.status,
1314
+ durationMs: Math.max(0, Date.now() - requestStartedAt)
1315
+ }
1316
+ });
1317
+ const contentType = upstream.headers.get("Content-Type") ?? "";
1318
+ if (stream && contentType.includes("text/event-stream")) return createCleanDocsCloudSseResponse(upstream);
1319
+ const upstreamBody = await upstream.text();
1320
+ let payload;
1321
+ let answer = upstreamBody;
1322
+ try {
1323
+ payload = JSON.parse(upstreamBody);
1324
+ answer = docsCloudAnswerFromPayload(payload) || answer;
1325
+ } catch {}
1326
+ const cleanAnswer = stripRelevantDocsFooter(answer);
1327
+ if (stream) return createOpenAICompatibleSseResponse(cleanAnswer);
1328
+ return Response.json(isPlainObject(payload) ? {
1329
+ ...payload,
1330
+ answer: cleanAnswer
1331
+ } : { answer: cleanAnswer });
1332
+ }
1333
+
961
1334
  //#endregion
962
1335
  //#region src/prompt-utils.ts
963
1336
  const require = createRequire(import.meta.url);
@@ -1133,4 +1506,4 @@ function readDocsSitemapManifest(rootDir, sitemap) {
1133
1506
  }
1134
1507
 
1135
1508
  //#endregion
1136
- export { resolveApiReferenceOpenApiDiscovery as C, resolveApiReferenceConfig as S, remarkCodeGroup as T, buildApiReferenceOpenApiDocument as _, DEFAULT_PROMPT_PROVIDER_TEMPLATES as a, buildApiReferenceScalarCss as b, resolvePromptProviderChoices as c, serializeDocsIconRegistry as d, serializeOpenDocsProvider as f, buildApiReferenceHtmlDocumentAsync as g, buildApiReferenceHtmlDocument as h, DEFAULT_OPEN_DOCS_TARGET as i, sanitizePromptText as l, DEFAULT_API_REFERENCE_OPENAPI_ROUTE as m, DEFAULT_OPEN_DOCS_PROMPT as n, normalizePromptProviderName as o, serializeOpenDocsProviders as p, DEFAULT_OPEN_DOCS_PROVIDER_IDS as r, parsePromptStringArray as s, readDocsSitemapManifest as t, serializeDocsIcon as u, buildApiReferenceOpenApiDocumentAsync as v, resolveApiReferenceRenderer as w, isApiReferenceOpenApiRequest as x, buildApiReferencePageTitle as y };
1509
+ export { isApiReferenceOpenApiRequest as C, remarkCodeGroup as D, resolveApiReferenceRenderer as E, buildApiReferenceScalarCss as S, resolveApiReferenceOpenApiDiscovery as T, buildApiReferenceHtmlDocument as _, DEFAULT_PROMPT_PROVIDER_TEMPLATES as a, buildApiReferenceOpenApiDocumentAsync as b, resolvePromptProviderChoices as c, serializeDocsIconRegistry as d, serializeOpenDocsProvider as f, DEFAULT_API_REFERENCE_OPENAPI_ROUTE as g, isDocsCloudAskAIProvider as h, DEFAULT_OPEN_DOCS_TARGET as i, sanitizePromptText as l, createDocsCloudAskAIResponse as m, DEFAULT_OPEN_DOCS_PROMPT as n, normalizePromptProviderName as o, serializeOpenDocsProviders as p, DEFAULT_OPEN_DOCS_PROVIDER_IDS as r, parsePromptStringArray as s, readDocsSitemapManifest as t, serializeDocsIcon as u, buildApiReferenceHtmlDocumentAsync as v, resolveApiReferenceConfig as w, buildApiReferencePageTitle as x, buildApiReferenceOpenApiDocument as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/docs",
3
- "version": "0.2.35",
3
+ "version": "0.2.36",
4
4
  "description": "Modern, flexible MDX-based docs framework — core types, config, and CLI",
5
5
  "keywords": [
6
6
  "docs",