UNPKG

@botpress/adk-cli

Version:

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

147 lines (145 loc) 4.54 kB
// @bun import { createAdkArchive, defaultArchiveFileName } from "./chunk-73xfqhym.js"; import"./chunk-8n02v208.js"; import { getClient } from "./chunk-33cg4pm3.js"; import { ensureJsonOnlyFormat } from "./chunk-7sfagm12.js"; import { DEPENDENCY_SNAPSHOT_SECURITY_NOTICE, clearDependencyConfig } from "./chunk-2xth50pf.js"; import { resolveEnvironmentRemoteContext } from "./chunk-3ahwp6fe.js"; import { DependencyManager } from "./chunk-5zm2mgt9.js"; import"./chunk-nbasj5jm.js"; import"./chunk-kk3h6qaj.js"; import { createCliLogger } from "./chunk-gzwt1qdr.js"; import { CLI_VERSION } from "./chunk-nxy2ya5r.js"; import"./chunk-wzj4dc7n.js"; import { AdkError } 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-export.ts import path from "path"; async function adkExport(output, options = {}) { ensureJsonOnlyFormat(options.format); const logger = createCliLogger({ format: options.format }); const includeConfig = options.config !== false; const context = await resolveEnvironmentRemoteContext({ createClient: false, projectLoadOptions: { noCache: true } }); const project = context.project; if (!project) { throw new AdkError({ code: "PROJECT_NOT_FOUND", message: "No ADK agent root found in the current directory or its parents.", expected: true }); } const projectName = project.config?.name ?? path.basename(project.path); const outputPath = path.resolve(process.cwd(), output ?? defaultArchiveFileName(projectName)); const dependencyStates = {}; const dependencySnapshotWarnings = []; const linkedBots = { prod: project.agentInfo?.botId, dev: project.agentInfo?.devId }; if (project.agentInfo?.workspaceId) { const client = await getClient({ workspaceId: project.agentInfo.workspaceId, apiUrl: context.apiUrl, credentials: context.credentials }); for (const env of ["dev", "prod"]) { const botId = linkedBots[env]; if (!botId) { continue; } try { const dm = new DependencyManager({ projectPath: project.path, env, client, botId }); const state = await dm.snapshotStateFromCloud(); dependencyStates[env] = includeConfig ? state : clearDependencyConfig(state); } catch (error) { const message = error instanceof Error ? error.message : String(error); dependencySnapshotWarnings.push({ env, botId, error: message }); logger.warn(`Skipping ${env} dependency snapshot: ${message}`); } } } const result = await createAdkArchive({ projectPath: project.path, outputPath, projectName, adkVersion: CLI_VERSION, dependencyStates }); if (Object.keys(dependencyStates).length === 0 && dependencySnapshotWarnings.length > 0) { logger.warn("No dependency snapshots were included because all snapshot fetches failed."); } else if (Object.keys(dependencyStates).length === 0) { logger.warn("No linked dev or prod bots found; exported source without dependency snapshots."); } const shouldShowSecurityNotice = includeConfig && result.manifest.dependencySnapshots.length > 0; if (shouldShowSecurityNotice) { logger.warn(DEPENDENCY_SNAPSHOT_SECURITY_NOTICE); } const outputResult = { ok: true, output: result.outputPath, projectName: result.manifest.projectName, dependencySnapshots: result.manifest.dependencySnapshots, dependencySnapshotWarnings, projectFileCount: result.projectFileCount, configIncluded: includeConfig, ...shouldShowSecurityNotice ? { securityNotice: DEPENDENCY_SNAPSHOT_SECURITY_NOTICE } : {} }; logger.info(`Exported ${result.outputPath}`).result(outputResult); } export { adkExport };