Elffuss BraidHub

kikocis/continue public

main · 1.9 KiBRawPermalink
1import { Box, Text, useInput } from "ink";
2import React, { useState } from "react";
3
4interface ToolPermissionRequestProps {
5 toolName: string;
6 toolArgs: any;
7 requestId: string;
8 onResponse: (requestId: string, approved: boolean) => void;
9}
10
11export const ToolPermissionRequest: React.FC<ToolPermissionRequestProps> = ({
12 toolName,
13 toolArgs,
14 requestId,
15 onResponse,
16}) => {
17 const [responded, setResponded] = useState(false);
18
19 useInput((input) => {
20 if (responded) return;
21
22 if (input === "y" || input === "Y") {
23 setResponded(true);
24 onResponse(requestId, true);
25 } else if (input === "n" || input === "N") {
26 setResponded(true);
27 onResponse(requestId, false);
28 }
29 });
30
31 if (responded) {
32 return null; // Component will be replaced by updated message
33 }
34
35 const formatArgs = (args: any) => {
36 if (!args || Object.keys(args).length === 0) return "";
37
38 const firstKey = Object.keys(args)[0];
39 const firstValue = args[firstKey];
40
41 if (typeof firstValue === "string" && firstValue.length > 50) {
42 return `${firstValue.substring(0, 50)}...`;
43 }
44
45 return String(firstValue);
46 };
47
48 return (
49 <Box flexDirection="column" marginBottom={1}>
50 <Box>
51 <Text color="yellow">⚠ </Text>
52 <Text color="yellow" bold>
53 Permission Required
54 </Text>
55 </Box>
56 <Box marginLeft={2}>
57 <Text>
58 Tool: <Text color="cyan">{toolName}</Text>
59 </Text>
60 </Box>
61 {formatArgs(toolArgs) && (
62 <Box marginLeft={2}>
63 <Text>
64 Args: <Text color="gray">{formatArgs(toolArgs)}</Text>
65 </Text>
66 </Box>
67 )}
68 <Box marginLeft={2}>
69 <Text>
70 Allow this tool call? (
71 <Text color="green" bold>
72 y
73 </Text>
74 /
75 <Text color="red" bold>
76 n
77 </Text>
78 )
79 </Text>
80 </Box>
81 </Box>
82 );
83};