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

+ 13 - 1
apps/app/src/features/openai/client/stores/ai-assistant.tsx

@@ -1,7 +1,11 @@
 import { useCallback } from 'react';
 
 import { useSWRStatic } from '@growi/core/dist/swr';
-import type { SWRResponse } from 'swr';
+import useSWR, { type SWRResponse } from 'swr';
+
+import { apiv3Get } from '~/client/util/apiv3-client';
+
+import { type AccessibleAiAssistantsHasId } from '../../interfaces/ai-assistant';
 
 export const AiAssistantManagementModalPageMode = {
   HOME: 'home',
@@ -38,3 +42,11 @@ export const useAiAssistantManagementModal = (
     }, [swrResponse]),
   };
 };
+
+
+export const useSWRxAiAssistants = (): SWRResponse<AccessibleAiAssistantsHasId, Error> => {
+  return useSWR<AccessibleAiAssistantsHasId>(
+    ['/openai/ai-assistants'],
+    ([endpoint]) => apiv3Get(endpoint).then(response => response.data.accessibleAiAssistants),
+  );
+};

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

@@ -1,4 +1,6 @@
-import type { IGrantedGroup, IUser, Ref } from '@growi/core';
+import type {
+  IGrantedGroup, IUser, Ref, HasObjectId,
+} from '@growi/core';
 
 import type { VectorStore } from '../server/models/vector-store';
 
@@ -37,9 +39,16 @@ export interface AiAssistant {
   accessScope: AiAssistantAccessScope
 }
 
+export type AiAssistantHasId = AiAssistant & HasObjectId
+
 export type IApiv3AiAssistantCreateParams = Omit<AiAssistant, 'owner' | 'vectorStore'>
 
 export type AccessibleAiAssistants = {
   myAiAssistants: AiAssistant[],
   teamAiAssistants: AiAssistant[],
 }
+
+export type AccessibleAiAssistantsHasId = {
+  myAiAssistants: AiAssistantHasId[],
+  teamAiAssistants: AiAssistantHasId[],
+}