UNPKG

@botpress/adk-cli

Version:

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

375 lines (369 loc) 9.52 kB
// @bun import { ne } from "./chunk-6w0knnta.js"; // src/utils/theme-preferences.ts import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"; import { homedir } from "os"; import { dirname, join } from "path"; // src/theme/palette.ts var terminalColorSchemeSchema = ne.enum(["dark", "light"]); var cliThemePreferenceSchema = ne.enum(["dark", "light", "system"]); var symbols = { progress: "\u23F5\u23F5", dot: "\u25CF", arrow: "\u2192", pointer: "\u203A", checkmark: "\u2713", cross: "\u2717", warning: "\u25B2", info: "\u2139" }; var terminalThemePalette = { light: { cli: { background: { primary: "#f8fafc", secondary: "#eef2f7", tertiary: "#e2e8f0" }, foreground: { primary: "#111827", secondary: "#334155", tertiary: "#64748b" }, status: { success: "#17B252", error: "#b91c1c", warning: "#b45309", info: "#1d4ed8" }, statusBackground: { success: "#dcfce7", successText: "#17B252", error: "#fee2e2", errorText: "#b91c1c", warning: "#fef3c7", warningText: "#b45309", info: "#dbeafe", infoText: "#1d4ed8" }, diff: { added: "#dcfce7", addedHighlight: "#bbf7d0", removed: "#fee2e2", removedHighlight: "#fecaca" }, text: { primary: "#111827", secondary: "#1F2329", dim: "#333C49", dimmer: "#647A9C", highlight: "#6d28d9", link: "#1d4ed8" }, accent: { blue: "#2563eb", purple: "#7c3aed", cyan: "#0e7490", green: "#15803d", yellow: "#b45309", orange: "#c2410c", red: "#b91c1c", pink: "#be185d" }, syntax: { keyword: "#7c3aed", string: "#15803d", number: "#b45309", boolean: "#c2410c", function: "#2563eb", class: "#0e7490", variable: "#111827", comment: "#6b7280", operator: "#b91c1c", punctuation: "#334155" }, ui: { border: "#cbd5e1", borderFocus: "#2563eb", selection: "#dbeafe", selectionText: "#1e293b", code: "#92400e", codeBackground: "#f1f5f9" }, semantic: { pending: "#6b7280", inProgress: "#2563eb", completed: "#15803d", disabled: "#94a3b8" }, plan: { community: "#64748b", team: "#2563eb", enterprise: "#7c3aed", plus: "#b45309" }, symbols }, taskList: { diff: { addition: { background: "#dcfce7", highlight: "#bbf7d0" }, deletion: { background: "#fee2e2", highlight: "#fecaca" }, text: "#1F2329" }, status: { pending: "#64748b", inProgress: "#1F2329", done: "#15803d" }, text: { normal: "#111827", dimmed: "#64748b", completed: "#15803d" } } }, dark: { cli: { background: { primary: "#0b0e14", secondary: "#1a1d26", tertiary: "#252833" }, foreground: { primary: "#e6e6e6", secondary: "#b8b8b8", tertiary: "#8a8a8a" }, status: { success: "#AAD94C", error: "#F26D78", warning: "#FFB454", info: "#59C2FF" }, statusBackground: { success: "#1a2e1a", successText: "#AAD94C", error: "#2e1a1a", errorText: "#F26D78", warning: "#2e2a1a", warningText: "#FFB454", info: "#1a1f2e", infoText: "#59C2FF" }, diff: { added: "#1a2e1a", addedHighlight: "#2d4a2d", removed: "#2e1a1a", removedHighlight: "#4a2d2d" }, text: { primary: "#e6e6e6", secondary: "#b8b8b8", dim: "#7d7d7d", dimmer: "#525252", highlight: "#D2A6FF", link: "#59C2FF" }, accent: { blue: "#59C2FF", purple: "#D2A6FF", cyan: "#95E6CB", green: "#AAD94C", yellow: "#FFB454", orange: "#FF9940", red: "#F26D78", pink: "#FF88CC" }, syntax: { keyword: "#D2A6FF", string: "#AAD94C", number: "#FFB454", boolean: "#FF9940", function: "#59C2FF", class: "#95E6CB", variable: "#e6e6e6", comment: "#646A71", operator: "#F26D78", punctuation: "#b8b8b8" }, ui: { border: "#3d4149", borderFocus: "#59C2FF", selection: "#2d3847", selectionText: "#e6e6e6", code: "#FFB454", codeBackground: "#1a1d26" }, semantic: { pending: "#7d7d7d", inProgress: "#59C2FF", completed: "#AAD94C", disabled: "#525252" }, plan: { community: "#7d7d7d", team: "#59C2FF", enterprise: "#D2A6FF", plus: "#FFB454" }, symbols }, taskList: { diff: { addition: { background: "#005E24", highlight: "#00A958" }, deletion: { background: "#852134", highlight: "#C0526A" }, text: "#f0f0f0" }, status: { pending: "#7d7d7d", inProgress: "#e6e6e6", done: "#AAD94C" }, text: { normal: "#e6e6e6", dimmed: "#7d7d7d", completed: "#AAD94C" } } } }; // src/utils/system-color-scheme.ts import { execFileSync } from "child_process"; var cached; function detectSystemColorScheme() { if (cached === undefined) { cached = compute(); } return cached; } function compute() { const fromEnv = fromColorFgBg(process.env.COLORFGBG); if (fromEnv) { return fromEnv; } if (process.platform === "darwin") { return fromMacOS(); } if (process.platform === "win32") { return fromWindows(); } return fromLinux(); } function fromColorFgBg(value) { if (!value) { return null; } const fields = value.split(";"); const bg = Number(fields[fields.length - 1]); if (Number.isNaN(bg)) { return null; } return bg <= 6 || bg === 8 ? "dark" : "light"; } function fromMacOS() { try { const out = run("defaults", ["read", "-g", "AppleInterfaceStyle"]); return out.toLowerCase().includes("dark") ? "dark" : "light"; } catch { return "light"; } } function fromWindows() { try { const out = run("reg", [ "query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "/v", "AppsUseLightTheme" ]); return /0x1\b/.test(out) ? "light" : "dark"; } catch { return "dark"; } } function fromLinux() { try { const out = run("gsettings", ["get", "org.gnome.desktop.interface", "color-scheme"]).toLowerCase(); if (out.includes("dark")) { return "dark"; } if (out.includes("light") || out.includes("default")) { return "light"; } } catch {} return "dark"; } function run(command, args) { return execFileSync(command, args, { stdio: ["ignore", "pipe", "ignore"], timeout: 1000 }).toString().trim(); } // src/utils/theme-preferences.ts var cliPreferencesSchema = ne.object({ theme: cliThemePreferenceSchema.optional().catch(undefined) }).passthrough(); var CLI_PREFERENCES_FILE_ENV_KEY = "ADK_CLI_PREFERENCES_FILE"; var CLI_PREFERENCES_DEFAULT_DIR = join(homedir(), ".botpress"); var CLI_PREFERENCES_DEFAULT_FILE = join(CLI_PREFERENCES_DEFAULT_DIR, "adk-cli.json"); var DEFAULT_CLI_THEME = "system"; var isCliThemePreference = (value) => { return cliThemePreferenceSchema.safeParse(value).success; }; var resolveColorScheme = (preference) => { return preference === "system" ? detectSystemColorScheme() : preference; }; var getPreferencesFilePath = (preferencesFilePath) => { const trimmedExplicitPath = preferencesFilePath?.trim(); if (trimmedExplicitPath) { return trimmedExplicitPath; } const fromEnv = process.env[CLI_PREFERENCES_FILE_ENV_KEY]?.trim(); return fromEnv || CLI_PREFERENCES_DEFAULT_FILE; }; var readPreferences = (preferencesFilePath) => { const preferencesFile = getPreferencesFilePath(preferencesFilePath); try { if (!existsSync(preferencesFile)) { return {}; } const raw = readFileSync(preferencesFile, "utf-8"); const parsed = cliPreferencesSchema.safeParse(JSON.parse(raw)); return parsed.success ? parsed.data : {}; } catch { return {}; } }; var writePreferences = (preferences, preferencesFilePath) => { const preferencesFile = getPreferencesFilePath(preferencesFilePath); const preferencesDir = dirname(preferencesFile); if (!existsSync(preferencesDir)) { mkdirSync(preferencesDir, { recursive: true }); } writeFileSync(preferencesFile, JSON.stringify(preferences, null, 2) + ` `, "utf-8"); }; var getSavedCliTheme = (preferencesFilePath) => { const preferences = readPreferences(preferencesFilePath); const result = cliThemePreferenceSchema.safeParse(preferences.theme); return result.success ? result.data : DEFAULT_CLI_THEME; }; var setSavedCliTheme = (theme, preferencesFilePath) => { const preferences = readPreferences(preferencesFilePath); writePreferences({ ...preferences, theme }, preferencesFilePath); }; export { terminalThemePalette, isCliThemePreference, resolveColorScheme, getSavedCliTheme, setSavedCliTheme };