@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
117 lines (115 loc) • 3.6 kB
JavaScript
// @bun
import {
assertValidProject
} from "./chunk-wmec2w0t.js";
import {
resolveCommandContext
} from "./chunk-3ahwp6fe.js";
import"./chunk-m2h26j5f.js";
import"./chunk-8gqzjqmb.js";
import"./chunk-kk3h6qaj.js";
import {
createCliLogger
} from "./chunk-gzwt1qdr.js";
import"./chunk-nxy2ya5r.js";
import"./chunk-wzj4dc7n.js";
import {
AdkError,
ScriptRunner
} from "./chunk-p0hjqn4r.js";
import"./chunk-np5wcwfv.js";
import"./chunk-dq2xpa24.js";
import"./chunk-6w0knnta.js";
import"./chunk-40x04ckt.js";
import"./chunk-t76d8fxx.js";
import"./chunk-nh2akp42.js";
import"./chunk-0fdvzjbh.js";
import"./chunk-2a5b6azq.js";
import"./chunk-vay209b5.js";
import"./chunk-3xrpxgq4.js";
import"./chunk-rfm3jr1m.js";
import"./chunk-w346ejn9.js";
import"./chunk-knvm2anf.js";
import"./chunk-65h5trb5.js";
import"./chunk-s2akeqpw.js";
import"./chunk-6771vrjp.js";
import"./chunk-g8mm42v1.js";
import"./chunk-50hzjdck.js";
import"./chunk-nn2jb0x0.js";
import"./chunk-v8xvth6j.js";
import"./chunk-kkk13rcb.js";
import"./chunk-ytpp1kam.js";
import"./chunk-na956zz3.js";
import"./chunk-f4bw8q7c.js";
import"./chunk-0v8vgrns.js";
import"./chunk-54qt5g7m.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-c07hkzqm.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
});
}
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
};