UNPKG

@botpress/adk-cli

Version:

Command-line interface for the Botpress Agent Development Kit (ADK)

138 lines (136 loc) 4.45 kB
// @bun import { AgentProjectPatcher, UNKNOWN_AGENT_PROJECT_VERSION } from "./chunk-a38y2kh3.js"; import"./chunk-bmbzs4s8.js"; import { ensureJsonOnlyFormat } from "./chunk-7sfagm12.js"; import"./chunk-tt572q4r.js"; import"./chunk-3ahwp6fe.js"; import { getRuntimeVersionReport } from "./chunk-ty7sdgd4.js"; import"./chunk-nbasj5jm.js"; import { findAgentRootOrFail } from "./chunk-kk3h6qaj.js"; import { createCliLogger } from "./chunk-gzwt1qdr.js"; import { CLI_VERSION } from "./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"./chunk-dhs2bg35.js"; // src/commands/adk-project-upgrade.ts async function adkProjectUpgrade(options = {}) { ensureJsonOnlyFormat(options.format); const logger = createCliLogger({ format: options.format }); const agentRoot = await findAgentRootOrFail(process.cwd()); let runtime = getRuntimeVersionReport(agentRoot); const patcher = new AgentProjectPatcher({ projectPath: agentRoot, fromVersion: UNKNOWN_AGENT_PROJECT_VERSION, toVersion: CLI_VERSION, runtimePackageVersion: runtime.expectedVersion, logger }); const initialPatchPlan = await patcher.plan(); let patchPlan = initialPatchPlan; let patchRun; if (!options.dryRun) { patchRun = await patcher.apply(initialPatchPlan); patchPlan = await patcher.plan(); runtime = getRuntimeVersionReport(agentRoot); } const pendingPatches = patchPlan.pending; const blockedPatches = patchPlan.blocked; const failedPatches = patchRun?.failed ?? []; const result = { projectPath: agentRoot, dryRun: !!options.dryRun, complete: runtime.compatible && pendingPatches.length === 0 && blockedPatches.length === 0 && failedPatches.length === 0, runtime, patches: { initialPlan: initialPatchPlan, plan: patchPlan, ...patchRun ? { run: patchRun } : {} } }; if (options.format === "json") { logger.info("Project upgrade result").result(result); if (!result.complete) process.exit(1); return result; } logger.info(options.dryRun ? "ADK project upgrade plan" : "ADK project upgrade", "blue"); logger.info(`Runtime: ${runtime.installedVersion ? `v${runtime.installedVersion}` : "not installed"}`, "gray"); logger.info(`Expected: v${runtime.expectedVersion}`, "gray"); logger.info(`Supported major: ${runtime.expectedMajor ?? "unknown"}.x`, "gray"); if (runtime.compatible) { logger.info(runtime.status === "outdated" ? "Runtime is compatible, upgrade recommended" : "Runtime is compatible", "green"); } else { logger.error(runtime.resolution.summary); } if (pendingPatches.length === 0) { logger.info("Project patches: none pending", "green"); } else { logger.warn(`Project patches: ${pendingPatches.length} pending`); for (const patch of pendingPatches) { logger.info(` - ${patch.title}: ${patch.reason ?? patch.description}`, "gray"); } if (options.dryRun) { logger.info("Run `adk project upgrade` to apply pending project updates.", "gray"); } } if (blockedPatches.length > 0) { logger.warn(`Project patches: ${blockedPatches.length} blocked`); for (const patch of blockedPatches) { logger.info(` - ${patch.title}: ${patch.reason}`, "gray"); } } if (patchRun) { for (const patch of patchRun.applied) { logger.info(`Applied: ${patch.title}`, "green"); } for (const patch of patchRun.failed) { logger.error(`Failed: ${patch.title} \u2014 ${patch.error ?? "unknown error"}`); } } logger.info("Project upgrade result").result(result); if (!result.complete) process.exit(1); return result; } export { adkProjectUpgrade };