[codex] align antigravity special-model non-stream path with CPA (#444)

* align antigravity special-model non-stream path with cpa

* fix antigravity tail aggregation review feedback

* fix antigravity fallback aggregation review feedback
This commit is contained in:
Cita
2026-04-06 15:03:55 +08:00
committed by GitHub
parent 448f488f95
commit 42f9049aff
8 changed files with 348 additions and 51 deletions
@@ -1,4 +1,5 @@
import type { PreparedProviderRequest, PrepareProviderRequestInput, ProviderAction, ProviderProfile } from './types.js';
import { resolveAntigravityProviderAction } from './antigravityRuntime.js';
const ANTIGRAVITY_RUNTIME_USER_AGENT = 'antigravity/1.19.6 darwin/arm64';
@@ -6,11 +7,6 @@ function asTrimmedString(value: unknown): string {
return typeof value === 'string' ? value.trim() : '';
}
function resolveAction(action: ProviderAction | undefined, stream: boolean): ProviderAction {
if (action) return action;
return stream ? 'streamGenerateContent' : 'generateContent';
}
function resolvePath(action: ProviderAction): string {
if (action === 'countTokens') return '/v1internal:countTokens';
if (action === 'streamGenerateContent') return '/v1internal:streamGenerateContent?alt=sse';
@@ -20,7 +16,7 @@ function resolvePath(action: ProviderAction): string {
export const antigravityProviderProfile: ProviderProfile = {
id: 'antigravity',
prepareRequest(input: PrepareProviderRequestInput): PreparedProviderRequest {
const action = resolveAction(input.action, input.stream);
const action = resolveAntigravityProviderAction(input.action, input.stream, input.modelName);
const projectId = asTrimmedString(input.oauthProjectId);
return {
path: resolvePath(action),
@@ -38,7 +34,7 @@ export const antigravityProviderProfile: ProviderProfile = {
runtime: {
executor: 'antigravity',
modelName: input.modelName,
stream: action === 'streamGenerateContent',
stream: input.stream,
oauthProjectId: projectId,
action,
},
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest';
import {
resolveAntigravityProviderAction,
shouldUseAntigravityStreamAction,
} from './antigravityRuntime.js';
describe('shouldUseAntigravityStreamAction', () => {
it('returns true for Claude-family model names', () => {
expect(shouldUseAntigravityStreamAction('claude')).toBe(true);
expect(shouldUseAntigravityStreamAction('claude-2')).toBe(true);
expect(shouldUseAntigravityStreamAction('claude-instant')).toBe(true);
expect(shouldUseAntigravityStreamAction('CLAUDE-OPUS-4-1')).toBe(true);
});
it('returns true for Gemini special-model names', () => {
expect(shouldUseAntigravityStreamAction('gemini-3-pro')).toBe(true);
expect(shouldUseAntigravityStreamAction('gemini-3-pro-latest')).toBe(true);
expect(shouldUseAntigravityStreamAction('gemini-3.1-flash-image')).toBe(true);
});
it('returns false for models outside the Claude-family heuristic', () => {
expect(shouldUseAntigravityStreamAction('gemini-2.5-pro')).toBe(false);
expect(shouldUseAntigravityStreamAction('gpt-5')).toBe(false);
});
});
describe('resolveAntigravityProviderAction', () => {
it('routes Claude-family non-stream requests through streamGenerateContent', () => {
expect(resolveAntigravityProviderAction('generateContent', false, 'claude-opus-4-1'))
.toBe('streamGenerateContent');
});
it('routes Gemini special-model non-stream requests through streamGenerateContent', () => {
expect(resolveAntigravityProviderAction('generateContent', false, 'gemini-3-pro-latest'))
.toBe('streamGenerateContent');
expect(resolveAntigravityProviderAction('generateContent', false, 'gemini-3.1-flash-image'))
.toBe('streamGenerateContent');
});
});
@@ -0,0 +1,21 @@
import type { ProviderAction } from './types.js';
export function shouldUseAntigravityStreamAction(modelName: string): boolean {
const normalizedModel = modelName.toLowerCase();
return normalizedModel.includes('claude')
|| normalizedModel.includes('gemini-3-pro')
|| normalizedModel.includes('gemini-3.1-flash-image');
}
export function resolveAntigravityProviderAction(
action: ProviderAction | undefined,
stream: boolean,
modelName: string,
): ProviderAction {
if (action === 'countTokens') return action;
if (action === 'streamGenerateContent') return action;
if (stream || shouldUseAntigravityStreamAction(modelName)) {
return 'streamGenerateContent';
}
return action || 'generateContent';
}