|
@@ -62,7 +62,6 @@ interface GenerateMessageCard {
|
|
|
}
|
|
}
|
|
|
export interface FormData {
|
|
export interface FormData {
|
|
|
input: string
|
|
input: string
|
|
|
- markdown?: string
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type DetectedDiff = Array<{
|
|
type DetectedDiff = Array<{
|
|
@@ -143,6 +142,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
// Refs
|
|
// Refs
|
|
|
// const positionRef = useRef<number>(0);
|
|
// const positionRef = useRef<number>(0);
|
|
|
const lineRef = useRef<number>(0);
|
|
const lineRef = useRef<number>(0);
|
|
|
|
|
+ const isQuickMenuReqRef = useRef<boolean>(false);
|
|
|
|
|
|
|
|
// States
|
|
// States
|
|
|
const [detectedDiff, setDetectedDiff] = useState<DetectedDiff>();
|
|
const [detectedDiff, setDetectedDiff] = useState<DetectedDiff>();
|
|
@@ -165,7 +165,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
|
|
|
|
|
// Functions
|
|
// Functions
|
|
|
const resetForm = useCallback(() => {
|
|
const resetForm = useCallback(() => {
|
|
|
- form.reset({ input: '', markdown: undefined });
|
|
|
|
|
|
|
+ form.reset({ input: '' });
|
|
|
}, [form]);
|
|
}, [form]);
|
|
|
|
|
|
|
|
const createThread: CreateThread = useCallback(async() => {
|
|
const createThread: CreateThread = useCallback(async() => {
|
|
@@ -177,20 +177,31 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
}, [selectedAiAssistant?._id]);
|
|
}, [selectedAiAssistant?._id]);
|
|
|
|
|
|
|
|
const postMessage: PostMessage = useCallback(async(threadId, userMessage) => {
|
|
const postMessage: PostMessage = useCallback(async(threadId, userMessage) => {
|
|
|
|
|
+ const getMarkdown = (): string | undefined => {
|
|
|
|
|
+ if (isQuickMenuReqRef.current) {
|
|
|
|
|
+ return codeMirrorEditor?.getDoc();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (selectedText != null && selectedText.length !== 0) {
|
|
|
|
|
+ return selectedText;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const response = await fetch('/_api/v3/openai/edit', {
|
|
const response = await fetch('/_api/v3/openai/edit', {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
body: JSON.stringify({
|
|
body: JSON.stringify({
|
|
|
threadId,
|
|
threadId,
|
|
|
userMessage,
|
|
userMessage,
|
|
|
- markdown: selectedText != null && selectedText.length !== 0
|
|
|
|
|
- ? selectedText
|
|
|
|
|
- : undefined,
|
|
|
|
|
|
|
+ markdown: getMarkdown(),
|
|
|
}),
|
|
}),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ isQuickMenuReqRef.current = false;
|
|
|
return response;
|
|
return response;
|
|
|
- }, [selectedText]);
|
|
|
|
|
|
|
+ }, [codeMirrorEditor, selectedText]);
|
|
|
|
|
|
|
|
const processMessage: ProcessMessage = useCallback((data, handler) => {
|
|
const processMessage: ProcessMessage = useCallback((data, handler) => {
|
|
|
handleIfSuccessfullyParsed(data, SseMessageSchema, (data: SseMessage) => {
|
|
handleIfSuccessfullyParsed(data, SseMessageSchema, (data: SseMessage) => {
|
|
@@ -312,6 +323,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const clickQuickMenuHandler = async(quickMenu: string) => {
|
|
const clickQuickMenuHandler = async(quickMenu: string) => {
|
|
|
|
|
+ isQuickMenuReqRef.current = true;
|
|
|
await onSubmit({ input: quickMenu });
|
|
await onSubmit({ input: quickMenu });
|
|
|
};
|
|
};
|
|
|
|
|
|