mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* fix(antigravity): preserve protocol fidelity and fail closed * chore: add PR-numbered changelog fragment * test: split oversized Antigravity suites * refactor(antigravity): align official IDE and CLI identities * fix(antigravity): align catalog with callable models * test(antigravity): update 2 test files to renamed version-cache API (#8013 fix) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: nguyenha935 <208228297+nguyenha935@users.noreply.github.com> Co-authored-by: backryun <backryun@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: nguyenha935 <nguyenha935@users.noreply.github.com> Co-authored-by: Probe Test <probe@example.com>
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import {
|
|
DEFAULT_ANTIGRAVITY_CLIENT_PROFILE,
|
|
normalizeAntigravityClientProfile,
|
|
type AntigravityClientProfile,
|
|
} from "@/shared/constants/antigravityClientProfile";
|
|
import { getAntigravityContentHeaders } from "./antigravityHeaders.ts";
|
|
import type { AntigravityCredentialsLike } from "./antigravityIdentity.ts";
|
|
import {
|
|
resolveAntigravityCliVersion,
|
|
resolveAntigravityIdeVersion,
|
|
} from "./antigravityVersion.ts";
|
|
|
|
export {
|
|
ANTIGRAVITY_CLIENT_PROFILE_VALUES,
|
|
DEFAULT_ANTIGRAVITY_CLIENT_PROFILE,
|
|
normalizeAntigravityClientProfile,
|
|
type AntigravityClientProfile,
|
|
} from "@/shared/constants/antigravityClientProfile";
|
|
|
|
type AntigravityProfileCredentials = AntigravityCredentialsLike & {
|
|
providerSpecificData?: Record<string, unknown> | null;
|
|
};
|
|
|
|
const ABSENT_CONTENT_IDENTITY_HEADERS = [
|
|
"x-client-name",
|
|
"x-client-version",
|
|
"x-machine-id",
|
|
"x-vscode-sessionid",
|
|
"X-Goog-Api-Client",
|
|
"Client-Metadata",
|
|
] as const;
|
|
|
|
export function getAntigravityClientProfile(
|
|
credentials?: AntigravityProfileCredentials | null
|
|
): AntigravityClientProfile {
|
|
const fromProviderData =
|
|
credentials?.providerSpecificData &&
|
|
typeof credentials.providerSpecificData === "object" &&
|
|
!Array.isArray(credentials.providerSpecificData)
|
|
? credentials.providerSpecificData.clientProfile
|
|
: undefined;
|
|
|
|
return normalizeAntigravityClientProfile(fromProviderData);
|
|
}
|
|
|
|
export function resolveAntigravityClientVersion(
|
|
profile: AntigravityClientProfile
|
|
): Promise<string> {
|
|
return profile === "cli" ? resolveAntigravityCliVersion() : resolveAntigravityIdeVersion();
|
|
}
|
|
|
|
export function removeHeaderCaseInsensitive(headers: Record<string, string>, name: string): void {
|
|
const lowerName = name.toLowerCase();
|
|
for (const key of Object.keys(headers)) {
|
|
if (key.toLowerCase() === lowerName) {
|
|
delete headers[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
function getProjectHeaderValue(body: unknown): string | null {
|
|
const project =
|
|
body && typeof body === "object" ? (body as Record<string, unknown>).project : null;
|
|
if (typeof project !== "string" || project.trim().length === 0) return null;
|
|
if (project === "test-project" || project === "project-id") return null;
|
|
return project;
|
|
}
|
|
|
|
/** Apply the selected official client identity to a Cloud Code content request. */
|
|
export function applyAntigravityClientProfileHeaders(
|
|
headers: Record<string, string>,
|
|
credentials: AntigravityProfileCredentials | null | undefined,
|
|
body: unknown
|
|
): AntigravityClientProfile {
|
|
const profile = getAntigravityClientProfile(credentials);
|
|
const identityHeaders = getAntigravityContentHeaders(profile);
|
|
|
|
removeHeaderCaseInsensitive(headers, "User-Agent");
|
|
headers["User-Agent"] = identityHeaders["User-Agent"];
|
|
for (const name of ABSENT_CONTENT_IDENTITY_HEADERS) {
|
|
removeHeaderCaseInsensitive(headers, name);
|
|
}
|
|
|
|
const project = getProjectHeaderValue(body);
|
|
removeHeaderCaseInsensitive(headers, "x-goog-user-project");
|
|
if (project) {
|
|
headers["x-goog-user-project"] = project;
|
|
}
|
|
|
|
return profile;
|
|
}
|