@farming-labs/docs 0.2.62 → 0.2.64
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-CQTH7NFu.mjs +624 -0
- package/dist/agent-DKKptIgy.mjs +4365 -0
- package/dist/agent-evals-B7MIxuEX.mjs +2144 -0
- package/dist/agent-export-CBgWgPvH.mjs +910 -0
- package/dist/agent-scope-C_U--OZ7.mjs +283 -0
- package/dist/agent-skills-bundle.d.mts +13 -0
- package/dist/agent-skills-bundle.mjs +12 -0
- package/dist/agent-skills-server-CPja6Syt.d.mts +14 -0
- package/dist/agent-skills-server-DraIb6FV.mjs +415 -0
- package/dist/agent-skills-vite.d.mts +31 -0
- package/dist/agent-skills-vite.mjs +70 -0
- package/dist/agents-XWZBub6f.mjs +221 -0
- package/dist/analytics-Bx44lg6d.mjs +177 -0
- package/dist/cli/index.d.mts +15 -0
- package/dist/cli/index.mjs +452 -0
- package/dist/client/react.d.mts +45 -0
- package/dist/client/react.mjs +223 -0
- package/dist/cloud-analytics-CSyFE6SS.mjs +132 -0
- package/dist/cloud-ask-ai-sbpjOR2K.mjs +382 -0
- package/dist/cloud-ask-ai-zpwkdwnF.d.mts +23 -0
- package/dist/cloud-pdNC-tyj.mjs +1615 -0
- package/dist/code-blocks-DnNVNK2M.mjs +871 -0
- package/dist/codeblocks-CFuurVIH.mjs +250 -0
- package/dist/config-Wcdj-D0a.mjs +369 -0
- package/dist/dev-Cmy6DtdF.mjs +1333 -0
- package/dist/docs-cloud-server.d.mts +70 -0
- package/dist/docs-cloud-server.mjs +310 -0
- package/dist/doctor-DtGYZ41i.mjs +2036 -0
- package/dist/downgrade-w7e6Se0L.mjs +184 -0
- package/dist/errors-DbOhkE1h.mjs +20 -0
- package/dist/golden-evaluations-Dj-9Eo3v.mjs +1785 -0
- package/dist/i18n-CCaFUnAN.mjs +40 -0
- package/dist/index.d.mts +1150 -0
- package/dist/index.mjs +10 -0
- package/dist/init-CQY0Woe3.mjs +1264 -0
- package/dist/mcp-B9dcsivk.mjs +156 -0
- package/dist/mcp.d.mts +298 -0
- package/dist/mcp.mjs +4430 -0
- package/dist/metadata-DWExHQnx.mjs +237 -0
- package/dist/package-version-n5AFur8a.mjs +128 -0
- package/dist/reading-time-CYZ5VvKU.mjs +742 -0
- package/dist/review-CLoHTywU.mjs +673 -0
- package/dist/robots-BIpC4j4P.mjs +201 -0
- package/dist/robots-CUTahhoY.mjs +179 -0
- package/dist/search-B6V6qtiI.mjs +1826 -0
- package/dist/search-CaSyi6H6.d.mts +279 -0
- package/dist/search-DSjCeOk7.mjs +104 -0
- package/dist/server.d.mts +343 -0
- package/dist/server.mjs +14 -0
- package/dist/sitemap-Cykpe3Tz.mjs +249 -0
- package/dist/sitemap-server-C_6Wes83.mjs +1137 -0
- package/dist/standards-discovery-C4HUqMd2.d.mts +227 -0
- package/dist/standards-discovery-jkykaXq1.mjs +519 -0
- package/dist/templates-Bq_P7ctv.mjs +2465 -0
- package/dist/types-lMBIdZg0.d.mts +3315 -0
- package/dist/upgrade-oz-GChgt.mjs +56 -0
- package/dist/utils-DpiIioYb.mjs +225 -0
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { n as sendDocsCloudAnalyticsEvent } from "../cloud-analytics-CSyFE6SS.mjs";
|
|
4
|
+
import { useEffect } from "react";
|
|
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
|
+
//#region src/client/react.ts
|
|
163
|
+
function isDocsCloudAnalyticsDisabled(analytics, enabled) {
|
|
164
|
+
return Boolean(enabled === false || analytics === false || analytics && typeof analytics === "object" && (analytics.enabled === false || analytics.cloud === false));
|
|
165
|
+
}
|
|
166
|
+
function callAnalyticsHandler(handler, event) {
|
|
167
|
+
if (!handler) return;
|
|
168
|
+
try {
|
|
169
|
+
Promise.resolve(handler(event)).catch(() => {});
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
172
|
+
function DocsCloudAnalytics({ analytics, children, projectId, endpoint, analyticsEndpoint, apiBaseUrl, analyticsKey, enabled, includeInputs, env, fetch, metadata, properties }) {
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (typeof window === "undefined") return;
|
|
175
|
+
if (isDocsCloudAnalyticsDisabled(analytics, enabled)) return;
|
|
176
|
+
const client = createDocsCloudClient({
|
|
177
|
+
projectId,
|
|
178
|
+
endpoint,
|
|
179
|
+
analyticsEndpoint,
|
|
180
|
+
apiBaseUrl,
|
|
181
|
+
analyticsKey,
|
|
182
|
+
enabled,
|
|
183
|
+
includeInputs: includeInputs ?? (typeof analytics === "object" && analytics.includeInputs === true),
|
|
184
|
+
env,
|
|
185
|
+
fetch,
|
|
186
|
+
metadata,
|
|
187
|
+
properties
|
|
188
|
+
});
|
|
189
|
+
if (!client.isConfigured()) return;
|
|
190
|
+
const target = window;
|
|
191
|
+
const previous = target.__fdAnalytics__;
|
|
192
|
+
const handler = (event) => {
|
|
193
|
+
callAnalyticsHandler(previous, event);
|
|
194
|
+
client.trackEvent(event).catch(() => {});
|
|
195
|
+
};
|
|
196
|
+
target.__fdAnalytics__ = handler;
|
|
197
|
+
const queued = target.__fdAnalyticsQueue__ ?? [];
|
|
198
|
+
delete target.__fdAnalyticsQueue__;
|
|
199
|
+
for (const event of queued) handler(event);
|
|
200
|
+
return () => {
|
|
201
|
+
if (target.__fdAnalytics__ === handler) if (typeof previous === "function") target.__fdAnalytics__ = previous;
|
|
202
|
+
else delete target.__fdAnalytics__;
|
|
203
|
+
};
|
|
204
|
+
}, [
|
|
205
|
+
analytics,
|
|
206
|
+
analyticsEndpoint,
|
|
207
|
+
analyticsKey,
|
|
208
|
+
apiBaseUrl,
|
|
209
|
+
enabled,
|
|
210
|
+
endpoint,
|
|
211
|
+
env,
|
|
212
|
+
fetch,
|
|
213
|
+
includeInputs,
|
|
214
|
+
metadata,
|
|
215
|
+
projectId,
|
|
216
|
+
properties
|
|
217
|
+
]);
|
|
218
|
+
return children ?? null;
|
|
219
|
+
}
|
|
220
|
+
const DocsCloudAnalyticsProvider = DocsCloudAnalytics;
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
export { DocsCloudAnalytics, DocsCloudAnalyticsProvider };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//#region src/cloud-analytics.ts
|
|
2
|
+
const DEFAULT_DOCS_CLOUD_ANALYTICS_ENDPOINT = "https://api.farming-labs.dev/v1/analytics/events";
|
|
3
|
+
function normalizeRuntimeEnvValue(value) {
|
|
4
|
+
const normalized = value?.trim();
|
|
5
|
+
return normalized ? normalized : void 0;
|
|
6
|
+
}
|
|
7
|
+
function readRuntimeEnv(name) {
|
|
8
|
+
if (typeof process === "undefined" || !process.env) return;
|
|
9
|
+
switch (name) {
|
|
10
|
+
case "PUBLIC_DOCS_CLOUD_PROJECT_ID": return normalizeRuntimeEnvValue(process.env.PUBLIC_DOCS_CLOUD_PROJECT_ID);
|
|
11
|
+
case "NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID": return normalizeRuntimeEnvValue(process.env.NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID);
|
|
12
|
+
case "DOCS_CLOUD_PROJECT_ID": return normalizeRuntimeEnvValue(process.env.DOCS_CLOUD_PROJECT_ID);
|
|
13
|
+
case "PUBLIC_DOCS_CLOUD_ANALYTICS_KEY": return normalizeRuntimeEnvValue(process.env.PUBLIC_DOCS_CLOUD_ANALYTICS_KEY);
|
|
14
|
+
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY": return normalizeRuntimeEnvValue(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY);
|
|
15
|
+
case "DOCS_CLOUD_ANALYTICS_KEY": return normalizeRuntimeEnvValue(process.env.DOCS_CLOUD_ANALYTICS_KEY);
|
|
16
|
+
case "PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED": return normalizeRuntimeEnvValue(process.env.PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED);
|
|
17
|
+
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED": return normalizeRuntimeEnvValue(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED);
|
|
18
|
+
case "DOCS_CLOUD_ANALYTICS_ENABLED": return normalizeRuntimeEnvValue(process.env.DOCS_CLOUD_ANALYTICS_ENABLED);
|
|
19
|
+
case "PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT": return normalizeRuntimeEnvValue(process.env.PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT);
|
|
20
|
+
case "NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT": return normalizeRuntimeEnvValue(process.env.NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT);
|
|
21
|
+
case "DOCS_CLOUD_ANALYTICS_ENDPOINT": return normalizeRuntimeEnvValue(process.env.DOCS_CLOUD_ANALYTICS_ENDPOINT);
|
|
22
|
+
default: return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function isFalsyEnv(value) {
|
|
26
|
+
if (!value) return false;
|
|
27
|
+
return /^(0|false|no|off)$/i.test(value);
|
|
28
|
+
}
|
|
29
|
+
function resolveDocsCloudAnalyticsOptions(analytics) {
|
|
30
|
+
if (analytics === false || analytics && typeof analytics === "object" && (analytics.enabled === false || analytics.cloud === false)) return null;
|
|
31
|
+
const projectId = readRuntimeEnv("PUBLIC_DOCS_CLOUD_PROJECT_ID") ?? readRuntimeEnv("NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID") ?? readRuntimeEnv("DOCS_CLOUD_PROJECT_ID");
|
|
32
|
+
const apiKey = readRuntimeEnv("PUBLIC_DOCS_CLOUD_ANALYTICS_KEY") ?? readRuntimeEnv("NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY") ?? readRuntimeEnv("DOCS_CLOUD_ANALYTICS_KEY");
|
|
33
|
+
const enabled = readRuntimeEnv("PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED") ?? readRuntimeEnv("NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED") ?? readRuntimeEnv("DOCS_CLOUD_ANALYTICS_ENABLED");
|
|
34
|
+
const endpoint = readRuntimeEnv("PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT") ?? readRuntimeEnv("NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT") ?? readRuntimeEnv("DOCS_CLOUD_ANALYTICS_ENDPOINT") ?? DEFAULT_DOCS_CLOUD_ANALYTICS_ENDPOINT;
|
|
35
|
+
if (isFalsyEnv(enabled)) return null;
|
|
36
|
+
if (!projectId) return null;
|
|
37
|
+
return {
|
|
38
|
+
endpoint,
|
|
39
|
+
projectId,
|
|
40
|
+
apiKey
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function asRecord(value) {
|
|
44
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
45
|
+
}
|
|
46
|
+
function asString(value) {
|
|
47
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
48
|
+
}
|
|
49
|
+
function normalizeAnalyticsLabel(value) {
|
|
50
|
+
return value?.trim().toLowerCase().replace(/[-\s]+/g, "_") ?? "";
|
|
51
|
+
}
|
|
52
|
+
function isProtocolAgentEvent(event) {
|
|
53
|
+
const type = normalizeAnalyticsLabel(event.type);
|
|
54
|
+
return normalizeAnalyticsLabel(event.source) === "mcp" || type.startsWith("mcp_");
|
|
55
|
+
}
|
|
56
|
+
function inferAgentProvider(event) {
|
|
57
|
+
const type = normalizeAnalyticsLabel(event.type);
|
|
58
|
+
if (normalizeAnalyticsLabel(event.source) === "mcp" || type.startsWith("mcp_")) return "MCP client";
|
|
59
|
+
if (type.startsWith("agent_") || type === "agents_request") return "Docs agent";
|
|
60
|
+
if ([
|
|
61
|
+
"llms_request",
|
|
62
|
+
"markdown_request",
|
|
63
|
+
"skill_request"
|
|
64
|
+
].includes(type)) return "Docs reader";
|
|
65
|
+
}
|
|
66
|
+
function detectAgentProviderFromUserAgent(userAgent) {
|
|
67
|
+
const value = userAgent?.toLowerCase() ?? "";
|
|
68
|
+
if (!value) return;
|
|
69
|
+
for (const [pattern, provider] of [
|
|
70
|
+
[/cursor/i, "Cursor"],
|
|
71
|
+
[/codex/i, "Codex"],
|
|
72
|
+
[/chatgpt-user|chatgpt/i, "ChatGPT"],
|
|
73
|
+
[/gptbot/i, "GPTBot"],
|
|
74
|
+
[/oai-searchbot|openai-search/i, "ChatGPT Search"],
|
|
75
|
+
[/openai/i, "ChatGPT"],
|
|
76
|
+
[/github-copilot|githubcopilot|copilot/i, "GitHub Copilot"],
|
|
77
|
+
[/claudebot|claude-user|anthropic/i, "Claude"],
|
|
78
|
+
[/perplexitybot|perplexity-user/i, "Perplexity"],
|
|
79
|
+
[/google-extended|googlebot|apis-google/i, "Google"],
|
|
80
|
+
[/bingbot|msnbot/i, "Bing"],
|
|
81
|
+
[/duckduckbot/i, "DuckDuckGo"],
|
|
82
|
+
[/applebot/i, "Apple"],
|
|
83
|
+
[/bytespider|bytedance/i, "ByteDance"],
|
|
84
|
+
[/ccbot|common crawl/i, "Common Crawl"],
|
|
85
|
+
[/ahrefsbot/i, "Ahrefs"],
|
|
86
|
+
[/semrushbot/i, "Semrush"]
|
|
87
|
+
]) if (pattern.test(value)) return provider;
|
|
88
|
+
if (/bot|crawler|spider|slurp|facebookexternalhit|ia_archiver/.test(value)) return "Other bot";
|
|
89
|
+
}
|
|
90
|
+
function withDocsCloudAnalyticsHints(event) {
|
|
91
|
+
const properties = asRecord(event.properties);
|
|
92
|
+
const detectedAgent = detectAgentProviderFromUserAgent(asString(properties.userAgent) ?? asString(properties.user_agent));
|
|
93
|
+
const protocolAgent = isProtocolAgentEvent(event);
|
|
94
|
+
const incomingTrafficType = asString(properties.trafficType)?.toLowerCase();
|
|
95
|
+
const explicitAgent = incomingTrafficType === "agent" || incomingTrafficType === "bot";
|
|
96
|
+
const agentProvider = asString(properties.agentName) ?? asString(properties.agent) ?? asString(properties.botProvider) ?? asString(properties.provider) ?? asString(properties.crawler) ?? asString(asRecord(properties.bot).provider) ?? detectedAgent ?? (protocolAgent || explicitAgent ? inferAgentProvider(event) : void 0);
|
|
97
|
+
if (!explicitAgent && !protocolAgent && !detectedAgent && !agentProvider) return event;
|
|
98
|
+
return {
|
|
99
|
+
...event,
|
|
100
|
+
properties: {
|
|
101
|
+
...properties,
|
|
102
|
+
trafficType: "agent",
|
|
103
|
+
...agentProvider && !asString(properties.agentName) ? { agentName: agentProvider } : {},
|
|
104
|
+
...agentProvider && !asString(properties.botProvider) ? { botProvider: agentProvider } : {}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function sendDocsCloudAnalyticsEvent(options, event) {
|
|
109
|
+
const fetcher = options.fetch ?? (typeof fetch === "function" ? fetch : void 0);
|
|
110
|
+
if (!fetcher) return;
|
|
111
|
+
const endpoint = options.endpoint?.trim() || DEFAULT_DOCS_CLOUD_ANALYTICS_ENDPOINT;
|
|
112
|
+
const projectId = options.projectId?.trim();
|
|
113
|
+
if (!endpoint || !projectId) return;
|
|
114
|
+
try {
|
|
115
|
+
const normalizedEvent = withDocsCloudAnalyticsHints(event);
|
|
116
|
+
await fetcher(endpoint, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: {
|
|
119
|
+
"content-type": "application/json",
|
|
120
|
+
...options.apiKey ? { authorization: `Bearer ${options.apiKey}` } : {}
|
|
121
|
+
},
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
projectId,
|
|
124
|
+
event: normalizedEvent
|
|
125
|
+
}),
|
|
126
|
+
keepalive: true
|
|
127
|
+
});
|
|
128
|
+
} catch {}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
export { sendDocsCloudAnalyticsEvent as n, resolveDocsCloudAnalyticsOptions as t };
|