@farming-labs/docs 0.2.62 → 0.2.63
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-CJqtzKZT.mjs +2036 -0
- package/dist/downgrade-w7e6Se0L.mjs +184 -0
- package/dist/errors-DbOhkE1h.mjs +20 -0
- package/dist/golden-evaluations-Dsvh0etV.mjs +1503 -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-Fndl5brR.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,221 @@
|
|
|
1
|
+
import { $ as renderDocsAgentsDocument, a as DEFAULT_AGENT_MD_ROUTE, at as resolveDocsAgentFeedbackConfig, b as DEFAULT_OPENAPI_SCHEMA_ROUTE, n as DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE, o as DEFAULT_AGENT_MD_WELL_KNOWN_ROUTE, t as DEFAULT_AGENTS_MD_ROUTE } from "./agent-DKKptIgy.mjs";
|
|
2
|
+
import "./standards-discovery-jkykaXq1.mjs";
|
|
3
|
+
import "./search-B6V6qtiI.mjs";
|
|
4
|
+
import { S as resolveApiReferenceConfig } from "./sitemap-server-C_6Wes83.mjs";
|
|
5
|
+
import "./agent-evals-B7MIxuEX.mjs";
|
|
6
|
+
import { resolveDocsMcpConfig } from "./mcp.mjs";
|
|
7
|
+
import "./code-blocks-DnNVNK2M.mjs";
|
|
8
|
+
import "./agent-skills-server-DraIb6FV.mjs";
|
|
9
|
+
import "./server.mjs";
|
|
10
|
+
import { a as loadDocsConfigModule, d as readNavTitle, g as resolveDocsConfigPath, h as readTopLevelStringProperty, l as readBooleanProperty, p as readStringProperty, t as extractNestedObjectLiteral } from "./config-Wcdj-D0a.mjs";
|
|
11
|
+
import { t as detectFramework } from "./utils-DpiIioYb.mjs";
|
|
12
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import pc from "picocolors";
|
|
15
|
+
|
|
16
|
+
//#region src/cli/agents.ts
|
|
17
|
+
const AGENTS_GENERATED_MARKER = "<!-- Generated by @farming-labs/docs agents generate. -->";
|
|
18
|
+
function parseInlineFlag(arg) {
|
|
19
|
+
const [rawKey, value] = arg.slice(2).split("=", 2);
|
|
20
|
+
return {
|
|
21
|
+
key: rawKey.trim(),
|
|
22
|
+
value
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseAgentsGenerateArgs(argv) {
|
|
26
|
+
const parsed = {};
|
|
27
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
28
|
+
const arg = argv[index];
|
|
29
|
+
if (arg === "--help" || arg === "-h") {
|
|
30
|
+
parsed.help = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (arg === "--force") {
|
|
34
|
+
parsed.force = true;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (arg === "--check") {
|
|
38
|
+
parsed.check = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (arg.startsWith("--config=")) {
|
|
42
|
+
const value = parseInlineFlag(arg).value;
|
|
43
|
+
if (!value) throw new Error("Missing value for --config.");
|
|
44
|
+
parsed.configPath = value;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (arg === "--config") {
|
|
48
|
+
const value = argv[index + 1];
|
|
49
|
+
if (!value || value.startsWith("--")) throw new Error("Missing value for --config.");
|
|
50
|
+
parsed.configPath = value;
|
|
51
|
+
index += 1;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (arg.startsWith("--path=")) {
|
|
55
|
+
const value = parseInlineFlag(arg).value;
|
|
56
|
+
if (!value) throw new Error("Missing value for --path.");
|
|
57
|
+
parsed.path = value;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (arg === "--path") {
|
|
61
|
+
const value = argv[index + 1];
|
|
62
|
+
if (!value || value.startsWith("--")) throw new Error("Missing value for --path.");
|
|
63
|
+
parsed.path = value;
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!arg.startsWith("--") && !parsed.path) {
|
|
68
|
+
parsed.path = arg;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Unknown agents generate flag: ${arg}.`);
|
|
72
|
+
}
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
function readTopLevelBooleanProperty(content, key) {
|
|
76
|
+
const match = content.match(new RegExp(`\\b${key}\\b\\s*:\\s*(true|false)`));
|
|
77
|
+
return match ? match[1] === "true" : void 0;
|
|
78
|
+
}
|
|
79
|
+
function readLlmsBaseUrlFromConfig(content, config) {
|
|
80
|
+
if (config?.llmsTxt && typeof config.llmsTxt === "object") return config.llmsTxt.baseUrl;
|
|
81
|
+
const block = extractNestedObjectLiteral(content, ["llmsTxt"]);
|
|
82
|
+
return block ? readStringProperty(block, "baseUrl") : void 0;
|
|
83
|
+
}
|
|
84
|
+
function readSitemapBaseUrlFromConfig(content, config) {
|
|
85
|
+
if (config?.sitemap && typeof config.sitemap === "object") return config.sitemap.baseUrl;
|
|
86
|
+
const block = extractNestedObjectLiteral(content, ["sitemap"]);
|
|
87
|
+
return block ? readStringProperty(block, "baseUrl") : void 0;
|
|
88
|
+
}
|
|
89
|
+
function readCloudApiRouteFromConfig(content, config) {
|
|
90
|
+
if (typeof config?.cloud?.apiRoute === "string") return config.cloud.apiRoute;
|
|
91
|
+
const block = extractNestedObjectLiteral(content, ["cloud"]);
|
|
92
|
+
return block ? readStringProperty(block, "apiRoute") : void 0;
|
|
93
|
+
}
|
|
94
|
+
function readRobotsConfigFromStatic(content) {
|
|
95
|
+
const topLevelBoolean = readTopLevelBooleanProperty(content, "robots");
|
|
96
|
+
if (typeof topLevelBoolean === "boolean") return topLevelBoolean;
|
|
97
|
+
const block = extractNestedObjectLiteral(content, ["robots"]);
|
|
98
|
+
if (!block) return void 0;
|
|
99
|
+
return { enabled: readBooleanProperty(block, "enabled") ?? true };
|
|
100
|
+
}
|
|
101
|
+
function resolvePublicDir(rootDir) {
|
|
102
|
+
if (detectFramework(rootDir) === "sveltekit") return path.join(rootDir, "static");
|
|
103
|
+
return path.join(rootDir, "public");
|
|
104
|
+
}
|
|
105
|
+
function resolveAgentsPath(rootDir, options) {
|
|
106
|
+
if (options.path) return path.isAbsolute(options.path) ? options.path : path.resolve(rootDir, options.path);
|
|
107
|
+
return path.join(rootDir, "AGENTS.md");
|
|
108
|
+
}
|
|
109
|
+
function publicFilePath(rootDir, route) {
|
|
110
|
+
return path.join(resolvePublicDir(rootDir), route.replace(/^\/+/, ""));
|
|
111
|
+
}
|
|
112
|
+
function normalizeGeneratedContent(content) {
|
|
113
|
+
return `${AGENTS_GENERATED_MARKER}\n${content.trimEnd()}\n`;
|
|
114
|
+
}
|
|
115
|
+
function normalizeCustomContent(content) {
|
|
116
|
+
return content.endsWith("\n") ? content : `${content}\n`;
|
|
117
|
+
}
|
|
118
|
+
function isManagedAgentsFile(content) {
|
|
119
|
+
return content.includes(AGENTS_GENERATED_MARKER);
|
|
120
|
+
}
|
|
121
|
+
function writeIfNeeded(filePath, content, options) {
|
|
122
|
+
const current = existsSync(filePath) ? readFileSync(filePath, "utf-8") : void 0;
|
|
123
|
+
if (current === content) return "current";
|
|
124
|
+
if (current !== void 0 && !options.force && !isManagedAgentsFile(current)) return "kept";
|
|
125
|
+
if (options.check) return "changed";
|
|
126
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
127
|
+
writeFileSync(filePath, content, "utf-8");
|
|
128
|
+
return "changed";
|
|
129
|
+
}
|
|
130
|
+
function resolveOpenApiDiscovery(config) {
|
|
131
|
+
const apiReference = resolveApiReferenceConfig(config?.apiReference);
|
|
132
|
+
if (!apiReference.enabled) return { enabled: false };
|
|
133
|
+
return {
|
|
134
|
+
enabled: true,
|
|
135
|
+
url: DEFAULT_OPENAPI_SCHEMA_ROUTE,
|
|
136
|
+
urlSource: "default",
|
|
137
|
+
source: apiReference.specUrl ? "configured" : "generated",
|
|
138
|
+
specUrl: apiReference.specUrl,
|
|
139
|
+
apiReferencePath: `/${apiReference.path}`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async function generateAgents(options = {}) {
|
|
143
|
+
const rootDir = process.cwd();
|
|
144
|
+
const loadedConfigModule = await loadDocsConfigModule(rootDir, options.configPath);
|
|
145
|
+
const configContent = readFileSync(loadedConfigModule?.path ?? resolveDocsConfigPath(rootDir, options.configPath), "utf-8");
|
|
146
|
+
const config = loadedConfigModule?.config;
|
|
147
|
+
const entry = config?.entry ?? readTopLevelStringProperty(configContent, "entry") ?? "docs";
|
|
148
|
+
const siteTitle = typeof config?.nav?.title === "string" ? config.nav.title : readNavTitle(configContent) ?? "Documentation";
|
|
149
|
+
const siteDescription = typeof config?.metadata?.description === "string" ? config.metadata.description : void 0;
|
|
150
|
+
const baseUrl = readLlmsBaseUrlFromConfig(configContent, config) ?? readSitemapBaseUrlFromConfig(configContent, config);
|
|
151
|
+
const apiRoute = readCloudApiRouteFromConfig(configContent, config);
|
|
152
|
+
const llmsTxt = config?.llmsTxt;
|
|
153
|
+
const llmsEnabled = llmsTxt === false ? false : typeof llmsTxt === "object" ? llmsTxt.enabled ?? true : true;
|
|
154
|
+
const llmsConfig = typeof llmsTxt === "object" ? llmsTxt : void 0;
|
|
155
|
+
const robotsInput = config?.robots ?? readRobotsConfigFromStatic(configContent) ?? true;
|
|
156
|
+
const rootAgentsPath = resolveAgentsPath(rootDir, options);
|
|
157
|
+
const generatedContent = normalizeGeneratedContent(renderDocsAgentsDocument({
|
|
158
|
+
origin: baseUrl ?? "http://localhost",
|
|
159
|
+
entry,
|
|
160
|
+
apiRoute,
|
|
161
|
+
search: config?.search,
|
|
162
|
+
mcp: resolveDocsMcpConfig(config?.mcp),
|
|
163
|
+
feedback: resolveDocsAgentFeedbackConfig(config?.feedback),
|
|
164
|
+
llms: {
|
|
165
|
+
enabled: llmsEnabled,
|
|
166
|
+
baseUrl,
|
|
167
|
+
siteTitle,
|
|
168
|
+
siteDescription,
|
|
169
|
+
maxChars: llmsConfig?.maxChars,
|
|
170
|
+
sections: llmsConfig?.sections
|
|
171
|
+
},
|
|
172
|
+
sitemap: config?.sitemap,
|
|
173
|
+
robots: robotsInput,
|
|
174
|
+
openapi: resolveOpenApiDiscovery(config),
|
|
175
|
+
markdown: { acceptHeader: false }
|
|
176
|
+
}));
|
|
177
|
+
const existingRoot = existsSync(rootAgentsPath) ? readFileSync(rootAgentsPath, "utf-8") : null;
|
|
178
|
+
const sourceContent = existingRoot !== null && !options.force && !isManagedAgentsFile(existingRoot) ? normalizeCustomContent(existingRoot) : generatedContent;
|
|
179
|
+
const writes = [];
|
|
180
|
+
const kept = [];
|
|
181
|
+
const rootStatus = writeIfNeeded(rootAgentsPath, sourceContent, options);
|
|
182
|
+
if (rootStatus === "changed") writes.push(rootAgentsPath);
|
|
183
|
+
if (rootStatus === "kept") kept.push(rootAgentsPath);
|
|
184
|
+
for (const route of [
|
|
185
|
+
DEFAULT_AGENTS_MD_ROUTE,
|
|
186
|
+
DEFAULT_AGENTS_MD_WELL_KNOWN_ROUTE,
|
|
187
|
+
DEFAULT_AGENT_MD_ROUTE,
|
|
188
|
+
DEFAULT_AGENT_MD_WELL_KNOWN_ROUTE
|
|
189
|
+
]) {
|
|
190
|
+
const filePath = publicFilePath(rootDir, route);
|
|
191
|
+
const status = writeIfNeeded(filePath, sourceContent, options);
|
|
192
|
+
if (status === "changed") writes.push(filePath);
|
|
193
|
+
if (status === "kept") kept.push(filePath);
|
|
194
|
+
}
|
|
195
|
+
if (options.check && writes.length > 0) throw new Error("AGENTS.md output is stale. Run `docs agents generate` to update it.");
|
|
196
|
+
const relativeRoot = path.relative(rootDir, rootAgentsPath).replace(/\\/g, "/");
|
|
197
|
+
console.log(writes.length > 0 ? pc.green(`Generated agent instructions at ${relativeRoot}.`) : pc.green(`Agent instructions are current at ${relativeRoot}.`));
|
|
198
|
+
for (const filePath of writes) {
|
|
199
|
+
if (filePath === rootAgentsPath) continue;
|
|
200
|
+
console.log(pc.dim(path.relative(rootDir, filePath).replace(/\\/g, "/")));
|
|
201
|
+
}
|
|
202
|
+
for (const filePath of kept) console.log(pc.yellow(`Kept user-owned ${path.relative(rootDir, filePath).replace(/\\/g, "/")}.`));
|
|
203
|
+
}
|
|
204
|
+
function printAgentsGenerateHelp() {
|
|
205
|
+
console.log(`
|
|
206
|
+
${pc.bold("docs agents generate")} — Generate AGENTS.md instructions for coding agents.
|
|
207
|
+
|
|
208
|
+
${pc.dim("Usage:")}
|
|
209
|
+
pnpm exec docs ${pc.cyan("agents generate")} ${pc.dim("[path]")}
|
|
210
|
+
|
|
211
|
+
${pc.dim("Options:")}
|
|
212
|
+
${pc.cyan("--path <path>")} Write the root instructions file; defaults to ${pc.dim("AGENTS.md")}
|
|
213
|
+
${pc.cyan("--force")} Replace existing AGENTS.md/static files
|
|
214
|
+
${pc.cyan("--check")} Fail if generated output would change
|
|
215
|
+
${pc.cyan("--config <path>")} Use a custom docs config path instead of ${pc.dim("docs.config.ts[x]")}
|
|
216
|
+
${pc.cyan("-h, --help")} Show this help message
|
|
217
|
+
`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
export { generateAgents, parseAgentsGenerateArgs, printAgentsGenerateHelp };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { n as sendDocsCloudAnalyticsEvent, t as resolveDocsCloudAnalyticsOptions } from "./cloud-analytics-CSyFE6SS.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/analytics.ts
|
|
4
|
+
const ANALYTICS_LOG_PREFIX = "[@farming-labs/docs:analytics]";
|
|
5
|
+
const OBSERVABILITY_LOG_PREFIX = "[@farming-labs/docs:observability]";
|
|
6
|
+
const DOCS_AGENT_TRACE_EVENT_TYPES = [
|
|
7
|
+
"run.start",
|
|
8
|
+
"run.end",
|
|
9
|
+
"run.error",
|
|
10
|
+
"user.input",
|
|
11
|
+
"prompt.build",
|
|
12
|
+
"retrieval.query",
|
|
13
|
+
"retrieval.result",
|
|
14
|
+
"retrieval.error",
|
|
15
|
+
"model.call",
|
|
16
|
+
"model.response",
|
|
17
|
+
"model.stream",
|
|
18
|
+
"model.error",
|
|
19
|
+
"tool.call",
|
|
20
|
+
"tool.result",
|
|
21
|
+
"tool.error",
|
|
22
|
+
"retry",
|
|
23
|
+
"timeout",
|
|
24
|
+
"error",
|
|
25
|
+
"agent.final"
|
|
26
|
+
];
|
|
27
|
+
function composeAnalyticsHandlers(userOnEvent, cloudOnEvent) {
|
|
28
|
+
if (typeof userOnEvent !== "function" && !cloudOnEvent) return;
|
|
29
|
+
return async (event) => {
|
|
30
|
+
let userError;
|
|
31
|
+
if (typeof userOnEvent === "function") try {
|
|
32
|
+
await userOnEvent(event);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
userError = error;
|
|
35
|
+
}
|
|
36
|
+
if (cloudOnEvent) try {
|
|
37
|
+
await cloudOnEvent(event);
|
|
38
|
+
} catch {}
|
|
39
|
+
if (typeof userError !== "undefined") throw userError;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function resolveConsoleLevel(value, hasEventHandler) {
|
|
43
|
+
if (value === false) return false;
|
|
44
|
+
if (value === true) return "info";
|
|
45
|
+
if (value === "log" || value === "info" || value === "debug") return value;
|
|
46
|
+
return hasEventHandler ? false : "info";
|
|
47
|
+
}
|
|
48
|
+
function createDocsAgentTraceId(prefix = "trace") {
|
|
49
|
+
return `${prefix.replace(/[^a-zA-Z0-9_-]/g, "_") || "trace"}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
50
|
+
}
|
|
51
|
+
function createDocsAgentTraceContext(name = "agent.run") {
|
|
52
|
+
return {
|
|
53
|
+
traceId: createDocsAgentTraceId("run"),
|
|
54
|
+
name,
|
|
55
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56
|
+
startedMs: Date.now()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getDocsRequestAnalyticsProperties(request) {
|
|
60
|
+
const userAgent = request.headers.get("user-agent")?.trim();
|
|
61
|
+
return userAgent ? { userAgent } : {};
|
|
62
|
+
}
|
|
63
|
+
function resolveDocsAnalyticsConfig(analytics) {
|
|
64
|
+
if (analytics === false) return {
|
|
65
|
+
enabled: false,
|
|
66
|
+
console: false,
|
|
67
|
+
includeInputs: false
|
|
68
|
+
};
|
|
69
|
+
const cloudOptions = resolveDocsCloudAnalyticsOptions(analytics);
|
|
70
|
+
const cloudOnEvent = cloudOptions ? async (event) => {
|
|
71
|
+
await sendDocsCloudAnalyticsEvent(cloudOptions, event);
|
|
72
|
+
} : void 0;
|
|
73
|
+
if (!analytics) {
|
|
74
|
+
if (!cloudOnEvent) return {
|
|
75
|
+
enabled: false,
|
|
76
|
+
console: false,
|
|
77
|
+
includeInputs: false
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
enabled: true,
|
|
81
|
+
console: false,
|
|
82
|
+
includeInputs: false,
|
|
83
|
+
onEvent: cloudOnEvent
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (analytics === true) return {
|
|
87
|
+
enabled: true,
|
|
88
|
+
console: "info",
|
|
89
|
+
includeInputs: false,
|
|
90
|
+
onEvent: cloudOnEvent
|
|
91
|
+
};
|
|
92
|
+
const userOnEvent = analytics.onEvent;
|
|
93
|
+
const hasEventHandler = typeof userOnEvent === "function" || Boolean(cloudOnEvent);
|
|
94
|
+
const onEvent = composeAnalyticsHandlers(userOnEvent, cloudOnEvent);
|
|
95
|
+
return {
|
|
96
|
+
enabled: analytics.enabled !== false,
|
|
97
|
+
console: resolveConsoleLevel(analytics.console, hasEventHandler),
|
|
98
|
+
includeInputs: analytics.includeInputs === true,
|
|
99
|
+
onEvent
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function resolveDocsObservabilityConfig(observability) {
|
|
103
|
+
if (!observability) return {
|
|
104
|
+
enabled: false,
|
|
105
|
+
console: false,
|
|
106
|
+
includeInputs: false
|
|
107
|
+
};
|
|
108
|
+
if (observability === true) return {
|
|
109
|
+
enabled: true,
|
|
110
|
+
console: "info",
|
|
111
|
+
includeInputs: false
|
|
112
|
+
};
|
|
113
|
+
const hasEventHandler = typeof observability.onEvent === "function";
|
|
114
|
+
return {
|
|
115
|
+
enabled: observability.enabled !== false,
|
|
116
|
+
console: resolveConsoleLevel(observability.console, hasEventHandler),
|
|
117
|
+
includeInputs: observability.includeInputs === true,
|
|
118
|
+
onEvent: observability.onEvent
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function normalizeAnalyticsEvent(event, config) {
|
|
122
|
+
const normalized = {
|
|
123
|
+
...event,
|
|
124
|
+
source: event.source ?? "server",
|
|
125
|
+
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
126
|
+
};
|
|
127
|
+
if (!config.includeInputs && normalized.input) delete normalized.input;
|
|
128
|
+
return normalized;
|
|
129
|
+
}
|
|
130
|
+
function normalizeObservabilityEvent(event, config) {
|
|
131
|
+
const normalized = {
|
|
132
|
+
...event,
|
|
133
|
+
source: event.source ?? "server",
|
|
134
|
+
timestamp: event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
135
|
+
};
|
|
136
|
+
if (!config.includeInputs && normalized.input) delete normalized.input;
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
async function emitDocsAnalyticsEvent(analytics, event) {
|
|
140
|
+
const resolved = resolveDocsAnalyticsConfig(analytics);
|
|
141
|
+
if (!resolved.enabled) return;
|
|
142
|
+
const normalized = normalizeAnalyticsEvent(event, resolved);
|
|
143
|
+
if (resolved.console) (console[resolved.console] ?? console.info).call(console, ANALYTICS_LOG_PREFIX, normalized);
|
|
144
|
+
if (!resolved.onEvent) return;
|
|
145
|
+
try {
|
|
146
|
+
await resolved.onEvent(normalized);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (resolved.console !== false) console.warn(`${ANALYTICS_LOG_PREFIX} onEvent failed`, error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function emitDocsObservabilityEvent(observability, event) {
|
|
152
|
+
const resolved = resolveDocsObservabilityConfig(observability);
|
|
153
|
+
if (!resolved.enabled) return;
|
|
154
|
+
const normalized = normalizeObservabilityEvent(event, resolved);
|
|
155
|
+
if (resolved.console) (console[resolved.console] ?? console.info).call(console, OBSERVABILITY_LOG_PREFIX, normalized);
|
|
156
|
+
if (!resolved.onEvent) return;
|
|
157
|
+
try {
|
|
158
|
+
await resolved.onEvent(normalized);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (resolved.console !== false) console.warn(`${OBSERVABILITY_LOG_PREFIX} onEvent failed`, error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function emitDocsAgentTraceEvent(observability, event) {
|
|
164
|
+
const timestamp = event.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
165
|
+
await emitDocsObservabilityEvent(observability, {
|
|
166
|
+
...event,
|
|
167
|
+
timestamp,
|
|
168
|
+
source: event.source ?? "server",
|
|
169
|
+
traceId: event.traceId ?? createDocsAgentTraceId("run"),
|
|
170
|
+
spanId: event.spanId ?? createDocsAgentTraceId("span"),
|
|
171
|
+
startedAt: event.startedAt ?? timestamp,
|
|
172
|
+
status: event.status ?? "success"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
export { emitDocsAnalyticsEvent as a, resolveDocsAnalyticsConfig as c, emitDocsAgentTraceEvent as i, resolveDocsObservabilityConfig as l, createDocsAgentTraceContext as n, emitDocsObservabilityEvent as o, createDocsAgentTraceId as r, getDocsRequestAnalyticsProperties as s, DOCS_AGENT_TRACE_EVENT_TYPES as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/cli/errors.d.ts
|
|
2
|
+
declare function formatCliError(error: unknown): string;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/cli/index.d.ts
|
|
5
|
+
declare const UPGRADE_TAGS: readonly ["latest", "beta"];
|
|
6
|
+
type UpgradeTag = (typeof UPGRADE_TAGS)[number];
|
|
7
|
+
/** Normalize command aliases like `upgrade@beta` into the base command + dist-tag. */
|
|
8
|
+
declare function parseCommandAlias(rawCommand?: string): {
|
|
9
|
+
command?: string;
|
|
10
|
+
tag?: UpgradeTag;
|
|
11
|
+
};
|
|
12
|
+
/** Parse flags like --template next, --name my-docs, --theme concrete, --entry docs, --framework astro (exported for tests). */
|
|
13
|
+
declare function parseFlags(argv: string[]): Record<string, string | boolean | undefined>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { formatCliError, parseCommandAlias, parseFlags };
|