MCPcopy Index your code
hub / github.com/coder/coder / updateChatPlanMode

Function updateChatPlanMode

site/src/api/queries/chats.ts:769–825  ·  view source on GitHub ↗
(queryClient: QueryClient)

Source from the content-addressed store, hash-verified

767});
768
769export const updateChatPlanMode = (queryClient: QueryClient) => ({
770 mutationFn: ({ chatId, planMode }: UpdateChatPlanModeVariables) =>
771 API.experimental.updateChat(chatId, {
772 plan_mode: toChatPlanModePayload(planMode),
773 }),
774 onMutate: async ({ chatId, planMode }: UpdateChatPlanModeVariables) => {
775 await queryClient.cancelQueries({
776 queryKey: chatsKey,
777 predicate: isChatListQuery,
778 });
779 await queryClient.cancelQueries({
780 queryKey: chatKey(chatId),
781 exact: true,
782 });
783 const previousChat = queryClient.getQueryData<TypesGen.Chat>(
784 chatKey(chatId),
785 );
786 updateInfiniteChatsCache(queryClient, (chats) =>
787 chats.map((chat) =>
788 chat.id === chatId ? { ...chat, plan_mode: planMode } : chat,
789 ),
790 );
791 if (previousChat) {
792 queryClient.setQueryData<TypesGen.Chat>(chatKey(chatId), {
793 ...previousChat,
794 plan_mode: planMode,
795 });
796 }
797 return { previousChat };
798 },
799 onError: (
800 _error: unknown,
801 { chatId }: UpdateChatPlanModeVariables,
802 context:
803 | {
804 previousChat?: TypesGen.Chat;
805 }
806 | undefined,
807 ) => {
808 void invalidateChatListQueries(queryClient);
809 const previousChat = context?.previousChat;
810 if (!previousChat) {
811 return;
812 }
813 updateInfiniteChatsCache(queryClient, (chats) =>
814 chats.map((chat) =>
815 chat.id === chatId
816 ? {
817 ...chat,
818 plan_mode: previousChat.plan_mode,
819 }
820 : chat,
821 ),
822 );
823 queryClient.setQueryData<TypesGen.Chat>(chatKey(chatId), previousChat);
824 },
825});
826

Callers 2

AgentChatPageFunction · 0.90
chats.test.tsFile · 0.90

Calls 4

toChatPlanModePayloadFunction · 0.85
chatKeyFunction · 0.85
updateInfiniteChatsCacheFunction · 0.85

Tested by

no test coverage detected