Skip to content

Commit 0605d6a

Browse files
committed
wip: remove attach file checkbox. (#644)
* wip: remove attach file checkbox. * feat: attach files button. * test: active file is no longer attached by default. * add an event for the ide to attach a file to chat. * fix: remove attached files after submit.
1 parent 2b7269b commit 0605d6a

File tree

11 files changed

+160
-140
lines changed

11 files changed

+160
-140
lines changed

refact-agent/gui/src/components/ChatForm/ChatControls.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Box,
99
Switch,
1010
Badge,
11+
Button,
1112
} from "@radix-ui/themes";
1213
import { Select } from "../Select";
1314
import { type Config } from "../../features/Config/configSlice";
@@ -36,6 +37,7 @@ import {
3637
setToolUse,
3738
} from "../../features/Chat/Thread";
3839
import { useAppSelector, useAppDispatch, useCapsForToolUse } from "../../hooks";
40+
import { useAttachedFiles } from "./useCheckBoxes";
3941

4042
export const ApplyPatchSwitch: React.FC = () => {
4143
const dispatch = useAppDispatch();
@@ -223,6 +225,7 @@ export type ChatControlsProps = {
223225
) => void;
224226

225227
host: Config["host"];
228+
attachedFiles: ReturnType<typeof useAttachedFiles>;
226229
};
227230

228231
const ChatControlCheckBox: React.FC<{
@@ -294,6 +297,7 @@ export const ChatControls: React.FC<ChatControlsProps> = ({
294297
checkboxes,
295298
onCheckedChange,
296299
host,
300+
attachedFiles,
297301
}) => {
298302
const refs = useTourRefs();
299303
const dispatch = useAppDispatch();
@@ -343,6 +347,18 @@ export const ChatControls: React.FC<ChatControlsProps> = ({
343347
);
344348
})}
345349

350+
{host !== "web" && (
351+
<Button
352+
title="Attach current file"
353+
onClick={attachedFiles.addFile}
354+
disabled={!attachedFiles.activeFile.name || attachedFiles.attached}
355+
size="1"
356+
radius="medium"
357+
>
358+
Attach: {attachedFiles.activeFile.name}
359+
</Button>
360+
)}
361+
346362
{showControls && (
347363
<Flex gap="2" direction="column">
348364
<ToolUseSwitch

refact-agent/gui/src/components/ChatForm/ChatForm.test.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ describe("ChatForm", () => {
115115
await user.type(textarea, "foo");
116116
await user.keyboard("{Enter}");
117117
const markdown = "```python\nprint(1)\n```\n";
118-
const cursor = app.store.getState().active_file.cursor;
119-
120-
const expected = `@file foo.txt:${
121-
cursor ? cursor + 1 : 1
122-
}\n${markdown}\nfoo\n`;
118+
const expected = `${markdown}\nfoo\n`;
123119
expect(fakeOnSubmit).toHaveBeenCalledWith(expected);
124120
});
125121

refact-agent/gui/src/components/ChatForm/ChatForm.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
useSendChatRequest,
2020
useCompressChat,
2121
useAutoFocusOnce,
22-
// useTotalTokenUsage,
2322
} from "../../hooks";
2423
import { ErrorCallout, Callout } from "../Callout";
2524
import { ComboBox } from "../ComboBox";
@@ -30,17 +29,16 @@ import { useCommandCompletionAndPreviewFiles } from "./useCommandCompletionAndPr
3029
import { useAppSelector, useAppDispatch } from "../../hooks";
3130
import { clearError, getErrorMessage } from "../../features/Errors/errorsSlice";
3231
import { useTourRefs } from "../../features/Tour";
33-
import { useCheckboxes } from "./useCheckBoxes";
32+
import { useAttachedFiles, useCheckboxes } from "./useCheckBoxes";
3433
import { useInputValue } from "./useInputValue";
3534
import {
3635
clearInformation,
3736
getInformationMessage,
38-
// setInformation,
3937
} from "../../features/Errors/informationSlice";
4038
import { InformationCallout } from "../Callout/Callout";
4139
import { ToolConfirmation } from "./ToolConfirmation";
4240
import { getPauseReasonsWithPauseStatus } from "../../features/ToolConfirmation/confirmationSlice";
43-
import { AttachFileButton, FileList } from "../Dropzone";
41+
import { AttachImagesButton, FileList } from "../Dropzone";
4442
import { useAttachedImages } from "../../hooks/useAttachedImages";
4543
import {
4644
enableSend,
@@ -51,15 +49,13 @@ import {
5149
selectLastSentCompression,
5250
selectMessages,
5351
selectPreventSend,
54-
// selectThreadMaximumTokens,
5552
selectThreadToolUse,
5653
selectToolUse,
5754
} from "../../features/Chat";
5855
import { telemetryApi } from "../../services/refact";
5956
import { push } from "../../features/Pages/pagesSlice";
6057
import { AgentCapabilities } from "./AgentCapabilities";
6158
import { TokensPreview } from "./TokensPreview";
62-
// import { useUsageCounter } from "../UsageCounter/useUsageCounter";
6359
import classNames from "classnames";
6460
import { ArchiveIcon } from "@radix-ui/react-icons";
6561

@@ -97,6 +93,7 @@ export const ChatForm: React.FC<ChatFormProps> = ({
9793
const lastSentCompression = useAppSelector(selectLastSentCompression);
9894
const { compressChat, compressChatRequest } = useCompressChat();
9995
const autoFocus = useAutoFocusOnce();
96+
const attachedFiles = useAttachedFiles();
10097

10198
const shouldAgentCapabilitiesBeShown = useMemo(() => {
10299
return threadToolUse === "agent";
@@ -161,7 +158,6 @@ export const ChatForm: React.FC<ChatFormProps> = ({
161158
checkboxes,
162159
onToggleCheckbox,
163160
unCheckAll,
164-
setFileInteracted,
165161
setLineSelectionInteracted,
166162
} = useCheckboxes();
167163

@@ -184,21 +180,23 @@ export const ChatForm: React.FC<ChatFormProps> = ({
184180
const handleSubmit = useCallback(() => {
185181
const trimmedValue = value.trim();
186182
if (!disableSend && trimmedValue.length > 0) {
183+
const valueWithFiles = attachedFiles.addFilesToInput(trimmedValue);
187184
const valueIncludingChecks = addCheckboxValuesToInput(
188-
trimmedValue,
185+
valueWithFiles,
189186
checkboxes,
190187
);
191-
setFileInteracted(false);
188+
// TODO: add @files
192189
setLineSelectionInteracted(false);
193190
onSubmit(valueIncludingChecks);
194191
setValue(() => "");
195192
unCheckAll();
193+
attachedFiles.removeAll();
196194
}
197195
}, [
198196
value,
199197
disableSend,
198+
attachedFiles,
200199
checkboxes,
201-
setFileInteracted,
202200
setLineSelectionInteracted,
203201
onSubmit,
204202
setValue,
@@ -241,7 +239,6 @@ export const ChatForm: React.FC<ChatFormProps> = ({
241239
setValue(command);
242240
const trimmedCommand = command.trim();
243241
if (!trimmedCommand) {
244-
setFileInteracted(false);
245242
setLineSelectionInteracted(false);
246243
}
247244

@@ -251,7 +248,7 @@ export const ChatForm: React.FC<ChatFormProps> = ({
251248
handleHelpInfo(null);
252249
}
253250
},
254-
[handleHelpInfo, setValue, setFileInteracted, setLineSelectionInteracted],
251+
[handleHelpInfo, setValue, setLineSelectionInteracted],
255252
);
256253

257254
const handleAgentIntegrationsClick = useCallback(() => {
@@ -423,7 +420,9 @@ export const ChatForm: React.FC<ChatFormProps> = ({
423420
/>
424421
)}
425422
{config.features?.images !== false &&
426-
isMultimodalitySupportedForCurrentModel && <AttachFileButton />}
423+
isMultimodalitySupportedForCurrentModel && (
424+
<AttachImagesButton />
425+
)}
427426
{/* TODO: Reserved space for microphone button coming later on */}
428427
<PaperPlaneButton
429428
disabled={disableSend}
@@ -435,12 +434,14 @@ export const ChatForm: React.FC<ChatFormProps> = ({
435434
</Flex>
436435
</Form>
437436
</Flex>
438-
<FileList />
437+
<FileList attachedFiles={attachedFiles} />
439438

440439
<ChatControls
440+
// handle adding files
441441
host={config.host}
442442
checkboxes={checkboxes}
443443
onCheckedChange={onToggleCheckbox}
444+
attachedFiles={attachedFiles}
444445
/>
445446
</Card>
446447
);

0 commit comments

Comments
 (0)