Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 36 additions & 21 deletions refact-agent/gui/src/app/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ import {
threadMessagesSlice,
} from "../features/ThreadMessages";
import {
createMessage,
createThreadWithMessage,
createThreadWitMultipleMessages,
graphqlQueriesAndMutations,
rejectToolUsageAction,
toolConfirmationThunk,
} from "../services/graphql/graphqlThunks";
} from "../services/graphql";
import { push } from "../features/Pages/pagesSlice";

const AUTH_ERROR_MESSAGE =
Expand Down Expand Up @@ -226,10 +223,17 @@ startListening({
}

// TODO: thread or message error?

if (
(createThreadWitMultipleMessages.rejected.match(action) ||
createThreadWithMessage.rejected.match(action) ||
createMessage.rejected.match(action)) &&
(graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage.matchRejected(
action,
) ||
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages.matchRejected(
action,
) ||
graphqlQueriesAndMutations.endpoints.sendMessages.matchRejected(
action,
)) &&
!action.meta.aborted &&
typeof action.payload === "string"
) {
Expand Down Expand Up @@ -281,25 +285,33 @@ startListening({

startListening({
matcher: isAnyOf(
createMessage.fulfilled,
createThreadWithMessage.fulfilled,
createThreadWitMultipleMessages.fulfilled,
graphqlQueriesAndMutations.endpoints.sendMessages.matchFulfilled,
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages
.matchFulfilled,
graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage
.matchFulfilled,
),
effect: (action, listenerApi) => {
const state = listenerApi.getState();
if (
createMessage.fulfilled.match(action) &&
action.meta.arg.input.ftm_belongs_to_ft_id ===
graphqlQueriesAndMutations.endpoints.sendMessages.matchFulfilled(
action,
) &&
action.meta.arg.originalArgs.input.ftm_belongs_to_ft_id ===
state.threadMessages.thread?.ft_id
) {
listenerApi.dispatch(resetAttachedImagesSlice());
} else if (
createThreadWithMessage.fulfilled.match(action) &&
graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage.matchFulfilled(
action,
) &&
action.payload.thread_create.ft_id === state.threadMessages.ft_id
) {
listenerApi.dispatch(resetAttachedImagesSlice());
} else if (
createThreadWitMultipleMessages.fulfilled.match(action) &&
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages.matchFulfilled(
action,
) &&
action.payload.thread_create.ft_id !== state.threadMessages.ft_id
) {
listenerApi.dispatch(resetAttachedImagesSlice());
Expand Down Expand Up @@ -336,9 +348,11 @@ startListening({

// An integration chat was started.
startListening({
actionCreator: createThreadWitMultipleMessages.fulfilled,
matcher:
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages
.matchFulfilled,
effect: (action, listenerApi) => {
if (action.meta.arg.integration) {
if (action.meta.arg.originalArgs.integration) {
listenerApi.dispatch(integrationsApi.util.resetApiState());
listenerApi.dispatch(clearError());
listenerApi.dispatch(
Expand Down Expand Up @@ -366,10 +380,11 @@ startListening({
if (!maybePendingToolCall) return;

if (action.payload.accepted) {
const thunk = toolConfirmationThunk({
ft_id: action.payload.chatId,
confirmation_response: JSON.stringify([action.payload.toolCallId]),
});
const thunk =
graphqlQueriesAndMutations.endpoints.toolConfirmation.initiate({
ft_id: action.payload.chatId,
confirmation_response: JSON.stringify([action.payload.toolCallId]),
});
void listenerApi.dispatch(thunk);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions refact-agent/gui/src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ import {
expertsSlice,
expertsAndModelsMiddleWare,
} from "../features/ExpertsAndModels";
import { toolsSlice } from "../features/Tools";
import { graphqlQueriesAndMutations } from "../services/graphql/graphqlThunks";
import { graphqlQueriesAndMutations } from "../services/graphql";
import { groupsSlice } from "../features/Groups";
import { connectionStatusSlice } from "../features/ConnectionStatus";

const tipOfTheDayPersistConfig = {
key: "totd",
Expand Down Expand Up @@ -109,8 +109,8 @@ const rootReducer = combineSlices(
threadListSlice,
threadMessagesSlice,
expertsSlice,
toolsSlice,
groupsSlice,
connectionStatusSlice,
);

const rootPersistConfig = {
Expand Down
5 changes: 3 additions & 2 deletions refact-agent/gui/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState } from "react";
import { ChatForm, ChatFormProps } from "../ChatForm";
import { ChatContent } from "../ChatContent";
import { Flex } from "@radix-ui/themes";
import { useAppSelector } from "../../hooks";
import { useAppSelector, useSendMessages } from "../../hooks";
import { type Config } from "../../features/Config/configSlice";

import { DropzoneProvider } from "../Dropzone";
Expand All @@ -28,7 +28,8 @@ export const Chat: React.FC<ChatProps> = ({ style, maybeSendToSidebar }) => {

const [isViewingRawJSON, setIsViewingRawJSON] = useState(false);
// const isStreaming = useAppSelector(selectIsStreaming);
const { sendMessage } = useMessageSubscription();
useMessageSubscription();
const { sendMessage } = useSendMessages();
// const totalMessages = useAppSelector(selectTotalMessagesInThread, {
// devModeChecks: { stabilityCheck: "never" },
// });
Expand Down
Loading