File size: 1,144 Bytes
3d700dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { useMutation } from "@tanstack/react-query";
import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";
import { getErrorStatus } from "#/hooks/query/use-settings";
import { displayErrorToast } from "#/utils/custom-toast-handlers";
import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message";
interface UseReadConversationFileVariables {
conversationId: string;
filePath?: string;
}
export const useReadConversationFile = () =>
useMutation({
mutationKey: ["read-conversation-file"],
// A 404 (no plan yet) is expected and must stay silent; `onError` below
// re-shows the toast for anything else so real failures still surface.
meta: { disableToast: true },
mutationFn: async ({
conversationId,
filePath,
}: UseReadConversationFileVariables): Promise<string> =>
AgentServerConversationService.readConversationFile(
conversationId,
filePath,
),
onError: (error) => {
if (getErrorStatus(error) === 404) return;
displayErrorToast(retrieveAxiosErrorMessage(error));
},
});
|