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

+ 2 - 2
apps/app/src/features/openai/client/services/ai-assistant.ts

@@ -1,8 +1,8 @@
 import { apiv3Post, apiv3Delete } from '~/client/util/apiv3-client';
 
-import type { IApiv3AiAssistantCreateParams } from '../../interfaces/ai-assistant';
+import type { UpsertAiAssistantData } from '../../interfaces/ai-assistant';
 
-export const createAiAssistant = async(body: IApiv3AiAssistantCreateParams): Promise<void> => {
+export const createAiAssistant = async(body: UpsertAiAssistantData): Promise<void> => {
   await apiv3Post('/openai/ai-assistant', body);
 };
 

+ 1 - 3
apps/app/src/features/openai/interfaces/ai-assistant.ts

@@ -41,9 +41,7 @@ export interface AiAssistant {
 
 export type AiAssistantHasId = AiAssistant & HasObjectId
 
-export type IApiv3AiAssistantCreateParams = Omit<AiAssistant, 'owner' | 'vectorStore'>
-
-export type AiAssistantUpdateData = Partial<Omit<AiAssistant, 'owner' | 'vectorStore'>>
+export type UpsertAiAssistantData = Omit<AiAssistant, 'owner' | 'vectorStore'>
 
 export type AccessibleAiAssistants = {
   myAiAssistants: AiAssistant[],

+ 4 - 2
apps/app/src/features/openai/server/routes/ai-assistant.ts

@@ -8,7 +8,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 IApiv3AiAssistantCreateParams } from '../../interfaces/ai-assistant';
+import { type UpsertAiAssistantData } from '../../interfaces/ai-assistant';
 import { getOpenaiService } from '../services/openai';
 
 import { certifyAiService } from './middlewares/certify-ai-service';
@@ -18,7 +18,9 @@ const logger = loggerFactory('growi:routes:apiv3:openai:create-ai-assistant');
 
 type CreateAssistantFactory = (crowi: Crowi) => RequestHandler[];
 
-type Req = Request<undefined, Response, IApiv3AiAssistantCreateParams> & {
+type ReqBody = UpsertAiAssistantData;
+
+type Req = Request<undefined, Response, ReqBody> & {
   user: IUserHasId,
 }
 

+ 4 - 3
apps/app/src/features/openai/server/routes/update-ai-assistant.ts

@@ -9,7 +9,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 AiAssistantUpdateData } from '../../interfaces/ai-assistant';
+import { type UpsertAiAssistantData } from '../../interfaces/ai-assistant';
 import { getOpenaiService } from '../services/openai';
 
 import { certifyAiService } from './middlewares/certify-ai-service';
@@ -23,7 +23,7 @@ type ReqParams = {
   id: string,
 }
 
-type ReqBody = AiAssistantUpdateData;
+type ReqBody = UpsertAiAssistantData;
 
 type Req = Request<ReqParams, Response, ReqBody> & {
   user: IUserHasId,
@@ -45,7 +45,8 @@ export const updateAiAssistantsFactory: UpdateAiAssistantsFactory = (crowi) => {
 
       try {
         const openaiService = getOpenaiService();
-        const updatedAiAssistant = await openaiService?.updateAiAssistant(user._id, id, req.body);
+        const aiAssistantData = { ...req.body, owner: user._id };
+        const updatedAiAssistant = await openaiService?.updateAiAssistant(id, aiAssistantData);
 
         return res.apiv3({ updatedAiAssistant });
       }

+ 3 - 4
apps/app/src/features/openai/server/services/openai.ts

@@ -24,7 +24,6 @@ import { createBatchStream } from '~/server/util/batch-stream';
 import loggerFactory from '~/utils/logger';
 
 import { OpenaiServiceTypes } from '../../interfaces/ai';
-import type { AiAssistantUpdateData } from '../../interfaces/ai-assistant';
 import {
   type AccessibleAiAssistants, type AiAssistant, AiAssistantAccessScope, AiAssistantShareScope,
 } from '../../interfaces/ai-assistant';
@@ -69,7 +68,7 @@ export interface IOpenaiService {
   // rebuildVectorStoreAll(): Promise<void>;
   // rebuildVectorStore(page: HydratedDocument<PageDocument>): Promise<void>;
   createAiAssistant(data: Omit<AiAssistant, 'vectorStore'>): Promise<AiAssistantDocument>;
-  updateAiAssistant(ownerId: string, aiAssistantId: string, data: AiAssistantUpdateData): Promise<AiAssistantDocument>;
+  updateAiAssistant(aiAssistantId: string, data: Omit<AiAssistant, 'vectorStore'>): Promise<AiAssistantDocument>;
   getAccessibleAiAssistants(user: IUserHasId): Promise<AccessibleAiAssistants>
   deleteAiAssistant(ownerId: string, aiAssistantId: string): Promise<AiAssistantDocument>
 }
@@ -571,8 +570,8 @@ class OpenaiService implements IOpenaiService {
     return aiAssistant;
   }
 
-  async updateAiAssistant(ownerId: string, aiAssistantId: string, data: AiAssistantUpdateData): Promise<AiAssistantDocument> {
-    const aiAssistant = await AiAssistantModel.findOne({ owner: ownerId, _id: aiAssistantId });
+  async updateAiAssistant(aiAssistantId: string, data: Omit<AiAssistant, 'vectorStore'>): Promise<AiAssistantDocument> {
+    const aiAssistant = await AiAssistantModel.findOne({ owner: data.owner, _id: aiAssistantId });
     if (aiAssistant == null) {
       throw new Error('AiAssistant document does not exist');
     }