UNPKG

@botpress/adk-cli

Version:

Command-line interface for the Botpress Agent Development Kit (ADK)

64 lines (59 loc) 2.14 kB
// @bun import { isAdkError, toSanitizedError } from "./chunk-wzj4dc7n.js"; // src/utils/build-constants.ts var CLI_VERSION = "2.0.5"; var EXPECTED_RUNTIME_VERSION = "2.0.5"; var IS_RELEASE_BUILD = false; // ../analytics/src/node.ts import { homedir } from "os"; import { join } from "path"; var TELEMETRY_CONFIG_DIR = join(homedir(), ".botpress"); var TELEMETRY_CONFIG_FILE = join(TELEMETRY_CONFIG_DIR, "telemetry.json"); // src/utils/telemetry-spool.ts import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync } from "fs"; import { dirname, join as join2 } from "path"; var FATAL_SPOOL_FILE = join2(TELEMETRY_CONFIG_DIR, "pending-exceptions.jsonl"); var FATAL_SPOOL_MAX_BYTES = 64 * 1024; function isTelemetryEnabled() { if (process.env.DO_NOT_TRACK === "1" || process.env.DO_NOT_TRACK === "true") return false; try { if (existsSync(TELEMETRY_CONFIG_FILE)) { const config = JSON.parse(readFileSync(TELEMETRY_CONFIG_FILE, "utf-8")); return config.enabled !== false; } } catch {} return true; } function spoolExceptionBeforeExit(error, properties = {}, spoolFile = FATAL_SPOOL_FILE) { if (false) ; if (!isTelemetryEnabled()) return; try { const sanitized = toSanitizedError(error); const record = { name: sanitized.name, message: sanitized.message, ...sanitized.stack ? { stack: sanitized.stack } : {}, properties: { ...properties, error_type: error instanceof Error ? error.constructor.name : "UnknownError", ...isAdkError(error) ? { error_code: error.code, expected: error.expected } : {}, adk_version: CLI_VERSION, timestamp: new Date().toISOString() } }; const dir = dirname(spoolFile); if (!existsSync(dir)) mkdirSync(dir, { recursive: true }); if (existsSync(spoolFile) && statSync(spoolFile).size > FATAL_SPOOL_MAX_BYTES) return; appendFileSync(spoolFile, `${JSON.stringify(record)} `); } catch {} } export { CLI_VERSION, EXPECTED_RUNTIME_VERSION, IS_RELEASE_BUILD, TELEMETRY_CONFIG_DIR, TELEMETRY_CONFIG_FILE, FATAL_SPOOL_FILE, spoolExceptionBeforeExit };