fix(antigravity): align identity protocol and behavior with official AM

This commit is contained in:
ivan_yakimkin
2026-05-08 11:20:32 +03:00
parent eeb836d62a
commit cababfe58a
3 changed files with 54 additions and 14 deletions

View File

@@ -757,10 +757,19 @@ export class AntigravityExecutor extends BaseExecutor {
);
}
const getChunkedOrFixedBody = (bodyStr: string) => {
if (stream) {
return (async function* () {
yield new TextEncoder().encode(bodyStr);
})();
}
return bodyStr;
};
let response = await fetch(url, {
method: "POST",
headers: finalHeaders,
body: serializedRequest.bodyString,
body: getChunkedOrFixedBody(serializedRequest.bodyString),
signal,
});
@@ -771,7 +780,7 @@ export class AntigravityExecutor extends BaseExecutor {
response = await fetch(url, {
method: "POST",
headers: retryHeaders,
body: serializedRequest.bodyString,
body: getChunkedOrFixedBody(serializedRequest.bodyString),
signal,
});
finalHeaders = retryHeaders;
@@ -840,7 +849,7 @@ export class AntigravityExecutor extends BaseExecutor {
const creditsResp = await fetch(url, {
method: "POST",
headers: finalCreditsHeaders,
body: serializedCreditsRequest.bodyString,
body: getChunkedOrFixedBody(serializedCreditsRequest.bodyString),
signal,
});
if (creditsResp.ok || creditsResp.status !== HTTP_STATUS.RATE_LIMITED) {

View File

@@ -83,18 +83,25 @@ export function getAntigravitySessionId(
);
}
import os from "node:os";
const STABLE_MACHINE_ID = crypto
.createHash("sha256")
.update(`omniroute:machine_id:${os.hostname()}`)
.digest("hex");
const FORMATTED_MACHINE_ID = [
STABLE_MACHINE_ID.slice(0, 8),
STABLE_MACHINE_ID.slice(8, 12),
STABLE_MACHINE_ID.slice(12, 16),
STABLE_MACHINE_ID.slice(16, 20),
STABLE_MACHINE_ID.slice(20, 32),
].join("-");
export function deriveAntigravityMachineId(
credentials?: AntigravityCredentialsLike | null
_credentials?: AntigravityCredentialsLike | null
): string {
const key = getAntigravityAccountKey(credentials) || PROCESS_SESSION_ID;
const hex = crypto.createHash("sha256").update(`antigravity:${key}`).digest("hex");
return [
hex.slice(0, 8),
hex.slice(8, 12),
hex.slice(12, 16),
hex.slice(16, 20),
hex.slice(20, 32),
].join("-");
return FORMATTED_MACHINE_ID;
}
export function getAntigravityVscodeSessionId(): string {

View File

@@ -136,6 +136,27 @@ function extractClientThoughtSignature(toolCall: unknown): string | null {
return typeof signature === "string" && signature.length > 0 ? signature : null;
}
function deepCleanUndefined(value: unknown, depth = 0): void {
if (depth > 10 || !value || typeof value !== "object") {
return;
}
if (Array.isArray(value)) {
for (const item of value) {
deepCleanUndefined(item, depth + 1);
}
} else {
const obj = value as Record<string, unknown>;
for (const key of Object.keys(obj)) {
const val = obj[key];
if (typeof val === "string" && val === "[undefined]") {
delete obj[key];
} else {
deepCleanUndefined(val, depth + 1);
}
}
}
}
function applyAntigravityGenerationDefaults(generationConfig: GeminiGenerationConfig) {
const config = { ...generationConfig };
if (config.topK === undefined) {
@@ -359,8 +380,9 @@ function openaiToGeminiBase(model, body, stream, toolNameOptions: GeminiToolName
...toolNameOptions,
toolNameMap,
});
if (geminiTools) {
if (geminiTools && geminiTools.length > 0) {
result.tools = geminiTools;
result.toolConfig = { functionCallingConfig: { mode: "VALIDATED" } };
}
// Convert response_format to Gemini's responseMimeType/responseSchema
@@ -384,6 +406,8 @@ function openaiToGeminiBase(model, body, stream, toolNameOptions: GeminiToolName
result._toolNameMap = changedToolNameMap;
}
deepCleanUndefined(result);
return result;
}