UNPKG

@botpress/adk-cli

Version:

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

80 lines (77 loc) 2.91 kB
// @bun // ../analytics/src/constants.ts var POSTHOG_API_KEY = typeof process !== "undefined" && process.env?.POSTHOG_API_KEY || "phc_i782iVFulXCgIMKtyOL5ns4IR1w4oW9lA5sUzwuY4wj"; var POSTHOG_HOST = "https://us.i.posthog.com"; // ../analytics/src/sanitize.ts function sanitizeErrorMessage(message) { let sanitized = message; sanitized = sanitized.replace(/\/[^\s"'`]+(\/[^\s"'`]+)+/g, "<path>"); sanitized = sanitized.replace(/[A-Z]:\\[\w\\]+/g, "<path>"); sanitized = sanitized.replace(/bp_pat_[A-Za-z0-9]+/g, "<token>"); sanitized = sanitized.replace(/Bearer\s+[A-Za-z0-9._-]+/g, "Bearer <token>"); sanitized = sanitized.replace(/phc_[A-Za-z0-9]+/g, "<posthog_key>"); sanitized = sanitized.replace(/([A-Z_]{2,})=\S+/g, "$1=<redacted>"); sanitized = sanitized.replace(/https?:\/\/[^:]+:[^@]+@/g, "https://<redacted>@"); if (sanitized.length > 500) { sanitized = sanitized.slice(0, 497) + "..."; } return sanitized; } function sanitizeStackTrace(stack) { let sanitized = stack; sanitized = sanitized.replace(/\/(Users|home)\/[^/\s)]+/g, "/$1/<user>"); sanitized = sanitized.replace(/([A-Z]:\\Users\\)[^\\\s)]+/gi, "$1<user>"); sanitized = sanitized.replace(/bp_pat_[A-Za-z0-9]+/g, "<token>"); sanitized = sanitized.replace(/Bearer\s+[A-Za-z0-9._-]+/g, "Bearer <token>"); sanitized = sanitized.replace(/phc_[A-Za-z0-9]+/g, "<posthog_key>"); return sanitized; } function toSanitizedError(error) { if (!(error instanceof Error)) { return new Error(sanitizeErrorMessage(String(error))); } const message = sanitizeErrorMessage(error.message); const sanitized = new Error(message); sanitized.name = error.name; if (error.stack) { const lines = error.stack.split(` `); let frameStart = lines.length; while (frameStart > 0 && /^\s+at /.test(lines[frameStart - 1])) frameStart--; const frames = lines.slice(frameStart); sanitized.stack = [`${error.name}: ${message}`, ...frames.map(sanitizeStackTrace)].join(` `); } else { sanitized.stack = `${error.name}: ${message}`; } return sanitized; } // ../analytics/src/errors.ts class AdkError extends Error { static __IS_ADK_BASE_ERROR = true; code; expected; details; suggestion; constructor(opts) { super(opts.message, opts.cause !== undefined ? { cause: opts.cause } : undefined); this.name = this.constructor.name; this.code = opts.code; this.expected = opts.expected ?? false; if (opts.details !== undefined) { this.details = opts.details; } if (opts.suggestion !== undefined) { this.suggestion = opts.suggestion; } } } function isAdkError(error) { if (error instanceof AdkError) return true; if (!(error instanceof Error)) return false; return error.constructor?.__IS_ADK_BASE_ERROR === true; } export { POSTHOG_API_KEY, POSTHOG_HOST, sanitizeErrorMessage, toSanitizedError, AdkError, isAdkError };