UNPKG

pyb-ts

Version:

PYB-CLI - Minimal AI Agent with multi-model support and CLI interface

84 lines (83 loc) 2.67 kB
import React from "react"; import { Box, Newline, Text, useInput } from "ink"; import { getTheme } from "@utils/theme"; import { Select } from "./CustomSelect/select.js"; import { render } from "ink"; import { writeFileSync } from "fs"; import { useExitOnCtrlCD } from "@hooks/useExitOnCtrlCD"; function InvalidConfigDialog({ filePath, errorDescription, onExit, onReset }) { const theme = getTheme(); useInput((_, key) => { if (key.escape) { onExit(); } }); const exitState = useExitOnCtrlCD(() => process.exit(0)); const handleSelect = (value) => { if (value === "exit") { onExit(); } else { onReset(); } }; return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement( Box, { flexDirection: "column", borderColor: theme.error, borderStyle: "round", padding: 1, width: 70, gap: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Configuration Error"), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", gap: 1 }, /* @__PURE__ */ React.createElement(Text, null, "The configuration file at ", /* @__PURE__ */ React.createElement(Text, { bold: true }, filePath), " contains invalid JSON."), /* @__PURE__ */ React.createElement(Text, null, errorDescription)), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Choose an option:"), /* @__PURE__ */ React.createElement( Select, { options: [ { label: "Exit and fix manually", value: "exit" }, { label: "Reset with default configuration", value: "reset" } ], onChange: handleSelect } )) ), exitState.pending ? /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "Press ", exitState.keyName, " again to exit") : /* @__PURE__ */ React.createElement(Newline, null)); } function showInvalidConfigDialog({ error }) { return new Promise((resolve) => { render( /* @__PURE__ */ React.createElement( InvalidConfigDialog, { filePath: error.filePath, errorDescription: error.message, onExit: () => { resolve(); process.exit(1); }, onReset: () => { writeFileSync( error.filePath, JSON.stringify(error.defaultConfig, null, 2) ); resolve(); process.exit(0); } } ), { exitOnCtrlC: false } ); }); } export { showInvalidConfigDialog }; //# sourceMappingURL=InvalidConfigDialog.js.map