fix: issue of prompt enhancer not working in prod mode #1499
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.
For issue #1448, this is my PR.
Issue Found:
The enhanced prompt was working in development mode because Node.js can handle a text stream. However, in production (Cloudflare Workers environment), it was failing.
Main Error:
The error "This ReadableStream did not return bytes" occurred because Cloudflare Workers expect a byte-based ReadableStream (e.g., Uint8Array). If _streamText (in stream-text.ts) returns a text-based stream or a different format, it fails in workerd.
Solution:
I updated api.enhancer.ts by implementing returnStream, which creates a new byte-based ReadableStream and returns it as the API response. I tested this fix in production mode, and it is now working correctly.
Thank you for reading!