WIP: Allow streaming from custom http endpoints #1219
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'd appreciate input on these changes. My goal is to have the ai plug be able to proxy all requests (optionally, configured per model) through the server, regardless of whether the client is in sync mode or not.
You can see the plug changes here: https://github.com/justyns/silverbullet-ai/pull/77/files
After testing a few different methods, this seems to work but is also a little hacky. I wanted the plug proxyHandler() to handle all of the fetch logic, but I could not figure out how to return something like
ReadableStream
to serveCustomEndpoints(). I'm assuming the response from the plug gets serialized somewhere so we lose the stream. My workaround was to have the plug return the info needed to initiate a new fetch request from serveCustomEndpoints and then stream directly from it.This does work, but I'm not sure if we want to turn serveCustomEndpoints into a psuedo proxy like this? Is there a way for a plug to register an endpoint without using the event system?