Elffuss BraidHub

kikocis/continue public

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