Skip to content

Commit 1036caa

Browse files
committed
fix(apply): auto calls when user manually presses apply then accept/reject.
1 parent cdfb725 commit 1036caa

File tree

5 files changed

+89
-101
lines changed

5 files changed

+89
-101
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
newIntegrationChat,
1313
chatResponse,
1414
setIsWaitingForResponse,
15-
upsertToolCall,
1615
} from "../features/Chat/Thread";
1716
import { statisticsApi } from "../services/refact/statistics";
1817
import { integrationsApi } from "../services/refact/integrations";
@@ -47,7 +46,6 @@ import {
4746
updateMaxAgentUsageAmount,
4847
} from "../features/AgentUsage/agentUsageSlice";
4948
import { ideToolCallResponse } from "../hooks/useEventBusForIDE";
50-
import { upsertToolCallIntoHistory } from "../features/History/historySlice";
5149

5250
const AUTH_ERROR_MESSAGE =
5351
"There is an issue with your API key. Check out your API Key or re-login";
@@ -510,8 +508,6 @@ startListening({
510508
actionCreator: ideToolCallResponse,
511509
effect: (action, listenerApi) => {
512510
const state = listenerApi.getState();
513-
listenerApi.dispatch(upsertToolCall(action.payload));
514-
listenerApi.dispatch(upsertToolCallIntoHistory(action.payload));
515511
listenerApi.dispatch(updateConfirmationAfterIdeToolUse(action.payload));
516512

517513
const pauseReasons = state.confirmation.pauseReasons.filter(

refact-agent/gui/src/features/Chat/Thread/actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
import { ToolCommand } from "../../../services/refact/tools";
3434
import { scanFoDuplicatesWith, takeFromEndWhile } from "../../../utils";
3535
import { debugApp } from "../../../debugConfig";
36-
import { ideToolCallResponse } from "../../../hooks";
36+
// import { ideToolCallResponse } from "../../../hooks";
3737

3838
export const newChatAction = createAction("chatThread/new");
3939

@@ -142,9 +142,9 @@ export const fixBrokenToolMessages = createAction<PayloadWithId>(
142142
"chatThread/fixBrokenToolMessages",
143143
);
144144

145-
export const upsertToolCall = createAction<
146-
Parameters<typeof ideToolCallResponse>[0]
147-
>("chatThread/upsertToolCall");
145+
// export const upsertToolCall = createAction<
146+
// Parameters<typeof ideToolCallResponse>[0]
147+
// >("chatThread/upsertToolCall");
148148

149149
// TODO: This is the circular dep when imported from hooks :/
150150
const createAppAsyncThunk = createAsyncThunk.withTypes<{

refact-agent/gui/src/features/Chat/Thread/reducer.ts

Lines changed: 72 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createReducer, Draft } from "@reduxjs/toolkit";
1+
import { createReducer } from "@reduxjs/toolkit";
22
import {
33
Chat,
44
ChatThread,
@@ -35,18 +35,11 @@ import {
3535
fixBrokenToolMessages,
3636
setIsNewChatSuggested,
3737
setIsNewChatSuggestionRejected,
38-
upsertToolCall,
3938
} from "./actions";
4039
import { formatChatResponse } from "./utils";
4140
import {
42-
ChatMessages,
4341
DEFAULT_MAX_NEW_TOKENS,
44-
isAssistantMessage,
45-
isDiffMessage,
46-
isMultiModalToolResult,
4742
isToolCallMessage,
48-
isToolMessage,
49-
ToolMessage,
5043
validateToolCall,
5144
} from "../../../services/refact";
5245

@@ -339,76 +332,76 @@ export const chatReducer = createReducer(initialState, (builder) => {
339332
state.thread.messages = [...messages, newMessage];
340333
});
341334

342-
builder.addCase(upsertToolCall, (state, action) => {
343-
// if (action.payload.toolCallId !== state.thread.id && !(action.payload.chatId in state.cache)) return state;
344-
if (action.payload.chatId === state.thread.id) {
345-
maybeAppendToolCallResultFromIdeToMessages(
346-
state.thread.messages,
347-
action.payload.toolCallId,
348-
action.payload.accepted,
349-
);
350-
} else if (action.payload.chatId in state.cache) {
351-
const thread = state.cache[action.payload.chatId];
352-
maybeAppendToolCallResultFromIdeToMessages(
353-
thread.messages,
354-
action.payload.toolCallId,
355-
action.payload.accepted,
356-
);
357-
}
358-
});
335+
// builder.addCase(upsertToolCall, (state, action) => {
336+
// // if (action.payload.toolCallId !== state.thread.id && !(action.payload.chatId in state.cache)) return state;
337+
// if (action.payload.chatId === state.thread.id) {
338+
// maybeAppendToolCallResultFromIdeToMessages(
339+
// state.thread.messages,
340+
// action.payload.toolCallId,
341+
// action.payload.accepted,
342+
// );
343+
// } else if (action.payload.chatId in state.cache) {
344+
// const thread = state.cache[action.payload.chatId];
345+
// maybeAppendToolCallResultFromIdeToMessages(
346+
// thread.messages,
347+
// action.payload.toolCallId,
348+
// action.payload.accepted,
349+
// );
350+
// }
351+
// });
359352
});
360353

361-
export function maybeAppendToolCallResultFromIdeToMessages(
362-
messages: Draft<ChatMessages>,
363-
toolCallId: string,
364-
accepted: boolean | "indeterminate",
365-
) {
366-
const hasDiff = messages.find(
367-
(d) => isDiffMessage(d) && d.tool_call_id === toolCallId,
368-
);
369-
if (hasDiff) return;
370-
371-
const message = messageForToolCall(accepted);
372-
373-
const hasToolCall = messages.find(
374-
(d) => isToolMessage(d) && d.content.tool_call_id === toolCallId,
375-
);
376-
377-
if (
378-
hasToolCall &&
379-
isToolMessage(hasToolCall) &&
380-
typeof hasToolCall.content.content === "string"
381-
) {
382-
hasToolCall.content.content = message;
383-
return;
384-
} else if (
385-
hasToolCall &&
386-
isToolMessage(hasToolCall) &&
387-
isMultiModalToolResult(hasToolCall.content)
388-
) {
389-
hasToolCall.content.content.push({ m_type: "text", m_content: message });
390-
return;
391-
}
392-
393-
const assistantMessageIndex = messages.findIndex((message) => {
394-
if (!isAssistantMessage(message)) return false;
395-
return message.tool_calls?.find((toolCall) => toolCall.id === toolCallId);
396-
});
397-
398-
if (assistantMessageIndex === -1) return;
399-
const toolMessage: ToolMessage = {
400-
role: "tool",
401-
content: {
402-
content: message,
403-
tool_call_id: toolCallId,
404-
},
405-
};
406-
407-
messages.splice(assistantMessageIndex + 1, 0, toolMessage);
408-
}
409-
410-
function messageForToolCall(accepted: boolean | "indeterminate") {
411-
if (accepted === false) return "The user rejected the changes.";
412-
if (accepted === true) return "The user accepted the changes.";
413-
return "The user may have made modifications to changes.";
414-
}
354+
// export function maybeAppendToolCallResultFromIdeToMessages(
355+
// messages: Draft<ChatMessages>,
356+
// toolCallId: string,
357+
// accepted: boolean | "indeterminate",
358+
// ) {
359+
// const hasDiff = messages.find(
360+
// (d) => isDiffMessage(d) && d.tool_call_id === toolCallId,
361+
// );
362+
// if (hasDiff) return;
363+
364+
// const message = messageForToolCall(accepted);
365+
366+
// const hasToolCall = messages.find(
367+
// (d) => isToolMessage(d) && d.content.tool_call_id === toolCallId,
368+
// );
369+
370+
// if (
371+
// hasToolCall &&
372+
// isToolMessage(hasToolCall) &&
373+
// typeof hasToolCall.content.content === "string"
374+
// ) {
375+
// hasToolCall.content.content = message;
376+
// return;
377+
// } else if (
378+
// hasToolCall &&
379+
// isToolMessage(hasToolCall) &&
380+
// isMultiModalToolResult(hasToolCall.content)
381+
// ) {
382+
// hasToolCall.content.content.push({ m_type: "text", m_content: message });
383+
// return;
384+
// }
385+
386+
// const assistantMessageIndex = messages.findIndex((message) => {
387+
// if (!isAssistantMessage(message)) return false;
388+
// return message.tool_calls?.find((toolCall) => toolCall.id === toolCallId);
389+
// });
390+
391+
// if (assistantMessageIndex === -1) return;
392+
// const toolMessage: ToolMessage = {
393+
// role: "tool",
394+
// content: {
395+
// content: message,
396+
// tool_call_id: toolCallId,
397+
// },
398+
// };
399+
400+
// messages.splice(assistantMessageIndex + 1, 0, toolMessage);
401+
// }
402+
403+
// function messageForToolCall(accepted: boolean | "indeterminate") {
404+
// if (accepted === false) return "The user rejected the changes.";
405+
// if (accepted === true) return "The user accepted the changes.";
406+
// return "The user may have made modifications to changes.";
407+
// }

refact-agent/gui/src/features/History/historySlice.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
chatGenerateTitleThunk,
1010
ChatThread,
1111
doneStreaming,
12-
maybeAppendToolCallResultFromIdeToMessages,
1312
removeChatFromCache,
1413
restoreChat,
1514
setChatMode,
@@ -20,7 +19,6 @@ import {
2019
isUserMessage,
2120
} from "../../services/refact";
2221
import { AppDispatch, RootState } from "../../app/store";
23-
import { ideToolCallResponse } from "../../hooks/useEventBusForIDE";
2422

2523
export type ChatHistoryItem = ChatThread & {
2624
createdAt: string;
@@ -144,17 +142,17 @@ export const historySlice = createSlice({
144142
return {};
145143
},
146144

147-
upsertToolCallIntoHistory: (
148-
state,
149-
action: PayloadAction<Parameters<typeof ideToolCallResponse>[0]>,
150-
) => {
151-
if (!(action.payload.chatId in state)) return;
152-
maybeAppendToolCallResultFromIdeToMessages(
153-
state[action.payload.chatId].messages,
154-
action.payload.toolCallId,
155-
action.payload.accepted,
156-
);
157-
},
145+
// upsertToolCallIntoHistory: (
146+
// state,
147+
// action: PayloadAction<Parameters<typeof ideToolCallResponse>[0]>,
148+
// ) => {
149+
// if (!(action.payload.chatId in state)) return;
150+
// maybeAppendToolCallResultFromIdeToMessages(
151+
// state[action.payload.chatId].messages,
152+
// action.payload.toolCallId,
153+
// action.payload.accepted,
154+
// );
155+
// },
158156
},
159157
selectors: {
160158
getChatById: (state, id: string): ChatHistoryItem | null => {
@@ -177,7 +175,6 @@ export const {
177175
setTitleGenerationCompletionForChat,
178176
updateChatTitleById,
179177
clearHistory,
180-
upsertToolCallIntoHistory,
181178
} = historySlice.actions;
182179
export const { getChatById, getHistory } = historySlice.selectors;
183180

refact-agent/gui/src/hooks/useSendChatRequest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export const useSendChatRequest = () => {
307307
);
308308

309309
const confirmToolUsage = useCallback(() => {
310+
// of either way it aborts, shouldn't it just abort before asking?
310311
abort();
311312
dispatch(
312313
clearPauseReasonsAndHandleToolsStatus({
@@ -375,6 +376,7 @@ export function useAutoSend() {
375376
!preventSend
376377
) {
377378
const lastMessage = currentMessages.slice(-1)[0];
379+
// here ish
378380
if (
379381
isAssistantMessage(lastMessage) &&
380382
lastMessage.tool_calls &&

0 commit comments

Comments
 (0)