-
Notifications
You must be signed in to change notification settings - Fork 146
Description
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is this a client library issue or a product issue? We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the Support page to reach the most relevant engineers.
If the support paths suggested above still do not result in a resolution, please provide the following details.
Environment details
- Programming language: JavaScript / TypeScript / Node.js
- OS: MacOS
- Language runtime version:
- Package version: ^1.19.0
Steps to reproduce
Note: I see possibility to occur in enterprise in case we have some custom handling of SSE event and data in between GCP and our service like gateway.
- If the stream response includes leading whitespace — for example:
'\n\ndata: {"candidates": [{"content": {"role": "model","parts": [{"text": "Sheldon"}]}}],"usageMetadata": {"trafficType": "ON_DEMAND"},"modelVersion": "gemini-2.0-flash","createTime": "2025-09-14T13:18:29.993482Z","responseId": "pcDGaMrRPIKrnvgP-_WisAs"}\n\n'
— then the condition in this section of the js-genai client evaluates to null, which leads to the error: Incomplete JSON segment at the end.
The regex here:
Line 28 in 3e850fd
const responseLineRE = /^data: (.*)(?:\n\n|\r\r|\r\n\r\n)/; |
Allowing leading whitespace like following is fixing the stream generate content issue:
const responseLineRE = /^\s*data: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!