Shun Miyazawa 1 год назад
Родитель
Сommit
5b5bbc197e

+ 13 - 5
apps/app/src/features/openai/client/services/editor-assistant.ts

@@ -8,6 +8,7 @@ import { useCodeMirrorEditorIsolated } from '@growi/editor/dist/client/stores/co
 import { useSecondaryYdocs } from '@growi/editor/dist/client/stores/use-secondary-ydocs';
 import { type Text as YText } from 'yjs';
 
+
 import {
   SseMessageSchema,
   SseDetectedDiffSchema,
@@ -24,6 +25,8 @@ import { handleIfSuccessfullyParsed } from '~/features/openai/utils/handle-if-su
 import { useIsEnableUnifiedMergeView } from '~/stores-universal/context';
 import { useCurrentPageId } from '~/stores/page';
 
+import type { IApiv3PostMessageParams } from '../../interfaces/apiv3/edit';
+
 interface PostMessage {
   (threadId: string, userMessage: string): Promise<Response>;
 }
@@ -113,14 +116,19 @@ export const useEditorAssistant: UseEditorAssistant = () => {
 
   // Functions
   const postMessage: PostMessage = useCallback(async(threadId, userMessage) => {
+    const body: IApiv3PostMessageParams = {
+      threadId,
+      userMessage,
+    };
+
+    if (selectedText != null) {
+      body.markdown = selectedText;
+    }
+
     const response = await fetch('/_api/v3/openai/edit', {
       method: 'POST',
       headers: { 'Content-Type': 'application/json' },
-      body: JSON.stringify({
-        threadId,
-        userMessage,
-        markdown: selectedText,
-      }),
+      body: JSON.stringify(body),
     });
 
     setSelectedText(undefined);

+ 5 - 0
apps/app/src/features/openai/interfaces/apiv3/edit.ts

@@ -0,0 +1,5 @@
+export type IApiv3PostMessageParams = {
+  threadId?: string,
+  userMessage: string,
+  markdown?: string,
+}

+ 2 - 5
apps/app/src/features/openai/server/routes/edit/index.ts

@@ -15,6 +15,7 @@ import { apiV3FormValidator } from '~/server/middlewares/apiv3-form-validator';
 import type { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response';
 import loggerFactory from '~/utils/logger';
 
+import type { IApiv3PostMessageParams } from '../../../interfaces/apiv3/edit';
 import { LlmEditorAssistantDiffSchema, LlmEditorAssistantMessageSchema } from '../../../interfaces/editor-assistant/llm-response-schemas';
 import type { SseDetectedDiff, SseFinalized, SseMessage } from '../../../interfaces/editor-assistant/sse-schemas';
 import { MessageErrorCode } from '../../../interfaces/message-error';
@@ -40,11 +41,7 @@ const LlmEditorAssistantResponseSchema = z.object({
 }).describe('The response format for the editor assistant');
 
 
-type ReqBody = {
-  userMessage: string,
-  markdown?: string,
-  threadId?: string,
-}
+type ReqBody = IApiv3PostMessageParams;
 
 type Req = Request<undefined, Response, ReqBody> & {
   user: IUserHasId,