Przeglądaj źródła

Impl useSWRxThreads

Shun Miyazawa 1 rok temu
rodzic
commit
091dc957ff

+ 15 - 0
apps/app/src/features/openai/client/stores/thread.tsx

@@ -0,0 +1,15 @@
+import { type SWRResponse } from 'swr';
+import useSWRImmutable from 'swr/immutable';
+
+import { apiv3Get } from '~/client/util/apiv3-client';
+
+import type { IThreadRelationHasId } from '../../interfaces/thread-relation';
+
+export const useSWRxThreads = (aiAssistantId: string): SWRResponse<IThreadRelationHasId[], Error> => {
+  const key = [`openai/threads/${aiAssistantId}`];
+
+  return useSWRImmutable<IThreadRelationHasId[]>(
+    key,
+    ([endpoint]) => apiv3Get(endpoint).then(response => response.data.threads),
+  );
+};

+ 3 - 1
apps/app/src/features/openai/interfaces/thread-relation.ts

@@ -1,4 +1,4 @@
-import type { IUser, Ref } from '@growi/core';
+import type { IUser, Ref, HasObjectId } from '@growi/core';
 
 
 import type { IVectorStore } from './vector-store';
 import type { IVectorStore } from './vector-store';
 
 
@@ -8,3 +8,5 @@ export interface IThreadRelation {
   threadId: string;
   threadId: string;
   expiredAt: Date;
   expiredAt: Date;
 }
 }
+
+export type IThreadRelationHasId = IThreadRelation & HasObjectId;