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

refactor: replace useAiAssistantSidebar with useAiAssistantSidebarStatus and useAiAssistantSidebarActions

Yuki Takei 6 месяцев назад
Родитель
Сommit
06fab41b35

+ 39 - 25
.serena/memories/apps-app-jotai-migration-consolidated.md

@@ -1,8 +1,8 @@
 # Jotai Migration Progress - Consolidated Report
 
-## 完了状況: **59/63 フック完了** (93.7%)
+## 完了状況: **60/63 フック完了** (95.2%)
 
-### 既完了移行 (59フック) ✅
+### 既完了移行 (60フック) ✅
 
 #### UI/Modal States (8フック)
 - useTemplateModalStatus/Actions, useLinkEditModalStatus/Actions
@@ -24,32 +24,18 @@
 - useCurrentPagePathStatus/Actions, usePageNotFoundStatus/Actions, useIsUntitledPageStatus
 - useWaitingSaveProcessingStatus/Actions, useCurrentIndentSizeStatus/Actions, usePageTagsForEditorsStatus/Actions
 
+#### OpenAI/AI Assistant States (1フック) 🤖
+- **useAiAssistantSidebar** → **Status/Actions分離** ✨
+
 #### **Phase 2完了 (6フック) - 2025年** 🚀
 1. **useAcceptedUploadFileType** → **Derived Atom**
-   - 計算: `isUploadEnabled + isUploadAllFileAllowed → AcceptedUploadFileType`
-   - 成果: SWRオーバーヘッド削除、自動メモ化
-
 2. **usePluginDeleteModal** → **Features Modal Status/Actions**
-   - データ: `{isOpened, id, name, url}`
-   - 成果: リレンダリング最適化
-
 3. **useSearchModal** → **Features Modal Status/Actions**  
-   - データ: `{isOpened, searchKeyword?}`
-   - 成果: グローバル検索UI最適化
-
 4. **useEditingClients** → **シンプル配列状態**
-   - データ: `EditingClient[]`
-   - 成果: 協調編集UI効率化
-
 5. **useAiAssistantManagementModal** → **Features Modal + 技術修復**
-   - データ: `{isOpened, pageMode: enum, aiAssistantData?}`
-   - 成果: 複雑Modal状態管理、ストア修復
-
 6. **useSocket群** → **atomWithLazy**
-   - Socket管理: `defaultSocket, adminSocket, customSocket`
-   - 成果: 適切なリソースライフサイクル
 
-#### **Phase 3完了 (2フック) - 本日** 🎉
+#### **Phase 3完了 (3フック) - 本日** 🎉
 7. **useIsSlackEnabled** → **シンプルBoolean状態**
    - データ: `boolean`
    - 実装: `states/ui/editor/is-slack-enabled.ts`
@@ -60,6 +46,12 @@
    - 実装: `states/ui/editor/reserved-next-caret-line.ts`
    - 成果: globalEmitter連携 + 適切な初期化処理
 
+9. **useAiAssistantSidebar** → **Status/Actions分離パターン**
+   - データ: `{isOpened, isEditorAssistant?, aiAssistantData?, threadData?}`
+   - 実装: `features/openai/client/states/ai-assistant-sidebar.ts`
+   - 移行ファイル数: 11ファイル
+   - 成果: 複雑サイドバー状態の最適化、リレンダリング削減
+
 ## 確立された実装パターン
 
 ### **Derived Atom** (計算値パターン)
@@ -104,10 +96,9 @@ export const useStateWithEmitter = () => {
 };
 ```
 
-## 残り移行候補 (4フック)
+## 残り移行候補 (3フック)
 
 ### **優先度B (中複雑度)**
-- **useAiAssistantSidebar** - 複雑サイドバー状態
 - **useKeywordManager** - Router連携 + URL同期
 
 ### **優先度C (高複雑度)**  
@@ -121,6 +112,7 @@ export const useStateWithEmitter = () => {
 - ❌ **計算値にSWR**: 同期計算にRevalidation概念は無意義
 - ❌ **Modal状態にSWR**: UI状態にRevalidation不要
 - ❌ **シンプルBoolean状態にSWR**: 単純状態にRevalidation不要
+- ❌ **サイドバー状態にSWR**: UI状態管理にRevalidation不要
 - ✅ **適切なツール選択**: 各状態管理に最適なJotaiパターン適用
 
 ### **パフォーマンス向上**
@@ -129,12 +121,34 @@ export const useStateWithEmitter = () => {
 - 不要なリレンダリング削除
 - リソース適切管理
 - globalEmitter連携の適切な実装
+- Status/Actions分離による参照安定化
 
 ## 品質保証実績
 - 型チェック完全通過 (`pnpm run lint:typecheck`)
-- 使用箇所完全移行確認
+- 使用箇所完全移行確認 (11ファイル更新)
 - 確立パターンによる実装統一
-- 旧コード完全削除(stores/editor.tsx から削除済み)
+- 旧コード完全削除
+  - `stores/editor.tsx`: useIsSlackEnabled, useReservedNextCaretLine削除済み
+  - `features/openai/client/stores/ai-assistant.tsx`: useAiAssistantSidebar削除済み
 
 ## 完了予定
-**Phase 3**: 残り4フック移行で **100%完了** → **inappropriate SWR usage の完全根絶**
+**Phase 3**: 残り3フック移行で **100%完了** → **inappropriate SWR usage の完全根絶**
+
+## useAiAssistantSidebar移行詳細
+
+### 更新ファイル一覧
+1. `OpenDefaultAiAssistantButton.tsx` - openChat使用
+2. `ThreadList.tsx` (Sidebar) - status + actions使用
+3. `AiAssistantSubstance.tsx` - status + close使用
+4. `AiAssistantList.tsx` - openChat使用
+5. `ThreadList.tsx` (AiAssistantSidebar) - status + openChat使用
+6. `AiAssistantSidebar.tsx` - status + close + refreshThreadData使用
+7. `AiAssistantManagementModal.tsx` - status + refreshAiAssistantData使用
+8. `knowledge-assistant.tsx` - status使用 (2箇所)
+9. `use-editor-assistant.tsx` - status使用
+10. `EditorAssistantToggleButton.tsx` - status + actions使用
+
+### 移行パターン
+- **Status読み取り専用**: `useAiAssistantSidebarStatus()`
+- **Actions書き込み専用**: `useAiAssistantSidebarActions()`
+- **メリット**: リレンダリング最適化、参照安定化

+ 3 - 2
apps/app/src/client/components/PageEditor/EditorNavbarBottom/EditorAssistantToggleButton.tsx

@@ -2,11 +2,12 @@ import { useCallback } from 'react';
 
 import { useTranslation } from 'next-i18next';
 
-import { useAiAssistantSidebar } from '~/features/openai/client/stores/ai-assistant';
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from '~/features/openai/client/states';
 
 export const EditorAssistantToggleButton = (): JSX.Element => {
   const { t } = useTranslation();
-  const { data, close, openEditor } = useAiAssistantSidebar();
+  const data = useAiAssistantSidebarStatus();
+  const { close, openEditor } = useAiAssistantSidebarActions();
   const { isOpened } = data ?? {};
 
   const toggle = useCallback(() => {

+ 4 - 2
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementModal.tsx

@@ -20,12 +20,13 @@ import loggerFactory from '~/utils/logger';
 import type { SelectablePage } from '../../../../interfaces/selectable-page';
 import { removeGlobPath } from '../../../../utils/remove-glob-path';
 import { createAiAssistant, updateAiAssistant } from '../../../services/ai-assistant';
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from '../../../states';
 import {
   useAiAssistantManagementModalStatus,
   useAiAssistantManagementModalActions,
   AiAssistantManagementModalPageMode,
 } from '../../../states/modal/ai-assistant-management';
-import { useSWRxAiAssistants, useAiAssistantSidebar } from '../../../stores/ai-assistant';
+import { useSWRxAiAssistants } from '../../../stores/ai-assistant';
 
 import { AiAssistantManagementEditInstruction } from './AiAssistantManagementEditInstruction';
 import { AiAssistantManagementEditPages } from './AiAssistantManagementEditPages';
@@ -76,7 +77,8 @@ const AiAssistantManagementModalSubstance = (): JSX.Element => {
   const { mutate: mutateAiAssistants } = useSWRxAiAssistants();
   const aiAssistantManagementModalData = useAiAssistantManagementModalStatus();
   const { close: closeAiAssistantManagementModal } = useAiAssistantManagementModalActions();
-  const { data: aiAssistantSidebarData, refreshAiAssistantData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
+  const { refreshAiAssistantData } = useAiAssistantSidebarActions();
   const { data: pagePathsWithDescendantCount } = useSWRxPagePathsWithDescendantCount(
     removeGlobPath(aiAssistantManagementModalData?.aiAssistantData?.pagePathPatterns) ?? null,
     undefined,

+ 3 - 3
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/AiAssistantSidebar.tsx

@@ -26,8 +26,7 @@ import {
   useFetchAndSetMessageDataEffect,
   type FormData as FormDataForKnowledgeAssistant,
 } from '../../../services/knowledge-assistant';
-import { useUnifiedMergeViewActions } from '../../../states';
-import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions, useUnifiedMergeViewActions } from '../../../states';
 import { useSWRxThreads } from '../../../stores/thread';
 
 import { MessageCard } from './MessageCard/MessageCard';
@@ -542,7 +541,8 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
 
 
 export const AiAssistantSidebar: FC = memo((): JSX.Element => {
-  const { data: aiAssistantSidebarData, close: closeAiAssistantSidebar, refreshThreadData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
+  const { close: closeAiAssistantSidebar, refreshThreadData } = useAiAssistantSidebarActions();
   const { disable: disableUnifiedMergeView } = useUnifiedMergeViewActions();
 
   const aiAssistantData = aiAssistantSidebarData?.aiAssistantData;

+ 3 - 2
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantSidebar/ThreadList.tsx

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
 
 import type { IThreadRelationHasId } from '~/features/openai/interfaces/thread-relation';
 
-import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from '../../../states';
 import { useSWRxThreads } from '../../../stores/thread';
 
 import styles from './ThreadList.module.scss';
@@ -14,7 +14,8 @@ const moduleClass = styles['thread-list'] ?? '';
 
 export const ThreadList: React.FC = () => {
   const { t } = useTranslation();
-  const { openChat, data: aiAssistantSidebarData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
+  const { openChat } = useAiAssistantSidebarActions();
   const { data: threads } = useSWRxThreads(aiAssistantSidebarData?.aiAssistantData?._id);
 
   const openChatHandler = useCallback((threadData: IThreadRelationHasId) => {

+ 3 - 2
apps/app/src/features/openai/client/components/AiAssistant/OpenDefaultAiAssistantButton.tsx

@@ -7,14 +7,15 @@ import { NotAvailable } from '~/client/components/NotAvailable';
 import { NotAvailableForGuest } from '~/client/components/NotAvailableForGuest';
 import { aiEnabledAtom } from '~/states/server-configurations';
 
-import { useAiAssistantSidebar, useSWRxAiAssistants } from '../../stores/ai-assistant';
+import { useAiAssistantSidebarActions } from '../../states';
+import { useSWRxAiAssistants } from '../../stores/ai-assistant';
 
 import styles from './OpenDefaultAiAssistantButton.module.scss';
 
 const OpenDefaultAiAssistantButtonSubstance = (): JSX.Element => {
   const { t } = useTranslation();
   const { data: aiAssistantData } = useSWRxAiAssistants();
-  const { openChat } = useAiAssistantSidebar();
+  const { openChat } = useAiAssistantSidebarActions();
 
   const defaultAiAssistant = useMemo(() => {
     if (aiAssistantData == null) {

+ 2 - 2
apps/app/src/features/openai/client/components/AiAssistant/Sidebar/AiAssistantList.tsx

@@ -12,8 +12,8 @@ import loggerFactory from '~/utils/logger';
 import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interfaces/ai-assistant';
 import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { deleteAiAssistant, setDefaultAiAssistant } from '../../../services/ai-assistant';
+import { useAiAssistantSidebarActions } from '../../../states';
 import { useAiAssistantManagementModalActions } from '../../../states/modal/ai-assistant-management';
-import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
 import { getShareScopeIcon } from '../../../utils/get-share-scope-Icon';
 
 import { DeleteAiAssistantModal } from './DeleteAiAssistantModal';
@@ -145,7 +145,7 @@ export const AiAssistantList: React.FC<AiAssistantListProps> = ({
   isTeamAssistant, aiAssistants, onUpdated, onDeleted, onCollapsed,
 }) => {
   const { t } = useTranslation();
-  const { openChat } = useAiAssistantSidebar();
+  const { openChat } = useAiAssistantSidebarActions();
   const currentUser = useCurrentUser();
   const { open: openAiAssistantManagementModal } = useAiAssistantManagementModalActions();
 

+ 4 - 2
apps/app/src/features/openai/client/components/AiAssistant/Sidebar/AiAssistantSubstance.tsx

@@ -2,8 +2,9 @@ import React, { type JSX, useCallback } from 'react';
 
 import { useTranslation } from 'react-i18next';
 
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from '../../../states';
 import { useAiAssistantManagementModalActions } from '../../../states/modal/ai-assistant-management';
-import { useSWRxAiAssistants, useAiAssistantSidebar } from '../../../stores/ai-assistant';
+import { useSWRxAiAssistants } from '../../../stores/ai-assistant';
 import { useSWRINFxRecentThreads } from '../../../stores/thread';
 
 import { AiAssistantList } from './AiAssistantList';
@@ -16,7 +17,8 @@ const moduleClass = styles['grw-ai-assistant-substance'] ?? '';
 export const AiAssistantContent = (): JSX.Element => {
   const { t } = useTranslation();
   const { open } = useAiAssistantManagementModalActions();
-  const { data: aiAssistantSidebarData, close: closeAiAssistantSidebar } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
+  const { close: closeAiAssistantSidebar } = useAiAssistantSidebarActions();
   const { mutate: mutateRecentThreads } = useSWRINFxRecentThreads();
   const { data: aiAssistants, mutate: mutateAiAssistants } = useSWRxAiAssistants();
 

+ 3 - 2
apps/app/src/features/openai/client/components/AiAssistant/Sidebar/ThreadList.tsx

@@ -9,7 +9,7 @@ import { useSWRMUTxThreads, useSWRINFxRecentThreads } from '~/features/openai/cl
 import loggerFactory from '~/utils/logger';
 
 import { deleteThread } from '../../../services/thread';
-import { useAiAssistantSidebar } from '../../../stores/ai-assistant';
+import { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from '../../../states';
 
 const logger = loggerFactory('growi:openai:client:components:ThreadList');
 
@@ -17,7 +17,8 @@ export const ThreadList: React.FC = () => {
   const swrInifiniteThreads = useSWRINFxRecentThreads();
   const { t } = useTranslation();
   const { data, mutate: mutateRecentThreads } = swrInifiniteThreads;
-  const { openChat, data: aiAssistantSidebarData, close: closeAiAssistantSidebar } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
+  const { openChat, close: closeAiAssistantSidebar } = useAiAssistantSidebarActions();
   const { trigger: mutateAssistantThreadData } = useSWRMUTxThreads(aiAssistantSidebarData?.aiAssistantData?._id);
 
   const isEmpty = data?.[0]?.paginateResult.totalDocs === 0;

+ 2 - 3
apps/app/src/features/openai/client/services/editor-assistant/use-editor-assistant.tsx

@@ -32,8 +32,7 @@ import { ThreadType } from '../../../interfaces/thread-relation';
 import { handleIfSuccessfullyParsed } from '../../../utils/handle-if-successfully-parsed';
 import { AiAssistantDropdown } from '../../components/AiAssistant/AiAssistantSidebar/AiAssistantDropdown';
 import { QuickMenuList } from '../../components/AiAssistant/AiAssistantSidebar/QuickMenuList';
-import { useIsEnableUnifiedMergeView, useUnifiedMergeViewActions } from '../../states';
-import { useAiAssistantSidebar } from '../../stores/ai-assistant';
+import { useIsEnableUnifiedMergeView, useUnifiedMergeViewActions, useAiAssistantSidebarStatus } from '../../states';
 import { useClientEngineIntegration, shouldUseClientProcessing } from '../client-engine-integration';
 
 import { getPageBodyForContext } from './get-page-body-for-context';
@@ -145,7 +144,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
   const { disable: disableUnifiedMergeView, enable: enableUnifiedMergeView } = useUnifiedMergeViewActions();
   const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
   const yDocs = useSecondaryYdocs(isEnableUnifiedMergeView ?? false, { pageId: currentPageId ?? undefined, useSecondary: isEnableUnifiedMergeView ?? false });
-  const { data: aiAssistantSidebarData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
   const clientEngine = useClientEngineIntegration({
     enableClientProcessing: shouldUseClientProcessing(),
     enableServerFallback: true,

+ 3 - 3
apps/app/src/features/openai/client/services/knowledge-assistant.tsx

@@ -19,7 +19,7 @@ import type { MessageLog, MessageWithCustomMetaData } from '../../interfaces/mes
 import type { IThreadRelationHasId } from '../../interfaces/thread-relation';
 import { ThreadType } from '../../interfaces/thread-relation';
 import { AiAssistantChatInitialView } from '../components/AiAssistant/AiAssistantSidebar/AiAssistantChatInitialView';
-import { useAiAssistantSidebar } from '../stores/ai-assistant';
+import { useAiAssistantSidebarStatus } from '../states';
 import { useSWRMUTxMessages } from '../stores/message';
 import { useSWRMUTxThreads, useSWRINFxRecentThreads } from '../stores/thread';
 
@@ -72,7 +72,7 @@ type UseKnowledgeAssistant = () => {
 
 export const useKnowledgeAssistant: UseKnowledgeAssistant = () => {
   // Hooks
-  const { data: aiAssistantSidebarData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
   const { aiAssistantData, threadData } = aiAssistantSidebarData ?? {};
   const { mutate: mutateRecentThreads } = useSWRINFxRecentThreads();
   const { trigger: mutateThreadData } = useSWRMUTxThreads(aiAssistantData?._id);
@@ -284,7 +284,7 @@ export const useFetchAndSetMessageDataEffect = (
     setMessageLogs: Dispatch<SetStateAction<MessageLog[]>>,
     threadId?: string,
 ): void => {
-  const { data: aiAssistantSidebarData } = useAiAssistantSidebar();
+  const aiAssistantSidebarData = useAiAssistantSidebarStatus();
   const { trigger: mutateMessageData } = useSWRMUTxMessages(
     aiAssistantSidebarData?.aiAssistantData?._id,
     threadId,

+ 101 - 0
apps/app/src/features/openai/client/states/ai-assistant-sidebar.ts

@@ -0,0 +1,101 @@
+import { useCallback } from 'react';
+
+import { atom, useAtomValue, useSetAtom } from 'jotai';
+
+import { type AiAssistantHasId } from '../../interfaces/ai-assistant';
+import type { IThreadRelationHasId } from '../../interfaces/thread-relation';
+
+/**
+ * Type definition for AI Assistant Sidebar status
+ */
+export type AiAssistantSidebarStatus = {
+  isOpened: boolean;
+  isEditorAssistant?: boolean;
+  aiAssistantData?: AiAssistantHasId;
+  threadData?: IThreadRelationHasId;
+};
+
+/**
+ * Type definition for AI Assistant Sidebar actions
+ */
+export type AiAssistantSidebarActions = {
+  openChat: (aiAssistantData: AiAssistantHasId, threadData?: IThreadRelationHasId) => void;
+  openEditor: () => void;
+  close: () => void;
+  refreshAiAssistantData: (aiAssistantData?: AiAssistantHasId) => void;
+  refreshThreadData: (threadData?: IThreadRelationHasId) => void;
+};
+
+/**
+ * Atom for managing AI Assistant Sidebar state
+ */
+const aiAssistantSidebarAtom = atom<AiAssistantSidebarStatus>({
+  isOpened: false,
+});
+
+/**
+ * Hook to get the AI Assistant Sidebar status
+ * @returns The current AI Assistant Sidebar status
+ */
+export const useAiAssistantSidebarStatus = (): AiAssistantSidebarStatus => {
+  return useAtomValue(aiAssistantSidebarAtom);
+};
+
+/**
+ * Hook to get the AI Assistant Sidebar actions
+ * @returns Actions for managing the AI Assistant Sidebar
+ */
+export const useAiAssistantSidebarActions = (): AiAssistantSidebarActions => {
+  const setSidebar = useSetAtom(aiAssistantSidebarAtom);
+
+  const openChat = useCallback(
+    (aiAssistantData: AiAssistantHasId, threadData?: IThreadRelationHasId) => {
+      setSidebar({ isOpened: true, aiAssistantData, threadData });
+    },
+    [setSidebar],
+  );
+
+  const openEditor = useCallback(() => {
+    setSidebar({
+      isOpened: true,
+      isEditorAssistant: true,
+      aiAssistantData: undefined,
+      threadData: undefined,
+    });
+  }, [setSidebar]);
+
+  const close = useCallback(() => {
+    setSidebar({
+      isOpened: false,
+      isEditorAssistant: false,
+      aiAssistantData: undefined,
+      threadData: undefined,
+    });
+  }, [setSidebar]);
+
+  const refreshAiAssistantData = useCallback(
+    (aiAssistantData?: AiAssistantHasId) => {
+      setSidebar((currentState) => {
+        return { ...currentState, aiAssistantData };
+      });
+    },
+    [setSidebar],
+  );
+
+  const refreshThreadData = useCallback(
+    (threadData?: IThreadRelationHasId) => {
+      setSidebar((currentState) => {
+        return { ...currentState, threadData };
+      });
+    },
+    [setSidebar],
+  );
+
+  return {
+    openChat,
+    openEditor,
+    close,
+    refreshAiAssistantData,
+    refreshThreadData,
+  };
+};

+ 2 - 0
apps/app/src/features/openai/client/states/index.ts

@@ -1 +1,3 @@
 export { useIsEnableUnifiedMergeView, useUnifiedMergeViewActions } from './unified-merge-view';
+export { useAiAssistantSidebarStatus, useAiAssistantSidebarActions } from './ai-assistant-sidebar';
+export type { AiAssistantSidebarStatus, AiAssistantSidebarActions } from './ai-assistant-sidebar';

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

@@ -1,13 +1,9 @@
-import { useCallback } from 'react';
-
-import { useSWRStatic } from '@growi/core/dist/swr';
 import { type SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 
 import { apiv3Get } from '~/client/util/apiv3-client';
 
-import { type AccessibleAiAssistantsHasId, type AiAssistantHasId } from '../../interfaces/ai-assistant';
-import type { IThreadRelationHasId } from '../../interfaces/thread-relation';
+import { type AccessibleAiAssistantsHasId } from '../../interfaces/ai-assistant';
 
 export const useSWRxAiAssistants = (): SWRResponse<AccessibleAiAssistantsHasId, Error> => {
   return useSWRImmutable<AccessibleAiAssistantsHasId>(
@@ -15,66 +11,3 @@ export const useSWRxAiAssistants = (): SWRResponse<AccessibleAiAssistantsHasId,
     ([endpoint]) => apiv3Get(endpoint).then(response => response.data.accessibleAiAssistants),
   );
 };
-
-/*
-*  useAiAssistantSidebar
-*/
-type AiAssistantSidebarStatus = {
-  isOpened: boolean,
-  isEditorAssistant?: boolean,
-  aiAssistantData?: AiAssistantHasId,
-  threadData?: IThreadRelationHasId,
-}
-
-type AiAssistantSidebarUtils = {
-  openChat(
-    aiAssistantData: AiAssistantHasId,
-    threadData?: IThreadRelationHasId,
-  ): void
-  openEditor(): void
-  close(): void
-  refreshAiAssistantData(aiAssistantData?: AiAssistantHasId): void
-  refreshThreadData(threadData?: IThreadRelationHasId): void
-}
-
-export const useAiAssistantSidebar = (
-    status?: AiAssistantSidebarStatus,
-): SWRResponse<AiAssistantSidebarStatus, Error> & AiAssistantSidebarUtils => {
-  const initialStatus = { isOpened: false };
-  const swrResponse = useSWRStatic<AiAssistantSidebarStatus, Error>('AiAssistantSidebar', status, { fallbackData: initialStatus });
-
-  return {
-    ...swrResponse,
-    openChat: useCallback(
-      (aiAssistantData: AiAssistantHasId, threadData?: IThreadRelationHasId) => {
-        swrResponse.mutate({ isOpened: true, aiAssistantData, threadData });
-      }, [swrResponse],
-    ),
-    openEditor: useCallback(
-      () => {
-        swrResponse.mutate({
-          isOpened: true, isEditorAssistant: true, aiAssistantData: undefined, threadData: undefined,
-        });
-      }, [swrResponse],
-    ),
-    close: useCallback(
-      () => swrResponse.mutate({
-        isOpened: false, isEditorAssistant: false, aiAssistantData: undefined, threadData: undefined,
-      }), [swrResponse],
-    ),
-    refreshAiAssistantData: useCallback(
-      (aiAssistantData) => {
-        swrResponse.mutate((currentState = { isOpened: false }) => {
-          return { ...currentState, aiAssistantData };
-        });
-      }, [swrResponse],
-    ),
-    refreshThreadData: useCallback(
-      (threadData?: IThreadRelationHasId) => {
-        swrResponse.mutate((currentState = { isOpened: false }) => {
-          return { ...currentState, threadData };
-        });
-      }, [swrResponse],
-    ),
-  };
-};