()
| 8 | import { loadSession, saveCurrentSession } from "../redux/thunks/session"; |
| 9 | |
| 10 | export const useCompactConversation = () => { |
| 11 | const dispatch = useAppDispatch(); |
| 12 | const ideMessenger = useContext(IdeMessengerContext); |
| 13 | const currentSessionId = useAppSelector((state) => state.session.id); |
| 14 | |
| 15 | return async (index: number) => { |
| 16 | if (!currentSessionId) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | try { |
| 21 | // Set loading state |
| 22 | dispatch(setCompactionLoading({ index, loading: true })); |
| 23 | |
| 24 | await ideMessenger.request("conversation/compact", { |
| 25 | index, |
| 26 | sessionId: currentSessionId, |
| 27 | }); |
| 28 | |
| 29 | // Reload the current session to refresh the conversation state |
| 30 | dispatch( |
| 31 | loadSession({ |
| 32 | sessionId: currentSessionId, |
| 33 | saveCurrentSession: false, |
| 34 | }), |
| 35 | ); |
| 36 | } catch (error) { |
| 37 | console.error("Error compacting conversation:", error); |
| 38 | } finally { |
| 39 | // Clear loading state |
| 40 | dispatch(setCompactionLoading({ index, loading: false })); |
| 41 | } |
| 42 | }; |
| 43 | }; |
| 44 | |
| 45 | export const useDeleteCompaction = () => { |
| 46 | const dispatch = useAppDispatch(); |
no test coverage detected