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
20 changes: 19 additions & 1 deletion refact-agent/gui/src/app/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
setIsWaitingForResponse,
upsertToolCall,
sendCurrentChatToLspAfterToolCallUpdate,
chatResponse,
} from "../features/Chat/Thread";
import { statisticsApi } from "../services/refact/statistics";
import { integrationsApi } from "../services/refact/integrations";
Expand All @@ -38,8 +39,12 @@ import {
updateConfirmationAfterIdeToolUse,
} from "../features/ToolConfirmation/confirmationSlice";
import { setInitialAgentUsage } from "../features/AgentUsage/agentUsageSlice";
import { ideToolCallResponse } from "../hooks/useEventBusForIDE";
import {
ideToolCallResponse,
ideForceReloadProjectTreeFiles,
} from "../hooks/useEventBusForIDE";
import { upsertToolCallIntoHistory } from "../features/History/historySlice";
import { isToolResponse } from "../events";

const AUTH_ERROR_MESSAGE =
"There is an issue with your API key. Check out your API Key or re-login";
Expand Down Expand Up @@ -536,3 +541,16 @@ startListening({
}
},
});

// JB file refresh
// TBD: this could include diff messages to
startListening({
actionCreator: chatResponse,
effect: (action, listenerApi) => {
const state = listenerApi.getState();
if (state.config.host !== "jetbrains") return;
if (!isToolResponse(action.payload)) return;
if (!window.postIntellijMessage) return;
window.postIntellijMessage(ideForceReloadProjectTreeFiles());
},
});
7 changes: 2 additions & 5 deletions refact-agent/gui/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useGetCapsQuery,
useCapsForToolUse,
useAgentUsage,
useLastSentCompressionStop,
} from "../../hooks";
import { type Config } from "../../features/Config/configSlice";
import {
Expand Down Expand Up @@ -54,7 +53,6 @@ export const Chat: React.FC<ChatProps> = ({
const { submit, abort, retryFromIndex } = useSendChatRequest();

const chatToolUse = useAppSelector(getSelectedToolUse);
const compressionStop = useLastSentCompressionStop();
const threadNewChatSuggested = useAppSelector(selectThreadNewChatSuggested);
const messages = useAppSelector(selectMessages);
const capsForToolUse = useCapsForToolUse();
Expand Down Expand Up @@ -106,9 +104,8 @@ export const Chat: React.FC<ChatProps> = ({
<AgentUsage />
<SuggestNewChat
shouldBeVisible={
compressionStop.stopped ||
(threadNewChatSuggested.wasSuggested &&
!threadNewChatSuggested.wasRejectedByUser)
threadNewChatSuggested.wasSuggested &&
!threadNewChatSuggested.wasRejectedByUser
}
/>
{!isStreaming && preventSend && unCalledTools && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { popBackTo, push } from "../../../features/Pages/pagesSlice";
import { telemetryApi } from "../../../services/refact";
import {
enableSend,
newChatAction,
selectChatId,
setIsNewChatSuggestionRejected,
Expand Down Expand Up @@ -64,6 +65,7 @@ export const SuggestNewChat = ({

const handleClose = () => {
dispatch(setIsNewChatSuggestionRejected({ chatId, value: true }));
dispatch(enableSend({ id: chatId }));

void sendTelemetryEvent({
scope: `dismissedNewChatSuggestionWarning`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
selectIsStreaming,
selectIsWaiting,
selectMessages,
// selectLastSentCompression,
} from "../../features/Chat";
import { useAppSelector, useLastSentCompressionStop } from "../../hooks";
import {
Expand Down Expand Up @@ -33,19 +32,17 @@ export function useUsageCounter() {
}, [currentThreadUsage]);

const isOverflown = useMemo(() => {
if (!compressionStop.stopped) return false;
if (compressionStop.strength === "low") return true;
if (compressionStop.strength === "medium") return true;
if (compressionStop.strength === "high") return true;
return false;
}, [compressionStop.stopped, compressionStop.strength]);
}, [compressionStop.strength]);

const isWarning = useMemo(() => {
if (!compressionStop.stopped) return false;
if (compressionStop.strength === "medium") return true;
if (compressionStop.strength === "high") return true;
return false;
}, [compressionStop.stopped, compressionStop.strength]);
}, [compressionStop.strength]);

const shouldShow = useMemo(() => {
return messages.length > 0 && !isStreaming && !isWaiting;
Expand Down
14 changes: 3 additions & 11 deletions refact-agent/gui/src/features/Chat/Thread/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
setIsNewChatSuggestionRejected,
upsertToolCall,
setIncreaseMaxTokens,
setThreadPaused,
} from "./actions";
import { formatChatResponse } from "./utils";
import {
Expand Down Expand Up @@ -79,7 +78,6 @@ const createChatThread = (
boost_reasoning: false,
automatic_patch: false,
increase_max_tokens: false,
paused: false,
};
return chat;
};
Expand Down Expand Up @@ -209,7 +207,7 @@ export const chatReducer = createReducer(initialState, (builder) => {
action.payload.compression_strength !== "absent"
) {
state.thread.new_chat_suggested = {
...state.thread.new_chat_suggested,
wasRejectedByUser: false,
wasSuggested: true,
};
}
Expand Down Expand Up @@ -243,15 +241,14 @@ export const chatReducer = createReducer(initialState, (builder) => {

builder.addCase(setIsNewChatSuggested, (state, action) => {
if (state.thread.id !== action.payload.chatId) return state;
state.thread.paused = true;
state.thread.new_chat_suggested = {
wasSuggested: action.payload.value,
};
});

builder.addCase(setIsNewChatSuggestionRejected, (state, action) => {
if (state.thread.id !== action.payload.chatId) return state;
state.thread.paused = false;
state.prevent_send = false;
state.thread.new_chat_suggested = {
...state.thread.new_chat_suggested,
wasRejectedByUser: action.payload.value,
Expand Down Expand Up @@ -279,7 +276,6 @@ export const chatReducer = createReducer(initialState, (builder) => {
state.streaming = true;
state.thread.read = false;
state.prevent_send = false;
state.thread.paused = false;
});

builder.addCase(removeChatFromCache, (state, action) => {
Expand Down Expand Up @@ -337,7 +333,7 @@ export const chatReducer = createReducer(initialState, (builder) => {
lastUserMessage.compression_strength !== "absent"
) {
state.thread.new_chat_suggested = {
...state.thread.new_chat_suggested,
wasRejectedByUser: false,
wasSuggested: true,
};
}
Expand Down Expand Up @@ -427,10 +423,6 @@ export const chatReducer = createReducer(initialState, (builder) => {
state.thread.increase_max_tokens = action.payload;
});

builder.addCase(setThreadPaused, (state, action) => {
state.thread.paused = action.payload;
});

builder.addMatcher(
capsApi.endpoints.getCaps.matchFulfilled,
(state, action) => {
Expand Down
5 changes: 0 additions & 5 deletions refact-agent/gui/src/features/Chat/Thread/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,3 @@ export const selectLastSentCompression = createSelector(
return lastCompression;
},
);

export const selectThreadPaused = createSelector(
selectThread,
(thread) => thread.paused ?? false,
);
1 change: 0 additions & 1 deletion refact-agent/gui/src/features/Chat/Thread/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export type ChatThread = {
currentMaximumContextTokens?: number;
currentMessageContextTokens?: number;
increase_max_tokens?: boolean;
paused?: boolean;
};

export type SuggestedChat = {
Expand Down
27 changes: 12 additions & 15 deletions refact-agent/gui/src/hooks/useCompressionStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { useEffect, useCallback, useMemo } from "react";
import { useAppSelector } from "./useAppSelector";
import { useAppDispatch } from "./useAppDispatch";
import {
selectChatId,
selectLastSentCompression,
selectMessages,
selectThreadPaused,
setThreadPaused,
setIsNewChatSuggested,
setIsNewChatSuggestionRejected,
setPreventSend,
} from "../features/Chat";
import { takeFromEndWhile } from "../utils";
import { isUserMessage } from "../events";
Expand All @@ -14,12 +16,7 @@ export function useLastSentCompressionStop() {
const dispatch = useAppDispatch();
const lastSentCompression = useAppSelector(selectLastSentCompression);
const messages = useAppSelector(selectMessages);
const stopped = useAppSelector(selectThreadPaused);
useEffect(() => {
if (lastSentCompression && lastSentCompression !== "absent" && !stopped) {
dispatch(setThreadPaused(true));
}
}, [dispatch, lastSentCompression, stopped]);
const chatId = useAppSelector(selectChatId);

const messagesFromLastUserMessage = useMemo(() => {
return takeFromEndWhile(messages, (message) => !isUserMessage(message))
Expand All @@ -30,16 +27,16 @@ export function useLastSentCompressionStop() {
if (
lastSentCompression &&
lastSentCompression !== "absent" &&
messagesFromLastUserMessage >= 40 &&
!stopped
messagesFromLastUserMessage >= 40
) {
dispatch(setThreadPaused(true));
dispatch(setPreventSend({ id: chatId }));
dispatch(setIsNewChatSuggested({ chatId, value: true }));
}
}, [dispatch, lastSentCompression, messagesFromLastUserMessage, stopped]);
}, [chatId, dispatch, lastSentCompression, messagesFromLastUserMessage]);

const resume = useCallback(() => {
dispatch(setThreadPaused(false));
}, [dispatch]);
dispatch(setIsNewChatSuggestionRejected({ chatId, value: true }));
}, [chatId, dispatch]);

return { stopped, resume, strength: lastSentCompression };
return { resume, strength: lastSentCompression };
}
1 change: 1 addition & 0 deletions refact-agent/gui/src/hooks/useDiffFileReload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isDiffMessage } from "../services/refact";
* Hook to handle file reloading for diff messages in JetBrains IDE
* Ensures each file is only reloaded once per message
*/
// Note this won't work if the chat is in the cache.
export function useDiffFileReload() {
const messages = useAppSelector(selectMessages);
const configIdeHost = useAppSelector(selectConfig).host;
Expand Down
4 changes: 4 additions & 0 deletions refact-agent/gui/src/hooks/useEventBusForIDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const ideToolCallResponse = createAction<{
accepted: boolean | "indeterminate";
}>("ide/toolEditResponse");

export const ideForceReloadProjectTreeFiles = createAction(
"ide/forceReloadProjectTreeFiles",
);

export const useEventsBusForIDE = () => {
const [sendTelemetryEvent] =
telemetryApi.useLazySendTelemetryChatEventQuery();
Expand Down
4 changes: 0 additions & 4 deletions refact-agent/gui/src/hooks/useSendChatRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {

import { v4 as uuidv4 } from "uuid";
import { upsertToolCallIntoHistory } from "../features/History/historySlice";
import { useLastSentCompressionStop } from "./useCompressionStop";

type SubmitHandlerParams =
| {
Expand Down Expand Up @@ -356,7 +355,6 @@ export function useAutoSend() {
const sendImmediately = useAppSelector(selectSendImmediately);
const wasInteracted = useAppSelector(getToolsInteractionStatus); // shows if tool confirmation popup was interacted by user
const areToolsConfirmed = useAppSelector(getToolsConfirmationStatus);
const compressionStop = useLastSentCompressionStop();
const { sendMessages, abort, messagesWithSystemPrompt } =
useSendChatRequest();
// TODO: make a selector for this, or show tool formation
Expand All @@ -381,7 +379,6 @@ export function useAutoSend() {
const lastMessage = currentMessages.slice(-1)[0];

if (
!compressionStop.stopped &&
isAssistantMessage(lastMessage) &&
lastMessage.tool_calls &&
lastMessage.tool_calls.length > 0
Expand Down Expand Up @@ -418,6 +415,5 @@ export function useAutoSend() {
isIntegration,
thread.mode,
thread,
compressionStop.stopped,
]);
}