@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
135 lines (133 loc) • 4.74 kB
JavaScript
// @bun
import {
ensureJsonOnlyFormat
} from "./chunk-7sfagm12.js";
import {
createCliLogger
} from "./chunk-gzwt1qdr.js";
import"./chunk-nxy2ya5r.js";
import"./chunk-wzj4dc7n.js";
import {
AdkError,
AgentProject,
SecretsManager,
validateSecretName
} 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-secret.ts
import path from "path";
async function adkSecret(options = {}) {
ensureJsonOnlyFormat(options.format);
const logger = createCliLogger({ format: options.format });
const isJson = options.format === "json";
const projectPath = path.resolve(process.cwd());
const project = await AgentProject.load(projectPath);
const manager = new SecretsManager(projectPath);
const declaredSecrets = project.config?.secrets ?? {};
if (Object.keys(declaredSecrets).length === 0) {
if (isJson) {
logger.info("").result({ success: true, secrets: [] });
} else {
logger.info("No secrets declared in agent.config.ts");
}
return;
}
const devSecrets = await manager.getAll("dev", declaredSecrets);
const prodSecrets = await manager.getAll("prod", declaredSecrets);
const buildList = (stored) => Object.entries(declaredSecrets).map(([name, def]) => ({
name,
declared: true,
set: name in stored,
optional: def.optional ?? false,
description: def.description ?? ""
}));
const devList = buildList(devSecrets);
const prodList = buildList(prodSecrets);
const printList = (label, list) => {
logger.info(`
\uD83D\uDD11 Secrets (${label})
`, "blue");
for (const secret of list) {
const status = secret.set ? "\u2713 set" : "\u2717 not set";
const optionalTag = secret.optional ? " (optional)" : "";
const descTag = secret.description ? ` \u2014 ${secret.description}` : "";
const color = secret.set ? "green" : "yellow";
logger.info(` ${secret.name}: ${status}${optionalTag}${descTag}`, color);
}
};
printList("dev", devList);
printList("prod", prodList);
logger.newline();
logger.info("").result({ success: true, dev: devList, prod: prodList });
}
async function adkSecretSet(key, value, options = {}) {
ensureJsonOnlyFormat(options.format);
const logger = createCliLogger({ format: options.format });
const projectPath = path.resolve(process.cwd());
const env = options.prod ? "prod" : "dev";
const validation = validateSecretName(key);
if (!validation.valid) {
throw new AdkError({ code: "INVALID_SECRET", message: validation.error, expected: true });
}
const project = await AgentProject.load(projectPath);
const declaredSecrets = project.config?.secrets ?? {};
if (!(key in declaredSecrets)) {
const available = Object.keys(declaredSecrets);
throw new AdkError({
code: "INVALID_SECRET",
message: available.length > 0 ? `Secret "${key}" is not declared in agent.config.ts. Available secrets: ${available.join(", ")}` : `Secret "${key}" is not declared in agent.config.ts. Add it to the secrets field in your config first.`,
expected: true
});
}
const normalizedValue = value.trim();
if (normalizedValue.length === 0) {
throw new AdkError({
code: "INVALID_SECRET",
message: `Invalid value for secret "${key}": value cannot be empty`,
expected: true
});
}
const manager = new SecretsManager(projectPath);
await manager.set(key, normalizedValue, env);
logger.info(`\u2713 Secret ${key} set (${env})`, "green").result({ success: true, key });
}
async function adkSecretDelete(key, options = {}) {
ensureJsonOnlyFormat(options.format);
const logger = createCliLogger({ format: options.format });
const projectPath = path.resolve(process.cwd());
const env = options.prod ? "prod" : "dev";
const manager = new SecretsManager(projectPath);
await manager.delete(key, env);
logger.info(`\u2713 Secret ${key} deleted (${env})`, "green").result({ success: true, key });
}
export {
adkSecretSet,
adkSecretDelete,
adkSecret
};