Skip to content

Commit 050adf5

Browse files
authored
Connection status (#864)
* wip: migrate getUser to getBasicStuff query * refactor: migrate `group_create` to urql/core * refactor: unify urql usage * fix: use group.id when creating a thread. * fix: linter issues. * wip: add socket counter and refactor sending messages * refactor: migration sendMessages to quiries and mutations api * move thread creation thunks to quires and mutations api. * refactor: migrate model and experts thunks to api * refactor: migrate cloud tools request to graphql api * fix(ui): remove thread * chore: remove unused thunk * refactor: pause thread thunk * refactor: migrate tool confirmation thunk to mutations api * refactor: move subscriptions to a different file from other graphql calls. * fix: stability checks warnings.
1 parent d5da095 commit 050adf5

39 files changed

+1474
-1479
lines changed

refact-agent/gui/src/app/middleware.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ import {
3434
threadMessagesSlice,
3535
} from "../features/ThreadMessages";
3636
import {
37-
createMessage,
38-
createThreadWithMessage,
39-
createThreadWitMultipleMessages,
37+
graphqlQueriesAndMutations,
4038
rejectToolUsageAction,
41-
toolConfirmationThunk,
42-
} from "../services/graphql/graphqlThunks";
39+
} from "../services/graphql";
4340
import { push } from "../features/Pages/pagesSlice";
4441

4542
const AUTH_ERROR_MESSAGE =
@@ -226,10 +223,17 @@ startListening({
226223
}
227224

228225
// TODO: thread or message error?
226+
229227
if (
230-
(createThreadWitMultipleMessages.rejected.match(action) ||
231-
createThreadWithMessage.rejected.match(action) ||
232-
createMessage.rejected.match(action)) &&
228+
(graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage.matchRejected(
229+
action,
230+
) ||
231+
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages.matchRejected(
232+
action,
233+
) ||
234+
graphqlQueriesAndMutations.endpoints.sendMessages.matchRejected(
235+
action,
236+
)) &&
233237
!action.meta.aborted &&
234238
typeof action.payload === "string"
235239
) {
@@ -281,25 +285,33 @@ startListening({
281285

282286
startListening({
283287
matcher: isAnyOf(
284-
createMessage.fulfilled,
285-
createThreadWithMessage.fulfilled,
286-
createThreadWitMultipleMessages.fulfilled,
288+
graphqlQueriesAndMutations.endpoints.sendMessages.matchFulfilled,
289+
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages
290+
.matchFulfilled,
291+
graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage
292+
.matchFulfilled,
287293
),
288294
effect: (action, listenerApi) => {
289295
const state = listenerApi.getState();
290296
if (
291-
createMessage.fulfilled.match(action) &&
292-
action.meta.arg.input.ftm_belongs_to_ft_id ===
297+
graphqlQueriesAndMutations.endpoints.sendMessages.matchFulfilled(
298+
action,
299+
) &&
300+
action.meta.arg.originalArgs.input.ftm_belongs_to_ft_id ===
293301
state.threadMessages.thread?.ft_id
294302
) {
295303
listenerApi.dispatch(resetAttachedImagesSlice());
296304
} else if (
297-
createThreadWithMessage.fulfilled.match(action) &&
305+
graphqlQueriesAndMutations.endpoints.createThreadWithSingleMessage.matchFulfilled(
306+
action,
307+
) &&
298308
action.payload.thread_create.ft_id === state.threadMessages.ft_id
299309
) {
300310
listenerApi.dispatch(resetAttachedImagesSlice());
301311
} else if (
302-
createThreadWitMultipleMessages.fulfilled.match(action) &&
312+
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages.matchFulfilled(
313+
action,
314+
) &&
303315
action.payload.thread_create.ft_id !== state.threadMessages.ft_id
304316
) {
305317
listenerApi.dispatch(resetAttachedImagesSlice());
@@ -336,9 +348,11 @@ startListening({
336348

337349
// An integration chat was started.
338350
startListening({
339-
actionCreator: createThreadWitMultipleMessages.fulfilled,
351+
matcher:
352+
graphqlQueriesAndMutations.endpoints.createThreadWitMultipleMessages
353+
.matchFulfilled,
340354
effect: (action, listenerApi) => {
341-
if (action.meta.arg.integration) {
355+
if (action.meta.arg.originalArgs.integration) {
342356
listenerApi.dispatch(integrationsApi.util.resetApiState());
343357
listenerApi.dispatch(clearError());
344358
listenerApi.dispatch(
@@ -366,10 +380,11 @@ startListening({
366380
if (!maybePendingToolCall) return;
367381

368382
if (action.payload.accepted) {
369-
const thunk = toolConfirmationThunk({
370-
ft_id: action.payload.chatId,
371-
confirmation_response: JSON.stringify([action.payload.toolCallId]),
372-
});
383+
const thunk =
384+
graphqlQueriesAndMutations.endpoints.toolConfirmation.initiate({
385+
ft_id: action.payload.chatId,
386+
confirmation_response: JSON.stringify([action.payload.toolCallId]),
387+
});
373388
void listenerApi.dispatch(thunk);
374389
return;
375390
}

refact-agent/gui/src/app/store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ import {
5252
expertsSlice,
5353
expertsAndModelsMiddleWare,
5454
} from "../features/ExpertsAndModels";
55-
import { toolsSlice } from "../features/Tools";
56-
import { graphqlQueriesAndMutations } from "../services/graphql/graphqlThunks";
55+
import { graphqlQueriesAndMutations } from "../services/graphql";
5756
import { groupsSlice } from "../features/Groups";
57+
import { connectionStatusSlice } from "../features/ConnectionStatus";
5858

5959
const tipOfTheDayPersistConfig = {
6060
key: "totd",
@@ -109,8 +109,8 @@ const rootReducer = combineSlices(
109109
threadListSlice,
110110
threadMessagesSlice,
111111
expertsSlice,
112-
toolsSlice,
113112
groupsSlice,
113+
connectionStatusSlice,
114114
);
115115

116116
const rootPersistConfig = {

refact-agent/gui/src/components/Chat/Chat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useState } from "react";
22
import { ChatForm, ChatFormProps } from "../ChatForm";
33
import { ChatContent } from "../ChatContent";
44
import { Flex } from "@radix-ui/themes";
5-
import { useAppSelector } from "../../hooks";
5+
import { useAppSelector, useSendMessages } from "../../hooks";
66
import { type Config } from "../../features/Config/configSlice";
77

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

2929
const [isViewingRawJSON, setIsViewingRawJSON] = useState(false);
3030
// const isStreaming = useAppSelector(selectIsStreaming);
31-
const { sendMessage } = useMessageSubscription();
31+
useMessageSubscription();
32+
const { sendMessage } = useSendMessages();
3233
// const totalMessages = useAppSelector(selectTotalMessagesInThread, {
3334
// devModeChecks: { stabilityCheck: "never" },
3435
// });

0 commit comments

Comments
 (0)