UNPKG

@botpress/adk-cli

Version:

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

75 lines (72 loc) 2.9 kB
// @bun import { resolveCommandContext } from "./chunk-3ahwp6fe.js"; import { createCliLogger } from "./chunk-gzwt1qdr.js"; import { auth, workspaceCache } from "./chunk-p0hjqn4r.js"; // src/utils/workspace-display.ts function normalizeOptions(input) { return typeof input === "string" ? { projectPath: input } : input ?? {}; } async function resolveDisplayContext(options) { if (options.context) { return { credentials: options.context.credentials, workspaceId: options.context.workspaceId ?? options.context.credentials.workspaceId, workspaceName: options.context.credentials.workspaceName, profileName: options.context.selectedProfile.name }; } if (options.projectPath) { const context = await resolveCommandContext({ cwd: options.projectPath, target: "dev", require: ["project", "credentials", "workspace"], createClient: false }); return { credentials: context.credentials, workspaceId: context.workspaceId, workspaceName: context.credentials.workspaceName, profileName: context.selectedProfile.name }; } const credentials = await auth.getActiveCredentials(); const profile = await auth.getCurrentProfileDetails(); return { credentials, workspaceId: credentials.workspaceId, workspaceName: credentials.workspaceName, profileName: profile?.name || "default" }; } async function displayWorkspaceInfo(input) { const logger = createCliLogger(); try { const options = normalizeOptions(input); const { credentials, workspaceId, profileName } = await resolveDisplayContext(options); let workspaceName = credentials.workspaceName; if (workspaceId && (!workspaceName || options.projectPath || options.context)) { const fetchedName = await workspaceCache.getWorkspaceName(workspaceId, credentials); if (fetchedName) { workspaceName = fetchedName; } } logger.newline(); logger.info("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501", "cyan"); logger.info(`Workspace: ${workspaceName || workspaceId || "Unknown"}`, "cyan"); logger.info(`Workspace ID: ${workspaceId || "Unknown"}`, "gray"); logger.info(`Profile: ${profileName}`, "gray"); logger.info("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501", "cyan"); logger.newline(); } catch { logger.warn('\u26A0\uFE0F Unable to display workspace info. Please run "adk login" first.'); logger.newline(); } } export { displayWorkspaceInfo };