pyb-ts
Version:
PYB-CLI - Minimal AI Agent with multi-model support and CLI interface
80 lines (79 loc) • 2.85 kB
JavaScript
import React from "react";
import { Box, Text, useInput } from "ink";
import { getTheme } from "@utils/theme";
import { Select } from "./CustomSelect/select.js";
import {
saveCurrentProjectConfig,
getCurrentProjectConfig
} from "@utils/config";
import { MCPServerDialogCopy } from "./MCPServerDialogCopy.js";
import { useExitOnCtrlCD } from "@hooks/useExitOnCtrlCD";
function MCPServerApprovalDialog({
serverName,
onDone
}) {
const theme = getTheme();
function onChange(value) {
const config = getCurrentProjectConfig();
switch (value) {
case "yes": {
if (!config.approvedMcprcServers) {
config.approvedMcprcServers = [];
}
if (!config.approvedMcprcServers.includes(serverName)) {
config.approvedMcprcServers.push(serverName);
}
saveCurrentProjectConfig(config);
onDone();
break;
}
case "no": {
if (!config.rejectedMcprcServers) {
config.rejectedMcprcServers = [];
}
if (!config.rejectedMcprcServers.includes(serverName)) {
config.rejectedMcprcServers.push(serverName);
}
saveCurrentProjectConfig(config);
onDone();
break;
}
}
}
const exitState = useExitOnCtrlCD(() => process.exit(0));
useInput((_input, key) => {
if (key.escape) {
onDone();
return;
}
});
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
Box,
{
flexDirection: "column",
gap: 1,
padding: 1,
borderStyle: "round",
borderColor: theme.warning
},
/* @__PURE__ */ React.createElement(Text, { bold: true, color: theme.warning }, "New MCP Server Detected"),
/* @__PURE__ */ React.createElement(Text, null, "This project contains a .mcprc file with an MCP server that requires your approval:"),
/* @__PURE__ */ React.createElement(Text, { bold: true }, serverName),
/* @__PURE__ */ React.createElement(MCPServerDialogCopy, null),
/* @__PURE__ */ React.createElement(Text, null, "Do you want to approve this MCP server?"),
/* @__PURE__ */ React.createElement(
Select,
{
options: [
{ label: "Yes, approve this server", value: "yes" },
{ label: "No, reject this server", value: "no" }
],
onChange: (value) => onChange(value)
}
)
), /* @__PURE__ */ React.createElement(Box, { marginLeft: 3 }, /* @__PURE__ */ React.createElement(Text, { dimColor: true }, exitState.pending ? /* @__PURE__ */ React.createElement(React.Fragment, null, "Press ", exitState.keyName, " again to exit") : /* @__PURE__ */ React.createElement(React.Fragment, null, "Enter to confirm \xB7 Esc to reject"))));
}
export {
MCPServerApprovalDialog
};
//# sourceMappingURL=MCPServerApprovalDialog.js.map