You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Want to stream function responses. Use case: stream chat completions from AI provider.
Describe the solution you'd like
Would love to augment the FunctionsClient to be able to stream data from a function response. Rough example of solution:
/// Implement the StreamResponseHandler protocol to handle the streamed data./// You could append received data chunks to a buffer, process data as it arrives, /// or update the UI (updates would be dispatched on the main thread).protocolStreamResponseHandler{func didReceive(data:Data)func didCompleteWithError(_ error:Error?)}classStreamDataTaskHandler:NSObject,URLSessionDataDelegate{letstreamHandler:StreamResponseHandlerinit(streamHandler:StreamResponseHandler){self.streamHandler = streamHandler
}func urlSession(_ session:URLSession, dataTask:URLSessionDataTask, didReceive data:Data){// Forward the received data to the stream handler
streamHandler.didReceive(data: data)}func urlSession(_ session:URLSession, task:URLSessionTask, didCompleteWithError error:Error?){// Notify the stream handler about completion or error
streamHandler.didCompleteWithError(error)}}extensionFunctionsClient{publicfunc invokeWithStream(
_ functionName:String,
options:FunctionInvokeOptions=.init(),
streamHandler:StreamResponseHandler)asyncthrows{// Setup URLSession with StreamDataTaskHandler as delegateletdelegate=StreamDataTaskHandler(streamHandler: streamHandler)letsession=URLSession(configuration:.default, delegate: delegate, delegateQueue:nil)// Rest of the setup similar to `rawInvoke`, but use the session with delegateleturl=self.url.appendingPathComponent(functionName)varurlRequest=URLRequest(url: url)
urlRequest.allHTTPHeaderFields = options.headers.merging(headers){ invoke, _ in invoke }
urlRequest.httpMethod =(options.method ??.post).rawValue
urlRequest.httpBody = options.body
// Start the data tasklettask= session.dataTask(with: urlRequest)
task.resume()// Ensure to keep the session and delegate alive as long as needed// This may require storing references in the FunctionsClient or managing lifecycle appropriately}}
Describe alternatives you've considered
Make the request to the function outside of supabase-swift.
Additional context
Open to alternatives, especially if this is somehow already supported and I missed it.
The text was updated successfully, but these errors were encountered:
Feature request
Is your feature request related to a problem? Please describe.
Want to stream function responses. Use case: stream chat completions from AI provider.
Describe the solution you'd like
Would love to augment the
FunctionsClient
to be able to stream data from a function response. Rough example of solution:Describe alternatives you've considered
Make the request to the function outside of supabase-swift.
Additional context
Open to alternatives, especially if this is somehow already supported and I missed it.
The text was updated successfully, but these errors were encountered: