fix: invoke onRequest callback for streaming prediction requests#362
Open
fix: invoke onRequest callback for streaming prediction requests#362
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a customFetch wrapper in the Bot component to allow for request interception via an onRequest prop. A critical syntax error was identified in the fetchEventSource URL template literal, where extra quotes and a closing brace were accidentally included, which will lead to malformed request URLs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
The
onRequestcallback prop((request: RequestInit) => Promise<void>)is not called when sending streaming prediction requests.This breaks any consumer relying on it to inject auth headers, set
credentials: 'include', or mutate the request before it is sent.Root cause:
The streaming path in
fetchResponseFromEventStreamcallsfetchEventSourcefrom@microsoft/fetch-event-sourcedirectly, and never invokes onRequest. All other request paths (config fetch, stream availability check, non-streaming prediction, TTS) go through sendRequest() in src/utils/index.ts, which correctly calls onRequest(requestInfo) before each fetch().This means
GETrequests likegetChatbotConfigandisStreamAvailableQueryreceive injected headers/credentials, but the streamingPOSTto/api/v1/prediction/{chatflowid}does not — causing auth failures for users who authenticate via cookies or bearer tokens.Resolution
fetchEventSource accepts a fetch parameter (FetchEventSourceInit.fetch?: typeof fetch) that replaces its underlying fetch implementation. A customFetch wrapper is defined inside fetchResponseFromEventStream that:
This mirrors the existing pattern in sendRequest() and generateTTSQuery(), and requires no changes to any other file.