Elffuss BraidHub

kikocis/continue public

e31fcddb0dec · 2.7 KiBRawPermalink
1import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
2import { selectPendingToolCalls } from "../../../../redux/selectors/selectToolCalls";
3import { callToolById } from "../../../../redux/thunks/callToolById";
4import { cancelToolCallThunk } from "../../../../redux/thunks/cancelToolCall";
5import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util";
6import { Button } from "../../../ui";
7
8export const generateToolCallButtonTestId = (
9 action: "accept" | "reject",
10 toolCallId: string,
11) => {
12 return `${action}-tool-call-button-${toolCallId}`;
13};
14
15export function PendingToolCallToolbar() {
16 const dispatch = useAppDispatch();
17 const jetbrains = isJetBrains();
18 const pendingToolCalls = useAppSelector(selectPendingToolCalls);
19
20 if (pendingToolCalls.length === 0) {
21 return null;
22 }
23
24 const handleAccept = (toolCallId: string) => {
25 void dispatch(callToolById({ toolCallId }));
26 };
27
28 const handleReject = (toolCallId: string) => {
29 void dispatch(cancelToolCallThunk({ toolCallId }));
30 };
31
32 return (
33 <div className="flex w-full flex-col pb-0.5">
34 {pendingToolCalls.map((toolCall, index) => (
35 <div
36 key={toolCall.toolCallId}
37 className="border-input bg-input flex items-center gap-2 rounded border"
38 >
39 <span className="text-description flex-1 truncate text-xs italic">
40 {toolCall.tool?.displayTitle ?? toolCall.toolCall.function.name}
41 </span>
42
43 <div className="flex items-center gap-1">
44 <Button
45 variant="ghost"
46 size="sm"
47 className="text-description-muted my-1 font-medium"
48 onClick={() => handleReject(toolCall.toolCallId)}
49 data-testid={generateToolCallButtonTestId(
50 "reject",
51 toolCall.toolCallId,
52 )}
53 >
54 {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
55 {index === 0 && (
56 <span className="text-2xs mr-1">
57 {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()}⌫
58 </span>
59 )}
60 <span>Reject</span>
61 </Button>
62
63 <Button
64 variant="primary"
65 size="sm"
66 className="my-1 font-medium"
67 onClick={() => handleAccept(toolCall.toolCallId)}
68 data-testid={generateToolCallButtonTestId(
69 "accept",
70 toolCall.toolCallId,
71 )}
72 >
73 {index === 0 && (
74 <span className="text-2xs mr-1">{getMetaKeyLabel()}⏎</span>
75 )}
76 <span>Accept</span>
77 </Button>
78 </div>
79 </div>
80 ))}
81 </div>
82 );
83}