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

Merge branch 'feat/growi-ai-next' into feat/160044-implement-logic-for-creating-pecialized-vector-store

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

+ 8 - 9
apps/app/src/features/openai/interfaces/ai-assistant.ts

@@ -6,22 +6,22 @@ import type { VectorStore } from '../server/models/vector-store';
 *  Objects
 */
 export const AiAssistantShareScope = {
-  PUBLIC: 'public',
-  ONLY_ME: 'onlyMe',
-  USER_GROUP: 'userGroup',
+  PUBLIC_ONLY: 'publicOnly',
+  OWNER: 'owner',
+  GROUPS: 'groups',
 } as const;
 
-export const AiAssistantOwnerAccessScope = {
-  PUBLIC: 'public',
-  ONLY_ME: 'onlyMe',
-  USER_GROUP: 'userGroup',
+export const AiAssistantAccessScope = {
+  PUBLIC_ONLY: 'publicOnly',
+  OWNER: 'owner',
+  GROUPS: 'groups',
 } as const;
 
 /*
 *  Interfaces
 */
 export type AiAssistantShareScope = typeof AiAssistantShareScope[keyof typeof AiAssistantShareScope];
-export type AiAssistantOwnerAccessScope = typeof AiAssistantOwnerAccessScope[keyof typeof AiAssistantOwnerAccessScope];
+export type AiAssistantOwnerAccessScope = typeof AiAssistantAccessScope[keyof typeof AiAssistantAccessScope];
 
 export interface AiAssistant {
   name: string;
@@ -30,7 +30,6 @@ export interface AiAssistant {
   pagePathPatterns: string[],
   vectorStore: Ref<VectorStore>
   owner: Ref<IUser>
-  grantedUsers?: IUser[]
   grantedGroups?: IGrantedGroup[]
   shareScope: AiAssistantShareScope
   ownerAccessScope: AiAssistantOwnerAccessScope

+ 2 - 9
apps/app/src/features/openai/server/models/ai-assistant.ts

@@ -3,7 +3,7 @@ import { type Model, type Document, Schema } from 'mongoose';
 
 import { getOrCreateModel } from '~/server/util/mongoose-utils';
 
-import { type AiAssistant, AiAssistantShareScope, AiAssistantOwnerAccessScope } from '../../interfaces/ai-assistant';
+import { type AiAssistant, AiAssistantShareScope, AiAssistantAccessScope } from '../../interfaces/ai-assistant';
 
 export interface AiAssistantDocument extends AiAssistant, Document {}
 
@@ -43,13 +43,6 @@ const schema = new Schema<AiAssistantDocument>(
       ref: 'User',
       required: true,
     },
-    grantedUsers: [
-      {
-        type: Schema.Types.ObjectId,
-        ref: 'User',
-        required: true,
-      },
-    ],
     grantedGroups: {
       type: [{
         type: {
@@ -79,7 +72,7 @@ const schema = new Schema<AiAssistantDocument>(
     },
     ownerAccessScope: {
       type: String,
-      enum: Object.values(AiAssistantOwnerAccessScope),
+      enum: Object.values(AiAssistantAccessScope),
       required: true,
     },
   },

+ 2 - 11
apps/app/src/features/openai/server/routes/create-ai-assistant.ts → apps/app/src/features/openai/server/routes/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 AiAssistant, AiAssistantShareScope, AiAssistantOwnerAccessScope } from '../../interfaces/ai-assistant';
+import { type AiAssistant, AiAssistantShareScope, AiAssistantAccessScope } from '../../interfaces/ai-assistant';
 import { getOpenaiService } from '../services/openai';
 
 import { certifyAiService } from './middlewares/certify-ai-service';
@@ -62,15 +62,6 @@ export const createAiAssistantFactory: CreateAssistantFactory = (crowi) => {
       .notEmpty()
       .withMessage('pagePathPatterns must not be empty'),
 
-    body('grantedUsers')
-      .optional()
-      .isArray()
-      .withMessage('grantedUsers must be an array'),
-
-    body('grantedUsers.*') // each item of grantedUsers
-      .isMongoId()
-      .withMessage('grantedUsers must be an array mongoId'),
-
     body('grantedGroups')
       .optional()
       .isArray()
@@ -89,7 +80,7 @@ export const createAiAssistantFactory: CreateAssistantFactory = (crowi) => {
       .withMessage('Invalid shareScope value'),
 
     body('ownerAccessScope')
-      .isIn(Object.values(AiAssistantOwnerAccessScope))
+      .isIn(Object.values(AiAssistantAccessScope))
       .withMessage('Invalid ownerAccessScope value'),
   ];
 

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

@@ -31,8 +31,8 @@ export const factory = (crowi: Crowi): express.Router => {
       router.post('/message', postMessageHandlersFactory(crowi));
     });
 
-    import('./create-ai-assistant').then(({ createAiAssistantFactory }) => {
-      router.post('/assistant', createAiAssistantFactory(crowi));
+    import('./ai-assistant').then(({ createAiAssistantFactory }) => {
+      router.post('ai-assistant', createAiAssistantFactory(crowi));
     });
   }