Merge branch 'main' into feat/agent-menu

This commit is contained in:
Siddhant Rai
2025-04-16 18:35:38 +05:30
21 changed files with 1568 additions and 231 deletions

View File

@@ -7,7 +7,13 @@ import {
handleFetchAnswer,
handleFetchAnswerSteaming,
} from './conversationHandlers';
import { Answer, ConversationState, Query, Status } from './conversationModels';
import {
Answer,
Query,
Status,
ConversationState,
Attachment,
} from './conversationModels';
const initialState: ConversationState = {
queries: [],
@@ -38,7 +44,9 @@ export const fetchAnswer = createAsyncThunk<
let isSourceUpdated = false;
const state = getState() as RootState;
const attachments = state.conversation.attachments?.map((a) => a.id) || [];
const attachmentIds = state.conversation.attachments
.filter((a) => a.id && a.status === 'completed')
.map((a) => a.id) as string[];
const currentConversationId = state.conversation.conversationId;
const conversationIdToSend = isPreview ? null : currentConversationId;
const save_conversation = isPreview ? false : true;
@@ -129,7 +137,7 @@ export const fetchAnswer = createAsyncThunk<
},
indx,
state.preference.selectedAgent?.id,
attachments,
attachmentIds,
save_conversation,
);
} else {
@@ -144,7 +152,7 @@ export const fetchAnswer = createAsyncThunk<
state.preference.chunks,
state.preference.token_limit,
state.preference.selectedAgent?.id,
attachments,
attachmentIds,
save_conversation,
);
if (answer) {
@@ -301,12 +309,34 @@ export const conversationSlice = createSlice({
const { index, message } = action.payload;
state.queries[index].error = message;
},
setAttachments: (
state,
action: PayloadAction<{ fileName: string; id: string }[]>,
) => {
setAttachments: (state, action: PayloadAction<Attachment[]>) => {
state.attachments = action.payload;
},
addAttachment: (state, action: PayloadAction<Attachment>) => {
state.attachments.push(action.payload);
},
updateAttachment: (
state,
action: PayloadAction<{
taskId: string;
updates: Partial<Attachment>;
}>,
) => {
const index = state.attachments.findIndex(
(att) => att.taskId === action.payload.taskId,
);
if (index !== -1) {
state.attachments[index] = {
...state.attachments[index],
...action.payload.updates,
};
}
},
removeAttachment: (state, action: PayloadAction<string>) => {
state.attachments = state.attachments.filter(
(att) => att.taskId !== action.payload && att.id !== action.payload,
);
},
resetConversation: (state) => {
state.queries = initialState.queries;
state.status = initialState.status;
@@ -337,6 +367,11 @@ export const selectQueries = (state: RootState) => state.conversation.queries;
export const selectStatus = (state: RootState) => state.conversation.status;
export const selectAttachments = (state: RootState) =>
state.conversation.attachments;
export const selectCompletedAttachments = (state: RootState) =>
state.conversation.attachments.filter((att) => att.status === 'completed');
export const {
addQuery,
updateQuery,
@@ -348,6 +383,9 @@ export const {
updateToolCalls,
setConversation,
setAttachments,
addAttachment,
updateAttachment,
removeAttachment,
resetConversation,
} = conversationSlice.actions;
export default conversationSlice.reducer;