fix(antigravity-auth): address Oracle feedback - custom credentials, logging, docs

- Fix custom credentials to actually work in OAuth/refresh flows
  - oauth.ts: Add clientId/clientSecret parameters to buildAuthURL(), exchangeCode()
  - token.ts: Add clientId/clientSecret parameters to refreshAccessToken()
  - fetch.ts: Pass credentials to oauth/token functions
  - plugin.ts: Use closure cache for credentials, pass to all flows

- Unify console.* logging policy with ANTIGRAVITY_DEBUG guards
  - constants.ts: Document logging policy
  - tools.ts: Guard console.warn with ANTIGRAVITY_DEBUG
  - plugin.ts: Guard 4 console.error with ANTIGRAVITY_DEBUG

- Add explicit init.body type handling
  - fetch.ts: Check body type, pass-through non-string bodies
  - fetch.ts: Document body type assumption

- Document SSE buffering behavior
  - response.ts: Add warning that current implementation buffers
  - response.ts: Add TODO for future ReadableStream enhancement

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-12 23:24:20 +09:00
parent 4b3b581901
commit d450c4f966
8 changed files with 137 additions and 79 deletions

View File

@@ -4,7 +4,7 @@
*
* Key responsibilities:
* - Non-streaming response transformation
* - SSE streaming response transformation (preserving stream)
* - SSE streaming response transformation (buffered - see transformStreamingResponse)
* - Error response handling with retry-after extraction
* - Usage metadata extraction from x-antigravity-* headers
*/
@@ -340,19 +340,29 @@ export function transformStreamingPayload(payload: string): string {
}
/**
* Transform a streaming SSE response
* Transforms a streaming SSE response from Antigravity to OpenAI format.
*
* For streaming responses:
* - Preserves the SSE format for downstream consumers
* **⚠️ CURRENT IMPLEMENTATION: BUFFERING**
* This implementation reads the entire stream into memory before transforming.
* While functional, it does not preserve true streaming characteristics:
* - Blocks until entire response is received
* - Consumes memory proportional to response size
* - Increases Time-To-First-Byte (TTFB)
*
* **TODO: Future Enhancement**
* Implement true streaming using ReadableStream transformation:
* - Parse SSE chunks incrementally
* - Transform and yield chunks as they arrive
* - Reduce memory footprint and TTFB
*
* For streaming responses (current buffered approach):
* - Unwraps the `response` field from each SSE event
* - Returns transformed SSE text as new Response
* - Extracts usage metadata from headers
*
* Note: This reads the entire stream and returns a new Response.
* The stream is preserved as SSE text, not blocked.
*
* Note: Does NOT handle thinking block extraction (Task 10)
*
* @param response - Fetch Response object with SSE body
* @param response - The SSE response from Antigravity API
* @returns TransformResult with transformed response and metadata
*/
export async function transformStreamingResponse(response: Response): Promise<TransformResult> {
@@ -425,6 +435,7 @@ export async function transformStreamingResponse(response: Response): Promise<Tr
}
// Handle SSE stream
// NOTE: Current implementation buffers entire stream - see JSDoc for details
try {
const text = await response.text()
const transformed = transformStreamingPayload(text)