// @bun
import {
  assertValidProject
} from "./chunk-1kgmzwze.js";
import {
  checkRuntimeVersion
} from "./chunk-rkjpw96h.js";
import {
  ensureJsonOnlyFormat
} from "./chunk-5zqmmchg.js";
import {
  telemetry_default
} from "./chunk-c18d2qwm.js";
import {
  findAgentRootOrFail
} from "./chunk-6fad0ts7.js";
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import {
  AgentProject,
  BpBuildCommand,
  generateAssetsRuntime,
  generateAssetsTypes,
  generateBotProject
} from "./chunk-7krp2mgz.js";
import {
  __require
} from "./chunk-dhs2bg35.js";

// src/commands/adk-build.ts
import path from "path";
async function adkBuild(options = {}) {
  ensureJsonOnlyFormat(options.format);
  const { silent = false, adkCommand = "adk-build" } = options;
  const logger = createCliLogger({ format: options.format, silent });
  logger.info("\uD83D\uDD28 Building ADK agent for production...", "blue");
  const { checkNodeVersion } = await import("./chunk-1q18v05y.js");
  checkNodeVersion(true);
  const agentRoot = await findAgentRootOrFail(process.cwd());
  await checkRuntimeVersion(agentRoot);
  const project = await AgentProject.load(agentRoot, {
    adkCommand: "adk-build"
  });
  await assertValidProject(project);
  logger.info(`\uD83D\uDCE6 Loaded project: ${project.config?.name || "Unknown"}`, "green");
  logger.info("\uD83D\uDCDD Generating assets types...", "cyan");
  try {
    await generateAssetsTypes(project.path);
    await generateAssetsRuntime(project.path, project.agentInfo?.botId);
    logger.info("\u2705 Assets types generated", "green");
  } catch (err) {
    logger.warn("\u26A0\uFE0F  No assets directory found, skipping asset type generation");
    logger.debug(`Asset type generation failed: ${err instanceof Error ? err.message : String(err)}`);
  }
  if (options.beforeGenerate) {
    await options.beforeGenerate();
  }
  logger.info("\uD83D\uDD28 Generating Botpress bot project...", "cyan");
  const botPath = path.join(project.path, ".adk", "bot");
  await generateBotProject({
    projectPath: project.path,
    outputPath: botPath,
    adkCommand
  });
  logger.info("\u2705 Bot project generated", "green");
  logger.info("\uD83C\uDFD7\uFE0F  Building agent...", "cyan");
  const buildCommand = new BpBuildCommand({ botPath });
  await buildCommand.run();
  await buildCommand.output();
  const primitiveTypes = [
    { type: "action", items: project.actions || [] },
    { type: "workflow", items: project.workflows || [] },
    { type: "conversation", items: project.conversations || [] },
    { type: "trigger", items: project.triggers || [] },
    { type: "table", items: project.tables || [] }
  ];
  for (const { type, items } of primitiveTypes) {
    for (const item of items) {
      telemetry_default.track("primitive_created", {
        type,
        name: item.name || ""
      });
    }
  }
  const { getAdkVersion } = await import("./chunk-tjmkrr1f.js");
  telemetry_default.track("build", {
    adkVersion: getAdkVersion()
  });
  logger.info(`
\u2705 Build completed successfully!`, "green").result({
    success: true,
    project: project.config?.name || "Unknown",
    outputDir: path.join(botPath, ".botpress", "dist")
  });
  logger.info(`\uD83D\uDCE6 Output directory: ${path.join(botPath, ".botpress", "dist")}`);
  logger.info(`
Next steps:`);
  logger.info("  - Run `adk deploy` to deploy your agent");
  logger.info("  - Or run `cd .adk/bot && bp deploy` to deploy manually");
}

export { adkBuild };
