• lynoot's avatar
    fix(gateway): aggregate all text chunks in non-streaming Gemini responses · 909b8a8f
    lynoot authored
    Previously, collectGeminiSSE() only returned the last chunk received
    from the upstream streaming response when converting to non-streaming.
    This caused incomplete responses where only the final text fragment
    was returned to clients.
    
    For example, a request asking to "count from 1 to 10" would only
    return "\n" (the last chunk) instead of "1\n2\n3\n...\n10\n".
    
    This was especially problematic for JSON structured output where
    the opening brace "{" from the first chunk was lost, resulting
    in invalid JSON like: colors": ["red", "blue"]}
    
    The fix:
    - Collect all text parts from each SSE chunk into a slice
    - Merge all collected text parts into the final response
    - Reuse the same pattern as handleGeminiStreamToNonStreaming
      in antigravity_gateway_service.go
    
    Fixes: non-streaming responses returning incomplete text
    Fixes: structured output (JSON schema) returning invalid JSON
    909b8a8f
gemini_messages_compat_service.go 88.3 KB