pyb-ts
Version:
PYB-CLI - Minimal AI Agent with multi-model support and CLI interface
132 lines (131 loc) • 4.5 kB
JavaScript
import { Box, Text } from "ink";
import React, { useMemo } from "react";
import { Select } from "@components/CustomSelect/select";
import { getTheme } from "@utils/theme";
import {
PermissionRequestTitle,
textColorForRiskScore
} from "./PermissionRequestTitle.js";
import { logUnaryEvent } from "@utils/unaryLogging";
import { env } from "@utils/env";
import { getCwd } from "@utils/state";
import { savePermission } from "@permissions";
import {
toolUseConfirmGetPrefix
} from "./PermissionRequest.js";
import chalk from "chalk";
import {
usePermissionRequestLogging
} from "@hooks/usePermissionRequestLogging";
function FallbackPermissionRequest({
toolUseConfirm,
onDone,
verbose
}) {
const theme = getTheme();
const originalUserFacingName = toolUseConfirm.tool.userFacingName();
const userFacingName = originalUserFacingName.endsWith(" (MCP)") ? originalUserFacingName.slice(0, -6) : originalUserFacingName;
const unaryEvent = useMemo(
() => ({
completion_type: "tool_use_single",
language_name: "none"
}),
[]
);
usePermissionRequestLogging(toolUseConfirm, unaryEvent);
return /* @__PURE__ */ React.createElement(
Box,
{
flexDirection: "column",
borderStyle: "round",
borderColor: textColorForRiskScore(toolUseConfirm.riskScore),
marginTop: 1,
paddingLeft: 1,
paddingRight: 1,
paddingBottom: 1
},
/* @__PURE__ */ React.createElement(
PermissionRequestTitle,
{
title: "Tool use",
riskScore: toolUseConfirm.riskScore
}
),
/* @__PURE__ */ React.createElement(Box, { flexDirection: "column", paddingX: 2, paddingY: 1 }, /* @__PURE__ */ React.createElement(Text, null, userFacingName, "(", toolUseConfirm.tool.renderToolUseMessage(
toolUseConfirm.input,
{ verbose }
), ")", originalUserFacingName.endsWith(" (MCP)") ? /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, " (MCP)") : ""), /* @__PURE__ */ React.createElement(Text, { color: theme.secondaryText }, toolUseConfirm.description)),
/* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Text, null, "Do you want to proceed?"), /* @__PURE__ */ React.createElement(
Select,
{
options: [
{
label: "Yes",
value: "yes"
},
{
label: `Yes, and don't ask again for ${chalk.bold(userFacingName)} commands in ${chalk.bold(getCwd())}`,
value: "yes-dont-ask-again"
},
{
label: `No, and provide instructions (${chalk.bold.hex(getTheme().warning)("esc")})`,
value: "no"
}
],
onChange: (newValue) => {
switch (newValue) {
case "yes":
logUnaryEvent({
completion_type: "tool_use_single",
event: "accept",
metadata: {
language_name: "none",
message_id: toolUseConfirm.assistantMessage.message.id,
platform: env.platform
}
});
toolUseConfirm.onAllow("temporary");
onDone();
break;
case "yes-dont-ask-again":
logUnaryEvent({
completion_type: "tool_use_single",
event: "accept",
metadata: {
language_name: "none",
message_id: toolUseConfirm.assistantMessage.message.id,
platform: env.platform
}
});
savePermission(
toolUseConfirm.tool,
toolUseConfirm.input,
toolUseConfirmGetPrefix(toolUseConfirm)
).then(() => {
toolUseConfirm.onAllow("permanent");
onDone();
});
break;
case "no":
logUnaryEvent({
completion_type: "tool_use_single",
event: "reject",
metadata: {
language_name: "none",
message_id: toolUseConfirm.assistantMessage.message.id,
platform: env.platform
}
});
toolUseConfirm.onReject();
onDone();
break;
}
}
}
))
);
}
export {
FallbackPermissionRequest
};
//# sourceMappingURL=FallbackPermissionRequest.js.map