-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Invoking Edge Functions Returning a server-sent events in client library. #67
Comments
@david-fischer Here is an javascript implementation sample that might help! |
Hello @dshukertjr, Definetly, implementing calling the edge-function and get the data as stream would be another possibility, that I did not explicitly state in my issue. Generally, this is something I would be very happy to avoid, as I basically have to duplicate logic from the SupabaseClient, introducing a further coupling to specifics in the API, authentication, etc... into our codebase. Is there any place, where Supabase users can upvote feature-requests to maybe influence your roadmap? I feel like specifically with chatGPT, this seems like a very common use-case that greatly improves the end-user experience! Thanks and kind regards, |
@david-fischer We don't really have a single source of truth for the community to upvote on feature requests, but I can pass the feedback to the functions team internally. |
Let me transfer this issue to js repo so that more people can see this and comment on it. |
I made a PR for this months ago here, it's two lines and enables SSE in the library: #74 @dshukertjr why wouldn't |
Thanks so much! @david-fischer in the meantime you should be able to get the same result outside of the client with minimal coupling by using the following pattern: const response = await fetch( FUNCTION_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': supabase.auth.headers.Authorization
},
body: JSON.stringify(body)
}) |
The recommended way of getting the user/client in edge functions const supabase = createClient(
Deno.env.get( 'SUPABASE_URL' ) ?? '',
Deno.env.get( 'SUPABASE_ANON_KEY' ) ?? '',
{
auth: { persistSession: false },
global: { headers: { Authorization: authorization }}
}
)
const { data: { user }} = supabase.auth.getUser() fails when using fetch in the way outlined in my above comment. It succeeds when using As a result, I'm currently having to fork and patch |
Any news about this? We would really appreciate to be able to get streams from our edge functions in flutter. |
@dshukertjr this library doesn't work on Thanks for all your good work! |
@soulofmischief I used code similar to yours now
Before I initialized it like this:
and use: but I am having the problem that when my app is open for some time, it seems that my JWT expires and when I trigger the Edge-Function again, I get Invalid JWT as a response. What do I have to do to make sure, that the auth.headers are renewed? |
@dshukertjr @laktek as the flutter_sse library does not work in And now I am running into error handling issues because of this, as the AutoreconnectHandler from This is really a mess. I am just starting to duplicate logic from the SupabaseClient just because there is no option to use streaming directly. I really like supabase but I really don't understand why this |
Yes, it's quite a cumbersome experience. As of now I'm just live-patching the module with yarn using the following patch: diff --git a/dist/main/FunctionsClient.js b/dist/main/FunctionsClient.js
index 834b25ee53b9a1a39560090bf77fe0a47e8d9563..c1dd7343456fd6c493bb37706b35577afb40d569 100644
--- a/dist/main/FunctionsClient.js
+++ b/dist/main/FunctionsClient.js
@@ -88,6 +88,9 @@ class FunctionsClient {
else if (responseType === 'application/octet-stream') {
data = yield response.blob();
}
+ else if (responseType === 'text/event-stream') {
+ data = response.body;
+ }
else if (responseType === 'multipart/form-data') {
data = yield response.formData();
}
diff --git a/dist/module/FunctionsClient.js b/dist/module/FunctionsClient.js
index 18f313203fafb581e46405312390496a7f7d8dd5..a9edf858a47a576c40213951217e08cafdbe5429 100644
--- a/dist/module/FunctionsClient.js
+++ b/dist/module/FunctionsClient.js
@@ -85,6 +85,9 @@ export class FunctionsClient {
else if (responseType === 'application/octet-stream') {
data = yield response.blob();
}
+ else if (responseType === 'text/event-stream') {
+ data = response.body;
+ }
else if (responseType === 'multipart/form-data') {
data = yield response.formData();
}
@dshukertjr @laktek Again this issue is solved in PR #74, in just two lines of code. It has been sitting open for almost 6 months now, please review and merge it. The lack of activity or triage in this repo is increasingly concerning, such basic functionality should not be neglected when the problem has been solved. |
@soulofmischief Sorry, I missed that PR. I merged it and will release it today or tomorrow to superbase-js. Thanks for the contribution. |
@soulofmischief This change should be included in |
@laktek will this also be merged into |
@dshukertjr can you handle the flutter change? |
PR for supabase-swift supabase/supabase-swift#346 |
@nietsmmar For the Flutter library, let's use this issue to track it. supabase/supabase-flutter#894 |
Is your feature request related to a problem? Please describe.
Yes. Currently, there seems to be no possibility to invoke an Edge Function that returns a server-sent events using the client library.
Describe the solution you'd like
I would like to see the implementation of an additional function, which could return a
Stream
of server-sent events instead of standard promise.Describe alternatives you've considered
One alternative I considered was to simply await the full result. However, this would leave the user waiting for a long period, which is not an ideal user experience.
Additional context
The motivation is a project, where we are looking to implement a ChatGPT interface within our Flutter application, and we need to stream the response of the API call to OpenAI to the user in real-time.
Implementing this functionality on the backend as an Edge Function was straightforward enough - I followed the tutorial on Streaming Data in Edge Functions by Supabase (https://www.youtube.com/watch?v=9N66JBRLNYU).
The text was updated successfully, but these errors were encountered: