@farming-labs/docs 0.2.120 → 0.2.122
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/README.md +8 -0
- package/dist/access.d.mts +13 -0
- package/dist/access.mjs +56 -0
- package/dist/agent-conformance.d.mts +60 -0
- package/dist/agent-conformance.mjs +538 -0
- package/dist/agent-contract.d.mts +47 -0
- package/dist/agent-contract.mjs +645 -0
- package/dist/agent-detection.d.mts +6 -0
- package/dist/agent-detection.mjs +83 -0
- package/dist/agent-evals.d.mts +224 -0
- package/dist/{agent-evals-BLNLvXbG.mjs → agent-evals.mjs} +7 -565
- package/dist/agent-feedback-evaluations-node.mjs +38 -0
- package/dist/agent-feedback-evaluations.d.mts +91 -0
- package/dist/{agent-feedback-evaluations-CcMGlgsO.mjs → agent-feedback-evaluations.mjs} +2 -2
- package/dist/agent-feedback-loop.d.mts +45 -0
- package/dist/{agent-feedback-loop-CcZL_sb1.mjs → agent-feedback-loop.mjs} +1 -1
- package/dist/agent-maintenance.d.mts +71 -0
- package/dist/{agent-maintenance-CuZ7iAKq.mjs → agent-maintenance.mjs} +1 -1
- package/dist/agent-provenance.d.mts +23 -0
- package/dist/agent-provenance.mjs +77 -0
- package/dist/agent-scope.mjs +321 -0
- package/dist/agent-skills-archive.mjs +86 -0
- package/dist/agent-skills-bundle.d.mts +1 -1
- package/dist/{agent-skills-progressive-disclosure-PjPtTYL-.mjs → agent-skills-progressive-disclosure.mjs} +2 -2
- package/dist/{agent-skills-server-D5IuvwM7.d.mts → agent-skills-server.d.mts} +3 -3
- package/dist/{agent-skills-server-BC7md56k.mjs → agent-skills-server.mjs} +2 -2
- package/dist/agent-skills-vite.d.mts +3 -3
- package/dist/agent-skills-vite.mjs +1 -2
- package/dist/agent-surface-drift.mjs +236 -0
- package/dist/{golden-evaluations-CLUViycJ.mjs → agent-usefulness.mjs} +5 -290
- package/dist/{content-change-hydration-wqXIZHp6.d.mts → agent.d.mts} +10 -411
- package/dist/agent.mjs +2729 -0
- package/dist/{analytics-w3FDOksr.d.mts → analytics.d.mts} +2 -2
- package/dist/{analytics-p8Vhhu2P.mjs → analytics.mjs} +2 -2
- package/dist/{sitemap-server-BUdPBcGs.d.mts → api-reference.d.mts} +2 -6
- package/dist/api-reference.mjs +1481 -0
- package/dist/{audience-exposure-DBrFWULA.d.mts → audience-exposure.d.mts} +1 -1
- package/dist/audience-exposure.mjs +8 -0
- package/dist/audience.d.mts +44 -0
- package/dist/audience.mjs +1654 -0
- package/dist/authoring-mcp.d.mts +44 -0
- package/dist/{authoring-mcp-CiCUQe3o.mjs → authoring-mcp.mjs} +3 -3
- package/dist/browser.d.mts +6 -4
- package/dist/browser.mjs +6 -7
- package/dist/build.d.mts +8 -0
- package/dist/build.mjs +8 -0
- package/dist/changelog.d.mts +20 -0
- package/dist/changelog.mjs +39 -0
- package/dist/{agent-export-CA6IUQ7T.mjs → cli/agent-export.mjs} +19 -45
- package/dist/{agent-CYk2DxY7.mjs → cli/agent.mjs} +6 -35
- package/dist/{agents-BUiVmj8i.mjs → cli/agents.mjs} +5 -18
- package/dist/cli/api-doctor.mjs +206 -0
- package/dist/{authoring-C2ymvYWl.mjs → cli/authoring.mjs} +2 -8
- package/dist/{cloud-6eKrlmKd.mjs → cli/cloud.mjs} +3 -3
- package/dist/{codeblocks-CHpgAwY-.mjs → cli/codeblocks.mjs} +2 -2
- package/dist/cli/config.d.mts +11 -0
- package/dist/{config-BZnKAj_Y.mjs → cli/config.mjs} +1 -1
- package/dist/cli/dev-banner.mjs +58 -0
- package/dist/{dev-Bnn-NUNa.mjs → cli/dev.mjs} +3 -57
- package/dist/{doctor-Bfkrkzad.mjs → cli/doctor.mjs} +41 -226
- package/dist/{downgrade-CHMta85e.mjs → cli/downgrade.mjs} +2 -2
- package/dist/cli/errors.d.mts +4 -0
- package/dist/{errors-BtnVLhNF.mjs → cli/errors.mjs} +1 -1
- package/dist/{feedback-evals-DMilg9pY.mjs → cli/feedback-evals.mjs} +3 -36
- package/dist/{feedback-DL4T5oIO.mjs → cli/feedback.mjs} +1 -1
- package/dist/cli/git-dates.mjs +35 -0
- package/dist/cli/golden-evaluations.mjs +52 -0
- package/dist/cli/index.d.mts +2 -3
- package/dist/cli/index.mjs +38 -38
- package/dist/{init-K0LmXDZ5.mjs → cli/init.mjs} +3 -3
- package/dist/{mcp-iLCmnPJI.mjs → cli/mcp.mjs} +7 -19
- package/dist/{openapi-diff-HcpUNjA-.mjs → cli/openapi-diff.mjs} +2 -7
- package/dist/{openapi-sdk-BQKC6H-_.mjs → cli/openapi-sdk.mjs} +2 -7
- package/dist/{openapi-source-DK6ts_Bk.mjs → cli/openapi-source.mjs} +2 -2
- package/dist/{package-version-HJhYeq4M.mjs → cli/package-version.mjs} +2 -2
- package/dist/{propose-JmUv_BTt.mjs → cli/propose.mjs} +1 -1
- package/dist/{review-C6EmbV0l.mjs → cli/review.mjs} +16 -15
- package/dist/{robots-DteZB8vl.mjs → cli/robots.mjs} +3 -7
- package/dist/{search-Bhuv_YsL.mjs → cli/search.mjs} +7 -20
- package/dist/{sitemap-DW5LDKDa.mjs → cli/sitemap.mjs} +7 -42
- package/dist/{skills-BAPQLSCm.mjs → cli/skills.mjs} +5 -19
- package/dist/{templates-BuQ8YsGv.mjs → cli/templates.mjs} +1 -1
- package/dist/{upgrade-DlQMOFV1.mjs → cli/upgrade.mjs} +2 -2
- package/dist/{utils-C7KDrPpA.mjs → cli/utils.mjs} +1 -1
- package/dist/client/react.d.mts +2 -18
- package/dist/client/react.mjs +1 -157
- package/dist/{cloud-analytics-D14HplI7.mjs → cloud-analytics.mjs} +1 -1
- package/dist/{cloud-ask-ai-BrsTXQf6.d.mts → cloud-ask-ai.d.mts} +2 -2
- package/dist/{cloud-ask-ai-BqKhjpS5.mjs → cloud-ask-ai.mjs} +3 -3
- package/dist/code-blocks.d.mts +51 -0
- package/dist/{code-blocks-GYdvS3BH.mjs → code-blocks.mjs} +2 -2
- package/dist/code-group-mdx.d.mts +11 -0
- package/dist/code-group-mdx.mjs +57 -0
- package/dist/content-change-hydration.d.mts +87 -0
- package/dist/{openapi-mcp-BIOTLiA7.mjs → content-change-hydration.mjs} +5 -210
- package/dist/content-changes.d.mts +47 -0
- package/dist/content-changes.mjs +216 -0
- package/dist/create-theme.d.mts +48 -0
- package/dist/create-theme.mjs +57 -0
- package/dist/date.d.mts +5 -0
- package/dist/date.mjs +17 -0
- package/dist/define-docs.d.mts +9 -0
- package/dist/define-docs.mjs +46 -0
- package/dist/docs-cloud-client.d.mts +18 -0
- package/dist/docs-cloud-client.mjs +161 -0
- package/dist/docs-cloud-server.d.mts +2 -2
- package/dist/docs-cloud-server.mjs +2 -3
- package/dist/heading-toc.d.mts +10 -0
- package/dist/heading-toc.mjs +23 -0
- package/dist/http-body.d.mts +14 -0
- package/dist/{http-body-DkAPk6D5.mjs → http-body.mjs} +1 -1
- package/dist/http-cache.d.mts +25 -0
- package/dist/http-cache.mjs +140 -0
- package/dist/http-link.mjs +81 -0
- package/dist/i18n.d.mts +18 -0
- package/dist/{i18n-B1gJ9EW0.mjs → i18n.mjs} +1 -1
- package/dist/index.d.mts +42 -674
- package/dist/index.mjs +40 -14
- package/dist/markdown-rendering.mjs +1 -1
- package/dist/markdown-section-cache.mjs +49 -0
- package/dist/markdown-sections.d.mts +47 -0
- package/dist/{markdown-sections-9Oxr33b-.mjs → markdown-sections.mjs} +29 -703
- package/dist/mcp-auth.d.mts +14 -0
- package/dist/mcp-auth.mjs +99 -0
- package/dist/mcp.d.mts +5 -3
- package/dist/mcp.mjs +21 -9
- package/dist/mdx.d.mts +6 -0
- package/dist/mdx.mjs +7 -0
- package/dist/metadata.d.mts +60 -0
- package/dist/{metadata-BOHn0Y5K.mjs → metadata.mjs} +2 -2
- package/dist/native-api-reference.mjs +968 -0
- package/dist/okf.d.mts +42 -0
- package/dist/okf.mjs +145 -0
- package/dist/openapi-contract.mjs +154 -0
- package/dist/{openapi-mcp-node-C4jUpZG6.mjs → openapi-mcp-node.mjs} +1 -1
- package/dist/openapi-mcp.d.mts +26 -0
- package/dist/openapi-mcp.mjs +132 -0
- package/dist/openapi-operations.d.mts +71 -0
- package/dist/{openapi-operations-DFpaqOqA.mjs → openapi-operations.mjs} +1 -1
- package/dist/openapi-overlays.mjs +221 -0
- package/dist/openapi-references.mjs +233 -0
- package/dist/pagination.d.mts +7 -0
- package/dist/pagination.mjs +100 -0
- package/dist/prompt-references.d.mts +12 -0
- package/dist/prompt-references.mjs +132 -0
- package/dist/prompt-utils.d.mts +36 -0
- package/dist/{prompt-utils-B5g-bv7o.mjs → prompt-utils.mjs} +1 -57
- package/dist/reading-time.d.mts +23 -0
- package/dist/reading-time.mjs +58 -0
- package/dist/related.d.mts +7 -0
- package/dist/related.mjs +50 -0
- package/dist/retrieval-digest.d.mts +16 -0
- package/dist/{retrieval-digest-CT-eIEcp.mjs → retrieval-digest.mjs} +1 -1
- package/dist/review.d.mts +69 -0
- package/dist/review.mjs +562 -0
- package/dist/robots.d.mts +54 -0
- package/dist/{robots-BYJAVeI6.mjs → robots.mjs} +5 -3
- package/dist/runtime.d.mts +3 -3
- package/dist/runtime.mjs +3 -9
- package/dist/search.d.mts +210 -0
- package/dist/search.mjs +3401 -0
- package/dist/server.d.mts +22 -198
- package/dist/server.mjs +21 -19
- package/dist/sidebar.d.mts +15 -0
- package/dist/sidebar.mjs +73 -0
- package/dist/sitemap-server.d.mts +7 -0
- package/dist/{sitemap-server-Lg3YhUx4.mjs → sitemap-server.mjs} +2 -2
- package/dist/{sitemap-Cl8vrixd.d.mts → sitemap.d.mts} +3 -3
- package/dist/sitemap.mjs +254 -0
- package/dist/{standards-discovery-BHPc7YIX.d.mts → standards-discovery.d.mts} +2 -2
- package/dist/{standards-discovery-sSEojU80.mjs → standards-discovery.mjs} +3 -139
- package/dist/telemetry-runtime.d.mts +42 -0
- package/dist/telemetry-runtime.mjs +238 -0
- package/dist/telemetry.d.mts +15 -0
- package/dist/telemetry.mjs +117 -0
- package/dist/{types-BJFeMXWZ.d.mts → types.d.mts} +3 -2
- package/dist/urls.d.mts +7 -0
- package/dist/urls.mjs +21 -0
- package/dist/utils.d.mts +8 -0
- package/dist/utils.mjs +22 -0
- package/package.json +21 -3
- package/dist/agent-DkAidqtV.mjs +0 -9026
- package/dist/api-reference-BYee4zMo.mjs +0 -3046
- package/dist/prompt-references-DMgbu_dz.mjs +0 -1082
- package/dist/retrieval-digest-AOx2-LbC.d.mts +0 -367
- package/dist/sidebar-CFHBj29f.mjs +0 -421
- package/dist/sidebar-CMPbVfGP.d.mts +0 -63
- /package/dist/{openapi-CfCzX_a1.mjs → cli/openapi.mjs} +0 -0
package/dist/client/react.d.mts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocsAnalyticsConfig } from "../types.mjs";
|
|
2
|
+
import { DocsCloudClientOptions, DocsCloudClientRuntimeValue } from "../docs-cloud-client.mjs";
|
|
2
3
|
import { ReactNode } from "react";
|
|
3
4
|
|
|
4
|
-
//#region src/docs-cloud-client.d.ts
|
|
5
|
-
type DocsCloudClientRuntimeValue<T = string> = T | undefined | null | (() => T | undefined | null);
|
|
6
|
-
type DocsCloudClientRuntimeEnv = Record<string, string | undefined> | (() => Record<string, string | undefined>);
|
|
7
|
-
interface DocsCloudClientOptions {
|
|
8
|
-
projectId?: DocsCloudClientRuntimeValue;
|
|
9
|
-
endpoint?: DocsCloudClientRuntimeValue;
|
|
10
|
-
analyticsEndpoint?: DocsCloudClientRuntimeValue;
|
|
11
|
-
apiBaseUrl?: DocsCloudClientRuntimeValue;
|
|
12
|
-
analyticsKey?: DocsCloudClientRuntimeValue;
|
|
13
|
-
enabled?: DocsCloudClientRuntimeValue<boolean | string>;
|
|
14
|
-
includeInputs?: DocsCloudClientRuntimeValue<boolean>;
|
|
15
|
-
env?: DocsCloudClientRuntimeEnv;
|
|
16
|
-
fetch?: typeof fetch;
|
|
17
|
-
metadata?: Record<string, unknown>;
|
|
18
|
-
properties?: Record<string, unknown>;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
5
|
//#region src/client/react.d.ts
|
|
22
6
|
interface DocsCloudAnalyticsProps extends DocsCloudClientOptions {
|
|
23
7
|
analytics?: boolean | DocsAnalyticsConfig;
|
package/dist/client/react.mjs
CHANGED
|
@@ -1,164 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { createDocsCloudClient } from "../docs-cloud-client.mjs";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
5
|
|
|
6
|
-
//#region src/docs-cloud-client.ts
|
|
7
|
-
const DEFAULT_DOCS_CLOUD_API_BASE_URL = "https://api.farming-labs.dev";
|
|
8
|
-
const DOCS_CLOUD_PROJECT_ID_ENVS = [
|
|
9
|
-
"NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID",
|
|
10
|
-
"PUBLIC_DOCS_CLOUD_PROJECT_ID",
|
|
11
|
-
"DOCS_CLOUD_PROJECT_ID"
|
|
12
|
-
];
|
|
13
|
-
const DOCS_CLOUD_API_BASE_URL_ENVS = [
|
|
14
|
-
"NEXT_PUBLIC_DOCS_CLOUD_URL",
|
|
15
|
-
"PUBLIC_DOCS_CLOUD_URL",
|
|
16
|
-
"DOCS_CLOUD_API_BASE_URL",
|
|
17
|
-
"DOCS_CLOUD_API_URL"
|
|
18
|
-
];
|
|
19
|
-
const DOCS_CLOUD_ANALYTICS_ENDPOINT_ENVS = [
|
|
20
|
-
"NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT",
|
|
21
|
-
"PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT",
|
|
22
|
-
"DOCS_CLOUD_ANALYTICS_ENDPOINT"
|
|
23
|
-
];
|
|
24
|
-
const DOCS_CLOUD_ANALYTICS_ENABLED_ENVS = [
|
|
25
|
-
"NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED",
|
|
26
|
-
"PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED",
|
|
27
|
-
"DOCS_CLOUD_ANALYTICS_ENABLED"
|
|
28
|
-
];
|
|
29
|
-
const DOCS_CLOUD_ANALYTICS_KEY_ENVS = [
|
|
30
|
-
"NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY",
|
|
31
|
-
"PUBLIC_DOCS_CLOUD_ANALYTICS_KEY",
|
|
32
|
-
"DOCS_CLOUD_ANALYTICS_KEY"
|
|
33
|
-
];
|
|
34
|
-
function normalizeRuntimeString(value) {
|
|
35
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
36
|
-
}
|
|
37
|
-
function resolveRuntimeValue(value) {
|
|
38
|
-
return (typeof value === "function" ? value() : value) ?? void 0;
|
|
39
|
-
}
|
|
40
|
-
function resolveRuntimeString(value) {
|
|
41
|
-
return normalizeRuntimeString(resolveRuntimeValue(value));
|
|
42
|
-
}
|
|
43
|
-
function resolveRuntimeEnv(env) {
|
|
44
|
-
return typeof env === "function" ? env() : env ?? {};
|
|
45
|
-
}
|
|
46
|
-
function readProcessEnv(name) {
|
|
47
|
-
if (typeof process === "undefined") return void 0;
|
|
48
|
-
if (!process.env) return void 0;
|
|
49
|
-
switch (name) {
|
|
50
|
-
case "NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID": return normalizeRuntimeString(process.env.NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID);
|
|
51
|
-
case "NEXT_PUBLIC_DOCS_CLOUD_URL": return normalizeRuntimeString(process.env.NEXT_PUBLIC_DOCS_CLOUD_URL);
|
|
52
|
-
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT": return normalizeRuntimeString(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT);
|
|
53
|
-
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED": return normalizeRuntimeString(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED);
|
|
54
|
-
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY": return normalizeRuntimeString(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY);
|
|
55
|
-
default: return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function readEnv(name, env) {
|
|
59
|
-
return normalizeRuntimeString(env[name]) ?? readProcessEnv(name);
|
|
60
|
-
}
|
|
61
|
-
function readFirstEnv(names, env) {
|
|
62
|
-
for (const name of names) {
|
|
63
|
-
const value = readEnv(name, env);
|
|
64
|
-
if (value) return value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function isFalsy(value) {
|
|
68
|
-
if (value === false) return true;
|
|
69
|
-
if (typeof value !== "string") return false;
|
|
70
|
-
return /^(0|false|no|off)$/i.test(value.trim());
|
|
71
|
-
}
|
|
72
|
-
function stripTrailingSlash(value) {
|
|
73
|
-
return value.replace(/\/+$/, "");
|
|
74
|
-
}
|
|
75
|
-
function mergeRecords(...records) {
|
|
76
|
-
const merged = {};
|
|
77
|
-
for (const record of records) {
|
|
78
|
-
if (!record) continue;
|
|
79
|
-
Object.assign(merged, record);
|
|
80
|
-
}
|
|
81
|
-
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
82
|
-
}
|
|
83
|
-
function getBrowserLocation() {
|
|
84
|
-
return typeof window !== "undefined" ? window.location : void 0;
|
|
85
|
-
}
|
|
86
|
-
function getBrowserReferrer() {
|
|
87
|
-
if (typeof document === "undefined") return void 0;
|
|
88
|
-
return document.referrer || void 0;
|
|
89
|
-
}
|
|
90
|
-
function createDocsCloudClient(options = {}) {
|
|
91
|
-
function env() {
|
|
92
|
-
return resolveRuntimeEnv(options.env);
|
|
93
|
-
}
|
|
94
|
-
function projectId() {
|
|
95
|
-
const runtimeEnv = env();
|
|
96
|
-
return resolveRuntimeString(options.projectId) ?? readFirstEnv(DOCS_CLOUD_PROJECT_ID_ENVS, runtimeEnv);
|
|
97
|
-
}
|
|
98
|
-
function apiBaseUrl() {
|
|
99
|
-
const runtimeEnv = env();
|
|
100
|
-
return stripTrailingSlash(resolveRuntimeString(options.apiBaseUrl) ?? readFirstEnv(DOCS_CLOUD_API_BASE_URL_ENVS, runtimeEnv) ?? DEFAULT_DOCS_CLOUD_API_BASE_URL);
|
|
101
|
-
}
|
|
102
|
-
function endpoint() {
|
|
103
|
-
const runtimeEnv = env();
|
|
104
|
-
return resolveRuntimeString(options.endpoint) ?? resolveRuntimeString(options.analyticsEndpoint) ?? readFirstEnv(DOCS_CLOUD_ANALYTICS_ENDPOINT_ENVS, runtimeEnv) ?? `${apiBaseUrl()}/v1/analytics/events`;
|
|
105
|
-
}
|
|
106
|
-
function analyticsKey() {
|
|
107
|
-
const runtimeEnv = env();
|
|
108
|
-
return resolveRuntimeString(options.analyticsKey) ?? readFirstEnv(DOCS_CLOUD_ANALYTICS_KEY_ENVS, runtimeEnv);
|
|
109
|
-
}
|
|
110
|
-
function enabled() {
|
|
111
|
-
const runtimeEnv = env();
|
|
112
|
-
return !isFalsy(resolveRuntimeValue(options.enabled) ?? readFirstEnv(DOCS_CLOUD_ANALYTICS_ENABLED_ENVS, runtimeEnv));
|
|
113
|
-
}
|
|
114
|
-
function includeInputs() {
|
|
115
|
-
return resolveRuntimeValue(options.includeInputs) === true;
|
|
116
|
-
}
|
|
117
|
-
function getConfig() {
|
|
118
|
-
const id = projectId();
|
|
119
|
-
return {
|
|
120
|
-
enabled: enabled(),
|
|
121
|
-
configured: Boolean(id),
|
|
122
|
-
...id ? { projectId: id } : {},
|
|
123
|
-
endpoint: endpoint()
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
async function trackEvent(event, trackOptions = {}) {
|
|
127
|
-
const config = getConfig();
|
|
128
|
-
if (!config.enabled || !config.projectId) return false;
|
|
129
|
-
const location = getBrowserLocation();
|
|
130
|
-
const normalized = {
|
|
131
|
-
...event,
|
|
132
|
-
source: event.source ?? "client",
|
|
133
|
-
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
134
|
-
url: event.url ?? location?.href,
|
|
135
|
-
path: event.path ?? location?.pathname,
|
|
136
|
-
referrer: event.referrer ?? getBrowserReferrer(),
|
|
137
|
-
locale: event.locale ?? trackOptions.locale,
|
|
138
|
-
metadata: mergeRecords(options.metadata, trackOptions.metadata, event.metadata),
|
|
139
|
-
properties: mergeRecords(options.properties, trackOptions.properties, event.properties)
|
|
140
|
-
};
|
|
141
|
-
if (!includeInputs()) delete normalized.input;
|
|
142
|
-
await sendDocsCloudAnalyticsEvent({
|
|
143
|
-
endpoint: config.endpoint,
|
|
144
|
-
projectId: config.projectId,
|
|
145
|
-
apiKey: analyticsKey(),
|
|
146
|
-
fetch: options.fetch
|
|
147
|
-
}, normalized);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
analytics: { track: trackEvent },
|
|
152
|
-
trackEvent,
|
|
153
|
-
getConfig,
|
|
154
|
-
isConfigured() {
|
|
155
|
-
const config = getConfig();
|
|
156
|
-
return config.enabled && config.configured;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
6
|
//#region src/client/react.ts
|
|
163
7
|
function isDocsCloudAnalyticsDisabled(analytics, enabled) {
|
|
164
8
|
return Boolean(enabled === false || analytics === false || analytics && typeof analytics === "object" && (analytics.enabled === false || analytics.cloud === false));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AIConfig, DocsAnalyticsConfig, DocsCloudConfig } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/cloud-ask-ai.d.ts
|
|
4
4
|
interface DocsCloudAskAIConfig {
|
|
@@ -20,4 +20,4 @@ interface DocsCloudAskAIResponseOptions {
|
|
|
20
20
|
declare function isDocsCloudAskAIProvider(config: Pick<AIConfig, "enabled" | "provider"> | undefined): boolean;
|
|
21
21
|
declare function createDocsCloudAskAIResponse(request: Request, options?: DocsCloudAskAIResponseOptions): Promise<Response>;
|
|
22
22
|
//#endregion
|
|
23
|
-
export {
|
|
23
|
+
export { DocsCloudAskAIConfig, DocsCloudAskAIResponseOptions, createDocsCloudAskAIResponse, isDocsCloudAskAIProvider };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { readDocsJsonBody } from "./http-body.mjs";
|
|
2
|
+
import { emitDocsAnalyticsEvent } from "./analytics.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/cloud-ask-ai.ts
|
|
5
5
|
const DEFAULT_DOCS_CLOUD_API_BASE_URL = "https://api.farming-labs.dev";
|
|
@@ -380,4 +380,4 @@ async function createDocsCloudAskAIResponse(request, options = {}) {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
//#endregion
|
|
383
|
-
export {
|
|
383
|
+
export { createDocsCloudAskAIResponse, isDocsCloudAskAIProvider };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DocsCodeBlocksPlannerProvider } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/code-blocks.d.ts
|
|
4
|
+
interface DocsCodeBlockTarget {
|
|
5
|
+
id: string;
|
|
6
|
+
filePath: string;
|
|
7
|
+
relativePath: string;
|
|
8
|
+
lineStart: number;
|
|
9
|
+
lineEnd: number;
|
|
10
|
+
language?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
framework?: string;
|
|
13
|
+
packageManager?: string;
|
|
14
|
+
runnable: boolean;
|
|
15
|
+
env: string[];
|
|
16
|
+
meta: Record<string, string | boolean>;
|
|
17
|
+
code: string;
|
|
18
|
+
}
|
|
19
|
+
interface DocsCodeBlockCommand {
|
|
20
|
+
cmd: string;
|
|
21
|
+
args: string[];
|
|
22
|
+
}
|
|
23
|
+
interface DocsCodeBlockExecutionPlan {
|
|
24
|
+
id: string;
|
|
25
|
+
target: DocsCodeBlockTarget;
|
|
26
|
+
action: "execute" | "validate-syntax" | "skip";
|
|
27
|
+
template: string;
|
|
28
|
+
runtime?: string;
|
|
29
|
+
filePath?: string;
|
|
30
|
+
command?: DocsCodeBlockCommand;
|
|
31
|
+
requiredEnv: string[];
|
|
32
|
+
reason?: string;
|
|
33
|
+
planner: DocsCodeBlocksPlannerProvider;
|
|
34
|
+
}
|
|
35
|
+
type DocsCodeBlockValidationStatus = "PLAN" | "PASS" | "SKIP" | "FAIL";
|
|
36
|
+
interface DocsCodeBlockValidationResult {
|
|
37
|
+
id: string;
|
|
38
|
+
target: DocsCodeBlockTarget;
|
|
39
|
+
plan: DocsCodeBlockExecutionPlan;
|
|
40
|
+
status: DocsCodeBlockValidationStatus;
|
|
41
|
+
stdout?: string;
|
|
42
|
+
stderr?: string;
|
|
43
|
+
exitCode?: number | null;
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
type OptionalModuleImporter = (specifier: string) => Promise<unknown>;
|
|
47
|
+
declare global {
|
|
48
|
+
var __DOCS_CODE_BLOCKS_MODULE_IMPORTER__: OptionalModuleImporter | undefined;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { DocsCodeBlockValidationResult };
|
|
@@ -499,7 +499,7 @@ async function runPlansInVercelSandbox(plans, rootDir, config, env) {
|
|
|
499
499
|
await sandbox.stop().catch(() => {});
|
|
500
500
|
}
|
|
501
501
|
} catch (error) {
|
|
502
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
502
|
+
const message = error?.code === "ERR_MODULE_NOT_FOUND" && String(error.message).includes("@vercel/sandbox") ? "install \"@vercel/sandbox\" to run code blocks in a Vercel Sandbox" : error instanceof Error ? error.message : String(error);
|
|
503
503
|
return plans.map((plan) => skippedResult(plan, `vercel-sandbox unavailable: ${message}`));
|
|
504
504
|
}
|
|
505
505
|
}
|
|
@@ -868,4 +868,4 @@ function skippedResult(plan, reason) {
|
|
|
868
868
|
}
|
|
869
869
|
|
|
870
870
|
//#endregion
|
|
871
|
-
export {
|
|
871
|
+
export { extractCodeBlocksFromMarkdown, planCodeBlockTargets, resolveDocsCodeBlocksValidateConfig, validateCodeBlockPlans, validateCodeBlocks };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/code-group-mdx.d.ts
|
|
2
|
+
interface MarkdownNode {
|
|
3
|
+
type: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
children?: MarkdownNode[];
|
|
6
|
+
lang?: string | null;
|
|
7
|
+
meta?: string | null;
|
|
8
|
+
}
|
|
9
|
+
declare function remarkCodeGroup(): (tree: MarkdownNode) => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { remarkCodeGroup };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/code-group-mdx.ts
|
|
2
|
+
const codeGroupTitleAttributes = [
|
|
3
|
+
"title",
|
|
4
|
+
"filename",
|
|
5
|
+
"file",
|
|
6
|
+
"name",
|
|
7
|
+
"label"
|
|
8
|
+
];
|
|
9
|
+
const ignoredBareMetaTokens = new Set([
|
|
10
|
+
"copy",
|
|
11
|
+
"no-copy",
|
|
12
|
+
"nocopy",
|
|
13
|
+
"line-numbers",
|
|
14
|
+
"linenumbers",
|
|
15
|
+
"runnable",
|
|
16
|
+
"show-line-numbers",
|
|
17
|
+
"showlinenumbers",
|
|
18
|
+
"wrap"
|
|
19
|
+
]);
|
|
20
|
+
function escapeMetaAttribute(value) {
|
|
21
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
22
|
+
}
|
|
23
|
+
function readCodeGroupTitleAttribute(meta) {
|
|
24
|
+
for (const name of codeGroupTitleAttributes) {
|
|
25
|
+
const match = meta.match(new RegExp(`(?:^|\\s)${name}=["']([^"']+)["']`));
|
|
26
|
+
if (match?.[1]?.trim()) return match[1].trim();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function readBareCodeGroupTitle(meta) {
|
|
30
|
+
return meta.replace(/\{[^}]*\}/g, " ").split(/\s+/).find((part) => part && !part.includes("=") && !ignoredBareMetaTokens.has(part.toLowerCase()))?.replace(/^["']|["']$/g, "");
|
|
31
|
+
}
|
|
32
|
+
function resolveCodeGroupCodeTitle(meta) {
|
|
33
|
+
const trimmed = meta?.trim();
|
|
34
|
+
if (!trimmed) return void 0;
|
|
35
|
+
return readCodeGroupTitleAttribute(trimmed) ?? readBareCodeGroupTitle(trimmed);
|
|
36
|
+
}
|
|
37
|
+
function ensureCodeGroupCodeTitle(node) {
|
|
38
|
+
const title = resolveCodeGroupCodeTitle(node.meta);
|
|
39
|
+
if (!title) return;
|
|
40
|
+
const meta = node.meta?.trim() ?? "";
|
|
41
|
+
if (/(?:^|\s)title=["']/.test(meta)) return;
|
|
42
|
+
node.meta = `title="${escapeMetaAttribute(title)}"${meta ? ` ${meta}` : ""}`;
|
|
43
|
+
}
|
|
44
|
+
function visitCodeGroups(node) {
|
|
45
|
+
if (node.type === "mdxJsxFlowElement" && node.name === "CodeGroup") {
|
|
46
|
+
for (const child of node.children ?? []) if (child.type === "code") ensureCodeGroupCodeTitle(child);
|
|
47
|
+
}
|
|
48
|
+
for (const child of node.children ?? []) visitCodeGroups(child);
|
|
49
|
+
}
|
|
50
|
+
function remarkCodeGroup() {
|
|
51
|
+
return (tree) => {
|
|
52
|
+
visitCodeGroups(tree);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { remarkCodeGroup };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DocsContentChangesResponse, DocsSearchSourcePage } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/content-change-hydration.d.ts
|
|
4
|
+
declare const DOCS_CONTENT_CHANGE_HYDRATION_FORMAT = "docs-content-change-hydration.v1";
|
|
5
|
+
declare const DEFAULT_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET = 5000;
|
|
6
|
+
declare const MIN_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET = 4;
|
|
7
|
+
declare const MAX_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET = 32000;
|
|
8
|
+
interface DocsContentChangeHydrationSection {
|
|
9
|
+
id: string;
|
|
10
|
+
heading: string;
|
|
11
|
+
level: number;
|
|
12
|
+
}
|
|
13
|
+
interface DocsContentChangeHydrationContent {
|
|
14
|
+
type: "content";
|
|
15
|
+
change: "added" | "changed";
|
|
16
|
+
url: string;
|
|
17
|
+
canonicalUrl: string;
|
|
18
|
+
/** Digest from the body-free document change feed. */
|
|
19
|
+
digest: string;
|
|
20
|
+
previousDigest?: string;
|
|
21
|
+
lastModified?: string;
|
|
22
|
+
previousLastModified?: string;
|
|
23
|
+
section: DocsContentChangeHydrationSection;
|
|
24
|
+
/** Digest of the complete, non-overlapping section before chunking. */
|
|
25
|
+
sectionDigest: string;
|
|
26
|
+
/** Digest of the content bytes returned in this chunk. */
|
|
27
|
+
chunkDigest: string;
|
|
28
|
+
chunk: {
|
|
29
|
+
index: number;
|
|
30
|
+
count: number;
|
|
31
|
+
};
|
|
32
|
+
content: string;
|
|
33
|
+
utf8Bytes: number;
|
|
34
|
+
}
|
|
35
|
+
interface DocsContentChangeHydrationTombstone {
|
|
36
|
+
type: "tombstone";
|
|
37
|
+
change: "deleted";
|
|
38
|
+
url: string;
|
|
39
|
+
canonicalUrl: string;
|
|
40
|
+
/** Last known digest for the deleted document. */
|
|
41
|
+
digest: string;
|
|
42
|
+
lastModified?: string;
|
|
43
|
+
}
|
|
44
|
+
interface DocsContentChangeHydrationBudget {
|
|
45
|
+
requestedTokens: number;
|
|
46
|
+
strategy: "utf8-bytes";
|
|
47
|
+
maxUtf8Bytes: number;
|
|
48
|
+
usedUtf8Bytes: number;
|
|
49
|
+
conservativeTokenUpperBound: number;
|
|
50
|
+
remainingUtf8Bytes: number;
|
|
51
|
+
}
|
|
52
|
+
interface DocsContentChangeHydrationResponse {
|
|
53
|
+
format: typeof DOCS_CONTENT_CHANGE_HYDRATION_FORMAT;
|
|
54
|
+
audience: "agent";
|
|
55
|
+
locale?: string;
|
|
56
|
+
since: string;
|
|
57
|
+
indexGeneration: string;
|
|
58
|
+
mode: DocsContentChangesResponse["mode"];
|
|
59
|
+
resetRequired: boolean;
|
|
60
|
+
documentCount: number;
|
|
61
|
+
counts: DocsContentChangesResponse["counts"];
|
|
62
|
+
budget: DocsContentChangeHydrationBudget;
|
|
63
|
+
resultCount: number;
|
|
64
|
+
total: number;
|
|
65
|
+
hasMore: boolean;
|
|
66
|
+
nextCursor?: string;
|
|
67
|
+
content: DocsContentChangeHydrationContent[];
|
|
68
|
+
tombstones: DocsContentChangeHydrationTombstone[];
|
|
69
|
+
}
|
|
70
|
+
interface HydrateDocsContentChangesOptions {
|
|
71
|
+
changes: DocsContentChangesResponse;
|
|
72
|
+
pages: readonly DocsSearchSourcePage[];
|
|
73
|
+
since: string;
|
|
74
|
+
tokenBudget?: number;
|
|
75
|
+
cursor?: string;
|
|
76
|
+
/** Stable MCP server identity mixed into opaque continuation cursors. */
|
|
77
|
+
cursorScope: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hydrate only the current bodies named by a content-change delta.
|
|
81
|
+
*
|
|
82
|
+
* The conservative budget treats one UTF-8 byte as at most one token. Cursors are
|
|
83
|
+
* bound to the requested generation, current generation, locale, and budget.
|
|
84
|
+
*/
|
|
85
|
+
declare function hydrateDocsContentChanges(options: HydrateDocsContentChangesOptions): DocsContentChangeHydrationResponse;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { DEFAULT_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, DOCS_CONTENT_CHANGE_HYDRATION_FORMAT, DocsContentChangeHydrationBudget, DocsContentChangeHydrationContent, DocsContentChangeHydrationResponse, DocsContentChangeHydrationSection, DocsContentChangeHydrationTombstone, HydrateDocsContentChangesOptions, MAX_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, MIN_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, hydrateDocsContentChanges };
|
|
@@ -1,85 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { parseDocsMarkdownSections } from "./markdown-sections.mjs";
|
|
2
|
+
import { digestDocsRetrievalContent } from "./retrieval-digest.mjs";
|
|
3
|
+
import { DocsPaginationCursorError, createDocsPaginationCursor, resolveDocsPaginationOffset } from "./pagination.mjs";
|
|
4
|
+
import { buildDocsRetrievalDigestProjection } from "./search.mjs";
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
|
|
7
|
-
//#region src/agent-provenance.ts
|
|
8
|
-
const GENERATED_AGENT_PROVENANCE_MARKER = "@farming-labs/docs:generated";
|
|
9
|
-
const GENERATED_AGENT_PROVENANCE_VERSION = 1;
|
|
10
|
-
function normalizeLineEndings(value) {
|
|
11
|
-
return value.replace(/\r\n?/g, "\n").replace(/^\uFEFF/, "");
|
|
12
|
-
}
|
|
13
|
-
function normalizeGeneratedAgentContent(value) {
|
|
14
|
-
return normalizeLineEndings(value).trimEnd();
|
|
15
|
-
}
|
|
16
|
-
function hashGeneratedAgentContent(value) {
|
|
17
|
-
const normalized = normalizeGeneratedAgentContent(value);
|
|
18
|
-
const bytes = new TextEncoder().encode(normalized);
|
|
19
|
-
let hash = 14695981039346656037n;
|
|
20
|
-
for (const byte of bytes) {
|
|
21
|
-
hash ^= BigInt(byte);
|
|
22
|
-
hash = BigInt.asUintN(64, hash * 1099511628211n);
|
|
23
|
-
}
|
|
24
|
-
return `fnv1a64:${hash.toString(16).padStart(16, "0")}`;
|
|
25
|
-
}
|
|
26
|
-
function parseProvenanceBlock(rawBlock) {
|
|
27
|
-
const entries = /* @__PURE__ */ new Map();
|
|
28
|
-
for (const line of rawBlock.split("\n")) {
|
|
29
|
-
const trimmed = line.trim();
|
|
30
|
-
if (!trimmed) continue;
|
|
31
|
-
const separatorIndex = trimmed.indexOf("=");
|
|
32
|
-
if (separatorIndex <= 0) continue;
|
|
33
|
-
const key = trimmed.slice(0, separatorIndex).trim();
|
|
34
|
-
const value = trimmed.slice(separatorIndex + 1).trim();
|
|
35
|
-
if (!key || !value) continue;
|
|
36
|
-
entries.set(key, value);
|
|
37
|
-
}
|
|
38
|
-
const version = Number.parseInt(entries.get("version") ?? "", 10);
|
|
39
|
-
const sourceKind = entries.get("sourceKind");
|
|
40
|
-
const sourceHash = entries.get("sourceHash");
|
|
41
|
-
const settingsHash = entries.get("settingsHash");
|
|
42
|
-
const outputHash = entries.get("outputHash");
|
|
43
|
-
const generatedAt = entries.get("generatedAt");
|
|
44
|
-
if (!Number.isFinite(version) || sourceKind !== "resolved-page" && sourceKind !== "agent-md" || !sourceHash || !settingsHash || !outputHash || !generatedAt) return;
|
|
45
|
-
return {
|
|
46
|
-
version,
|
|
47
|
-
sourceKind,
|
|
48
|
-
sourceHash,
|
|
49
|
-
settingsHash,
|
|
50
|
-
outputHash,
|
|
51
|
-
generatedAt
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function parseGeneratedAgentDocument(raw) {
|
|
55
|
-
const normalized = normalizeLineEndings(raw);
|
|
56
|
-
const headerPattern = new RegExp(`^<!-- ${GENERATED_AGENT_PROVENANCE_MARKER}\\n([\\s\\S]*?)\\n-->\\n?`);
|
|
57
|
-
const match = normalized.match(headerPattern);
|
|
58
|
-
if (!match) return { content: normalized };
|
|
59
|
-
return {
|
|
60
|
-
provenance: parseProvenanceBlock(match[1]),
|
|
61
|
-
content: normalized.slice(match[0].length)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function stripGeneratedAgentProvenance(raw) {
|
|
65
|
-
return parseGeneratedAgentDocument(raw).content;
|
|
66
|
-
}
|
|
67
|
-
function serializeGeneratedAgentDocument(content, provenance) {
|
|
68
|
-
const normalizedContent = normalizeGeneratedAgentContent(content);
|
|
69
|
-
return `${[
|
|
70
|
-
`<!-- ${GENERATED_AGENT_PROVENANCE_MARKER}`,
|
|
71
|
-
`version=${provenance.version}`,
|
|
72
|
-
`sourceKind=${provenance.sourceKind}`,
|
|
73
|
-
`sourceHash=${provenance.sourceHash}`,
|
|
74
|
-
`settingsHash=${provenance.settingsHash}`,
|
|
75
|
-
`outputHash=${provenance.outputHash}`,
|
|
76
|
-
`generatedAt=${provenance.generatedAt}`,
|
|
77
|
-
"-->",
|
|
78
|
-
normalizedContent
|
|
79
|
-
].join("\n")}\n`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
7
|
//#region src/content-change-hydration.ts
|
|
84
8
|
const DOCS_CONTENT_CHANGE_HYDRATION_FORMAT = "docs-content-change-hydration.v1";
|
|
85
9
|
const DEFAULT_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET = 5e3;
|
|
@@ -294,133 +218,4 @@ function hydrateDocsContentChanges(options) {
|
|
|
294
218
|
}
|
|
295
219
|
|
|
296
220
|
//#endregion
|
|
297
|
-
|
|
298
|
-
const OPENAPI_RATE_WINDOW_MS = 6e4;
|
|
299
|
-
const openApiRateWindows = /* @__PURE__ */ new Map();
|
|
300
|
-
function acquireDocsOpenApiMcpBudget(key, config, now = Date.now()) {
|
|
301
|
-
const requestsPerMinute = Math.max(1, config.requestsPerMinute ?? 60);
|
|
302
|
-
const maxConcurrentRequests = Math.max(1, config.maxConcurrentRequests ?? 4);
|
|
303
|
-
let window = openApiRateWindows.get(key);
|
|
304
|
-
if (!window || now - window.startedAt >= OPENAPI_RATE_WINDOW_MS) {
|
|
305
|
-
window = {
|
|
306
|
-
startedAt: now,
|
|
307
|
-
count: 0,
|
|
308
|
-
active: window?.active ?? 0
|
|
309
|
-
};
|
|
310
|
-
openApiRateWindows.set(key, window);
|
|
311
|
-
}
|
|
312
|
-
if (window.count >= requestsPerMinute) throw new Error("OpenAPI MCP rate limit exceeded for this principal and operation.");
|
|
313
|
-
if (window.active >= maxConcurrentRequests) throw new Error("OpenAPI MCP concurrency limit exceeded for this principal and operation.");
|
|
314
|
-
window.count += 1;
|
|
315
|
-
window.active += 1;
|
|
316
|
-
let released = false;
|
|
317
|
-
return () => {
|
|
318
|
-
if (released) return;
|
|
319
|
-
released = true;
|
|
320
|
-
window.active = Math.max(0, window.active - 1);
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
async function readDocsOpenApiMcpResponse(response, maxBytes = 1e6) {
|
|
324
|
-
const limit = Math.max(1, maxBytes);
|
|
325
|
-
if (!response.body) return {
|
|
326
|
-
text: "",
|
|
327
|
-
truncated: false
|
|
328
|
-
};
|
|
329
|
-
const reader = response.body.getReader();
|
|
330
|
-
const chunks = [];
|
|
331
|
-
let used = 0;
|
|
332
|
-
let truncated = false;
|
|
333
|
-
try {
|
|
334
|
-
while (true) {
|
|
335
|
-
const { done, value } = await reader.read();
|
|
336
|
-
if (done) break;
|
|
337
|
-
if (used + value.byteLength > limit) {
|
|
338
|
-
const remaining = limit - used;
|
|
339
|
-
if (remaining > 0) chunks.push(value.subarray(0, remaining));
|
|
340
|
-
used = limit;
|
|
341
|
-
truncated = true;
|
|
342
|
-
await reader.cancel("OpenAPI MCP response byte limit reached");
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
chunks.push(value);
|
|
346
|
-
used += value.byteLength;
|
|
347
|
-
}
|
|
348
|
-
} finally {
|
|
349
|
-
reader.releaseLock();
|
|
350
|
-
}
|
|
351
|
-
const bytes = new Uint8Array(used);
|
|
352
|
-
let offset = 0;
|
|
353
|
-
for (const chunk of chunks) {
|
|
354
|
-
bytes.set(chunk, offset);
|
|
355
|
-
offset += chunk.byteLength;
|
|
356
|
-
}
|
|
357
|
-
return {
|
|
358
|
-
text: new TextDecoder().decode(bytes),
|
|
359
|
-
truncated
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
function asRecord(value) {
|
|
363
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
364
|
-
}
|
|
365
|
-
function sanitizeToolName(value) {
|
|
366
|
-
return `api_${value.trim().replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 56) || "operation"}`;
|
|
367
|
-
}
|
|
368
|
-
function operationExtensionEnabled(operation) {
|
|
369
|
-
const extension = operation.extensions["x-farming-labs-mcp"];
|
|
370
|
-
return extension === true || asRecord(extension)?.enabled === true;
|
|
371
|
-
}
|
|
372
|
-
function resolveDocsOpenApiMcpOperations(document, config) {
|
|
373
|
-
if (!config || config.enabled === false) return [];
|
|
374
|
-
const allow = new Set((config.operations ?? []).map((value) => value.trim()).filter(Boolean));
|
|
375
|
-
const model = buildNormalizedOpenApiModel(document);
|
|
376
|
-
const operations = [];
|
|
377
|
-
const names = /* @__PURE__ */ new Set();
|
|
378
|
-
for (const operation of model.operations) {
|
|
379
|
-
if (operation.method === "TRACE") continue;
|
|
380
|
-
if (!(allow.has(operation.operationId) || allow.has(operation.selector) || operationExtensionEnabled(operation))) continue;
|
|
381
|
-
if (![
|
|
382
|
-
"GET",
|
|
383
|
-
"HEAD",
|
|
384
|
-
"OPTIONS"
|
|
385
|
-
].includes(operation.method) && config.allowMutations !== true) continue;
|
|
386
|
-
const toolName = sanitizeToolName(operation.operationId);
|
|
387
|
-
if (names.has(toolName)) throw new Error(`OpenAPI MCP tool name collision: ${toolName}`);
|
|
388
|
-
names.add(toolName);
|
|
389
|
-
operations.push({
|
|
390
|
-
toolName,
|
|
391
|
-
operationId: operation.operationId,
|
|
392
|
-
method: operation.method,
|
|
393
|
-
path: operation.path,
|
|
394
|
-
title: operation.title,
|
|
395
|
-
...operation.description ? { description: operation.description } : {},
|
|
396
|
-
parameters: operation.parameters.flatMap((parameter) => {
|
|
397
|
-
if (parameter.in !== "path" && parameter.in !== "query" && parameter.in !== "header" && parameter.in !== "cookie") return [];
|
|
398
|
-
return [{
|
|
399
|
-
name: parameter.name,
|
|
400
|
-
in: parameter.in,
|
|
401
|
-
required: parameter.required
|
|
402
|
-
}];
|
|
403
|
-
}),
|
|
404
|
-
security: operation.security,
|
|
405
|
-
securitySchemes: operation.securitySchemes,
|
|
406
|
-
readOnly: operation.method === "GET" || operation.method === "HEAD",
|
|
407
|
-
destructive: operation.method === "DELETE",
|
|
408
|
-
idempotent: [
|
|
409
|
-
"GET",
|
|
410
|
-
"HEAD",
|
|
411
|
-
"PUT",
|
|
412
|
-
"DELETE",
|
|
413
|
-
"OPTIONS"
|
|
414
|
-
].includes(operation.method)
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
return operations.sort((left, right) => left.toolName.localeCompare(right.toolName));
|
|
418
|
-
}
|
|
419
|
-
function resolveDocsOpenApiMcpBaseUrl(document, config) {
|
|
420
|
-
const configured = config.baseUrl?.trim();
|
|
421
|
-
if (configured) return configured;
|
|
422
|
-
return buildNormalizedOpenApiModel(document).servers[0];
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
//#endregion
|
|
426
|
-
export { DEFAULT_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET as a, MIN_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET as c, GENERATED_AGENT_PROVENANCE_VERSION as d, hashGeneratedAgentContent as f, stripGeneratedAgentProvenance as g, serializeGeneratedAgentDocument as h, resolveDocsOpenApiMcpOperations as i, hydrateDocsContentChanges as l, parseGeneratedAgentDocument as m, readDocsOpenApiMcpResponse as n, DOCS_CONTENT_CHANGE_HYDRATION_FORMAT as o, normalizeGeneratedAgentContent as p, resolveDocsOpenApiMcpBaseUrl as r, MAX_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET as s, acquireDocsOpenApiMcpBudget as t, GENERATED_AGENT_PROVENANCE_MARKER as u };
|
|
221
|
+
export { DEFAULT_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, DOCS_CONTENT_CHANGE_HYDRATION_FORMAT, MAX_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, MIN_DOCS_CONTENT_CHANGE_HYDRATION_TOKEN_BUDGET, hydrateDocsContentChanges };
|