@@ -71,7 +71,7 @@ function transformSseLine(line: string, onError?: (body: GeminiApiBody) => Gemin
7171 }
7272 try {
7373 let parsed = JSON . parse ( json ) as unknown ;
74-
74+
7575 // Handle array-wrapped responses
7676 if ( Array . isArray ( parsed ) ) {
7777 parsed = parsed . find ( ( item ) => typeof item === "object" && item !== null ) ;
@@ -127,7 +127,7 @@ export function createSseTransformStream(onError?: (body: GeminiApiBody) => Gemi
127127 if ( ! sessionId || ! family ) return ;
128128 const response = body . response as any ;
129129 if ( ! response ?. candidates ) return ;
130-
130+
131131 response . candidates . forEach ( ( candidate : any , index : number ) => {
132132 if ( candidate . groundingMetadata ) {
133133 log . debug ( "SSE Grounding metadata found" , { groundingMetadata : candidate . groundingMetadata } ) ;
@@ -199,17 +199,17 @@ export async function prepareAntigravityRequest(
199199 new Headers ( init . headers ) . forEach ( ( value , key ) => reqHeaders . set ( key , value ) ) ;
200200 }
201201 requestInit . headers = reqHeaders ;
202-
202+
203203 // If body isn't in init, try to get it from request
204204 if ( ! originalBody && input . body ) {
205205 // We need to clone to avoid consuming the original request if possible,
206206 // but standard Request cloning is sync.
207207 // We'll try to read text if we can.
208208 try {
209- // Note: If input is a Request object that has been used, this might fail.
210- // But usually in this context it's fresh.
211- const cloned = input . clone ( ) ;
212- originalBody = await cloned . text ( ) ;
209+ // Note: If input is a Request object that has been used, this might fail.
210+ // But usually in this context it's fresh.
211+ const cloned = input . clone ( ) ;
212+ originalBody = await cloned . text ( ) ;
213213 } catch ( e ) {
214214 // If clone fails (e.g. body used), we might be in trouble or it's empty.
215215 }
@@ -256,33 +256,33 @@ export async function prepareAntigravityRequest(
256256
257257 if ( isWrapped ) {
258258 if ( isClaudeModel ) {
259- const context : TransformContext = {
260- model : effectiveModel ,
261- family : getModelFamily ( effectiveModel ) ,
262- projectId : ( parsedBody . project as string ) || projectId ,
263- streaming,
264- requestId : generateRequestId ( ) ,
265- sessionId : getSessionId ( ) ,
266- } ;
267- const innerRequest = parsedBody . request as Record < string , unknown > ;
268- const result = transformClaudeRequest ( context , innerRequest ) ;
269- body = result . body ;
270- transformDebugInfo = result . debugInfo ;
271-
272- if ( transformDebugInfo ) {
273- log . debug ( "Using transformer (wrapped)" , { transformer : transformDebugInfo . transformer , model : effectiveModel , family : context . family , toolCount : transformDebugInfo . toolCount } ) ;
274- }
259+ const context : TransformContext = {
260+ model : effectiveModel ,
261+ family : getModelFamily ( effectiveModel ) ,
262+ projectId : ( parsedBody . project as string ) || projectId ,
263+ streaming,
264+ requestId : generateRequestId ( ) ,
265+ sessionId : getSessionId ( ) ,
266+ } ;
267+ const innerRequest = parsedBody . request as Record < string , unknown > ;
268+ const result = transformClaudeRequest ( context , innerRequest ) ;
269+ body = result . body ;
270+ transformDebugInfo = result . debugInfo ;
271+
272+ if ( transformDebugInfo ) {
273+ log . debug ( "Using transformer (wrapped)" , { transformer : transformDebugInfo . transformer , model : effectiveModel , family : context . family , toolCount : transformDebugInfo . toolCount } ) ;
274+ }
275275 } else {
276- const wrappedBody = {
276+ const wrappedBody = {
277277 ...parsedBody ,
278278 model : effectiveModel ,
279279 userAgent : "antigravity" ,
280280 requestId : generateRequestId ( ) ,
281- } as Record < string , unknown > ;
282- if ( wrappedBody . request && typeof wrappedBody . request === "object" ) {
281+ } as Record < string , unknown > ;
282+ if ( wrappedBody . request && typeof wrappedBody . request === "object" ) {
283283 ( wrappedBody . request as Record < string , unknown > ) . sessionId = getSessionId ( ) ;
284- }
285- body = JSON . stringify ( wrappedBody ) ;
284+ }
285+ body = JSON . stringify ( wrappedBody ) ;
286286 }
287287 } else {
288288 const context : TransformContext = {
@@ -369,22 +369,22 @@ export async function transformAntigravityResponse(
369369 return response ;
370370 }
371371
372- const errorHandler = ( body : GeminiApiBody ) : GeminiApiBody | null => {
373- const previewErrorFixed = rewriteGeminiPreviewAccessError ( body , response . status , requestedModel ) ;
374- const rateLimitErrorFixed = rewriteGeminiRateLimitError ( body ) ;
372+ const errorHandler = ( body : GeminiApiBody ) : GeminiApiBody | null => {
373+ const previewErrorFixed = rewriteGeminiPreviewAccessError ( body , response . status , requestedModel ) ;
374+ const rateLimitErrorFixed = rewriteGeminiRateLimitError ( body ) ;
375375
376- const patched = previewErrorFixed ?? rateLimitErrorFixed ;
376+ const patched = previewErrorFixed ?? rateLimitErrorFixed ;
377377
378- if ( previewErrorFixed ?. error ) {
379- client . tui . showToast ( {
380- body : { message : previewErrorFixed . error . message ?? "You need access to gemini 3" , title : "Gemini 3 Access Required" , variant : "error" }
381- } ) . catch ( ( ) => { } ) ;
382- }
378+ if ( previewErrorFixed ?. error ) {
379+ client . tui . showToast ( {
380+ body : { message : previewErrorFixed . error . message ?? "You need access to gemini 3" , title : "Gemini 3 Access Required" , variant : "error" }
381+ } ) . catch ( ( ) => { } ) ;
382+ }
383383
384- return patched ;
385- } ;
384+ return patched ;
385+ } ;
386386
387- if ( streaming && response . ok && isEventStreamResponse && response . body ) {
387+ if ( streaming && response . ok && isEventStreamResponse && response . body ) {
388388 logAntigravityDebugResponse ( debugContext , response , {
389389 note : "Streaming SSE (passthrough mode)" ,
390390 } ) ;
@@ -419,25 +419,25 @@ export async function transformAntigravityResponse(
419419 if ( sessionId && parsed ) {
420420 const responseBody = parsed . response as any ;
421421 if ( responseBody ?. candidates ) {
422- responseBody . candidates . forEach ( ( candidate : any ) => {
423- if ( candidate . groundingMetadata ) {
424- log . debug ( "Grounding metadata found" , { groundingMetadata : candidate . groundingMetadata } ) ;
425- }
426- let fullText = "" ;
427- let signature = "" ;
428- if ( candidate . content ?. parts ) {
429- candidate . content . parts . forEach ( ( part : any ) => {
430- if ( part . thought ) {
431- if ( part . text ) fullText += part . text ;
432- if ( part . thoughtSignature ) signature = part . thoughtSignature ;
433- }
434- } ) ;
435- }
436- if ( fullText && signature ) {
437- cacheSignature ( family , sessionId , fullText , signature ) ;
438- log . debug ( "Cached signature" , { family, sessionId, textLen : fullText . length } ) ;
422+ responseBody . candidates . forEach ( ( candidate : any ) => {
423+ if ( candidate . groundingMetadata ) {
424+ log . debug ( "Grounding metadata found" , { groundingMetadata : candidate . groundingMetadata } ) ;
425+ }
426+ let fullText = "" ;
427+ let signature = "" ;
428+ if ( candidate . content ?. parts ) {
429+ candidate . content . parts . forEach ( ( part : any ) => {
430+ if ( part . thought ) {
431+ if ( part . text ) fullText += part . text ;
432+ if ( part . thoughtSignature ) signature = part . thoughtSignature ;
439433 }
440- } ) ;
434+ } ) ;
435+ }
436+ if ( fullText && signature ) {
437+ cacheSignature ( family , sessionId , fullText , signature ) ;
438+ log . debug ( "Cached signature" , { family, sessionId, textLen : fullText . length } ) ;
439+ }
440+ } ) ;
441441 }
442442 }
443443
@@ -487,7 +487,7 @@ export async function transformAntigravityResponse(
487487 variant : "error" ,
488488 } ,
489489 } ) ;
490- } catch { }
490+ } catch { }
491491 }
492492
493493 if ( streaming && response . ok && isEventStreamResponse ) {
0 commit comments