Просмотр исходного кода

Revert "Add type for request body"

This reverts commit 5b5bbc197e5360e9ae1e114e84fae6d4b869ec6d.
Shun Miyazawa 1 год назад
Родитель
Сommit
5171cd04d0

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

@@ -8,7 +8,6 @@ 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,
@@ -25,8 +24,6 @@ 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>;
 }
@@ -116,20 +113,14 @@ export const useEditorAssistant: UseEditorAssistant = () => {
 
   // Functions
   const postMessage: PostMessage = useCallback(async(threadId, userMessage) => {
-    const body: IApiv3PostMessageParams = {
-      threadId,
-      userMessage,
-    };
-
-    // Insert selectedText into object after null check since JSON.stringify returns empty string when selectedText is undefined
-    if (selectedText != null) {
-      body.markdown = selectedText;
-    }
-
     const response = await fetch('/_api/v3/openai/edit', {
       method: 'POST',
       headers: { 'Content-Type': 'application/json' },
-      body: JSON.stringify(body),
+      body: JSON.stringify({
+        threadId,
+        userMessage,
+        markdown: selectedText,
+      }),
     });
 
     setSelectedText(undefined);

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

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

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

@@ -15,7 +15,6 @@ 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';
@@ -41,7 +40,11 @@ const LlmEditorAssistantResponseSchema = z.object({
 }).describe('The response format for the editor assistant');
 
 
-type ReqBody = IApiv3PostMessageParams;
+type ReqBody = {
+  userMessage: string,
+  markdown?: string,
+  threadId?: string,
+}
 
 type Req = Request<undefined, Response, ReqBody> & {
   user: IUserHasId,