Might be a slightly questionable refactor... so writing out some thoughts here.
high-level changes:
specs are responsible for job creation
it was awkward that the user can mess with the curl args function and sse data handler... but they weren't expected to mess with the "event state logic" even though this is inherently quite coupled with the model spec anyways.
there's basically no point of allowing the user to "configure" something behind the black box. By the time they are messing with curl args and what not, they already have to have to already have your code cloned/forked tbh.
job stdout handler is reponsible for sse parsing + state management (anthropic)
there aren't an endless number of model providers... yet. But the sse parser logic is basically dictated by the model provider. Now that specs are responsible for making the jobs too, I can also leave it up to the model spec to manage event state if needed or do something special with the events (or in OpenAI spec... there's no state to manage)
move writer into utils
felt weird for "the thing that writes into my buffer" to be in a job... but it's also weird that it's grouped together with the logic that's grabbing the visual selection. only the "jobs" are doing the writing, so it feels right to place it somewhere closer to the model specs
roll up get_prompt into get_visual_selection - it was kind of redundant anyways
At the end of all these changes, most of the complex stuff is now sitting in model specs whereas the top-level module is just holding the stuff that's closest to neovim (i.e. key bindings, get visual selection, start job, cancel job, etc.)
some earlier changes were around simplifying get_visual_selection to just do the swap upfront to cut down any confusion and remove replace because it's only a few vim keys away anyways.
Might be a slightly questionable refactor... so writing out some thoughts here.
high-level changes:
get_prompt
intoget_visual_selection
- it was kind of redundant anywaysAt the end of all these changes, most of the complex stuff is now sitting in model specs whereas the top-level module is just holding the stuff that's closest to neovim (i.e. key bindings, get visual selection, start job, cancel job, etc.)
some earlier changes were around simplifying
get_visual_selection
to just do the swap upfront to cut down any confusion and remove replace because it's only a few vim keys away anyways.