MCPcopy Create free account
hub / github.com/outerbase/studio / CodeMirrorPromptWidget

Function CodeMirrorPromptWidget

src/components/editor/prompt-widget.tsx:27–277  ·  view source on GitHub ↗
({
  onClose,
  onCancel,
  onSubmit,
  onAccept,
  onReject,
  agentDriver,
}: CodeMirrorPromptWidgetProps)

Source from the content-addressed store, hash-verified

25}
26
27export function CodeMirrorPromptWidget({
28 onClose,
29 onCancel,
30 onSubmit,
31 onAccept,
32 onReject,
33 agentDriver,
34}: CodeMirrorPromptWidgetProps) {
35 const textareaClassName =
36 "absolute left-0 right-0 resize-none p-1 p-2 outline-none";
37
38 const fakeTextareaRef = useRef<HTMLTextAreaElement>(null);
39 const textareaRef = useRef<HTMLTextAreaElement>(null);
40
41 const agentList = useMemo(() => {
42 if (!agentDriver) return [];
43 return agentDriver.list();
44 }, [agentDriver]);
45 const [selectedAgent, setSelectedAgent] = useState(() =>
46 agentDriver?.getDefaultModelName()
47 );
48
49 const [previousPrompt, setPreviousPrompt] = useState("");
50 const [error, setError] = useState("");
51 const [loading, setLoading] = useState(false);
52 const [height, setHeight] = useState(60);
53 const [prompt, setPrompt] = useState("");
54 const cancelTriggered = useRef(false);
55
56 const minHeight = 60;
57
58 const handleResize = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
59 if (fakeTextareaRef.current && textareaRef.current) {
60 fakeTextareaRef.current.value = e.currentTarget.value;
61 const newHeight = Math.max(
62 minHeight,
63 fakeTextareaRef.current.scrollHeight
64 );
65
66 setHeight(Math.max(minHeight, fakeTextareaRef.current.scrollHeight));
67 textareaRef.current.style.height = newHeight + "px";
68 }
69 };
70
71 const showSubmitButton = !previousPrompt && prompt;
72 const showSubmitEditButton = previousPrompt && previousPrompt !== prompt;
73 const showAcceptButton = prompt === previousPrompt && previousPrompt;
74
75 const triggerSubmit = useCallback(() => {
76 if (onSubmit) {
77 setLoading(true);
78 setError("");
79 cancelTriggered.current = false;
80
81 onSubmit(prompt, selectedAgent)
82 .then(() => {
83 if (!cancelTriggered.current) {
84 setPreviousPrompt(prompt);

Callers

nothing calls this directly

Calls 6

cnFunction · 0.90
handleResizeFunction · 0.85
listMethod · 0.80
getDefaultModelNameMethod · 0.80
setDefaultModelNameMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected