@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
246 lines (244 loc) • 8.34 kB
JavaScript
// @bun
import {
select
} from "./chunk-seyt2a5p.js";
import {
adkLogo
} from "./chunk-5agyx08n.js";
import"./chunk-bexyahs9.js";
import {
telemetry_default
} from "./chunk-kwmsaz7n.js";
import"./chunk-9e2nksab.js";
import {
bold,
box,
fg,
getActiveTheme,
mount,
renderToString,
router,
signal,
t,
text
} from "./chunk-m2h26j5f.js";
import"./chunk-8gqzjqmb.js";
import {
createCliLogger
} from "./chunk-gzwt1qdr.js";
import"./chunk-nxy2ya5r.js";
import"./chunk-wzj4dc7n.js";
import {
auth,
getRelativeTime
} 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-profiles.ts
function buildProfilesList(ctx, profiles, currentProfile) {
const theme = getActiveTheme();
const list = profiles.map((profile) => {
const isCurrent = profile.name === currentProfile;
const userDisplay = profile.displayName ? `${profile.displayName} (${profile.email})` : profile.email || "Unknown user";
const nameLine = isCurrent ? text(ctx, t`${fg(theme.status.success)(bold(`${theme.symbols.pointer} ${profile.name}`))}${fg(theme.text.dim)(" (current)")}`) : text(ctx, t`${fg(theme.text.primary)(` ${profile.name}`)}`);
return box(ctx, { flexDirection: "column", marginBottom: 1 }, [
box(ctx, {}, [nameLine]),
box(ctx, { paddingLeft: 2 }, [text(ctx, t`${fg(theme.text.primary)(userDisplay)}`)]),
box(ctx, { paddingLeft: 2 }, [text(ctx, t`${fg(theme.text.primary)(profile.apiUrl.replace("https://", ""))}`)]),
box(ctx, { paddingLeft: 2 }, [text(ctx, t`${fg(theme.text.dim)(`Used ${getRelativeTime(profile.lastUsed)}`)}`)])
]);
});
return box(ctx, { flexDirection: "column", paddingX: 1, paddingY: 1 }, [
adkLogo(ctx, { subtitle: "Profiles" }),
box(ctx, { marginTop: 1 }, [text(ctx, t`${fg(theme.text.dim)(`Current profile: ${currentProfile}`)}`)]),
box(ctx, { flexDirection: "column", marginTop: 1 }, list)
]);
}
var adkProfilesList = async () => {
const logger = createCliLogger();
if (!process.stdout.isTTY) {
try {
const profiles = await auth.listProfiles();
const currentProfile = await auth.getCurrentProfile();
if (profiles.length === 0) {
logger.warn("No profiles found.");
logger.info("Use 'adk login' to create your first profile.", "gray");
return;
}
logger.info("Botpress ADK Profiles");
logger.info(`Current profile: ${currentProfile}
`, "gray");
profiles.forEach((profile) => {
const isCurrent = profile.name === currentProfile;
const marker = isCurrent ? "\u25B8" : " ";
const currentLabel = isCurrent ? " (current)" : "";
const userDisplay = profile.displayName ? `${profile.displayName} (${profile.email})` : profile.email || "Unknown user";
if (isCurrent) {
logger.info(`${marker} ${profile.name}${currentLabel}`, "green");
} else {
logger.info(`${marker} ${profile.name}${currentLabel}`, "cyan");
}
logger.info(` ${userDisplay}`);
logger.info(` ${profile.apiUrl.replace("https://", "")}`);
logger.info(` Used ${getRelativeTime(profile.lastUsed)}
`, "gray");
});
} catch (error) {
logger.fatal(error);
}
return;
}
try {
const profiles = await auth.listProfiles();
const currentProfile = await auth.getCurrentProfile();
if (profiles.length === 0) {
console.log(await renderToString((ctx) => {
const theme = getActiveTheme();
return box(ctx, { flexDirection: "column", paddingX: 1, paddingY: 1 }, [
text(ctx, t`${fg(theme.status.warning)("No profiles found.")}`),
text(ctx, t`${fg(theme.text.dim)("Use 'adk login' to create your first profile.")}`)
]);
}));
return;
}
console.log(await renderToString((ctx) => buildProfilesList(ctx, profiles, currentProfile)));
} catch (error) {
logger.fatal(error);
}
};
var adkProfilesSet = async (profileName) => {
const logger = createCliLogger();
if (profileName) {
try {
await auth.setCurrentProfile(profileName);
telemetry_default.reset();
logger.info(`\u2713 Successfully switched to profile: ${profileName}`, "green");
} catch (error) {
logger.fatal(error);
}
return;
}
let appRef = null;
let exitCode = 0;
const close = (code = 0, delayMs = 0) => {
exitCode = code;
setTimeout(() => appRef?.unmount(), delayMs);
};
const app = await mount((renderer, scope) => {
const theme = getActiveTheme();
const view = signal("loading");
const errorMsg = signal("");
const selected = signal(profileName || "");
let options = [];
let successUser = "";
const finishSuccess = (name, userInfo) => {
selected.set(name);
successUser = userInfo;
view.set("success");
close(0, 500);
};
(async () => {
try {
const profiles = await auth.listProfiles();
if (profiles.length === 0) {
errorMsg.set("No profiles found. Use 'adk login' to create your first profile.");
view.set("error");
close(1, 100);
return;
}
options = profiles.map((p) => {
const userDisplay = p.displayName ? `${p.displayName} (${p.email})` : p.email || "Unknown user";
return {
id: p.name,
label: p.name,
value: p.name,
description: `${userDisplay}
${p.apiUrl.replace("https://", "")}
Used ${getRelativeTime(p.lastUsed)}`
};
});
view.set("select");
} catch (error) {
errorMsg.set(error instanceof Error ? error.message : "Failed to set profile");
view.set("error");
}
})();
const handleSelect = async (name) => {
view.set("loading");
try {
await auth.setCurrentProfile(name);
telemetry_default.reset();
const opt = options.find((o) => o.id === name);
finishSuccess(name, opt?.description?.split(`
`)[0] || "Unknown user");
} catch (error) {
errorMsg.set(error instanceof Error ? error.message : "Failed to set profile");
view.set("error");
}
};
return router(renderer, scope, view, (v, viewScope) => {
if (v === "loading") {
return box(renderer, { flexDirection: "column" }, [
text(renderer, t`${fg(theme.text.dim)("Setting profile\u2026")}`)
]);
}
if (v === "error") {
return box(renderer, { flexDirection: "column" }, [
text(renderer, t`${fg(theme.status.error)(`Error: ${errorMsg()}`)}`)
]);
}
if (v === "success") {
return box(renderer, { flexDirection: "column" }, [
text(renderer, t`${fg(theme.status.success)(`${theme.symbols.checkmark} Successfully switched to profile: ${selected()}`)}`),
text(renderer, t`${fg(theme.text.primary)(`Logged in as ${successUser}`)}`)
]);
}
return box(renderer, { flexDirection: "column", paddingX: 1, paddingY: 1 }, [
adkLogo(renderer, { subtitle: "Select Profile" }),
box(renderer, { marginTop: 1 }, [
text(renderer, t`${fg(theme.text.dim)("Press Enter to switch \u2022 Esc to cancel")}`)
]),
select(renderer, viewScope, {
options,
initialSelected: selected(),
onSubmit: handleSelect,
onCancel: () => close(0)
})
]);
});
}, { exitOnCtrlC: true });
appRef = app;
await app.waitUntilExit();
if (exitCode !== 0) {
process.exitCode = exitCode;
}
};
export {
adkProfilesSet,
adkProfilesList
};