// @bun
import {
  assertValidProject
} from "./chunk-1kgmzwze.js";
import {
  checkRuntimeVersion
} from "./chunk-rkjpw96h.js";
import"./chunk-62hm2spv.js";
import"./chunk-7zvmmxnc.js";
import {
  resolveCommandContext
} from "./chunk-2jcqy5j6.js";
import"./chunk-m2h26j5f.js";
import"./chunk-8gqzjqmb.js";
import"./chunk-6fad0ts7.js";
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import"./chunk-px7fts59.js";
import {
  AdkError,
  ScriptRunner
} from "./chunk-7krp2mgz.js";
import"./chunk-np5wcwfv.js";
import"./chunk-je8v6rhj.js";
import"./chunk-6w0knnta.js";
import"./chunk-w15xmtkn.js";
import"./chunk-3sd5p4qp.js";
import"./chunk-nh2akp42.js";
import"./chunk-kat1bv74.js";
import"./chunk-2a5b6azq.js";
import"./chunk-s8cp3qe6.js";
import"./chunk-fv5teh9w.js";
import"./chunk-8ab2w9a1.js";
import"./chunk-3xrpxgq4.js";
import"./chunk-w346ejn9.js";
import"./chunk-n8gath4k.js";
import"./chunk-v3ens42y.js";
import"./chunk-8839jtgk.js";
import"./chunk-s2akeqpw.js";
import"./chunk-6771vrjp.js";
import"./chunk-g8mm42v1.js";
import"./chunk-0q5d80bn.js";
import"./chunk-300xaact.js";
import"./chunk-b8c41yvb.js";
import"./chunk-jsqe5am4.js";
import"./chunk-m4c14gcg.js";
import"./chunk-gspjbr79.js";
import"./chunk-wesykvkp.js";
import"./chunk-gzj56z73.js";
import {
  __require
} from "./chunk-dhs2bg35.js";

// src/commands/adk-run.ts
import path from "path";
import { existsSync } from "fs";
async function adkRun(scriptPath, args = [], options = {}) {
  const logger = createCliLogger();
  const envLabel = options.prod ? "production" : "development";
  logger.info(`\uD83D\uDE80 Running script with ADK runtime (${envLabel})...`, "blue");
  try {
    const { checkNodeVersion } = await import("./chunk-1q18v05y.js");
    checkNodeVersion(true);
    const context = await resolveCommandContext({
      target: options.prod ? "prod" : "dev",
      projectLoadOptions: { adkCommand: "adk-build" },
      require: ["project", "credentials", "workspace"]
    });
    const agentRoot = context.agentRoot;
    const credentials = context.credentials;
    if (!credentials.token) {
      throw new AdkError({
        code: "AUTH_REQUIRED",
        message: 'No credentials found. Please run "adk login" first.',
        expected: true
      });
    }
    await checkRuntimeVersion(agentRoot);
    const project = context.project;
    await assertValidProject(project);
    logger.info(`\uD83D\uDCE6 Project: ${project.config?.name || "Unknown"}`, "green");
    const absoluteScriptPath = path.isAbsolute(scriptPath) ? scriptPath : path.resolve(process.cwd(), scriptPath);
    if (!existsSync(absoluteScriptPath)) {
      throw new AdkError({
        code: "SCRIPT_NOT_FOUND",
        message: `Script not found: ${absoluteScriptPath}`,
        expected: true
      });
    }
    logger.info(`\uD83D\uDCDC Script: ${path.relative(process.cwd(), absoluteScriptPath)}`, "cyan");
    const runner = new ScriptRunner({
      projectPath: agentRoot,
      forceRegenerate: options.force,
      prod: options.prod,
      credentials: {
        token: credentials.token,
        apiUrl: credentials.apiUrl,
        ...credentials.workspaceId ? { workspaceId: credentials.workspaceId } : {}
      }
    });
    logger.info("\uD83D\uDD27 Preparing ADK runtime...", "cyan");
    const exitCode = await runner.run(absoluteScriptPath, {
      args,
      inheritStdio: true
    });
    if (exitCode === 0) {
      logger.info(`
\u2705 Script completed successfully`, "green");
    } else {
      logger.error(`
\u274C Script exited with code ${exitCode}`);
      process.exit(exitCode);
    }
  } catch (err) {
    logger.error(`\u274C Script execution failed: ${err instanceof Error ? err.message : String(err)}`);
    throw err;
  }
}
export {
  adkRun
};
