Spaces:
Configuration error
Configuration error
Download frontend/src/hooks/mutation/use-create-conversation.ts from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/hooks/mutation/use-create-conversation.ts
- Command line
-
hf download hf://spaces/flyingdarkdev/README/frontend/src/hooks/mutation/use-create-conversation.ts
-
curl -L -o use-create-conversation.ts https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/frontend/src/hooks/mutation/use-create-conversation.ts
1.62 kB
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | |
| import { useNavigate } from "react-router"; | |
| import posthog from "posthog-js"; | |
| import { useDispatch, useSelector } from "react-redux"; | |
| import OpenHands from "#/api/open-hands"; | |
| import { setInitialPrompt } from "#/state/initial-query-slice"; | |
| import { RootState } from "#/store"; | |
| export const useCreateConversation = () => { | |
| const navigate = useNavigate(); | |
| const dispatch = useDispatch(); | |
| const queryClient = useQueryClient(); | |
| const { selectedRepository, files, replayJson } = useSelector( | |
| (state: RootState) => state.initialQuery, | |
| ); | |
| return useMutation({ | |
| mutationFn: async (variables: { q?: string }) => { | |
| if ( | |
| !variables.q?.trim() && | |
| !selectedRepository && | |
| files.length === 0 && | |
| !replayJson | |
| ) { | |
| throw new Error("No query provided"); | |
| } | |
| if (variables.q) dispatch(setInitialPrompt(variables.q)); | |
| return OpenHands.createConversation( | |
| selectedRepository || undefined, | |
| variables.q, | |
| files, | |
| replayJson || undefined, | |
| ); | |
| }, | |
| onSuccess: async ({ conversation_id: conversationId }, { q }) => { | |
| posthog.capture("initial_query_submitted", { | |
| entry_point: "task_form", | |
| query_character_length: q?.length, | |
| has_repository: !!selectedRepository, | |
| has_files: files.length > 0, | |
| has_replay_json: !!replayJson, | |
| }); | |
| await queryClient.invalidateQueries({ | |
| queryKey: ["user", "conversations"], | |
| }); | |
| navigate(`/conversations/${conversationId}`); | |
| }, | |
| }); | |
| }; | |