Elffuss BraidHub

kikocis/continue public

c55965a9627b · 4.3 KiBRawPermalink
1import { Editor, JSONContent } from "@tiptap/react";
2import { ContextItemWithId, InputModifiers } from "core";
3import { useMemo } from "react";
4import styled, { keyframes } from "styled-components";
5import { defaultBorderRadius, vscBackground } from "..";
6import { useAppSelector } from "../../redux/hooks";
7import { selectSlashCommandComboBoxInputs } from "../../redux/selectors";
8import { ContextItemsPeek } from "./belowMainInput/ContextItemsPeek";
9import { ToolbarOptions } from "./InputToolbar";
10import { Lump } from "./Lump";
11import { TipTapEditor } from "./TipTapEditor";
12
13interface ContinueInputBoxProps {
14 isLastUserInput: boolean;
15 isMainInput?: boolean;
16 onEnter: (
17 editorState: JSONContent,
18 modifiers: InputModifiers,
19 editor: Editor,
20 ) => void;
21 editorState?: JSONContent;
22 contextItems?: ContextItemWithId[];
23 hidden?: boolean;
24 inputId: string; // used to keep track of things per input in redux
25}
26
27const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [
28 "codebase",
29 "tree",
30 "open",
31 "web",
32 "diff",
33 "folder",
34 "search",
35 "debugger",
36 "repo-map",
37];
38
39const gradient = keyframes`
40 0% {
41 background-position: 0px 0;
42 }
43 100% {
44 background-position: 100em 0;
45 }
46`;
47
48const GradientBorder = styled.div<{
49 borderRadius?: string;
50 borderColor?: string;
51 loading: 0 | 1;
52}>`
53 border-radius: ${(props) => props.borderRadius || "0"};
54 padding: 1px;
55 background: ${(props) =>
56 props.borderColor
57 ? props.borderColor
58 : `repeating-linear-gradient(
59 101.79deg,
60 #1BBE84 0%,
61 #331BBE 16%,
62 #BE1B55 33%,
63 #A6BE1B 55%,
64 #BE1B55 67%,
65 #331BBE 85%,
66 #1BBE84 99%
67 )`};
68 animation: ${(props) => (props.loading ? gradient : "")} 6s linear infinite;
69 background-size: 200% 200%;
70 width: 100%;
71 display: flex;
72 flex-direction: row;
73 align-items: center;
74`;
75
76function ContinueInputBox(props: ContinueInputBoxProps) {
77 const isStreaming = useAppSelector((state) => state.session.isStreaming);
78 const availableSlashCommands = useAppSelector(
79 selectSlashCommandComboBoxInputs,
80 );
81 const availableContextProviders = useAppSelector(
82 (state) => state.config.config.contextProviders,
83 );
84 const mode = useAppSelector((store) => store.session.mode);
85 const editModeState = useAppSelector((state) => state.editModeState);
86
87 const filteredSlashCommands = useMemo(() => {
88 return mode === "edit" ? [] : availableSlashCommands;
89 }, [mode, availableSlashCommands]);
90
91 const filteredContextProviders = useMemo(() => {
92 if (mode === "edit") {
93 return (
94 availableContextProviders?.filter(
95 (provider) =>
96 !EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title),
97 ) ?? []
98 );
99 }
100
101 return availableContextProviders ?? [];
102 }, [availableContextProviders, mode]);
103
104 const historyKey = mode === "edit" ? "edit" : "chat";
105 const placeholder = mode === "edit" ? "Describe changes" : undefined;
106
107 const toolbarOptions: ToolbarOptions =
108 mode === "edit"
109 ? {
110 hideAddContext: false,
111 hideImageUpload: false,
112 hideUseCodebase: true,
113 hideSelectModel: false,
114 enterText:
115 editModeState.applyState.status === "done" ? "Retry" : "Edit",
116 }
117 : {};
118
119 return (
120 <div
121 className={`${props.hidden ? "hidden" : ""}`}
122 data-testid="continue-input-box"
123 >
124 <div className={`relative flex flex-col px-2`}>
125 {props.isMainInput && <Lump />}
126 <GradientBorder
127 loading={isStreaming && props.isLastUserInput ? 1 : 0}
128 borderColor={
129 isStreaming && props.isLastUserInput ? undefined : vscBackground
130 }
131 borderRadius={defaultBorderRadius}
132 >
133 <TipTapEditor
134 editorState={props.editorState}
135 onEnter={props.onEnter}
136 placeholder={placeholder}
137 isMainInput={props.isMainInput ?? false}
138 availableContextProviders={filteredContextProviders}
139 availableSlashCommands={filteredSlashCommands}
140 historyKey={historyKey}
141 toolbarOptions={toolbarOptions}
142 inputId={props.inputId}
143 />
144 </GradientBorder>
145 </div>
146 <ContextItemsPeek
147 contextItems={props.contextItems}
148 isCurrentContextPeek={props.isLastUserInput}
149 />
150 </div>
151 );
152}
153
154export default ContinueInputBox;