@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
197 lines (195 loc) • 6.14 kB
JavaScript
// @bun
import {
validateAndPromptConfig
} from "./chunk-sky56mbb.js";
import"./chunk-tefbm840.js";
import"./chunk-bexyahs9.js";
import {
ensureJsonOnlyFormat
} from "./chunk-7sfagm12.js";
import {
resolveCommandContext
} from "./chunk-3ahwp6fe.js";
import"./chunk-9e2nksab.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,
ConfigManager
} 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"./chunk-dhs2bg35.js";
// src/commands/adk-config.ts
import path from "path";
async function adkConfig(key, options = {}) {
ensureJsonOnlyFormat(options.format);
const logger = createCliLogger({ format: options.format });
const isJson = options.format === "json";
const projectPath = path.resolve(process.cwd());
const isProd = options.prod || false;
const context = await resolveCommandContext({
target: isProd ? "prod" : "dev",
require: ["project", "credentials", "workspace"]
});
const project = context.project;
const configSchema = project.config?.configuration?.schema;
if (!configSchema) {
if (isJson) {
throw new AdkError({
code: "NO_CONFIG_SCHEMA",
message: "No configuration schema defined in agent.config.ts",
expected: true
});
}
logger.warn("No configuration schema defined in agent.config.ts");
return;
}
const botId = isProd ? project.agentInfo?.botId : project.agentInfo?.devId;
if (!botId) {
if (isJson) {
throw new AdkError({
code: "BOT_NOT_LINKED",
message: `No ${isProd ? "production" : "development"} bot ID found`,
expected: true
});
}
logger.warn(`No ${isProd ? "production bot ID found in agent.json" : "development bot ID found in agent.local.json"}`);
logger.info(`Run 'adk ${isProd ? "deploy" : "dev"}' first to create a bot
`, "gray");
return;
}
const configManager = new ConfigManager(botId, {
project,
credentials: context.credentials
});
const env = isProd ? "production" : "development";
if (!key) {
const allConfig = await configManager.getAll();
logger.info(`
\uD83D\uDCDD Configuration (${env})
`, "blue").result({ success: true, config: allConfig ?? {} });
if (!isJson) {
await validateAndPromptConfig({
projectPath,
isProd,
interactive: true,
botId,
project,
credentials: context.credentials
});
}
return;
}
const configValue = await configManager.get(key);
if (configValue === undefined) {
if (isJson) {
throw new AdkError({ code: "CONFIG_KEY_NOT_FOUND", message: `No value found for key: ${key}`, expected: true });
}
logger.warn(`No value found for key: ${key}`);
logger.info(`Environment: ${env}
`, "gray");
return;
}
logger.info(`
\uD83D\uDCDD Configuration value (${env})
`, "blue");
logger.info(` Key: ${key}`, "cyan");
logger.info(` Value: ${configValue}`).result({ success: true, key, value: configValue ?? null });
logger.newline();
}
async function adkConfigSet(key, value, options = {}) {
ensureJsonOnlyFormat(options.format);
const logger = createCliLogger({ format: options.format });
const isJson = options.format === "json";
const isProd = options.prod || false;
const context = await resolveCommandContext({
target: isProd ? "prod" : "dev",
require: ["project", "credentials", "workspace"]
});
const project = context.project;
const configSchema = project.config?.configuration?.schema;
if (!configSchema) {
if (isJson) {
throw new AdkError({
code: "NO_CONFIG_SCHEMA",
message: "No configuration schema defined in agent.config.ts",
expected: true
});
}
logger.warn("No configuration schema defined in agent.config.ts");
return;
}
const botId = isProd ? project.agentInfo?.botId : project.agentInfo?.devId;
if (!botId) {
if (isJson) {
throw new AdkError({
code: "BOT_NOT_LINKED",
message: `No ${isProd ? "production" : "development"} bot ID found`,
expected: true
});
}
logger.warn(`No ${isProd ? "production bot ID found in agent.json" : "development bot ID found in agent.local.json"}`);
logger.info(`Run 'adk ${isProd ? "deploy" : "dev"}' first to create a bot
`, "gray");
return;
}
const configManager = new ConfigManager(botId, {
project,
credentials: context.credentials
});
const env = isProd ? "production" : "development";
const normalizedValue = value.trim();
if (normalizedValue.length === 0) {
throw new AdkError({
code: "INVALID_CONFIG_VALUE",
message: `Invalid value for key "${key}": value cannot be empty`,
expected: true
});
}
const result = await configManager.setWithValidation(key, normalizedValue, configSchema);
if (result.success === false) {
throw new AdkError({ code: "INVALID_CONFIG_VALUE", message: result.error, expected: true, cause: result.error });
}
logger.info(`\u2713 Configuration updated (${env})`, "green");
logger.info(` ${key} = ${result.data}
`, "cyan").result({ success: true, key, value: result.data });
}
async function adkConfigGet(key, options = {}) {
await adkConfig(key, options);
}
export {
adkConfigSet,
adkConfigGet,
adkConfig
};