@botpress/adk-cli
Version:
Command-line interface for the Botpress Agent Development Kit (ADK)
114 lines (112 loc) • 4.71 kB
JavaScript
// @bun
import {
loadProjectDM,
parseFormat,
parseKeyValueOptions,
parseTarget,
runDependencyCommand
} from "./chunk-69myctr2.js";
import"./chunk-3k2q12qe.js";
import"./chunk-3ahwp6fe.js";
import"./chunk-5zm2mgt9.js";
import"./chunk-kk3h6qaj.js";
import"./chunk-gzwt1qdr.js";
import"./chunk-nxy2ya5r.js";
import"./chunk-wzj4dc7n.js";
import"./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/integrations/add.ts
async function adkIntegrationsAdd(resource, options) {
await runDependencyCommand({
options,
run: async (logger) => {
const format = parseFormat(options.format);
const parsed = parseTarget(options.target);
if (parsed === "all") {
const { DependencyError } = await import("./chunk-z6sc1k1g.js");
throw new DependencyError({
code: "MISSING_INPUT",
message: `'all' is not valid for --target on this command. Use 'dev' or 'prod'.`
});
}
const target = parsed;
const [name, version] = resource.split("@");
if (!name) {
const { DependencyError } = await import("./chunk-z6sc1k1g.js");
throw new DependencyError({ code: "MISSING_INPUT", message: "<name> is required" });
}
const config = parseKeyValueOptions(options.config, "--config");
const { dm } = await loadProjectDM(target);
const result = await dm.add("integration", { name, version, alias: options.alias, config });
const installedLive = !result.noop && !result.installedDisabled && !result.installedAwaitingAuthorization;
let live;
if (target === "dev" && installedLive && process.env.ADK_SKIP_INTEGRATION_WAIT !== "1") {
const resourceName = result.resource?.name ?? name;
if (format === "text") {
logger.info(` Waiting for ${resourceName} to go live on the dev bot\u2026`, "gray");
}
live = await dm.waitForIntegrationWebhook(resourceName, { timeoutMs: 90000, intervalMs: 3000 });
}
if (format === "text") {
if (result.noop) {
logger.info(`\u2713 ${result.resource?.alias} already at ${result.resource?.version}, no-op`, "green");
} else if (result.installedAwaitingAuthorization) {
logger.info(`\u2713 ${result.resource?.alias} installed (disabled). It requires authorization.`, "green");
logger.info(" Connect it in the Botpress Control Panel, then re-run your build/deploy to enable it.");
} else if (result.installedDisabled) {
const missing = result.installedDisabled.missingFields.join(", ");
const aliasArg = result.resource?.alias ?? name;
const setFlags = result.installedDisabled.missingFields.map((f) => `--set ${f}=\u2026`).join(" ");
logger.info(`\u2713 ${result.resource?.alias} installed (disabled). Missing required config: ${missing}.`, "green");
logger.info(` Run: adk integrations configure ${aliasArg} ${setFlags} --target ${target}`);
} else if (live === false) {
logger.warn(`${result.resource?.alias} added to the dev config, but its webhook is NOT live on the running dev bot. Re-run adk dev to try again.`);
logger.info(" A channel only activates on the dev bot\u2019s first deploy with it in the lock \u2014 re-running " + "`adk integrations add` will not make it live on the already-running bot.", "gray");
} else {
logger.info(`\u2713 Added integration ${result.resource?.alias} (${result.resource?.name}@${result.resource?.version})`, "green");
}
return {};
}
return {
data: { result },
extras: {
noop: result.noop ?? false,
installedDisabled: result.installedDisabled,
...result.installedAwaitingAuthorization ? { installedAwaitingAuthorization: true } : {},
...live !== undefined ? { live } : {}
}
};
}
});
}
export {
adkIntegrationsAdd
};