6 Commits

  • feat: passthrough upstream response headers to clients
    CPA previously stripped ALL response headers from upstream AI provider
    APIs, preventing clients from seeing rate-limit info, request IDs,
    server-timing and other useful headers.
    
    Changes:
    - Add Headers field to Response and StreamResult structs
    - Add FilterUpstreamHeaders helper (hop-by-hop + security denylist)
    - Add WriteUpstreamHeaders helper (respects CPA-set headers)
    - ExecuteWithAuthManager/ExecuteCountWithAuthManager now return headers
    - ExecuteStreamWithAuthManager returns headers from initial connection
    - All 11 provider executors populate Response.Headers
    - All handler call sites write filtered upstream headers before response
    
    Filtered headers (not forwarded):
    - RFC 7230 hop-by-hop: Connection, Transfer-Encoding, Keep-Alive, etc.
    - Security: Set-Cookie
    - CPA-managed: Content-Length, Content-Encoding
  • fix(logging): capture streaming TTFB on first chunk and make timestamps required
    - Add firstChunkTimestamp field to ResponseWriterWrapper for sync capture
    - Capture TTFB in Write() and WriteString() before async channel send
    - Add SetFirstChunkTimestamp() to StreamingLogWriter interface
    - Make requestTimestamp/apiResponseTimestamp required in LogRequest()
    - Remove timestamp capture from WriteAPIResponse() (now via setter)
    - Fix Gemini handler to set API_RESPONSE_TIMESTAMP before writing response
    
    This ensures accurate TTFB measurement for all streaming API formats
    (OpenAI, Gemini, Claude) by capturing timestamp synchronously when
    the first response chunk arrives, not when the stream finalizes.
  • fix(logging): add API response timestamp and fix request timestamp timing
    Previously:
    - REQUEST INFO timestamp was captured at log write time (not request arrival)
    - API RESPONSE had NO timestamp at all
    
    This fix:
    - Captures REQUEST INFO timestamp when request first arrives
    - Adds API RESPONSE timestamp when upstream response arrives
    
    Changes:
    - Add Timestamp field to RequestInfo, set at middleware initialization
    - Set API_RESPONSE_TIMESTAMP in appendAPIResponse() and gemini handler
    - Pass timestamps through logging chain to writeNonStreamingLog()
    - Add timestamp output to API RESPONSE section
    
    This enables accurate measurement of backend response latency in error logs.
  • refactor(config): migrate to SDKConfig and streamline proxy handling
    - Replaced `config.Config` with `config.SDKConfig` across components for simpler configuration management.
    - Updated proxy setup functions and handlers to align with `SDKConfig` improvements.
    - Reorganized handler imports to match new SDK structure.