import { createRequire } from "node:module";
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toESMCache_node;
var __toESMCache_esm;
var __toESM = (mod, isNodeMode, target) => {
  var canCache = mod != null && typeof mod === "object";
  if (canCache) {
    var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
    var cached = cache.get(mod);
    if (cached)
      return cached;
  }
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: __accessProp.bind(mod, key),
        enumerable: true
      });
  if (canCache)
    cache.set(mod, to);
  return to;
};
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = /* @__PURE__ */ createRequire(import.meta.url);

// ../analytics/src/errors.ts
function isAdkError(error) {
  if (error instanceof AdkError)
    return true;
  if (!(error instanceof Error))
    return false;
  return error.constructor?.__IS_ADK_BASE_ERROR === true;
}
var AdkError;
var init_errors = __esm(() => {
  AdkError = 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;
      }
    }
  };
});

// ../analytics/src/index.ts
var init_src = __esm(() => {
  init_errors();
});

// src/commands/bp-cli.ts
init_src();
import { existsSync } from "fs";
import os from "os";
import path from "path";
import createDebug from "debug";
var debug = createDebug("adk:bp-cli");
var BP_CLI_VERSION = "6.8.6";
var BP_CLI_INSTALL_ALL = path.join(os.homedir(), ".adk", `bp-cli`);
var BP_CLI_INSTALL_DIR = path.join(BP_CLI_INSTALL_ALL, BP_CLI_VERSION);
var BP_CLI_BIN_PATH = path.join(BP_CLI_INSTALL_DIR, "node_modules", "@botpress", "cli", "bin.js");
var BP_CLIENT_ENV_KEYS = [
  "BP_API_URL",
  "BP_TOKEN",
  "BP_WORKSPACE_ID",
  "BP_BOT_ID",
  "BP_INTEGRATION_ID",
  "BP_INTEGRATION_ALIAS"
];
debug("BP_CLI_VERSION=%s (injected at build time)", BP_CLI_VERSION);
debug("BP_CLI_INSTALL_ALL=%s", BP_CLI_INSTALL_ALL);
debug("BP_CLI_INSTALL_DIR=%s", BP_CLI_INSTALL_DIR);
debug("BP_CLI_BIN_PATH=%s", BP_CLI_BIN_PATH);
function getBpCli() {
  debug("getBpCli() called");
  debug("checking if BP_CLI_BIN_PATH exists: %s", BP_CLI_BIN_PATH);
  const exists = existsSync(BP_CLI_BIN_PATH);
  debug("BP_CLI_BIN_PATH exists=%s", exists);
  if (!exists) {
    debug("ERROR: bp CLI not found at expected path");
    throw new AdkError({
      code: "INTERNAL_BP_CLI_MISSING",
      message: `@botpress/cli version ${BP_CLI_VERSION} is not installed in the ADK directory "${BP_CLI_INSTALL_DIR}". This is a bug, please report it to the Botpress team.`,
      expected: false
    });
  }
  const info = {
    path: BP_CLI_BIN_PATH,
    version: BP_CLI_VERSION
  };
  debug("returning BpCliInfo: %O", info);
  return info;
}
function getBpCliEnvironment(overrides = {}) {
  const env = { ...process.env };
  for (const key of BP_CLIENT_ENV_KEYS) {
    delete env[key];
  }
  return {
    ...env,
    ...overrides
  };
}
export {
  getBpCliEnvironment,
  getBpCli,
  BP_CLI_VERSION,
  BP_CLI_INSTALL_DIR,
  BP_CLI_INSTALL_ALL,
  BP_CLI_BIN_PATH
};

//# debugId=7A5941364504441B64756E2164756E21
