Skip to content
Draft
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
663 changes: 533 additions & 130 deletions refact-agent/gui/generated/documents.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions refact-agent/gui/generated/graphql/gql.ts

Large diffs are not rendered by default.

566 changes: 463 additions & 103 deletions refact-agent/gui/generated/graphql/graphql.ts

Large diffs are not rendered by default.

350 changes: 283 additions & 67 deletions refact-agent/gui/generated/schema.graphql

Large diffs are not rendered by default.

40 changes: 9 additions & 31 deletions refact-agent/gui/src/app/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ import { isToolMessage, modelsApi, providersApi } from "../services/refact";
import {
receiveThread,
receiveThreadMessages,
selectLastMessageForAlt,
selectMessageByToolCallId,
selectToolConfirmationRequests,
threadMessagesSlice,
} from "../features/ThreadMessages";
import {
graphqlQueriesAndMutations,
rejectToolUsageAction,
} from "../services/graphql";
import { graphqlQueriesAndMutations } from "../services/graphql";
import { push } from "../features/Pages/pagesSlice";
import { setExpert, setModel } from "../features/ExpertsAndModels/expertsSlice";
import { setBallanceInformation } from "../features/Errors/informationSlice";
Expand Down Expand Up @@ -368,7 +363,6 @@ startListening({
});

// TODO: this should let flexus know that the user accepted the tool
// Tool Call results from ide.
startListening({
actionCreator: ideToolCallResponse,
effect: (action, listenerApi) => {
Expand All @@ -384,30 +378,14 @@ startListening({
);
if (!maybePendingToolCall) return;

if (action.payload.accepted) {
const thunk =
graphqlQueriesAndMutations.endpoints.toolConfirmation.initiate({
ft_id: action.payload.chatId,
confirmation_response: JSON.stringify([action.payload.toolCallId]),
});
void listenerApi.dispatch(thunk);
return;
}

// rejection creates a new message at the end of the thread
// find the parent, then find the end point
const message = selectMessageByToolCallId(state, action.payload.toolCallId);
if (!message) return;
const lastMessage = selectLastMessageForAlt(state, message.ftm_alt);
if (!lastMessage) return;
const rejectAction = rejectToolUsageAction(
[action.payload.toolCallId],
action.payload.chatId,
lastMessage.ftm_num,
lastMessage.ftm_alt,
lastMessage.ftm_prev_alt,
);
void listenerApi.dispatch(rejectAction);
const thunk =
graphqlQueriesAndMutations.endpoints.toolConfirmation.initiate({
ft_id: action.payload.chatId,
fcall_id: action.payload.toolCallId,
positive: action.payload.accepted,
});
void listenerApi.dispatch(thunk);
return;
},
});

Expand Down
36 changes: 18 additions & 18 deletions refact-agent/gui/src/components/ChatForm/ChatControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ import {

import {
selectPatchIsAutomatic,
selectThreadId,
selectToolConfirmationResponses,
// selectThreadId,
// selectToolConfirmationResponses,
} from "../../features/ThreadMessages";
import { useAppSelector } from "../../hooks";
import { useAttachedFiles } from "./useCheckBoxes";
import { graphqlQueriesAndMutations } from "../../services/graphql";
// import { graphqlQueriesAndMutations } from "../../services/graphql";

export const ApplyPatchSwitch: React.FC = () => {
const chatId = useAppSelector(selectThreadId);
// const chatId = useAppSelector(selectThreadId);
const isPatchAutomatic = useAppSelector(selectPatchIsAutomatic);
const toolConfirmationResponses = useAppSelector(
selectToolConfirmationResponses,
);
const [toolConfirmation, _toolConfirmationResult] =
graphqlQueriesAndMutations.useToolConfirmationMutation();

const handleAutomaticPatchChange = (checked: boolean) => {
const value = checked
? toolConfirmationResponses.filter((res) => res !== "*")
: [...toolConfirmationResponses, "*"];
// const toolConfirmationResponses = useAppSelector(
// selectToolConfirmationResponses,
// );
// const [toolConfirmation, _toolConfirmationResult] =
// graphqlQueriesAndMutations.useToolConfirmationMutation();

void toolConfirmation({
ft_id: chatId,
confirmation_response: JSON.stringify(value),
});
const handleAutomaticPatchChange = (_checked: boolean) => {
// TODO: enable tools
// const value = checked
// ? toolConfirmationResponses.filter((res) => res !== "*")
// : [...toolConfirmationResponses, "*"];
// void toolConfirmation({
// ft_id: chatId,
// confirmation_response: JSON.stringify(value),
// });
};

return (
Expand Down
60 changes: 21 additions & 39 deletions refact-agent/gui/src/components/ChatForm/ToolConfirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React, { useCallback, useMemo } from "react";
import {
useAppDispatch,
useAppSelector,
// useSendChatRequest,
// useEventsBusForIDE
} from "../../hooks";
import { useAppSelector } from "../../hooks";
import { Card, Button, Text, Flex } from "@radix-ui/themes";
import { Markdown } from "../Markdown";
import styles from "./ToolConfirmation.module.css";
Expand All @@ -22,29 +17,27 @@ const PATCH_LIKE_FUNCTIONS = [
import {
selectThreadMessages,
selectThreadMeta,
selectThreadEnd,
ToolConfirmationRequest,
} from "../../features/ThreadMessages";
import {
graphqlQueriesAndMutations,
rejectToolUsageAction,
} from "../../services/graphql";
import { graphqlQueriesAndMutations } from "../../services/graphql";
import { parseOrElse } from "../../utils/parseOrElse";

function useToolConfirmation() {
const dispatch = useAppDispatch();
const threadMeta = useAppSelector(selectThreadMeta);
const threadEnd = useAppSelector(selectThreadEnd);
const [toolConfirmation, _toolConfirmationResult] =
graphqlQueriesAndMutations.useToolConfirmationMutation();

const confirmToolUsage = useCallback(
(ids: string[]) => {
if (!threadMeta?.ft_id) return;
void toolConfirmation({
ft_id: threadMeta.ft_id,
confirmation_response: JSON.stringify(ids),
});
const requests = ids.map((id) =>
toolConfirmation({
ft_id: threadMeta.ft_id,
fcall_id: id,
positive: true,
}),
);
void Promise.all(requests);
},
[threadMeta?.ft_id, toolConfirmation],
);
Expand All @@ -53,32 +46,22 @@ function useToolConfirmation() {
(ids: string[]) => {
// TODO: find the message with the tool call
if (!threadMeta?.ft_id) return;
const action = rejectToolUsageAction(
ids,
threadMeta.ft_id,
threadEnd.endNumber,
threadEnd.endAlt,
threadEnd.endPrevAlt,
const requests = ids.map((id) =>
toolConfirmation({
ft_id: threadMeta.ft_id,
fcall_id: id,
positive: false,
}),
);
void dispatch(action);
void Promise.all(requests);
},
[
dispatch,
threadEnd.endAlt,
threadEnd.endNumber,
threadEnd.endPrevAlt,
threadMeta?.ft_id,
],
[threadMeta?.ft_id, toolConfirmation],
);

// TBD: how to allow all ?
const allowAll = useCallback(() => {
if (!threadMeta?.ft_id) return;

void toolConfirmation({
ft_id: threadMeta.ft_id,
confirmation_response: JSON.stringify(["*"]),
});
}, [threadMeta?.ft_id, toolConfirmation]);
confirmToolUsage(["*"]);
}, [confirmToolUsage]);

return { confirmToolUsage, rejectToolUsage, allowAll };
}
Expand Down Expand Up @@ -120,7 +103,6 @@ const getConfirmationMessage = (
}
};

// here
export const ToolConfirmation: React.FC<ToolConfirmationProps> = ({
toolConfirmationRequests,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion refact-agent/gui/src/components/Toolbar/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
<DropdownMenu.Label>
<Flex align="center" gap="1">
{/**TODO: there could be multiple source for this */}
{coinBallance / 100000} <Coin />
{coinBallance / 1000000} <Coin />
<HoverCard.Root>
<HoverCard.Trigger>
<QuestionMarkCircledIcon style={{ marginLeft: 4 }} />
Expand Down
53 changes: 30 additions & 23 deletions refact-agent/gui/src/features/ThreadMessages/threadMessagesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,51 +424,58 @@ export const threadMessagesSlice = createSlice({
},
),

// TODO: fix this once the lsp is working again :/
selectToolConfirmationRequests: (state) => {
if (!state.thread) return [];
if (
Array.isArray(state.thread.ft_confirmation_response) &&
state.thread.ft_confirmation_response.includes("*")
) {
return [];
}
// if (
// Array.isArray(state.thread.ft_confirmation_response) &&
// state.thread.ft_confirmation_response.includes("*")
// ) {
// return [];
// }
const messages = Object.values(state.messages);
if (messages.length === 0) return [];
if (!state.thread.ft_confirmation_request) return [];
if (!Array.isArray(state.thread.ft_confirmation_request)) return [];
const responses = Array.isArray(state.thread.ft_confirmation_response)
? state.thread.ft_confirmation_response
: [];
// const responses = Array.isArray(state.thread.ft_confirmation_response)
// ? state.thread.ft_confirmation_response
// : [];
const toolRequests = state.thread.ft_confirmation_request.filter(
isToolConfirmationRequest,
);

const messageIds = messages.map((message) => message.ftm_call_id);
// const unresolved = toolRequests.filter(
// (req) =>
// !responses.includes(req.tool_call_id) &&
// !messageIds.includes(req.tool_call_id),
// );
const unresolved = toolRequests.filter(
(req) =>
!responses.includes(req.tool_call_id) &&
!messageIds.includes(req.tool_call_id),
(req) => !messageIds.includes(req.tool_call_id),
);

return unresolved;
},

selectToolConfirmationResponses: (state) => {
if (!state.thread) return [];
if (!Array.isArray(state.thread.ft_confirmation_response)) {
return [];
}

return state.thread.ft_confirmation_response.filter(
(s) => typeof s === "string",
);
return [];
// if (!Array.isArray(state.thread.ft_confirmation_response)) {
// return [];
// }

// return state.thread.ft_confirmation_response.filter(
// (s) => typeof s === "string",
// );
},
// TODO: figure this out
selectPatchIsAutomatic: (state) => {
if (!state.thread) return false;
return (
Array.isArray(state.thread.ft_confirmation_response) &&
state.thread.ft_confirmation_response.includes("*")
);
return false;
// return (
// Array.isArray(state.thread.ft_confirmation_response) &&
// state.thread.ft_confirmation_response.includes("*")
// );
},
selectMessageByToolCallId: createSelector(
[selectMessagesValues, (_messages, id: string) => id],
Expand Down
2 changes: 1 addition & 1 deletion refact-agent/gui/src/hooks/useEventBusForIDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ideToolCall = createAction<{
export const ideToolCallResponse = createAction<{
toolCallId: string;
chatId: string;
accepted: boolean | "indeterminate";
accepted: boolean;
}>("ide/toolEditResponse");

export const ideForceReloadProjectTreeFiles = createAction(
Expand Down
29 changes: 0 additions & 29 deletions refact-agent/gui/src/services/graphql/actions.ts

This file was deleted.

14 changes: 8 additions & 6 deletions refact-agent/gui/src/services/graphql/flexus.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ subscription MessagesSubscription($ft_id: String!, $want_deltas: Boolean!) {
ft_need_assistant
ft_fexp_id ## contain the expert id
ft_confirmation_request
ft_confirmation_response
# ft_confirmation_response
ft_title
ft_toolset
## ft_need_tool_calls ## This might be useful for tool confirmation?
Expand Down Expand Up @@ -115,13 +115,15 @@ query ToolsForGroup($located_fgroup_id: String!) {
}
}

mutation ThreadConfirmationResponse(
$confirmation_response: String = ""
$ft_id: String = ""
mutation ThreadConfirmationResolve(
$fcall_id: String!
$ft_id: String!
$positive: Boolean!
) {
thread_set_confirmation_response(
thread_confirmation_resolve(
fcall_id: $fcall_id
ft_id: $ft_id
confirmation_response: $confirmation_response
positive: $positive
)
}

Expand Down
1 change: 0 additions & 1 deletion refact-agent/gui/src/services/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./queriesAndMutationsApi";
export * from "./subscriptions";
export * from "./actions";
Loading