({
task,
workspace,
open,
onOpenChange,
})
| 28 | }; |
| 29 | |
| 30 | export const ModifyPromptDialog: FC<ModifyPromptDialogProps> = ({ |
| 31 | task, |
| 32 | workspace, |
| 33 | open, |
| 34 | onOpenChange, |
| 35 | }) => { |
| 36 | const formId = useId(); |
| 37 | const formik = useFormik({ |
| 38 | initialValues: { |
| 39 | prompt: task.initial_prompt, |
| 40 | }, |
| 41 | onSubmit: (values) => { |
| 42 | updatePromptMutation.mutate(values.prompt); |
| 43 | }, |
| 44 | }); |
| 45 | |
| 46 | const queryClient = useQueryClient(); |
| 47 | |
| 48 | const buildParametersQuery = useQuery( |
| 49 | workspaceBuildParameters(workspace.latest_build.id), |
| 50 | ); |
| 51 | |
| 52 | const updatePromptMutation = useMutation({ |
| 53 | mutationFn: async (prompt: string) => { |
| 54 | const currentBuild = await API.getWorkspaceBuildByNumber( |
| 55 | workspace.owner_name, |
| 56 | workspace.name, |
| 57 | workspace.latest_build.build_number, |
| 58 | ); |
| 59 | |
| 60 | if (currentBuild.status !== "stopped") { |
| 61 | if (!currentBuild.job.completed_at) { |
| 62 | await API.cancelWorkspaceBuild(currentBuild.id); |
| 63 | await API.waitForBuild(currentBuild); |
| 64 | } |
| 65 | |
| 66 | const stopBuild = await API.stopWorkspace(workspace.id); |
| 67 | await API.waitForBuild(stopBuild); |
| 68 | } |
| 69 | |
| 70 | await API.updateTaskInput(task.owner_name, task.id, prompt); |
| 71 | await API.startWorkspace( |
| 72 | workspace.id, |
| 73 | task.template_version_id, |
| 74 | undefined, |
| 75 | buildParametersQuery.data, |
| 76 | ); |
| 77 | }, |
| 78 | onSuccess: () => { |
| 79 | queryClient.invalidateQueries({ |
| 80 | queryKey: ["tasks", task.owner_name, task.id], |
| 81 | }); |
| 82 | queryClient.invalidateQueries({ |
| 83 | queryKey: workspaceByOwnerAndNameKey( |
| 84 | workspace.owner_name, |
| 85 | workspace.name, |
| 86 | ), |
| 87 | }); |
nothing calls this directly
no test coverage detected