mirror of
https://github.com/decolua/9router.git
synced 2026-05-08 12:01:28 +00:00
Fix Antigravity OAuth
This commit is contained in:
@@ -94,7 +94,7 @@ export const CLIENT_METADATA = {
|
||||
// Internal anti-loop header to identify requests originating from this proxy
|
||||
export const INTERNAL_REQUEST_HEADER = { name: "x-request-source", value: "local" };
|
||||
|
||||
// Antigravity headers
|
||||
// Antigravity headers (for chat/stream requests)
|
||||
export const ANTIGRAVITY_HEADERS = {
|
||||
"X-Client-Name": "antigravity",
|
||||
"X-Client-Version": "1.107.0",
|
||||
@@ -108,6 +108,21 @@ export const CLOUD_CODE_API = {
|
||||
onboardUser: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
||||
};
|
||||
|
||||
// Headers for loadCodeAssist / onboardUser API calls (matches CLIProxyAPI Go source)
|
||||
export const LOAD_CODE_ASSIST_HEADERS = {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "google-api-nodejs-client/9.15.1",
|
||||
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
||||
"Client-Metadata": JSON.stringify({ ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" }),
|
||||
};
|
||||
|
||||
// Metadata body for loadCodeAssist / onboardUser (string enum, matches CLIProxyAPI Go source)
|
||||
export const LOAD_CODE_ASSIST_METADATA = {
|
||||
ideType: "IDE_UNSPECIFIED",
|
||||
platform: "PLATFORM_UNSPECIFIED",
|
||||
pluginType: "GEMINI",
|
||||
};
|
||||
|
||||
// Provider configurations
|
||||
export const PROVIDERS = {
|
||||
claude: {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* This significantly reduces the risk of being flagged by Google's anti-abuse systems.
|
||||
*/
|
||||
|
||||
import {ANTIGRAVITY_HEADERS, CLIENT_METADATA, CLOUD_CODE_API, getPlatformUserAgent} from "../config/constants.js";
|
||||
import {CLOUD_CODE_API, LOAD_CODE_ASSIST_HEADERS, LOAD_CODE_ASSIST_METADATA} from "../config/constants.js";
|
||||
|
||||
// ─── Cache ────────────────────────────────────────────────────────────────────
|
||||
// connectionId -> { projectId: string, fetchedAt: number }
|
||||
@@ -159,13 +159,8 @@ export function removeConnection(connectionId) {
|
||||
async function fetchProjectId(accessToken, signal) {
|
||||
const response = await fetch(CLOUD_CODE_API.loadCodeAssist, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": getPlatformUserAgent(),
|
||||
...ANTIGRAVITY_HEADERS
|
||||
},
|
||||
body: JSON.stringify({metadata: CLIENT_METADATA, mode: 1}),
|
||||
headers: { ...LOAD_CODE_ASSIST_HEADERS, "Authorization": `Bearer ${accessToken}` },
|
||||
body: JSON.stringify({ metadata: LOAD_CODE_ASSIST_METADATA }),
|
||||
signal
|
||||
});
|
||||
|
||||
@@ -205,7 +200,7 @@ async function fetchProjectId(accessToken, signal) {
|
||||
async function onboardUser(accessToken, tierID, externalSignal) {
|
||||
console.log(`[ProjectId] Onboarding user with tier: ${tierID}`);
|
||||
|
||||
const reqBody = {tierId: tierID, metadata: CLIENT_METADATA, mode: 1};
|
||||
const reqBody = { tierId: tierID, metadata: LOAD_CODE_ASSIST_METADATA };
|
||||
const MAX_ATTEMPTS = 5;
|
||||
|
||||
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||
@@ -221,12 +216,7 @@ async function onboardUser(accessToken, tierID, externalSignal) {
|
||||
try {
|
||||
const response = await fetch(CLOUD_CODE_API.onboardUser, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": getPlatformUserAgent(),
|
||||
...ANTIGRAVITY_HEADERS
|
||||
},
|
||||
headers: { ...LOAD_CODE_ASSIST_HEADERS, "Authorization": `Bearer ${accessToken}` },
|
||||
body: JSON.stringify(reqBody),
|
||||
signal: localCtrl.signal
|
||||
});
|
||||
|
||||
@@ -97,7 +97,8 @@ export const ANTIGRAVITY_CONFIG = {
|
||||
onboardUserEndpoint: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
||||
loadCodeAssistUserAgent: "google-api-nodejs-client/9.15.1",
|
||||
loadCodeAssistApiClient: "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
||||
loadCodeAssistClientMetadata: JSON.stringify({ ideType: 9, platform: getOAuthPlatformEnum(), pluginType: 2 }),
|
||||
// String enum matches CLIProxyAPI Go source (internal/auth/antigravity/constants.go)
|
||||
loadCodeAssistClientMetadata: JSON.stringify({ ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" }),
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
KIMI_CODING_CONFIG,
|
||||
KILOCODE_CONFIG,
|
||||
CLINE_CONFIG,
|
||||
getOAuthClientMetadata,
|
||||
} from "./constants/oauth";
|
||||
|
||||
// Provider configurations
|
||||
@@ -255,21 +254,22 @@ const PROVIDERS = {
|
||||
return await response.json();
|
||||
},
|
||||
postExchange: async (tokens) => {
|
||||
const headers = {
|
||||
Authorization: `Bearer ${tokens.access_token}`,
|
||||
// Matches CLIProxyAPI Go source: string enum, no mode field
|
||||
const loadHeaders = {
|
||||
"Authorization": `Bearer ${tokens.access_token}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": ANTIGRAVITY_CONFIG.loadCodeAssistUserAgent,
|
||||
"X-Goog-Api-Client": ANTIGRAVITY_CONFIG.loadCodeAssistApiClient,
|
||||
"Client-Metadata": ANTIGRAVITY_CONFIG.loadCodeAssistClientMetadata,
|
||||
"x-request-source": "local", // MITM passthrough marker
|
||||
"x-request-source": "local",
|
||||
};
|
||||
const metadata = getOAuthClientMetadata();
|
||||
const metadata = { ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
|
||||
|
||||
// Fetch user info
|
||||
const userInfoRes = await fetch(`${ANTIGRAVITY_CONFIG.userInfoUrl}?alt=json`, {
|
||||
headers: {
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokens.access_token}`,
|
||||
"x-request-source": "local", // MITM passthrough marker
|
||||
"x-request-source": "local",
|
||||
},
|
||||
});
|
||||
const userInfo = userInfoRes.ok ? await userInfoRes.json() : {};
|
||||
@@ -280,13 +280,12 @@ const PROVIDERS = {
|
||||
try {
|
||||
const loadRes = await fetch(ANTIGRAVITY_CONFIG.loadCodeAssistEndpoint, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ metadata, mode: 1 }),
|
||||
headers: loadHeaders,
|
||||
body: JSON.stringify({ metadata }),
|
||||
});
|
||||
if (loadRes.ok) {
|
||||
const data = await loadRes.json();
|
||||
projectId = data.cloudaicompanionProject?.id || data.cloudaicompanionProject || "";
|
||||
// Extract tier ID
|
||||
if (Array.isArray(data.allowedTiers)) {
|
||||
for (const tier of data.allowedTiers) {
|
||||
if (tier.isDefault && tier.id) {
|
||||
@@ -307,8 +306,8 @@ const PROVIDERS = {
|
||||
try {
|
||||
const onboardRes = await fetch(ANTIGRAVITY_CONFIG.onboardUserEndpoint, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({ tierId, metadata, cloudaicompanionProject: projectId, mode: 1 }),
|
||||
headers: loadHeaders,
|
||||
body: JSON.stringify({ tierId, metadata }),
|
||||
});
|
||||
if (onboardRes.ok) {
|
||||
const result = await onboardRes.json();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import crypto from "crypto";
|
||||
import { platform, arch } from "os";
|
||||
import open from "open";
|
||||
import { ANTIGRAVITY_CONFIG } from "../constants/oauth.js";
|
||||
import { getServerCredentials } from "../config/index.js";
|
||||
@@ -92,21 +91,14 @@ export class AntigravityService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata object for API calls
|
||||
* Uses numeric enum values matching Antigravity binary specifications
|
||||
* Get metadata object for loadCodeAssist / onboardUser API calls.
|
||||
* Uses string enum values matching CLIProxyAPI Go source.
|
||||
*/
|
||||
getMetadata() {
|
||||
const os = platform();
|
||||
const architecture = arch();
|
||||
let platformEnum = 0; // UNSPECIFIED
|
||||
if (os === "darwin") platformEnum = architecture === "arm64" ? 2 : 1;
|
||||
else if (os === "linux") platformEnum = architecture === "arm64" ? 4 : 3;
|
||||
else if (os === "win32") platformEnum = 5;
|
||||
|
||||
return {
|
||||
ideType: 9, // ANTIGRAVITY
|
||||
platform: platformEnum,
|
||||
pluginType: 2, // GEMINI
|
||||
ideType: "IDE_UNSPECIFIED",
|
||||
platform: "PLATFORM_UNSPECIFIED",
|
||||
pluginType: "GEMINI",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +109,7 @@ export class AntigravityService {
|
||||
const response = await fetch(this.config.loadCodeAssistEndpoint, {
|
||||
method: "POST",
|
||||
headers: this.getApiHeaders(accessToken),
|
||||
body: JSON.stringify({ metadata: this.getMetadata(), mode: 1 }),
|
||||
body: JSON.stringify({ metadata: this.getMetadata() }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -154,12 +146,7 @@ export class AntigravityService {
|
||||
const response = await fetch(this.config.onboardUserEndpoint, {
|
||||
method: "POST",
|
||||
headers: this.getApiHeaders(accessToken),
|
||||
body: JSON.stringify({
|
||||
tierId,
|
||||
metadata: this.getMetadata(),
|
||||
cloudaicompanionProject: projectId,
|
||||
mode: 1,
|
||||
}),
|
||||
body: JSON.stringify({ tierId, metadata: this.getMetadata() }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user