@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
56 lines (54 loc) • 2.13 kB
JavaScript
// @bun
// src/utils/dependency-status-format.ts
function formatStatusLine(d) {
const ref = `${d.alias} (${d.name}@${d.version})`;
switch (d.state) {
case "available":
return `\u2713 ${ref} \u2014 available`;
case "disabled":
return `\u2022 ${ref} \u2014 disabled`;
case "unconfigured": {
const fields = d.missingFields && d.missingFields.length > 0 ? ` (missing: ${d.missingFields.join(", ")})` : "";
return `\u2717 ${ref} \u2014 unconfigured${fields}`;
}
case "not_installed":
return `\u2717 ${ref} \u2014 not installed`;
case "unresolved":
return `\u2717 ${ref} \u2014 unresolved`;
case "errored":
return `\u2717 ${ref} \u2014 errored`;
default:
return `? ${ref} \u2014 ${d.state}`;
}
}
function remediationFor(d) {
const group = `${d.type}s`;
switch (d.state) {
case "available":
return;
case "unconfigured": {
const fields = d.missingFields && d.missingFields.length > 0 ? ` ${d.missingFields.map((f) => `--set ${f}=\u2026`).join(" ")}` : "";
return `Configure it: adk ${group} configure ${d.alias}${fields} (or set values in the Control Panel)`;
}
case "disabled":
return `Enable it: adk ${group} enable ${d.alias}`;
case "not_installed":
return `Module missing on disk \u2014 run 'adk deploy' (or 'adk dev') to sync it`;
case "unresolved":
return d.reason ?? `Could not resolve the definition \u2014 check the catalog and the pinned version`;
case "errored":
return d.reason ?? `Unexpected error loading the dependency`;
default:
return;
}
}
function summarizeStatuses(deps) {
if (deps.length === 0)
return "no dependencies";
const counts = new Map;
for (const d of deps)
counts.set(d.state, (counts.get(d.state) ?? 0) + 1);
const order = ["available", "unconfigured", "disabled", "not_installed", "unresolved", "errored"];
return [...counts.entries()].sort((a, b) => order.indexOf(a[0]) - order.indexOf(b[0])).map(([state, n]) => `${n} ${state}`).join(", ");
}
export { formatStatusLine, remediationFor, summarizeStatuses };