-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.ts
More file actions
40 lines (35 loc) · 1.05 KB
/
api.ts
File metadata and controls
40 lines (35 loc) · 1.05 KB
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
32
33
34
35
36
37
38
39
40
import { useMutation, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { ApiErrorData } from '@open-webui-react-native/shared/data-access/api-client';
import { Chat, patchChatQueryData } from '../chats';
import { StopTaskResponse } from './models';
import { tasksService } from './service';
type StopTaskArgs = {
taskId: string;
chatId: string;
lastMessageId: string;
};
function useStopTask(
props?: UseMutationOptions<StopTaskResponse, AxiosError<ApiErrorData>, StopTaskArgs>,
): UseMutationResult<StopTaskResponse, AxiosError<ApiErrorData>, StopTaskArgs> {
return useMutation({
mutationFn: ({ taskId }) => tasksService.stopTask(taskId),
onSuccess: (_, { chatId, lastMessageId }) => {
patchChatQueryData(chatId, {
chat: {
history: {
messages: {
[lastMessageId]: {
done: true,
},
},
},
} as Chat,
});
},
...props,
});
}
export const tasksApi = {
useStopTask,
};