feat(shared): sync sources flow; clean up

This commit is contained in:
ManishMadan2882
2024-09-23 01:33:41 +05:30
parent 757abda654
commit 40c361968e
2 changed files with 27 additions and 56 deletions

View File

@@ -6,7 +6,6 @@ import { createAsyncThunk } from '@reduxjs/toolkit';
import {
handleFetchSharedAnswer,
handleFetchSharedAnswerStreaming,
handleSearchViaApiKey,
} from './conversationHandlers';
const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
@@ -45,22 +44,13 @@ export const fetchSharedAnswer = createAsyncThunk<Answer, { question: string }>(
// set status to 'idle'
dispatch(sharedConversationSlice.actions.setStatus('idle'));
dispatch(saveToLocalStorage());
state.sharedConversation.apiKey &&
handleSearchViaApiKey(
question,
state.sharedConversation.apiKey,
state.sharedConversation.queries,
).then((sources) => {
//dispatch streaming sources
sources &&
dispatch(
updateStreamingSource({
index: state.sharedConversation.queries.length - 1,
query: { sources: sources ?? [] },
}),
);
});
} else if (data.type === 'source') {
dispatch(
updateStreamingSource({
index: state.sharedConversation.queries.length - 1,
query: { sources: data.source ?? [] },
}),
);
} else if (data.type === 'error') {
// set status to 'failed'
dispatch(sharedConversationSlice.actions.setStatus('failed'));
@@ -247,7 +237,8 @@ export const {
updateStreamingSource,
} = sharedConversationSlice.actions;
export const selectStatus = (state: RootState) => state.conversation.status;
export const selectStatus = (state: RootState) =>
state.sharedConversation.status;
export const selectClientAPIKey = (state: RootState) =>
state.sharedConversation.apiKey;
export const selectQueries = (state: RootState) =>