|
@@ -41,8 +41,14 @@ import { performSearchReplace } from './search-replace-engine';
|
|
|
interface CreateThread {
|
|
interface CreateThread {
|
|
|
(): Promise<IThreadRelationHasId>;
|
|
(): Promise<IThreadRelationHasId>;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+type PostMessageArgs = {
|
|
|
|
|
+ threadId: string;
|
|
|
|
|
+ formData: FormData;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
interface PostMessage {
|
|
interface PostMessage {
|
|
|
- (threadId: string, formData: FormData): Promise<Response>;
|
|
|
|
|
|
|
+ (args: PostMessageArgs): Promise<Response>;
|
|
|
}
|
|
}
|
|
|
interface ProcessMessage {
|
|
interface ProcessMessage {
|
|
|
(data: unknown, handler: {
|
|
(data: unknown, handler: {
|
|
@@ -122,6 +128,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
const [detectedDiff, setDetectedDiff] = useState<DetectedDiff>();
|
|
const [detectedDiff, setDetectedDiff] = useState<DetectedDiff>();
|
|
|
const [selectedAiAssistant, setSelectedAiAssistant] = useState<AiAssistantHasId>();
|
|
const [selectedAiAssistant, setSelectedAiAssistant] = useState<AiAssistantHasId>();
|
|
|
const [selectedText, setSelectedText] = useState<string>();
|
|
const [selectedText, setSelectedText] = useState<string>();
|
|
|
|
|
+ const [selectedTextIndex, setSelectedTextIndex] = useState<number>();
|
|
|
const [isGeneratingEditorText, setIsGeneratingEditorText] = useState<boolean>(false);
|
|
const [isGeneratingEditorText, setIsGeneratingEditorText] = useState<boolean>(false);
|
|
|
const [partialContentInfo, setPartialContentInfo] = useState<{
|
|
const [partialContentInfo, setPartialContentInfo] = useState<{
|
|
|
startIndex: number;
|
|
startIndex: number;
|
|
@@ -162,7 +169,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
return response.data;
|
|
return response.data;
|
|
|
}, [selectedAiAssistant?._id]);
|
|
}, [selectedAiAssistant?._id]);
|
|
|
|
|
|
|
|
- const postMessage: PostMessage = useCallback(async(threadId, formData) => {
|
|
|
|
|
|
|
+ const postMessage: PostMessage = useCallback(async({ threadId, formData }) => {
|
|
|
// Clear partial content info on new request
|
|
// Clear partial content info on new request
|
|
|
setPartialContentInfo(null);
|
|
setPartialContentInfo(null);
|
|
|
|
|
|
|
@@ -185,13 +192,17 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
|
|
|
|
|
const requestBody = {
|
|
const requestBody = {
|
|
|
threadId,
|
|
threadId,
|
|
|
|
|
+ aiAssistantId: selectedAiAssistant?._id,
|
|
|
userMessage: formData.input,
|
|
userMessage: formData.input,
|
|
|
- selectedText,
|
|
|
|
|
pageBody: pageBodyContext.content,
|
|
pageBody: pageBodyContext.content,
|
|
|
...(pageBodyContext.isPartial && {
|
|
...(pageBodyContext.isPartial && {
|
|
|
isPageBodyPartial: pageBodyContext.isPartial,
|
|
isPageBodyPartial: pageBodyContext.isPartial,
|
|
|
partialPageBodyStartIndex: pageBodyContext.startIndex,
|
|
partialPageBodyStartIndex: pageBodyContext.startIndex,
|
|
|
}),
|
|
}),
|
|
|
|
|
+ ...(selectedText != null && selectedText.length > 0 && {
|
|
|
|
|
+ selectedText,
|
|
|
|
|
+ selectedPosition: selectedTextIndex,
|
|
|
|
|
+ }),
|
|
|
} satisfies EditRequestBody;
|
|
} satisfies EditRequestBody;
|
|
|
|
|
|
|
|
const response = await fetch('/_api/v3/openai/edit', {
|
|
const response = await fetch('/_api/v3/openai/edit', {
|
|
@@ -201,7 +212,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return response;
|
|
return response;
|
|
|
- }, [codeMirrorEditor, mutateIsEnableUnifiedMergeView, selectedText]);
|
|
|
|
|
|
|
+ }, [codeMirrorEditor, mutateIsEnableUnifiedMergeView, selectedAiAssistant?._id, selectedText, selectedTextIndex]);
|
|
|
|
|
|
|
|
|
|
|
|
|
// Enhanced processMessage with client engine support (保持)
|
|
// Enhanced processMessage with client engine support (保持)
|
|
@@ -290,8 +301,9 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
});
|
|
});
|
|
|
}, [isGeneratingEditorText, mutateIsEnableUnifiedMergeView, clientEngine, yDocs]);
|
|
}, [isGeneratingEditorText, mutateIsEnableUnifiedMergeView, clientEngine, yDocs]);
|
|
|
|
|
|
|
|
- const selectTextHandler = useCallback((selectedText: string, selectedTextFirstLineNumber: number) => {
|
|
|
|
|
|
|
+ const selectTextHandler = useCallback(({ selectedText, selectedTextIndex, selectedTextFirstLineNumber }) => {
|
|
|
setSelectedText(selectedText);
|
|
setSelectedText(selectedText);
|
|
|
|
|
+ setSelectedTextIndex(selectedTextIndex);
|
|
|
lineRef.current = selectedTextFirstLineNumber;
|
|
lineRef.current = selectedTextFirstLineNumber;
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
@@ -307,12 +319,11 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
pendingDetectedDiff.forEach((detectedDiff) => {
|
|
pendingDetectedDiff.forEach((detectedDiff) => {
|
|
|
if (detectedDiff.data.diff) {
|
|
if (detectedDiff.data.diff) {
|
|
|
const { search, replace, startLine } = detectedDiff.data.diff;
|
|
const { search, replace, startLine } = detectedDiff.data.diff;
|
|
|
-
|
|
|
|
|
- // 新しい検索・置換処理
|
|
|
|
|
|
|
+ // New search and replace processing
|
|
|
const success = performSearchReplace(yText, search, replace, startLine);
|
|
const success = performSearchReplace(yText, search, replace, startLine);
|
|
|
|
|
|
|
|
if (!success) {
|
|
if (!success) {
|
|
|
- // フォールバック: 既存の動作
|
|
|
|
|
|
|
+ // Fallback: existing behavior
|
|
|
if (isTextSelected) {
|
|
if (isTextSelected) {
|
|
|
insertTextAtLine(yText, lineRef.current, replace);
|
|
insertTextAtLine(yText, lineRef.current, replace);
|
|
|
lineRef.current += 1;
|
|
lineRef.current += 1;
|
|
@@ -343,6 +354,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (detectedDiff?.filter(detectedDiff => detectedDiff.applied === false).length === 0) {
|
|
if (detectedDiff?.filter(detectedDiff => detectedDiff.applied === false).length === 0) {
|
|
|
setSelectedText(undefined);
|
|
setSelectedText(undefined);
|
|
|
|
|
+ setSelectedTextIndex(undefined);
|
|
|
setDetectedDiff(undefined);
|
|
setDetectedDiff(undefined);
|
|
|
lineRef.current = 0;
|
|
lineRef.current = 0;
|
|
|
}
|
|
}
|