It's very simple. First reduce the requirements: ignore the melody. Then iterate through the inversions of a chord in closed position, and pick the one with the smallest "distance" from the previous chord.
Using that strategy, you can pick different chord voicing templates, like drop-2 or quartal. An even better method would be to move the "hands" up the keyboard after a tonic chord, that way you don't end up in the low registers too quickly, since jazz harmony tends to go down in 4ths a good bit.